Skip to content

Commit

Permalink
Support recording demos to SRAM
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Sep 27, 2024
1 parent ebd75e3 commit a8c2fdb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
11 changes: 8 additions & 3 deletions d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,14 @@ int MiniLoop ( void (*start)(void), void (*stop)(void)
gamevbls += vblsinframe;

if (demorecording)
*demo_p++ = buttons;
{
#ifdef MARS_USE_SRAM_DEMO
I_WriteU32SRAM((intptr_t)demo_p, buttons);
#else
*demo_p = buttons;
#endif
demo_p++;
}

if ((demorecording || demoplayback) && (buttons & BT_PAUSE) )
{
Expand Down Expand Up @@ -950,8 +957,6 @@ D_printf ("DM_Main\n");

/* while (1) RunDemo ("DEMO1"); */

/*G_RecordDemo (); // set startmap and startskill */

/* MiniLoop (F_Start, F_Stop, F_Ticker, F_Drawer, UpdateBuffer); */

/*G_InitNew (startskill, startmap, gt_deathmatch, false); */
Expand Down
11 changes: 11 additions & 0 deletions doomdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
#endif
#endif

#define MARS_USE_SRAM_DEMO
#define MARS_SRAM_DEMO_OFS 0x800
#if defined(MARS_USE_SRAM_DEMO) && !defined(MARS)
#undef MARS_USE_SRAM_DEMO
#endif

typedef unsigned short pixel_t;

#ifdef MARS
Expand Down Expand Up @@ -1254,6 +1260,11 @@ void I_SetCDFileCache(int length);
void *I_GetCDFileCache(int length);
int I_ReadCDDirectory(const char *path);

uint8_t I_ReadSRAM(int offset);
void I_WriteSRAM(int offset, int val);
uint32_t I_ReadU32SRAM(int offset);
void I_WriteU32SRAM(int offset, uint32_t val);

/*================= */
/*TLS */
/*================= */
Expand Down
18 changes: 15 additions & 3 deletions g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ void G_RunGame (void)
I_NetStop();
if (startsave != -1)
G_LoadGame(startsave);
else if (demorecording)
G_RecordDemo(); // set startmap and startskill
else
G_InitNew(startskill, startmap, starttype, startsplitscreen);
continue;
Expand Down Expand Up @@ -733,18 +735,28 @@ int G_PlayDemoPtr (unsigned *demo)

void G_RecordDemo (void)
{
#ifdef MARS_USE_SRAM_DEMO
demo_p = demobuffer = (void *)MARS_SRAM_DEMO_OFS;

I_WriteU32SRAM((intptr_t)demo_p, startskill);
demo_p++;

I_WriteU32SRAM((intptr_t)demo_p, startmap);
demo_p++;
#else
demo_p = demobuffer = Z_Malloc (0x8000, PU_STATIC);

*demo_p++ = startskill;
*demo_p++ = startmap;

#endif

G_InitNew (startskill, startmap, gt_single, false);
demorecording = true;
MiniLoop (P_Start, P_Stop, P_Ticker, P_Drawer, P_Update);
demorecording = false;

#ifdef MARS
I_Error("%d %p", demo_p - demobuffer, demobuffer);
I_Error("%d %p", (intptr_t)demo_p - (intptr_t)demobuffer, demobuffer);
#endif

D_printf ("w %x,%x",demobuffer,demo_p);
Expand Down
5 changes: 5 additions & 0 deletions m_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ int M_Ticker (void)
startskill = playerskill; /* set skill level */
starttype = currentplaymode; /* set play type */
startsplitscreen = currentgametype == mi_splitscreen;
if ((ticrealbuttons & (BT_Y|BT_MODE)) == (BT_Y|BT_MODE))
{
// hold Y and MODE to begin recording a demo
demorecording = true;
}
return ga_startnew; /* done with menu */
}

Expand Down
30 changes: 30 additions & 0 deletions marsnew.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,3 +1262,33 @@ int I_ReadCDDirectory(const char *path)
{
return Mars_MCDReadDirectory(path);
}

uint8_t I_ReadU8SRAM(int offset)
{
uint8_t c;
Mars_ReadSRAM(&c, offset, 1);
return c;
}

void I_WriteU8SRAM(int offset, int val)
{
uint8_t c = val & 0xff;
Mars_WriteSRAM(&c, offset, 1);
}

uint32_t I_ReadU32SRAM(int offset)
{
uint8_t c[4];
Mars_ReadSRAM(c, offset, 4);
return (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3];
}

void I_WriteU32SRAM(int offset, uint32_t val)
{
uint8_t c[4];
c[0] = (val >> 24) & 0xff;
c[1] = (val >> 16) & 0xff;
c[2] = (val >> 8) & 0xff;
c[3] = (val >> 0) & 0xff;
Mars_WriteSRAM(c, offset, 4);
}

0 comments on commit a8c2fdb

Please sign in to comment.