Advertisement
Guest User

meh

a guest
Jun 30th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.53 KB | None | 0 0
  1.         /*  1 */    Instruction("sys"   , 0x0000);  // @deprecated Jump to machine code at nnn | 0x0nnn
  2.         /*  2 */    Instruction("cls"   , 0x00E0);  // Clear the display
  3.         /*  3 */    Instruction("ret"   , 0x00EE);  // Return from subroutine, Set program counter(PC) to top of stack and subtract 1 from stackpointer
  4.         /*  4 */    Instruction("jp"    , 0x1000);  // Jump to location at nnn                                                                   | 0x 1nnn
  5.         /*  5 */    Instruction("call"  , 0x2000);  // Call subroutine at nnn, Increment stackpointer, put PC on top of the stack, Set PC to nnn | 0x 2nnn
  6.         /*  6 */    Instruction("se"    , 0x3000);  // Skip instruction, if Vx = kk then increment program counter by 2                          | 0x 3xkk
  7.         /*  7 */    Instruction("sne"   , 0x4000);  // Skip instruction, if Vx != kk then increment program counter by 2                         | 0x 4xkk
  8.         /*  8 */    Instruction("se"    , 0x5000);  // Skip instruction, if Vx = Vy then increment program counter by 2                          | 0x 5xy0
  9.         /*  9 */    Instruction("ld"    , 0x6000);  // Put value kk into register Vx                                                             | 0x 6xkk
  10.         /* 10 */    Instruction("add"   , 0x7000);  // Set Vx = Vx + kk                                                                          | 0x 7xkk
  11.         /* 11 */    Instruction("ld"    , 0x8000);  // Put the value of register Vy in Vx                                                        | 0x 8xy0
  12.         /* 12 */    Instruction("or"    , 0x8001);  // Performs a bitwise Or on the values of Vx and Vy, Result in Vx                            | 0x 8xy1
  13.         /* 13 */    Instruction("and"   , 0x8002);  // Performs a bitwise And on the vlaues of Vx and Vy, Result in Vx                           | 0x 8xy2
  14.         /* 14 */    Instruction("xor"   , 0x8003);  // Performs a bitwise Xor on the values of Vx and Vy, Result in Vx                           | 0x 8xy3
  15.         /* 15 */    Instruction("add"   , 0x8004);  // Set Vx = Vx + Vy,Set VF = carry                                                           | 0x 8xy4
  16.         /* 16 */    Instruction("sub"   , 0x8005);  // If Vx > Vy then VF set to 1 else 0, Vx = Vy - Vx                                          | 0x 8xy5
  17.         /* 17 */    Instruction("shr"   , 0x8006);  // if least-significant bit (lsb) of Vx is 1 then vf = 1 else vf = 0. Vx = Vx / 2            | 0x 8xy6
  18.         /* 18 */    Instruction("subn"  , 0x8007);  // if Vy > Vx then VF set to 1 else 0, Vx = Vy - Vx                                          | 0x 8xy7
  19.         /* 19 */    Instruction("shl"   , 0x800e);  // If most-significant bit (msb) of Vx is 1 then vf = 1 else vf = 0, Vx = Vx * 2             | 0x 8xyE
  20.         /* 20 */    Instruction("sne"   , 0x9000);  // The values of Vx and Vy are compared, if they are not increment program counter by 2      | 0x 9xy0
  21.         /* 21 */    Instruction("ld"    , 0xa000);  // Register I is set to nnn                                                                  | 0x Annn
  22.         /* 22 */    Instruction("jp"    , 0xb000);  // Jump to location nnn + V0                                                                 | 0x Bnnn
  23.         /* 23 */    Instruction("rnd"   , 0xc000);  // Vx = random byte (0 - ff) AND kk                                                          | 0x Cxkk
  24.         /* 24 */    Instruction("drw"   , 0xd000);  // Display n-byte sprite starting at memory location I at (Vx, Vy), set VF = collision       | 0x Dxyn
  25.                                                     /* @Implementation-notes drw draws using Vx Vy as coordinates. Sprites are XORED onto the existing screen. If anything is erased vf set to 1
  26.                                                             If the sprite would draw outside the display then it wraps around to the opposite side of the screen.
  27.                                                     */
  28.         /* 25 */    Instruction("skp"   , 0xe09e);  // Skip next instruction if key with value Vx is pressed                                     | 0x Ex9E
  29.         /* 26 */    Instruction("skpnp" , 0xe0a1);  // Skip next instruction if key with value Vx is not pressed                                 | 0x Exa1
  30.         /* 27 */    Instruction("ld"    , 0xF007);  // Set Vx = delay timer value                                                                | 0x Fx07
  31.         /* 28 */    Instruction("ld"    , 0xF015);  // Set Dt = value of Vx                                                                      | 0x Fx15
  32.         /* 29 */    Instruction("ld"    , 0xF018);  // Set St = value of Vx                                                                      | 0x Fx18
  33.         /* 30 */    Instruction("add"   , 0xF01e);  // Set I = I + Vx                                                                            | 0x Fx1E
  34.         /* 31 */    Instruction("ld"    , 0xF029);  // Set I = location of sprite for digit Vx                                                   | 0x Fx29
  35.         /* 32 */    Instruction("ld"    , 0xF033);  // Store binary coded decimal(bcd) representation of Vx in mem loc I, I+1, and I+2           | 0x Fx33
  36.                                                     /* @Implementation-notes I stores the hundreds digit, I + 1 stores the tens digit, I+2 stores the ones digit
  37.                                                     */
  38.         /* 33 */    Instruction("ld"    , 0xF055);  // Store registers V0 through Vx in memory starting at location I                            | 0x Fx55
  39.         /* 34 */    Instruction("ld"    , 0xF065);  // Read into Registers V0 through Vx from memory starting at location I                      | 0x Fx65
  40.  
  41.                                                         // @Optional Super Chip-48 Instructions (May not support all of these)
  42.         /* 35 */    Instruction("scd"   , 0x00C0);  // Scroll display N lines down                                                               | 0x 00Cn
  43.         /* 36 */    Instruction("scr"   , 0x00FB);  // Scroll display 4 pixels right
  44.         /* 37 */    Instruction("scl"   , 0x00FC);  // Scroll display 4 pixels left
  45.         /* 38 */    Instruction("exit"  , 0x00FD);  // Leave the chip8 interpreter / Stop running
  46.         /* 39 */    Instruction("low"   , 0x00FE);  // Disable Extended Screen Mode
  47.         /* 40 */    Instruction("high"  , 0x00FF);  // Enable Extended Screen Mode
  48.         /* 41 */    Instruction("ld"    , 0xF030);  // Set I = Location of 10 byte sprite for digit VX (0..9)                                    | 0x Fx30
  49.  
  50. static uint8_t Memory[0xFFF];
  51. // 16 16-bit values used to store the address that the interpreter should return to when finished with a subroutine
  52. // There is a hard limit of 16 levels of nesting on subroutines.
  53. static uint16_t Stack[16];
  54.  
  55.  
  56. struct Registers
  57. {
  58.  
  59.     // 16 general purpose 8 bit Registers, VF should not be used by any program (Used as a flag)
  60.     uint8_t v[16];
  61.  
  62.     // Used to store memory addresses, generally only the lowest 12 bits are used
  63.     uint16_t I = 0;
  64.  
  65.     // Delay Timer is actve when non-zero. Subtracts 1 at the rate of 60Hz
  66.     // Sound Timer is the same as DT. However, it activates the buzzer while it is greater than 0.
  67.     // Output from Sound timer should be a constant single tone.
  68.     uint8_t DT = 0, ST = 0;
  69.  
  70. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement