8

a CHIP-8 emulator
Log | Files | Refs | README

commit d34851144fe8a99cb3a5fb5e11ef746ef5385d68
parent 347eb87157a3f97b4f0f6c87e8dfa79b8f424dba
Author: Naveen Narayanan <zerous@nocebo.space>
Date:   Fri, 26 Jul 2024 00:41:40 +0200

Style Fix

Diffstat:
M8.c | 62+++++++++++++++++++++++++++++++-------------------------------
Mav.c | 44++++++++++++++++++++++----------------------
2 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/8.c b/8.c @@ -54,11 +54,11 @@ init(int fd, size_t sz) { size_t r, t; - t = sz; - mem = malloc(4096); + t = sz; + mem = malloc(4096); if (mem == NULL) err(1, "malloc failed"); - memset(mem, 0, 4096); + memset(mem, 0, 4096); pc = START; memcpy(mem, fnt, 80); @@ -74,19 +74,19 @@ init(int fd, size_t sz) void predraw(unsigned short n, unsigned short x, unsigned y) { - uint16_t px; + uint16_t px; - V[0xF] = 0; + V[0xF] = 0; for (int yy = 0; yy < n; ++yy) { px = mem[I + yy]; for (int xx = 0; xx < 8; ++xx) { if ((px & (0x80 >> xx)) != 0) { - if (scene[(V[x] + xx + ((V[y] + yy) * 64))] == 1) - V[0xF] = 1; - scene[V[x] + xx + ((V[y] + yy) * 64)] ^= 1; - } - } - } + if (scene[(V[x] + xx + ((V[y] + yy) * 64))] == 1) + V[0xF] = 1; + scene[V[x] + xx + ((V[y] + yy) * 64)] ^= 1; + } + } + } draw(scene); } @@ -97,60 +97,60 @@ execute(void) switch (opcode & 0xF000) { case 0x0000: - switch (opcode & 0x0FFF) { + switch (opcode & 0x0FFF) { case 0xe0: //fprintf(stderr,"[OK] 0x%X: 00E0\n", opcode); - memset(scene, 0, 2048); + memset(scene, 0, 2048); pc += 2; return; case 0xee: //fprintf(stderr,"[OK] 0x%X: 00EE\n", opcode); pc = *sp--; - pc += 2; + pc += 2; return; } case 0x1000: - //fprintf(stderr,"[OK] 0x%X: 1NNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: 1NNN\n", opcode); pc = opcode & 0x0FFF; return; case 0x2000: - //fprintf(stderr,"[OK] 0x%X: 2NNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: 2NNN\n", opcode); *++sp = pc; pc = opcode & 0x0FFF; return; case 0x3000: - //fprintf(stderr,"[OK] 0x%X: 3XNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: 3XNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = opcode & 0x00FF; if (V[x] == c) pc += 2; - pc += 2; + pc += 2; return; case 0x4000: - //fprintf(stderr,"[OK] 0x%X: 4XNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: 4XNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = opcode & 0x00FF; if (V[x] != c) pc += 2; - pc += 2; + pc += 2; return; case 0x5000: - //fprintf(stderr,"[OK] 0x%X: 5XY0\n", opcode); + //fprintf(stderr,"[OK] 0x%X: 5XY0\n", opcode); x = (opcode & 0x0F00) >> 8; y = (opcode & 0x00F0) >> 4; if (V[x] == V[y]) pc += 2; - pc += 2; + pc += 2; return; case 0x6000: - //fprintf(stderr,"[OK] 0x%X: 6XNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: 6XNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = opcode & 0x00FF; V[x] = c; pc += 2; return; case 0x7000: - //fprintf(stderr,"[OK] 0x%X: 7XNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: 7XNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = opcode & 0x00FF; V[x] += c; @@ -213,7 +213,7 @@ execute(void) } case 0x9000: //fprintf(stderr,"[OK] 0x%X: 9XY0\n", opcode); - //fprintf(stderr, "0x9000\n"); + //fprintf(stderr, "0x9000\n"); x = (opcode & 0x0F00) >> 8; y = (opcode & 0x00F0) >> 4; if (V[x] != V[y]) @@ -221,17 +221,17 @@ execute(void) pc += 2; return; case 0xA000: - //fprintf(stderr,"[OK] 0x%X: ANNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: ANNN\n", opcode); I = opcode & 0x0FFF; pc += 2; return; case 0xB000: //fprintf(stderr,"[OK] 0x%X: BNNN\n", opcode); - //fprintf(stderr, "0xB000\n"); + //fprintf(stderr, "0xB000\n"); pc = V[0] + (opcode & 0x0FFF); return; case 0xC000: - //fprintf(stderr,"[OK] 0x%X: CXNN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: CXNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = (opcode & 0x00FF); V[x] = (rand() % 256) & c; @@ -239,7 +239,7 @@ execute(void) pc += 2; return; case 0xD000: - //fprintf(stderr,"[OK] 0x%X: DXYN\n", opcode); + //fprintf(stderr,"[OK] 0x%X: DXYN\n", opcode); n = (opcode & 0x00F); x = (opcode & 0x0F00) >> 8; y = (opcode & 0x00F0) >> 4; @@ -300,7 +300,7 @@ execute(void) //fprintf(stderr,"[OK] 0x%X: FX33\n", opcode); mem[I] = (V[x] % 1000) / 100; mem[I + 1] = (V[x] % 100) / 10; - mem[I + 2] = V[x] % 10; + mem[I + 2] = V[x] % 10; return; case 0x0055: //fprintf(stderr,"[OK] 0x%X: FX55\n", opcode); @@ -333,7 +333,7 @@ cycle() { static int n; - opcode = mem[pc] << 8 | mem[pc + 1]; + opcode = mem[pc] << 8 | mem[pc + 1]; //fprintf(stderr, "opc: 0x%hx\n", opcode); execute(); handleev(); diff --git a/av.c b/av.c @@ -67,7 +67,7 @@ timer(unsigned int interval, void *) soundtmr--; beep(); } - return interval; + return interval; } void @@ -83,38 +83,38 @@ sdlinit(void) R = SDL_CreateRenderer(W, -1, SDL_RENDERER_ACCELERATED); if (R == NULL) errx(1, "SDL_CreateRenderer failed: %s\n", SDL_GetError()); - if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) + if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) errx(1, "Mix_OpenAudio failed: %s\n", Mix_GetError()); - M = Mix_LoadMUS("assets/beep.wav"); + M = Mix_LoadMUS("assets/beep.wav"); if (M == NULL) errx(1, "Mix_LoadMUS failed: %s\n", Mix_GetError()); - T = SDL_AddTimer(16, timer, NULL); - if (T == 0) - errx(1, "Mix_LoadMUS failed: %s\n", Mix_GetError()); + T = SDL_AddTimer(16, timer, NULL); + if (T == 0) + errx(1, "Mix_LoadMUS failed: %s\n", Mix_GetError()); } int makesound(void *) { - unsigned int tick; - - tick = SDL_GetTicks(); - while (1) { - if (Mix_PlayingMusic()) { - if ((SDL_GetTicks() - tick) > 4) { - Mix_HaltMusic(); - return 0; - } - } else { - Mix_PlayMusic(M, -1); - } - } + unsigned int tick; + + tick = SDL_GetTicks(); + while (1) { + if (Mix_PlayingMusic()) { + if ((SDL_GetTicks() - tick) > 4) { + Mix_HaltMusic(); + return 0; + } + } else { + Mix_PlayMusic(M, -1); + } + } } void beep(void) { - SDL_CreateThread(makesound, "BEEP", NULL); + SDL_CreateThread(makesound, "BEEP", NULL); } int @@ -145,7 +145,7 @@ sdlquit(void) { SDL_DestroyRenderer(R); SDL_DestroyWindow(W); - Mix_FreeMusic(M); - SDL_RemoveTimer(T); + Mix_FreeMusic(M); + SDL_RemoveTimer(T); SDL_Quit(); }