Browse Source

Adding exection speed control and fixing skp/sknp instructions

master
MisterCyb 1 month ago
parent
commit
e0154c31aa
3 changed files with 17 additions and 8 deletions
  1. 10
    4
      CHIP8.c
  2. 6
    4
      Machine.c
  3. 1
    0
      README.md

+ 10
- 4
CHIP8.c View File

@@ -48,7 +48,7 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
}while(Bfile_FindNext(file, &actual_name[0], &info) == 0);

// Main loop
while(1){
while(key != KEY_CTRL_MENU){
// The key part
if(key == KEY_CTRL_EXE)
Run_Program(names + selected_program * FILENAME_SIZE);
@@ -92,7 +92,7 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
Print((unsigned char*)"No program found");

ML_display_vram();
while(1);
while(!IsKeyDown(KEY_CTRL_MENU));
}

return 1;
@@ -117,7 +117,7 @@ void PrintLine_FONTCHARACTER(const FONTCHARACTER *text){
}

void Run_Program(const FONTCHARACTER *fileName){
int file, i;
int file, i, time_to_wait = 5;
Machine_State state;
FONTCHARACTER fn[FILENAME_SIZE + 9];

@@ -147,8 +147,14 @@ void Run_Program(const FONTCHARACTER *fileName){
ML_clear_vram();
ML_display_vram();
while(!IsKeyDown(KEY_CTRL_EXIT))
while(!IsKeyDown(KEY_CTRL_EXIT)){
if(time_to_wait > 0)
time_to_wait -= IsKeyDown(KEY_CTRL_UP);
time_to_wait += IsKeyDown(KEY_CTRL_DOWN);
Sleep(time_to_wait);

Machine_Update(&state);
}

Bfile_CloseFile(file);
}

+ 6
- 4
Machine.c View File

@@ -203,7 +203,7 @@ void Machine_Update(Machine_State* state){

/* RND Vx, kk */
case 0xC0:
state->V[state->Memory[state->PC] & 0x0F] = (rand() * 255 / RAND_MAX);
state->V[state->Memory[state->PC] & 0x0F] = (rand() * 0xFF) / RAND_MAX;
state->V[state->Memory[state->PC] & 0x0F] &= kk;
break;

@@ -211,7 +211,7 @@ void Machine_Update(Machine_State* state){
case 0xD0:
x = state->V[state->Memory[state->PC] & 0x0F];
y = state->V[state->Memory[state->PC + 1] >> 4];
// If any pixel is erased, then V15 = 1
// If any black pixel is cleared, then V15 = 1
state->V[15] = 0;

for(i = 0; i < (state->Memory[state->PC + 1] & 0x0F); i++){
@@ -230,10 +230,12 @@ void Machine_Update(Machine_State* state){

/* SKP/SKNP Vx */
case 0xE0:
/* SKP Vx */
if(kk == 0x9E && getKeyPressed() == (state->V[state->Memory[state->PC] & 0x0F]))
state->PC += 2;

if(kk == 0xA1 && getKeyPressed() == (state->V[state->Memory[state->PC] & 0x0F]))
/* SKNP Vx */
if(kk == 0xA1 && getKeyPressed() != (state->V[state->Memory[state->PC] & 0x0F]))
state->PC += 2;
break;

@@ -302,7 +304,7 @@ void Machine_Update(Machine_State* state){
}

int getKeyPressed(){
if(IsKeyDown(KEY_CHAR_7)) return 0x1;
if(IsKeyDown(KEY_CHAR_8)) return 0x2;
if(IsKeyDown(KEY_CHAR_9)) return 0x3;

+ 1
- 0
README.md View File

@@ -10,6 +10,7 @@ Use Exe to play the selected game.
# The controls in game

Use Exit to leave the game.
Use Up and Down to speed up or slow down the emulator.
And for playing, use the following keys :
[Emulator key]=[Calcuator's key]
1=7 2=8 3=9 C=Del

Loading…
Cancel
Save