Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/core/emu_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ int32_t decode_exec(emu *chip8, options_config *config) {
switch (chip8->opcode >> 12) { // Check first hex nibble & execute opcode accordingly
case (0x0):
if (chip8->opcode == 0x00e0) {
for (int x = 0; x < DISPLAY_WIDTH; ++x) {
for (int y = 0; y < DISPLAY_HEIGHT; ++y) {
for (int32_t x = 0; x < DISPLAY_WIDTH; ++x) {
for (int32_t y = 0; y < DISPLAY_HEIGHT; ++y) {
chip8->pixels[x][y] = 0;
}
}
Expand Down Expand Up @@ -265,13 +265,13 @@ int32_t decode_exec(emu *chip8, options_config *config) {
break;

case (0x55):
for (int i = 0x0; i <= X; ++i) {
for (int32_t i = 0x0; i <= X; ++i) {
chip8->ram[(chip8->I + i) % RAM_SIZE] = chip8->reg[i];
}
break;

case (0x65):
for (int i = 0x0; i <= X; ++i) {
for (int32_t i = 0x0; i <= X; ++i) {
chip8->reg[i] = chip8->ram[(chip8->I + i) % RAM_SIZE];
}
break;
Expand All @@ -288,9 +288,9 @@ int32_t decode_exec(emu *chip8, options_config *config) {

chip8->reg[0xF] = 0;

for (int y = 0; y < N1; ++y) {
for (int32_t y = 0; y < N1; ++y) {
uint8_t pixel = chip8->ram[chip8->I + y];
for (int x = 0; x < 8; ++x) {
for (int32_t x = 0; x < 8; ++x) {
if ((pixel & (0x80 >> x)) != 0) {
if (X + x < DISPLAY_WIDTH && Y + y < DISPLAY_HEIGHT) {
if (chip8->pixels[X + x][Y + y] == 1) {
Expand All @@ -304,8 +304,8 @@ int32_t decode_exec(emu *chip8, options_config *config) {

// Save pixels into a virtual Texture
Image pixels = GenImageColor(DISPLAY_WIDTH, DISPLAY_HEIGHT, config->background_color);
for (int y = 0; y < DISPLAY_HEIGHT; ++y) {
for (int x = 0; x < DISPLAY_WIDTH; ++x) {
for (int32_t y = 0; y < DISPLAY_HEIGHT; ++y) {
for (int32_t x = 0; x < DISPLAY_WIDTH; ++x) {
if (chip8->pixels[x][y] == 1) {
ImageDrawPixel(&pixels, x, y, config->pixel_color);
}
Expand Down
25 changes: 14 additions & 11 deletions src/core/emu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void emu_stop(emu *chip8, AudioStream beep) {
ClearBackground(BLACK);
TraceLog(LOG_INFO, "EMU_MAIN -> Stopped emulation");
SetWindowState(FLAG_WINDOW_RESIZABLE);
SetExitKey(KEY_ESCAPE);
}

void check_input(emu *chip8) { // I'm sorry, I tried it with a switch but nope...
Expand Down Expand Up @@ -78,13 +79,13 @@ void check_input(emu *chip8) { // I'm sorry, I tried it with a switch but
// Audio frequency values
float frequency = 440.0f, audio_frequency = 440.0f, sine_index = 0.0f, sample = 35000.0f;

void generate_beep(void *buffer, unsigned int frames) {
void generate_beep(void *buffer, uint32_t frames) {
audio_frequency = frequency + (audio_frequency - frequency) * 0.95f;

float increase = audio_frequency / sample;
short *d = (short *) buffer;

for (unsigned int i = 0; i < frames; i++) {
for (uint32_t i = 0; i < frames; i++) {
d[i] = (short) (16000.0f * sinf(2 * PI * sine_index));
sine_index += increase;
if (sine_index > 1.0f) sine_index -= 1.0f;
Expand All @@ -96,32 +97,32 @@ int32_t emu_main(options_config *config, ui_scale *scale) {
bool undefined = false;

TraceLog(LOG_INFO, "EMU_MAIN -> Starting emulation");
for (int i = 0; i < RAM_SIZE; ++i) {
for (int32_t i = 0; i < RAM_SIZE; ++i) {
chip8.ram[i] = 0;
}
TraceLog(LOG_INFO, "EMU_MAIN -> Cleared RAM");
for (int i = 0; i < STACK_SIZE; ++i) {
for (int32_t i = 0; i < STACK_SIZE; ++i) {
chip8.stack[i] = 0;
}
chip8.i_stack = -1;
TraceLog(LOG_INFO, "EMU_MAIN -> Cleared Stack");
for (int i = 0; i < REGISTER_SIZE; ++i) {
for (int32_t i = 0; i < REGISTER_SIZE; ++i) {
chip8.reg[i] = 0;
}
TraceLog(LOG_INFO, "EMU_MAIN -> Cleared registers");
if (gui_load_file(&chip8) == -1) { // LOAD DROPPED FILE, IF NOT A ROM RETURN
TraceLog(LOG_INFO, "EMU_MAIN -> Emulation stopped");
return -1;
}
for (int i = 0; i < FONT_SIZE; ++i) {
for (int32_t i = 0; i < FONT_SIZE; ++i) {
chip8.ram[i] = FONT[i];
}
TraceLog(LOG_INFO, "EMU_MAIN -> Loaded FONT into RAM");
chip8.pc = 0x200;
TraceLog(LOG_INFO, "EMU_MAIN -> Set pc to Address 0x200");

for (int x = 0; x < DISPLAY_WIDTH; ++x) {
for (int y = 0; y < DISPLAY_HEIGHT; ++y) {
for (int32_t x = 0; x < DISPLAY_WIDTH; ++x) {
for (int32_t y = 0; y < DISPLAY_HEIGHT; ++y) {
chip8.pixels[x][y] = 0;
}
}
Expand All @@ -135,6 +136,8 @@ int32_t emu_main(options_config *config, ui_scale *scale) {
SetAudioStreamCallback(beep, generate_beep);
SetAudioStreamVolume(beep, config->volume);

SetExitKey(KEY_NULL);

while (!IsKeyPressed(KEY_ESCAPE)) {
BeginDrawing();

Expand All @@ -156,11 +159,11 @@ int32_t emu_main(options_config *config, ui_scale *scale) {
DrawTextureEx(chip8.display, (Vector2) {0, 0}, 0, (float) config->display_scaling, WHITE);

if (config->show_fps) {
DrawText(TextFormat("%dhz", GetFPS() + 1), (int) config->display_scaling, (int) config->display_scaling / 2,
(int) (GetScreenHeight() / (config->display_scaling * 1.5)), DARKGREEN);
DrawText(TextFormat("%dhz", GetFPS() + 1), (int32_t) config->display_scaling, (int32_t) config->display_scaling / 2,
(int32_t) (GetScreenHeight() / (config->display_scaling * 1.5)), DARKGREEN);
}

for (int i = 0; i < (int) (CLOCK_RATE / REFRESH_RATE); ++i) {
for (int32_t i = 0; i < (int32_t) (CLOCK_RATE / REFRESH_RATE); ++i) {
check_input(&chip8);
if (!undefined && fetch(&chip8) == -1) {
undefined = true;
Expand Down
8 changes: 4 additions & 4 deletions src/gui/options_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void load_settings(options_config *config) {
// READ OPTIONS
char line[100];
int32_t temp;
for (int i = 0; i < items; ++i) {
for (int32_t i = 0; i < items; ++i) {
fgets(line, 100, file);
uint16_t color[4] = {0, 0, 0, 0};
uint32_t counter = 0;
Expand All @@ -76,7 +76,7 @@ void load_settings(options_config *config) {

switch (i) {
case 0:
for (int j = 0; line[j] != ';'; ++j) {
for (int32_t j = 0; line[j] != ';'; ++j) {
if (isnumber(line[j]) && color[counter] > 0) {
color[counter] = (color[counter] * 10) + line[j] - '0';
} else if (isnumber(line[j])) {
Expand All @@ -90,7 +90,7 @@ void load_settings(options_config *config) {
break;

case 1:
for (int j = 0; line[j] != ';'; ++j) {
for (int32_t j = 0; line[j] != ';'; ++j) {
if (isnumber(line[j]) && color[counter] > 0) {
color[counter] = (color[counter] * 10) + line[j] - '0';
} else if (isnumber(line[j])) {
Expand All @@ -104,7 +104,7 @@ void load_settings(options_config *config) {
break;

case 2:
for (int j = 0; line[j] != ';'; ++j) {
for (int32_t j = 0; line[j] != ';'; ++j) {
if (isnumber(line[j]) && color[0] > 0) {
color[0] = (color[0] * 10) + line[j] - '0';
} else if (isnumber(line[j])) {
Expand Down