Browse Source

lots of changes

- fix all stack allocations
- fix font spacing issues
- fix missing mail titles
- fix UI inconsistencies
- fix lightamp finish sound not playing
- make the rest of the debugging stuff unavailable in release builds
- replace uses of SetClip in GUIs with G_Clip
- make G_Clip use a clip stack again
- fix a lot of performance issues
- fix some functions being declared outside of headers
- add debugging flag for GUI rectangles
- add movable GUI windows
- fix fast character functions being static-inline
- fix x32_to_x32 functions causing automatic storage to be used
- optimize many common subroutines
- make memory allocation functions use signed integers for optimization purposes
- replace the debug flag cvars with a single debug flag cvar
- safety improvements to fastmemset and fastmemmove
- improve the workings of player levelups
- change the save debug flag to a log level
- add dynamic stack allocator for functions that require Aut to be consistent over multiple ticks
- optimize memory routines with assembly
- fix notes not deallocating when cleared
- fix some errors not being marked
- increase alloc-Aut default to 8192
- improve packaging script
master
Alison Watson 11 months ago
parent
commit
8abfa868dd
95 changed files with 1233 additions and 727 deletions
  1. BIN
      pk7/acs/lithmain.bin
  2. +2
    -7
      pk7/cvarinfo.txt
  3. +2
    -0
      pk7/fonts/lmidfont/font.inf
  4. +1
    -0
      pk7/fonts/smallfont/font.inf
  5. +3
    -2
      pk7/language.txt
  6. BIN
      pk7/lgfx/UI_Basilissa/Background.png
  7. BIN
      pk7/lgfx/UI_Ender/Background.png
  8. BIN
      pk7/lgfx/UI_Ghost/Background.png
  9. BIN
      pk7/lgfx/UI_Green/Background.png
  10. BIN
      pk7/lgfx/UI_Grey/Background.png
  11. BIN
      pk7/lgfx/UI_Orange/Background.png
  12. BIN
      pk7/lgfx/UI_Rose/Background.png
  13. BIN
      pk7/lgfx/UI_Trans/Background.png
  14. BIN
      pk7/lgfx/UI_Umi/Background.png
  15. BIN
      pk7/lgfx/UI_WinXP/Background.png
  16. +7
    -2
      pk7/lzscript/Items/Powerups.zsc
  17. +7
    -3
      source/d_compile.c
  18. +88
    -62
      source/d_vm.c
  19. +5
    -4
      source/debug.c
  20. +75
    -14
      source/g_auto.c
  21. +9
    -0
      source/g_preset.c
  22. +2
    -4
      source/g_scrollbar.c
  23. +91
    -0
      source/g_window.c
  24. +15
    -2
      source/include/common.h
  25. +2
    -0
      source/include/d_vm.h
  26. +41
    -15
      source/include/gui.h
  27. +21
    -23
      source/include/m_char.h
  28. +2
    -0
      source/include/m_drawing.h
  29. +20
    -15
      source/include/m_math.h
  30. +6
    -3
      source/include/m_memory.h
  31. +0
    -7
      source/include/m_stab.h
  32. +19
    -16
      source/include/m_str.h
  33. +13
    -14
      source/include/m_types.h
  34. +1
    -0
      source/include/p_attrib.h
  35. +18
    -0
      source/include/p_cbi.h
  36. +2
    -0
      source/include/p_log.h
  37. +25
    -3
      source/include/p_player.h
  38. +2
    -0
      source/include/p_shopdef.h
  39. +3
    -1
      source/include/p_upgrades.h
  40. +3
    -0
      source/include/p_wepinfo.h
  41. +1
    -1
      source/include/u_func_beg.h
  42. +3
    -0
      source/include/w_monster.h
  43. +4
    -0
      source/include/w_world.h
  44. +39
    -0
      source/m_char.c
  45. +6
    -3
      source/m_file.c
  46. +59
    -8
      source/m_math.c
  47. +191
    -92
      source/m_memory.c
  48. +14
    -1
      source/m_str.c
  49. +1
    -1
      source/m_token.c
  50. +29
    -21
      source/p_attrib.c
  51. +14
    -3
      source/p_bip.c
  52. +8
    -23
      source/p_cbi.c
  53. +59
    -41
      source/p_data.c
  54. +40
    -33
      source/p_gui_bip.c
  55. +6
    -6
      source/p_gui_cbi.c
  56. +18
    -18
      source/p_gui_upgrades.c
  57. +32
    -27
      source/p_items.c
  58. +4
    -4
      source/p_log.c
  59. +3
    -3
      source/p_magic.c
  60. +12
    -8
      source/p_notes.c
  61. +1
    -1
      source/p_payout.c
  62. +38
    -46
      source/p_player.c
  63. +5
    -3
      source/p_powerup.c
  64. +2
    -0
      source/p_ren_debug.c
  65. +0
    -25
      source/p_ren_item.c
  66. +2
    -2
      source/p_ren_scope.c
  67. +1
    -1
      source/p_ren_step.c
  68. +8
    -14
      source/p_render.c
  69. +4
    -7
      source/p_savedata.c
  70. +2
    -2
      source/p_settings.c
  71. +7
    -7
      source/p_shop.c
  72. +4
    -2
      source/p_statistics.c
  73. +5
    -5
      source/p_upgrades.c
  74. +2
    -7
      source/p_weapons.c
  75. +23
    -21
      source/u_adrenaline.c
  76. +1
    -1
      source/u_cyberlegs.c
  77. +1
    -1
      source/u_magic.c
  78. +2
    -2
      source/u_reflexwetw.c
  79. +1
    -1
      source/u_stealthsys.c
  80. +9
    -2
      source/u_subweapons.c
  81. +1
    -3
      source/u_vitalscan.c
  82. +8
    -4
      source/w_boss.c
  83. +0
    -4
      source/w_data.c
  84. +3
    -1
      source/w_dmon.c
  85. +8
    -8
      source/w_finale.c
  86. +38
    -27
      source/w_monster.c
  87. +0
    -1
      source/w_payout.c
  88. +1
    -1
      source/w_rain.c
  89. +1
    -1
      source/w_title.c
  90. +18
    -30
      source/w_world.c
  91. +3
    -0
      text/en/Info/Mail.txt
  92. +0
    -1
      text/en/Misc/UI.txt
  93. +0
    -1
      text/jp/Misc/UI.txt
  94. +1
    -1
      tools/genbuild.rb
  95. +5
    -4
      tools/package.sh

BIN
pk7/acs/lithmain.bin View File


+ 2
- 7
pk7/cvarinfo.txt View File

@@ -12,13 +12,8 @@ server float __lith_version;
server noarchive string __lith_end;
server nosave int __lith_fun;

server noarchive int __lith_debug_level = 0;
server noarchive bool __lith_debug_all = false;
server noarchive bool __lith_debug_items = false;
server noarchive bool __lith_debug_bip = false;
server noarchive bool __lith_debug_score = false;
server noarchive bool __lith_debug_upgrades = false;
server noarchive bool __lith_debug_save = false;
server noarchive int __lith_debug_level = 0;
server noarchive int __lith_debug_flags = 0;

server int lith_sv_difficulty = 10;
server bool lith_sv_rain = false;


+ 2
- 0
pk7/fonts/lmidfont/font.inf View File

@@ -0,0 +1,2 @@
FontHeight 7
SpaceWidth 4

+ 1
- 0
pk7/fonts/smallfont/font.inf View File

@@ -1 +1,2 @@
FontHeight 7
SpaceWidth 4

+ 3
- 2
pk7/language.txt View File

@@ -616,10 +616,13 @@
"LITH_MAIL_TEMPLATE" = "\cd>>>>>[[[[RELAYING MESSAGE]]]]\n\n\cd> Remote: <\cj%s\cd>\n\cd> Date: \cj%s";
"LITH_MAIL_INTERNAL" = "<internal>";
"LITH_MAIL_NOTITLE" = "<title omitted>";
"LITH_INFO_TITLE_MJamesDefeated" = "the end?";
"LITH_INFO_REMOT_MJamesDefeated" = "jam0s@g0n0j0t00.1025";
"LITH_INFO_DESCR_MJamesDefeated" = "\ccI woke in a \cudark place\cc, unsure of my fate; if my life was renewed out of cruel retribution or of a final opportunity.\n\n\ccI wandered this hell, more real and yet more dream-like than I thought possible, seeking any sign of escape; any sign of pity from the monsters that inhabit this place.\n\n\ccNo, the fate of the damned is but this.\n\n\ccI can only guess that my family went to Heaven and that I was left the lone sinner.\n\n\cgThank you for putting this to an end.";
"LITH_INFO_TITLE_MMakarovDefeated" = "On Manifestations";
"LITH_INFO_REMOT_MMakarovDefeated" = "mak666v@org.r\\.\\\\\\-";
"LITH_INFO_DESCR_MMakarovDefeated" = "There aren't many like you who can take such a being down. Maybe I should commend you for that, struggler.\n\nNo, there is no need. What your victories have done is enough.\n\n\cgMaybe I advise you turn back.\n\n\crI am not the strongest of these manifestations.\n\nMaybe you don't need such advice.";
"LITH_INFO_TITLE_MIsaacDefeated" = "Gift";
"LITH_INFO_REMOT_MIsaacDefeated" = "isaac@syn.400khz";
"LITH_INFO_DESCR_MIsaacDefeated" = "\caOne shan't care what he shoots, but one may take care in where he treads.\n\n\ca And I think that you've treaded\n\cr a bit too far.\n\n\ca Perhaps just me.\n\ca Or maybe you agree?\n\n\ca Here is a gift.\n\n\ca I won't tell you to use it wisely.";
"LITH_INFO_SHORT_AetosVi" = "Aetos Vi";
@@ -1674,7 +1677,6 @@
"LITH_xhair_g" = "Dynamic crosshair green";
"LITH_xhair_r" = "Dynamic crosshair red";
"LITH_xhair_style" = "Dynamic crosshair style";
"LITH_COST" = "Cost:";
"LITH_EFFECT" = "Effect:";
"LITH_FREE" = "Free";
"LITH_CATEGORY" = "Category";
@@ -2748,7 +2750,6 @@
"LITH_ST_NAME_Theme_7" = "ゴースト";
"LITH_ST_NAME_Theme_8" = "ウィンドウズXP";
"LITH_ST_NAME_Theme_9" = "ドンキーコング";
"LITH_COST" = "価格";
"LITH_EFFECT" = "効果";
"LITH_FREE" = "無料";
"LITH_CATEGORY" = "種類";


BIN
pk7/lgfx/UI_Basilissa/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 44KB Width: 300  |  Height: 219  |  Size: 44KB

BIN
pk7/lgfx/UI_Ender/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 321B Width: 300  |  Height: 219  |  Size: 285B

BIN
pk7/lgfx/UI_Ghost/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 322B Width: 300  |  Height: 219  |  Size: 300B

BIN
pk7/lgfx/UI_Green/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 321B Width: 300  |  Height: 219  |  Size: 286B

BIN
pk7/lgfx/UI_Grey/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 322B Width: 300  |  Height: 219  |  Size: 286B

BIN
pk7/lgfx/UI_Orange/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 321B Width: 300  |  Height: 219  |  Size: 285B

BIN
pk7/lgfx/UI_Rose/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 322B Width: 300  |  Height: 219  |  Size: 286B

BIN
pk7/lgfx/UI_Trans/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 507B Width: 300  |  Height: 219  |  Size: 476B

BIN
pk7/lgfx/UI_Umi/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 322B Width: 300  |  Height: 219  |  Size: 286B

BIN
pk7/lgfx/UI_WinXP/Background.png View File

Before After
Width: 320  |  Height: 240  |  Size: 97KB Width: 300  |  Height: 219  |  Size: 97KB

+ 7
- 2
pk7/lzscript/Items/Powerups.zsc View File

@@ -276,8 +276,13 @@ class Lith_ArtiTeleport : Inventory replaces ArtiTeleport
}
}

class Lith_PowerLightAmp : PowerLightAmp
{override void Tick() {if(!level.isFrozen()) Super.Tick();}}
class Lith_PowerLightAmp : PowerLightAmp {
override void Tick() {if(!level.isFrozen()) Super.Tick();}
override void EndEffect() {
Super.EndEffect();
S_StartSound("player/infraredoff", lch_item, CHANF_UI);
}
}

class Lith_PowerInvulnerable : PowerInvulnerable
{override void Tick() {if(!level.isFrozen()) Super.Tick();}}


+ 7
- 3
source/d_compile.c View File

@@ -15,6 +15,7 @@

/* Static Functions -------------------------------------------------------- */

#ifndef NDEBUG
script
static void Disassemble(struct dlg_def const *def) {
ACS_BeginLog();
@@ -34,7 +35,7 @@ static void Disassemble(struct dlg_def const *def) {
script
static void DumpCode(struct dlg_def *def) {
ACS_BeginLog();
__nprintf("Dumping code...\n");
PrintChrSt("Dumping code...\n");
Dbg_PrintMemC(def->codeV, def->codeC);
ACS_EndLog();
}
@@ -63,9 +64,10 @@ static void PrintDbg() {
}

ACS_BeginLog();
__nprintf("Done.");
PrintChrSt("Done.");
ACS_EndLog();
}
#endif

static void FinishDef(struct compiler *d)
{
@@ -142,7 +144,7 @@ u32 Dlg_WriteCode(struct dlg_def const *def, u32 c, u32 i)
__nprintf("%02X ", c);

if(!inf->name[0]) {
__nprintf(" invalid opcode");
PrintChrSt(" invalid opcode");
return i;
}

@@ -250,7 +252,9 @@ void Dlg_MInit(void)
fclose(d.tb.fp);
}

#ifndef NDEBUG
if(get_bit(dbglevel, log_dlg)) PrintDbg();
#endif
}

/* EOF */

+ 88
- 62
source/d_vm.c View File

@@ -78,6 +78,8 @@ static cstr const action_names[] = {
/* Static Functions -------------------------------------------------------- */

/* utilities */
#define local alloc_aut(0) stkcall static

#define SignB1(v) get_bit(v, 7)
#define SignB2(v) get_bit(v, 15)

@@ -139,19 +141,19 @@ local void ModSR_V(u32 ua, u32 ub, u32 ur)
local void ModSR_ZN(u32 v) {ModSR_Z(v); ModSR_N(v);}

/* direct memory access */
local cstr MemSC_G(u32 p) {return Cps_ExpandNT(memory, p);}
local str MemSA_G(u32 p) {return Cps_ExpandNT_str(memory, p);}
local u32 MemB1_G(u32 p) {return Cps_GetC(memory, p);}
local u32 MemB2_G(u32 p) {return MemB1_G(p) | (MemB1_G(p + 1) << 8);}
#define MemC1_G() (MemB1_G(GetPC()))
#define MemC2_G() (MemB2_G(GetPC()))
#define MemI1_G() (MemB1_G(IncPC(1)))
#define MemI2_G() (MemB2_G(IncPC(2)))
local u32 MemIZ_G(u32 p) {return WrapB1(MemI1_G() + p);}
local u32 MemIA_G(u32 p) {return WrapB2(MemI2_G() + p);}
local void MemB1_S(u32 p, u32 v) {Cps_SetC(memory, p, WrapB1(v));}
local void MemB2_S(u32 p, u32 v) {MemB1_S(p, v); MemB1_S(p + 1, v >> 8);}
static cstr MemSC_G(u32 p) {return Cps_ExpandNT(memory, p);}
static str MemSA_G(u32 p) {return Cps_ExpandNT_str(memory, p);}
static u32 MemB1_G(u32 p) {return Cps_GetC(memory, p);}
static u32 MemB2_G(u32 p) {return MemB1_G(p) | (MemB1_G(p + 1) << 8);}
#define MemC1_G() (MemB1_G(GetPC()))
#define MemC2_G() (MemB2_G(GetPC()))
#define MemI1_G() (MemB1_G(IncPC(1)))
#define MemI2_G() (MemB2_G(IncPC(2)))
static u32 MemIZ_G(u32 p) {return WrapB1(MemI1_G() + p);}
static u32 MemIA_G(u32 p) {return WrapB2(MemI2_G() + p);}
static void MemB1_S(u32 p, u32 v) {Cps_SetC(memory, p, WrapB1(v));}
static void MemB2_S(u32 p, u32 v) {MemB1_S(p, v); MemB1_S(p + 1, v >> 8);}

/* addressed memory access */
#define AdrAI_V() (MemI2_G())
@@ -166,7 +168,7 @@ local void MemB2_S(u32 p, u32 v) {MemB1_S(p, v); MemB1_S(p + 1, v >> 8);}
#define AdrZX_V() (MemIZ_G(GetRX()))
#define AdrZY_V() (MemIZ_G(GetRY()))

local u32 AdrAC_G(u32 a, u32 b) {
static u32 AdrAC_G(u32 a, u32 b) {
if(b & 2) return GetAC();
else return MemB1_G(a);
}
@@ -180,46 +182,55 @@ local u32 AdrAC_G(u32 a, u32 b) {
#define AdrZX_G() (MemB1_G(AdrZX_V()))
#define AdrZY_G() (MemB1_G(AdrZY_V()))

local void AdrAC_S(u32 a, u32 b, u32 r) {
static void AdrAC_S(u32 a, u32 b, u32 r) {
if(b & 2) SetAC(r);
else MemB1_S(a, r);
}

local void AdrAI_S(u32 v) {MemB1_S(AdrAI_V(), v);}
local void AdrAX_S(u32 v) {MemB1_S(AdrAX_V(), v);}
local void AdrAY_S(u32 v) {MemB1_S(AdrAY_V(), v);}
local void AdrIX_S(u32 v) {MemB1_S(AdrIX_V(), v);}
local void AdrIY_S(u32 v) {MemB1_S(AdrIY_V(), v);}
local void AdrZI_S(u32 v) {MemB1_S(AdrZI_V(), v);}
local void AdrZX_S(u32 v) {MemB1_S(AdrZX_V(), v);}
local void AdrZY_S(u32 v) {MemB1_S(AdrZY_V(), v);}
static void AdrAI_S(u32 v) {MemB1_S(AdrAI_V(), v);}
static void AdrAX_S(u32 v) {MemB1_S(AdrAX_V(), v);}
static void AdrAY_S(u32 v) {MemB1_S(AdrAY_V(), v);}
static void AdrIX_S(u32 v) {MemB1_S(AdrIX_V(), v);}
static void AdrIY_S(u32 v) {MemB1_S(AdrIY_V(), v);}
static void AdrZI_S(u32 v) {MemB1_S(AdrZI_V(), v);}
static void AdrZX_S(u32 v) {MemB1_S(AdrZX_V(), v);}
static void AdrZY_S(u32 v) {MemB1_S(AdrZY_V(), v);}

/* stack */
#define StaB1_G() (MemB1_G(STA_BEG + IncSP(1)))
#define StaB2_G() (MemB2_G(STA_BEG + IncSP(2)))

local void StaB1_S(u32 v) {MemB1_S(STA_BEG + DecSP(1), v);}
local void StaB2_S(u32 v) {MemB2_S(STA_BEG + DecSP(2) - 1, v);}
static void StaB1_S(u32 v) {MemB1_S(STA_BEG + DecSP(1), v);}
static void StaB2_S(u32 v) {MemB2_S(STA_BEG + DecSP(2) - 1, v);}

/* trace */
local void TraceReg() {
#ifndef NDEBUG
static void TraceReg() {
__nprintf("PC:%04X SP:%02X VA:%02X "
"AC:%02X RX:%02X RY:%02X SR:%02X",
GetPC(), GetSP(), GetVA(),
GetAC(), GetRX(), GetRY(), GetSR());
}
#endif

/* jumps */
#ifndef NDEBUG
#define JmpDbg() \
if(get_bit(dbglevel, log_dlg)) { \
ACS_BeginLog(); \
Dlg_WriteCode(def, next, GetPC() - PRG_BEG); \
ACS_PrintChar(' '); \
TraceReg(); \
ACS_EndLog(); \
}
#else
#define JmpDbg()
#endif

#define JmpVI { \
/* jump next byte */ \
u32 next = MemI1_G(); \
if(get_bit(dbglevel, log_dlg)) { \
ACS_BeginLog(); \
Dlg_WriteCode(def, next, GetPC() - PRG_BEG); \
ACS_PrintChar(' '); \
TraceReg(); \
ACS_EndLog(); \
} \
JmpDbg(); \
goto *cases[next]; \
}

@@ -235,7 +246,7 @@ enum {
_from_lon,
};

local str GetText(i32 from) {
static str GetText(i32 from) {
u32 adr = MemB2_G(VAR_TEXTL);
cstr pfx;

@@ -248,19 +259,19 @@ local str GetText(i32 from) {
return adr ? LanguageNull(LANG "%s_%s", pfx, MemSC_G(adr)) : snil;
}

local str GetRemote() {
static str GetRemote() {
u32 adr = MemB2_G(VAR_REMOTEL);
cstr nam = adr ? MemSC_G(adr) : "UNKNOWN";
return Language(LANG "REMOTE_%s", nam);
}

local str GetName() {
static str GetName() {
u32 adr = MemB2_G(VAR_NAMEL);
cstr nam = adr ? MemSC_G(adr) : "UNKNOWN";
return Language(LANG "PNAME_%s", nam);
}

local void ConsoleLogText(i32 from) {
static void ConsoleLogText(i32 from) {
__with(str text = GetText(from);) if(text) ConsoleLog("%s", text);
}

@@ -268,7 +279,8 @@ local void ConsoleLogText(i32 from) {
#define ResetRemote() MemB2_S(VAR_REMOTEL, 0)
#define ResetText() MemB2_S(VAR_TEXTL, 0)

script static void TerminalGUI(struct player *p, u32 tact) {
static
void TerminalGUI(struct player *p, u32 tact) {
enum {
/* text */
twidth = 640, theigh = 480,
@@ -276,14 +288,16 @@ script static void TerminalGUI(struct player *p, u32 tact) {
ttop = theigh*0.08,
tbottom = theigh*0.75,
tleft = twidth/2 - 10,
ttwidth = twidth,
ttheigh = tbottom - ttop * 2,

tmidx = tright/2, tmidy = tbottom/2,
};

Str(term_disconnecting, sLANG "TERM_DISCONNECTING");
Str(term_ip, sLANG "TERM_IP");
Str(term_sgxline, sLANG "TERM_SGXLINE");
Str(term_use_to_ack, sLANG "TERM_USE_TO_ACK");
Str(term_disconnecting, sLANG "TERM_DISCONNECTING");
Str(term_ip, sLANG "TERM_IP");
Str(term_sgxline, sLANG "TERM_SGXLINE");
Str(term_use_to_ack, sLANG "TERM_USE_TO_ACK");

G_Begin(&gst, twidth, theigh);
G_UpdateState(&gst, p);
@@ -318,9 +332,7 @@ script static void TerminalGUI(struct player *p, u32 tact) {
PrintText_str(br, s_ltrmfont, CR_RED, tright,2, tbottom,2);

/* Contents */
SetSize(gst.w, gst.h);

char pict[32] = ":Terminal:"; strcat(pict, MemSC_G(MemB2_G(VAR_PICTL)));
char pict[64] = ":Terminal:"; strcat(pict, MemSC_G(MemB2_G(VAR_PICTL)));

switch(tact) {
case TACT_LOGON:
@@ -341,25 +353,25 @@ script static void TerminalGUI(struct player *p, u32 tact) {

PrintSprite(l_strdup(pict), tmidx/2,0, tmidy,0);

SetClipW(tleft, ttop, tright - tleft, tbottom, tright - tleft);
G_Clip(&gst, tleft, ttop, tmidx, ttheigh);

if(text) {
PrintText_str(text, s_ltrmfont, CR_WHITE, tleft,1, ttop,1);
}

ClearClip();
G_ClipRelease(&gst);
break;
}
case TACT_INFO: {
str text = GetText(_from_trm);

SetClipW(0, ttop, twidth, tbottom, twidth);
G_Clip(&gst, 0, ttop, ttwidth, ttheigh);

if(text) {
PrintText_str(text, s_ltrmfont, CR_WHITE, 2,1, ttop+2,1);
}

ClearClip();
G_ClipRelease(&gst);
break;
}
}
@@ -372,7 +384,7 @@ script static void TerminalGUI(struct player *p, u32 tact) {
}
}

script static void DialogueGUI(struct player *p) {
static void DialogueGUI(struct player *p) {
enum {left = 37, top = 75, texttop = top + 24};

str snam = GetName();
@@ -389,7 +401,7 @@ script static void DialogueGUI(struct player *p) {
PrintTextStr(snam);
PrintText(s_bigupper, CR_GREEN, 30,1, 35,1);

SetClipW(left, top, 263, 157, 263);
G_Clip(&gst, left, top, 257, 150);
PrintTextFmt("\Cd> Remote: %S\n\Cd> Date: %s", srem, CanonTime(ct_full, ticks));
PrintText(s_lmidfont, CR_WHITE, left,1, top,1);

@@ -397,7 +409,7 @@ script static void DialogueGUI(struct player *p) {
PrintText_str(text, s_smallfnt, CR_WHITE, left,1, texttop,1);
}

ClearClip();
G_ClipRelease(&gst);

u32 oc = MemB1_G(VAR_OPT_CNT);

@@ -418,6 +430,7 @@ script static void DialogueGUI(struct player *p) {
G_End(&gst, gui_curs_outlineinv);
}

static
void GuiAct(void) {
u32 action = MemB1_G(VAR_UACT);
MemB1_S(VAR_UACT, UACT_NONE);
@@ -443,7 +456,8 @@ void GuiAct(void) {
}

/* VM actions */
sync static void ActDLG_WAIT(struct player *p) {
alloc_aut(0) sync static
void ActDLG_WAIT(struct player *p) {
SetVA(ACT_NONE);

ACS_LocalAmbientSound(ss_player_cbi_dlgopen, 127);
@@ -498,17 +512,17 @@ static void ActSCRIPT_S(struct player *p) {
ModSR_ZN(SetAC(ACS_NamedExecuteWithResult(s0, s1, s2, s3, s4)));
}

sync static void ActTELEPORT_INTERLEVEL(struct player *p) {
alloc_aut(0) sync static
void ActTELEPORT_INTERLEVEL(struct player *p) {
u32 tag = MemB2_G(VAR_ADRL);

ACS_Delay(5);
P_TeleportOut(p);
ACS_Teleport_NewMap(tag | LithMapMagic, 0, 0);

SetVA(ACT_HALT);
}

sync static void ActTELEPORT_INTRALEVEL(struct player *p) {
alloc_aut(0) sync static
void ActTELEPORT_INTRALEVEL(struct player *p) {
u32 tag = MemB2_G(VAR_ADRL);

ACS_Delay(5);
@@ -517,7 +531,8 @@ sync static void ActTELEPORT_INTRALEVEL(struct player *p) {
SetVA(ACT_HALT);
}

sync static void ActTRM_WAIT(struct player *p) {
alloc_aut(0) sync static
void ActTRM_WAIT(struct player *p) {
SetVA(ACT_NONE);

u32 tact = MemB1_G(VAR_TACT);
@@ -551,7 +566,8 @@ sync static void ActTRM_WAIT(struct player *p) {
/* Extern Functions -------------------------------------------------------- */

/* Main dialogue VM. */
script void Dlg_Run(struct player *p, u32 num) {
dynam_aut script
void Dlg_Run(struct player *p, u32 num) {
if(p->dead || p->dlg.active > 1)
return;

@@ -561,7 +577,9 @@ script void Dlg_Run(struct player *p, u32 num) {
p->dlg.active++;

if(!def->codeV) {
Log("%s: dialogue %u has no code", __func__, num);
#ifndef NDEBUG
Log("%s ERROR: dialogue %u has no code", __func__, num);
#endif
JmpHL;
}

@@ -587,14 +605,16 @@ script void Dlg_Run(struct player *p, u32 num) {
for(u32 i = 0; i < def->codeC; i++) memory[PRG_BEG_C + i] = def->codeV[i];
for(u32 i = 0; i < def->stabC; i++) memory[STR_BEG_C + i] = def->stabV[i];

#ifndef NDEBUG
if(get_bit(dbglevel, log_dlg)) {
ACS_BeginLog();
__nprintf("Dumping segment PRG..");
PrintChrSt("Dumping segment PRG...\n");
Dbg_PrintMemC(&memory[PRG_BEG_C], def->codeC);
__nprintf("Dumping segment STR..");
PrintChrSt("Dumping segment STR...\n");
Dbg_PrintMemC(&memory[STR_BEG_C], def->stabC);
ACS_EndLog();
}
#endif

/* copy some constants into memory */
MemB1_S(VAR_PCLASS, p->pclass);
@@ -933,20 +953,26 @@ INY_NP: ModSR_ZN(SetRY(GetRY() + 1)); JmpVI;

/* Trace */
TRR_NP:
#ifndef NDEBUG
ACS_BeginLog();
TraceReg();
ACS_EndLog();
JmpVI;
#endif

TRS_NP:
#ifndef NDEBUG
for(u32 i = GetSP() + 1; i <= 0xFF; i++)
Log("%02X: %02X", i, MemB1_G(STA_BEG + i));
JmpVI;
#endif

TRV_NP:
#ifndef NDEBUG
for(u32 i = 0; i <= 0xFF; i++)
Log("%02X: %02X", i, MemB1_G(VAR_BEG + i));
JmpVI;
#endif

halt:
Dbg_Log(log_dlg, "%s: exited", __func__);


+ 5
- 4
source/debug.c View File

@@ -11,6 +11,7 @@
* ---------------------------------------------------------------------------|
*/

#ifndef NDEBUG
#include "common.h"
#include "p_player.h"
#include "w_monster.h"
@@ -80,7 +81,7 @@ void Dbg_PrintMemC(void const *data, size_t size)
pos += 3;
}

__nprintf("\nEOF\n");
PrintChrSt("\nEOF\n");
}

void Dbg_PrintMem(void const *data, size_t size)
@@ -100,7 +101,7 @@ void Dbg_PrintMem(void const *data, size_t size)
pos += 3;
}

__nprintf("\nEOF\n");
PrintChrSt("\nEOF\n");
}

void Log(cstr fmt, ...)
@@ -118,7 +119,7 @@ void Log(cstr fmt, ...)

/* Scripts ----------------------------------------------------------------- */

script_str ext("ACS") addr(OBJ "FontTest")
alloc_aut(0) script_str ext("ACS") addr(OBJ "FontTest")
void Sc_FontTest(i32 fontnum) {
static struct {cstr lhs, rhs;} const strings[] = {
/*
@@ -190,7 +191,6 @@ void Sc_DbgDumpAlloc(void) {

script_str ext("ACS") addr(OBJ "PrintMonsterInfo")
void Sc_PrintMonsterInfo(void) {
extern void PrintMonsterInfo(void);
PrintMonsterInfo();
}

@@ -209,5 +209,6 @@ void Sc_TriggerEnding(i32 num) {
}
F_Start(which);
}
#endif

/* EOF */

+ 75
- 14
source/g_auto.c View File

@@ -15,6 +15,27 @@
#include "p_player.h"
#include "w_world.h"

/* Static Functions -------------------------------------------------------- */

static
void G_cutBox(struct gui_clip *other, i32 *x, i32 *y, i32 *w, i32 *h) {
*x = minmax(*x, other->x, other->x + other->w);
*y = minmax(*y, other->y, other->y + other->h);

*w = min(*x + *w, other->x + other->w) - *x;
*h = min(*y + *h, other->y + other->h) - *y;
}

static
void G_setClip(struct gui_state *g) {
if(g->clip >= 0) {
struct gui_clip *clip = &g->clips[g->clip];
SetClipW(clip->x, clip->y, clip->w, clip->h, clip->ww);
} else {
ClearClip();
}
}

/* Extern Functions -------------------------------------------------------- */

void G_Auto(struct gui_state *g, u32 id, i32 x, i32 y, i32 w, i32 h,
@@ -22,16 +43,16 @@ void G_Auto(struct gui_state *g, u32 id, i32 x, i32 y, i32 w, i32 h,
x += g->ox;
y += g->oy;

/* check clip versus cursor (if clipping), then check control
* versus cursor
*/
if((!g->useclip ||
aabb_point(g->clpxS, g->clpyS, g->clpxE, g->clpyE, g->cx, g->cy)) &&
aabb_point(x, y, w, h, g->cx, g->cy)) {
if(g->clip >= 0) {
G_cutBox(&g->clips[g->clip], &x, &y, &w, &h);
}

if(aabb_point(x, y, w, h, g->cx, g->cy)) {
g->hot = id;

if(g->active == 0 && g->clicklft)
if(g->active == 0 && g->clicklft) {
g->active = id;
}
}

/* check slide state */
@@ -40,6 +61,16 @@ void G_Auto(struct gui_state *g, u32 id, i32 x, i32 y, i32 w, i32 h,
g->slidetime = 1;
g->slidecount = 0;
}

#ifndef NDEBUG
if(get_bit(dbgflags, dbgf_gui)) {
PrintLine(x, y, x + w, y + h, 0xFF0000);
PrintLine(x, y, x + w, y, 0xFF0000);
PrintLine(x, y, x, y + h, 0xFF0000);
PrintLine(x, y + h, x + w, y + h, 0xFF0000);
PrintLine(x + w, y, x + w, y + h, 0xFF0000);
}
#endif
}

void G_Init(struct gui_state *g, void *state) {
@@ -86,6 +117,7 @@ void G_Begin(struct gui_state *g, i32 w, i32 h) {
if(!h) h = 200;

g->hot = 0;
g->clip = -1;

SetSize(g->w = w, g->h = h);
}
@@ -114,17 +146,46 @@ void G_End(struct gui_state *g, enum cursor curs) {
}

void G_Clip(struct gui_state *g, i32 x, i32 y, i32 w, i32 h, i32 ww) {
g->useclip = true;
g->clpxE = w;
g->clpyE = h;
struct gui_clip *clip, *other;

if(g->clip >= 0) {
other = &g->clips[g->clip];
} else {
other = nil;
}

if(ww == 0) ww = w;
SetClipW(g->clpxS = x, g->clpyS = y, w, h, ww);
clip = &g->clips[++g->clip];

clip->x = x;
clip->y = y;
clip->w = w;
clip->h = h;

if(other) {
G_cutBox(other, &clip->x, &clip->y, &clip->w, &clip->h);
}

clip->ww = ww ? min(ww, clip->w) : clip->w;

G_setClip(g);

#ifndef NDEBUG
if(get_bit(dbgflags, dbgf_gui)) {
x = clip->x, y = clip->y, w = clip->w, h = clip->h;
PrintLine(x, y, x + w, y + h, 0x00FFFF);
PrintLine(x, y, x + w, y, 0x00FFFF);
PrintLine(x, y + h, x + w, y + h, 0x00FFFF);
PrintLine(x + w, y, x + w, y + h, 0x00FFFF);
PrintLine(x, y, x, y + h, 0x00FFFF);

PrintLine(x, y + h / 2, x + clip->ww, y + h / 2, 0xFF00FF);
}
#endif
}

void G_ClipRelease(struct gui_state *g) {
g->useclip = g->clpxS = g->clpyS = g->clpxE = g->clpyE = 0;
ClearClip();
g->clip--;
G_setClip(g);
}

void G_TypeOn(struct gui_state *g, struct gui_typ *typeon, str text) {


+ 9
- 0
source/g_preset.c View File

@@ -303,6 +303,15 @@ struct gui_presets const gui_p = {
.w = 80,
.h = 7
},

.windef = {
.bg = "Background",
.w = 300,
.h = 219,
.a = 0.7k,
.bx = 3,
.by = 3,
},
};

/* EOF */

+ 2
- 4
source/g_scrollbar.c View File

@@ -157,8 +157,7 @@ void G_ScrBeg_Imp(struct gui_state *g, u32 id, struct gui_arg_scr const *a) {
G_Clip(g, x, ory, a->w, realh, a->ww);
}

void G_ScrEnd(struct gui_state *g, struct gui_scr *scr)
{
void G_ScrEnd(struct gui_state *g, struct gui_scr *scr) {
/* reset offsets */
g->ox -= scr->ox;
g->oy -= scr->oy;
@@ -167,8 +166,7 @@ void G_ScrEnd(struct gui_state *g, struct gui_scr *scr)
G_ClipRelease(g);
}

bool G_ScrOcc(struct gui_state *g, struct gui_scr const *scr, i32 y, i32 h)
{
bool G_ScrOcc(struct gui_state *g, struct gui_scr const *scr, i32 y, i32 h) {
return y > scr->occludeE || (h && (y + h) - scr->occludeS < 0);
}



+ 91
- 0
source/g_window.c View File

@@ -0,0 +1,91 @@
/* ---------------------------------------------------------------------------|
*
* Distributed under the CC0 public domain license.
* By Alison G. Watson. Attribution is encouraged, though not required.
* See licenses/cc0.txt for more information.
*
* ---------------------------------------------------------------------------|
*
* GUI windows.
*
* ---------------------------------------------------------------------------|
*/

#include "common.h"
#include "p_player.h"

void G_WinBeg_Imp(struct gui_state *g, u32 id, struct gui_arg_win const *a) {
struct gui_pre_win const *pre = a->preset ? a->preset : &gui_p.windef;
struct gui_win *win = a->st;

if(!win->init) {
i32 bx = g->w - pre->w;
i32 by = g->h - pre->h;
win->x = bx / 2;
win->y = by / 2;
win->init = true;
}

if(win->nextsnd) win->nextsnd--;

i32 ox = g->ox + win->x;
i32 oy = g->oy + win->y;

G_Auto(g, id,
ox, oy,
pre->w, pre->by);
G_Auto(g, id,
ox, oy,
pre->bx, pre->h);
G_Auto(g, id,
ox,
oy + pre->h - pre->by,
pre->w, pre->by);
G_Auto(g, id,
ox + pre->w - pre->bx,
oy,
pre->bx, pre->h);

if(g->active == id) {
win->x += g->cx - g->old.cx;
win->y += g->cy - g->old.cy;
win->x = minmax(win->x, 0, g->w - pre->w);
win->y = minmax(win->y, 0, g->h - pre->h);
ox = g->ox + win->x;
oy = g->oy + win->y;

if(g->cy != g->old.cy && win->nextsnd == 0) {
ACS_LocalAmbientSound(ss_player_cbi_scroll, 127);
win->grabbed = true;
win->nextsnd = 7;
}
} else if(win->grabbed) {
ACS_LocalAmbientSound(ss_player_cbi_scrollend, 127);
win->grabbed = false;
}

__with(char bg[64];) {
G_Prefix(g, bg, pre, bg);
PrintSpriteA(l_strdup(bg), ox,1, oy,1, pre->a);
}

ox += pre->bx;
oy += pre->by;

i32 const w = pre->w - pre->bx * 2;
i32 const h = pre->h - pre->by * 2;

g->ox += (win->ox = ox - g->ox);
g->oy += (win->oy = oy - g->oy);

G_Clip(g, g->ox, g->oy, w, h, w);
}

void G_WinEnd(struct gui_state *g, struct gui_win *win) {
g->ox -= win->ox;
g->oy -= win->oy;

G_ClipRelease(g);
}

/* EOF */

+ 15
- 2
source/include/common.h View File

@@ -102,11 +102,16 @@
#define DrawCallK(...) SCallK(so_Draw, __VA_ARGS__)
#define DrawCallS(...) SCallS(so_Draw, __VA_ARGS__)

#ifndef NDEBUG
#define Dbg_Stat(...) \
(get_bit(dbglevel, log_devh) ? Dbg_Stat_Impl(__VA_ARGS__) : (void)0)

#define Dbg_Note(...) \
(get_bit(dbglevel, log_devh) ? Dbg_Note_Impl(__VA_ARGS__) : (void)0)
#else
#define Dbg_Stat(...)
#define Dbg_Note(...)
#endif

#define InvGive ACS_GiveInventory
#define InvMax(arg) ACS_GetMaxInventory(0, arg)
@@ -115,6 +120,7 @@

/* Types ------------------------------------------------------------------- */

#ifndef NDEBUG
enum {
log_none,
log_dev, /* general debug info */
@@ -126,15 +132,18 @@ enum {
log_bip, /* debug info for the BIP */
log_sys, /* meta debug info */
log_sysV, /* tick info */
log_dpl, /* dynamic stack usage */
log_save, /* save data */
};

enum {
dbgf_bip,
dbgf_gui,
dbgf_items,
dbgf_save,
dbgf_score,
dbgf_upgr,
};
#endif

/* Extern Functions -------------------------------------------------------- */

@@ -147,18 +156,22 @@ i32 PtrInvNum(i32 tid, str item);
void PtrInvGive(i32 tid, str item, i32 amount);
void PtrInvTake(i32 tid, str item, i32 amount);
void PtrInvSet (i32 tid, str item, i32 amount);
#ifndef NDEBUG
void Dbg_Stat_Impl(cstr fmt, ...);
void Dbg_Note_Impl(cstr fmt, ...);
void Dbg_PrintMem(void const *data, size_t size);
void Dbg_PrintMemC(void const *data, size_t size);
void Log(cstr fmt, ...);
#endif

/* Extern Objects ---------------------------------------------------------- */

#ifndef NDEBUG
extern str dbgstat[], dbgnote[];
extern i32 dbgstatnum, dbgnotenum;

extern i32 lmvar dbglevel;
extern i32 lmvar dbgflag;
extern i32 lmvar dbgflags;
#endif

#endif

+ 2
- 0
source/include/d_vm.h View File

@@ -444,6 +444,8 @@ struct dcd_info {

/* Extern Functions -------------------------------------------------------- */

void Dlg_MInit(void);

script void Dlg_Run(struct player *p, u32 num);

/* Extern Objects ---------------------------------------------------------- */


+ 41
- 15
source/include/gui.h View File

@@ -68,9 +68,13 @@

/* Types ------------------------------------------------------------------- */

struct gui_fil {
u32 *ptr;
u32 tic;
};

struct gui_scr {
i32 ox;
i32 oy;
i32 ox, oy;
i32 occludeS;
i32 occludeE;
k64 y;
@@ -90,9 +94,11 @@ struct gui_txt {
i32 tbptr;
};

struct gui_fil {
u32 *ptr;
u32 tic;
struct gui_win {
bool init, grabbed;
i32 x, y;
i32 ox, oy;
i32 nextsnd;
};

struct gui_delta {
@@ -103,6 +109,10 @@ struct gui_delta {
bool clickany;
};

struct gui_clip {
i32 x, y, w, h, ww;
};

struct gui_state {
anonymous
struct gui_delta cur;
@@ -121,8 +131,8 @@ struct gui_state {
u32 dbl;
i32 dbltime;

bool useclip;
i32 clpxS, clpyS, clpxE, clpyE;
i32 clip;
struct gui_clip clips[16];

void *state;

@@ -136,12 +146,12 @@ struct gui_pre_btn {
cstr cact;
cstr chot;
cstr cdis;
str font;
str snd;
i32 ax;
i32 ay;
i32 w;
i32 h;
str font;
str snd;
i32 ax;
i32 ay;
i32 w;
i32 h;
bool external;
};

@@ -230,6 +240,21 @@ struct gui_arg_txt {
struct player *p;
};

struct gui_pre_win {
cstr bg;
i32 w;
i32 h;
k32 a;
i32 bx;
i32 by;
bool external;
};

struct gui_arg_win {
struct gui_win *st;
struct gui_pre_win const *preset;
};

struct gui_presets {
struct gui_pre_btn btndef;
struct gui_pre_btn btntab;
@@ -251,6 +276,7 @@ struct gui_presets {
struct gui_pre_cbx cbxsmall;
struct gui_pre_scr scrdef;
struct gui_pre_sld slddef;
struct gui_pre_win windef;
};

enum cursor {
@@ -301,14 +327,14 @@ void G_ScrEnd(struct gui_state *g, struct gui_scr *scr);
optargs(1)
bool G_ScrOcc(struct gui_state *g, struct gui_scr const *scr, i32 y, i32 h);

void G_WinEnd(struct gui_state *g, struct gui_win *win);

#define G_ImpArgs(ty) struct gui_state *g, u32 id, struct gui_arg_##ty const *a
bool G_Button_Imp(G_ImpArgs(btn));
bool G_ChkBox_Imp(G_ImpArgs(cbx));
void G_ScrBeg_Imp(G_ImpArgs(scr));
k64 G_Slider_Imp(G_ImpArgs(sld));
struct gui_txt *G_TxtBox_Imp(G_ImpArgs(txt));
#if 0
void G_WinBeg_Imp(G_ImpArgs(win));
#endif

#endif

+ 21
- 23
source/include/m_char.h View File

@@ -11,27 +11,25 @@
* ---------------------------------------------------------------------------|
*/

local bool IsGraph(i32 c) {return c > ' ' && c <= '~';}
local bool IsPrint(i32 c) {return c >= ' ' && c <= '~';}
local bool IsPunct(i32 c) {return c >= '!' && c <= '/' ||
c >= ':' && c <= '@' ||
c >= '[' && c <= '`' ||
c >= '{' && c <= '~';}
local bool IsSpace(i32 c) {return c >= 9 && c <= 13 ||
c == ' ';}
local bool IsBlank(i32 c) {return c == ' ' || c == 9;}
local bool IsDigit(i32 c) {return c >= '0' && c <= '9';}
local bool IsXDigi(i32 c) {return c >= 'a' && c <= 'f' ||
c >= 'A' && c <= 'F' ||
IsDigit(c);}
local bool IsLower(i32 c) {return c >= 'a' && c <= 'z';}
local bool IsUpper(i32 c) {return c >= 'A' && c <= 'Z';}
local bool IsAlpha(i32 c) {return IsLower(c) || IsUpper(c);}
local bool IsAlNum(i32 c) {return IsAlpha(c) || IsDigit(c);}
local bool IsIdent(i32 c) {return IsAlNum(c) || c == '_';}
local bool IsNumId(i32 c) {return IsIdent(c) || c == '.';}
local bool IsCntrl(i32 c) {return !IsPrint(c);}
local i32 ToUpper(i32 c) {return IsLower(c) ? c - ('a' - 'A') : c;}
local i32 ToLower(i32 c) {return IsUpper(c) ? c + ('a' - 'A') : c;}
#ifndef m_char_h
#define m_char_h
#include "m_types.h"

/* EOF */
stkcall bool IsGraph(i32 c);
stkcall bool IsPrint(i32 c);
stkcall bool IsPunct(i32 c);
stkcall bool IsSpace(i32 c);
stkcall bool IsBlank(i32 c);
stkcall bool IsDigit(i32 c);
stkcall bool IsXDigi(i32 c);
stkcall bool IsLower(i32 c);
stkcall bool IsUpper(i32 c);
stkcall bool IsAlpha(i32 c);
stkcall bool IsAlNum(i32 c);
stkcall bool IsIdent(i32 c);
stkcall bool IsNumId(i32 c);
stkcall bool IsCntrl(i32 c);
stkcall i32 ToUpper(i32 c);
stkcall i32 ToLower(i32 c);

#endif

+ 2
- 0
source/include/m_drawing.h View File

@@ -246,6 +246,8 @@ enum /* Channel */
};

/* decompat-cut */
void Draw_Init(void);

#endif
/* decompat-end */



+ 20
- 15
source/include/m_math.h View File

@@ -21,13 +21,16 @@
#define min(x, y) ((x) < (y) ? (x) : (y))
#define minmax(x, mi, ma) (min(max(x, mi), ma))

#define k32_to_i32(n) ((union ik32){.k=(n)}.i)
#define i32_to_k32(n) ((union ik32){.i=(n)}.k)
#define k32_to_u32(n) ((union uk32){.k=(n)}.u)
#define u32_to_k32(n) ((union uk32){.u=(n)}.k)
#define k32_to_i32(n) (ik32.k = (n), ik32.i)
#define i32_to_k32(n) (ik32.i = (n), ik32.k)
#define k32_to_u32(n) (uk32.k = (n), uk32.u)
#define u32_to_k32(n) (uk32.u = (n), uk32.k)

#define k32_to_byte(n) ((k32_to_u32((k32)(n) * 255.0) >> 16) & 0xff)

extern union ik32 ik32;
extern union uk32 uk32;

/* To make pitch values down=0, up=1 */
#define PITCH_BASE (-0.5)

@@ -50,20 +53,22 @@ struct interp_data_lli {

optargs(1) u64 crc64(void const *data, size_t len, u64 result);
optargs(1) u64 crc64_str(void __str_ars const *data, size_t len, u64 result);
i32 fastabs(i32 n);
k64 powlk(k64 x, i32 y);
k64 mag2lk(k64 x, k64 y);
k32 mag2k(k32 x, k32 y);
i32 mag2i(i32 x, i32 y);
k32 lerpk(k32 a, k32 b, k32 t);
stkcall i32 fastabs(i32 n);
stkcall k32 fastabsk(k32 n);
stkcall k32 fastroundk(k32 k, i32 n);
stkcall k64 powlk(k64 x, i32 y);
stkcall k64 mag2lk(k64 x, k64 y);
stkcall k32 mag2k(k32 x, k32 y);
stkcall i32 mag2i(i32 x, i32 y);
stkcall k32 lerpk(k32 a, k32 b, k32 t);
k64 lerplk(k64 a, k64 b, k64 t);
void lerplli(struct interp_data_lli *data);
void lerplli_init(struct interp_data_lli *data, i96 value, i96 timer);
bool aabb_aabb(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2, i32 w2, i32 h2);
bool aabb_point(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2);
i32 ceilk(k32 n);
k64 bzpolylk(k64 a, k64 b, k64 t);
i32 bzpolyi(i32 a, i32 b, k64 t);
stkcall bool aabb_aabb(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2, i32 w2, i32 h2);
stkcall bool aabb_point(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2);
stkcall i32 ceilk(k32 n);
stkcall k64 bzpolylk(k64 a, k64 b, k64 t);
stkcall i32 bzpolyi(i32 a, i32 b, k64 t);
struct i32v2 qbezieri(i32 x1, i32 y1, i32 x2, i32 y2, i32 x3, i32 y3, k64 t);
struct k64v2 qbezierlk(k64 x1, k64 y1, k64 x2, k64 y2, k64 x3, k64 y3, k64 t);
struct polar ctopol(k32 x, k32 y);


+ 6
- 3
source/include/m_memory.h View File

@@ -35,11 +35,14 @@ enum {
_tag_max
};

typedef i32 mem_tag_t;
typedef i32 mem_size_t;

#define Salloc(t, tag) Malloc(sizeof(t), tag)

stkcall void Dalloc(void *p);
stkcall void *Malloc(size_t s, u32 tag);
stkcall void *Ralloc(void *p, size_t s, u32 tag);
stkcall void Xalloc(u32 tag);
stkcall void *Malloc(mem_size_t s, mem_tag_t tag);
stkcall void *Ralloc(void *p, mem_size_t s, mem_tag_t tag);
stkcall void Xalloc(mem_tag_t tag);

#endif

+ 0
- 7
source/include/m_stab.h View File

@@ -28,13 +28,6 @@ X(s_ltrmfont, "ltrmfont")
X(s_smallfnt, "smallfnt")

/* Console Variables */
X(sc_debug_all, DCVAR "debug_all")
X(sc_debug_bip, DCVAR "debug_bip")
X(sc_debug_items, DCVAR "debug_items")
X(sc_debug_level, DCVAR "debug_level")
X(sc_debug_save, DCVAR "debug_save")
X(sc_debug_score, DCVAR "debug_score")
X(sc_debug_upgrades, DCVAR "debug_upgrades")
X(sc_fun, DCVAR "fun")
X(sc_gui_buyfiller, CVAR "gui_buyfiller")
X(sc_gui_cursor, CVAR "gui_cursor")


+ 19
- 16
source/include/m_str.h View File

@@ -35,12 +35,15 @@
(ACS_BeginPrint(), PrintChrSt(s1), PrintChrSt(s2), ACS_EndStrParam())

#define fastmemset(p, s, c, ...) \
for(register i32 _i = 0; _i < (c); _i++) ((byte __VA_ARGS__ *)(p))[_i] = s
__with(register byte *_p = (void *)(p), \
_s = (s);) \
for(register i32 _i = 0, _c = (c); _i < _c; _i++) \
_p[_i] = _s

#define fastmemmove(lhs, rhs, s) \
do { \
register char *_lhs = (void *)(lhs); \
register char const *_rhs = (void *)(rhs); \
register byte *_lhs = (void *)(lhs); \
register byte const *_rhs = (void *)(rhs); \
register size_t _s = (s); \
if(_lhs < _rhs) { \
while(_s--) \
@@ -53,22 +56,22 @@
} \
} while(0)

str l_strupper(str in);
u32 l_strhash(astr s);
u32 lstrhash(cstr s);
char *lstrcpy_str(char *dest, astr src);
char *lstrcpy2(char *out, cstr s1, cstr s2);
char *lstrcpy3(char *out, cstr s1, cstr s2, cstr s3);
i32 lstrcmp_str(cstr s1, astr s2);
i32 faststrcmp(cstr s1, cstr s2);
i32 faststrcasecmp(cstr s1, cstr s2);
cstr scoresep(i96 num);
cstr alientext(i32 num);
stkcall str l_strupper(str in);
stkcall u32 l_strhash(astr s);
stkcall u32 lstrhash(cstr s);
stkcall char *lstrcpy_str(char *dest, astr src);
stkcall char *lstrcpy2(char *out, cstr s1, cstr s2);
stkcall char *lstrcpy3(char *out, cstr s1, cstr s2, cstr s3);
stkcall i32 lstrcmp_str(cstr s1, astr s2);
stkcall i32 faststrcmp(cstr s1, cstr s2);
stkcall i32 faststrcasecmp(cstr s1, cstr s2);
stkcall cstr scoresep(i96 num);
stkcall cstr alientext(i32 num);
str LanguageV(str name);
char *LanguageVC(char *out, cstr name);
char *LanguageCV(char *out, cstr name, ...);
str LanguageNull(cstr fmt, ...);
cstr RemoveTextColors_str(astr s, i32 size);
cstr RemoveTextColors (cstr s, i32 size);
stkcall cstr RemoveTextColors_str(astr s, i32 size);
stkcall cstr RemoveTextColors (cstr s, i32 size);

/* EOF */

+ 13
- 14
source/include/m_types.h View File

@@ -24,20 +24,19 @@
#define snil ((__str_ent *)0)
#define lnil ((__label *)0)

#define script [[__call("ScriptI")]]
#define script_str [[__call("ScriptS")]]
#define stkcall [[__call("StkCall")]]
#define sync [[__call("SScriptI")]]
#define sync_str [[__call("SScriptS")]]
#define optargs(x) [[__optional_args(x)]]
#define noinit [[__no_init]]
#define anonymous [[__anonymous]]
#define ext(x) [[__extern(x)]]
#define stksize(x) [[__alloc_Aut(x)]]
#define type(x) [[__script(x)]]
#define addr(x) [[__address(x)]]

#define local static inline
#define script [[__call("ScriptI")]]
#define script_str [[__call("ScriptS")]]
#define stkcall [[__call("StkCall")]]
#define sync [[__call("SScriptI")]]
#define sync_str [[__call("SScriptS")]]
#define optargs(x) [[__optional_args(x)]]
#define noinit [[__no_init]]
#define anonymous [[__anonymous]]
#define ext(x) [[__extern(x)]]
#define alloc_aut(x) [[__alloc_Aut(x)]]
#define dynam_aut [[__alloc_Aut(0x80000000)]]
#define type(x) [[__script(x)]]
#define addr(x) [[__address(x)]]

/* Types ------------------------------------------------------------------- */



+ 1
- 0
source/include/p_attrib.h View File

@@ -33,6 +33,7 @@ struct player_attributes {

char names[at_max][3];
char lvupstr[130];
u32 lvupstrn;
};

#endif

+ 18
- 0
source/include/p_cbi.h View File

@@ -69,6 +69,8 @@ struct cbi {
u32 infotab;
u32 settingstab;

struct gui_win mainwin;

struct gui_typ biptypeon;
struct gui_scr bipscr;
struct gui_scr bipinfoscr;
@@ -102,6 +104,22 @@ struct cbi {

/* Extern Functions -------------------------------------------------------- */

void CBI_InstallSpawned(void);

void P_CBI_TabUpgrades(struct gui_state *g, struct player *p);
void P_CBI_TabShop (struct gui_state *g, struct player *p);

void P_CBI_TabCBI (struct gui_state *g, struct player *p);
void P_CBI_TabStatus (struct gui_state *g, struct player *p);
void P_CBI_TabStatistics(struct gui_state *g, struct player *p);

void P_CBI_TabBIP (struct gui_state *g, struct player *p);
void P_CBI_TabLog (struct gui_state *g, struct player *p);
void P_CBI_TabNotes (struct gui_state *g, struct player *p);

void P_CBI_TabItems (struct gui_state *g, struct player *p);
void P_CBI_TabSettings(struct gui_state *g, struct player *p);

void P_CBI_PMinit(struct player *p);

#endif

+ 2
- 0
source/include/p_log.h View File

@@ -48,6 +48,8 @@ struct loginfo
u32 curtime;
};

str RandomName(i32 id);

void P_Log_Both(struct player *p, i32 levl, cstr fmt, ...); /* log to HUD and full log */
void P_Log_HUDs(struct player *p, i32 levl, cstr fmt, ...); /* log to HUD only */
void P_Log_Full(struct player *p, cstr fmt, ...); /* log to full log only */


+ 25
- 3
source/include/p_player.h View File

@@ -55,6 +55,7 @@ PCL(gR, pcl_robot)

#define LocalPlayer \
(ACS_PlayerNumber() >= 0 ? &players[ACS_PlayerNumber()] : (struct player *)nil)
#define UnsafeLocalPlayer players[ACS_PlayerNumber()]
#define P_Discount(n) (i96)((n) * p->discount)
#define P_None(p) (!(p) || !(p)->active)
#define with_player(ptr) \
@@ -80,13 +81,35 @@ void P_Lv_GiveEXP(struct player *p, u64 amt);
cstr P_Discrim(i32 pclass);
i32 P_Color(i32 pclass);
void P_Dat_PTickPst(struct player *p);
struct player *P_PtrFind(i32 tid, i32 ptr);
stkcall struct player *P_PtrFind(i32 tid, i32 ptr);
script extern void P_Scr_Payout(struct player *p);
void P_Log_SellWeapon(struct player *p, struct weaponinfo const *info, i96 score);
void P_Log_Weapon(struct player *p, struct weaponinfo const *info);
i32 P_Wep_FromName(struct player *p, i32 name);

script extern void P_Wep_PTickPre(struct player *p);
extern void P_Dat_PTickPre(struct player *p);
script extern void P_CBI_PTick (struct player *p);
script extern void P_Inv_PTick (struct player *p);
script extern void P_Log_PTick (struct player *p);
script extern void P_Upg_PTick (struct player *p);
script extern void P_Wep_PTick (struct player *p);
script extern void P_Upg_PTickPst(struct player *p);
extern void P_Ren_PTickPst(struct player *p);

sync void P_TeleportIn(struct player *p);
sync void P_TeleportOut(struct player *p);
script void P_TeleportInAsync(struct player *p);
script void P_TeleportOutAsync(struct player *p);

#ifndef NDEBUG
void P_Ren_Debug(struct player *p);
#endif
void P_Ren_Magic(struct player *p);
script void P_Ren_Step(struct player *p);
void P_Ren_View(struct player *p);
script void P_Ren_Scope(struct player *p);

/* Types ------------------------------------------------------------------- */

enum {
@@ -245,8 +268,7 @@ struct player

char *notes[16];

u32 nextstep;
bool hadinfrared;
u32 nextstep;

bool teleportedout;
u32 done_intro;


+ 2
- 0
source/include/p_shopdef.h View File

@@ -32,6 +32,8 @@ struct shopdef
bool (*ShopGive) (struct player *p, struct shopdef const *def, void *obj, i32 tid);
};

void Shop_MInit(void);

i96 P_Shop_Cost(struct player *p, struct shopdef const *def);
bool P_Shop_CanBuy(struct player *p, struct shopdef const *def, void *obj);
optargs(1) bool P_Shop_Buy(struct player *p, struct shopdef const *def, void *obj, cstr namefmt, bool nodelivery, bool nolog);


+ 3
- 1
source/include/p_upgrades.h View File

@@ -35,13 +35,15 @@
#define RequiresButDontHave_RDI RequiresButDontHave(UR_RDI, cbiupgr[cupg_rdistinter])
#define RequiresButDontHave_RA RequiresButDontHave(UR_RA, get_bit(p->upgrades[UPGR_ReactArmor].flags, _ug_owned))

/* Extern Functions -------------------------------------------------------- */
extern struct upgradeinfo upgrinfo[UPGR_MAX];

/* These are included here so the compiler may check the function signatures. */
#define Fn_F(n, cb) void Upgr_##n##_##cb(struct player *p, struct upgrade *upgr);
#define Fn_S(n, cb) script void Upgr_##n##_##cb(struct player *p, struct upgrade *upgr);
#include "u_func.h"

void Upgr_MInit(void);

script void P_Upg_PInit(struct player *p);
void P_Upg_PQuit(struct player *p);
void P_Upg_PDeinit(struct player *p);


+ 3
- 0
source/include/p_wepinfo.h View File

@@ -63,6 +63,9 @@ struct weapondata {
};

extern struct weaponinfo const weaponinfo[weapon_max];

void Wep_GInit(void);

cstr P_Wep_GetPickup(i32 n);

#endif

+ 1
- 1
source/include/u_func_beg.h View File

@@ -12,7 +12,7 @@
*/

#if defined(Ret)
#define Case(n) Ret(n) case UPGR_##n:;
#define Case(n) Ret(n) case UPGR_##n:
#define A(n) Fn_F(n, Activate)
#define D(n) Fn_F(n, Deactivate)
#define U(n) Fn_S(n, Update)


+ 3
- 0
source/include/w_monster.h View File

@@ -92,11 +92,14 @@ struct dmon {
/* address space, and then I'd have to do a bunch of rewriting again */
typedef struct dmon dmon_t;

void DmonInit();

script dmon_t *DmonPtr(i32 tid, i32 ptr);
dmon_t *DmonSelf(void);
dmon_t *Dmon(i32 id);
dmon_t *AllocDmon(void);

void PrintMonsterInfo(void);
void PrintDmonAllocSize(struct player *p);

#endif


+ 4
- 0
source/include/w_world.h View File

@@ -101,6 +101,7 @@ extern bool cbiupgr[cupg_max];
extern bool legendoom;
extern bool drlamonsters;
extern enum mission_status lmvar mission;
extern bool dorain;

/* DECORATE data */
extern i32 a_x, a_y;
@@ -109,6 +110,7 @@ extern i32 a_cur;

/* Extern Functions -------------------------------------------------------- */

void Scr_HInit(void);
cstr CanonTime(i32 type, u64 time);
optargs(1) i32 UniqueID(i32 tid);
void BeginAngles(i32 x, i32 y);
@@ -116,8 +118,10 @@ k32 AddAngle(i32 x, i32 y);
optargs(1) void FreezeTime(bool players_ok);
optargs(1) void UnfreezeTime(bool players_ok);
script void CBI_Install(i32 num);
script void W_Title(void);
script void F_Run(struct player *p);
void F_Load(void);
void F_Start(cstr which);
script void W_DoRain();

#endif

+ 39
- 0
source/m_char.c View File

@@ -0,0 +1,39 @@
/* ---------------------------------------------------------------------------|
*
* Distributed under the CC0 public domain license.
* By Alison G. Watson. Attribution is encouraged, though not required.
* See licenses/cc0.txt for more information.
*
* ---------------------------------------------------------------------------|
*
* Various string functions.
*
* ---------------------------------------------------------------------------|
*/

#include "m_char.h"

alloc_aut(0) stkcall bool IsGraph(i32 c) {return c > ' ' && c <= '~';}
alloc_aut(0) stkcall bool IsPrint(i32 c) {return c >= ' ' && c <= '~';}
alloc_aut(0) stkcall bool IsPunct(i32 c) {return c >= '!' && c <= '/' ||
c >= ':' && c <= '@' ||
c >= '[' && c <= '`' ||
c >= '{' && c <= '~';}
alloc_aut(0) stkcall bool IsSpace(i32 c) {return c >= 9 && c <= 13 ||
c == ' ';}
alloc_aut(0) stkcall bool IsBlank(i32 c) {return c == ' ' || c == 9;}
alloc_aut(0) stkcall bool IsDigit(i32 c) {return c >= '0' && c <= '9';}
alloc_aut(0) stkcall bool IsXDigi(i32 c) {return c >= 'a' && c <= 'f' ||
c >= 'A' && c <= 'F' ||
IsDigit(c);}
alloc_aut(0) stkcall bool IsLower(i32 c) {return c >= 'a' && c <= 'z';}
alloc_aut(0) stkcall bool IsUpper(i32 c) {return c >= 'A' && c <= 'Z';}
alloc_aut(0) stkcall bool IsAlpha(i32 c) {return IsLower(c) || IsUpper(c);}
alloc_aut(0) stkcall bool IsAlNum(i32 c) {return IsAlpha(c) || IsDigit(c);}
alloc_aut(0) stkcall bool IsIdent(i32 c) {return IsAlNum(c) || c == '_';}
alloc_aut(0) stkcall bool IsNumId(i32 c) {return IsIdent(c) || c == '.';}
alloc_aut(0) stkcall bool IsCntrl(i32 c) {return !IsPrint(c);}
alloc_aut(0) stkcall i32 ToUpper(i32 c) {return IsLower(c) ? c - ('a' - 'A') : c;}
alloc_aut(0) stkcall i32 ToLower(i32 c) {return IsUpper(c) ? c + ('a' - 'A') : c;}

/* EOF */

+ 6
- 3
source/m_file.c View File

@@ -44,15 +44,16 @@ struct netfile {
static i32 NetClose(void *nfdata) {
struct netfile *nf = nfdata;

#ifndef NDEBUG
/* If debugging, print out information about the buffer being written. */
if(get_bit(dbgflag, dbgf_save))
{
if(get_bit(dbglevel, log_save)) {
ACS_BeginLog();
__nprintf("NetClose: Writing netfile \"%S\" (%zub)\nData follows\n",
nf->pcvar, nf->pos);
Dbg_PrintMem(nf->mem, nf->pos);
ACS_EndLog();
}
#endif

/* Base64 encode the buffer. */
size_t outsize;
@@ -199,14 +200,16 @@ FILE *NFOpen(i32 pnum, str pcvar, char rw) {

Dalloc(input);

#ifndef NDEBUG
/* If debugging, print out information about the buffer being read. */
if(get_bit(dbgflag, dbgf_save)) {
if(get_bit(dbglevel, log_save)) {
ACS_BeginLog();
__nprintf("NFOpen: Opening memfile \"%S\" (%zub)\nData follows\n",
pcvar, size);
Dbg_PrintMem(data, size);
ACS_EndLog();
}
#endif

if(data) {
struct memfile *mem = Salloc(struct memfile, _tag_file);


+ 59
- 8
source/m_math.c View File

@@ -16,11 +16,17 @@
#include <math.h>

#define BezierImpl(type, ret, func) \
static ret r; \
type xa = func(x1, x2, t); \
type ya = func(y1, y2, t); \
type xb = func(x2, x3, t); \
type yb = func(y2, y3, t); \
return (ret){func(xa, xb, t), func(ya, yb, t)}
r.x = func(xa, xb, t); \
r.y = func(ya, yb, t); \
return r

union ik32 ik32;
union uk32 uk32;

static u64 lmvar crctable[256]; /* NB: Don't try to hash >8bit data. */
static bool lmvar crcinit;
@@ -72,6 +78,7 @@ u64 crc64_str(void __str_ars const *data, size_t len, u64 result)
return ~result;
}

alloc_aut(0) stkcall
i32 fastabs(i32 n)
{
[[return]] __asm(
@@ -79,11 +86,43 @@ i32 fastabs(i32 n)
"Jcnd_Tru(Stk() Lit(:\"neg\"))"
"Retn (LocReg(Lit(:n)))"
":\"neg\""
"Neg:I (Stk() LocReg(Lit(:n)))"
"Retn (Stk())"
"Neg:I(Stk() LocReg(Lit(:n)))"
"Retn (Stk())"
);
}

alloc_aut(0) stkcall
k32 fastabsk(k32 n)
{
[[return]] __asm(
"BAnd (Stk() LocReg(Lit(:n)) Lit(0x80000000_s31.0))"
"Jcnd_Tru(Stk() Lit(:\"neg\"))"
"Retn (LocReg(Lit(:n)))"
":\"neg\""
"Neg:I(Stk() LocReg(Lit(:n)))"
"Retn (Stk())"
);
}

alloc_aut(0) stkcall
k32 fastroundk(k32 k, i32 n) {
i32 mask = ~(0xFFFF >> n);

ik32.k = k;

if(ik32.i & (((0xFFFF >> 1) + 1) >> n)) {
if((ik32.i & mask) == (mask & 0x7FFFFFFF))
return ACCUM_MAX;

ik32.i += (0xFFFF + 1) >> n;
}

ik32.i &= mask;

return ik32.k;
}

alloc_aut(0) stkcall
k64 powlk(k64 x, i32 y)
{
k64 z = 1;
@@ -91,26 +130,30 @@ k64 powlk(k64 x, i32 y)
return z;
}

alloc_aut(0) stkcall
k64 mag2lk(k64 x, k64 y)
{
return ACS_FixedSqrt(x * x + y * y);
}

alloc_aut(0) stkcall
k32 mag2k(k32 x, k32 y)
{
return ACS_FixedSqrt(x * x + y * y);
}

alloc_aut(0) stkcall
i32 mag2i(i32 x, i32 y)
{
return ACS_Sqrt(x * x + y * y);
}

alloc_aut(0) stkcall
k32 lerpk(k32 a, k32 b, k32 t)
{
k32 ret = (1.0k - t) * a + t * b;

if(roundk(ret, 15) == b)
if(fastroundk(ret, 15) == b)
return b;

return ret;
@@ -166,6 +209,7 @@ void lerplli_init(struct interp_data_lli *data, i96 value, i96 timer)
data->timer_max_cap = 2;
}

alloc_aut(0) stkcall
bool aabb_aabb(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2, i32 w2, i32 h2)
{
return
@@ -175,6 +219,7 @@ bool aabb_aabb(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2, i32 w2, i32 h2)
y1 + h1 > y2;
}

alloc_aut(0) stkcall
bool aabb_point(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2) {
return
x2 >= x1 &&
@@ -183,18 +228,21 @@ bool aabb_point(i32 x1, i32 y1, i32 w1, i32 h1, i32 x2, i32 y2) {
y2 <= y1 + h1;
}

alloc_aut(0) stkcall
i32 ceilk(k32 n)
{
union ik32 u = {.k = n};
if(u.i & 0xFFF1) return u.i &= 0xFFFF0000, u.k + 1;
else return u.k;
ik32.k = n;
if(ik32.i & 0xFFF1) return ik32.i &= 0xFFFF0000, ik32.k + 1;
else return ik32.k;
}

alloc_aut(0) stkcall
k64 bzpolylk(k64 a, k64 b, k64 t)
{
return a + (b - a) * t;
}

alloc_aut(0) stkcall
i32 bzpolyi(i32 a, i32 b, k64 t)
{
return a + (b - a) * t;
@@ -212,7 +260,10 @@ struct i32v2 qbezieri(i32 x1, i32 y1, i32 x2, i32 y2, i32 x3, i32 y3, k64 t)

struct polar ctopol(k32 x, k32 y)
{
return (struct polar){ACS_VectorAngle(x, y), mag2i(x, y)};
static struct polar pol;
pol.ang = ACS_VectorAngle(x, y);
pol.dst = mag2i(x, y);
return pol;
}

/* EOF */

+ 191
- 92
source/m_memory.c View File

@@ -13,17 +13,21 @@

#include "common.h"

#define _mem_idn 0x71711177
#define _mem_idn 0xC0FFEE69
#define _mem_beg 0xADEADBED
#define _mem_frg 64
#define _mem_frg 128
#define _mem_siz 268435456

#define _pls_siz 67108864

#define _dpl_siz 64
#define _dpl_bsz 8192

struct mem_blk {
mem_tag_t idn;
struct mem_blk *prv, *nxt;
size_t siz;
u32 tag, idn;
mem_size_t siz;
mem_tag_t tag;
char dat[];
};

@@ -32,6 +36,11 @@ struct mem_top {
char dat[];
};

struct dpl_blk {
struct dpl_blk *prv, *nxt;
char dat[_dpl_bsz];
};

noinit static
char mem_dat[_mem_siz];

@@ -41,21 +50,11 @@ struct mem_top *mem_top;
noinit static
char pls_stk[_pls_siz], *pls_cur;

stkcall static
void AllocInit(void) {
mem_top = (void *)mem_dat;

mem_top->beg.prv = mem_top->beg.nxt = mem_top->cur = (void *)mem_top->dat;
mem_top->beg.tag = _tag_head;
mem_top->beg.idn = _mem_beg;

mem_top->cur->prv = mem_top->cur->nxt = &mem_top->beg;
mem_top->cur->tag = _tag_free;
mem_top->cur->siz = sizeof(mem_dat) - sizeof(struct mem_top);
}
noinit static
struct dpl_blk dpl_dat[_dpl_siz], *dpl_ina, *dpl_act;

stkcall static
cstr TagName(u32 tag) {
alloc_aut(0) stkcall static
cstr TagName(mem_tag_t tag) {
switch(tag) {
case _tag_cybr: return "cyberspace";
case _tag_dlgs: return "dialogue";
@@ -72,21 +71,8 @@ cstr TagName(u32 tag) {
return "unknown";
}

stkcall static
struct mem_blk *MergeAdjacent(struct mem_blk *blk, struct mem_blk *adj) {
adj->siz += blk->siz;
adj->nxt = blk->nxt;
adj->nxt->prv = adj;

if(blk == mem_top->cur) {
mem_top->cur = adj;
}

return adj;
}

#ifndef NDEBUG
stkcall static
alloc_aut(0) stkcall static
struct mem_blk *CheckUsedBlock(struct mem_blk *blk, cstr func) {
if((void *)blk < (void *)mem_dat ||
(void *)blk > (void *)(mem_dat + sizeof mem_dat)) {
@@ -94,7 +80,7 @@ struct mem_blk *CheckUsedBlock(struct mem_blk *blk, cstr func) {
ACS_BeginPrint();
PrintChrSt(func);
ACS_PrintString(err);
ACS_PrintHex((uintptr_t)blk);
ACS_PrintHex((intptr_t)blk);
ACS_EndLog();
return nil;
}
@@ -104,7 +90,7 @@ struct mem_blk *CheckUsedBlock(struct mem_blk *blk, cstr func) {
ACS_BeginPrint();
PrintChrSt(func);
ACS_PrintString(err);
ACS_PrintHex((uintptr_t)blk);
ACS_PrintHex((intptr_t)blk);
ACS_EndLog();
return nil;
}
@@ -114,7 +100,7 @@ struct mem_blk *CheckUsedBlock(struct mem_blk *blk, cstr func) {
ACS_BeginPrint();
PrintChrSt(func);
ACS_PrintString(err);
ACS_PrintHex((uintptr_t)blk);
ACS_PrintHex((intptr_t)blk);
ACS_EndLog();
return nil;
}
@@ -128,38 +114,63 @@ struct mem_blk *CheckUsedBlock(struct mem_blk *blk, cstr func) {
#define GetBlock(p) \
((struct mem_blk *)((char *)p - sizeof(struct mem_blk)))

stkcall
alloc_aut(0) stkcall
struct mem_blk *MergeAdjacent(struct mem_blk *lhs, struct mem_blk *rhs)
{
rhs->siz += lhs->siz;
(rhs->nxt = lhs->nxt)->prv = rhs;

return
lhs == mem_top->cur
? mem_top->cur = rhs
: rhs;
}

alloc_aut(0) stkcall
void Dalloc(register void *p) {
register struct mem_blk *blk;