Advertisement
Guest User

yeet

a guest
Oct 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.54 KB | None | 0 0
  1. if (instructionHeader == 0x0) {
  2.             if (instructionArg3 == 0x0) { //CLS
  3.                 clearScreen(cpu->displayPtr);
  4.             } else if (instructionArg3 == 0xE) { //RET
  5.                 //TODO
  6.                 cpu->PC = cpu->STACK[cpu->SP];
  7.                 cpu->SP--;
  8.                 incrementPC = 0;
  9.             }
  10.         } else if (instructionHeader == 0x1) { //JMP
  11.             cpu->PC = instructionArg1to3;
  12.             incrementPC = 0;
  13.         } else if (instructionHeader == 0x2) {
  14.             //increment stack pointer, put the current PC on top of stack, PC Set to 2nnn
  15.             cpu->STACK[cpu->SP] = cpu->PC;
  16.             cpu->SP++;
  17.             cpu->PC = instructionArg1to3;
  18.             incrementPC = 0;
  19.         } else if (instructionHeader == 0x3) {
  20.             if (*(cpu->regptr[instructionArg1]) == instructionArg2to3) {
  21.                 cpu->PC += 2;
  22.             }
  23.         } else if (instructionHeader == 0x4) {
  24.             if (*(cpu->regptr[instructionArg1]) != instructionArg2to3) {
  25.                 cpu->PC += 2;
  26.             }
  27.         } else if (instructionHeader == 0x5) {
  28.             if (*(cpu->regptr[instructionArg1]) == *(cpu->regptr[instructionArg2])) {
  29.                 cpu->PC += 2;
  30.             }
  31.         } else if (instructionHeader == 0x6) {
  32.             *(cpu->regptr[instructionArg1]) = instructionArg2to3;
  33.         } else if (instructionHeader == 0x7) {
  34.             *(cpu->regptr[instructionArg1]) += instructionArg2to3;
  35.         } else if (instructionHeader == 0x8) {
  36.             if (instructionArg3 == 0x0) {
  37.                 *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg2]);
  38.             } else if (instructionArg3 == 0x1) {
  39.                 *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) | *(cpu->regptr[instructionArg2]);
  40.             } else if (instructionArg3 == 0x2) {
  41.                 *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) & *(cpu->regptr[instructionArg2]);
  42.             } else if (instructionArg3 == 0x3) {
  43.                 *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) ^ *(cpu->regptr[instructionArg2]);
  44.             } else if (instructionArg3 == 0x4) {
  45.                 //The values of Vx and Vy are added together. If the result is greater than 8 bits (i.e., > 255,) VF is set to 1, otherwise 0. Only the lowest 8 bits of the result are kept, and stored in Vx.
  46.                 *(cpu->regptr[instructionArg1]) += *(cpu->regptr[instructionArg2]);
  47.                 if (*(cpu->regptr[instructionArg1]) + *(cpu->regptr[instructionArg2]) != (*(cpu->regptr[instructionArg1]) + *(cpu->regptr[instructionArg3]) & 0xFF)) {
  48.                     cpu->VF = 1;
  49.                 } else {
  50.                     cpu->VF = 0;
  51.                 }
  52.             } else if (instructionArg3 == 0x5) {
  53.                 *(cpu->regptr[instructionArg1]) -= *(cpu->regptr[instructionArg2]);
  54.                 if (*(cpu->regptr[instructionArg1]) > *(cpu->regptr[instructionArg2])) {
  55.                     cpu->VF = 1;
  56.                 } else {
  57.                     cpu->VF = 0;
  58.                 }
  59.             } else if (instructionArg3 == 0x6) {
  60.                 *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) / 2;
  61.                 if (*(cpu->regptr[instructionArg1]) & 0b00000001) {
  62.                     cpu->VF = 1;
  63.                 } else {
  64.                     cpu->VF = 0;
  65.                 }
  66.             } else if (instructionArg3 == 0x7) {
  67.                 *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg2]) - *(cpu->regptr[instructionArg1]);
  68.                 if (*(cpu->regptr[instructionArg3]) > *(cpu->regptr[instructionArg2])) {
  69.                     cpu->VF = 1;
  70.                 } else {
  71.                     cpu->VF = 0;
  72.                 }
  73.             } else if (instructionArg3 == 0xE) {
  74.                 *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) * 2;
  75.                 if (*(cpu->regptr[instructionArg1]) & 0b10000000) {
  76.                     cpu->VF = 1;
  77.                 } else {
  78.                     cpu->VF = 0;
  79.                 }
  80.             }
  81.         } else if (instructionHeader == 0x9) {
  82.             if (*(cpu->regptr[instructionArg2]) != *(cpu->regptr[instructionArg3])) {
  83.                 cpu->PC += 2;
  84.             }
  85.         } else if (instructionHeader == 0xA) {
  86.             cpu->I = instructionArg1to3;
  87.         } else if (instructionHeader == 0xB) {
  88.             cpu->PC = instructionArg1to3 + cpu->V0;
  89.         } else if (instructionHeader == 0xC) {
  90.             *cpu->regptr[instructionArg1] = (rand() % 255) & instructionArg2to3;
  91.         } else if (instructionHeader == 0xD) {
  92.             //DRW, todo
  93.             uint8_t bytesToRead = instructionArg3;
  94.             uint8_t *sprite = malloc(sizeof(uint8_t) * bytesToRead);
  95.             for (int i = 0; i < bytesToRead; i++) {
  96.                 *(sprite + i) = *(cpu->ramPtr->mem + cpu->I + i);
  97.             }
  98.             displaySprite(cpu, *(cpu->regptr[instructionArg1]), *(cpu->regptr[instructionArg2]), bytesToRead, sprite);
  99.             free(sprite);
  100.         } else if (instructionHeader == 0xE) {
  101.             if (instructionArg3 == 0xE) {
  102.                 if ((cpu->KEY[instructionArg1])) {
  103.                     cpu->PC += 2;
  104.                 }
  105.             } else if (instructionArg3 == 0x1) {
  106.                 if (!(cpu->KEY[instructionArg1])) {
  107.                     cpu->PC += 2;
  108.                 }
  109.             }
  110.         } else if (instructionHeader == 0xF) {
  111.             if (instructionArg3 == 0x7) {
  112.                 *(cpu->regptr[instructionArg1]) = cpu->DT;
  113.             } else if (instructionArg3 == 0xA) {
  114.  
  115.             } else if (instructionArg2 == 1 && instructionArg3 == 0x5) {
  116.                 cpu->DT = *(cpu->regptr[instructionArg1]);
  117.             } else if (instructionArg3 == 0x8) {
  118.                 cpu->ST = *(cpu->regptr[instructionArg1]);
  119.             } else if (instructionArg3 == 0xE) {
  120.                 cpu->I += *(cpu->regptr[instructionArg1]);
  121.             } else if (instructionArg3 == 0x9) {
  122.                 cpu->I = *(cpu->ramPtr->mem + 0x50 + instructionArg1*5);
  123.             } else if (instructionArg3 == 0x3) {
  124.  
  125.             } else if (instructionArg2 == 5 && instructionArg3 == 0x5) {
  126.                 for (int i = 0; i < 0xF; i++) {
  127.                     *(cpu->ramPtr->mem + cpu->I + i) = *(cpu->regptr[i]);
  128.                 }
  129.             } else if (instructionArg2 == 6 && instructionArg3 == 0x5) {
  130.                 for (int i = 0; i < 0xF; i++) {
  131.                     *(cpu->regptr[i]) = *(cpu->ramPtr->mem + cpu->I + i);
  132.                 }
  133.             }
  134.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement