program counter must start at memory location 0x200 Std::mt19937 gen // generates pseudo-random numbersīool draw_flag // true when gfx needs to be updated
Opcode galay mac emulator generator#
Std::random_device rd // used to obtain seed for generator
Std::uint16_t opcode // current instruction Std::uint16_t sp // points to top of stack Std::uint16_t pc // currently executing address Std::uint16_t I // stores memory addresses Std::uint8_t sound_timer // decrements at 60Hz when nonzero Std::uint8_t delay_timer // decrements at 60Hz when nonzero Std::array keys // stores hexadecimal keypad Std::array stack // subroutine return addresses Std::array V // general registers, VF = carry bit Std::array memory // ram, first 512 bytes reserved I was taught to use getters and setters, but I feel like making some of my variables (keys, graphics) public would've been easier. SDL_LockTexture(texture, nullptr, reinterpret_cast(&pixels), &pitch) SDLK_4, SDLK_r, SDLK_f, SDLK_v} // C D E F SDLK_s, SDLK_d, SDLK_z, SDLK_c, // 8 9 A B #include Ĭonstexpr int TICKS_PER_FRAME = 1000 / FPS Ĭonstexpr int INSTRUCTIONS_PER_STEP = 10 I also had some trouble getting some lines under 80 characters (the SDL ones). I think there's too much stuff in my main function and I feel like this file isn't very readable in general. I'm hoping for general advice / suggestions about the code structure and the way it's written. I've tested it with roms off Zophar's Domain and it appears to work with my limited testing. I wrote this chip8 emulator as practice recently since my coursework is mostly console programs.