diff --git a/cgdoom/cgdoom-ui.c b/cgdoom/cgdoom-ui.c index cb78d81..1b77bf3 100644 --- a/cgdoom/cgdoom-ui.c +++ b/cgdoom/cgdoom-ui.c @@ -172,7 +172,7 @@ void UI_Checkbox(int x, int y, int checked) void UI_FileMappingProgressBar(int size_mapped, int size_total) { const int w=192, h=5; - const int x0=(WIDTH-w)/2, y0=HEIGHT-20; + const int x0=(WIDTH-w)/2, y0=HEIGHT-10; const int pos = x0 + (w * size_mapped) / size_total; for(int x = x0; x < x0+w; x++) @@ -206,7 +206,7 @@ void Layout_Init(Layout *l) void Layout_StartFrame(Layout *l) { l->focus_count = 0; - l->y = 12; + l->y = 10; } void Layout_EndFrame(Layout *l) @@ -377,7 +377,7 @@ int Layout_Event(Layout *l, int key) int UI_Main(WADFileInfo *wads, int wad_count, int *dev_info, int *use_mmap, int *startmap, int *startepisode, int *trustunaligned, - int *autostart, int *enabledemos) + int *autostart, int *enabledemos, int *enable2MBline) { Layout l; Layout_Init(&l); @@ -387,7 +387,7 @@ int UI_Main(WADFileInfo *wads, int wad_count, int *dev_info, int *use_mmap, Bdisp_AllClr_VRAM(); Layout_StartFrame(&l); Layout_CenteredText(&l, "CGDoom for fx-CG 50 and Graph 90+E"); - Layout_Spacing(&l, 12); + Layout_Spacing(&l, 10); for(int i = 0; i < wad_count; i++) { @@ -410,17 +410,19 @@ int UI_Main(WADFileInfo *wads, int wad_count, int *dev_info, int *use_mmap, (wads[i].size % 1000000) / 100000); } - Layout_Spacing(&l, 12); + Layout_Spacing(&l, 10); Layout_Integer(&l, "Start at episode:", startepisode); Layout_Integer(&l, "Start at map:", startmap); Layout_Text(&l, "Title screen:", *autostart ? "Skip" : !*enabledemos ? "No demos" : "Full"); - Layout_Spacing(&l, 12); + Layout_Spacing(&l, 10); Layout_Checkbox(&l, "Developer info:", dev_info); Layout_Checkbox(&l, "Map file to memory:", use_mmap); Layout_Checkbox(&l, "Trust unaligned lumps:", trustunaligned); + if(enable2MBline) + Layout_Checkbox(&l, "Use memory beyond 2MB:", enable2MBline); Layout_EndFrame(&l); Bdisp_PutDisp_DD(); diff --git a/cgdoom/cgdoom-ui.h b/cgdoom/cgdoom-ui.h index 5b0e0a4..1244e92 100644 --- a/cgdoom/cgdoom-ui.h +++ b/cgdoom/cgdoom-ui.h @@ -69,7 +69,8 @@ int UI_Main(WADFileInfo *wads, int wad_count, int *startepisode, /* Warp to this episode */ int *trustunaligned, /* Trust unaligned lumps */ int *autostart, /* Skip title screen, straight to gameplay */ - int *enabledemos /* Enable demos on the title screen */ + int *enabledemos, /* Enable demos on the title screen */ + int *enable2MBline /* Enable memory past the 2MB line */ ); /* Show an error with custom formatting. */ diff --git a/cgdoom/cgdoom.c b/cgdoom/cgdoom.c index 002336b..b40b313 100644 --- a/cgdoom/cgdoom.c +++ b/cgdoom/cgdoom.c @@ -383,6 +383,7 @@ static SectorIndexInfo *gIndex = NULL; int CGD_TrustUnalignedLumps = 1; int CGD_EnableDemos = 0; int CGD_SingleEpisodeUltimate = 0; +int CGD_2MBLineMemory = 0; /* Performance counters */ struct CGD_Perf CGD_Perf; @@ -621,6 +622,20 @@ void abort(void){ #endif /* CG_EMULATOR */ +static int FindZeroedMemory(void *start) +{ + /* Look for zero-longwords every 16 bytes */ + int size = 0; + + /* Limit to 6 MB since the fx-CG 50 doesn't have any more memory and + anything after the RAM is likely to be zero non-writable */ + while(size < CGDOOM_2MBLINEMEMORY_MAX && !*(uint32_t *)(start + size)) + size += 16; + + /* Round down to a multiple of 4096 */ + return size & ~0xfff; +} + /////////////////////////////////////////////////////////////////////////////////////////////////// int main(void) { @@ -644,9 +659,16 @@ int main(void) int wad_count = FindWADs(wads, 16); int dev_info = 0; + + /* Allow the user to use memory past the 2 MB line on known OS versions */ + int *enable_2MBline=NULL; + char const *osv = (void *)0x80020020; + if(!strncmp(osv, "03.", 3) && osv[3] <= '5') // 3.50 or earlier + enable_2MBline = &CGD_2MBLineMemory; + int choice = UI_Main(wads, wad_count, &dev_info, &gWADmethod, &startmap, &startepisode, &CGD_TrustUnalignedLumps, &autostart_, - &CGD_EnableDemos); + &CGD_EnableDemos, enable_2MBline); if(choice < 0) return 1; @@ -664,9 +686,13 @@ int main(void) unsigned tmp=((unsigned)getSecondaryVramAddress()+3)&(~3); SaveVRAMBuffer = (unsigned char*)tmp; - /* Graph 90+E: RAM starts at 0x0c000000 in physical memory */ + /* fx-CG 50 / Graph 90+E: RAM starts at 0x0c000000 in physical memory */ SystemStack = (void *)0xac0f0000; + /* Determine how much RAM is zeroed out at 2 MB */ + if(CGD_2MBLineMemory) + CGD_2MBLineMemory = FindZeroedMemory((void *)0xac200000); + /* Setup access to WAD file */ #ifdef CG_EMULATOR gWADmethod = CGDOOM_WAD_BFILE; diff --git a/cgdoom/i_system.c b/cgdoom/i_system.c index cc938ca..e4c9f48 100644 --- a/cgdoom/i_system.c +++ b/cgdoom/i_system.c @@ -92,7 +92,7 @@ byte *I_ScreenBase(int screen) /* On the calculator, scrap every possible bit of RAM */ byte* I_ZoneBase (int* size, int i) { - if (i == 0) + if (i-- == 0) { /* System stack (~500 kiB) */ *size = RAM_I_Zone_SIZE; @@ -100,15 +100,21 @@ byte* I_ZoneBase (int* size, int i) ASSERT(RAM_I_Zone_SIZE <= SYSTEM_STACK_SIZE); return mb_mainzone; } - if (i == 1) + if (i-- == 0) { /* Unused part of user stack (~200 kiB); provided by linker script */ extern byte sextra, eextra; *size = &eextra - &sextra; return &sextra; } + if (CGD_2MBLineMemory && i-- == 0) + { + /* Memory beyond the 2MB line */ + *size = CGD_2MBLineMemory; + return (void *)0x8c200000; + } #ifdef CGDOOM_DIRECT_R61524 - if (i == 2) + if (i-- == 0) { /* Secondary VRAM (screen buffers being in the main VRAM because we're doing direct access so we don't need Bdisp_PutDisp_DD() */ diff --git a/cgdoom/st_stuff.c b/cgdoom/st_stuff.c index f426c35..4ed51c6 100644 --- a/cgdoom/st_stuff.c +++ b/cgdoom/st_stuff.c @@ -486,7 +486,7 @@ void CGFreeMem() if (!ptr) break; - sprintf(message+strlen(message), "%s%d/%d kB", (i ? ", " : ""), + sprintf(message+strlen(message), "%s%d/%dk", (i ? ", " : ""), Z_FreeMemory(i) >> 10, size >> 10); } diff --git a/src-cg/platform.h b/src-cg/platform.h index 4a40522..62e7eab 100644 --- a/src-cg/platform.h +++ b/src-cg/platform.h @@ -81,6 +81,12 @@ extern int CGD_TrustUnalignedLumps; # define CGDOOM_SCREENS_BASE SaveVRAMBuffer #endif +/* Amount of extra memory past the 2 MB line that we deem safe to access. */ +extern int CGD_2MBLineMemory; + +/* Maximum amount of memory beyond the 2 MB line */ +#define CGDOOM_2MBLINEMEMORY_MAX (6 << 20) + //--- #include "keyboard.hpp"