Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (instructionHeader == 0x0) {
- if (instructionArg3 == 0x0) { //CLS
- clearScreen(cpu->displayPtr);
- } else if (instructionArg3 == 0xE) { //RET
- //TODO
- cpu->PC = cpu->STACK[cpu->SP];
- cpu->SP--;
- incrementPC = 0;
- }
- } else if (instructionHeader == 0x1) { //JMP
- cpu->PC = instructionArg1to3;
- incrementPC = 0;
- } else if (instructionHeader == 0x2) {
- //increment stack pointer, put the current PC on top of stack, PC Set to 2nnn
- cpu->STACK[cpu->SP] = cpu->PC;
- cpu->SP++;
- cpu->PC = instructionArg1to3;
- incrementPC = 0;
- } else if (instructionHeader == 0x3) {
- if (*(cpu->regptr[instructionArg1]) == instructionArg2to3) {
- cpu->PC += 2;
- }
- } else if (instructionHeader == 0x4) {
- if (*(cpu->regptr[instructionArg1]) != instructionArg2to3) {
- cpu->PC += 2;
- }
- } else if (instructionHeader == 0x5) {
- if (*(cpu->regptr[instructionArg1]) == *(cpu->regptr[instructionArg2])) {
- cpu->PC += 2;
- }
- } else if (instructionHeader == 0x6) {
- *(cpu->regptr[instructionArg1]) = instructionArg2to3;
- } else if (instructionHeader == 0x7) {
- *(cpu->regptr[instructionArg1]) += instructionArg2to3;
- } else if (instructionHeader == 0x8) {
- if (instructionArg3 == 0x0) {
- *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg2]);
- } else if (instructionArg3 == 0x1) {
- *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) | *(cpu->regptr[instructionArg2]);
- } else if (instructionArg3 == 0x2) {
- *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) & *(cpu->regptr[instructionArg2]);
- } else if (instructionArg3 == 0x3) {
- *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) ^ *(cpu->regptr[instructionArg2]);
- } else if (instructionArg3 == 0x4) {
- //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.
- *(cpu->regptr[instructionArg1]) += *(cpu->regptr[instructionArg2]);
- if (*(cpu->regptr[instructionArg1]) + *(cpu->regptr[instructionArg2]) != (*(cpu->regptr[instructionArg1]) + *(cpu->regptr[instructionArg3]) & 0xFF)) {
- cpu->VF = 1;
- } else {
- cpu->VF = 0;
- }
- } else if (instructionArg3 == 0x5) {
- *(cpu->regptr[instructionArg1]) -= *(cpu->regptr[instructionArg2]);
- if (*(cpu->regptr[instructionArg1]) > *(cpu->regptr[instructionArg2])) {
- cpu->VF = 1;
- } else {
- cpu->VF = 0;
- }
- } else if (instructionArg3 == 0x6) {
- *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) / 2;
- if (*(cpu->regptr[instructionArg1]) & 0b00000001) {
- cpu->VF = 1;
- } else {
- cpu->VF = 0;
- }
- } else if (instructionArg3 == 0x7) {
- *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg2]) - *(cpu->regptr[instructionArg1]);
- if (*(cpu->regptr[instructionArg3]) > *(cpu->regptr[instructionArg2])) {
- cpu->VF = 1;
- } else {
- cpu->VF = 0;
- }
- } else if (instructionArg3 == 0xE) {
- *(cpu->regptr[instructionArg1]) = *(cpu->regptr[instructionArg1]) * 2;
- if (*(cpu->regptr[instructionArg1]) & 0b10000000) {
- cpu->VF = 1;
- } else {
- cpu->VF = 0;
- }
- }
- } else if (instructionHeader == 0x9) {
- if (*(cpu->regptr[instructionArg2]) != *(cpu->regptr[instructionArg3])) {
- cpu->PC += 2;
- }
- } else if (instructionHeader == 0xA) {
- cpu->I = instructionArg1to3;
- } else if (instructionHeader == 0xB) {
- cpu->PC = instructionArg1to3 + cpu->V0;
- } else if (instructionHeader == 0xC) {
- *cpu->regptr[instructionArg1] = (rand() % 255) & instructionArg2to3;
- } else if (instructionHeader == 0xD) {
- //DRW, todo
- uint8_t bytesToRead = instructionArg3;
- uint8_t *sprite = malloc(sizeof(uint8_t) * bytesToRead);
- for (int i = 0; i < bytesToRead; i++) {
- *(sprite + i) = *(cpu->ramPtr->mem + cpu->I + i);
- }
- displaySprite(cpu, *(cpu->regptr[instructionArg1]), *(cpu->regptr[instructionArg2]), bytesToRead, sprite);
- free(sprite);
- } else if (instructionHeader == 0xE) {
- if (instructionArg3 == 0xE) {
- if ((cpu->KEY[instructionArg1])) {
- cpu->PC += 2;
- }
- } else if (instructionArg3 == 0x1) {
- if (!(cpu->KEY[instructionArg1])) {
- cpu->PC += 2;
- }
- }
- } else if (instructionHeader == 0xF) {
- if (instructionArg3 == 0x7) {
- *(cpu->regptr[instructionArg1]) = cpu->DT;
- } else if (instructionArg3 == 0xA) {
- } else if (instructionArg2 == 1 && instructionArg3 == 0x5) {
- cpu->DT = *(cpu->regptr[instructionArg1]);
- } else if (instructionArg3 == 0x8) {
- cpu->ST = *(cpu->regptr[instructionArg1]);
- } else if (instructionArg3 == 0xE) {
- cpu->I += *(cpu->regptr[instructionArg1]);
- } else if (instructionArg3 == 0x9) {
- cpu->I = *(cpu->ramPtr->mem + 0x50 + instructionArg1*5);
- } else if (instructionArg3 == 0x3) {
- } else if (instructionArg2 == 5 && instructionArg3 == 0x5) {
- for (int i = 0; i < 0xF; i++) {
- *(cpu->ramPtr->mem + cpu->I + i) = *(cpu->regptr[i]);
- }
- } else if (instructionArg2 == 6 && instructionArg3 == 0x5) {
- for (int i = 0; i < 0xF; i++) {
- *(cpu->regptr[i]) = *(cpu->ramPtr->mem + cpu->I + i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement