Minor changes

This commit is contained in:
Loïc Guégan 2023-12-25 21:21:20 +01:00
parent 309e9921f8
commit c50ed6ba73
6 changed files with 51 additions and 6 deletions

View file

@ -1,7 +1,7 @@
EXEC=chip-8
$(EXEC): main.c screen.c mem.c vcpu.c
$(EXEC): main.c screen.c mem.c vcpu.c keypad.c
gcc -lraylib $^ -o $@
clean:

28
src/keypad.c Normal file
View file

@ -0,0 +1,28 @@
#include "keypad.h"
int map[]={
KEY_X, // 0
KEY_ONE, // 1
KEY_TWO, // 2
KEY_THREE, // 3
KEY_Q, // 4
KEY_W, // 5
KEY_E, // 6
KEY_A, // 7
KEY_S, // 8
KEY_D, // 9
KEY_Z, // A
KEY_C, // B
KEY_FOUR, // C
KEY_R, // D
KEY_F, // E
KEY_V // F
};
int KeypadIsPressed(unsigned char c){
if(c<=0xF){
if(IsKeyPressed(map[c]))
return 1;
}
return 0;
}

6
src/keypad.h Normal file
View file

@ -0,0 +1,6 @@
#pragma once
#include "raylib.h"
int KeypadIsPressed(unsigned char c);

View file

@ -13,7 +13,7 @@ int main(int argc, char *argv[])
// Initialize
MemInit();
MemLoadROM("../roms/chiptest.ch8");
MemLoadROM("../roms/chip8-test-suite/5-quirks.ch8");
ScreenInit(800,400);
VCPUInit();
@ -21,9 +21,11 @@ int main(int argc, char *argv[])
int i=0;
while (!WindowShouldClose()){
for(int i=0;i<500;i++){
VCPUFetch();
VCPUDecode();
VCPUExecute();
VCPUExecute();
}
ScreenUpdate();
}

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(200); // Set game to run at 60 frames-per-second
SetTargetFPS(500); // Set game to run at 60 frames-per-second
}
void ScreenClear() {

View file

@ -1,6 +1,8 @@
#include "vcpu.h"
#include "mem.h"
#include "screen.h"
#include "keypad.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@ -201,7 +203,14 @@ void VCPUExecute(){
break;
case 0xE:
// TODO
if(State.NN==0x9E){ // Skip if keypress in VX
if(KeypadIsPressed(State.V[State.X]&0x0F)){
State.PC+=2;
}
}else if(State.NN==0xA1){ // Skip if not keypress in VX
if(!KeypadIsPressed(State.V[State.X]&0x0F))
State.PC+=2;
}
break;
case 0xF:
@ -236,7 +245,7 @@ void VCPUExecute(){
MemStore(&hundreds,1,State.I);
MemStore(&tens,1,State.I+1);
MemStore(&units,1,State.I+2);
// printf("hundreds:%d tens:%d units:%d byte:%d\n",hundreds,tens,units,State.V[State.X]);
//printf("hundreds:%d tens:%d units:%d byte:%d\n",hundreds,tens,units,State.V[State.X]);
break;
case 0x55: