From 4d345079aea612d9bff2d9f86ad537f4dedcf560 Mon Sep 17 00:00:00 2001 From: Godzil Date: Mon, 14 Mar 2022 15:05:18 +0000 Subject: [PATCH] Fix building Most patches are temporary and there just to let the code to build. It will not work in the current state. Also now force the use of paged memory. It was not working properly because of the way the old GPU code is working. --- source/CMakeLists.txt | 10 +++- source/gpu.c | 3 + source/includes/io.h | 10 ---- source/includes/memory.h | 5 +- source/io.c | 5 -- source/memory.c | 120 +------------------------------------ source/peripherals/audio.c | 4 +- source/peripherals/rtc.c | 11 +++- source/ws.c | 19 ++++-- 9 files changed, 42 insertions(+), 145 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index b0085f3..e60d359 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,9 +1,13 @@ -set(SOURCES audio.c emulate.c gpu.c io.c log.c memory.c rom.c ws.c) -set(HEADERS includes/audio.h includes/emulate.h includes/gpu.h includes/io.h includes/log.h includes/memory.h includes/rom.h includes/ws.h) +set(SOURCES emulate.c gpu.c io.c log.c memory.c rom.c ws.c) +set(PERIPHERAL_SOURCES peripherals/audio.c peripherals/buttons.c peripherals/color_gpu.c peripherals/color_system.c + peripherals/debug.c peripherals/dma.c peripherals/eeprom.c peripherals/mono_gpu.c peripherals/mono_system.c + peripherals/rtc.c peripherals/universal_luxor.c) +set(HEADERS includes/audio.h includes/device.h includes/emulate.h includes/gpu.h includes/io.h includes/log.h + includes/memory.h includes/nec.h includes/nec_debugger.h includes/necintrf.h includes/rom.h includes/ws.h) option(FAKE_DISPLAY "Disable OpenGL and fake displaying" OFF) -add_library(wswan ${SOURCES} ${HEADERS}) +add_library(wswan ${SOURCES} ${PERIPHERAL_SOURCES} ${HEADERS}) if (FAKE_DISPLAY) target_compile_options(wswan PRIVATE -DPRETENT_DISPLAY) diff --git a/source/gpu.c b/source/gpu.c index 602aa0f..2dddfb3 100644 --- a/source/gpu.c +++ b/source/gpu.c @@ -23,6 +23,9 @@ extern uint8_t *internalRam; +// TODO: Temporary to let build for now +static uint8_t ws_ioRam[0x100]; + enum VideoModes { DISPLAY_MODE_GRAY = 0, DISPLAY_MODE_2BPP = 4, DISPLAY_MODE_P_4BPP = 7, DISPLAY_MODE_L_4BPP = 6, diff --git a/source/includes/io.h b/source/includes/io.h index 89f2e05..2312c20 100644 --- a/source/includes/io.h +++ b/source/includes/io.h @@ -6,22 +6,12 @@ * Copyright (c) 2014-2022 986-Studio. All rights reserved. * ******************************************************************************/ - -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// #ifndef __IO_H__ #define __IO_H__ #include -extern uint8_t *ws_ioRam; extern uint8_t ws_key_start; extern uint8_t ws_key_x4; extern uint8_t ws_key_x2; diff --git a/source/includes/memory.h b/source/includes/memory.h index cbbaa12..5f3f8e6 100644 --- a/source/includes/memory.h +++ b/source/includes/memory.h @@ -38,8 +38,7 @@ char *create_file(char *filename, uint32_t size); char *load_file(char *filename); void dump_memory(); -//#define USE_PAGED_MEMORY_ACCESS -#ifdef USE_PAGED_MEMORY_ACCESS + /*** * Set a memory page with a ganularity of 4-16 * @param bank: the bank (0-F) to set @@ -68,8 +67,6 @@ typedef enum { void set_iram_access(iram_access_t mode); -#endif - #define mem_readop mem_readmem20 #define mem_readop_arg mem_readmem20 void mem_writemem20(uint32_t addr, uint8_t value); diff --git a/source/io.c b/source/io.c index d21ae29..665f118 100644 --- a/source/io.c +++ b/source/io.c @@ -87,11 +87,6 @@ void io_flipControls(void) void io_done(void) { - if (ws_ioRam == NULL) - { - free(ws_ioRam); - } - #ifdef IO_DUMP fclose(ioLogFp); #endif diff --git a/source/memory.c b/source/memory.c index 1a0b4d1..99ef494 100644 --- a/source/memory.c +++ b/source/memory.c @@ -63,6 +63,8 @@ extern nec_Regs I; void dump_memory() { + // TODO: Need complete rewrite +#if 0 int i; FILE *fp; printf("Dumping memory....\n"); @@ -103,118 +105,9 @@ void dump_memory() /* IP */ fwrite(&I.ip, 1, 2, fp); fclose(fp); +#endif } -#ifndef USE_PAGED_MEMORY_ACCESS -void mem_writemem20(uint32_t addr, uint8_t value) -{ - uint32_t offset = addr & 0xffff; - uint32_t bank = addr >> 16; - - if (!bank) - { - // 0 - RAM - 16 KB (WS) / 64 KB (WSC) internal RAM - ws_gpu_write_byte(offset, value); - ws_audio_write_byte(offset, value); - } - else if (bank == 1) - { - // 1 - SRAM (cart) - ws_staticRam[offset & sramAddressMask] = value; - } - - // other banks are read-only -} - -uint8_t mem_readmem20(uint32_t addr) -{ - uint32_t offset = addr & 0xffff; - uint32_t bank = addr >> 16; - //uint16_t romBank; - uint8_t hwReg; - uint32_t temp; - uint8_t ret; - wssystem_t currentSystem = ws_get_system(); - - switch (bank) - { - case 0: - /* - * So the original WonderSwan, and Color/Crystal in B&W mode have 16KB of IRAM Mapped. - * Color/Crystal in color mode have 64 KB IRAM mapped. - */ - if (ws_gpu_operatingInColor) - { - return (internalRam[offset]); - } - else if (offset < 0x4000) - { - return (internalRam[offset]); - } - - return (0x90); - - case 1: // 1 - SRAM (cart) - return ws_staticRam[offset & sramAddressMask]; - - case 2: - // Bank 2 - hwReg = ws_ioRam[0xC2]; - temp = hwReg << 16; - temp += offset; - temp &= (romSize - 1); - return ws_rom[temp]; - case 3: - // Bank 3 - hwReg = ws_ioRam[0xC3]; - temp = hwReg << 16; - temp += offset; - temp &= (romSize - 1); - return ws_rom[temp]; - - case 0xF: - hwReg = ws_ioRam[0xA0]; - - if (!(hwReg & 1)) - { - if (currentSystem == WS_SYSTEM_COLOR && ws_haveColorIRom) - { - if (addr >= 0xFE000) - { - ret = internalColorIRom[addr & ~0xFE000]; - return ret; - } - } - else if (currentSystem == WS_SYSTEM_CRYSTAL && ws_haveColorIRom) - { - if (addr >= 0xFE000) - { - ret = internalCrystalIRom[addr & ~0xFE000]; - return ret; - } - } - else if (currentSystem == WS_SYSTEM_MONO && ws_haveBWIRom) - { - if (addr >= 0xFF000) - { - ret = internalBWIRom[addr & ~0xFF000]; - return ret; - } - } - } - // fall through - - default: - hwReg = ws_ioRam[0xC0]; - temp = hwReg << 20; - temp += addr & 0xFFFFF; - temp &= (romSize - 1); - return ws_rom[temp]; - } - - return (0x90); -} -#else /* 256 page of 12 bits */ uint8_t *pagedMemory[0x100]; @@ -330,7 +223,6 @@ void mem_dump_info() i, pagedMemory[i], i+1, pagedMemory[i+1], i+2, pagedMemory[i+2], i+3, pagedMemory[i+3]); } } -#endif char *load_file(char *filename) { @@ -468,16 +360,11 @@ void ws_memory_init(uint8_t *rom, uint32_t wsRomSize) romAddressMask = romSize - 1; - -#ifdef USE_PAGED_MEMORY_ACCESS for(int i = 0; i < 0x100; i++) { pagedMemory[i] = NULL; } - /* We start in B&W mode */ - set_iram_access(IRAM_LIMITED_ACCESS); - /* Cart SRAM */ if (sramSize > 0) { @@ -494,7 +381,6 @@ void ws_memory_init(uint8_t *rom, uint32_t wsRomSize) mem_dump_info(); set_irom_overlay(); -#endif } void ws_memory_reset(void) diff --git a/source/peripherals/audio.c b/source/peripherals/audio.c index 4eedee0..6aecd9e 100644 --- a/source/peripherals/audio.c +++ b/source/peripherals/audio.c @@ -1,7 +1,6 @@ /******************************************************************************* * NewOswan * audio.c: - * * Based on the original Oswan-unix * Copyright (c) 2014-2022 986-Studio. All rights reserved. * @@ -110,6 +109,9 @@ uint32_t ws_audio_channel_isPlaying[6]; static unsigned int ws_audio_log; +// TODO: Temporary to let build for now +static uint8_t ws_ioRam[0x100]; + void ws_audio_init(void) { Log(TLOG_NORMAL, "audio", "audio init"); diff --git a/source/peripherals/rtc.c b/source/peripherals/rtc.c index 1f4e261..f0fa354 100644 --- a/source/peripherals/rtc.c +++ b/source/peripherals/rtc.c @@ -8,12 +8,18 @@ ******************************************************************************/ #include +#include static int rtcDataRegisterReadCount = 0; +// TODO: Temporary to let build for now +static uint8_t ws_ioRam[0x100]; + uint8_t rtc_io_read(void *pdata, uint8_t port) { - case (port) + uint8_t retVal = 0; + + switch (port) { case 0xca : // RTC Command and status register // set ack to always 1 @@ -78,6 +84,9 @@ uint8_t rtc_io_read(void *pdata, uint8_t port) goto exit; } } + +exit: + return retVal; } void rtc_io_write(void *pdata, uint8_t port, uint8_t value) diff --git a/source/ws.c b/source/ws.c index 76b7a44..655647a 100644 --- a/source/ws.c +++ b/source/ws.c @@ -115,7 +115,7 @@ int ws_executeLine(int16_t *framebuffer, int renderLine) ws_audio_process(); // update scanline register - ws_ioRam[2] = ws_gpu_scanline; + //ws_ioRam[2] = ws_gpu_scanline; /* Why twice like that and random cycle count???? */ ws_cycles = nec_execute((ws_cyclesByLine >> 1) + (rand() & 7)); @@ -152,29 +152,34 @@ int ws_executeLine(int16_t *framebuffer, int renderLine) { ws_gpu_scanline = 0; { +#if 0 if ((ws_ioRam[0xb2] & 32)) /* VBLANK Timer */ { /* TODO: REPAIR THAT SHIT */ ws_ioRam[0xb6] &= ~32; nec_int((ws_ioRam[0xb0] + 5) * 4); } +#endif } } +#if 0 ws_ioRam[2] = ws_gpu_scanline; +#endif if (drawWholeScreen) { - +#if 0 if (ws_ioRam[0xb2] & 64) /* VBLANK INT */ { ws_ioRam[0xb6] &= ~64; nec_int((ws_ioRam[0xb0] + 6) * 4); } - +#endif vblank_count++; } +#if 0 if (ws_ioRam[0xa4] && (ws_ioRam[0xb2] & 128)) /*HBLANK TMR*/ { /* TODO: Check that shit */ @@ -201,6 +206,7 @@ int ws_executeLine(int16_t *framebuffer, int renderLine) ws_ioRam[0xb6] &= ~16; nec_int((ws_ioRam[0xb0] + 4) * 4); } +#endif return (drawWholeScreen); } @@ -233,6 +239,8 @@ wssystem_t ws_get_system() int ws_loadState(char *statepath) { + // TODO: need a complete rewrite +#if 0 Log(TLOG_NORMAL, "ws", "loading %s\n", statepath); uint16_t crc = memory_getRomCrc(); uint16_t newCrc; @@ -287,6 +295,7 @@ int ws_loadState(char *statepath) // force a video mode change to make all tiles dirty ws_gpu_clearCache(); +#endif return (1); } @@ -296,6 +305,8 @@ int ws_loadState(char *statepath) int ws_saveState(char *statepath) { + // TODO: need a complete rewrite +#if 0 uint16_t crc = memory_getRomCrc(); uint32_t value; char newPath[1024]; @@ -370,7 +381,7 @@ int ws_saveState(char *statepath) ws_audio_writeState(fp); close(fp); - +#endif return (1); }