From d7ee5a1bbb65f512127dd96d2f3aa034b64f17c3 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Tue, 27 Jul 2021 14:18:06 +0200 Subject: [PATCH] Restore video system screens and memcpy bug in V_CopyRect * Restore screen numbers; BG is 4, at least in the ST module. * Let ST module allocate BG, which is just 32 pixels high and not a full VRAM (huge memory gain!) * Fix V_CopyRect() not working because memcpy is still broken (this will be changed later with a proper memcpy) --- CGDOOM-minisdk/CGDOOM/platform.h | 8 ++++--- README | 4 ++-- cgdoom/cgdoom.c | 41 +++++++++++++++++--------------- cgdoom/r_main.c | 3 --- cgdoom/st_stuff.c | 17 +++++++------ cgdoom/v_video.c | 13 ++-------- cgdoom/v_video.h | 10 +++----- 7 files changed, 42 insertions(+), 54 deletions(-) diff --git a/CGDOOM-minisdk/CGDOOM/platform.h b/CGDOOM-minisdk/CGDOOM/platform.h index 64b0749..9893e86 100644 --- a/CGDOOM-minisdk/CGDOOM/platform.h +++ b/CGDOOM-minisdk/CGDOOM/platform.h @@ -6,11 +6,13 @@ // WAD file access method (enable exactly one) //--- -/* Use BFile dynamically (slow but entirely accurate, a good reference) */ +/* Use BFile (100% accurate but slows down the game quite a bit because of + reads happening all the time; mostly a good reference for testing) */ // #define CGDOOM_WAD_BFILE -/* Search fragments in physical ROM and copy by hand (faster) */ +/* Search fragments in physical ROM when loading the game, and copy by hand + from ROM to RAM during accesses (much faster) */ #define CGDOOM_WAD_MAPPING -/* Search fragments in phyiscal ROM and copy with DMA (even faster) */ +/* Idem, but copy copy with DMA (even faster) */ // #define CGDOOM_WAD_MAPPING_DMA /* Settings for file mappings: traverse the whole 32-MiB Flash */ diff --git a/README b/README index 925ad85..61f254f 100644 --- a/README +++ b/README @@ -8,10 +8,10 @@ Credit goes to: TODO: -> Reenable LTO if possible --> HUD glitches? +-> Include a proper fast, version of memcpy -> Try and use more memory regions in z_zone.c -> Overclocking etc. --> Improve file mapping speed +-> Improve file mapping speed (DMA) CGDOOM used to be compiled with the mini-SDK. However, it's become quite difficult to get a copy of that. Instead, this port is built with a slightly diff --git a/cgdoom/cgdoom.c b/cgdoom/cgdoom.c index 60f7d02..731a1a9 100644 --- a/cgdoom/cgdoom.c +++ b/cgdoom/cgdoom.c @@ -309,7 +309,27 @@ void ResetData(FileMapping *pMap) pMap->miCurrentLength = 0; } -int CreateFileMapping(const unsigned short *pFileName,FileMapping *pMap){ + +void I_Error (char *error, ...); + +#ifdef CGDOOM_WAD_BFILE + +int FindInFlash(void **buf, int size, int readpos) +{ + return 0; +} + +int Flash_ReadFile(void *buf, int size, int readpos) +{ + return Bfile_ReadFile_OS(cgdoom_wad_fd, buf, size, readpos); +} + +#else /* CGDOOM_WAD_MAPPING, CGDOOM_WAD_MAPPING_DMA */ + +static FileMapping *gpWADMap = 0; + +int CreateFileMapping(const unsigned short *pFileName,FileMapping *pMap) +{ int iResult = 0; char cBuffer[FLASH_PAGE_SIZE]; int hFile = Bfile_OpenFile_OS(pFileName,0,0); @@ -322,7 +342,7 @@ int CreateFileMapping(const unsigned short *pFileName,FileMapping *pMap){ while(iLength > 0) { //do not optimize (= do not move these 2 variables before loop)! - // fx-cg allocates pages for file in order so page from the end of the file + // fx-cg allocates pages for file in order so page from the end of the file //can have lower index than page from the beginning const char *pTgt = pFlashFS; int iPageIndx = 0; @@ -392,24 +412,7 @@ int CreateFileMapping(const unsigned short *pFileName,FileMapping *pMap){ lbExit: Bfile_CloseFile_OS(hFile); return iResult; - } -void I_Error (char *error, ...); -static FileMapping *gpWADMap = 0; - -#ifdef CGDOOM_WAD_BFILE - -int FindInFlash(void **buf, int size, int readpos) -{ - return 0; -} - -int Flash_ReadFile(void *buf, int size, int readpos) -{ - return Bfile_ReadFile_OS(cgdoom_wad_fd, buf, size, readpos); -} - -#else /* CGDOOM_WAD_MAPPING, CGDOOM_WAD_MAPPING_DMA */ int FindInFlash(void **buf, int size, int readpos) { diff --git a/cgdoom/r_main.c b/cgdoom/r_main.c index e37b9f9..e8f390c 100644 --- a/cgdoom/r_main.c +++ b/cgdoom/r_main.c @@ -558,8 +558,6 @@ void R_SetViewSize( int blocks) setblocks = blocks; } -void V_Clear(); - // // R_ExecuteSetViewSize // @@ -573,7 +571,6 @@ void R_ExecuteSetViewSize (void) int startmap; setsizeneeded = false; - V_Clear(); if (setblocks == 11) { diff --git a/cgdoom/st_stuff.c b/cgdoom/st_stuff.c index 938e9e5..82475ae 100644 --- a/cgdoom/st_stuff.c +++ b/cgdoom/st_stuff.c @@ -427,7 +427,6 @@ void ST_refreshBackground(void) V_CopyRect(ST_X, 0, BG, ST_WIDTH, ST_HEIGHT, ST_X, ST_Y, FG); } - } @@ -474,13 +473,13 @@ void CGSwitchClip() } } -void CGFreeMem() -{ - static char cRAMBuff[16]; - int iFree = Z_FreeMemory(); - CGDAppendNum0_999("Free:",iFree,0,cRAMBuff); - plyr->message = cRAMBuff; -} +void CGFreeMem() +{ + static char cRAMBuff[16]; + int iFree = Z_FreeMemory(); + CGDAppendNum0_999("Free:",iFree,0,cRAMBuff); + plyr->message = cRAMBuff; +} int giRefreshMask = 1; void CGRefreshSwitch() @@ -1104,5 +1103,5 @@ void ST_Init (void) { veryfirsttime = 0; ST_loadData(); - //screens[4] = (byte *) Z_Malloc(ST_WIDTH*ST_HEIGHT, PU_STATIC, 0); + screens[4] = (byte *) Z_Malloc(ST_WIDTH*ST_HEIGHT, PU_STATIC, 0); } diff --git a/cgdoom/v_video.c b/cgdoom/v_video.c index 2485ba6..c3d0ca6 100644 --- a/cgdoom/v_video.c +++ b/cgdoom/v_video.c @@ -171,7 +171,8 @@ void V_CopyRect(int srcx,int srcy,int srcscrn,int width,int height,int destx,int dest = screens[destscrn]+SCREENWIDTH*desty+destx; for ( ; height>0 ; height--) { - memcpy (dest, src, width); + for(int n = 0; n < width; n++) dest[n] = src[n]; +// memcpy (dest, src, width); src += SCREENWIDTH; dest += SCREENWIDTH; } @@ -355,18 +356,8 @@ void V_Init (void) for (i=0 ; i< SCREEN_COUNT; i++) screens[i] = CGDMalloc(SCREENWIDTH*SCREENHEIGHT);*/ screens[0] = SaveVRAMBuffer; - screens[1] = SaveVRAMBuffer + SCREENWIDTH*SCREENHEIGHT; - ASSERT(SAVE_VRAM_SIZE >= 2 * SCREENWIDTH*SCREENHEIGHT); - ASSERT(SCREEN_COUNT == 2); //Blank the screen, to indicate on real hardware that SOMETHING is going on //Done since loading on real hardware takes so damn long // I_PrepScreen(); } - -//CGD: hack to clear screen (except lower part) when changing details -void V_Clear() -{ - memset(screens[0],0,320*(200-32)); - memset(screens[1],0,320*200); -} \ No newline at end of file diff --git a/cgdoom/v_video.h b/cgdoom/v_video.h index d7a141c..3d43c09 100644 --- a/cgdoom/v_video.h +++ b/cgdoom/v_video.h @@ -41,16 +41,12 @@ #define CENTERY (SCREENHEIGHT/2) -// Screen 0 is the screen updated by I_Update screen. -// Screen 1 is an extra buffer. - -// Background and foreground screen numbers -// -#define BG 1 //4 +// Screen numbers +#define BG 4 #define FG 0 -#define SCREEN_COUNT 2 +#define SCREEN_COUNT 5 extern byte* screens[SCREEN_COUNT]; extern int dirtybox[4];