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.
This commit is contained in:
Godzil 2022-03-14 15:05:18 +00:00
parent 2305ce975b
commit 4d345079ae
9 changed files with 42 additions and 145 deletions

View File

@ -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)

View File

@ -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,

View File

@ -6,22 +6,12 @@
* Copyright (c) 2014-2022 986-Studio. All rights reserved.
*
******************************************************************************/
//////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __IO_H__
#define __IO_H__
#include <stdint.h>
extern uint8_t *ws_ioRam;
extern uint8_t ws_key_start;
extern uint8_t ws_key_x4;
extern uint8_t ws_key_x2;

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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");

View File

@ -8,12 +8,18 @@
******************************************************************************/
#include <stdint.h>
#include <time.h>
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)

View File

@ -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);
}