|
|
|
@ -65,15 +65,18 @@ public: |
|
|
|
|
|
|
|
|
|
bool OnUserCreate() override |
|
|
|
|
{ |
|
|
|
|
/*std::ifstream file("IBM Logo.ch8",std::ios_base::binary);
|
|
|
|
|
for (int i=0;i<display.size();i++){ |
|
|
|
|
display[i]=0; |
|
|
|
|
} |
|
|
|
|
std::ifstream file("test_opcode.ch8",std::ios_base::binary); |
|
|
|
|
uint16_t counter=0x200; |
|
|
|
|
while (file.good()){ |
|
|
|
|
int val = file.get(); |
|
|
|
|
if (val!=-1){ |
|
|
|
|
memory[counter++]=val; |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
memory[0x200]=0x00; |
|
|
|
|
} |
|
|
|
|
/*memory[0x200]=0x00;
|
|
|
|
|
memory[0x201]=0xE0; |
|
|
|
|
memory[0x202]=0xA0; |
|
|
|
|
memory[0x203]=0x50; |
|
|
|
@ -81,8 +84,10 @@ public: |
|
|
|
|
memory[0x205]=0x04; |
|
|
|
|
memory[0x206]=0xD0; |
|
|
|
|
memory[0x207]=0x05; |
|
|
|
|
memory[0x208]=0x12; |
|
|
|
|
memory[0x209]=0x08; |
|
|
|
|
memory[0x208]=0xD0; |
|
|
|
|
memory[0x209]=0x05; |
|
|
|
|
memory[0x210]=0x12; |
|
|
|
|
memory[0x211]=0x10;*/ |
|
|
|
|
//0x200 program start
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -104,6 +109,7 @@ public: |
|
|
|
|
//FETCH
|
|
|
|
|
uint16_t opcode = memory[pc]<<8|memory[pc+1]; |
|
|
|
|
pc+=2; |
|
|
|
|
//std::cout<<"Next instruction is 0x"<<std::hex<<pc<<std::endl;
|
|
|
|
|
|
|
|
|
|
//DECODE
|
|
|
|
|
uint8_t nibble1 = opcode>>12; |
|
|
|
@ -121,13 +127,26 @@ public: |
|
|
|
|
display[i]=0; |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case 0x0EE:{ //Return from subroutine.
|
|
|
|
|
uint8_t byte1,byte2; |
|
|
|
|
byte1=stack.top(); |
|
|
|
|
stack.pop(); |
|
|
|
|
byte2=stack.top(); |
|
|
|
|
stack.pop(); |
|
|
|
|
pc=byte2<<8|byte1; |
|
|
|
|
//std::cout<<"Exiting subroutine to 0x"<<std::hex<<pc<<std::endl;
|
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case 0x1:{ //Jump.
|
|
|
|
|
pc=NNN; |
|
|
|
|
}break; |
|
|
|
|
case 0x2:{ |
|
|
|
|
|
|
|
|
|
case 0x2:{ //calls the subroutine at memory location NNN
|
|
|
|
|
stack.push(pc>>8); |
|
|
|
|
stack.push(pc&0xFF); |
|
|
|
|
//std::cout<<"Pushed 0x"<<std::hex<<pc<<" onto stack"<<std::endl;
|
|
|
|
|
pc=NNN; |
|
|
|
|
//std::cout<<"Entering subroutine @ 0x"<<std::hex<<NNN<<std::endl;
|
|
|
|
|
}break; |
|
|
|
|
case 0x3:{ |
|
|
|
|
|
|
|
|
@ -174,17 +193,12 @@ public: |
|
|
|
|
//0xF0,0x90,0x90,0x90,0xF0
|
|
|
|
|
bool pixel = spriteRow>>(8-x-1)&0x1; |
|
|
|
|
if (display[(start_Y+y)*ScreenWidth()+(start_X+x)]&&pixel){ |
|
|
|
|
//std::cout<<"Double on."<<std::endl;
|
|
|
|
|
reg[0xF]=0; |
|
|
|
|
} |
|
|
|
|
display[(start_Y+y)*ScreenWidth()+(start_X+x)]^=pixel; |
|
|
|
|
if (pixel){ |
|
|
|
|
std::cout<<"X"; |
|
|
|
|
} else { |
|
|
|
|
std::cout<<" "; |
|
|
|
|
} |
|
|
|
|
display[(start_Y+y)*ScreenWidth()+(start_X+x)]=display[(start_Y+y)*ScreenWidth()+(start_X+x)]^pixel; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::cout<<std::endl; |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case 0xE:{ |
|
|
|
|