Minor changes
This commit is contained in:
parent
8fd3d27abe
commit
7642efad5a
7 changed files with 31 additions and 8 deletions
BIN
roms/logo_chip8.ch8
Normal file
BIN
roms/logo_chip8.ch8
Normal file
Binary file not shown.
BIN
roms/logo_ibm.ch8
Normal file
BIN
roms/logo_ibm.ch8
Normal file
Binary file not shown.
|
@ -7,7 +7,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
MemInit();
|
MemInit();
|
||||||
MemLoadROM("../roms/2-ibm-logo.ch8");
|
MemLoadROM("../roms/logo_chip8.ch8");
|
||||||
|
|
||||||
ScreenInit(800,400);
|
ScreenInit(800,400);
|
||||||
VCPUInit();
|
VCPUInit();
|
||||||
|
|
14
src/screen.c
14
src/screen.c
|
@ -15,7 +15,7 @@ void ScreenInit(int width, int height){
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_ERROR); // Disable anoying raylib logs
|
SetTraceLogLevel(LOG_ERROR); // Disable anoying raylib logs
|
||||||
InitWindow(width, height, "Chip-8 Emulator");
|
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() {
|
void ScreenClear() {
|
||||||
|
@ -40,8 +40,11 @@ void ScreenUpdate(){
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetPixel(int x, int y, unsigned char state){
|
char ScreenPixelApply(int x, int y, unsigned char state){
|
||||||
Screen.pixels[x+y*64]=(state==0) ? 0: 1;
|
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){
|
void ScreenPixelFlip(int x, int y){
|
||||||
|
@ -51,6 +54,11 @@ void ScreenPixelFlip(int x, int y){
|
||||||
Screen.pixels[x+y*64]=0;
|
Screen.pixels[x+y*64]=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScreenWH(int *width, int *height){
|
||||||
|
*width=64;
|
||||||
|
*height=32;
|
||||||
|
}
|
||||||
|
|
||||||
void ScreenClose(){
|
void ScreenClose(){
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ typedef struct SCREEN_DATA {
|
||||||
|
|
||||||
void ScreenInit(int width, int height);
|
void ScreenInit(int width, int height);
|
||||||
void ScreenClear();
|
void ScreenClear();
|
||||||
void ScreenSetPixel(int x, int y, unsigned char state);
|
char ScreenPixelApply(int x, int y, unsigned char state);
|
||||||
void ScreenPixelFlip(int x, int y);
|
void ScreenWH(int *width, int *height);
|
||||||
void ScreenUpdate();
|
void ScreenUpdate();
|
||||||
void ScreenClose();
|
void ScreenClose();
|
||||||
|
|
19
src/vcpu.c
19
src/vcpu.c
|
@ -8,6 +8,7 @@ VCPU_State State;
|
||||||
|
|
||||||
void VCPUInit(){
|
void VCPUInit(){
|
||||||
State.PC=ADDR_ROM;
|
State.PC=ADDR_ROM;
|
||||||
|
State.S=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCPUFetch(){
|
void VCPUFetch(){
|
||||||
|
@ -54,12 +55,26 @@ void VCPUExecute(){
|
||||||
State.I=State.NNN;
|
State.I=State.NNN;
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
case 0xD:
|
case 0xD: // Draw a sprite
|
||||||
int X=State.V[State.X]%63;
|
int X=State.V[State.X]%63;
|
||||||
int Y=State.V[State.Y]%31;
|
int Y=State.V[State.Y]%31;
|
||||||
State.V[REG_FLAG]=0; // Set flag to 0
|
State.V[REG_FLAG]=0; // Set flag to 0
|
||||||
|
int width,height;
|
||||||
|
ScreenWH(&width,&height);
|
||||||
for(char row=0;row<State.N;row++){
|
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;
|
break;
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Reference in a new issue