8

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

commit f61f7d91ef03a964fc8b45ab5ef058fd88fc8ab7
parent babe8eafd82c7c14fe0507f47b1a13863e7a674c
Author: Naveen Narayanan <zerous@nocebo.space>
Date:   Fri, 26 Jul 2024 15:01:59 +0200

Get rid of commented code

Diffstat:
M8.c | 38--------------------------------------
MMakefile | 2+-
2 files changed, 1 insertion(+), 39 deletions(-)

diff --git a/8.c b/8.c @@ -95,27 +95,22 @@ execute(void) case 0x0000: switch (opcode & 0x0FFF) { case 0xe0: - //fprintf(stderr,"[OK] 0x%X: 00E0\n", opcode); memset(scene, 0, 2048); pc += 2; return; case 0xee: - //fprintf(stderr,"[OK] 0x%X: 00EE\n", opcode); pc = *sp--; pc += 2; return; } case 0x1000: - //fprintf(stderr,"[OK] 0x%X: 1NNN\n", opcode); pc = opcode & 0x0FFF; return; case 0x2000: - //fprintf(stderr,"[OK] 0x%X: 2NNN\n", opcode); *++sp = pc; pc = opcode & 0x0FFF; return; case 0x3000: - //fprintf(stderr,"[OK] 0x%X: 3XNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = opcode & 0x00FF; if (V[x] == c) @@ -123,7 +118,6 @@ execute(void) pc += 2; return; case 0x4000: - //fprintf(stderr,"[OK] 0x%X: 4XNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = opcode & 0x00FF; if (V[x] != c) @@ -131,7 +125,6 @@ execute(void) pc += 2; return; case 0x5000: - //fprintf(stderr,"[OK] 0x%X: 5XY0\n", opcode); x = (opcode & 0x0F00) >> 8; y = (opcode & 0x00F0) >> 4; if (V[x] == V[y]) @@ -139,14 +132,12 @@ execute(void) pc += 2; return; case 0x6000: - //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); x = (opcode & 0x0F00) >> 8; c = opcode & 0x00FF; V[x] += c; @@ -158,49 +149,40 @@ execute(void) pc += 2; switch(opcode & 0x000F) { case 0x0000: - //fprintf(stderr,"[OK] 0x%X: 8XY0\n", opcode); V[x] = V[y]; return; case 0x0001: - //fprintf(stderr,"[OK] 0x%X: 8XY1\n", opcode); V[x] |= V[y]; return; case 0x0002: - //fprintf(stderr,"[OK] 0x%X: 8XY2\n", opcode); V[x] &= V[y]; return; case 0x0003: - //fprintf(stderr,"[OK] 0x%X: 8XY3\n", opcode); V[x] ^= V[y]; return; case 0x0004: - //fprintf(stderr,"[OK] 0x%X: 8XY4\n", opcode); V[0xF] = 0; if (V[y] > CHAR_MAX - V[x]) V[0xF] = 1; V[x] += V[y]; return; case 0x0005: - //fprintf(stderr,"[OK] 0x%X: 8XY5\n", opcode); V[0xF] = 0; if (V[y] < V[x]) V[0xF] = 1; V[x] -= V[y]; return; case 0x0006: - //fprintf(stderr,"[OK] 0x%X: 8XY6\n", opcode); V[0xF] = V[x] & 0x01; V[x] >>= 1; return; case 0x0007: - //fprintf(stderr,"[OK] 0x%X: 8XY7\n", opcode); V[0xF] = 0; if (V[x] < V[y]) V[0xF] = 1; V[x] = V[y] - V[x]; return; case 0x000E: - //fprintf(stderr,"[OK] 0x%X: 8XYE\n", opcode); V[0xF] = (V[x] >> 7) & 0x01; V[x] <<= 1; return; @@ -208,8 +190,6 @@ execute(void) goto err; } case 0x9000: - //fprintf(stderr,"[OK] 0x%X: 9XY0\n", opcode); - //fprintf(stderr, "0x9000\n"); x = (opcode & 0x0F00) >> 8; y = (opcode & 0x00F0) >> 4; if (V[x] != V[y]) @@ -217,25 +197,19 @@ execute(void) pc += 2; return; case 0xA000: - //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"); pc = V[0] + (opcode & 0x0FFF); return; case 0xC000: - //fprintf(stderr,"[OK] 0x%X: CXNN\n", opcode); x = (opcode & 0x0F00) >> 8; c = (opcode & 0x00FF); V[x] = (rand() % 256) & c; - //V[x] = 128 & c; pc += 2; return; case 0xD000: - //fprintf(stderr,"[OK] 0x%X: DXYN\n", opcode); n = (opcode & 0x00F); x = (opcode & 0x0F00) >> 8; y = (opcode & 0x00F0) >> 4; @@ -247,12 +221,10 @@ execute(void) pc += 2; switch (opcode & 0x00FF) { case 0x009E: - //fprintf(stderr,"[OK] 0x%X: EX9E\n", opcode); if (key[V[x]]) pc += 2; return; case 0x00A1: - //fprintf(stderr,"[OK] 0x%X: EXA1\n", opcode); if (!key[V[x]]) pc += 2; return; @@ -264,11 +236,9 @@ execute(void) pc += 2; switch (opcode & 0x00FF) { case 0x0007: - //fprintf(stderr,"[OK] 0x%X: FX07\n", opcode); V[x] = delaytmr; return; case 0x000A: - //fprintf(stderr,"[OK] 0x%X: FX0A\n", opcode); for (int i = 0; i < 16; ++i) if (key[i]) { V[x] = i; @@ -277,33 +247,26 @@ execute(void) pc -= 2; return; case 0x0015: - //fprintf(stderr,"[OK] 0x%X: FX15\n", opcode); delaytmr = V[x]; return; case 0x0018: - //fprintf(stderr,"[OK] 0x%X: FX18\n", opcode); soundtmr = V[x]; return; case 0x001E: - //fprintf(stderr,"[OK] 0x%X: FX1E\n", opcode); I += V[x]; return; case 0x0029: - //fprintf(stderr,"[OK] 0x%X: FX29\n", opcode); I = V[x] * 5; return; case 0x0033: - //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; return; case 0x0055: - //fprintf(stderr,"[OK] 0x%X: FX55\n", opcode); memcpy(mem + I, V, x+1); return; case 0x0065: - //fprintf(stderr,"[OK] 0x%X: FX65\n", opcode); memcpy(V, mem + I, x+1); return; default: @@ -328,7 +291,6 @@ static void cycle() { opcode = mem[pc] << 8 | mem[pc + 1]; - //fprintf(stderr, "opc: 0x%hx\n", opcode); execute(); handleev(); if (quit) diff --git a/Makefile b/Makefile @@ -13,7 +13,7 @@ all: $(BIN) .PHONY: clean clean: - -rm -f ${BIN} av 8.o av.o + -rm -f ${BIN} 8.o av.o .SUFFIXES: .c .o