From 913ac3558234fb137c604362b9e861529d74d1d1 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Thu, 30 Sep 2021 11:44:07 +0200 Subject: [PATCH] Emulate PRAM and the secondary VRAM layout --- cgdoom/cgdoom.c | 15 ++++++++------- cgdoom/i_system.c | 14 ++------------ src-cg/platform.h | 9 +++++++++ src-sdl2/emul.c | 4 +++- src-sdl2/platform.h | 10 ++++++++++ 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/cgdoom/cgdoom.c b/cgdoom/cgdoom.c index 8a3b0de..58df167 100644 --- a/cgdoom/cgdoom.c +++ b/cgdoom/cgdoom.c @@ -524,7 +524,7 @@ int main(void) if (!strcmp(wads[choice].name, "doomu4.wad")) CGD_SingleEpisodeUltimate = 4; - uintptr_t secondary_vram = ((uintptr_t)GetSecondaryVRAMAddress() | 3) + 1; + uintptr_t secondary_vram = ((uintptr_t)GetSecondaryVRAMAddress() + 3) & -4; SaveVRAMBuffer = (void *)secondary_vram; /* fx-CG 50 / Graph 90+E: RAM starts at 0x0c000000 in physical memory */ @@ -534,6 +534,8 @@ int main(void) if(CGD_2MBLineMemory) CGD_2MBLineMemory = FindZeroedMemory((void *)0xac200000); + void *PRAM0_alloc_start = PRAM0_START; + /* Remember WAD file name for saves and loads */ static char wad_name[32] = { 0 }; for (int i = 0; wads[choice].name[i] != '.'; i++) @@ -564,7 +566,7 @@ int main(void) #endif /* FLASH_INDEX */ time = RTC_GetTicks(); - gWADMap.mTable = (void *)0xfe200000; /* PRAM0 */ + gWADMap.mTable = PRAM0_START; int fd = Bfile_OpenFile_OS(wads[choice].path, 0, 0); int size = CreateFileMapping(fd, &gWADMap); Bfile_CloseFile_OS(fd); @@ -605,13 +607,12 @@ int main(void) GetKey(&key); } - /* Initialize the PRAM allocator */ - void *PRAM0_start = (void *)0xfe200000; - void *PRAM0_end = (void *)0xfe228000; - PRAM0_start += gWADMap.miItemCount * sizeof(FileMappingItem); - CGD_PRAM_Init(PRAM0_start, PRAM0_end); + PRAM0_alloc_start += gWADMap.miItemCount * sizeof(FileMappingItem); } + /* Initialize the PRAM allocator */ + CGD_PRAM_Init(PRAM0_alloc_start, PRAM0_END); + memset(VRAM, 0, WIDTH*HEIGHT*2); D_DoomMain(); diff --git a/cgdoom/i_system.c b/cgdoom/i_system.c index 361baed..3795afb 100644 --- a/cgdoom/i_system.c +++ b/cgdoom/i_system.c @@ -67,16 +67,6 @@ byte* I_ZoneBase (int* size, int i) return NULL; } -byte *I_ScreenBase(int screen) -{ - if (screen == 0 || screen == 1 || screen == 2 || screen == 3) - return malloc(320 * 200); - if (screen == 4) - return malloc(320 * 32); - - return NULL; -} - #else /* fx-CG build */ /* On the calculator, scrap every possible bit of RAM */ @@ -114,6 +104,8 @@ byte* I_ZoneBase (int* size, int i) return NULL; } +#endif + byte *I_ScreenBase(int screen) { /* The primary/secondary VRAM covers 384*216*2 = 162 kiB: @@ -141,8 +133,6 @@ byte *I_ScreenBase(int screen) return NULL; } -#endif - // // I_Init // Initialize machine state diff --git a/src-cg/platform.h b/src-cg/platform.h index b89747d..7bcf8b4 100644 --- a/src-cg/platform.h +++ b/src-cg/platform.h @@ -50,6 +50,15 @@ disable.) */ #define CGDOOM_DIRECT_R61524 +//--- +// Memory layout +//--- + +/* PRAM0 is an area of SPU2 memory that supports only 32-bit access. It is used + for the file mapping and some allocations; see . */ +#define PRAM0_START ((void *)0xfe200000) +#define PRAM0_END ((void *)0xfe228000) + //--- // Memory distribution //--- diff --git a/src-sdl2/emul.c b/src-sdl2/emul.c index 949d682..3b4d2e0 100644 --- a/src-sdl2/emul.c +++ b/src-sdl2/emul.c @@ -8,6 +8,8 @@ SDL_Window *window = NULL; SDL_Surface *VRAM_RGB888 = NULL; +char _PRAM0[160*1024]; + /* Rendering system emulation. */ uint16_t _VRAM[WIDTH * HEIGHT]; @@ -334,7 +336,7 @@ int Bfile_FindNext(int fd, uint16_t *found, void *fileinfo0) return -16; const char *name = glob->gl_pathv[*pos]; - Bfile_StrToName_ncpy(found, name, strlen(name)); + Bfile_StrToName_ncpy(found, name, strlen(name)+1); (*pos)++; Bfile_FileInfo *fileinfo = fileinfo0; diff --git a/src-sdl2/platform.h b/src-sdl2/platform.h index 50a22a3..389651a 100644 --- a/src-sdl2/platform.h +++ b/src-sdl2/platform.h @@ -8,6 +8,16 @@ #include #include "keyboard.hpp" +//--- +// Memory layout +//--- + +extern char _PRAM0[160*1024]; +#define PRAM0_START ((void *)_PRAM0) +#define PRAM0_END ((void *)_PRAM0 + sizeof _PRAM0) + +#define CGDOOM_SCREENS_BASE SaveVRAMBuffer + //--- // fx-CG-specific functions not defined on emulator //---