Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/AI/sithAI.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ sithAIAlign sithAI_aAlignments[10] = {0}; // MoTS Added
// Added: 84KB of .bss -> extram. Allocated once at sithAI_Startup; SithAIControlBlock is
// all word-width fields (audited) and every clear below is word-safe.
SithAIControlBlock* sithAI_actors = NULL;
#elif defined(PLATFORM_SESSION_ARRAYS)
// Added: SITHAI_MAX_ACTORS entries the platform allocates (zeroed) before the engine
// starts and frees after it has shut down (Platform/ESP32/jk_esp_arrays.c)
SithAIControlBlock* sithAI_actors = NULL;
#else
SithAIControlBlock sithAI_actors[SITHAI_MAX_ACTORS] = {0};
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/AI/sithAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#define sithAI_CanDetectSightThing_ADDR (0x004EC140)

extern int sithAI_bOpened;
#ifdef TARGET_TWL
extern SithAIControlBlock* sithAI_actors; // Added: heap'd (extram); see sithAI.c
#if defined(TARGET_TWL) || defined(PLATFORM_SESSION_ARRAYS)
extern SithAIControlBlock* sithAI_actors; // Added: heap'd (extram, or per session); see sithAI.c
#else
extern SithAIControlBlock sithAI_actors[SITHAI_MAX_ACTORS];
#endif
Expand Down
18 changes: 18 additions & 0 deletions src/Cog/lex.yy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,11 @@ FILE *input_file;
#endif

{
#ifdef TARGET_ESP32
/* (as newer flex does: sithCogParse_ESP32_ReleaseLexer may have freed it) */
if ( ! yy_current_buffer )
yy_current_buffer = yy_create_buffer( (FILE*)yyin, YY_BUF_SIZE );
#endif
yy_init_buffer( yy_current_buffer, input_file );
yy_load_buffer_state();
}
Expand Down Expand Up @@ -1303,3 +1308,16 @@ FILE *file;
}
# line 89 "cog.l"

#ifdef TARGET_ESP32
/* ESP32: the lexer's input buffer (YY_BUF_SIZE) is made by the first parse
* and kept for the process. The port frees it when the engine has stopped:
* made during the first level load, it otherwise stays in the middle of the
* PSRAM heap after the game and splits its largest free block. The next parse
* makes a new one (yyrestart / yylex). */
void sithCogParse_ESP32_ReleaseLexer(void)
{
if ( yy_current_buffer )
yy_delete_buffer( yy_current_buffer );
yy_init = 1;
}
#endif
6 changes: 4 additions & 2 deletions src/Devices/sithSound.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ sithSound* sithSound_GetFromIdx(int idx)
}


#ifdef TARGET_RETRO_HOMEBREW
#if defined(TARGET_RETRO_HOMEBREW) && !defined(TARGET_ESP32)
// Added: fileRead byte-writes into the destination, but long-sound PCM may live
// in word-addressable-only memory (DC VRAM arena). Bounce those through a chunk
// buffer with word-safe copies; everything else reads direct.
// buffer with word-safe copies; everything else reads direct. (Not on ESP32: all
// of its memory takes byte stores, stdPlatform_IsWordAddressableOnly() is always
// 0 there, and the 16 KB bounce buffer was never used.)
static int sithSound_ReadIntoBuffer(int fd, void* pDst, int len)
{
if (!stdPlatform_IsWordAddressableOnly(pDst))
Expand Down
33 changes: 25 additions & 8 deletions src/Engine/rdActive.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@
#include "jk.h"

#ifdef RDRASTER_SOFTWARE_RENDERER
// Software-rasterizer working pools. numActiveFaces caps at 0x3ff and numActiveSpans at
// 0x7ff, so the pools hold 1024 faces (~512 KB) and 2048 spans (~176 KB). These are
// present only when the software path is compiled in.
// Software-rasterizer working pools. numActiveFaces caps at RDACTIVE_MAX_FACES-1 and
// numActiveSpans at RDACTIVE_MAX_SPANS-1, so by default the pools hold 1024 faces (~512 KB)
// and 2048 spans (~104 KB). These are present only when the software path is compiled in.
// Added: the build may set the pool sizes (RDACTIVE_MAX_FACES / RDACTIVE_MAX_SPANS, see
// rdActive.h).
// TODO(integration): for TARGET_TWL / TARGET_DREAMCAST, gate the caps / place the pools
// in extram to reclaim RAM (see PROGRESS.md).
#define RDACTIVE_MAX_FACES 1024
#define RDACTIVE_MAX_SPANS 2048

#ifdef PLATFORM_SESSION_ARRAYS
// Added: pointers to pools the platform allocates for an engine session (see
// rdActive.h). With RDRASTER_SW_ZBUFFER the world is drawn by rdZRaster and these
// pools are never used, so the platform does not allocate them at all; the
// rasterizer below draws nothing while they are NULL.
rdActiveFace* aActiveFaces = NULL;
rdActiveSpan* aActiveSpans = NULL;
#else
static rdActiveFace aActiveFaces[RDACTIVE_MAX_FACES];
static rdActiveSpan aActiveSpans[RDACTIVE_MAX_SPANS];
#endif
static int yCurScanLine; // scanline currently being rasterized by rdActive_DrawScene

// Exposed so the rdAFRaster draw callbacks can validate a span-list link points into the
Expand All @@ -30,8 +39,11 @@ int rdActive_Startup()
// Working pools are re-populated from index 0 every frame (counters reset in
// rdActive_AdvanceFrame), but zero them here so the soft-reset loop in main.c
// never leaves stale pointers behind when swapping JK.EXE/JKM.EXE functionality.
_memset(aActiveFaces, 0, sizeof(aActiveFaces));
_memset(aActiveSpans, 0, sizeof(aActiveSpans));
// (Added: sized by the counts, not sizeof(): the pools may be pointers)
if (aActiveFaces)
_memset(aActiveFaces, 0, sizeof(rdActiveFace) * RDACTIVE_MAX_FACES);
if (aActiveSpans)
_memset(aActiveSpans, 0, sizeof(rdActiveSpan) * RDACTIVE_MAX_SPANS);
yCurScanLine = 0;
#endif
return 1;
Expand Down Expand Up @@ -351,7 +363,7 @@ void rdActive_BuildSpans()
// uninitialized callbacks — see the rdAFRaster Setup*NGon families still to be ported.
int rdActive_AddActiveFace(rdProcEntry* pProcEntry)
{
if ((uint32_t)numActiveFaces > 0x3ff)
if ((uint32_t)numActiveFaces > RDACTIVE_MAX_FACES - 1) // JK: 0x3ff
return 0;

int geometryMode = pProcEntry->geometryMode;
Expand Down Expand Up @@ -599,6 +611,11 @@ void rdActive_BuildEdges()
// finished edges, and step the surviving edges one scanline (re-sorting any that cross).
void rdActive_DrawScene()
{
#ifdef PLATFORM_SESSION_ARRAYS
// Added: no pools this session (see the definitions above)
if (!aActiveFaces || !aActiveSpans)
return;
#endif
rdActive_BuildEdges();

for (yCurScanLine = yMinEdge; (uint32_t)yCurScanLine <= (uint32_t)yMaxEdge; yCurScanLine++)
Expand Down
14 changes: 14 additions & 0 deletions src/Engine/rdActive.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,26 @@ void rdActive_AdvanceFrame();
void rdActive_ClearFrameCounters();

#ifdef RDRASTER_SOFTWARE_RENDERER
// Added: working-pool sizes (the build may set them; JK.EXE's are 1024 / 2048)
#ifndef RDACTIVE_MAX_FACES
#define RDACTIVE_MAX_FACES 1024
#endif
#ifndef RDACTIVE_MAX_SPANS
#define RDACTIVE_MAX_SPANS 2048
#endif

void rdActive_DrawScene();
void rdActive_BuildEdges();
void rdActive_BuildSpans();
void rdActive_FlushSpans();
rdActiveSpan* rdActive_pSpanPoolBegin(void);
rdActiveSpan* rdActive_pSpanPoolEnd(void);
#ifdef PLATFORM_SESSION_ARRAYS
// Added: the working pools, RDACTIVE_MAX_FACES / RDACTIVE_MAX_SPANS entries, set by the
// platform before the engine starts (NULL when the build does not draw with them)
extern rdActiveFace* aActiveFaces;
extern rdActiveSpan* aActiveSpans;
#endif
// Defined by the rdAFRaster family (P3): dispatches a proc face to the setup routine
// that matches its shading/surface/bit-depth and admits it to the active-face pool.
int rdActive_AddActiveFace(rdProcEntry* pProcEntry);
Expand Down
7 changes: 7 additions & 0 deletions src/Gui/jkGUIForce.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,13 @@ int jkGuiForce_Show(int bCanSpendStars, int isMulti, int a4, char16_t* a5, int *
clicked = jkGuiRend_DisplayAndReturnClicked(jkGuiForce_pMenu);
if ( clicked == -1 )
{
#ifdef TARGET_ESP32
// Added: closing the menus for a pending load or a quit (see
// jkGuiRend_ESP32_bCloseMenus): the Yes/No below returns -1 too,
// so this screen would reopen forever
if ( jkGuiRend_ESP32_bCloseMenus )
break;
#endif
if ( !jkGuiDialog_YesNoDialog(jkStrings_GetUniStringWithFallback("GUI_ABORT_GAME"), jkStrings_GetUniStringWithFallback("GUI_CONFIRM_ABORTCD")) )
continue;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Gui/jkGUIMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ void jkGuiMain_Show()
do
{
if (g_should_exit) return; // Added
#ifdef TARGET_ESP32
// Added: a level switch requested from outside the menus (the
// tab5-emu pause menu loading a save) waits for this loop to end;
// leave it the way starting a game from the menus does
if (jkGuiRend_ESP32_bCloseMenus) break;
#endif

jkGuiRend_MenuSetEscapeKeyShortcutElement(&jkGuiMain_menu, &jkGuiMain_elements[2]);
v1 = jkGuiRend_DisplayAndReturnClicked(&jkGuiMain_menu);
Expand Down Expand Up @@ -278,6 +284,11 @@ void jkGuiMain_ShowCutscenes()
}
}
while ( v4 != -1 );
#ifdef TARGET_ESP32
// Added: closed for a pending load (see jkGuiRend_ESP32_bCloseMenus):
// going back to the main menu would replace that switch
if ( !jkGuiRend_ESP32_bCloseMenus )
#endif
jkMain_MenuReturn();
LABEL_17:
v7 = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/Gui/jkGUIPlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "General/stdFnames.h"
#include "General/stdFileUtil.h"
#include "World/jkPlayer.h"
#ifdef TARGET_ESP32
#include "Devices/sithControl.h"
#endif

static int jkGuiPlayer_bInitted = 0;

Expand Down Expand Up @@ -350,7 +353,20 @@ void jkGuiPlayer_ShowNewPlayer(int a1)
jkPlayer_CreateConf(jkGuiPlayer_awTmp_555D28);
}
if ( v7 < 0 )
{
#ifdef TARGET_ESP32
// Added: closing the menus for a pending load or a quit (see
// jkGuiRend_ESP32_bCloseMenus). With no profile to go back to
// (v15) this dialog reopens until one is created, i.e. forever;
// leave with the default controls instead, since no profile was
// read. With profiles, going back to the list reads the selected
// one (its -1 case) and leaves.
if ( jkGuiRend_ESP32_bCloseMenus && v15 )
sithControl_DefaultInit();
else
#endif
v14 = 1;
}
}
while ( v14 );
jkGuiRend_DarrayFree(&a1a);
Expand Down
23 changes: 23 additions & 0 deletions src/Gui/jkGUIRend.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ void jkGuiRend_ESP32_CancelActiveMenu(void)
if (jkGuiRend_activeMenu && !jkGuiRend_activeMenu->lastClicked)
jkGuiRend_activeMenu->lastClicked = -1;
}

// tab5-emu: set when the platform asks for a GUI state switch while a modal
// menu is open (the pause menu loading a save at the engine's main menu).
// jkMain_GuiAdvance switches only once no menu is open, and on this target a
// menu does not close by itself for that (the original's jkGuiRend_thing_four
// cancel is off for TARGET_RETRO_HOMEBREW, see below), so the load would wait
// for the user to leave the menus -- and New Game would replace it. While set,
// every menu returns -1 (back), the screens that would ask "abort?" or reopen
// themselves on -1 (Force, tally, new player) return instead, jkGuiMain_Show
// leaves its loop, and the state handlers that fall back to the main menu on
// -1 keep the pending switch; cleared by jkMain_GuiAdvance when the switch
// happens. Also set by a quit from outside the engine (Window_MessageLoop):
// the same loops are what kept a quit at the main menu from returning.
int jkGuiRend_ESP32_bCloseMenus = 0;
#endif
static tVBuffer* jkGuiRend_menuBuffer = NULL;
static tVBuffer *jkGuiRend_texture_dword_8561E8 = NULL;
Expand Down Expand Up @@ -343,6 +357,10 @@ int32_t jkGuiRend_DisplayAndReturnClicked(jkGuiMenu *menu)
while ( !menu->lastClicked )
{
msgret = Window_MessageLoop();
#ifdef TARGET_ESP32
if ( jkGuiRend_ESP32_bCloseMenus )
menu->lastClicked = -1;
#endif
if ( jkGuiRend_thing_four && jkGuiRend_thing_five )
{
// Added: this makes the menu that appears when pressing ESC in jkGUISingleTally flicker,
Expand Down Expand Up @@ -544,6 +562,11 @@ void jkGuiRend_Shutdown()

jkGuiRend_thing_five = 0;
jkGuiRend_thing_four = 0;
#ifdef TARGET_ESP32
// Added: a quit (or a quit right after a load at a menu) ends the session
// before jkMain_GuiAdvance clears it; the next launch starts without it
jkGuiRend_ESP32_bCloseMenus = 0;
#endif
jkGuiRend_bIsSurfaceValid = 0;
jkGuiRend_bInitted = 0;
jkGuiRend_bOpen = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/jkGUIRend.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
extern int32_t jkGuiRend_thing_five;
extern int32_t jkGuiRend_thing_four;

#ifdef TARGET_ESP32
// tab5-emu: close the open modal menus for a pending GUI state switch or a quit (see jkGUIRend.c)
extern int jkGuiRend_ESP32_bCloseMenus;
#endif

void jkGuiRend_CopyVBuffer(jkGuiMenu *menu, rdRect *rect);
void jkGuiRend_SetPalette(uint8_t* pal);
void jkGuiRend_DrawRect(tVBuffer *vbuf, rdRect *rect, __int16 color);
Expand Down
7 changes: 7 additions & 0 deletions src/Gui/jkGUISingleTally.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ int jkGuiSingleTally_Show()
ret = jkGuiRend_DisplayAndReturnClicked(&jkGuiSingleTally_menu);
if ( ret == -1 )
{
#ifdef TARGET_ESP32
// Added: closing the menus for a pending load or a quit (see
// jkGuiRend_ESP32_bCloseMenus): the Yes/No below returns -1 too,
// so this screen would reopen forever
if ( jkGuiRend_ESP32_bCloseMenus )
break;
#endif
if ( !jkGuiDialog_YesNoDialog(jkStrings_GetUniStringWithFallback("GUI_ABORT_GAME"), jkStrings_GetUniStringWithFallback("GUI_CONFIRM_ABORTCD")) )
continue;
}
Expand Down
Loading