|
|
|
@ -9,7 +9,7 @@ |
|
|
|
|
|
|
|
|
|
using namespace olc; |
|
|
|
|
|
|
|
|
|
bool USE_DEBUG_DISPLAY=false; |
|
|
|
|
bool USE_DEBUG_DISPLAY=true; |
|
|
|
|
int EMULATOR_SCREEN_WIDTH = 64; |
|
|
|
|
int EMULATOR_SCREEN_HEIGHT = 32; |
|
|
|
|
int EMULATOR_PIXEL_SIZE=5; |
|
|
|
@ -154,12 +154,23 @@ public: |
|
|
|
|
advanceTimers(); //After 10 instructions, 1/60th of a second has passed.
|
|
|
|
|
} |
|
|
|
|
DrawDisplay(); |
|
|
|
|
} else |
|
|
|
|
if (GetKey(END).bHeld){ |
|
|
|
|
for (int i=0;i<10;i++){ |
|
|
|
|
RunInstruction(); |
|
|
|
|
instructionCount++; |
|
|
|
|
} |
|
|
|
|
advanceTimers(); //After 10 instructions, 1/60th of a second has passed.
|
|
|
|
|
DrawDisplay(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (IsTextEntryEnabled()){ |
|
|
|
|
DrawStringDecal({2,2},"Goto Memory Address: "+TextEntryGetString()); |
|
|
|
|
} |
|
|
|
|
if (GetKey(F12).bPressed){ |
|
|
|
|
PAUSED=!PAUSED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::stringstream s; |
|
|
|
|
s<<"PC: 0x"<<std::setfill('0')<< std::setw(4)<<std::hex<<pc; |
|
|
|
@ -190,6 +201,10 @@ public: |
|
|
|
|
DrawStringDecal(vi2d{12+i/8*64,EMULATOR_PIXEL_SIZE*EMULATOR_SCREEN_HEIGHT+54+i%8*10},s.str()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DrawStringDecal(vi2d{8+164,EMULATOR_PIXEL_SIZE*EMULATOR_SCREEN_HEIGHT+44},"TIMERS"); |
|
|
|
|
DrawStringDecal(vi2d{12+164,EMULATOR_PIXEL_SIZE*EMULATOR_SCREEN_HEIGHT+54},"DELAY "+std::to_string(delay_timer)); |
|
|
|
|
DrawStringDecal(vi2d{12+164,EMULATOR_PIXEL_SIZE*EMULATOR_SCREEN_HEIGHT+64},"SOUND "+std::to_string(sound_timer)); |
|
|
|
|
|
|
|
|
|
std::stringstream index_s; |
|
|
|
|
index_s<<"0x"<<std::hex<<std::setfill('0')<<std::setw(4)<<index; |
|
|
|
|
DrawStringDecal(vi2d{8,EMULATOR_PIXEL_SIZE*EMULATOR_SCREEN_HEIGHT+64+10*8},"INDEX: "+index_s.str()); |
|
|
|
@ -364,7 +379,7 @@ public: |
|
|
|
|
return jump.str(); |
|
|
|
|
}break; |
|
|
|
|
case 0xC:{//Random number from 0 to NN.
|
|
|
|
|
return "RAND (0-"+std::to_string(NN)+")"; |
|
|
|
|
return "RAND (0-"+std::to_string(NN)+") SET TO V"+std::to_string(X); |
|
|
|
|
}break; |
|
|
|
|
case 0xD:{ //Display
|
|
|
|
|
return "DISPLAY X:[V"+std::to_string(X)+"],Y:[V"+std::to_string(Y)+"] H:"+std::to_string(N); |
|
|
|
@ -503,10 +518,10 @@ public: |
|
|
|
|
reg[0xF]=carryFlag; |
|
|
|
|
}break; |
|
|
|
|
case 0x5:{// sets VX to the result of VX - VY.
|
|
|
|
|
bool carryFlag=0; |
|
|
|
|
if (reg[X]>reg[Y]){ |
|
|
|
|
bool carryFlag=false; |
|
|
|
|
if (reg[X]>=reg[Y]){ |
|
|
|
|
//reg[0xF]=1;
|
|
|
|
|
carryFlag=1; |
|
|
|
|
carryFlag=true; |
|
|
|
|
} |
|
|
|
|
reg[X]-=reg[Y]; |
|
|
|
|
reg[0xF]=carryFlag; |
|
|
|
@ -527,7 +542,7 @@ public: |
|
|
|
|
case 0x7:{//sets VX to the result of VY - VX. It's a reverse subtraction.
|
|
|
|
|
//reg[0xF]=0;
|
|
|
|
|
bool carryFlag=false; |
|
|
|
|
if (reg[Y]>reg[X]){ |
|
|
|
|
if (reg[Y]>=reg[X]){ |
|
|
|
|
//reg[0xF]=1;
|
|
|
|
|
carryFlag=true; |
|
|
|
|
} |
|
|
|
@ -612,13 +627,13 @@ public: |
|
|
|
|
}break; |
|
|
|
|
case 0x1E:{//The index register I will get the value in VX added to it.
|
|
|
|
|
//reg[0xF]=0;
|
|
|
|
|
bool carryFlag=false; |
|
|
|
|
/*bool carryFlag=false;
|
|
|
|
|
if (index+reg[X]>=0x1000){ |
|
|
|
|
//reg[0xF]=1;
|
|
|
|
|
carryFlag=true; |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
index+=reg[X]; |
|
|
|
|
reg[0xF]=carryFlag; |
|
|
|
|
//reg[0xF]=carryFlag;
|
|
|
|
|
}break; |
|
|
|
|
case 0x0A:{//This instruction “blocks”; it stops executing instructions and waits for key input
|
|
|
|
|
for (int i=0;i<keymap.size();i++){ |
|
|
|
|