From 5520a6e5eeafdd5f8bfffcd9f5a98a5b7c22b85f Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Thu, 12 Aug 2021 13:12:48 +0200 Subject: [PATCH] Restore video mode after an error When using direct-DD access, the window size would not be restored, producing complete nonsense. --- README | 4 +++- cgdoom/i_system.c | 2 ++ cgdoom/i_video.c | 26 +++++++++++++++++++------- cgdoom/i_video.h | 2 ++ cgdoom/st_stuff.c | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README b/README index 0ad17a3..18a861d 100644 --- a/README +++ b/README @@ -14,6 +14,7 @@ sources (GPL) and nDoom (GPLv2). See LICENSE. UI improvements TODO: -> Better keyboard layout (including more keys, eg. Run) => Edit messages accordingly ("press y"/etc) +-> Use MENU for the escape and EXE to validate in menus WAD support TODO: -> Unmodified 1.9 shareware WAD works all the way through? @@ -29,11 +30,12 @@ Technical support TODO: -> Supply more VRAM memory to internal allocator => Merge internal heap into Z_Zone? (< 50 kB) => Rewrite video code to use long PRAM0 access? (138 kB) + => Identify arrays that can go to PRAM, eg. lumpcache + => Remove multiply-avoiding lookup tables? -> Rate-limit the game when overclocking -> Switches don't always show the pressed texture (?) -> Add more SHORT() to avoid having to copy-align lumps (note left by MPoupe in m_swap.h) --> Quit Game menu sometimes crashes the add-in -> Load/Save game would be very cool -> Reenable LTO if possible -> Built-in overclocking? diff --git a/cgdoom/i_system.c b/cgdoom/i_system.c index 62040a0..9be5ebe 100644 --- a/cgdoom/i_system.c +++ b/cgdoom/i_system.c @@ -154,6 +154,7 @@ void I_ErrorI (const char *error, int i1,int i2,int i3,int i4) locate_OS( 1, 5 );CGDAppendHex32("i3:",i3,8,buf);PrintLine( buf, 21 ); locate_OS( 1, 6 );CGDAppendHex32("i4:",i4,8,buf);PrintLine( buf, 21 ); GetKey( &key ); + I_ReinitAfterError(); #else I_Error (error,i1,i2,i3,i4); #endif @@ -181,6 +182,7 @@ void I_Error (char *error, ...) locate_OS( 1, 2 ); PrintLine( error, 21 ); GetKey( &key ); + I_ReinitAfterError(); #endif //#ifdef CG_EMULATOR //I_Quit(); } diff --git a/cgdoom/i_video.c b/cgdoom/i_video.c index 7561c5f..7ab6030 100644 --- a/cgdoom/i_video.c +++ b/cgdoom/i_video.c @@ -130,14 +130,15 @@ static void SetWindow(int left, int top, int width, int height) WriteLCDReg(LCD_WINDOW_BOTTOM, top + height - 1); } +/* Whether the black background has been rendered. We could fill the screen + at initialization but it would flicker. Instead, we go the extra mile and + render the background at the same time as the first frame. This also allows + redrawing it after erros.*/ +static int firstflipdone = 0; + void I_Flip (void) { - /* Whether the black background has been rendered. We could fill the screen - at initialization but it would flicker. Instead, we go the extra mile and - render the background at the same time as the first frame. */ - static int black_bg = 0; - - if (!black_bg) + if (!firstflipdone) { SetWindow(0, 0, 396, 224); WriteLCDReg(LCD_GRAM_X, 0); @@ -165,7 +166,7 @@ void I_Flip (void) /* Set the future window */ SetWindow((396 - SCREENWIDTH) / 2, (224 - SCREENHEIGHT) / 2, SCREENWIDTH, SCREENHEIGHT); - black_bg = 1; + firstflipdone = 1; } else { @@ -193,6 +194,14 @@ void I_ShutdownGraphics(void) SetWindow(6, 0, 384, 216); } +void I_ReinitAfterError(void) +{ + firstflipdone = 0; + /* Redraw status bar over help message */ + extern boolean st_firsttime; + st_firsttime = true; +} + #else void I_Flip (void) @@ -223,7 +232,10 @@ void I_InitGraphics(void) void I_ShutdownGraphics(void) { +} +void I_SetWindowAfterError(void) +{ } #endif diff --git a/cgdoom/i_video.h b/cgdoom/i_video.h index 5bdd996..7d6abd9 100644 --- a/cgdoom/i_video.h +++ b/cgdoom/i_video.h @@ -51,6 +51,8 @@ void I_ReadScreen (byte* scr); //void I_BeginRead (void); //void I_EndRead (void); +/* CGDOOM: Restore video after error when using direct-DD access */ +void I_ReinitAfterError (void); #endif diff --git a/cgdoom/st_stuff.c b/cgdoom/st_stuff.c index 5eab4d3..0cc2fa2 100644 --- a/cgdoom/st_stuff.c +++ b/cgdoom/st_stuff.c @@ -267,7 +267,7 @@ static player_t* plyr; // ST_Start() has just been called -static boolean st_firsttime; +boolean st_firsttime; // used to execute ST_Init() only once static int veryfirsttime = 1;