diff options
| author | 2019-10-07 12:23:40 -0400 | |
|---|---|---|
| committer | 2019-10-07 12:23:40 -0400 | |
| commit | 4c5482d30566124e18930a56153c636527b67971 (patch) | |
| tree | 2483079418fabd912dbc17d17c35146e97202966 | |
| parent | 02852b1c8c6ba40af2c972dcaf0aaae04d16c2f0 (diff) | |
| download | chip8-4c5482d30566124e18930a56153c636527b67971.tar.gz chip8-4c5482d30566124e18930a56153c636527b67971.tar.bz2 chip8-4c5482d30566124e18930a56153c636527b67971.zip | |
rom->ram, change colors and fix comment
| -rw-r--r-- | chip8.c | 31 | ||||
| -rw-r--r-- | chip8.h | 2 | ||||
| -rw-r--r-- | ui_sdl.c | 4 |
3 files changed, 18 insertions, 19 deletions
@@ -42,8 +42,9 @@ static u8 font[] = { void init_vm() { vm.PC = 0x200; // start of chip8 programs + // write fonts into memory for (int i = 0; i < sizeof(font); i++) { - vm.rom[FONT_OFFSET + i] = font[i]; + vm.ram[FONT_OFFSET + i] = font[i]; } } @@ -55,14 +56,14 @@ void load_rom(char *file_path) { off_t fsize = ftell(f); rewind(f); - vm.rom = (u8*)malloc(0xFFF); + vm.ram = (u8*)malloc(0xFFF); - memset(vm.rom, 0, 0xFFF); + memset(vm.ram, 0, 0xFFF); #ifdef _WIN32 - size_t res = read(fd, &vm.rom[0x200], fsize); + size_t res = read(fd, &vm.ram[0x200], fsize); #else - size_t res = fread(&vm.rom[0x200], 1, fsize, f); + size_t res = fread(&vm.ram[0x200], 1, fsize, f); #endif if (res != fsize) { @@ -74,7 +75,7 @@ void load_rom(char *file_path) { void vm_step() { // read 2 bytes and convert to big-endian - u16 in = htons(vm.rom[vm.PC + 0x1]<<8 | vm.rom[vm.PC]); + u16 in = htons(vm.ram[vm.PC + 0x1]<<8 | vm.ram[vm.PC]); // in>>12&0xF 0xFFFF // ^ @@ -84,12 +85,10 @@ void vm_step() { // ^ // in&0xF 0xFFFF // ^ - // in&0xFFF 0xFFFF - // ^^^ - // in&0xFF 0xFFFF - // ^^ // in&0xFF 0xFFFF // ^^ + // in&0xFFF 0xFFFF + // ^^^ switch ((in>>12&0xF)) { case 0x0: @@ -198,7 +197,7 @@ void vm_step() { vm.Vx[0xF] = 0; for (u32 i = 0; i < (in&0xF); i++) { for (u32 s = 0; s < 8; s++) { - u8 pix = (vm.rom[vm.I + i] & (0x80 >> s)) != 0; + u8 pix = (vm.ram[vm.I + i] & (0x80 >> s)) != 0; if (pix) { u8 y = (vm.Vx[in>>4&0xF] + i)&0x1F; @@ -250,18 +249,18 @@ void vm_step() { vm.I = FONT_OFFSET + (vm.Vx[in>>8&0xF] * 5); break; case 0x33: // LD B, Vx - vm.rom[vm.I] = (vm.Vx[in>>8&0xF] / 100); - vm.rom[vm.I+0x1] = ((vm.Vx[in>>8&0xF] % 100)/10); - vm.rom[vm.I+0x2] = (vm.Vx[in>>8&0xF] % 10); + vm.ram[vm.I] = (vm.Vx[in>>8&0xF] / 100); + vm.ram[vm.I+0x1] = ((vm.Vx[in>>8&0xF] % 100)/10); + vm.ram[vm.I+0x2] = (vm.Vx[in>>8&0xF] % 10); break; case 0x55: // LD [I], Vx for (u8 i = 0; i <= (in>>8&0xF); i++) { - vm.rom[(vm.I) + i] = vm.Vx[i]; + vm.ram[(vm.I) + i] = vm.Vx[i]; } break; case 0x65: // LD Vx, [I] for (u8 i = 0; i <= (in>>8&0xF); i++) { - vm.Vx[i] = vm.rom[(vm.I) + i]; + vm.Vx[i] = vm.ram[(vm.I) + i]; } break; } @@ -7,7 +7,7 @@ void vm_step(); void load_rom(); typedef struct { - u8* rom; + u8* ram; u16 PC; @@ -24,9 +24,9 @@ void setup() { void draw() { SDL_Rect box = (SDL_Rect){1, 0, 10, 10}; - SDL_SetRenderDrawColor(r, 50, 0, 0, 255); + SDL_SetRenderDrawColor(r, 12, 5, 9, 255); SDL_RenderClear(r); - SDL_SetRenderDrawColor(r, 160, 200, 255, 255); + SDL_SetRenderDrawColor(r, 228, 167, 104, 255); //SDL_RenderFillRect(r, &box); for (int x = 0; x <= 0x3F; x++) { for (int y = 0; y <= 0x1F; y++) { |