diff --git a/GBADoom.pro b/GBADoom.pro index cd4b20a..50fc5b5 100644 --- a/GBADoom.pro +++ b/GBADoom.pro @@ -177,6 +177,6 @@ win32-msvc* { # LIBS += $$PWD/codeprophet.lib # QMAKE_CXXFLAGS += /GH /Gh # QMAKE_CFLAGS += /GH /Gh - QMAKE_CFLAGS += /fsanitize=address - QMAKE_CXXFLAGS += /fsanitize=address +# QMAKE_CFLAGS += /fsanitize=address +# QMAKE_CXXFLAGS += /fsanitize=address } diff --git a/GBADoomMemory.xlsx b/GBADoomMemory.xlsx index 7a99371..fb6ac98 100644 Binary files a/GBADoomMemory.xlsx and b/GBADoomMemory.xlsx differ diff --git a/Makefile b/Makefile index 6244422..9c7cd3d 100644 --- a/Makefile +++ b/Makefile @@ -27,13 +27,25 @@ INCLUDES := include DATA := data MUSIC := music +#--------------------------------------------------------------------------------- +# Disable LTO for IWRAM +#--------------------------------------------------------------------------------- +%.iwram.o: %.iwram.cpp + $(SILENTMSG) $(notdir $<) + $(SILENTCMD)$(CXX) -MMD -MP -MF $(DEPSDIR)/$*.iwram.d $(CXXFLAGS) -fno-lto -marm -c $< -o $@ $(ERROR_FILTER) + +#--------------------------------------------------------------------------------- +%.iwram.o: %.iwram.c + $(SILENTMSG) $(notdir $<) + $(SILENTCMD)$(CC) -MMD -MP -MF $(DEPSDIR)/$*.iwram.d $(CFLAGS) -fno-lto -marm -c $< -o $@ $(ERROR_FILTER) + #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- ARCH := -mthumb -mthumb-interwork -CFLAGS := -g -Wall -O3 -fgcse-after-reload\ - -mcpu=arm7tdmi -mtune=arm7tdmi\ +CFLAGS := -g -Wall -O3 -fgcse-after-reload -gdwarf-4\ + -mcpu=arm7tdmi -mtune=arm7tdmi -flto\ $(ARCH) CFLAGS += $(INCLUDE) diff --git a/include/f_wipe.h b/include/f_wipe.h index d991a50..f21165d 100644 --- a/include/f_wipe.h +++ b/include/f_wipe.h @@ -38,6 +38,7 @@ * SCREEN WIPE PACKAGE */ +void wipe_initMelt(); int wipe_ScreenWipe (int ticks); int wipe_StartScreen(void); int wipe_EndScreen (void); diff --git a/include/global_data.h b/include/global_data.h index 16f47fc..1ba659f 100644 --- a/include/global_data.h +++ b/include/global_data.h @@ -163,7 +163,7 @@ boolean castdeath; //f_wipe.c //****************************************************************************** -int wipe_tick; +short y_lookup[SCREENWIDTH]; //****************************************************************************** //g_game.c diff --git a/include/i_system_e32.h b/include/i_system_e32.h index 0aa2283..e483d11 100644 --- a/include/i_system_e32.h +++ b/include/i_system_e32.h @@ -34,6 +34,8 @@ void I_Quit_e32(); unsigned short* I_GetBackBuffer(); +unsigned short* I_GetFrontBuffer(); + #ifdef __cplusplus } #endif diff --git a/source/d_main.c b/source/d_main.c index 9e15c2d..5faad7d 100644 --- a/source/d_main.c +++ b/source/d_main.c @@ -135,6 +135,8 @@ static void D_Wipe(void) boolean done; int wipestart = I_GetTime () - 1; + wipe_initMelt(); + do { int nowtime, tics; @@ -147,7 +149,7 @@ static void D_Wipe(void) wipestart = nowtime; done = wipe_ScreenWipe(tics); - I_UpdateNoBlit(); + I_UpdateNoBlit(); M_Drawer(); // menu is drawn even on top of wipes } while (!done); diff --git a/source/f_wipe.c b/source/f_wipe.c index 8ae23bb..8289d3f 100644 --- a/source/f_wipe.c +++ b/source/f_wipe.c @@ -32,6 +32,8 @@ *----------------------------------------------------------------------------- */ +//Most of this code is backported from https://github.com/next-hack/nRF52840Doom + #ifdef HAVE_CONFIG_H #include "config.h" @@ -44,6 +46,8 @@ #include "m_random.h" #include "f_wipe.h" #include "global_data.h" +#include "i_system_e32.h" + #ifdef __arm__ #include @@ -55,59 +59,101 @@ int wipe_StartScreen(void) { - _g->wipe_tick = 0; return 0; } int wipe_EndScreen(void) { - _g->wipe_tick = 0; return 0; } -// killough 3/5/98: reformatted and cleaned up -int wipe_ScreenWipe(int ticks) +// oh man, why aren't you commenting anything ? +// 2021-08-08 next-hack: commented and modified to use the dual buffer. +static int wipe_doMelt(int ticks) { - unsigned int wipepos; + boolean done = true; - //Do a pageflip on the 16th tick. - boolean pageflip = (_g->wipe_tick < 16) && (_g->wipe_tick + ticks >= 16); + unsigned short* backbuffer = I_GetBackBuffer(); + unsigned short* frontbuffer = I_GetFrontBuffer(); - _g->wipe_tick += ticks; - - int wipeticks = _g->wipe_tick; - - if(wipeticks >= 32) - { - wipeticks = 32; - wipepos = 0; - } - else if(wipeticks < 16) - { - wipepos = wipeticks; - } - else //16->31 + while (ticks--) { - wipepos = 31 - wipeticks; + for (int i = 0; i < SCREENWIDTH; i++) + { + if (_g->y_lookup[i] < 0) + { + _g->y_lookup[i]++; + done = false; + continue; + } + + // scroll down columns, which are still visible + if (_g->y_lookup[i] < SCREENHEIGHT) + { + /* cph 2001/07/29 - + * The original melt rate was 8 pixels/sec, i.e. 25 frames to melt + * the whole screen, so make the melt rate depend on SCREENHEIGHT + * so it takes no longer in high res + */ + int dy = (_g->y_lookup[i] < 16) ? _g->y_lookup[i] + 1 : SCREENHEIGHT / 25; + // At most dy shall be so that the column is shifted by SCREENHEIGHT (i.e. just + // invisible) + if (_g->y_lookup[i] + dy >= SCREENHEIGHT) + dy = SCREENHEIGHT - _g->y_lookup[i]; + + unsigned short* s = &frontbuffer[i] + ((SCREENHEIGHT - dy - 1) * SCREENPITCH); + + unsigned short* d = &frontbuffer[i] + ((SCREENHEIGHT - 1) * SCREENPITCH); + + // scroll down the column. Of course we need to copy from the bottom... up to + // SCREENHEIGHT - yLookup - dy + + for (int j = SCREENHEIGHT - _g->y_lookup[i] - dy; j; j--) + { + *d = *s; + d += -SCREENPITCH; + s += -SCREENPITCH; + } + + // copy new screen. We need to copy only between y_lookup and + dy y_lookup + s = &backbuffer[i] + _g->y_lookup[i] * SCREENPITCH; + d = &frontbuffer[i] + _g->y_lookup[i] * SCREENPITCH; + + for (int j = 0 ; j < dy; j++) + { + *d = *s; + d += SCREENPITCH; + s += SCREENPITCH; + } + + _g->y_lookup[i] += dy; + done = false; + } + } } + return done; +} -#ifdef __arm__ - REG_BLDCNT = 0xc4; - REG_BLDY = wipepos; - - VBlankIntrWait(); -#endif +void wipe_initMelt() +{ + // setup initial column positions (y<0 => not ready to scroll yet) + _g->y_lookup[0] = -(M_Random() % 16); + for (int i = 1; i < SCREENWIDTH; i++) + { + int r = (M_Random() % 3) - 1; - if(pageflip) - I_FinishUpdate(); + _g->y_lookup[i] = _g->y_lookup[i - 1] + r; - if(wipeticks >= 32) - { -#ifdef __arm__ - REG_BLDCNT = 0; -#endif - return 1; + if (_g->y_lookup[i] > 0) + _g->y_lookup[i] = 0; + else if (_g->y_lookup[i] == -16) + _g->y_lookup[i] = -15; } +} - return 0; + +int wipe_ScreenWipe(int ticks) +{ + // do a piece of wipe-in + return wipe_doMelt(ticks); } diff --git a/source/i_system_e32.cpp b/source/i_system_e32.cpp index 1d9c402..4312846 100644 --- a/source/i_system_e32.cpp +++ b/source/i_system_e32.cpp @@ -38,6 +38,7 @@ unsigned char* thearray = NULL; int thesize; unsigned short backbuffer[120 *160]; +unsigned short frontbuffer[120 *160]; //************************************************************************************** @@ -82,6 +83,11 @@ unsigned short* I_GetBackBuffer() return &backbuffer[0]; } +unsigned short* I_GetFrontBuffer() +{ + return &frontbuffer[0]; +} + //************************************************************************************** void I_CreateWindow_e32() diff --git a/source/i_system_gba.cpp b/source/i_system_gba.cpp index 0f3edd4..27f015e 100644 --- a/source/i_system_gba.cpp +++ b/source/i_system_gba.cpp @@ -248,6 +248,16 @@ unsigned short* I_GetBackBuffer() //************************************************************************************** +unsigned short* I_GetFrontBuffer() +{ + if(REG_DISPCNT & DCNT_PAGE) + return (unsigned short*)VID_PAGE2; + + return (unsigned short*)VID_PAGE1; +} + +//************************************************************************************** + void I_CreateWindow_e32() {