diff --git a/C++ProjectTemplate b/C++ProjectTemplate index f8a08dc..0a06ac4 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 4e14175..4877807 100644 --- a/main.cpp +++ b/main.cpp @@ -53,7 +53,7 @@ public: }; std::arraydisplay; std::arrayscreen; - std::stackstack; + std::liststack; float pulse=0; uint8_t delay_timer,sound_timer; uint16_t pc=0x200; @@ -65,6 +65,7 @@ public: std::arraykeymap{X,K1,K2,K3,Q,W,E,A,S,D,Z,C,K4,R,F,V}; bool USE_ORIGINAL_CHIP8_SET=true; //True means use the original CHIP-8 spec (COSMAC VIP emulation). Set to false to use CHIP-48 spec. bool PAUSED=true; + long instructionCount=0; std::string Display8(int number){ std::bitset<8>numb(number); @@ -75,6 +76,14 @@ public: return numb.to_string(); } + void advanceTimers(){ + if (delay_timer>0){ + delay_timer--; + } + if (sound_timer>0){ + sound_timer--; + } + } bool OnUserCreate() override { @@ -112,12 +121,7 @@ public: if (!USE_DEBUG_DISPLAY||!PAUSED){ pulse+=fElapsedTime; if (pulse>=1/60.f){ - if (delay_timer>0){ - delay_timer--; - } - if (sound_timer>0){ - sound_timer--; - } + advanceTimers(); pulse-=1/60.f; for (int i=0;i<10;i++){ @@ -128,15 +132,31 @@ public: } else { if (GetKey(OEM_6).bPressed){ RunInstruction(); + instructionCount++; + if (instructionCount%10==0){ + advanceTimers(); //After 10 instructions, 1/60th of a second has passed. + } + DrawDisplay(); + } else + if (GetKey(SPACE).bHeld){ + RunInstruction(); + instructionCount++; + if (instructionCount%10==0){ + advanceTimers(); //After 10 instructions, 1/60th of a second has passed. + } DrawDisplay(); } } std::stringstream s; s<<"PC: 0x"<=10)?3:4)<<(int)reg[i]; + DrawStringDecal(vi2d{12+i/8*64,EMULATOR_PIXEL_SIZE*EMULATOR_SCREEN_HEIGHT+54+i%8*10},s.str()); + } + + std::stringstream index_s; + index_s<<"0x"<>8); - stack.push(pc&0xFF); + stack.push_front(pc>>8); + stack.push_front(pc&0xFF); //std::cout<<"Pushed 0x"<