Commits

spencercw committed dbff38a

Make consistent file names.

  • Participants
  • Parent commits 5462085

Comments (0)

Files changed (41)

gb_emulator/gb_cpu_opcodes.h

+#ifndef GB_CPU_OPCODES_H_B5585700_06F3_11E0_A80E_0002A5D5C51B
+#define GB_CPU_OPCODES_H_B5585700_06F3_11E0_A80E_0002A5D5C51B
+
+/* This file was automatically generated from the opcodes definition file */
+
+#include <stdint.h>
+
+const uint8_t MULTI_BYTE = 0xcb;  /* First byte of multi-byte opcodes */
+
+/* 8-bit loads */
+
+/* ld r,n */
+const uint8_t LD_A_N     = 0x3e;
+const uint8_t LD_B_N     = 0x06;
+const uint8_t LD_C_N     = 0x0e;
+const uint8_t LD_D_N     = 0x16;
+const uint8_t LD_E_N     = 0x1e;
+const uint8_t LD_H_N     = 0x26;
+const uint8_t LD_L_N     = 0x2e;
+
+/* ld r,m */
+const uint8_t LD_A_MBC   = 0x0a;
+const uint8_t LD_A_MHL   = 0x7e;
+const uint8_t LD_A_MDE   = 0x1a;
+const uint8_t LD_A_MNN   = 0xfa;
+
+const uint8_t LD_A_MFFC  = 0xf2;
+const uint8_t LD_A_MFFN  = 0xf0;
+
+const uint8_t LDD_A_MHL  = 0x3a;
+const uint8_t LDI_A_MHL  = 0x2a;
+
+const uint8_t LD_B_MHL   = 0x46;
+const uint8_t LD_C_MHL   = 0x4e;
+const uint8_t LD_D_MHL   = 0x56;
+const uint8_t LD_E_MHL   = 0x5e;
+const uint8_t LD_H_MHL   = 0x66;
+const uint8_t LD_L_MHL   = 0x6e;
+
+/* ld m,r */
+const uint8_t LD_MBC_A   = 0x02;
+const uint8_t LD_MDE_A   = 0x12;
+const uint8_t LD_MHL_A   = 0x77;
+const uint8_t LD_MNN_A   = 0xea;
+const uint8_t LD_MFFC_A  = 0xe2;
+const uint8_t LD_MFFN_A  = 0xe0;
+
+const uint8_t LDD_MHL_A  = 0x32;
+const uint8_t LDI_MHL_A  = 0x22;
+
+const uint8_t LD_MHL_B   = 0x70;
+const uint8_t LD_MHL_C   = 0x71;
+const uint8_t LD_MHL_D   = 0x72;
+const uint8_t LD_MHL_E   = 0x73;
+const uint8_t LD_MHL_H   = 0x74;
+const uint8_t LD_MHL_L   = 0x75;
+
+/* ld m,n */
+const uint8_t LD_MHL_N   = 0x36;
+
+/* ld r1,r2 */
+const uint8_t LD_A_A     = 0x7f;
+const uint8_t LD_A_B     = 0x78;
+const uint8_t LD_A_C     = 0x79;
+const uint8_t LD_A_D     = 0x7a;
+const uint8_t LD_A_E     = 0x7b;
+const uint8_t LD_A_H     = 0x7c;
+const uint8_t LD_A_L     = 0x7d;
+
+const uint8_t LD_B_A     = 0x47;
+const uint8_t LD_B_B     = 0x40;
+const uint8_t LD_B_C     = 0x41;
+const uint8_t LD_B_D     = 0x42;
+const uint8_t LD_B_E     = 0x43;
+const uint8_t LD_B_H     = 0x44;
+const uint8_t LD_B_L     = 0x45;
+
+const uint8_t LD_C_A     = 0x4f;
+const uint8_t LD_C_B     = 0x48;
+const uint8_t LD_C_C     = 0x49;
+const uint8_t LD_C_D     = 0x4a;
+const uint8_t LD_C_E     = 0x4b;
+const uint8_t LD_C_H     = 0x4c;
+const uint8_t LD_C_L     = 0x4d;
+
+const uint8_t LD_D_A     = 0x57;
+const uint8_t LD_D_B     = 0x50;
+const uint8_t LD_D_C     = 0x51;
+const uint8_t LD_D_D     = 0x52;
+const uint8_t LD_D_E     = 0x53;
+const uint8_t LD_D_H     = 0x54;
+const uint8_t LD_D_L     = 0x55;
+
+const uint8_t LD_E_A     = 0x5f;
+const uint8_t LD_E_B     = 0x58;
+const uint8_t LD_E_C     = 0x59;
+const uint8_t LD_E_D     = 0x5a;
+const uint8_t LD_E_E     = 0x5b;
+const uint8_t LD_E_H     = 0x5c;
+const uint8_t LD_E_L     = 0x5d;
+
+const uint8_t LD_H_A     = 0x67;
+const uint8_t LD_H_B     = 0x60;
+const uint8_t LD_H_C     = 0x61;
+const uint8_t LD_H_D     = 0x62;
+const uint8_t LD_H_E     = 0x63;
+const uint8_t LD_H_H     = 0x64;
+const uint8_t LD_H_L     = 0x65;
+
+const uint8_t LD_L_A     = 0x6f;
+const uint8_t LD_L_B     = 0x68;
+const uint8_t LD_L_C     = 0x69;
+const uint8_t LD_L_D     = 0x6a;
+const uint8_t LD_L_E     = 0x6b;
+const uint8_t LD_L_H     = 0x6c;
+const uint8_t LD_L_L     = 0x6d;
+
+/* 16-bit loads */
+
+/* ld r,nn */
+const uint8_t LD_BC_NN   = 0x01;
+const uint8_t LD_DE_NN   = 0x11;
+const uint8_t LD_HL_NN   = 0x21;
+const uint8_t LD_SP_NN   = 0x31;
+
+/* ldhl r,n */
+const uint8_t LDHL_SP_N  = 0xf8;
+
+/* ld r,r */
+const uint8_t LD_SP_HL   = 0xf9;
+
+/* ld m,r */
+const uint8_t LD_MNN_SP  = 0x08;
+
+/* push */
+const uint8_t PUSH_AF    = 0xf5;
+const uint8_t PUSH_BC    = 0xc5;
+const uint8_t PUSH_DE    = 0xd5;
+const uint8_t PUSH_HL    = 0xe5;
+
+/* pop */
+const uint8_t POP_AF     = 0xf1;
+const uint8_t POP_BC     = 0xc1;
+const uint8_t POP_DE     = 0xd1;
+const uint8_t POP_HL     = 0xe1;
+
+/* 8-bit arithmetic */
+
+/* add a,rmn */
+const uint8_t ADD_A_A    = 0x87;
+const uint8_t ADD_A_B    = 0x80;
+const uint8_t ADD_A_C    = 0x81;
+const uint8_t ADD_A_D    = 0x82;
+const uint8_t ADD_A_E    = 0x83;
+const uint8_t ADD_A_H    = 0x84;
+const uint8_t ADD_A_L    = 0x85;
+
+const uint8_t ADD_A_MHL  = 0x86;
+const uint8_t ADD_A_N    = 0xc6;
+
+/* adc a,rmn */
+const uint8_t ADC_A_A    = 0x8f;
+const uint8_t ADC_A_B    = 0x88;
+const uint8_t ADC_A_C    = 0x89;
+const uint8_t ADC_A_D    = 0x8a;
+const uint8_t ADC_A_E    = 0x8b;
+const uint8_t ADC_A_H    = 0x8c;
+const uint8_t ADC_A_L    = 0x8d;
+const uint8_t ADC_A_MHL  = 0x8e;
+const uint8_t ADC_A_N    = 0xce;
+
+/* sub a,rmn */
+const uint8_t SUB_A_A    = 0x97;
+const uint8_t SUB_A_B    = 0x90;
+const uint8_t SUB_A_C    = 0x91;
+const uint8_t SUB_A_D    = 0x92;
+const uint8_t SUB_A_E    = 0x93;
+const uint8_t SUB_A_H    = 0x94;
+const uint8_t SUB_A_L    = 0x95;
+
+const uint8_t SUB_A_MHL  = 0x96;
+const uint8_t SUB_A_N    = 0xd6;
+
+/* sbc a,rmn */
+const uint8_t SBC_A_A    = 0x9f;
+const uint8_t SBC_A_B    = 0x98;
+const uint8_t SBC_A_C    = 0x99;
+const uint8_t SBC_A_D    = 0x9a;
+const uint8_t SBC_A_E    = 0x9b;
+const uint8_t SBC_A_H    = 0x9c;
+const uint8_t SBC_A_L    = 0x9d;
+const uint8_t SBC_A_MHL  = 0x9e;
+const uint8_t SBC_A_N    = 0xde;
+
+/* and a,rmn */
+const uint8_t AND_A_A    = 0xa7;
+
+const uint8_t AND_A_B    = 0xa0;
+const uint8_t AND_A_C    = 0xa1;
+const uint8_t AND_A_D    = 0xa2;
+const uint8_t AND_A_E    = 0xa3;
+const uint8_t AND_A_H    = 0xa4;
+const uint8_t AND_A_L    = 0xa5;
+const uint8_t AND_A_MHL  = 0xa6;
+const uint8_t AND_A_N    = 0xe6;
+
+/* or a,rmn */
+const uint8_t OR_A_A     = 0xb7;
+
+const uint8_t OR_A_B     = 0xb0;
+const uint8_t OR_A_C     = 0xb1;
+const uint8_t OR_A_D     = 0xb2;
+const uint8_t OR_A_E     = 0xb3;
+const uint8_t OR_A_H     = 0xb4;
+const uint8_t OR_A_L     = 0xb5;
+const uint8_t OR_A_MHL   = 0xb6;
+const uint8_t OR_A_N     = 0xf6;
+
+/* xor a,rmn */
+const uint8_t XOR_A_A    = 0xaf;
+
+const uint8_t XOR_A_B    = 0xa8;
+const uint8_t XOR_A_C    = 0xa9;
+const uint8_t XOR_A_D    = 0xaa;
+const uint8_t XOR_A_E    = 0xab;
+const uint8_t XOR_A_H    = 0xac;
+const uint8_t XOR_A_L    = 0xad;
+const uint8_t XOR_A_MHL  = 0xae;
+const uint8_t XOR_A_N    = 0xee;
+
+/* cp a,rmn */
+const uint8_t CP_A_A     = 0xbf;
+const uint8_t CP_A_B     = 0xb8;
+const uint8_t CP_A_C     = 0xb9;
+const uint8_t CP_A_D     = 0xba;
+const uint8_t CP_A_E     = 0xbb;
+const uint8_t CP_A_H     = 0xbc;
+const uint8_t CP_A_L     = 0xbd;
+
+const uint8_t CP_A_MHL   = 0xbe;
+const uint8_t CP_A_N     = 0xfe;
+
+/* inc rm */
+const uint8_t INC_A      = 0x3c;
+const uint8_t INC_B      = 0x04;
+const uint8_t INC_C      = 0x0c;
+const uint8_t INC_D      = 0x14;
+const uint8_t INC_E      = 0x1c;
+const uint8_t INC_H      = 0x24;
+const uint8_t INC_L      = 0x2c;
+const uint8_t INC_MHL    = 0x34;
+
+/* dec rn */
+const uint8_t DEC_A      = 0x3d;
+const uint8_t DEC_B      = 0x05;
+const uint8_t DEC_C      = 0x0d;
+const uint8_t DEC_D      = 0x15;
+const uint8_t DEC_E      = 0x1d;
+const uint8_t DEC_H      = 0x25;
+const uint8_t DEC_L      = 0x2d;
+const uint8_t DEC_MHL    = 0x35;
+
+/* 16-bit arithmetic */
+
+/* add r,rn */
+const uint8_t ADD_HL_BC  = 0x09;
+const uint8_t ADD_HL_DE  = 0x19;
+const uint8_t ADD_HL_HL  = 0x29;
+const uint8_t ADD_HL_SP  = 0x39;
+const uint8_t ADD_SP_N   = 0xe8;
+
+/* inc r */
+const uint8_t INC_BC     = 0x03;
+const uint8_t INC_DE     = 0x13;
+const uint8_t INC_HL     = 0x23;
+const uint8_t INC_SP     = 0x33;
+
+/* dec r */
+const uint8_t DEC_BC     = 0x0b;
+const uint8_t DEC_DE     = 0x1b;
+const uint8_t DEC_HL     = 0x2b;
+const uint8_t DEC_SP     = 0x3b;
+
+/* Miscellaneous */
+
+/* swap rm */
+const uint8_t SWAP_A     = 0x37;
+const uint8_t SWAP_B     = 0x30;
+const uint8_t SWAP_C     = 0x31;
+const uint8_t SWAP_D     = 0x32;
+const uint8_t SWAP_E     = 0x33;
+const uint8_t SWAP_H     = 0x34;
+const uint8_t SWAP_L     = 0x35;
+const uint8_t SWAP_MHL   = 0x36;
+
+const uint8_t DAA        = 0x27;
+const uint8_t CPL        = 0x2f;
+const uint8_t CCF        = 0x3f;
+const uint8_t SCF        = 0x37;
+const uint8_t NOP        = 0x00;
+const uint8_t HALT       = 0x76;
+const uint8_t STOP       = 0x10;
+const uint8_t DI         = 0xf3;
+const uint8_t EI         = 0xfb;
+
+/* Rotates and shifts */
+
+/* rlc rm */
+const uint8_t RLCA       = 0x07;
+const uint8_t RLC_A      = 0x07;
+const uint8_t RLC_B      = 0x00;
+const uint8_t RLC_C      = 0x01;
+const uint8_t RLC_D      = 0x02;
+const uint8_t RLC_E      = 0x03;
+const uint8_t RLC_H      = 0x04;
+const uint8_t RLC_L      = 0x05;
+const uint8_t RLC_MHL    = 0x06;
+
+/* rl rm */
+const uint8_t RLA        = 0x17;
+const uint8_t RL_A       = 0x17;
+const uint8_t RL_B       = 0x10;
+const uint8_t RL_C       = 0x11;
+const uint8_t RL_D       = 0x12;
+const uint8_t RL_E       = 0x13;
+const uint8_t RL_H       = 0x14;
+const uint8_t RL_L       = 0x15;
+const uint8_t RL_MHL     = 0x16;
+
+/* rrc rm */
+const uint8_t RRCA       = 0x0f;
+const uint8_t RRC_A      = 0x0f;
+const uint8_t RRC_B      = 0x08;
+const uint8_t RRC_C      = 0x09;
+const uint8_t RRC_D      = 0x0a;
+const uint8_t RRC_E      = 0x0b;
+const uint8_t RRC_H      = 0x0c;
+const uint8_t RRC_L      = 0x0d;
+const uint8_t RRC_MHL    = 0x0e;
+
+/* rr rm */
+const uint8_t RRA        = 0x1f;
+const uint8_t RR_A       = 0x1f;
+const uint8_t RR_B       = 0x18;
+const uint8_t RR_C       = 0x19;
+const uint8_t RR_D       = 0x1a;
+const uint8_t RR_E       = 0x1b;
+const uint8_t RR_H       = 0x1c;
+const uint8_t RR_L       = 0x1d;
+const uint8_t RR_MHL     = 0x1e;
+
+/* sla rm */
+const uint8_t SLA_A      = 0x27;
+const uint8_t SLA_B      = 0x20;
+const uint8_t SLA_C      = 0x21;
+const uint8_t SLA_D      = 0x22;
+const uint8_t SLA_E      = 0x23;
+const uint8_t SLA_H      = 0x24;
+const uint8_t SLA_L      = 0x25;
+const uint8_t SLA_MHL    = 0x26;
+
+/* sra rm */
+const uint8_t SRA_A      = 0x2f;
+const uint8_t SRA_B      = 0x28;
+const uint8_t SRA_C      = 0x29;
+const uint8_t SRA_D      = 0x2a;
+const uint8_t SRA_E      = 0x2b;
+const uint8_t SRA_H      = 0x2c;
+const uint8_t SRA_L      = 0x2d;
+const uint8_t SRA_MHL    = 0x2e;
+
+/* srl rm */
+const uint8_t SRL_A      = 0x3f;
+const uint8_t SRL_B      = 0x38;
+const uint8_t SRL_C      = 0x39;
+const uint8_t SRL_D      = 0x3a;
+const uint8_t SRL_E      = 0x3b;
+const uint8_t SRL_H      = 0x3c;
+const uint8_t SRL_L      = 0x3d;
+const uint8_t SRL_MHL    = 0x3e;
+
+/* ... */
+
+/* Bit operations */
+
+/* bit b,r */
+const uint8_t BIT_0_A    = 0x47;
+const uint8_t BIT_0_B    = 0x40;
+const uint8_t BIT_0_C    = 0x41;
+const uint8_t BIT_0_D    = 0x42;
+const uint8_t BIT_0_E    = 0x43;
+const uint8_t BIT_0_H    = 0x44;
+const uint8_t BIT_0_L    = 0x45;
+
+const uint8_t BIT_1_A    = 0x4f;
+const uint8_t BIT_1_B    = 0x48;
+const uint8_t BIT_1_C    = 0x49;
+const uint8_t BIT_1_D    = 0x4a;
+const uint8_t BIT_1_E    = 0x4b;
+const uint8_t BIT_1_H    = 0x4c;
+const uint8_t BIT_1_L    = 0x4d;
+
+const uint8_t BIT_2_A    = 0x57;
+const uint8_t BIT_2_B    = 0x50;
+const uint8_t BIT_2_C    = 0x51;
+const uint8_t BIT_2_D    = 0x52;
+const uint8_t BIT_2_E    = 0x53;
+const uint8_t BIT_2_H    = 0x54;
+const uint8_t BIT_2_L    = 0x55;
+
+const uint8_t BIT_3_A    = 0x5f;
+const uint8_t BIT_3_B    = 0x58;
+const uint8_t BIT_3_C    = 0x59;
+const uint8_t BIT_3_D    = 0x5a;
+const uint8_t BIT_3_E    = 0x5b;
+const uint8_t BIT_3_H    = 0x5c;
+const uint8_t BIT_3_L    = 0x5d;
+
+const uint8_t BIT_4_A    = 0x67;
+const uint8_t BIT_4_B    = 0x60;
+const uint8_t BIT_4_C    = 0x61;
+const uint8_t BIT_4_D    = 0x62;
+const uint8_t BIT_4_E    = 0x63;
+const uint8_t BIT_4_H    = 0x64;
+const uint8_t BIT_4_L    = 0x65;
+
+const uint8_t BIT_5_A    = 0x6f;
+const uint8_t BIT_5_B    = 0x68;
+const uint8_t BIT_5_C    = 0x69;
+const uint8_t BIT_5_D    = 0x6a;
+const uint8_t BIT_5_E    = 0x6b;
+const uint8_t BIT_5_H    = 0x6c;
+const uint8_t BIT_5_L    = 0x6d;
+
+const uint8_t BIT_6_A    = 0x77;
+const uint8_t BIT_6_B    = 0x70;
+const uint8_t BIT_6_C    = 0x71;
+const uint8_t BIT_6_D    = 0x72;
+const uint8_t BIT_6_E    = 0x73;
+const uint8_t BIT_6_H    = 0x74;
+const uint8_t BIT_6_L    = 0x75;
+
+const uint8_t BIT_7_A    = 0x7f;
+const uint8_t BIT_7_B    = 0x78;
+const uint8_t BIT_7_C    = 0x79;
+const uint8_t BIT_7_D    = 0x7a;
+const uint8_t BIT_7_E    = 0x7b;
+const uint8_t BIT_7_H    = 0x7c;
+const uint8_t BIT_7_L    = 0x7d;
+
+/* bit b,m */
+const uint8_t BIT_0_MHL  = 0x46;
+const uint8_t BIT_1_MHL  = 0x4e;
+const uint8_t BIT_2_MHL  = 0x56;
+const uint8_t BIT_3_MHL  = 0x5e;
+const uint8_t BIT_4_MHL  = 0x66;
+const uint8_t BIT_5_MHL  = 0x6e;
+const uint8_t BIT_6_MHL  = 0x76;
+const uint8_t BIT_7_MHL  = 0x7e;
+
+/* set b,r */
+const uint8_t SET_0_A    = 0xc7;
+const uint8_t SET_0_B    = 0xc0;
+const uint8_t SET_0_C    = 0xc1;
+const uint8_t SET_0_D    = 0xc2;
+const uint8_t SET_0_E    = 0xc3;
+const uint8_t SET_0_H    = 0xc4;
+const uint8_t SET_0_L    = 0xc5;
+
+const uint8_t SET_1_A    = 0xcf;
+const uint8_t SET_1_B    = 0xc8;
+const uint8_t SET_1_C    = 0xc9;
+const uint8_t SET_1_D    = 0xca;
+const uint8_t SET_1_E    = 0xcb;
+const uint8_t SET_1_H    = 0xcc;
+const uint8_t SET_1_L    = 0xcd;
+
+const uint8_t SET_2_A    = 0xd7;
+const uint8_t SET_2_B    = 0xd0;
+const uint8_t SET_2_C    = 0xd1;
+const uint8_t SET_2_D    = 0xd2;
+const uint8_t SET_2_E    = 0xd3;
+const uint8_t SET_2_H    = 0xd4;
+const uint8_t SET_2_L    = 0xd5;
+
+const uint8_t SET_3_A    = 0xdf;
+const uint8_t SET_3_B    = 0xd8;
+const uint8_t SET_3_C    = 0xd9;
+const uint8_t SET_3_D    = 0xda;
+const uint8_t SET_3_E    = 0xdb;
+const uint8_t SET_3_H    = 0xdc;
+const uint8_t SET_3_L    = 0xdd;
+
+const uint8_t SET_4_A    = 0xe7;
+const uint8_t SET_4_B    = 0xe0;
+const uint8_t SET_4_C    = 0xe1;
+const uint8_t SET_4_D    = 0xe2;
+const uint8_t SET_4_E    = 0xe3;
+const uint8_t SET_4_H    = 0xe4;
+const uint8_t SET_4_L    = 0xe5;
+
+const uint8_t SET_5_A    = 0xef;
+const uint8_t SET_5_B    = 0xe8;
+const uint8_t SET_5_C    = 0xe9;
+const uint8_t SET_5_D    = 0xea;
+const uint8_t SET_5_E    = 0xeb;
+const uint8_t SET_5_H    = 0xec;
+const uint8_t SET_5_L    = 0xed;
+
+const uint8_t SET_6_A    = 0xf7;
+const uint8_t SET_6_B    = 0xf0;
+const uint8_t SET_6_C    = 0xf1;
+const uint8_t SET_6_D    = 0xf2;
+const uint8_t SET_6_E    = 0xf3;
+const uint8_t SET_6_H    = 0xf4;
+const uint8_t SET_6_L    = 0xf5;
+
+const uint8_t SET_7_A    = 0xff;
+const uint8_t SET_7_B    = 0xf8;
+const uint8_t SET_7_C    = 0xf9;
+const uint8_t SET_7_D    = 0xfa;
+const uint8_t SET_7_E    = 0xfb;
+const uint8_t SET_7_H    = 0xfc;
+const uint8_t SET_7_L    = 0xfd;
+
+/* set b,m */
+const uint8_t SET_0_MHL  = 0xc6;
+const uint8_t SET_1_MHL  = 0xce;
+const uint8_t SET_2_MHL  = 0xd6;
+const uint8_t SET_3_MHL  = 0xde;
+const uint8_t SET_4_MHL  = 0xe6;
+const uint8_t SET_5_MHL  = 0xee;
+const uint8_t SET_6_MHL  = 0xf6;
+const uint8_t SET_7_MHL  = 0xfe;
+
+/* res b,r */
+const uint8_t RES_0_A    = 0x87;
+const uint8_t RES_0_B    = 0x80;
+const uint8_t RES_0_C    = 0x81;
+const uint8_t RES_0_D    = 0x82;
+const uint8_t RES_0_E    = 0x83;
+const uint8_t RES_0_H    = 0x84;
+const uint8_t RES_0_L    = 0x85;
+
+const uint8_t RES_1_A    = 0x8f;
+const uint8_t RES_1_B    = 0x88;
+const uint8_t RES_1_C    = 0x89;
+const uint8_t RES_1_D    = 0x8a;
+const uint8_t RES_1_E    = 0x8b;
+const uint8_t RES_1_H    = 0x8c;
+const uint8_t RES_1_L    = 0x8d;
+
+const uint8_t RES_2_A    = 0x97;
+const uint8_t RES_2_B    = 0x90;
+const uint8_t RES_2_C    = 0x91;
+const uint8_t RES_2_D    = 0x92;
+const uint8_t RES_2_E    = 0x93;
+const uint8_t RES_2_H    = 0x94;
+const uint8_t RES_2_L    = 0x95;
+
+const uint8_t RES_3_A    = 0x9f;
+const uint8_t RES_3_B    = 0x98;
+const uint8_t RES_3_C    = 0x99;
+const uint8_t RES_3_D    = 0x9a;
+const uint8_t RES_3_E    = 0x9b;
+const uint8_t RES_3_H    = 0x9c;
+const uint8_t RES_3_L    = 0x9d;
+
+const uint8_t RES_4_A    = 0xa7;
+const uint8_t RES_4_B    = 0xa0;
+const uint8_t RES_4_C    = 0xa1;
+const uint8_t RES_4_D    = 0xa2;
+const uint8_t RES_4_E    = 0xa3;
+const uint8_t RES_4_H    = 0xa4;
+const uint8_t RES_4_L    = 0xa5;
+
+const uint8_t RES_5_A    = 0xaf;
+const uint8_t RES_5_B    = 0xa8;
+const uint8_t RES_5_C    = 0xa9;
+const uint8_t RES_5_D    = 0xaa;
+const uint8_t RES_5_E    = 0xab;
+const uint8_t RES_5_H    = 0xac;
+const uint8_t RES_5_L    = 0xad;
+
+const uint8_t RES_6_A    = 0xb7;
+const uint8_t RES_6_B    = 0xb0;
+const uint8_t RES_6_C    = 0xb1;
+const uint8_t RES_6_D    = 0xb2;
+const uint8_t RES_6_E    = 0xb3;
+const uint8_t RES_6_H    = 0xb4;
+const uint8_t RES_6_L    = 0xb5;
+
+const uint8_t RES_7_A    = 0xbf;
+const uint8_t RES_7_B    = 0xb8;
+const uint8_t RES_7_C    = 0xb9;
+const uint8_t RES_7_D    = 0xba;
+const uint8_t RES_7_E    = 0xbb;
+const uint8_t RES_7_H    = 0xbc;
+const uint8_t RES_7_L    = 0xbd;
+
+/* res b,m */
+const uint8_t RES_0_MHL  = 0x86;
+const uint8_t RES_1_MHL  = 0x8e;
+const uint8_t RES_2_MHL  = 0x96;
+const uint8_t RES_3_MHL  = 0x9e;
+const uint8_t RES_4_MHL  = 0xa6;
+const uint8_t RES_5_MHL  = 0xae;
+const uint8_t RES_6_MHL  = 0xb6;
+const uint8_t RES_7_MHL  = 0xbe;
+
+/* Jumps */
+
+/* jp mnn */
+const uint8_t JP_NN      = 0xc3;
+const uint8_t JP_MHL     = 0xe9;
+
+/* jp c,nn */
+const uint8_t JP_NZ_NN   = 0xc2;
+const uint8_t JP_Z_NN    = 0xca;
+const uint8_t JP_NC_NN   = 0xd2;
+const uint8_t JP_C_NN    = 0xda;
+
+/* jr n */
+const uint8_t JR_N       = 0x18;
+
+/* jr c,n */
+const uint8_t JR_NZ_N    = 0x20;
+const uint8_t JR_Z_N     = 0x28;
+const uint8_t JR_NC_N    = 0x30;
+const uint8_t JR_C_N     = 0x38;
+
+/* Calls */
+
+/* call nn */
+const uint8_t CALL_NN    = 0xcd;
+
+/* call c,nn */
+const uint8_t CALL_NZ_NN = 0xc4;
+const uint8_t CALL_Z_NN  = 0xcc;
+const uint8_t CALL_NC_NN = 0xd4;
+const uint8_t CALL_C_NN  = 0xdc;
+
+/* Restarts */
+const uint8_t RST_00     = 0xc7;
+const uint8_t RST_08     = 0xcf;
+const uint8_t RST_10     = 0xd7;
+const uint8_t RST_18     = 0xdf;
+const uint8_t RST_20     = 0xe7;
+const uint8_t RST_28     = 0xef;
+const uint8_t RST_30     = 0xf7;
+const uint8_t RST_38     = 0xff;
+
+/* Returns */
+
+/* ret */
+const uint8_t RET        = 0xc9;
+
+/* ret c */
+const uint8_t RET_NZ     = 0xc0;
+const uint8_t RET_Z      = 0xc8;
+const uint8_t RET_NC     = 0xd0;
+const uint8_t RET_C      = 0xd8;
+
+/* reti */
+const uint8_t RETI       = 0xd9;
+
+#endif

gb_emulator/gb_cpu_opcodes.hpp

-#ifndef GB_CPU_OPCODES_HPP_B5585700_06F3_11E0_A80E_0002A5D5C51B
-#define GB_CPU_OPCODES_HPP_B5585700_06F3_11E0_A80E_0002A5D5C51B
-
-/* This file was automatically generated from the opcodes definition file */
-
-#include <stdint.h>
-
-const uint8_t MULTI_BYTE = 0xcb;  /* First byte of multi-byte opcodes */
-
-/* 8-bit loads */
-
-/* ld r,n */
-const uint8_t LD_A_N     = 0x3e;
-const uint8_t LD_B_N     = 0x06;
-const uint8_t LD_C_N     = 0x0e;
-const uint8_t LD_D_N     = 0x16;
-const uint8_t LD_E_N     = 0x1e;
-const uint8_t LD_H_N     = 0x26;
-const uint8_t LD_L_N     = 0x2e;
-
-/* ld r,m */
-const uint8_t LD_A_MBC   = 0x0a;
-const uint8_t LD_A_MHL   = 0x7e;
-const uint8_t LD_A_MDE   = 0x1a;
-const uint8_t LD_A_MNN   = 0xfa;
-
-const uint8_t LD_A_MFFC  = 0xf2;
-const uint8_t LD_A_MFFN  = 0xf0;
-
-const uint8_t LDD_A_MHL  = 0x3a;
-const uint8_t LDI_A_MHL  = 0x2a;
-
-const uint8_t LD_B_MHL   = 0x46;
-const uint8_t LD_C_MHL   = 0x4e;
-const uint8_t LD_D_MHL   = 0x56;
-const uint8_t LD_E_MHL   = 0x5e;
-const uint8_t LD_H_MHL   = 0x66;
-const uint8_t LD_L_MHL   = 0x6e;
-
-/* ld m,r */
-const uint8_t LD_MBC_A   = 0x02;
-const uint8_t LD_MDE_A   = 0x12;
-const uint8_t LD_MHL_A   = 0x77;
-const uint8_t LD_MNN_A   = 0xea;
-const uint8_t LD_MFFC_A  = 0xe2;
-const uint8_t LD_MFFN_A  = 0xe0;
-
-const uint8_t LDD_MHL_A  = 0x32;
-const uint8_t LDI_MHL_A  = 0x22;
-
-const uint8_t LD_MHL_B   = 0x70;
-const uint8_t LD_MHL_C   = 0x71;
-const uint8_t LD_MHL_D   = 0x72;
-const uint8_t LD_MHL_E   = 0x73;
-const uint8_t LD_MHL_H   = 0x74;
-const uint8_t LD_MHL_L   = 0x75;
-
-/* ld m,n */
-const uint8_t LD_MHL_N   = 0x36;
-
-/* ld r1,r2 */
-const uint8_t LD_A_A     = 0x7f;
-const uint8_t LD_A_B     = 0x78;
-const uint8_t LD_A_C     = 0x79;
-const uint8_t LD_A_D     = 0x7a;
-const uint8_t LD_A_E     = 0x7b;
-const uint8_t LD_A_H     = 0x7c;
-const uint8_t LD_A_L     = 0x7d;
-
-const uint8_t LD_B_A     = 0x47;
-const uint8_t LD_B_B     = 0x40;
-const uint8_t LD_B_C     = 0x41;
-const uint8_t LD_B_D     = 0x42;
-const uint8_t LD_B_E     = 0x43;
-const uint8_t LD_B_H     = 0x44;
-const uint8_t LD_B_L     = 0x45;
-
-const uint8_t LD_C_A     = 0x4f;
-const uint8_t LD_C_B     = 0x48;
-const uint8_t LD_C_C     = 0x49;
-const uint8_t LD_C_D     = 0x4a;
-const uint8_t LD_C_E     = 0x4b;
-const uint8_t LD_C_H     = 0x4c;
-const uint8_t LD_C_L     = 0x4d;
-
-const uint8_t LD_D_A     = 0x57;
-const uint8_t LD_D_B     = 0x50;
-const uint8_t LD_D_C     = 0x51;
-const uint8_t LD_D_D     = 0x52;
-const uint8_t LD_D_E     = 0x53;
-const uint8_t LD_D_H     = 0x54;
-const uint8_t LD_D_L     = 0x55;
-
-const uint8_t LD_E_A     = 0x5f;
-const uint8_t LD_E_B     = 0x58;
-const uint8_t LD_E_C     = 0x59;
-const uint8_t LD_E_D     = 0x5a;
-const uint8_t LD_E_E     = 0x5b;
-const uint8_t LD_E_H     = 0x5c;
-const uint8_t LD_E_L     = 0x5d;
-
-const uint8_t LD_H_A     = 0x67;
-const uint8_t LD_H_B     = 0x60;
-const uint8_t LD_H_C     = 0x61;
-const uint8_t LD_H_D     = 0x62;
-const uint8_t LD_H_E     = 0x63;
-const uint8_t LD_H_H     = 0x64;
-const uint8_t LD_H_L     = 0x65;
-
-const uint8_t LD_L_A     = 0x6f;
-const uint8_t LD_L_B     = 0x68;
-const uint8_t LD_L_C     = 0x69;
-const uint8_t LD_L_D     = 0x6a;
-const uint8_t LD_L_E     = 0x6b;
-const uint8_t LD_L_H     = 0x6c;
-const uint8_t LD_L_L     = 0x6d;
-
-/* 16-bit loads */
-
-/* ld r,nn */
-const uint8_t LD_BC_NN   = 0x01;
-const uint8_t LD_DE_NN   = 0x11;
-const uint8_t LD_HL_NN   = 0x21;
-const uint8_t LD_SP_NN   = 0x31;
-
-/* ldhl r,n */
-const uint8_t LDHL_SP_N  = 0xf8;
-
-/* ld r,r */
-const uint8_t LD_SP_HL   = 0xf9;
-
-/* ld m,r */
-const uint8_t LD_MNN_SP  = 0x08;
-
-/* push */
-const uint8_t PUSH_AF    = 0xf5;
-const uint8_t PUSH_BC    = 0xc5;
-const uint8_t PUSH_DE    = 0xd5;
-const uint8_t PUSH_HL    = 0xe5;
-
-/* pop */
-const uint8_t POP_AF     = 0xf1;
-const uint8_t POP_BC     = 0xc1;
-const uint8_t POP_DE     = 0xd1;
-const uint8_t POP_HL     = 0xe1;
-
-/* 8-bit arithmetic */
-
-/* add a,rmn */
-const uint8_t ADD_A_A    = 0x87;
-const uint8_t ADD_A_B    = 0x80;
-const uint8_t ADD_A_C    = 0x81;
-const uint8_t ADD_A_D    = 0x82;
-const uint8_t ADD_A_E    = 0x83;
-const uint8_t ADD_A_H    = 0x84;
-const uint8_t ADD_A_L    = 0x85;
-
-const uint8_t ADD_A_MHL  = 0x86;
-const uint8_t ADD_A_N    = 0xc6;
-
-/* adc a,rmn */
-const uint8_t ADC_A_A    = 0x8f;
-const uint8_t ADC_A_B    = 0x88;
-const uint8_t ADC_A_C    = 0x89;
-const uint8_t ADC_A_D    = 0x8a;
-const uint8_t ADC_A_E    = 0x8b;
-const uint8_t ADC_A_H    = 0x8c;
-const uint8_t ADC_A_L    = 0x8d;
-const uint8_t ADC_A_MHL  = 0x8e;
-const uint8_t ADC_A_N    = 0xce;
-
-/* sub a,rmn */
-const uint8_t SUB_A_A    = 0x97;
-const uint8_t SUB_A_B    = 0x90;
-const uint8_t SUB_A_C    = 0x91;
-const uint8_t SUB_A_D    = 0x92;
-const uint8_t SUB_A_E    = 0x93;
-const uint8_t SUB_A_H    = 0x94;
-const uint8_t SUB_A_L    = 0x95;
-
-const uint8_t SUB_A_MHL  = 0x96;
-const uint8_t SUB_A_N    = 0xd6;
-
-/* sbc a,rmn */
-const uint8_t SBC_A_A    = 0x9f;
-const uint8_t SBC_A_B    = 0x98;
-const uint8_t SBC_A_C    = 0x99;
-const uint8_t SBC_A_D    = 0x9a;
-const uint8_t SBC_A_E    = 0x9b;
-const uint8_t SBC_A_H    = 0x9c;
-const uint8_t SBC_A_L    = 0x9d;
-const uint8_t SBC_A_MHL  = 0x9e;
-const uint8_t SBC_A_N    = 0xde;
-
-/* and a,rmn */
-const uint8_t AND_A_A    = 0xa7;
-
-const uint8_t AND_A_B    = 0xa0;
-const uint8_t AND_A_C    = 0xa1;
-const uint8_t AND_A_D    = 0xa2;
-const uint8_t AND_A_E    = 0xa3;
-const uint8_t AND_A_H    = 0xa4;
-const uint8_t AND_A_L    = 0xa5;
-const uint8_t AND_A_MHL  = 0xa6;
-const uint8_t AND_A_N    = 0xe6;
-
-/* or a,rmn */
-const uint8_t OR_A_A     = 0xb7;
-
-const uint8_t OR_A_B     = 0xb0;
-const uint8_t OR_A_C     = 0xb1;
-const uint8_t OR_A_D     = 0xb2;
-const uint8_t OR_A_E     = 0xb3;
-const uint8_t OR_A_H     = 0xb4;
-const uint8_t OR_A_L     = 0xb5;
-const uint8_t OR_A_MHL   = 0xb6;
-const uint8_t OR_A_N     = 0xf6;
-
-/* xor a,rmn */
-const uint8_t XOR_A_A    = 0xaf;
-
-const uint8_t XOR_A_B    = 0xa8;
-const uint8_t XOR_A_C    = 0xa9;
-const uint8_t XOR_A_D    = 0xaa;
-const uint8_t XOR_A_E    = 0xab;
-const uint8_t XOR_A_H    = 0xac;
-const uint8_t XOR_A_L    = 0xad;
-const uint8_t XOR_A_MHL  = 0xae;
-const uint8_t XOR_A_N    = 0xee;
-
-/* cp a,rmn */
-const uint8_t CP_A_A     = 0xbf;
-const uint8_t CP_A_B     = 0xb8;
-const uint8_t CP_A_C     = 0xb9;
-const uint8_t CP_A_D     = 0xba;
-const uint8_t CP_A_E     = 0xbb;
-const uint8_t CP_A_H     = 0xbc;
-const uint8_t CP_A_L     = 0xbd;
-
-const uint8_t CP_A_MHL   = 0xbe;
-const uint8_t CP_A_N     = 0xfe;
-
-/* inc rm */
-const uint8_t INC_A      = 0x3c;
-const uint8_t INC_B      = 0x04;
-const uint8_t INC_C      = 0x0c;
-const uint8_t INC_D      = 0x14;
-const uint8_t INC_E      = 0x1c;
-const uint8_t INC_H      = 0x24;
-const uint8_t INC_L      = 0x2c;
-const uint8_t INC_MHL    = 0x34;
-
-/* dec rn */
-const uint8_t DEC_A      = 0x3d;
-const uint8_t DEC_B      = 0x05;
-const uint8_t DEC_C      = 0x0d;
-const uint8_t DEC_D      = 0x15;
-const uint8_t DEC_E      = 0x1d;
-const uint8_t DEC_H      = 0x25;
-const uint8_t DEC_L      = 0x2d;
-const uint8_t DEC_MHL    = 0x35;
-
-/* 16-bit arithmetic */
-
-/* add r,rn */
-const uint8_t ADD_HL_BC  = 0x09;
-const uint8_t ADD_HL_DE  = 0x19;
-const uint8_t ADD_HL_HL  = 0x29;
-const uint8_t ADD_HL_SP  = 0x39;
-const uint8_t ADD_SP_N   = 0xe8;
-
-/* inc r */
-const uint8_t INC_BC     = 0x03;
-const uint8_t INC_DE     = 0x13;
-const uint8_t INC_HL     = 0x23;
-const uint8_t INC_SP     = 0x33;
-
-/* dec r */
-const uint8_t DEC_BC     = 0x0b;
-const uint8_t DEC_DE     = 0x1b;
-const uint8_t DEC_HL     = 0x2b;
-const uint8_t DEC_SP     = 0x3b;
-
-/* Miscellaneous */
-
-/* swap rm */
-const uint8_t SWAP_A     = 0x37;
-const uint8_t SWAP_B     = 0x30;
-const uint8_t SWAP_C     = 0x31;
-const uint8_t SWAP_D     = 0x32;
-const uint8_t SWAP_E     = 0x33;
-const uint8_t SWAP_H     = 0x34;
-const uint8_t SWAP_L     = 0x35;
-const uint8_t SWAP_MHL   = 0x36;
-
-const uint8_t DAA        = 0x27;
-const uint8_t CPL        = 0x2f;
-const uint8_t CCF        = 0x3f;
-const uint8_t SCF        = 0x37;
-const uint8_t NOP        = 0x00;
-const uint8_t HALT       = 0x76;
-const uint8_t STOP       = 0x10;
-const uint8_t DI         = 0xf3;
-const uint8_t EI         = 0xfb;
-
-/* Rotates and shifts */
-
-/* rlc rm */
-const uint8_t RLCA       = 0x07;
-const uint8_t RLC_A      = 0x07;
-const uint8_t RLC_B      = 0x00;
-const uint8_t RLC_C      = 0x01;
-const uint8_t RLC_D      = 0x02;
-const uint8_t RLC_E      = 0x03;
-const uint8_t RLC_H      = 0x04;
-const uint8_t RLC_L      = 0x05;
-const uint8_t RLC_MHL    = 0x06;
-
-/* rl rm */
-const uint8_t RLA        = 0x17;
-const uint8_t RL_A       = 0x17;
-const uint8_t RL_B       = 0x10;
-const uint8_t RL_C       = 0x11;
-const uint8_t RL_D       = 0x12;
-const uint8_t RL_E       = 0x13;
-const uint8_t RL_H       = 0x14;
-const uint8_t RL_L       = 0x15;
-const uint8_t RL_MHL     = 0x16;
-
-/* rrc rm */
-const uint8_t RRCA       = 0x0f;
-const uint8_t RRC_A      = 0x0f;
-const uint8_t RRC_B      = 0x08;
-const uint8_t RRC_C      = 0x09;
-const uint8_t RRC_D      = 0x0a;
-const uint8_t RRC_E      = 0x0b;
-const uint8_t RRC_H      = 0x0c;
-const uint8_t RRC_L      = 0x0d;
-const uint8_t RRC_MHL    = 0x0e;
-
-/* rr rm */
-const uint8_t RRA        = 0x1f;
-const uint8_t RR_A       = 0x1f;
-const uint8_t RR_B       = 0x18;
-const uint8_t RR_C       = 0x19;
-const uint8_t RR_D       = 0x1a;
-const uint8_t RR_E       = 0x1b;
-const uint8_t RR_H       = 0x1c;
-const uint8_t RR_L       = 0x1d;
-const uint8_t RR_MHL     = 0x1e;
-
-/* sla rm */
-const uint8_t SLA_A      = 0x27;
-const uint8_t SLA_B      = 0x20;
-const uint8_t SLA_C      = 0x21;
-const uint8_t SLA_D      = 0x22;
-const uint8_t SLA_E      = 0x23;
-const uint8_t SLA_H      = 0x24;
-const uint8_t SLA_L      = 0x25;
-const uint8_t SLA_MHL    = 0x26;
-
-/* sra rm */
-const uint8_t SRA_A      = 0x2f;
-const uint8_t SRA_B      = 0x28;
-const uint8_t SRA_C      = 0x29;
-const uint8_t SRA_D      = 0x2a;
-const uint8_t SRA_E      = 0x2b;
-const uint8_t SRA_H      = 0x2c;
-const uint8_t SRA_L      = 0x2d;
-const uint8_t SRA_MHL    = 0x2e;
-
-/* srl rm */
-const uint8_t SRL_A      = 0x3f;
-const uint8_t SRL_B      = 0x38;
-const uint8_t SRL_C      = 0x39;
-const uint8_t SRL_D      = 0x3a;
-const uint8_t SRL_E      = 0x3b;
-const uint8_t SRL_H      = 0x3c;
-const uint8_t SRL_L      = 0x3d;
-const uint8_t SRL_MHL    = 0x3e;
-
-/* ... */
-
-/* Bit operations */
-
-/* bit b,r */
-const uint8_t BIT_0_A    = 0x47;
-const uint8_t BIT_0_B    = 0x40;
-const uint8_t BIT_0_C    = 0x41;
-const uint8_t BIT_0_D    = 0x42;
-const uint8_t BIT_0_E    = 0x43;
-const uint8_t BIT_0_H    = 0x44;
-const uint8_t BIT_0_L    = 0x45;
-
-const uint8_t BIT_1_A    = 0x4f;
-const uint8_t BIT_1_B    = 0x48;
-const uint8_t BIT_1_C    = 0x49;
-const uint8_t BIT_1_D    = 0x4a;
-const uint8_t BIT_1_E    = 0x4b;
-const uint8_t BIT_1_H    = 0x4c;
-const uint8_t BIT_1_L    = 0x4d;
-
-const uint8_t BIT_2_A    = 0x57;
-const uint8_t BIT_2_B    = 0x50;
-const uint8_t BIT_2_C    = 0x51;
-const uint8_t BIT_2_D    = 0x52;
-const uint8_t BIT_2_E    = 0x53;
-const uint8_t BIT_2_H    = 0x54;
-const uint8_t BIT_2_L    = 0x55;
-
-const uint8_t BIT_3_A    = 0x5f;
-const uint8_t BIT_3_B    = 0x58;
-const uint8_t BIT_3_C    = 0x59;
-const uint8_t BIT_3_D    = 0x5a;
-const uint8_t BIT_3_E    = 0x5b;
-const uint8_t BIT_3_H    = 0x5c;
-const uint8_t BIT_3_L    = 0x5d;
-
-const uint8_t BIT_4_A    = 0x67;
-const uint8_t BIT_4_B    = 0x60;
-const uint8_t BIT_4_C    = 0x61;
-const uint8_t BIT_4_D    = 0x62;
-const uint8_t BIT_4_E    = 0x63;
-const uint8_t BIT_4_H    = 0x64;
-const uint8_t BIT_4_L    = 0x65;
-
-const uint8_t BIT_5_A    = 0x6f;
-const uint8_t BIT_5_B    = 0x68;
-const uint8_t BIT_5_C    = 0x69;
-const uint8_t BIT_5_D    = 0x6a;
-const uint8_t BIT_5_E    = 0x6b;
-const uint8_t BIT_5_H    = 0x6c;
-const uint8_t BIT_5_L    = 0x6d;
-
-const uint8_t BIT_6_A    = 0x77;
-const uint8_t BIT_6_B    = 0x70;
-const uint8_t BIT_6_C    = 0x71;
-const uint8_t BIT_6_D    = 0x72;
-const uint8_t BIT_6_E    = 0x73;
-const uint8_t BIT_6_H    = 0x74;
-const uint8_t BIT_6_L    = 0x75;
-
-const uint8_t BIT_7_A    = 0x7f;
-const uint8_t BIT_7_B    = 0x78;
-const uint8_t BIT_7_C    = 0x79;
-const uint8_t BIT_7_D    = 0x7a;
-const uint8_t BIT_7_E    = 0x7b;
-const uint8_t BIT_7_H    = 0x7c;
-const uint8_t BIT_7_L    = 0x7d;
-
-/* bit b,m */
-const uint8_t BIT_0_MHL  = 0x46;
-const uint8_t BIT_1_MHL  = 0x4e;
-const uint8_t BIT_2_MHL  = 0x56;
-const uint8_t BIT_3_MHL  = 0x5e;
-const uint8_t BIT_4_MHL  = 0x66;
-const uint8_t BIT_5_MHL  = 0x6e;
-const uint8_t BIT_6_MHL  = 0x76;
-const uint8_t BIT_7_MHL  = 0x7e;
-
-/* set b,r */
-const uint8_t SET_0_A    = 0xc7;
-const uint8_t SET_0_B    = 0xc0;
-const uint8_t SET_0_C    = 0xc1;
-const uint8_t SET_0_D    = 0xc2;
-const uint8_t SET_0_E    = 0xc3;
-const uint8_t SET_0_H    = 0xc4;
-const uint8_t SET_0_L    = 0xc5;
-
-const uint8_t SET_1_A    = 0xcf;
-const uint8_t SET_1_B    = 0xc8;
-const uint8_t SET_1_C    = 0xc9;
-const uint8_t SET_1_D    = 0xca;
-const uint8_t SET_1_E    = 0xcb;
-const uint8_t SET_1_H    = 0xcc;
-const uint8_t SET_1_L    = 0xcd;
-
-const uint8_t SET_2_A    = 0xd7;
-const uint8_t SET_2_B    = 0xd0;
-const uint8_t SET_2_C    = 0xd1;
-const uint8_t SET_2_D    = 0xd2;
-const uint8_t SET_2_E    = 0xd3;
-const uint8_t SET_2_H    = 0xd4;
-const uint8_t SET_2_L    = 0xd5;
-
-const uint8_t SET_3_A    = 0xdf;
-const uint8_t SET_3_B    = 0xd8;
-const uint8_t SET_3_C    = 0xd9;
-const uint8_t SET_3_D    = 0xda;
-const uint8_t SET_3_E    = 0xdb;
-const uint8_t SET_3_H    = 0xdc;
-const uint8_t SET_3_L    = 0xdd;
-
-const uint8_t SET_4_A    = 0xe7;
-const uint8_t SET_4_B    = 0xe0;
-const uint8_t SET_4_C    = 0xe1;
-const uint8_t SET_4_D    = 0xe2;
-const uint8_t SET_4_E    = 0xe3;
-const uint8_t SET_4_H    = 0xe4;
-const uint8_t SET_4_L    = 0xe5;
-
-const uint8_t SET_5_A    = 0xef;
-const uint8_t SET_5_B    = 0xe8;
-const uint8_t SET_5_C    = 0xe9;
-const uint8_t SET_5_D    = 0xea;
-const uint8_t SET_5_E    = 0xeb;
-const uint8_t SET_5_H    = 0xec;
-const uint8_t SET_5_L    = 0xed;
-
-const uint8_t SET_6_A    = 0xf7;
-const uint8_t SET_6_B    = 0xf0;
-const uint8_t SET_6_C    = 0xf1;
-const uint8_t SET_6_D    = 0xf2;
-const uint8_t SET_6_E    = 0xf3;
-const uint8_t SET_6_H    = 0xf4;
-const uint8_t SET_6_L    = 0xf5;
-
-const uint8_t SET_7_A    = 0xff;
-const uint8_t SET_7_B    = 0xf8;
-const uint8_t SET_7_C    = 0xf9;
-const uint8_t SET_7_D    = 0xfa;
-const uint8_t SET_7_E    = 0xfb;
-const uint8_t SET_7_H    = 0xfc;
-const uint8_t SET_7_L    = 0xfd;
-
-/* set b,m */
-const uint8_t SET_0_MHL  = 0xc6;
-const uint8_t SET_1_MHL  = 0xce;
-const uint8_t SET_2_MHL  = 0xd6;
-const uint8_t SET_3_MHL  = 0xde;
-const uint8_t SET_4_MHL  = 0xe6;
-const uint8_t SET_5_MHL  = 0xee;
-const uint8_t SET_6_MHL  = 0xf6;
-const uint8_t SET_7_MHL  = 0xfe;
-
-/* res b,r */
-const uint8_t RES_0_A    = 0x87;
-const uint8_t RES_0_B    = 0x80;
-const uint8_t RES_0_C    = 0x81;
-const uint8_t RES_0_D    = 0x82;
-const uint8_t RES_0_E    = 0x83;
-const uint8_t RES_0_H    = 0x84;
-const uint8_t RES_0_L    = 0x85;
-
-const uint8_t RES_1_A    = 0x8f;
-const uint8_t RES_1_B    = 0x88;
-const uint8_t RES_1_C    = 0x89;
-const uint8_t RES_1_D    = 0x8a;
-const uint8_t RES_1_E    = 0x8b;
-const uint8_t RES_1_H    = 0x8c;
-const uint8_t RES_1_L    = 0x8d;
-
-const uint8_t RES_2_A    = 0x97;
-const uint8_t RES_2_B    = 0x90;
-const uint8_t RES_2_C    = 0x91;
-const uint8_t RES_2_D    = 0x92;
-const uint8_t RES_2_E    = 0x93;
-const uint8_t RES_2_H    = 0x94;
-const uint8_t RES_2_L    = 0x95;
-
-const uint8_t RES_3_A    = 0x9f;
-const uint8_t RES_3_B    = 0x98;
-const uint8_t RES_3_C    = 0x99;
-const uint8_t RES_3_D    = 0x9a;
-const uint8_t RES_3_E    = 0x9b;
-const uint8_t RES_3_H    = 0x9c;
-const uint8_t RES_3_L    = 0x9d;
-
-const uint8_t RES_4_A    = 0xa7;
-const uint8_t RES_4_B    = 0xa0;
-const uint8_t RES_4_C    = 0xa1;
-const uint8_t RES_4_D    = 0xa2;
-const uint8_t RES_4_E    = 0xa3;
-const uint8_t RES_4_H    = 0xa4;
-const uint8_t RES_4_L    = 0xa5;
-
-const uint8_t RES_5_A    = 0xaf;
-const uint8_t RES_5_B    = 0xa8;
-const uint8_t RES_5_C    = 0xa9;
-const uint8_t RES_5_D    = 0xaa;
-const uint8_t RES_5_E    = 0xab;
-const uint8_t RES_5_H    = 0xac;
-const uint8_t RES_5_L    = 0xad;
-
-const uint8_t RES_6_A    = 0xb7;
-const uint8_t RES_6_B    = 0xb0;
-const uint8_t RES_6_C    = 0xb1;
-const uint8_t RES_6_D    = 0xb2;
-const uint8_t RES_6_E    = 0xb3;
-const uint8_t RES_6_H    = 0xb4;
-const uint8_t RES_6_L    = 0xb5;
-
-const uint8_t RES_7_A    = 0xbf;
-const uint8_t RES_7_B    = 0xb8;
-const uint8_t RES_7_C    = 0xb9;
-const uint8_t RES_7_D    = 0xba;
-const uint8_t RES_7_E    = 0xbb;
-const uint8_t RES_7_H    = 0xbc;
-const uint8_t RES_7_L    = 0xbd;
-
-/* res b,m */
-const uint8_t RES_0_MHL  = 0x86;
-const uint8_t RES_1_MHL  = 0x8e;
-const uint8_t RES_2_MHL  = 0x96;
-const uint8_t RES_3_MHL  = 0x9e;
-const uint8_t RES_4_MHL  = 0xa6;
-const uint8_t RES_5_MHL  = 0xae;
-const uint8_t RES_6_MHL  = 0xb6;
-const uint8_t RES_7_MHL  = 0xbe;
-
-/* Jumps */
-
-/* jp mnn */
-const uint8_t JP_NN      = 0xc3;
-const uint8_t JP_MHL     = 0xe9;
-
-/* jp c,nn */
-const uint8_t JP_NZ_NN   = 0xc2;
-const uint8_t JP_Z_NN    = 0xca;
-const uint8_t JP_NC_NN   = 0xd2;
-const uint8_t JP_C_NN    = 0xda;
-
-/* jr n */
-const uint8_t JR_N       = 0x18;
-
-/* jr c,n */
-const uint8_t JR_NZ_N    = 0x20;
-const uint8_t JR_Z_N     = 0x28;
-const uint8_t JR_NC_N    = 0x30;
-const uint8_t JR_C_N     = 0x38;
-
-/* Calls */
-
-/* call nn */
-const uint8_t CALL_NN    = 0xcd;
-
-/* call c,nn */
-const uint8_t CALL_NZ_NN = 0xc4;
-const uint8_t CALL_Z_NN  = 0xcc;
-const uint8_t CALL_NC_NN = 0xd4;
-const uint8_t CALL_C_NN  = 0xdc;
-
-/* Restarts */
-const uint8_t RST_00     = 0xc7;
-const uint8_t RST_08     = 0xcf;
-const uint8_t RST_10     = 0xd7;
-const uint8_t RST_18     = 0xdf;
-const uint8_t RST_20     = 0xe7;
-const uint8_t RST_28     = 0xef;
-const uint8_t RST_30     = 0xf7;
-const uint8_t RST_38     = 0xff;
-
-/* Returns */
-
-/* ret */
-const uint8_t RET        = 0xc9;
-
-/* ret c */
-const uint8_t RET_NZ     = 0xc0;
-const uint8_t RET_Z      = 0xc8;
-const uint8_t RET_NC     = 0xd0;
-const uint8_t RET_C      = 0xd8;
-
-/* reti */
-const uint8_t RETI       = 0xd9;
-
-#endif

gb_emulator/gb_emulator.vcxproj

   </ItemDefinitionGroup>
   <ItemGroup>
     <ClInclude Include="gb.pb.h" />
-    <ClInclude Include="gb_cpu_opcodes.hpp" />
+    <ClInclude Include="gb_cpu_opcodes.h" />
     <ClInclude Include="include\gb_emulator\cdb_file.h" />
-    <ClInclude Include="include\gb_emulator\constants.hpp" />
-    <ClInclude Include="include\gb_emulator\defs.hpp" />
-    <ClInclude Include="include\gb_emulator\gb.hpp" />
+    <ClInclude Include="include\gb_emulator\constants.h" />
+    <ClInclude Include="include\gb_emulator\defs.h" />
+    <ClInclude Include="include\gb_emulator\gb.h" />
     <ClInclude Include="include\gb_emulator\gb_comms_serial.h" />
     <ClInclude Include="include\gb_emulator\gb_config.h" />
-    <ClInclude Include="include\gb_emulator\gb_cpu.hpp" />
+    <ClInclude Include="include\gb_emulator\gb_cpu.h" />
     <ClInclude Include="include\gb_emulator\gb_debugger.h" />
     <ClInclude Include="include\gb_emulator\gb_debugger_module.h" />
     <ClInclude Include="include\gb_emulator\gb_disassembler.h" />
-    <ClInclude Include="include\gb_emulator\gb_input.hpp" />
-    <ClInclude Include="include\gb_emulator\gb_memory.hpp" />
-    <ClInclude Include="include\gb_emulator\gb_sound.hpp" />
+    <ClInclude Include="include\gb_emulator\gb_input.h" />
+    <ClInclude Include="include\gb_emulator\gb_memory.h" />
+    <ClInclude Include="include\gb_emulator\gb_sound.h" />
     <ClInclude Include="include\gb_emulator\gb_sound_sdl.h" />
     <ClInclude Include="include\gb_emulator\gb_sound_wasapi.h" />
     <ClInclude Include="include\gb_emulator\gb_sound_wasapi_renderer.h" />
-    <ClInclude Include="include\gb_emulator\gb_timers.hpp" />
-    <ClInclude Include="include\gb_emulator\gb_video.hpp" />
+    <ClInclude Include="include\gb_emulator\gb_timers.h" />
+    <ClInclude Include="include\gb_emulator\gb_video.h" />
     <ClInclude Include="include\gb_emulator\gb_video_d3d11.h" />
     <ClInclude Include="include\gb_emulator\gb_video_sdl.h" />
     <ClInclude Include="src\gb_sound_tables.h" />
       <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">python gen_ops.py</Command>
       <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Generating opcodes...</Message>
       <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Generating opcodes...</Message>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">gb_cpu_opcodes.hpp;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">gb_cpu_opcodes.hpp;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">gb_cpu_opcodes.h;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">gb_cpu_opcodes.h;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
       <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">python gen_ops.py</Command>
       <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">python gen_ops.py</Command>
       <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Generating opcodes...</Message>
       <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Generating opcodes...</Message>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">gb_cpu_opcodes.hpp;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
-      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">gb_cpu_opcodes.hpp;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">gb_cpu_opcodes.h;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
+      <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">gb_cpu_opcodes.h;gb_cpu_opcodes.cpp.inc;%(Outputs)</Outputs>
     </CustomBuild>
     <None Include="gb_cpu_opcodes.cpp.inc" />
     <None Include="gb_disassembler_opcodes.cpp.inc" />

gb_emulator/gb_emulator.vcxproj.filters

     <ClInclude Include="gb.pb.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\constants.hpp">
+    <ClInclude Include="include\gb_emulator\constants.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\gb.hpp">
+    <ClInclude Include="include\gb_emulator\gb.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\gb_cpu.hpp">
+    <ClInclude Include="include\gb_emulator\gb_cpu.h">
       <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="include\gb_emulator\gb_debugger.h">
     <ClInclude Include="include\gb_emulator\gb_debugger_module.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\gb_input.hpp">
+    <ClInclude Include="include\gb_emulator\gb_input.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\gb_memory.hpp">
+    <ClInclude Include="include\gb_emulator\gb_memory.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\gb_sound.hpp">
+    <ClInclude Include="include\gb_emulator\gb_sound.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\gb_timers.hpp">
+    <ClInclude Include="include\gb_emulator\gb_timers.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\gb_video.hpp">
+    <ClInclude Include="include\gb_emulator\gb_video.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="include\gb_emulator\defs.hpp">
+    <ClInclude Include="include\gb_emulator\defs.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="gb_cpu_opcodes.hpp">
+    <ClInclude Include="gb_cpu_opcodes.h">
       <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="include\gb_emulator\cdb_file.h">

gb_emulator/gen_ops.py

 	sys.exit(1)
 
 # Generate opcode defines
-f = open('gb_cpu_opcodes.hpp', 'wb')
+f = open('gb_cpu_opcodes.h', 'wb')
 sys.stdout = f
 
 # Find widest machine-readable name
 	if type(op).__name__ == 'dict':
 		width = max(width, len(op['mName']))
 
-print '#ifndef GB_CPU_OPCODES_HPP_B5585700_06F3_11E0_A80E_0002A5D5C51B'
-print '#define GB_CPU_OPCODES_HPP_B5585700_06F3_11E0_A80E_0002A5D5C51B'
+print '#ifndef GB_CPU_OPCODES_H_B5585700_06F3_11E0_A80E_0002A5D5C51B'
+print '#define GB_CPU_OPCODES_H_B5585700_06F3_11E0_A80E_0002A5D5C51B'
 print
 print '/* This file was automatically generated from the opcodes definition file */'
 print

gb_emulator/include/gb_emulator/constants.h

+/*  Copyright © 2010 Chris Spencer <spencercw@gmail.com>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef CONSTANTS_H_83E2A140_0A3F_11E0_8B27_0002A5D5C51B
+#define CONSTANTS_H_83E2A140_0A3F_11E0_8B27_0002A5D5C51B
+
+#include <stdint.h>
+
+/* Registers */
+const unsigned REG_COUNT_16             = 4;
+const unsigned REG_COUNT_8              = 2 * REG_COUNT_16;
+
+const unsigned A                        = 1;
+const unsigned F                        = 0;
+const unsigned AF                       = 0;
+
+const unsigned B                        = 3;
+const unsigned C                        = 2;
+const unsigned BC                       = 1;
+
+const unsigned D                        = 5;
+const unsigned E                        = 4;
+const unsigned DE                       = 2;
+
+const unsigned H                        = 7;
+const unsigned L                        = 6;
+const unsigned HL                       = 3;
+
+const uint16_t MBC1_ROM_BANK_SELECT     = 0x2000;
+const uint16_t MBC1_ROM_RAM_BANK_SELECT = 0x4000;
+const uint16_t MBC1_ROM_RAM_MODE_SELECT = 0x6000;
+
+const uint16_t MBC3_ROM_BANK_SELECT     = 0x2000;
+const uint16_t MBC3_RAM_BANK_RTC_SELECT = 0x4000;
+const uint16_t MBC3_LATCH_CLOCK         = 0x6000;
+
+const uint16_t MBC5_LO_ROM_BANK_SELECT  = 0x2000;
+const uint16_t MBC5_HI_ROM_BANK_SELECT  = 0x3000;
+const uint16_t MBC5_RAM_BANK_SELECT     = 0x4000;
+const uint16_t MBC5_TOP                 = 0x6000;
+
+/* MBC3 RTC registers */
+const unsigned RTC_S                    = 0;
+const unsigned RTC_M                    = 1;
+const unsigned RTC_H                    = 2;
+const unsigned RTC_DL                   = 3;
+const unsigned RTC_DH                   = 4;
+
+/* Flags */
+const uint8_t  Z                        = 0x80;
+const uint8_t  N                        = 0x40;
+const uint8_t  HF                       = 0x20;
+const uint8_t  CF                       = 0x10;
+
+/* Sizes */
+const uint16_t BIOS_SIZE                = 0x900;
+const uint16_t ROM_BANK_SIZE            = 0x4000;
+const uint16_t VRAM_SIZE                = 0x4000;
+const uint16_t VRAM_BANK_SIZE           = 0x2000;
+const uint16_t EXT_RAM_SIZE             = 0x8000;
+const uint16_t EXT_RAM_BANK_SIZE        = 0x2000;
+const uint16_t RAM_SIZE                 = 0x8000;
+const uint16_t RAM_BANK_SIZE            = 0x1000;
+const uint16_t OAM_SIZE                 = 0xa0;
+const uint16_t IO_PORTS_SIZE            = 0x80;
+const uint16_t HIGH_RAM_SIZE            = 0x7f;
+const uint16_t GBC_PALETTE_SIZE         = 0x40;
+
+/* Cartridge types */
+const uint8_t  ROM_ONLY                 = 0x00;
+const uint8_t  MBC1                     = 0x01;
+const uint8_t  MBC1_RAM                 = 0x02;
+const uint8_t  MBC1_RAM_BAT             = 0x03;
+const uint8_t  MBC2                     = 0x05;
+const uint8_t  MBC2_BAT                 = 0x06;
+const uint8_t  ROM_RAM                  = 0x08;
+const uint8_t  ROM_RAM_BAT              = 0x09;
+const uint8_t  MMM01                    = 0x0b;
+const uint8_t  MMM01_RAM                = 0x0c;
+const uint8_t  MMM01_RAM_BAT            = 0x0d;
+const uint8_t  MBC3_TIMER_BAT           = 0x0f;
+const uint8_t  MBC3_TIMER_RAM_BAT       = 0x10;
+const uint8_t  MBC3                     = 0x11;
+const uint8_t  MBC3_RAM                 = 0x12;
+const uint8_t  MBC3_RAM_BAT             = 0x13;
+const uint8_t  MBC4                     = 0x15;
+const uint8_t  MBC4_RAM                 = 0x16;
+const uint8_t  MBC4_RAM_BAT             = 0x17;
+const uint8_t  MBC5                     = 0x19;
+const uint8_t  MBC5_RAM                 = 0x1a;
+const uint8_t  MBC5_RAM_BAT             = 0x1b;
+const uint8_t  MBC5_RUMBLE              = 0x1c;
+const uint8_t  MBC5_RUMBLE_RAM          = 0x1d;
+const uint8_t  MBC5_RUMBLE_RAM_BAT      = 0x1e;
+const uint8_t  POCKET_CAMERA            = 0xfc;
+const uint8_t  BANDAI_TAMA5             = 0xfd;
+const uint8_t  HUC3                     = 0xfe;
+const uint8_t  HUC1_RAM_BAT             = 0xff;
+
+/* Interesting durations */
+const unsigned CPU_CLOCK                = 1048576;   /* CPU clock frequency */
+const unsigned CYCLES_PER_FRAME         = 17556;     /* Number of clock cycles per frame */
+const double   FRAME_DURATION           = static_cast<double>(CYCLES_PER_FRAME) / CPU_CLOCK;  /* Frame duration in seconds */
+// The maximum number of days the real time clock is capable of tracking without overflowing.
+const unsigned RTC_MAX_DAYS             = 511;
+
+/* Memory map */
+const uint16_t BIOS1_END                = 0x0100;
+const uint16_t BIOS2_START              = 0x0200;
+const uint16_t BIOS2_END                = 0x0900;
+const uint16_t ROM_BANKX                = 0x4000;
+const uint16_t VIDEO_RAM                = 0x8000;
+const uint16_t EXT_RAM                  = 0xa000;
+const uint16_t RAM_BANK0                = 0xc000;
+const uint16_t RAM_BANKX                = 0xd000;
+const uint16_t ECHO_BANK0               = 0xe000;
+const uint16_t ECHO_BANKX               = 0xf000;
+const uint16_t OAM                      = 0xfe00;
+const uint16_t UNUSABLE                 = 0xfea0;
+const uint16_t IO_PORTS                 = 0xff00;
+const uint16_t HIGH_RAM                 = 0xff80;
+const uint16_t IE                       = 0xffff;
+
+/* I/O ports */
+const uint8_t  P1                       = 0x00;          /* Joypad */
+const uint8_t  SB                       = 0x01;          /* Serial transfer data */
+const uint8_t  SC                       = 0x02;          /* Serial transfer control */
+const uint8_t  DIV                      = 0x04;          /* Divider */
+const uint8_t  TIMA                     = 0x05;          /* Timer counter */
+const uint8_t  TMA                      = 0x06;          /* Timer modulo */
+const uint8_t  TAC                      = 0x07;          /* Timer control */
+const uint8_t  IF                       = 0x0f;          /* Interrupt flags */
+const uint8_t  NR10                     = 0x10;          /* Sound mode 1; sweep */
+const uint8_t  NR11                     = 0x11;          /* Sound mode 1; sound length / wave pattern duty */
+const uint8_t  NR12                     = 0x12;          /* Sound mode 1; envelope */
+const uint8_t  NR13                     = 0x13;          /* Sound mode 1; frequency lo */
+const uint8_t  NR14                     = 0x14;          /* Sound mode 1; frequency hi */
+const uint8_t  NR20                     = 0x15;          /* Sound mode 2; unused */
+const uint8_t  NR21                     = 0x16;          /* Sound mode 2; sound length / wave pattern duty */
+const uint8_t  NR22                     = 0x17;          /* Sound mode 2; envelope */
+const uint8_t  NR23                     = 0x18;          /* Sound mode 2; frequency lo */
+const uint8_t  NR24                     = 0x19;          /* Sound mode 2; frequency hi */
+const uint8_t  NR30                     = 0x1a;          /* Sound mode 3; sound on/off */
+const uint8_t  NR31                     = 0x1b;          /* Sound mode 3; sound length */
+const uint8_t  NR32                     = 0x1c;          /* Sound mode 3; select output level */
+const uint8_t  NR33                     = 0x1d;          /* Sound mode 3; frequency lo */
+const uint8_t  NR34                     = 0x1e;          /* Sound mode 3; frequency hi */
+const uint8_t  NR40                     = 0x1f;          /* Sound mode 4; unused */
+const uint8_t  NR41                     = 0x20;          /* Sound mode 4; sound length */
+const uint8_t  NR42                     = 0x21;          /* Sound mode 4; envelope */
+const uint8_t  NR43                     = 0x22;          /* Sound mode 4; polynomial counter */
+const uint8_t  NR44                     = 0x23;          /* Sound mode 4; counter/consectutive; initial */
+const uint8_t  NR50                     = 0x24;          /* Sound mode 5; channel control / on/off / volume */
+const uint8_t  NR51                     = 0x25;          /* Sound mode 5; selection of sound output terminal */
+const uint8_t  NR52                     = 0x26;          /* Sound mode 5; sound on/off */
+const uint8_t  LCDC                     = 0x40;          /* LCD control */
+const uint8_t  STAT                     = 0x41;          /* LCD status */
+const uint8_t  SCY                      = 0x42;          /* Scroll Y */
+const uint8_t  SCX                      = 0x43;          /* Scroll X */
+const uint8_t  LY                       = 0x44;          /* Current draw line */
+const uint8_t  LYC                      = 0x45;          /* LYC */
+const uint8_t  DMA                      = 0x46;          /* DMA transfer */
+const uint8_t  BGP                      = 0x47;          /* Background and window palette */
+const uint8_t  OBP0                     = 0x48;          /* Object palette 0 data */
+const uint8_t  OBP1                     = 0x49;          /* Object palette 1 data */
+const uint8_t  WY                       = 0x4a;          /* Window Y position */
+const uint8_t  WX                       = 0x4b;          /* Window X position */
+const uint8_t  KEY1                     = 0x4d;          /* CPU speed switch */
+const uint8_t  VBK                      = 0x4f;          /* VRAM bank selector */
+const uint8_t  BLCK                     = 0x50;          /* BIOS disable */
+const uint8_t  HDMA1                    = 0x51;          /* GBC DMA source hi */
+const uint8_t  HDMA2                    = 0x52;          /* GBC DMA source lo */
+const uint8_t  HDMA3                    = 0x53;          /* GBC DMA destination hi */
+const uint8_t  HDMA4                    = 0x54;          /* GBC DMA destination lo */
+const uint8_t  HDMA5                    = 0x55;          /* GBC DMA transfer */
+const uint8_t  RP                       = 0x56;          /* Infrared communications port */
+const uint8_t  BCPS                     = 0x68;          /* GBC background palette index */
+const uint8_t  BCPD                     = 0x69;          /* GBC background palette data */
+const uint8_t  OCPS                     = 0x6a;          /* GBC sprite palette index */
+const uint8_t  OCPD                     = 0x6b;          /* GBC sprite palette data */
+const uint8_t  SVBK                     = 0x70;          /* RAM bank selector */
+
+/* I/O port bits */
+const uint8_t  JOYP_BUTTONS             = 0x20;
+const uint8_t  JOYP_DIRECTION           = 0x10;
+const uint8_t  JOYP_DOWN_OR_START       = 0x08;
+const uint8_t  JOYP_UP_OR_SELECT        = 0x04;
+const uint8_t  JOYP_LEFT_OR_B           = 0x02;
+const uint8_t  JOYP_RIGHT_OR_A          = 0x01;
+
+const uint8_t  LCDC_OPERATIONAL         = 0x80;
+const uint8_t  LCDC_WNDW_TILE_MAP       = 0x40;
+const uint8_t  LCDC_WNDW_DISPLAY        = 0x20;
+const uint8_t  LCDC_TILE_DATA           = 0x10;
+const uint8_t  LCDC_BG_TILE_MAP         = 0x08;
+const uint8_t  LCDC_SPRITE_SIZE         = 0x04;
+const uint8_t  LCDC_SPRITE_DISPLAY      = 0x02;
+const uint8_t  LCDC_BG_DISPLAY          = 0x01;
+
+const uint8_t  LCD_STAT_COINC_INTR      = 0x40;
+const uint8_t  LCD_STAT_OAM_READ_INTR   = 0x20;
+const uint8_t  LCD_STAT_VBLANK_INTR     = 0x10;
+const uint8_t  LCD_STAT_HBLANK_INTR     = 0x08;
+const uint8_t  LCD_STAT_COINCIDENCE     = 0x04;
+
+/* Interrupt master enable states */
+const uint8_t  IME_DISABLED             = 0;
+const uint8_t  IME_ENABLING1            = 1;
+const uint8_t  IME_ENABLING2            = 2;
+const uint8_t  IME_DISABLING1           = 3;
+const uint8_t  IME_DISABLING2           = 4;
+const uint8_t  IME_ENABLED              = 5;
+
+/* Interrupts */
+const uint8_t  VBLANK_INTR              = 0x01;
+const uint8_t  LCD_STAT_INTR            = 0x02;
+const uint8_t  TIMER_INTR               = 0x04;
+const uint8_t  SERIAL_INTR              = 0x08;
+const uint8_t  JOYPAD_INTR              = 0x10;
+
+const uint16_t VBLANK_INTR_ADDR         = 0x40;
+const uint16_t LCD_STAT_INTR_ADDR       = 0x48;
+const uint16_t TIMER_INTR_ADDR          = 0x50;
+const uint16_t SERIAL_INTR_ADDR         = 0x58;
+const uint16_t JOYPAD_INTR_ADDR         = 0x60;
+
+/* Video constants */
+const unsigned VBLANK_START             = 144;           /* Line at which VBLANK starts */
+const unsigned VIDEO_LINES              = 256;           /* Total number of video lines */
+const unsigned HBLANK_CYCLES            = 51;            /* Duration of the HBLANK period (mode 0) */
+const unsigned OAM_READ_CYCLES          = 20;            /* Duration of the OAM read period (mode 2) */
+const unsigned OAM_VRAM_READ_CYCLES     = 43;            /* Duration of the OAM and VRAM read period (mode 3) */
+const unsigned LINE_CYCLES              = HBLANK_CYCLES + OAM_READ_CYCLES + OAM_VRAM_READ_CYCLES;
+const double   COLOUR_RATIO             = 255. / 31.;    /* Ratio between GBC and standard colours */
+
+/* Timers */
+const int DIVIDER_CYCLES                = 64;
+const int TIMER0_CYCLES                 = 256;
+const int TIMER1_CYCLES                 = 4;
+const int TIMER2_CYCLES                 = 16;
+const int TIMER3_CYCLES                 = 64;
+const int RTC_CYCLES                    = CPU_CLOCK;
+
+/* Serial comms clock durations
+ * This is the number of cycles per *byte*, not per bit as the real Game Boy operates. SB is
+ * inaccessible during transfers so emulating the bit shifting is unnecessary. */
+const int SERIAL1_CYCLES                = 1024;  /* 1024 Hz (8192 Hz) */
+const int SERIAL2_CYCLES                = 32;    /* 32 768 Hz (262 144 Hz) */
+/* Maximum number of cycles to execute when an internal clock request is received when the game is
+ * not ready for it before giving up. (~8ms) */
+const int SERIAL_DELAY_ALLOWANCE        = 8192;
+
+#endif

gb_emulator/include/gb_emulator/constants.hpp

-/*  Copyright © 2010 Chris Spencer <spencercw@gmail.com>
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef CONSTANTS_HPP_83E2A140_0A3F_11E0_8B27_0002A5D5C51B
-#define CONSTANTS_HPP_83E2A140_0A3F_11E0_8B27_0002A5D5C51B
-
-#include <stdint.h>
-
-/* Registers */
-const unsigned REG_COUNT_16             = 4;
-const unsigned REG_COUNT_8              = 2 * REG_COUNT_16;
-
-const unsigned A                        = 1;
-const unsigned F                        = 0;
-const unsigned AF                       = 0;
-
-const unsigned B                        = 3;
-const unsigned C                        = 2;
-const unsigned BC                       = 1;
-
-const unsigned D                        = 5;
-const unsigned E                        = 4;
-const unsigned DE                       = 2;
-
-const unsigned H                        = 7;
-const unsigned L                        = 6;
-const unsigned HL                       = 3;
-
-const uint16_t MBC1_ROM_BANK_SELECT     = 0x2000;
-const uint16_t MBC1_ROM_RAM_BANK_SELECT = 0x4000;
-const uint16_t MBC1_ROM_RAM_MODE_SELECT = 0x6000;
-
-const uint16_t MBC3_ROM_BANK_SELECT     = 0x2000;
-const uint16_t MBC3_RAM_BANK_RTC_SELECT = 0x4000;
-const uint16_t MBC3_LATCH_CLOCK         = 0x6000;
-
-const uint16_t MBC5_LO_ROM_BANK_SELECT  = 0x2000;
-const uint16_t MBC5_HI_ROM_BANK_SELECT  = 0x3000;
-const uint16_t MBC5_RAM_BANK_SELECT     = 0x4000;
-const uint16_t MBC5_TOP                 = 0x6000;
-
-/* MBC3 RTC registers */
-const unsigned RTC_S                    = 0;
-const unsigned RTC_M                    = 1;
-const unsigned RTC_H                    = 2;
-const unsigned RTC_DL                   = 3;
-const unsigned RTC_DH                   = 4;
-
-/* Flags */
-const uint8_t  Z                        = 0x80;
-const uint8_t  N                        = 0x40;
-const uint8_t  HF                       = 0x20;
-const uint8_t  CF                       = 0x10;
-
-/* Sizes */
-const uint16_t BIOS_SIZE                = 0x900;
-const uint16_t ROM_BANK_SIZE            = 0x4000;
-const uint16_t VRAM_SIZE                = 0x4000;
-const uint16_t VRAM_BANK_SIZE           = 0x2000;
-const uint16_t EXT_RAM_SIZE             = 0x8000;
-const uint16_t EXT_RAM_BANK_SIZE        = 0x2000;
-const uint16_t RAM_SIZE                 = 0x8000;
-const uint16_t RAM_BANK_SIZE            = 0x1000;
-const uint16_t OAM_SIZE                 = 0xa0;
-const uint16_t IO_PORTS_SIZE            = 0x80;
-const uint16_t HIGH_RAM_SIZE            = 0x7f;
-const uint16_t GBC_PALETTE_SIZE         = 0x40;
-
-/* Cartridge types */
-const uint8_t  ROM_ONLY                 = 0x00;
-const uint8_t  MBC1                     = 0x01;
-const uint8_t  MBC1_RAM                 = 0x02;
-const uint8_t  MBC1_RAM_BAT             = 0x03;
-const uint8_t  MBC2                     = 0x05;
-const uint8_t  MBC2_BAT                 = 0x06;
-const uint8_t  ROM_RAM                  = 0x08;
-const uint8_t  ROM_RAM_BAT              = 0x09;
-const uint8_t  MMM01                    = 0x0b;
-const uint8_t  MMM01_RAM                = 0x0c;
-const uint8_t  MMM01_RAM_BAT            = 0x0d;
-const uint8_t  MBC3_TIMER_BAT           = 0x0f;
-const uint8_t  MBC3_TIMER_RAM_BAT       = 0x10;
-const uint8_t  MBC3                     = 0x11;
-const uint8_t  MBC3_RAM                 = 0x12;
-const uint8_t  MBC3_RAM_BAT             = 0x13;
-const uint8_t  MBC4                     = 0x15;
-const uint8_t  MBC4_RAM                 = 0x16;
-const uint8_t  MBC4_RAM_BAT             = 0x17;
-const uint8_t  MBC5                     = 0x19;
-const uint8_t  MBC5_RAM                 = 0x1a;
-const uint8_t  MBC5_RAM_BAT             = 0x1b;
-const uint8_t  MBC5_RUMBLE              = 0x1c;
-const uint8_t  MBC5_RUMBLE_RAM          = 0x1d;
-const uint8_t  MBC5_RUMBLE_RAM_BAT      = 0x1e;
-const uint8_t  POCKET_CAMERA            = 0xfc;
-const uint8_t  BANDAI_TAMA5             = 0xfd;
-const uint8_t  HUC3                     = 0xfe;
-const uint8_t  HUC1_RAM_BAT             = 0xff;
-
-/* Interesting durations */
-const unsigned CPU_CLOCK                = 1048576;   /* CPU clock frequency */
-const unsigned CYCLES_PER_FRAME         = 17556;     /* Number of clock cycles per frame */
-const double   FRAME_DURATION           = static_cast<double>(CYCLES_PER_FRAME) / CPU_CLOCK;  /* Frame duration in seconds */
-// The maximum number of days the real time clock is capable of tracking without overflowing.
-const unsigned RTC_MAX_DAYS             = 511;
-
-/* Memory map */
-const uint16_t BIOS1_END                = 0x0100;
-const uint16_t BIOS2_START              = 0x0200;
-const uint16_t BIOS2_END                = 0x0900;
-const uint16_t ROM_BANKX                = 0x4000;
-const uint16_t VIDEO_RAM                = 0x8000;
-const uint16_t EXT_RAM                  = 0xa000;
-const uint16_t RAM_BANK0                = 0xc000;
-const uint16_t RAM_BANKX                = 0xd000;
-const uint16_t ECHO_BANK0               = 0xe000;
-const uint16_t ECHO_BANKX               = 0xf000;
-const uint16_t OAM                      = 0xfe00;
-const uint16_t UNUSABLE                 = 0xfea0;
-const uint16_t IO_PORTS                 = 0xff00;
-const uint16_t HIGH_RAM                 = 0xff80;
-const uint16_t IE                       = 0xffff;
-
-/* I/O ports */
-const uint8_t  P1                       = 0x00;          /* Joypad */
-const uint8_t  SB                       = 0x01;          /* Serial transfer data */
-const uint8_t  SC                       = 0x02;          /* Serial transfer control */
-const uint8_t  DIV                      = 0x04;          /* Divider */
-const uint8_t  TIMA                     = 0x05;          /* Timer counter */
-const uint8_t  TMA                      = 0x06;          /* Timer modulo */
-const uint8_t  TAC                      = 0x07;          /* Timer control */
-const uint8_t  IF                       = 0x0f;          /* Interrupt flags */
-const uint8_t  NR10                     = 0x10;          /* Sound mode 1; sweep */
-const uint8_t  NR11                     = 0x11;          /* Sound mode 1; sound length / wave pattern duty */
-const uint8_t  NR12                     = 0x12;          /* Sound mode 1; envelope */
-const uint8_t  NR13                     = 0x13;          /* Sound mode 1; frequency lo */
-const uint8_t  NR14                     = 0x14;          /* Sound mode 1; frequency hi */
-const uint8_t  NR20                     = 0x15;          /* Sound mode 2; unused */
-const uint8_t  NR21                     = 0x16;          /* Sound mode 2; sound length / wave pattern duty */
-const uint8_t  NR22                     = 0x17;          /* Sound mode 2; envelope */
-const uint8_t  NR23                     = 0x18;          /* Sound mode 2; frequency lo */
-const uint8_t  NR24                     = 0x19;          /* Sound mode 2; frequency hi */
-const uint8_t  NR30                     = 0x1a;          /* Sound mode 3; sound on/off */
-const uint8_t  NR31                     = 0x1b;          /* Sound mode 3; sound length */
-const uint8_t  NR32                     = 0x1c;          /* Sound mode 3; select output level */
-const uint8_t  NR33                     = 0x1d;          /* Sound mode 3; frequency lo */
-const uint8_t  NR34                     = 0x1e;          /* Sound mode 3; frequency hi */
-const uint8_t  NR40                     = 0x1f;          /* Sound mode 4; unused */
-const uint8_t  NR41                     = 0x20;          /* Sound mode 4; sound length */
-const uint8_t  NR42                     = 0x21;          /* Sound mode 4; envelope */
-const uint8_t  NR43                     = 0x22;          /* Sound mode 4; polynomial counter */
-const uint8_t  NR44                     = 0x23;          /* Sound mode 4; counter/consectutive; initial */
-const uint8_t  NR50                     = 0x24;          /* Sound mode 5; channel control / on/off / volume */
-const uint8_t  NR51                     = 0x25;          /* Sound mode 5; selection of sound output terminal */
-const uint8_t  NR52                     = 0x26;          /* Sound mode 5; sound on/off */
-const uint8_t  LCDC                     = 0x40;          /* LCD control */
-const uint8_t  STAT                     = 0x41;          /* LCD status */
-const uint8_t  SCY                      = 0x42;          /* Scroll Y */
-const uint8_t  SCX                      = 0x43;          /* Scroll X */
-const uint8_t  LY                       = 0x44;          /* Current draw line */
-const uint8_t  LYC                      = 0x45;          /* LYC */
-const uint8_t  DMA                      = 0x46;          /* DMA transfer */
-const uint8_t  BGP                      = 0x47;          /* Background and window palette */
-const uint8_t  OBP0                     = 0x48;          /* Object palette 0 data */
-const uint8_t  OBP1                     = 0x49;          /* Object palette 1 data */
-const uint8_t  WY                       = 0x4a;          /* Window Y position */
-const uint8_t  WX                       = 0x4b;          /* Window X position */
-const uint8_t  KEY1                     = 0x4d;          /* CPU speed switch */
-const uint8_t  VBK                      = 0x4f;          /* VRAM bank selector */
-const uint8_t  BLCK                     = 0x50;          /* BIOS disable */
-const uint8_t  HDMA1                    = 0x51;          /* GBC DMA source hi */
-const uint8_t  HDMA2                    = 0x52;          /* GBC DMA source lo */
-const uint8_t  HDMA3                    = 0x53;          /* GBC DMA destination hi */
-const uint8_t  HDMA4                    = 0x54;          /* GBC DMA destination lo */
-const uint8_t  HDMA5                    = 0x55;          /* GBC DMA transfer */
-const uint8_t  RP                       = 0x56;          /* Infrared communications port */
-const uint8_t  BCPS                     = 0x68;          /* GBC background palette index */
-const uint8_t  BCPD                     = 0x69;          /* GBC background palette data */
-const uint8_t  OCPS                     = 0x6a;          /* GBC sprite palette index */
-const uint8_t  OCPD                     = 0x6b;          /* GBC sprite palette data */
-const uint8_t  SVBK                     = 0x70;          /* RAM bank selector */
-
-/* I/O port bits */
-const uint8_t  JOYP_BUTTONS             = 0x20;
-const uint8_t  JOYP_DIRECTION           = 0x10;
-const uint8_t  JOYP_DOWN_OR_START       = 0x08;
-const uint8_t  JOYP_UP_OR_SELECT        = 0x04;
-const uint8_t  JOYP_LEFT_OR_B           = 0x02;
-const uint8_t  JOYP_RIGHT_OR_A          = 0x01;
-
-const uint8_t  LCDC_OPERATIONAL         = 0x80;
-const uint8_t  LCDC_WNDW_TILE_MAP       = 0x40;
-const uint8_t  LCDC_WNDW_DISPLAY        = 0x20;
-const uint8_t  LCDC_TILE_DATA           = 0x10;
-const uint8_t  LCDC_BG_TILE_MAP         = 0x08;
-const uint8_t  LCDC_SPRITE_SIZE         = 0x04;
-const uint8_t  LCDC_SPRITE_DISPLAY      = 0x02;
-const uint8_t  LCDC_BG_DISPLAY          = 0x01;
-
-const uint8_t  LCD_STAT_COINC_INTR      = 0x40;
-const uint8_t  LCD_STAT_OAM_READ_INTR   = 0x20;
-const uint8_t  LCD_STAT_VBLANK_INTR     = 0x10;
-const uint8_t  LCD_STAT_HBLANK_INTR     = 0x08;
-const uint8_t  LCD_STAT_COINCIDENCE     = 0x04;
-
-/* Interrupt master enable states */
-const uint8_t  IME_DISABLED             = 0;
-const uint8_t  IME_ENABLING1            = 1;
-const uint8_t  IME_ENABLING2            = 2;
-const uint8_t  IME_DISABLING1           = 3;
-const uint8_t  IME_DISABLING2           = 4;
-const uint8_t  IME_ENABLED              = 5;
-
-/* Interrupts */
-const uint8_t  VBLANK_INTR              = 0x01;
-const uint8_t  LCD_STAT_INTR            = 0x02;
-const uint8_t  TIMER_INTR               = 0x04;
-const uint8_t  SERIAL_INTR              = 0x08;
-const uint8_t  JOYPAD_INTR              = 0x10;
-
-const uint16_t VBLANK_INTR_ADDR         = 0x40;
-const uint16_t LCD_STAT_INTR_ADDR       = 0x48;
-const uint16_t TIMER_INTR_ADDR          = 0x50;
-const uint16_t SERIAL_INTR_ADDR         = 0x58;
-const uint16_t JOYPAD_INTR_ADDR         = 0x60;
-
-/* Video constants */
-const unsigned VBLANK_START             = 144;           /* Line at which VBLANK starts */
-const unsigned VIDEO_LINES              = 256;           /* Total number of video lines */
-const unsigned HBLANK_CYCLES            = 51;            /* Duration of the HBLANK period (mode 0) */
-const unsigned OAM_READ_CYCLES          = 20;            /* Duration of the OAM read period (mode 2) */
-const unsigned OAM_VRAM_READ_CYCLES     = 43;            /* Duration of the OAM and VRAM read period (mode 3) */
-const unsigned LINE_CYCLES              = HBLANK_CYCLES + OAM_READ_CYCLES + OAM_VRAM_READ_CYCLES;
-const double   COLOUR_RATIO             = 255. / 31.;    /* Ratio between GBC and standard colours */
-
-/* Timers */
-const int DIVIDER_CYCLES                = 64;
-const int TIMER0_CYCLES                 = 256;
-const int TIMER1_CYCLES                 = 4;
-const int TIMER2_CYCLES                 = 16;