Refactored godmode so it's not occupying memory most of the time.

This commit is contained in:
Martin Haye 2018-04-20 09:21:52 -07:00
parent c7dfbef4c6
commit 80bc9c277c
6 changed files with 63 additions and 35 deletions

View File

@ -74,8 +74,8 @@
; 0000.01FF 6502 zero page and stack (aux)
; 0200.03FF (currently unused)
; 0400.07FF (unused, but screen holes overwritten by hard drive C7xx ROM)
; 0800.0D7A texture expander part 1 (used by 3D renderer)
; 0D7B.9xxx (free, managed)
; 0800.0D82 texture expander part 1 (used by 3D renderer)
; 0D83.9xxx (free, managed)
; A0xx.BFFF gameloop PLASMA code (loaded as high as possible)
; C000.CFFF I/O
; (bank 1) D000.DAFF ProRWTS runtime and buffers

View File

@ -111,7 +111,6 @@ import gamelib
predef scriptEvent(event, param)#0
predef scriptSetAvatar(avatarTileNum)#0
predef select(p, sel, num)#1
predef setCmd(key, func)#0
predef setCursor(x, y)#0
predef setGameFlag(flagName, val)#0
predef setGround(num)#0
@ -149,7 +148,6 @@ import gamelib
word skyNum
word groundNum
byte portraitNum
word pGodModule
word typeHash
byte isPlural
word ctx

View File

@ -2217,14 +2217,8 @@ def initMap(x, y, dir)#0
else
mmgr(QUEUE_LOAD, CODE_TILE_ENGINE<<8 | RES_TYPE_CODE)
fin
if global->b_godmode
pGodModule = mmgr(QUEUE_LOAD, MOD_GODMODE<<8 | RES_TYPE_MODULE)
fin
mmgr(FINISH_LOAD, 0)
// Grab the function table for the godMode module (if enabled)
if global->b_godmode; pGodModule = pGodModule(); fin
// Set up the command table
initCmds()
@ -3153,15 +3147,30 @@ def toggleGodMode()#1
textDrawn = TRUE
beep; beep
clearTextWindow()
saveMapPos(); restoreMapPos() // reload everything, including god module
initCmds() // rebuild the command table with new commands
fin
fin
return 0
end
///////////////////////////////////////////////////////////////////////////////////////////////////
export def setCmd(key, func)#0
cmdTbl[key] = func
def cheatCmd()#1
byte key
word pModule
key = charToUpper((^kbd) & $7F)
// We don't use laodEngine, since godmode may use it too, and we'd get double modules
unloadTextures() // seems to be necessary for teleport-to-3d to work right
flipToPage1()
mmgr(START_LOAD, 1) // code is in partition 1
pModule = mmgr(QUEUE_LOAD, MOD_GODMODE<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 0)
pModule()=>godmode_cheatCmd(key)
mmgr(FREE_MEMORY, pModule)
if renderLoaded; texControl(1); texturesLoaded = TRUE; fin
return 0
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -3186,7 +3195,16 @@ def initCmds()#0
cmdTbl[' '] = @snooze // "space out" (snooze)
cmdTbl['-'] = @showAutomap
if global->b_godmode
pGodModule=>godmode_setCheatCmds()
// install cheat commands
cmdTbl['T'] = @cheatCmd
cmdTbl['P'] = @cheatCmd
cmdTbl['>'] = @cheatCmd
cmdTbl['<'] = @cheatCmd
cmdTbl['!'] = @cheatCmd
cmdTbl['Y'] = @cheatCmd
cmdTbl['G'] = @cheatCmd
cmdTbl['&'] = @cheatCmd
cmdTbl['^'] = @cheatCmd
fin
// Commands handled differently in 3D vs 2D

View File

@ -20,10 +20,10 @@ include "gen_flags.plh"
// Exported functions go here. First a predef for each one, then a table with function pointers
// in the same order as the constants are defined in the the header.
predef _setCheatCmds()#1
predef _addItem(player)#1
predef _cheatCmd(key)#1
predef _addItem()#1
predef _addPlayer()#1
word[] funcTbl = @_setCheatCmds, @_addItem, @_addPlayer
word[] funcTbl = @_cheatCmd, @_addItem, @_addPlayer
asm _defs
@ -104,7 +104,7 @@ def kbdTeleport()#1
^$c052
setMap(d3, num, x, y, dir)
queue_setMap(d3, num, x, y, dir)
return 0
end
@ -224,17 +224,19 @@ def editFlags()#1
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def _setCheatCmds()#1
// install cheat commands
setCmd('T', @kbdTeleport)
setCmd('P', @showPos)
setCmd('>', @nextPortrait)
setCmd('<', @prevPortrait)
setCmd('!', @testCombat)
setCmd('Y', @nextSky)
setCmd('G', @nextGround)
setCmd('&', @printMem)
setCmd('^', @editFlags)
def _cheatCmd(key)#1
when key
is 'T'; kbdTeleport(); break
is 'P'; showPos(); break
is '>'; nextPortrait(); break
is '<'; prevPortrait(); break
is '!'; testCombat(); break
is 'Y'; nextSky(); break
is 'G'; nextGround(); break
is '&'; printMem(); break
is '^'; editFlags(); break
otherwise fatal("gmcmd")
wend
return 0
end
@ -286,7 +288,7 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Add an item cheat
def _addItem(player)#1
def _addItem()#1
word funcNum
funcNum = selectThing(MOD_GEN_ITEMS, NUM_ITEMS, 2, "Add item #: ")
if funcNum >= 0

View File

@ -9,6 +9,6 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// Each module-exported function needs its own constant, 0..n
const godmode_setCheatCmds = 0
const godmode_cheatCmd = 0
const godmode_addItem = 2
const godmode_addPlayer = 4

View File

@ -643,6 +643,18 @@ def interactWithItem(player, item)#1
return NULL
end
// Do a cheat command, loading and unloading the godmode module
def callGodModule(funcNum)#0
word pModule, func
clearMainRect()
mmgr(START_LOAD, 1) // code is in partition 1
pModule = mmgr(QUEUE_LOAD, MOD_GODMODE<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, 0)
func = *(pModule() + funcNum)
func()
mmgr(FREE_MEMORY, pModule)
end
// Show player sheet and accept command. If using an item (not just for stats gain)
// the item is returned; else NULL is returned.
def _showPlayerSheet(player_num)#1 // funcTbl functions always have to return a value
@ -738,15 +750,13 @@ def _showPlayerSheet(player_num)#1 // funcTbl functions always have to return a
break
is '%' // add item cheat
if global->b_godmode
clearMainRect()
pGodModule=>godmode_addItem(player)
callGodModule(godmode_addItem)
redisplay = 2
fin
break
is '9' // add player cheat
if global->b_godmode
clearMainRect()
pGodModule=>godmode_addPlayer()
callGodModule(godmode_addPlayer)
redisplay = 2
fin
break