Browse Source

rewrite dialogue VM entirely, making it a 6502 emulator

tags/1.6.2
Alison Watson 2 years ago
parent
commit
751a808966
57 changed files with 2158 additions and 1046 deletions
  1. BIN
      pk7/acs/lithmain.bin
  2. +30
    -28
      pk7/lfiles/Dialogue_TESTMAP.txt
  3. +6
    -4
      source/Headers/common.h
  4. +404
    -79
      source/Headers/dialogue.h
  5. +0
    -31
      source/Headers/dlgstab.h
  6. +32
    -32
      source/Headers/gui.h
  7. +22
    -22
      source/Headers/m_char.h
  8. +12
    -11
      source/Headers/m_cps.h
  9. +1
    -1
      source/Headers/m_drawing.h
  10. +1
    -1
      source/Headers/m_file.h
  11. +11
    -10
      source/Headers/m_str.h
  12. +2
    -0
      source/Headers/m_tokbuf.h
  13. +1
    -1
      source/Headers/m_token.h
  14. +7
    -0
      source/Headers/m_types.h
  15. +1
    -1
      source/Headers/p_bip.h
  16. +1
    -1
      source/Headers/p_cbi.h
  17. +1
    -1
      source/Headers/p_hud.h
  18. +3
    -3
      source/Headers/p_log.h
  19. +2
    -2
      source/Headers/p_player.h
  20. +0
    -2
      source/Headers/p_savedata.h
  21. +1
    -1
      source/Headers/p_shopdef.h
  22. +1
    -1
      source/Headers/w_world.h
  23. +29
    -4
      source/Main/debug.c
  24. +598
    -352
      source/Main/dialogue_compiler.c
  25. +815
    -350
      source/Main/dialogue_vm.c
  26. +2
    -2
      source/Main/g_auto.c
  27. +1
    -1
      source/Main/g_button.c
  28. +2
    -2
      source/Main/g_slider.c
  29. +4
    -2
      source/Main/g_textbox.c
  30. +49
    -0
      source/Main/m_cps.c
  31. +1
    -1
      source/Main/m_draw.c
  32. +4
    -4
      source/Main/m_file.c
  33. +8
    -8
      source/Main/m_namegen.c
  34. +38
    -35
      source/Main/m_str.c
  35. +6
    -0
      source/Main/m_tokbuf.c
  36. +11
    -3
      source/Main/m_token.c
  37. +3
    -3
      source/Main/p_attrib.c
  38. +4
    -3
      source/Main/p_bip.c
  39. +3
    -3
      source/Main/p_cbi.c
  40. +1
    -1
      source/Main/p_gui_bip.c
  41. +2
    -2
      source/Main/p_gui_cbi.c
  42. +2
    -2
      source/Main/p_gui_upgrades.c
  43. +1
    -1
      source/Main/p_hud.c
  44. +4
    -4
      source/Main/p_log.c
  45. +2
    -2
      source/Main/p_notes.c
  46. +3
    -3
      source/Main/p_obituary.c
  47. +3
    -3
      source/Main/p_pickups.c
  48. +1
    -1
      source/Main/p_player.c
  49. +10
    -10
      source/Main/p_settings.c
  50. +1
    -1
      source/Main/p_shop.c
  51. +1
    -1
      source/Main/p_shopdef.c
  52. +1
    -1
      source/Main/u_magic.c
  53. +3
    -3
      source/Main/u_reactarmor.c
  54. +3
    -3
      source/Main/w_spawn.c
  55. +1
    -1
      source/Main/w_time.c
  56. +1
    -1
      source/Main/w_title.c
  57. +1
    -1
      tools/package.sh

BIN
pk7/acs/lithmain.bin View File


+ 30
- 28
pk7/lfiles/Dialogue_TESTMAP.txt View File

@@ -8,22 +8,23 @@
*/

/* ------------------------------------------------------------------------- */
/*
program 1
program 7;

entry 0
{
lda 0
add 5
tax
mul 10

tra
trx
trz "butts"
ldx #$FF
txs
lda #$1A
pha
pla
tay
lda #$AA
trs
trr
}
*/

/* ------------------------------------------------------------------------- */
dialogue 1
dialogue 1;

page 0
{
@@ -37,13 +38,13 @@ page 0
`...
option "Say hello" page 2
option "Exit" exit
option "Exit" brk
}

page 2
{
if class pcl_marine `Who are you?
if class pcl_cybermage `Right. The Cybernati.
if class pM `Who are you?
if class pC `Right. The Cybernati.

@@
`Test of concatenated
@@ -53,8 +54,8 @@ page 2
`and break on multiple lines.
@@

$QUITMSG39
#QUITMSG39
option "emit skeltal"
{
script 2
@@ -62,7 +63,7 @@ page 2
}

option "Talk to me." page 3
option "Thanks, bye!" exit
option "Thanks, bye!" brk
}

page 3
@@ -70,7 +71,7 @@ page 3
`What, you want something?
`

if class pcl_cybermage
if class pC
{
`What did you need, Stilko?
option "The nightmares are back." page 10
@@ -82,7 +83,7 @@ page 3
option "That's rude." page 4
}

option "Bye." exit
option "Bye." brk
}

page 10
@@ -97,7 +98,7 @@ page 10
@@

option "It's not that, I'm certain.. They're \cmworse\c-." page 13
option "Right... Thank you, Zeke." exit
option "Right... Thank you, Zeke." brk
}

page 11
@@ -173,7 +174,7 @@ page 16
`incantation, vile, enroaching reality, Hell?
@@

option "It's coming. Just thought I'd let you know." exit
option "It's coming. Just thought I'd let you know." brk
}

page 4
@@ -182,7 +183,7 @@ page 4
`
`Now go away.

option "Right." exit
option "Right." brk
}

page 7
@@ -200,18 +201,18 @@ page 7
`find yourself
`starting back
option "Thanks, bye!" exit
option "Thanks, bye!" brk
}

/*
/* ------------------------------------------------------------------------- */
terminal 1
terminal 1;

unfinished
{
remote "test@org.example"
logon 01602
logon "01602"
`\cgehhg.431.4122/-/<PFGR ZNE6 \cr&49c2\cg>
info
@@ -221,7 +222,8 @@ unfinished
`test with picture
`and multiple lines of text
logoff 01602
logoff "01602"
}
*/

/* EOF */

+ 6
- 4
source/Headers/common.h View File

@@ -27,7 +27,6 @@
#include "m_math.h"
#include "m_str.h"
#include "m_stab.h"
#include "m_char.h"

#define LineHash ((u32)__LINE__ * FileHash)

@@ -50,6 +49,8 @@
#define TickerT(t, on, off) ((ACS_Timer() % 35) < (t) ? (on) : (off))
#define Ticker(on, off) (TickerT(17, on, off))

#define FourCC(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | (a << 0))

#define SCallI ACS_ScriptCall
#define SCallK ACS_ScriptCallFixed
#define SCallS ACS_ScriptCallString
@@ -162,10 +163,11 @@ stkcall i32 PtrInvNum(i32 tid, str item);
stkcall void PtrInvGive(i32 tid, str item, i32 amount);
stkcall void PtrInvTake(i32 tid, str item, i32 amount);
stkcall void PtrInvSet (i32 tid, str item, i32 amount);
void Dbg_Stat_Impl(char const *fmt, ...);
void Dbg_Note_Impl(char const *fmt, ...);
void Dbg_Stat_Impl(cstr fmt, ...);
void Dbg_Note_Impl(cstr fmt, ...);
script void Dbg_PrintMem(void const *data, size_t size);
void Log(char const *fmt, ...);
script void Dbg_PrintMemC(void const *data, size_t size);
void Log(cstr fmt, ...);

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



+ 404
- 79
source/Headers/dialogue.h View File

@@ -6,123 +6,448 @@
*
* ---------------------------------------------------------------------------|
*
* Dialogue VM code data.
* Dialogue VM data. A 6502 emulator with extensions.
*
* Registers:
*
* AC - Accumulator
* PC - Program Counter
* RX - X
* RY - Y
* SP - Stack Pointer
* SR - Processor State
*
* Extended registers:
*
* TX - Text
* UI - GUI State
* VA - VM Action
*
* Status bits:
*
* B - Break Command (ignored)
* C - Carry
* D - Decimal Mode (ignored)
* I - Interrupt Disable (ignored)
* N - Negative
* V - Overflow
* Z - Zero
*
* Base instructions:
*
* ADC AND ASL BCC BCS BEQ BIT BMI BNE BPL BRK BVC BVS CLC
* CLD CLI CLV CMP CPX CPY DEC DEX DEY EOR INC INX INY JMP
* JSR LDA LDX LDY LSR NOP ORA PHA PHP PLA PLP ROL ROR RTI
* RTS SBC SEC SED SEI STA STX STY TAX TAY TSX TXA TXS TYA
*
* Extended instructions:
*
* JPG - Jump Page
* LDV - Load VM Action
* TRR - Trace Registers
* TRS - Trace Stack
* TRT - Trace Text
* TRV - Trace Variables
*
* ---------------------------------------------------------------------------|
*/

#ifdef DCD
/* VM state */
DCD(NOP)
DCD(HLT)
#if defined(ACT)
ACT(DLG_WAIT) /* (OP) -> VA<ret> OPT_SEL */
ACT(LD_ITEM) /* (ADRL(name)) -> AC<count> */
ACT(LD_OPT) /* (ADRL<name> RADRL<ptr>) -> OPT_CNT OPT */
ACT(SCRIPT_I) /* (SCP0 SCP1 SCP2 SCP3 SCP4) -> AC<ret> */
ACT(SCRIPT_S) /* (ADRL SCP1 SCP2 SCP3 SCP4) -> AC<ret> */
ACT(TELEPORT_INTERLEVEL) /* (ADRL<map>) -> VA<halt> */
ACT(TELEPORT_INTRALEVEL) /* (ADRL<tag>) -> VA<halt> */
ACT(TEXT_ADDI) /* (ADRL) -> TX */
ACT(TEXT_ADDL) /* (ADRL) -> TX */
ACT(TEXT_SETI) /* (ADRL) -> TX */
ACT(TEXT_SETL) /* (ADRL) -> TX */
/*ACT(TRM_INFO)
ACT(TRM_LOGOFF)
ACT(TRM_LOGON)
ACT(TRM_PICT)
ACT(TRM_WAIT)*/

#undef ACT
#elif defined(DCD)
/* No-op */
DCD(0xEA, NOP, NP)

/* Jumps */
DCD(0x00, BRK, NP)
DCD(0x10, BPL, RI)
DCD(0x20, JSR, AI)
DCD(0x30, BMI, RI)
DCD(0x40, RTI, NP)
DCD(0x50, BVC, RI)
DCD(0x60, RTS, NP)
DCD(0x70, BVS, RI)
DCD(0x90, BCC, RI)
DCD(0xB0, BCS, RI)
DCD(0xD0, BNE, RI)
DCD(0xF0, BEQ, RI)

DCD(0x4C, JMP, AI)
DCD(0x6C, JMP, II)

DCD(0x22, JPG, VI) /* Extension */

/* Comparison */
DCD(0xC0, CPY, VI)
DCD(0xE0, CPX, VI)

DCD(0xC1, CMP, IX)
DCD(0xD1, CMP, IY)

DCD(0x24, BIT, ZI)
DCD(0xC4, CPY, ZI)
DCD(0xE4, CPX, ZI)

DCD(0xC5, CMP, ZI)
DCD(0xD5, CMP, ZX)

DCD(0xC9, CMP, VI)
DCD(0xD9, CMP, AY)

DCD(0x2C, BIT, AI)

DCD(0xCC, CPY, AI)
DCD(0xEC, CPX, AI)

DCD(0xCD, CMP, AI)
DCD(0xDD, CMP, AX)

/* Stack */
DCD(PHA)
DCD(PLA)
DCD(0x08, PHP, NP)
DCD(0x28, PLP, NP)
DCD(0x48, PHA, NP)
DCD(0x68, PLA, NP)

/* Flags */
DCD(0x18, CLC, NP)
DCD(0x38, SEC, NP)
DCD(0x58, CLI, NP)
DCD(0x78, SEI, NP)
DCD(0xB8, CLV, NP)
DCD(0xD8, CLD, NP)
DCD(0xF8, SED, NP)

/* Load */
DCD(LDA)
DCD(LDX)
DCD(LDY)
DCD(0xA0, LDY, VI)

DCD(0xA1, LDA, IX)
DCD(0xB1, LDA, IY)

DCD(0xA2, LDX, VI)

DCD(0xA4, LDY, ZI)
DCD(0xB4, LDY, ZX)

DCD(0xA5, LDA, ZI)
DCD(0xB5, LDA, ZX)

DCD(0xA6, LDX, ZI)
DCD(0xB6, LDX, ZY)

DCD(0xA9, LDA, VI)
DCD(0xB9, LDA, AY)

DCD(0xAC, LDY, AI)
DCD(0xBC, LDY, AX)

DCD(0xAD, LDA, AI)
DCD(0xBD, LDA, AX)

DCD(0xAE, LDX, AI)
DCD(0xBE, LDX, AY)

DCD(0x03, LDV, VI) /* Extension */
DCD(0x13, LDV, ZI) /* Extension */
DCD(0x23, LDV, ZX) /* Extension */
DCD(0x33, LDV, AI) /* Extension */
DCD(0x43, LDV, AX) /* Extension */

/* Transfer */
DCD(TAX)
DCD(TAY)
DCD(TSX)
DCD(TXA)
DCD(TXS)
DCD(TYA)
DCD(0x98, TYA, NP)
DCD(0xA8, TAY, NP)

DCD(0x8A, TXA, NP)
DCD(0x9A, TXS, NP)
DCD(0xAA, TAX, NP)
DCD(0xBA, TSX, NP)

/* Store */
DCD(0x81, STA, IX)
DCD(0x91, STA, IY)

DCD(0x84, STY, ZI)
DCD(0x94, STY, ZX)

DCD(0x85, STA, ZI)
DCD(0x95, STA, ZX)

DCD(0x86, STX, ZI)
DCD(0x96, STX, ZY)

DCD(0x99, STA, AY)

DCD(0x8C, STY, AI)

DCD(0x8D, STA, AI)
DCD(0x9D, STA, AX)

DCD(0x8E, STX, AI)

/* Arithmetic */
#define ArithSet(sfx) \
DCD(ADD##sfx) \
DCD(SUB##sfx) \
DCD(MUL##sfx) \
DCD(DIV##sfx) \
DCD(MOD##sfx) \
DCD(IOR##sfx) \
DCD(AND##sfx) \
DCD(XOR##sfx) \
DCD(LSH##sfx) \
DCD(RSH##sfx)
ArithSet(I)
#undef ArithSet
DCD(0x01, ORA, IX)
DCD(0x11, ORA, IY)
DCD(0x21, AND, IX)
DCD(0x31, AND, IY)
DCD(0x41, EOR, IX)
DCD(0x51, EOR, IY)
DCD(0x61, ADC, IX)
DCD(0x71, ADC, IY)
DCD(0xE1, SBC, IX)
DCD(0xF1, SBC, IY)

/* Jumps */
DCD(JPAGE)
DCD(JMP)
DCD(JNZ)
DCD(JNITEM)
DCD(JNCLASS)

/* Interaction */
DCD(SCRIPTI)
DCD(SCRIPTS)
DCD(TELEPORT_INTRALEVEL)
DCD(TELEPORT_INTERLEVEL)

/* Debugging */
DCD(TRA)
DCD(TRX)
DCD(TRY)
DCD(TRZ)

/* Shared */
DCD(SETSTRING)
DCD(SETTEXT)
DCD(SETTEXTLOCAL)
DCD(ADDTEXT)
DCD(ADDTEXTLOCAL)
DCD(CONCAT)
DCD(CONCATEND)

/* Dialogue */
DCD(PUTOPT)
DCD(DLGWAIT)

/* Terminal */
DCD(LOGON)
DCD(LOGOFF)
DCD(INFO)
DCD(PICT)
DCD(TRMWAIT)
DCD(0x05, ORA, ZI)
DCD(0x15, ORA, ZX)
DCD(0x25, AND, ZI)
DCD(0x35, AND, ZX)
DCD(0x45, EOR, ZI)
DCD(0x55, EOR, ZX)
DCD(0x65, ADC, ZI)
DCD(0x75, ADC, ZX)
DCD(0xE5, SBC, ZI)
DCD(0xF5, SBC, ZX)

DCD(0x06, ASL, ZI)
DCD(0x16, ASL, ZX)
DCD(0x26, ROL, ZI)
DCD(0x36, ROL, ZX)
DCD(0x46, LSR, ZI)
DCD(0x56, LSR, ZX)
DCD(0x66, ROR, ZI)
DCD(0x76, ROR, ZX)
DCD(0xC6, DEC, ZI)
DCD(0xD6, DEC, ZX)
DCD(0xE6, INC, ZI)
DCD(0xF6, INC, ZX)

DCD(0x88, DEY, NP)
DCD(0xC8, INY, NP)
DCD(0xE8, INX, NP)

DCD(0x09, ORA, VI)
DCD(0x19, ORA, AY)
DCD(0x29, AND, VI)
DCD(0x39, AND, AY)
DCD(0x49, EOR, VI)
DCD(0x59, EOR, AY)
DCD(0x69, ADC, VI)
DCD(0x79, ADC, AY)
DCD(0xE9, SBC, VI)
DCD(0xF9, SBC, AY)

DCD(0x0A, ASL, NP)
DCD(0x2A, ROL, NP)
DCD(0x4A, LSR, NP)
DCD(0x6A, ROR, NP)

DCD(0xCA, DEX, NP)

DCD(0x0D, ORA, AI)
DCD(0x1D, ORA, AX)
DCD(0x2D, AND, AI)
DCD(0x3D, AND, AX)
DCD(0x4D, EOR, AI)
DCD(0x5D, EOR, AX)
DCD(0x6D, ADC, AI)
DCD(0x7D, ADC, AX)
DCD(0xED, SBC, AI)
DCD(0xFD, SBC, AX)

DCD(0x0E, ASL, AI)
DCD(0x1E, ASL, AX)
DCD(0x2E, ROL, AI)
DCD(0x3E, ROL, AX)
DCD(0x4E, LSR, AI)
DCD(0x5E, LSR, AX)
DCD(0x6E, ROR, AI)
DCD(0x7E, ROR, AX)
DCD(0xCE, DEC, AI)
DCD(0xDE, DEC, AX)
DCD(0xEE, INC, AI)
DCD(0xFE, INC, AX)

/* Trace */
DCD(0x02, TRR, NP) /* Extension */
DCD(0x12, TRS, NP) /* Extension */
DCD(0x32, TRV, NP) /* Extension */
DCD(0x42, TRT, NP) /* Extension */
#undef DCD
#elif !defined(dialogue_h)
#define dialogue_h

#include "w_world.h"
#include "m_vec.h"
#include "m_cps.h"

#define StructOfs(nam, mem, sel) \
(VAR_##nam##_BEG + S_##nam##_##mem + S_##nam##_SIZE * (sel))

#define StructOfsHead(nam, sel) (VAR_##nam##_BEG + S_##nam##_SIZE * (sel))

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

enum
{
#define DCD(name) DCD_##name,
#define DCD(n, op, ty) DCD_##op##_##ty = n,
#include "dialogue.h"
};

enum
{
DPAGE_DIALOGUE = 0x1A,
DPAGE_TERMINAL = 0xF0,
DPAGE_UNFINISHED = 0xFD,
DPAGE_FINISHED,
DPAGE_FAILURE,
};

enum
{
STA_START = 0x0100,
VAR_START = 0x0200,
PRG_START = 0xA000,
STR_START = 0xC000,
IRQ_START = 0xFF00,
STA_START_C = STA_START / 4,
PRG_START_C = PRG_START / 4,
STR_START_C = STR_START / 4,
};

enum
{
ADRM_AI, /* Absolute-immediate */
ADRM_AX, /* Absolute-X */
ADRM_AY, /* Absolute-Y */
ADRM_II, /* Indirect-immediate */
ADRM_IX, /* Indirect-X */
ADRM_IY, /* Indirect-Y */
ADRM_NP, /* No-parameter */
ADRM_RI, /* Relative-immediate */
ADRM_VI, /* Value-immediate */
ADRM_ZI, /* Zeropage-immediate */
ADRM_ZX, /* Zeropage-X */
ADRM_ZY, /* Zeropage-Y */
};

/* structures */
enum
{
/* options */
S_OPT_PTRL,
S_OPT_PTRH,
S_OPT_NAML,
S_OPT_NAMH,
S_OPT_SIZE,
};

enum
{
/* constants */
VAR_PCLASS = VAR_START,

/* vars */
VAR_CONCAT,
VAR_UACT,

/* general address */
VAR_ADRL,
VAR_ADRH,
VAR_RADRL,
VAR_RADRH,

/* scripts */
VAR_SCP0,
VAR_SCP1,
VAR_SCP2,
VAR_SCP3,
VAR_SCP4,

/* strings */
VAR_NAMEL,
VAR_NAMEH,
VAR_ICONL,
VAR_ICONH,
VAR_REMOTEL,
VAR_REMOTEH,
VAR_PICTL,
VAR_PICTH,

/* options */
VAR_OPT_CNT,
VAR_OPT_SEL,

VAR_OPT_BEG,
VAR_OPT_END = VAR_OPT_BEG + S_OPT_SIZE * 16,

/* end */
VAR_END
};

enum
{
#define ACT(name) ACT_##name,
#include "dialogue.h"
ACT_MAX,

/* response actions */
ACT_NONE,
ACT_HALT,
ACT_JUMP,
};

enum
{
DSTR_NAME,
DSTR_ICON,
DSTR_REMOTE,
TACT_NONE,
TACT_LOGON,
TACT_LOGOFF,
TACT_INFO,
TACT_PICT,
};

enum
{
DTRMPAGE_UNFINISHED = 0x7FFFFF0F,
DTRMPAGE_FINISHED,
DTRMPAGE_FAILURE,
UACT_NONE,
UACT_ACKNOWLEDGE,
UACT_SELOPTION,
UACT_EXIT,
};

struct dlgdef
struct dlg_def
{
i32 num;
i32 pages[48];
Vec_Decl(i32, code);
Vec_Decl(char, stab);
u32 pages[0xFF];
size_t codeP, stabP;
Vec_Decl(u32, code);
Vec_Decl(u32, stab);

struct dlgdef *next;
struct dlg_def *next;
};

struct dcd_info
{
char name[7];
u32 adrm;
};

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

extern struct dlg_def *lmvar dlgdefs;
extern struct dcd_info const dcdinfo[0xFF];

#endif

+ 0
- 31
source/Headers/dlgstab.h View File

@@ -1,31 +0,0 @@
/* ---------------------------------------------------------------------------|
*
* Distributed under the CC0 public domain license.
* By Alison Sanderson. Attribution is encouraged, though not required.
* See licenses/cc0.txt for more information.
*
* ---------------------------------------------------------------------------|
*
* Dialogue string table.
*
* ---------------------------------------------------------------------------|
*/

Str(NULL, "")
Str(class, "class")
Str(dialogue, "dialogue")
Str(else, "else")
Str(exec, "exec")
Str(failure, "failure")
Str(finished, "finished")
Str(if, "if")
Str(item, "item")
Str(option, "option")
Str(page, "page")
Str(terminal, "terminal")
Str(Informant, "Informant")
Str(unfinished, "unfinished")

#undef Str

/* EOF */

+ 32
- 32
source/Headers/gui.h View File

@@ -75,8 +75,8 @@
#define G_TextBox_Reset(st) ((st)->tbptr = 0)

#define G_TextBox_OnTextEntered(st) \
__with(char const *txt_buf = Cps_Print(st->txtbuf, st->tbptr);) \
ifauto(char const *, _c, strchr(txt_buf, '\n')) \
__with(cstr txt_buf = Cps_Expand(st->txtbuf, 0, st->tbptr);) \
ifauto(cstr , _c, strchr(txt_buf, '\n')) \
__with(size_t txt_len = _c - txt_buf; G_TextBox_Reset(st);)

/* Types ------------------------------------------------------------------- */
@@ -132,17 +132,17 @@ struct gui_state

void *state;

char const *gfxprefix;
cstr gfxprefix;
};

struct gui_pre_btn
{
char const *gfx;
char const *hot;
char const *cdef;
char const *cact;
char const *chot;
char const *cdis;
cstr gfx;
cstr hot;
cstr cdef;
cstr cact;
cstr chot;
cstr cdis;
str font;
str snd;
i32 ax;
@@ -154,23 +154,23 @@ struct gui_pre_btn

struct gui_arg_btn
{
char const *label;
i32 x, y;
bool disabled;
char const *color;
bool slide;
cstr label;
i32 x, y;
bool disabled;
cstr color;
bool slide;
struct gui_pre_btn const *preset;
};

struct gui_pre_cbx
{
char const *gfx;
char const *hot;
char const *dis;
char const *chkgfx;
char const *chkhot;
char const *chkact;
char const *chkdis;
cstr gfx;
cstr hot;
cstr dis;
cstr chkgfx;
cstr chkhot;
cstr chkact;
cstr chkdis;
str sndup;
str snddn;
bool external;
@@ -188,11 +188,11 @@ struct gui_arg_cbx

struct gui_pre_scr
{
char const *capS;
char const *capE;
char const *scrl;
char const *notchgfx;
char const *notchhot;
cstr capS;
cstr capE;
cstr scrl;
cstr notchgfx;
cstr notchhot;
bool external;
i32 scrlw;
i32 scrlh;
@@ -212,9 +212,9 @@ struct gui_arg_scr

struct gui_pre_sld
{
char const *gfx;
char const *notch;
char const *notchhot;
cstr gfx;
cstr notch;
cstr notchhot;
str snd;
str font;
bool external;
@@ -231,7 +231,7 @@ struct gui_arg_sld
k64 maxima;
k64 val;
bool integ;
char const *suf;
cstr suf;
struct gui_pre_sld const *preset;
};

@@ -305,8 +305,8 @@ void G_Clip(struct gui_state *g, i32 x, i32 y, i32 w, i32 h, i32 ww);
stkcall
void G_ClipRelease(struct gui_state *g);

stkcall char const *RemoveTextColors_str(char __str_ars const *s, i32 size);
stkcall char const *RemoveTextColors (char const *s, i32 size);
stkcall cstr RemoveTextColors_str(astr s, i32 size);
stkcall cstr RemoveTextColors (cstr s, i32 size);

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


+ 22
- 22
source/Headers/m_char.h View File

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

#define IsGraph(ch) ((ch) > ' ' && (ch) <= '~')
#define IsPrint(ch) ((ch) >= ' ' && (ch) <= '~')
#define IsPunct(ch) ((ch) >= '!' && (ch) <= '/' || \
(ch) >= ':' && (ch) <= '@' || \
(ch) >= '[' && (ch) <= '`' || \
(ch) >= '{' && (ch) <= '~')
#define IsSpace(ch) ((ch) >= 0x9 && (ch) <= 0xD || \
(ch) == ' ')
#define IsBlank(ch) ((ch) == ' ' || (ch) == 0x9)
#define IsDigit(ch) ((ch) >= '0' && (ch) <= '9')
#define IsXDigi(ch) ((ch) >= 'a' && (ch) <= 'f' || \
(ch) >= 'A' && (ch) <= 'F' || \
IsDigit(ch))
#define IsLower(ch) ((ch) >= 'a' && (ch) <= 'z')
#define IsUpper(ch) ((ch) >= 'A' && (ch) <= 'Z')
#define IsAlpha(ch) (IsLower(ch) || IsUpper(ch))
#define IsAlNum(ch) (IsAlpha(ch) || IsDigit(ch))
#define IsIdent(ch) (IsAlNum(ch) || (ch) == '_')
#define IsNumId(ch) (IsIdent(ch) || (ch) == '.')
#define IsCntrl(ch) (!IsPrint(ch))
#define ToUpper(ch) (IsLower(ch) ? (ch) | 0x20 : (ch))
#define ToLower(ch) (IsUpper(ch) ? (ch) & ~0x20 : (ch))
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 >= 0x9 && c <= 0xD ||
c == ' ';}
local bool IsBlank(i32 c) {return c == ' ' || c == 0x9;}
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;}

/* EOF */

+ 12
- 11
source/Headers/m_cps.h View File

@@ -14,19 +14,20 @@
#ifndef m_cps_h
#define m_cps_h

#define Cps_Count(name) (countof(name) * 4)
#define Cps_Size(len) ((len) / 4 + (len) % 4)
#define Cps_Defn(name, len) u32 (name)[Cps_Size(len)] = {}
#define Cps_Decl(name, len) u32 (name)[Cps_Size(len)]
#define Cps_Shif(i, set) ((set) << ((i) % 4 * 8))
#define Cps_Adjust(len) ((len) / 4 + (((len) % 4) != 0))

#define Cps_SetC(name, i, set) \
((name)[(i) / 4] &= ~Cps_Shif(i, 0xFF), \
(name)[(i) / 4] |= Cps_Shif(i, set & 0xFF))
#define Cps_CountOf(name) (countof(name) * 4)

#define Cps_GetC(name, i) \
(((name)[(i) / 4] & (0xFF << ((i) % 4 * 8))) >> ((i) % 4 * 8))
#define Cps_Defn(name, len) u32 (name)[Cps_Adjust(len)] = {}
#define Cps_Decl(name, len) u32 (name)[Cps_Adjust(len)]

stkcall char const *Cps_Print(u32 *cps, i32 l);
#define Cps_Expand_str(cps, s) l_strdup(Cps_Expand(cps, s))
#define Cps_ExpandNT_str(cps, s) l_strdup(Cps_ExpandNT(cps, s))

stkcall void Cps_SetC(u32 *cps, u32 p, u32 c);
stkcall byte Cps_GetC(u32 const *cps, u32 p);

stkcall cstr Cps_Expand(u32 *cps, u32 s, u32 l);
stkcall cstr Cps_ExpandNT(u32 *cps, u32 s);

#endif

+ 1
- 1
source/Headers/m_drawing.h View File

@@ -158,6 +158,6 @@ stkcall void DrawSpriteXXX(str name, i32 flags, i32 id, k32 x, k32 y, k32 hold,
stkcall void DrawSpritePlain(str name, i32 id, k32 x, k32 y, k32 hold);
stkcall void DrawSpriteAlpha(str name, i32 id, k32 x, k32 y, k32 hold, k32 alpha);
stkcall void DrawSpriteFade(str name, i32 id, k32 x, k32 y, k32 hold, k32 fadetime);
void HudMessage(char const *fmt, ...);
void HudMessage(cstr fmt, ...);

/* EOF */

+ 1
- 1
source/Headers/m_file.h View File

@@ -21,7 +21,7 @@

#define FEOF(fp) ((fp)->_flag & _FILEFLAG_EOF)

FILE *W_Open(str fname, char const *rw);
FILE *W_Open(str fname, cstr rw);
FILE *NFOpen(i32 pnum, str pcvar, char rw);
size_t FWrite32(void const *restrict ptr, size_t count, size_t bytes, FILE *restrict fp);
size_t FWrite(void const *restrict ptr, size_t count, FILE *restrict fp);


+ 11
- 10
source/Headers/m_str.h View File

@@ -29,16 +29,17 @@
#define l_strdup(s) (ACS_BeginPrint(), PrintChrSt(s), ACS_EndStrParam())

stkcall str l_strupper(str in);
stkcall u32 l_strhash(char __str_ars const *s);
stkcall u32 lstrhash(char const *s);
stkcall char *lstrcpy_str(char *dest, char __str_ars const *src);
stkcall char *lstrcpy2(char *out, char const *s1, char const *s2);
stkcall i32 lstrcmp_str(char const *s1, char __str_ars const *s2);
stkcall i32 faststrcmp(char const *s1, char const *s2);
stkcall char const *scoresep(i96 num);
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 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);
str LanguageV(str name);
str LanguageNull(char const *fmt, ...);
char *LanguageVC(char *out, char const *name);
char *LanguageCV(char *out, char const *name, ...);
str LanguageNull(cstr fmt, ...);
char *LanguageVC(char *out, cstr name);
char *LanguageCV(char *out, cstr name, ...);

/* EOF */

+ 2
- 0
source/Headers/m_tokbuf.h View File

@@ -27,6 +27,7 @@
struct token *TBufPeek (struct tokbuf *tb);
stkcall struct token *TBufUnGet(struct tokbuf *tb);
stkcall struct token *TBufReGet(struct tokbuf *tb);
stkcall struct token *TBufBack (struct tokbuf *tb, i32 n);
bool TBufDrop (struct tokbuf *tb, i32 t);
stkcall i32 TBufProc (struct token *tok);
stkcall i32 TBufProcL(struct token *tok);
@@ -46,6 +47,7 @@ struct tokbuf
__prop peek {call: TBufPeek (this)}
__prop unget {call: TBufUnGet(this)}
__prop reget {call: TBufReGet(this)}
__prop back {call: TBufBack (this)}
__prop drop {call: TBufDrop (this)}

struct origin orig;


+ 1
- 1
source/Headers/m_token.h View File

@@ -45,7 +45,7 @@ enum
tok_lnend, /* \n */
tok_semico, /* ; */
tok_comma, /* , */
tok_dollar, /* $ */
tok_hash, /* # */
tok_bracko, /* [ */
tok_brackc, /* ] */
tok_braceo, /* { */


+ 7
- 0
source/Headers/m_types.h View File

@@ -30,6 +30,8 @@
#define stkcall [[__call("StkCall")]]
#define script [[__call("ScriptI")]]
#define script_str [[__call("ScriptS")]]
#define sync [[__call("SScriptI")]]
#define sync_str [[__call("SScriptS")]]
#define optargs(x) [[__optional_args(x)]]
#define noinit [[__no_init]]
#define anonymous [[__anonymous]]
@@ -38,6 +40,8 @@
#define type(x) [[__script(x)]]
#define addr(x) [[__address(x)]]

#define local stkcall static inline

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

typedef int32_t i32;
@@ -52,6 +56,9 @@ typedef unsigned char byte;

typedef __str str;

typedef char __str_ars const *astr;
typedef char const *cstr;

typedef _Accum k32;
typedef long _Accum k64;



+ 1
- 1
source/Headers/p_bip.h View File

@@ -33,7 +33,7 @@ LITH_X(MAIL, "Mail")
/* Extern Functions -------------------------------------------------------- */

script void P_BIP_PInit(struct player *p);
optargs(1) struct page *P_BIP_Unlock(struct player *p, char const *name);
optargs(1) struct page *P_BIP_Unlock(struct player *p, cstr name);
stkcall void P_BIP_PQuit(struct player *p);
script optargs(1) void P_BIP_GiveMail(struct player *p, str title, i32 flags);



+ 1
- 1
source/Headers/p_cbi.h View File

@@ -106,6 +106,6 @@ struct cbi
/* Extern Functions -------------------------------------------------------- */

void P_CBI_PMinit(struct player *p);
char const *ThemeName(u32 num);
cstr ThemeName(u32 num);

#endif

+ 1
- 1
source/Headers/p_hud.h View File

@@ -31,7 +31,7 @@ struct hud_wsl
};

void HUD_WeaponSlots_Impl(struct player *p, struct hud_wsl const *a);
void HUD_Score(struct player *p, char const *fmt, i96 scr, str font, str cr, i32 x, i32 xa, i32 y, i32 ya);
void HUD_Score(struct player *p, cstr fmt, i96 scr, str font, str cr, i32 x, i32 xa, i32 y, i32 ya);
void HUD_KeyInd(struct player *p, i32 x, i32 y, bool horz, k32 a);
script void HUD_Log(struct player *p, i32 cr, i32 x, i32 yy);



+ 3
- 3
source/Headers/p_log.h View File

@@ -48,9 +48,9 @@ struct loginfo
u32 curtime;
};

void P_Log_Both(struct player *p, i32 levl, char const *fmt, ...); /* log to HUD and full log */
void P_Log_HUDs(struct player *p, i32 levl, char const *fmt, ...); /* log to HUD only */
void P_Log_Full(struct player *p, char const *fmt, ...); /* log to full log only */
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 */
void P_Log_Entry(struct player *p);

#endif

+ 2
- 2
source/Headers/p_player.h View File

@@ -82,7 +82,7 @@ stkcall void P_Scr_Take(struct player *p, i96 score);
stkcall void P_Lv_GiveEXP(struct player *p, u64 amt);
stkcall struct upgrade *P_Upg_GetNamed(struct player *p, i32 name);
stkcall bool P_Upg_IsActive(struct player *p, i32 name);
stkcall char const *P_Discrim(i32 pclass);
stkcall cstr P_Discrim(i32 pclass);
stkcall void P_Dat_PTickPst(struct player *p);
struct player *P_PtrFind(i32 tid, i32 ptr);

@@ -201,7 +201,7 @@ struct player
i32 pronoun;
i32 dlgnum;
i32 fun;
char const *discrim;
cstr discrim;

/* Deltas */
anonymous


+ 0
- 2
source/Headers/p_savedata.h View File

@@ -17,8 +17,6 @@
#include <stdio.h>
#include <stdint.h>

#define FourCC(a, b, c, d) ((d << 24) | (c << 16) | (b << 8) | (a << 0))

/* Lith: First valid chunk in save file. */
/* Ver. 7: Initial version. */
/* Ver. 14: Rewrite of save system. */


+ 1
- 1
source/Headers/p_shopdef.h View File

@@ -34,6 +34,6 @@ struct shopdef

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, char const *namefmt, bool nodelivery, bool nolog);
optargs(1) bool P_Shop_Buy(struct player *p, struct shopdef const *def, void *obj, cstr namefmt, bool nodelivery, bool nolog);

#endif

+ 1
- 1
source/Headers/w_world.h View File

@@ -66,7 +66,7 @@ enum game
Game_Episodic,
};

char const *CanonTime(i32 type);
cstr CanonTime(i32 type);
optargs(1) i32 UniqueID(i32 tid);
stkcall void BeginAngles(i32 x, i32 y);
stkcall k32 AddAngle(i32 x, i32 y);


+ 29
- 4
source/Main/debug.c View File

@@ -14,6 +14,7 @@
#include "common.h"
#include "p_player.h"
#include "w_monster.h"
#include "m_char.h"

#include <stdio.h>
#include <GDCC.h>
@@ -25,7 +26,7 @@ i32 dbgstatnum, dbgnotenum;

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

void Dbg_Stat_Impl(char const *fmt, ...)
void Dbg_Stat_Impl(cstr fmt, ...)
{
if(!(dbglevel & log_devh)) return;

@@ -40,7 +41,7 @@ void Dbg_Stat_Impl(char const *fmt, ...)
dbgstat[dbgstatnum++] = ACS_EndStrParam();
}

void Dbg_Note_Impl(char const *fmt, ...)
void Dbg_Note_Impl(cstr fmt, ...)
{
if(!(dbglevel & log_devh)) return;

@@ -55,6 +56,30 @@ void Dbg_Note_Impl(char const *fmt, ...)
dbgnote[dbgnotenum++] = ACS_EndStrParam();
}

script
void Dbg_PrintMemC(void const *data, size_t size)
{
u32 const *d = data;
i32 pos = 0;

for(size_t i = 0; i < size * 4; i++)
{
if(pos + 3 > 79)
{
puts("");
pos = 0;
}

byte c = Cps_GetC(d, i);

printf(IsPrint(c) ? "%c " : c"%.2X ", c);

pos += 3;
}

puts("\nEOF\n\n");
}

script
void Dbg_PrintMem(void const *data, size_t size)
{
@@ -69,7 +94,7 @@ void Dbg_PrintMem(void const *data, size_t size)
pos = 0;
}

printf(IsPrint(d[i]) ? "%c " : c"%.2X ", d[i]);
printf(IsPrint(d[i]) ? "%c " : c"%.2X ", d[i]);

pos += 3;
}
@@ -77,7 +102,7 @@ void Dbg_PrintMem(void const *data, size_t size)
puts("\nEOF\n\n");
}

void Log(char const *fmt, ...)
void Log(cstr fmt, ...)
{
va_list vl;



+ 598
- 352
source/Main/dialogue_compiler.c
File diff suppressed because it is too large
View File


+ 815
- 350
source/Main/dialogue_vm.c
File diff suppressed because it is too large
View File


+ 2
- 2
source/Main/g_auto.c View File

@@ -173,13 +173,13 @@ void G_TypeOn(struct gui_state *g, struct gui_typ *typeon, str text)
return tcbuf;

stkcall
char const *RemoveTextColors_str(char __str_ars const *s, i32 size)
cstr RemoveTextColors_str(astr s, i32 size)
{
RemoveTextColorsImpl();
}

stkcall
char const *RemoveTextColors(char const *s, i32 size)
cstr RemoveTextColors(cstr s, i32 size)
{
RemoveTextColorsImpl();
}


+ 1
- 1
source/Main/g_button.c View File

@@ -32,7 +32,7 @@ bool G_Button_Impl(struct gui_state *g, u32 id, struct gui_arg_btn const *a)
if(a->label && pre->font)
{
i32 x, y;
char const *color;
cstr color;

if(pre->ax == 4 || !pre->ax) x = (pre->w / 2) + a->x + g->ox;
else x = a->x + g->ox;


+ 2
- 2
source/Main/g_slider.c View File

@@ -74,8 +74,8 @@ k64 G_Slider_Impl(struct gui_state *g, u32 id, struct gui_arg_sld const *a)
/* draw value */
if(pre->font)
{
char const *suf = a->suf ? a->suf : "";
k64 amt = roundlk(norm * 100.lk, 10) / 100.lk;
cstr suf = a->suf ? a->suf : "";
k64 amt = roundlk(norm * 100.lk, 10) / 100.lk;
if(a->integ) PrintTextFmt("%i%s", (i32)amt, suf);
else PrintTextFmt("%.1k%s", (k32)amt, suf);



+ 4
- 2
source/Main/g_textbox.c View File

@@ -15,6 +15,7 @@
#include "p_player.h"
#include "w_world.h"
#include "m_cps.h"
#include "m_char.h"

struct gui_txt *G_TextBox_Impl(struct gui_state *g, u32 id, struct gui_arg_txt const *a)
{
@@ -39,7 +40,7 @@ struct gui_txt *G_TextBox_Impl(struct gui_state *g, u32 id, struct gui_arg_txt c
case '\r':
*c = '\n';
default:
if(st->tbptr + 1 < Cps_Count(st->txtbuf) && (IsPrint(*c) || IsSpace(*c)))
if(st->tbptr + 1 < Cps_CountOf(st->txtbuf) && (IsPrint(*c) || IsSpace(*c)))
{
Cps_SetC(st->txtbuf, st->tbptr, *c);
st->tbptr++;
@@ -54,7 +55,8 @@ struct gui_txt *G_TextBox_Impl(struct gui_state *g, u32 id, struct gui_arg_txt c

SetClipW(a->x + g->ox, a->y + g->oy, 260, 200, 260);
if(st->tbptr)
PrintTextFmt("%s%s", Cps_Print(st->txtbuf, st->tbptr), hot ? Ticker("|", "") : "");
PrintTextFmt("%s%s", Cps_Expand(st->txtbuf, 0, st->tbptr),
hot ? Ticker("|", "") : "");
else
PrintTextFmt("\C%c%s", hot ? 'c' : 'm', LC(LANG "GUI_TEXTBOX"));
PrintText(s_cbifont, CR_WHITE, a->x + g->ox,1, a->y + g->oy,1);


+ 49
- 0
source/Main/m_cps.c View File

@@ -0,0 +1,49 @@
/* ---------------------------------------------------------------------------|
*
* Distributed under the CC0 public domain license.
* By Alison Sanderson. Attribution is encouraged, though not required.
* See licenses/cc0.txt for more information.
*
* ---------------------------------------------------------------------------|
*
* Compressed strings.
*
* ---------------------------------------------------------------------------|
*/

#include "common.h"
#include "m_cps.h"

#define Cps_Shift(i, set) ((set) << ((i) % 4 * 8))

stkcall void Cps_SetC(u32 *cps, u32 p, u32 c)
{
cps[p / 4] &= ~Cps_Shift(p, 0xFF);
cps[p / 4] |= Cps_Shift(p, c & 0xFF);
}

stkcall byte Cps_GetC(u32 const *cps, u32 p)
{
return (cps[p / 4] & (0xFF << (p % 4 * 8))) >> (p % 4 * 8);
}

stkcall cstr Cps_Expand(u32 *cps, u32 s, u32 l)
{
noinit static char buf[4096];
u32 i;
for(i = 0; i < l;) buf[i++] = Cps_GetC(cps, i + s);
buf[i] = '\0';
return buf;
}

stkcall cstr Cps_ExpandNT(u32 *cps, u32 s)
{
noinit static char buf[4096];
u32 i;
char ch;
for(i = 0; (ch = Cps_GetC(cps, i + s));) buf[i++] = ch;
buf[i] = '\0';
return buf;
}

/* EOF */

+ 1
- 1
source/Main/m_draw.c View File

@@ -93,7 +93,7 @@ void DrawSpriteFade(str name, i32 id, k32 x, k32 y, k32 hold, k32 fadetime)
ACS_EndHudMessage(fadetime);
}

void HudMessage(char const *fmt, ...)
void HudMessage(cstr fmt, ...)
{
va_list vl;



+ 4
- 4
source/Main/m_file.c View File

@@ -100,7 +100,7 @@ static ssize_t MemRead(void *memdata, char *buf, size_t size)
return size;
}

static ssize_t MemWrite(void *memdata, char const *buf, size_t size)
static ssize_t MemWrite(void *memdata, cstr buf, size_t size)
{
struct memfile *mem = memdata;
size_t avail = mem->len - mem->pos;
@@ -152,7 +152,7 @@ static i32 MemClose(void *memdata)

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

FILE *W_Open(str fname, char const *rw)
FILE *W_Open(str fname, cstr rw)
{
str f;
ifw(i32 lmp = W_Find(fname), lmp == -1)
@@ -256,7 +256,7 @@ size_t FWrite(void const *restrict ptr, size_t count, FILE *restrict fp)
{
size_t res = 0;

for(char const *itr = ptr; count--; res++)
for(cstr itr = ptr; count--; res++)
if(fputc(*itr++, fp) == EOF) return res;

return res;
@@ -266,7 +266,7 @@ size_t FWriteStr(void const __str_ars *restrict ptr, size_t count, FILE *restric
{
size_t res = 0;

for(char const __str_ars *itr = ptr; count--; res++)
for(astr itr = ptr; count--; res++)
if(fputc(*itr++, fp) == EOF) return res;

return res;


+ 8
- 8
source/Main/m_namegen.c View File

@@ -2,6 +2,8 @@
*
* Distributed under the CC0 public domain license.
* By Alison Sanderson. Attribution is encouraged, though not required.
* Predefined names and suffixes mostly taken from Kyle873's Doom RPG.
* Used with permission.
* See licenses/cc0.txt for more information.
*
* ---------------------------------------------------------------------------|
@@ -11,15 +13,13 @@
* ---------------------------------------------------------------------------|
*/

/* Predefined names and suffixes mostly taken from Kyle873's Doom RPG. */
/* Used with permission. */
#include "common.h"
#include "w_world.h"
#include <ctype.h>
#include "m_char.h"

/* Static Objects ---------------------------------------------------------- */

static char const *syll[] = {
static cstr syll[] = {
"ka", "k'", "khi", "kaz", "kr",
"ga", "go", "gor", "got", "gn", "gl",
"sha", "sk", "shu", "shi", "si",
@@ -36,7 +36,7 @@ static char const *syll[] = {
"ver", "xel'", "xe",
};

static char const *lulz[] = {
static cstr lulz[] = {
"ohgodwhat",
"kdizd",
"help",
@@ -207,9 +207,9 @@ str RandomName(i32 id)
ACS_PrintString(name[rand() % countof(name)]);
else for(i32 i = 0, n = 3 + (rand() % 6); i < n; i++)
{
char const *s = rand() % 101 == 0 ?
lulz[rand() % countof(lulz)] :
syll[rand() % countof(syll)];
cstr s = rand() % 101 == 0 ?
lulz[rand() % countof(lulz)] :
syll[rand() % countof(syll)];

if(i == 0) {ACS_PrintChar(ToUpper(*s)); s++;}



+ 38
- 35
source/Main/m_str.c View File

@@ -12,10 +12,9 @@
*/

#include "common.h"
#include "m_cps.h"
#include "m_char.h"

#include <stdio.h>
#include <ctype.h>

#define CpyStrLocal(out, st) \
do { \
@@ -35,45 +34,30 @@ StrEntON
#include "m_stab.h"
StrEntOFF

stkcall
char const *Cps_Print(u32 *cps, i32 l)
{
noinit static char buf[4096];
i32 i, ch;
for(i = 0; (ch = Cps_GetC(cps, i)) && (!l || i < l); i++) buf[i] = ch;
buf[i] = '\0';
return buf;
}

stkcall
str l_strupper(str in)
stkcall str l_strupper(str in)
{
ACS_BeginPrint();
for(char __str_ars const *c = in; *c; c++) ACS_PrintChar(ToUpper(*c));
for(astr c = in; *c; c++) ACS_PrintChar(ToUpper(*c));
return ACS_EndStrParam();
}

stkcall
u32 l_strhash(char __str_ars const *s)
stkcall u32 l_strhash(astr s)
{
StrHashImpl();
}

stkcall
u32 lstrhash(char const *s)
stkcall u32 lstrhash(cstr s)
{
StrHashImpl();
}

stkcall
char *lstrcpy_str(char *dest, char __str_ars const *src)
stkcall char *lstrcpy_str(char *dest, astr src)
{
for(char *i = dest; (*i = *src); ++i, ++src);
return dest;
}

stkcall
char *lstrcpy2(char *out, char const *s1, char const *s2)
stkcall char *lstrcpy2(char *out, cstr s1, cstr s2)
{
char *p = out;
for(; *s1; s1++) *p++ = *s1;
@@ -82,22 +66,41 @@ char *lstrcpy2(char *out, char const *s1, char const *s2)
return out;
}

#define StrCmpImpl() while(*s1 && *s2 && *s1 == *s2) ++s1, ++s2; return *s1 - *s2
stkcall i32 lstrcmp_str(cstr s1, astr s2)
{
register i32 res;

while((res = *s1 - *s2++) == 0)
if(*s1++ == '\0') break;

return res;
}

stkcall
i32 lstrcmp_str(char const *s1, char __str_ars const *s2)
stkcall i32 faststrcmp(cstr s1, cstr s2)
{
StrCmpImpl();
if(s1 == s2) return 0;

register i32 res;

while((res = *s1 - *s2++) == 0)
if(*s1++ == '\0') break;

return res;
}

stkcall
i32 faststrcmp(char const *s1, char const *s2)
stkcall i32 faststrcasecmp(cstr s1, cstr s2)
{
StrCmpImpl();
if(s1 == s2) return 0;

register i32 res;

while((res = ToUpper(*s1) - ToUpper(*s2++)) == 0)
if(*s1++ == '\0') break;

return res;
}

stkcall
char const *scoresep(i96 num)
stkcall cstr scoresep(i96 num)
{
static char out[48];

@@ -146,7 +149,7 @@ str LanguageV(str name)
return ret;
}

char *LanguageVC(char *out, char const *name)
char *LanguageVC(char *out, cstr name)
{
noinit static char sbuf[8192];

@@ -158,7 +161,7 @@ char *LanguageVC(char *out, char const *name)
return out;
}

char *LanguageCV(char *out, char const *fmt, ...)
char *LanguageCV(char *out, cstr fmt, ...)
{
noinit static char nbuf[256];
va_list vl;
@@ -170,7 +173,7 @@ char *LanguageCV(char *out, char const *fmt, ...)
return LanguageVC(out, nbuf);
}

str LanguageNull(char const *fmt, ...)
str LanguageNull(cstr fmt, ...)
{
va_list vl;



+ 6
- 0
source/Main/m_tokbuf.c View File

@@ -109,6 +109,12 @@ struct token *TBufReGet(struct tokbuf *tb)
return &tb->toks[tb->tpos];
}

stkcall
struct token *TBufBack(struct tokbuf *tb, i32 n)
{
return &tb->toks[tb->tpos - n];
}

bool TBufDrop(struct tokbuf *tb, i32 t)
{
if(TBufGet(tb)->type != t)


+ 11
- 3
source/Main/m_token.c View File

@@ -75,7 +75,7 @@ begin:;
/* 1-op tokens */
case ';': tok1(tok_semico); return;
case ',': tok1(tok_comma ); return;
case '$': tok1(tok_dollar); return;
case '#': tok1(tok_hash ); return;
case '[': tok1(tok_bracko); return;
case ']': tok1(tok_brackc); return;
case '{': tok1(tok_braceo); return;
@@ -173,10 +173,18 @@ begin:;
unget();
goto begin;
}
else if(IsDigit(ch) || ch == '.' || ch == '-')
else if(IsDigit(ch) || ch == '.' || ch == '-' || ch == '$')
{
tok1(tok_number);
textNext() = ch;

if(ch == '$')
{
textNext() = '0';
textNext() = 'x';
}
else
textNext() = ch;

getch();
tokText(IsNumId);
}


+ 3
- 3
source/Main/p_attrib.c View File

@@ -26,9 +26,9 @@ static void AttrBar(struct gui_state *g, i32 x, i32 y, i32 w, str gfx)

static void DrawAttr(struct gui_state *g, i32 x, i32 y, struct player *p, i32 at)
{
u32 attr = p->attr.attrs[at];
char const *name = p->attr.names[at];
k32 helptrns = 0.5;
u32 attr = p->attr.attrs[at];
cstr name = p->attr.names[at];
k32 helptrns = 0.5;

if(p->attr.points)
if(G_Button_Id(g, at, .x = x-42 + gui_p.btnnext.w, y-2, Pre(btnnext), .slide = true))


+ 4
- 3
source/Main/p_bip.c View File

@@ -18,6 +18,7 @@
#include "w_world.h"
#include "m_file.h"
#include "m_tokbuf.h"
#include "m_char.h"

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

@@ -31,7 +32,7 @@ struct page_init

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

static str DecryptBody(char __str_ars const *s)
static str DecryptBody(astr s)
{
ACS_BeginPrint();
for(; *s; s++) ACS_PrintChar(!IsPrint(*s) ? *s : *s ^ 7);
@@ -164,7 +165,7 @@ static i32 LoadBIPInfo(struct player *p, str fname)
return total;
}

static struct page *FindPage(struct bip *bip, char const *name)
static struct page *FindPage(struct bip *bip, cstr name)
{
if(!name) return nil;
ForCategoryAndPage() if(faststrcmp(page->name, name) == 0) return page;
@@ -252,7 +253,7 @@ void P_BIP_GiveMail(struct player *p, str title, i32 flags)
}
}

struct page *P_BIP_Unlock(struct player *p, char const *name)
struct page *P_BIP_Unlock(struct player *p, cstr name)
{
struct bip *bip = &p->bip;
struct page *page = FindPage(bip, name);


+ 3
- 3
source/Main/p_cbi.c View File

@@ -79,9 +79,9 @@ static void P_CBI_TabInfo(struct gui_state *g, struct player *p)

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

char const *ThemeName(u32 num)
cstr ThemeName(u32 num)
{
static char const *themes[cbi_theme_max] = {
static cstr themes[cbi_theme_max] = {
"Green",
"Rose Pink",
"Umi Blue",
@@ -110,7 +110,7 @@ void P_CBI_PTick(struct player *p)
if(p->cbi.theme != p->cbi.oldtheme)
{
#define X(n) ":UI_" n ":"
static char const *names[] = {
static cstr names[] = {
X("Green"),
X("Rose"),
X("Umi"),


+ 1
- 1
source/Main/p_gui_bip.c View File

@@ -172,7 +172,7 @@ static void DrawPage(struct gui_state *g, struct player *p, struct bip *bip)
/* render an outline if the page has an image */
if(page->image)
{
char const *txt = RemoveTextColors_str(typeon->txt, typeon->pos);
cstr txt = RemoveTextColors_str(typeon->txt, typeon->pos);
str s = l_strdup(txt);

DrawText(s, CR_BLACK, 112, 61); DrawText(s, CR_BLACK, 110, 61);


+ 2
- 2
source/Main/p_gui_cbi.c View File

@@ -44,7 +44,7 @@
static void CBITab_Marine(struct gui_state *g, struct player *p)
{
i32 ram;
char const *name;
cstr name;

Upgr(hasupgr2) {CPU(1); ram = 150; name = LC(LANG "CBI_CPU3");}
else Upgr(hasupgr1) {CPU(2); ram = 100; name = LC(LANG "CBI_CPU2");}
@@ -75,7 +75,7 @@ static void CBITab_Marine(struct gui_state *g, struct player *p)

static void CBITab_CyberMage(struct gui_state *g, struct player *p)
{
char const *name = LC(LANG "CBI_CPU4");
cstr name = LC(LANG "CBI_CPU4");

CPU(2);
PrintTextChS(name);


+ 2
- 2
source/Main/p_gui_upgrades.c View File

@@ -69,7 +69,7 @@ static void GUIUpgradesList(struct gui_state *g, struct player *p)
if(G_ScrollOcclude(g, &CBIState(g)->upgrscr, y, gui_p.btnlist.h))
continue;

char const *color;
cstr color;
if(!upgr->owned && !P_Shop_CanBuy(p, &upgr->info->shopdef, upgr))
color = "u";
else switch(upgr->info->key)
@@ -154,7 +154,7 @@ static void GUIUpgradeDescription(struct gui_state *g, struct player *p, struct
SetClipW(111, 30, 190, 170, 184);

/* Cost */
char const *mark;
cstr mark;
str cost;

switch(upgr->info->key) {


+ 1
- 1
source/Main/p_hud.c View File

@@ -40,7 +40,7 @@ void HUD_WeaponSlots_Impl(struct player *p, struct hud_wsl const *a)
}
}

void HUD_Score(struct player *p, char const *fmt, i96 scrn, str font, str cr, i32 x, i32 xa, i32 y, i32 ya)
void HUD_Score(struct player *p, cstr fmt, i96 scrn, str font, str cr, i32 x, i32 xa, i32 y, i32 ya)
{
if(p->getCVarI(sc_hud_showscore))
{


+ 4
- 4
source/Main/p_log.c View File

@@ -54,7 +54,7 @@ static void LogF(struct player *p, struct logfdt *lf)

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

void P_Log_Both(struct player *p, i32 levl, char const *fmt, ...)
void P_Log_Both(struct player *p, i32 levl, cstr fmt, ...)
{
struct logdat ld = {};

@@ -71,7 +71,7 @@ void P_Log_Both(struct player *p, i32 levl, char const *fmt, ...)
LogH(p, &ld);
}

void P_Log_HUDs(struct player *p, i32 levl, char const *fmt, ...)
void P_Log_HUDs(struct player *p, i32 levl, cstr fmt, ...)
{
struct logdat ld = {};

@@ -87,7 +87,7 @@ void P_Log_HUDs(struct player *p, i32 levl, char const *fmt, ...)
LogH(p, &ld);
}

void P_Log_Full(struct player *p, char const *fmt, ...)
void P_Log_Full(struct player *p, cstr fmt, ...)
{
struct logfdt lf = {};

@@ -198,7 +198,7 @@ void HUD_Log(struct player *p, i32 cr, i32 x, i32 yy)

if(CheckFade(fid_logadS + i))
{
char const *s = RemoveTextColors_str(ld->inf, ACS_StrLen(ld->inf));
cstr s = RemoveTextColors_str(ld->inf, ACS_StrLen(ld->inf));
PrintTextChS(s);
PrintTextF(s_logfont, CR_WHITE, x,1, y,ya, fid_logadS + i);
}


+ 2
- 2
source/Main/p_notes.c View File

@@ -39,8 +39,8 @@ void P_CBI_TabNotes(struct gui_state *g, struct player *p)
if(G_Button_Id(g, i, p->notes[i] ? p->notes[i] : LC(LANG "EMPTY"),
44, i * 30, .disabled = !CBIState(g)->noteedit, Pre(btnnote)))
{
i32 l = CBIState(g)->notebox.tbptr;
char const *s = Cps_Print(CBIState(g)->notebox.txtbuf, l);
i32 l = CBIState(g)->notebox.tbptr;
cstr s = Cps_Expand(CBIState(g)->notebox.txtbuf, 0, l);

Dalloc(p->notes[i]);
p->notes[i] = Nalloc(l + 1);


+ 3
- 3
source/Main/p_obituary.c View File

@@ -20,7 +20,7 @@
script_str ext("ACS") addr("Lith_Obituary")
void Sc_Obituary(void)
{
static char const *pronoun[pro_max][5] = {
static cstr pronoun[pro_max][5] = {
{"they", "them", "their", "theirs", "they're"},
{"she", "her", "her", "hers", "she's" },
{"he", "him", "his", "his", "he's" },
@@ -46,9 +46,9 @@ void Sc_Obituary(void)
noinit static char out[1024];
char *pt = out;

for(char __str_ars const *s = obit; *s;)
for(astr s = obit; *s;)
{
char const *cs;
cstr cs;
str st;
i32 len;



+ 3
- 3
source/Main/p_pickups.c View File

@@ -61,8 +61,8 @@ static void StupidPickup(struct player *p, i32 weapon)

str nam = StupidName(weapon);

char const *fmt = LanguageC(LANG "PK_GET_%.3i", ifmt);
str unc = Language (LANG "PK_UNCERTAIN_%.3i", iunc);
cstr fmt = LanguageC(LANG "PK_GET_%.3i", ifmt);
str unc = Language (LANG "PK_UNCERTAIN_%.3i", iunc);

if(flag & 1 && flag & 4) p->logB(1, fmt, nam, nam, unc);
else if(flag & 1 ) p->logB(1, fmt, nam, nam);
@@ -92,7 +92,7 @@ void P_Log_SellWeapon(struct player *p, struct weaponinfo const *info, i96 score
else
nam = Language(LANG "INFO_SHORT_%S", info->name);

char const *msg = LC(LANG "LOG_Sell");
cstr msg = LC(LANG "LOG_Sell");

if(ord) p->logB(1, msg, nam, score);
else p->logB(1, msg, score, nam);


+ 1
- 1
source/Main/p_player.c View File

@@ -253,7 +253,7 @@ bool P_Upg_IsActive(struct player *p, i32 name)
}

stkcall
char const *P_Discrim(i32 pclass)
cstr P_Discrim(i32 pclass)
{
switch(pclass) {
case pcl_marine: return "Stan";


+ 10
- 10
source/Main/p_settings.c View File

@@ -149,17 +149,17 @@ if(p->num == 0) {

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

static char const *LvSysName(i32 num)
static cstr LvSysName(i32 num)
{
static char const *names[] = {"Auto", "Hybrid", "Manual"};
static cstr names[] = {"Auto", "Hybrid", "Manual"};

if(num < atsys_auto || num > atsys_manual) return "Unknown";
else return names[num];
}

static char const *ColorName(char ch)
static cstr ColorName(char ch)
{
static char const *colors[] = {
static cstr colors[] = {
"Brick", "Tan", "Grey", "Green", "Brown", "Gold", "Red", "Blue",
"Orange", "White", "Yellow", "Default", "Black", "Light Blue", "Cream",
"Olive", "Dark Green", "Dark Red", "Dark Brown", "Purple", "Dark Grey",
@@ -170,9 +170,9 @@ static char const *ColorName(char ch)