diff options
| author | 2019-09-23 22:39:37 -0400 | |
|---|---|---|
| committer | 2019-09-23 22:39:37 -0400 | |
| commit | 4c4110d6529a502efba928ffb03af64816053eb9 (patch) | |
| tree | c4e687e01ad37691128d93e32e853877e56ce731 | |
| parent | 1ea493d0d11d19dd3777f3e2646bce19929f786a (diff) | |
| download | chip8-4c4110d6529a502efba928ffb03af64816053eb9.tar.gz chip8-4c4110d6529a502efba928ffb03af64816053eb9.tar.bz2 chip8-4c4110d6529a502efba928ffb03af64816053eb9.zip | |
improve ui and implement 2 more instructions
| -rwxr-xr-x | Makefile | 2 | ||||
| -rw-r--r-- | chip8.c | 16 | ||||
| -rw-r--r-- | chip8.h | 2 | ||||
| -rw-r--r-- | ui.c | 40 |
4 files changed, 50 insertions, 10 deletions
@@ -9,7 +9,7 @@ win: BIN = chip8.exe all: executable
win: executable
-all: LDFLAGS = -lncursesw -ltinfow -lpthread
+all: LDFLAGS = -lncursesw -lpthread
win: LDFLAGS = ./win/pdcurses.a
executable: chip8.c ui.c util.c
@@ -55,9 +55,6 @@ void push_top_of_stack(u16 val) { } void vm_thread(void* v) { - if (vm.PC > vm.rom_size) { - return; - } // read 2 bytes and convert to big-endian u16 instr = htons(vm.rom[(vm.PC) - 0x1FF]<<8 | vm.rom[(vm.PC) - 0x200]); @@ -113,6 +110,19 @@ void vm_thread(void* v) { case '2': vm.Vx[hex_char(str[1])] &= vm.Vx[hex_char(str[2])]; break; + case '3': + vm.Vx[hex_char(str[1])] ^= vm.Vx[hex_char(str[2])]; + break; + case '4': + vm.Vx[hex_char(str[1])] += vm.Vx[hex_char(str[2])] + if (vm.Vx[hex_char(str[1])] + vm.Vx[hex_char(str[2])] > 255) { + vm.Vx[15] = 1; + vm.Vx[hex_char(str[1])] &= 0x255; + } else { + vm.Vx[15] = 0; + } + break; + } } @@ -19,6 +19,8 @@ typedef struct { u16 I; u8 Vx[16]; + + u8 screen[64][32]; } chip8_vm; extern chip8_vm vm; @@ -5,6 +5,7 @@ #include <stdlib.h> #include "chip8.h" +#include "util.h" void init_curses() { initscr(); @@ -14,6 +15,38 @@ void init_curses() { clear(); } +void draw() { + for (int x = 0; x < 64; x++) { + for (int y = 0; y < 32; y++) { + if (vm.screen[x][y]) { + mvaddstr(x * 2, y, "[]"); + } + } + } + + char buf[25]; + for (int i = 0; i < 7; i++) { + sprintf(buf, "V%x: 0x%x", i, vm.Vx[i]); + mvaddstr(34, 9 * i, buf); + } + for (int i = 7; i < 15; i++) { + sprintf(buf, "V%x: 0x%x", i, vm.Vx[i]); + mvaddstr(35, 9 * (i - 8), buf); + } + sprintf(buf, "Vf: 0x%x", vm.Vx[15]); + mvaddstr(36, 0, buf); + sprintf(buf, "SP: 0x%x", vm.SP); + mvaddstr(36, 9, buf); + sprintf(buf, "DT: 0x%x", vm.DT); + mvaddstr(36, 18, buf); + sprintf(buf, "ST: 0x%x", vm.ST); + mvaddstr(36, 27, buf); + sprintf(buf, "PC: 0x%x", vm.PC); + mvaddstr(36, 36, buf); + sprintf(buf, "I: 0x%x", vm.I); + mvaddstr(36, 46, buf); +} + void curses_thread(void* v) { char c; while(1) { @@ -22,12 +55,7 @@ void curses_thread(void* v) { endwin(); exit(1); } - mvaddstr(0, 0, "V0 V1 V2 V3 V4 V5 V6 V7 V8 V9 VA VB VC VD VE VF"); - char buf[5]; - for (int i = 0; i < 16; i++) { - sprintf(buf, "%i", vm.Vx[i]); - mvaddstr(1, i * 4, buf); - } + draw(); usleep(100); } } |