Minor changes

This commit is contained in:
Loïc Guégan 2023-12-25 10:01:40 +01:00
parent 8fd3d27abe
commit 7642efad5a
7 changed files with 31 additions and 8 deletions

BIN
roms/logo_chip8.ch8 Normal file

Binary file not shown.

BIN
roms/logo_ibm.ch8 Normal file

Binary file not shown.

View file

@ -7,7 +7,7 @@ int main(int argc, char *argv[])
// Initialize
MemInit();
MemLoadROM("../roms/2-ibm-logo.ch8");
MemLoadROM("../roms/logo_chip8.ch8");
ScreenInit(800,400);
VCPUInit();

View file

@ -15,7 +15,7 @@ void ScreenInit(int width, int height){
SetTraceLogLevel(LOG_ERROR); // Disable anoying raylib logs
InitWindow(width, height, "Chip-8 Emulator");
SetTargetFPS(60); // Set game to run at 60 frames-per-second
SetTargetFPS(80); // Set game to run at 60 frames-per-second
}
void ScreenClear() {
@ -40,8 +40,11 @@ void ScreenUpdate(){
EndDrawing();
}
void ScreenSetPixel(int x, int y, unsigned char state){
Screen.pixels[x+y*64]=(state==0) ? 0: 1;
char ScreenPixelApply(int x, int y, unsigned char state){
if(Screen.pixels[x+y*64] != 0 && state != 0)
return 1;
Screen.pixels[x+y*64]=state;
return 0;
}
void ScreenPixelFlip(int x, int y){
@ -51,6 +54,11 @@ void ScreenPixelFlip(int x, int y){
Screen.pixels[x+y*64]=0;
}
void ScreenWH(int *width, int *height){
*width=64;
*height=32;
}
void ScreenClose(){
CloseWindow(); // Close window and OpenGL context
}

View file

@ -15,7 +15,7 @@ typedef struct SCREEN_DATA {
void ScreenInit(int width, int height);
void ScreenClear();
void ScreenSetPixel(int x, int y, unsigned char state);
void ScreenPixelFlip(int x, int y);
char ScreenPixelApply(int x, int y, unsigned char state);
void ScreenWH(int *width, int *height);
void ScreenUpdate();
void ScreenClose();

View file

@ -8,6 +8,7 @@ VCPU_State State;
void VCPUInit(){
State.PC=ADDR_ROM;
State.S=0;
}
void VCPUFetch(){
@ -54,12 +55,26 @@ void VCPUExecute(){
State.I=State.NNN;
break
;;
case 0xD:
case 0xD: // Draw a sprite
int X=State.V[State.X]%63;
int Y=State.V[State.Y]%31;
State.V[REG_FLAG]=0; // Set flag to 0
int width,height;
ScreenWH(&width,&height);
for(char row=0;row<State.N;row++){
// Stop if row out of screen
if(Y+row>=height)
break;
char sprite;
MemRead(&sprite,1,State.I+row); // Load sprite
// Draw sprite
for(int shift=0;shift<8;shift++){
// Stop if column is out of screen
if(X+shift >= width)
break;
if(ScreenPixelApply(X+shift,Y+row,(sprite>>(7-shift))&0x1))
State.V[REG_FLAG]=1;
}
}
break;
;;