Refactored to get rid of lib vectors, thanks to Dave.

This commit is contained in:
Martin Haye 2016-07-03 13:39:00 -07:00
parent 0708cbda95
commit 0fe5ef28ca
5 changed files with 98 additions and 285 deletions

View File

@ -1070,9 +1070,19 @@ class PackPartitions
} }
else if (esdFlag == 0x08) { else if (esdFlag == 0x08) {
assert name == "gameloop" : "Can only export from gameloop" assert name == "gameloop" : "Can only export from gameloop"
//println "Export 'esdName' at offset $esdNum." //println "Export '$esdName' at offset $esdNum."
def target = invDefs[esdNum] def target
assert target != null : "Can only export functions" if (invDefs.containsKey(esdNum)) {
//println " ...in invDefs."
target = invDefs[esdNum]
}
else {
//println " ...in asm or data."
target = esdNum - 0x1000
target -= asmCodeStart
target += stubsSize // account for the stubs we prepended to the asm code
}
//println "...final target: $target"
exports[esdName] = target exports[esdName] = target
} }
else else
@ -1113,8 +1123,7 @@ class PackPartitions
//println String.format("...target=0x%04x", target) //println String.format("...target=0x%04x", target)
if (fixupType == 0x91) { // external fixup if (fixupType == 0x91) { // external fixup
//println "external fixup: esdIndex=$esdIndex" //println "external fixup: esdIndex=$esdIndex target=$target"
//println "imports=$imports is=${imports.containsKey(esdIndex)}"
def esdName = imports[esdIndex] def esdName = imports[esdIndex]
//println "esdName='$esdName'" //println "esdName='$esdName'"
assert esdName != null : "failed to look up esdIndex $esdIndex" assert esdName != null : "failed to look up esdIndex $esdIndex"
@ -1864,6 +1873,7 @@ class PackPartitions
out.println("// Generated code - DO NOT MODIFY BY HAND") out.println("// Generated code - DO NOT MODIFY BY HAND")
out.println() out.println()
out.println("include \"gamelib.plh\"") out.println("include \"gamelib.plh\"")
out.println("include \"globalDefs.plh\"")
out.println("include \"playtype.plh\"") out.println("include \"playtype.plh\"")
out.println("include \"gen_images.plh\"") out.println("include \"gen_images.plh\"")
out.println() out.println()
@ -2126,6 +2136,7 @@ end
out.println("// Generated code - DO NOT MODIFY BY HAND") out.println("// Generated code - DO NOT MODIFY BY HAND")
out.println() out.println()
out.println("include \"gamelib.plh\"") out.println("include \"gamelib.plh\"")
out.println("include \"globalDefs.plh\"")
out.println("include \"playtype.plh\"") out.println("include \"playtype.plh\"")
out.println("include \"gen_items.plh\"") out.println("include \"gen_items.plh\"")
out.println() out.println()
@ -2255,6 +2266,7 @@ end
out.println("// Generated code - DO NOT MODIFY BY HAND") out.println("// Generated code - DO NOT MODIFY BY HAND")
out.println() out.println()
out.println("include \"gamelib.plh\"") out.println("include \"gamelib.plh\"")
out.println("include \"globalDefs.plh\"")
out.println("include \"playtype.plh\"") out.println("include \"playtype.plh\"")
out.println("include \"gen_modules.plh\"") out.println("include \"gen_modules.plh\"")
out.println("include \"gen_items.plh\"") out.println("include \"gen_items.plh\"")
@ -2587,6 +2599,7 @@ end
out = new PrintWriter(new FileWriter(outFile)) out = new PrintWriter(new FileWriter(outFile))
out << "// Generated code - DO NOT MODIFY BY HAND\n\n" out << "// Generated code - DO NOT MODIFY BY HAND\n\n"
out << "include \"../plasma/gamelib.plh\"\n" out << "include \"../plasma/gamelib.plh\"\n"
out << "include \"../plasma/globalDefs.plh\"\n"
out << "include \"../plasma/playtype.plh\"\n" out << "include \"../plasma/playtype.plh\"\n"
out << "include \"../plasma/gen_images.plh\"\n\n" out << "include \"../plasma/gen_images.plh\"\n\n"
out << "word global\n" out << "word global\n"

View File

@ -9,6 +9,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
include "gamelib.plh" include "gamelib.plh"
include "globalDefs.plh"
include "playtype.plh" include "playtype.plh"
include "gen_images.plh" include "gen_images.plh"
include "gen_enemies.plh" include "gen_enemies.plh"

View File

@ -9,6 +9,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
include "gamelib.plh" include "gamelib.plh"
include "globalDefs.plh"
include "playtype.plh" include "playtype.plh"
include "diskops.plh" include "diskops.plh"
include "gen_modules.plh" include "gen_modules.plh"
@ -283,10 +284,6 @@ end
def _newOrLoadGame() def _newOrLoadGame()
byte key byte key
printf1("testFunc=$%x\n", @testFunc)
printf1("fooFunc=$%x\n", @fooFunc)
brk()
if !gameExists() if !gameExists()
newGame(); return 1 newGame(); return 1
fin fin

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1 // Copyright (C) 2016 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License. // (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>. // You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under // Unless required by applicable law or agreed to in writing, software distributed under
@ -8,146 +8,19 @@
// governing permissions and limitations under the License. // governing permissions and limitations under the License.
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
import gamelib
predef testFunc
predef fooFunc
word glib
word glib2
struc t_gamelib
word testStructOff1
word testStructOff2
end
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Handy constants.
const FALSE = 0
const TRUE = 1
const NULL = 0
const INT_MAX = 32767
const INT_MIN = -32768
///////////////////////////////////////////////////////////////////////////////////////////////////
// IO locations
const kbd = $C000
const kbdStrobe = $C010
///////////////////////////////////////////////////////////////////////////////////////////////////
// Memory manager definitions
// Resource types
const RES_TYPE_CODE = 1
const RES_TYPE_2D_MAP = 2
const RES_TYPE_3D_MAP = 3
const RES_TYPE_TILE = 4
const RES_TYPE_TEXTURE = 5
const RES_TYPE_SCREEN = 6
const RES_TYPE_FONT = 7
const RES_TYPE_MODULE = 8
const RES_TYPE_BYTECODE = 9
const RES_TYPE_FIXUP = 10
const RES_TYPE_PORTRAIT = 11
// Command codes
const RESET_MEMORY = $10
const REQUEST_MEMORY = $11
const LOCK_MEMORY = $12
const UNLOCK_MEMORY = $13
const SET_MEM_TARGET = $14
const START_LOAD = $15
const QUEUE_LOAD = $16
const FINISH_LOAD = $17
const FREE_MEMORY = $18
const CALC_FREE = $19
const DEBUG_MEM = $1A
const CHECK_MEM = $1B
const CHAIN_LOADER = $1E
const FATAL_ERROR = $1F
const HEAP_SET = $20
const HEAP_ADD_TYPE = $21
const HEAP_ALLOC = $22
const HEAP_INTERN = $23
const HEAP_COLLECT = $24
// Constants for FINISH_LOAD
const WITH_CLOSE = 0
const LEAVE_OPEN = 1
// Heap location in memory
const HEAP_BOTTOM = $F000
const HEAP_SIZE = $800
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Shared library routines // Shared library routines
const gameLibVecs = $1F00 import gamelib
predef setScriptInfo, scriptDisplayStr, scriptDisplayStrNL, getYN, queue_setMap
const setScriptInfo = gameLibVecs + 3*0 predef setSky, setGround, queue_teleport, setPortrait, clearPortrait, moveWayBackward
const scriptDisplayStr = gameLibVecs + 3*1 predef getUpperKey, clearWindow, getGlobals, rand16, printf1, printf2, printf3
const scriptDisplayStrNL = gameLibVecs + 3*2 predef displayf1, displayf2, displayf3, buildString, addToString, finishString
const getYN = gameLibVecs + 3*3 predef rawDisplayStr, displayStr, puts
const queue_setMap = gameLibVecs + 3*4 predef min, max, countList, countListFiltered, randomFromListFiltered, randomFromArray, addToList
const setSky = gameLibVecs + 3*5 predef beep, showParty, mmgr, setWindow1, setWindow2, setWindow3, reboot, brk
const setGround = gameLibVecs + 3*6 predef encodeDice, rollDice, setPlural, getStringResponse
const queue_teleport = gameLibVecs + 3*7 predef streqi, fatal, pause, tossStrings
const setPortrait = gameLibVecs + 3*8 predef addEncounterZone, showMapName, setMapWindow, makeModifier
const clearPortrait = gameLibVecs + 3*9 predef calcPlayerArmor, diskActivity, rdkey, initHeap, scriptCombat
const moveWayBackward = gameLibVecs + 3*10 end
const getUpperKey = gameLibVecs + 3*11
const clearWindow = gameLibVecs + 3*12
const getGlobals = gameLibVecs + 3*13
const rand16 = gameLibVecs + 3*14
const printf1 = gameLibVecs + 3*15
const printf2 = gameLibVecs + 3*16
const printf3 = gameLibVecs + 3*17
const displayf1 = gameLibVecs + 3*18
const displayf2 = gameLibVecs + 3*19
const displayf3 = gameLibVecs + 3*20
const buildString = gameLibVecs + 3*21
const addToString = gameLibVecs + 3*22
const finishString = gameLibVecs + 3*23
const rawDisplayStr = gameLibVecs + 3*24
const displayStr = gameLibVecs + 3*25
const puts = gameLibVecs + 3*26
const min = gameLibVecs + 3*27
const max = gameLibVecs + 3*28
const countList = gameLibVecs + 3*29
const countListFiltered = gameLibVecs + 3*30
const randomFromListFiltered = gameLibVecs + 3*31
const addToList = gameLibVecs + 3*32
const beep = gameLibVecs + 3*33
const showParty = gameLibVecs + 3*34
const mmgr = gameLibVecs + 3*35
const setWindow1 = gameLibVecs + 3*36
const setWindow2 = gameLibVecs + 3*37
const setWindow3 = gameLibVecs + 3*38
const reboot = gameLibVecs + 3*39
const brk = gameLibVecs + 3*40
const encodeDice = gameLibVecs + 3*41
const rollDice = gameLibVecs + 3*42
const setPlural = gameLibVecs + 3*43
const getStringResponse = gameLibVecs + 3*44
const streqi = gameLibVecs + 3*45
const addEncounterZone = gameLibVecs + 3*46
const fatal = gameLibVecs + 3*47
const pause = gameLibVecs + 3*48
const tossStrings = gameLibVecs + 3*49
const showMapName = gameLibVecs + 3*50
const setMapWindow = gameLibVecs + 3*51
const makeModifier = gameLibVecs + 3*52
const randomFromArray = gameLibVecs + 3*53
const calcPlayerArmor = gameLibVecs + 3*54
const diskActivity = gameLibVecs + 3*55
const rdkey = gameLibVecs + 3*56
const initHeap = gameLibVecs + 3*57
const scriptCombat = gameLibVecs + 3*58
const UNUSED_FN_59 = gameLibVecs + 3*59
const UNUSED_FN_60 = gameLibVecs + 3*60
const UNUSED_FN_61 = gameLibVecs + 3*61
const UNUSED_FN_62 = gameLibVecs + 3*62
const UNUSED_FN_63 = gameLibVecs + 3*63
const UNUSED_FN_64 = gameLibVecs + 3*64
const UNUSED_FN_65 = gameLibVecs + 3*65
const UNUSED_FN_66 = gameLibVecs + 3*66
const UNUSED_FN_67 = gameLibVecs + 3*67
const UNUSED_FN_68 = gameLibVecs + 3*68

View File

@ -8,8 +8,6 @@
// governing permissions and limitations under the License. // governing permissions and limitations under the License.
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
include "gamelib.plh"
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Fixed memory locations // Fixed memory locations
const seed = $4E // Incremented continuously by keyboard read routine const seed = $4E // Incremented continuously by keyboard read routine
@ -28,6 +26,7 @@ const ANIM_FLAG_RANDOM = $80
const ANIM_PAUSE_MAX = 300 const ANIM_PAUSE_MAX = 300
include "globalDefs.plh"
include "playtype.plh" include "playtype.plh"
include "gen_images.plh" include "gen_images.plh"
include "gen_modules.plh" include "gen_modules.plh"
@ -42,13 +41,14 @@ include "diskops.plh"
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Data structures // Data structures
word fooStart
include "playtype.pla" include "playtype.pla"
word global // the global heap object, from which all live objects must be reachable word global // the global heap object, from which all live objects must be reachable
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Predefined functions, for circular calls or out-of-order calls // Predefined functions, for circular calls or out-of-order calls
predef setWindow2, initCmds, nextAnimFrame, checkEncounter, doCombat predef setWindow2, initCmds, nextAnimFrame, checkEncounter, doCombat, clearPortrait, showMapName
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Global variables // Global variables
@ -95,44 +95,9 @@ byte animNumFrames
byte animFrame byte animFrame
word animPauseCt word animPauseCt
// Game library functions
predef _setScriptInfo, _scriptDisplayStr, _scriptDisplayStrNL, _getYN
predef _queue_setMap, _setSky, _setGround, _queue_teleport, _setPortrait, _clearPortrait
predef _moveWayBackward, _getUpperKey, _clearWindow, _setPortrait
predef _getGlobals, _rand16
predef _printf1, _printf2, _printf3
predef _displayf1, _displayf2, _displayf3
predef _buildString, _addToString, _finishString, _rawDisplayStr, _displayStr
predef _puts, _min, _max
predef _countList, _countListFiltered, _randomFromListFiltered, _addToList, _beep
predef _showParty, _mmgr, _setWindow1, _setWindow2, _setWindow3
predef _reboot, _brk, _encodeDice, _rollDice
predef _setPlural, _getStringResponse, _streqi, _addEncounterZone, _fatal
predef _pause, _tossStrings, _showMapName, _setMapWindow
predef _makeModifier, _randomFromArray, _calcPlayerArmor, _diskActivity
predef _rdkey, _initHeap, _scriptCombat
word gameLib_addrs = @_setScriptInfo, @_scriptDisplayStr, @_scriptDisplayStrNL, @_getYN
word = @_queue_setMap, @_setSky, @_setGround, @_queue_teleport, @_setPortrait, @_clearPortrait
word = @_moveWayBackward, @_getUpperKey, @_clearWindow
word = @_getGlobals, @_rand16
word = @_printf1, @_printf2, @_printf3
word = @_displayf1, @_displayf2, @_displayf3
word = @_buildString, @_addToString, @_finishString, @_rawDisplayStr, @_displayStr
word = @_puts, @_min, @_max
word = @_countList, @_countListFiltered, @_randomFromListFiltered, @_addToList, @_beep
word = @_showParty, @_mmgr, @_setWindow1, @_setWindow2, @_setWindow3
word = @_reboot, @_brk, @_encodeDice, @_rollDice
word = @_setPlural, @_getStringResponse, @_streqi, @_addEncounterZone, @_fatal
word = @_pause, @_tossStrings, @_showMapName, @_setMapWindow
word = @_makeModifier, @_randomFromArray, @_calcPlayerArmor, @_diskActivity
word = @_rdkey, @_initHeap, @_scriptCombat
word = 0 // end of library functions
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Definitions used by assembly code // Definitions used by assembly code
asm __defs asm _defs
; Use hi-bit ASCII for Apple II ; Use hi-bit ASCII for Apple II
!convtab "../../include/hiBitAscii.ct" !convtab "../../include/hiBitAscii.ct"
@ -165,7 +130,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Temporary hack: after scriptDisplayStr is called, generated code calls this to clear the PLASMA // Temporary hack: after scriptDisplayStr is called, generated code calls this to clear the PLASMA
// string pool. That way, many long strings can be used in a single function. // string pool. That way, many long strings can be used in a single function.
asm _tossStrings export asm tossStrings
lda framePtr lda framePtr
sta outerFramePtr sta outerFramePtr
lda framePtr+1 lda framePtr+1
@ -261,7 +226,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// String building for display with the font engine. Includes plurality processing to handily // String building for display with the font engine. Includes plurality processing to handily
// handle things like "Dirt bag(s)" and "his/their" // handle things like "Dirt bag(s)" and "his/their"
asm _buildString export asm buildString
+asmPlasm 1 +asmPlasm 1
sta cswl sta cswl
sty cswh sty cswh
@ -270,7 +235,7 @@ asm _buildString
rts rts
end end
asm _addToString export asm addToString
sty ysav1 sty ysav1
inc inbuf inc inbuf
ldy inbuf ldy inbuf
@ -279,7 +244,7 @@ asm _addToString
rts rts
end end
asm _finishString export asm finishString
!zone { !zone {
+asmPlasm 1 +asmPlasm 1
sta tmp ; save isPlural flag sta tmp ; save isPlural flag
@ -490,7 +455,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Print a string to the current character output vector // Print a string to the current character output vector
asm _puts export asm puts
+asmPlasm 1 +asmPlasm 1
sta pTmp sta pTmp
sty pTmp+1 sty pTmp+1
@ -509,7 +474,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Get a character from the keyboard // Get a character from the keyboard
asm _rdkey export asm rdkey
+asmPlasm 0 +asmPlasm 0
jmp rdkey jmp rdkey
end end
@ -577,7 +542,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Ring the bell // Ring the bell
asm _beep export asm beep
+asmPlasm 0 +asmPlasm 0
jmp bell jmp bell
end end
@ -605,7 +570,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Send a command to the memory manager // Send a command to the memory manager
// Params: cmd, wordParam // Params: cmd, wordParam
asm _mmgr export asm mmgr
+asmPlasm 2 +asmPlasm 2
lda evalStkL+1,x ; command code lda evalStkL+1,x ; command code
pha pha
@ -636,7 +601,7 @@ end
// Show or hide the disk activity icon (at the top of hi-res page 1). The icon consists of a 4x4 // Show or hide the disk activity icon (at the top of hi-res page 1). The icon consists of a 4x4
// block of blue pixels surrounded by a black border. // block of blue pixels surrounded by a black border.
// Params: show/hide ($FF, or 0) // Params: show/hide ($FF, or 0)
asm _diskActivity export asm diskActivity
+asmPlasm 1 +asmPlasm 1
sta tmp ; save show(FF) / hide(0) flag sta tmp ; save show(FF) / hide(0) flag
ldx #0 ldx #0
@ -673,7 +638,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Execute a monitor breakpoint // Execute a monitor breakpoint
// Params: None // Params: None
asm _brk export asm brk
bit setText bit setText
bit page1 bit page1
brk brk
@ -683,7 +648,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Clear the screen and reboot the machine // Clear the screen and reboot the machine
// Params: None // Params: None
asm _reboot export asm reboot
bit setROM bit setROM
jsr home jsr home
bit setText bit setText
@ -734,7 +699,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Use the font engine to clear the current text window // Use the font engine to clear the current text window
// Params: None // Params: None
asm _clearWindow export asm clearWindow
+asmPlasm_bank2 0 +asmPlasm_bank2 0
jmp ClearWindow jmp ClearWindow
end end
@ -758,7 +723,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Display a string using the font engine. // Display a string using the font engine.
// Params: pStr // Params: pStr
asm _displayStr export asm displayStr
+asmPlasm_bank2 1 +asmPlasm_bank2 1
jmp DisplayStr jmp DisplayStr
end end
@ -774,7 +739,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Display a string using the font engine but not its parser. // Display a string using the font engine but not its parser.
// Params: pStr // Params: pStr
asm _rawDisplayStr export asm rawDisplayStr
+asmPlasm_bank2 1 +asmPlasm_bank2 1
sta pTmp sta pTmp
sty pTmp+1 sty pTmp+1
@ -802,7 +767,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Random number generator // Random number generator
// Adapted from http://codebase64.org/doku.php?id=base:small_fast_16-bit_prng // Adapted from http://codebase64.org/doku.php?id=base:small_fast_16-bit_prng
asm _rand16 export asm rand16
+asmPlasm 0 +asmPlasm 0
lda seed lda seed
@ -846,26 +811,15 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// General methods // General methods
// FOO
export def testFunc()
puts("This is testFunc.\n")
brk()
end
export def fooFunc()
puts("This is foo\n")
brk()
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Fatal error: print message and stop the system. // Fatal error: print message and stop the system.
def _fatal(msg) export def fatal(msg)
mmgr(FATAL_ERROR, msg) mmgr(FATAL_ERROR, msg)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Return the max of two signed 16-bit numbers // Return the max of two signed 16-bit numbers
def _max(a, b) export def max(a, b)
if a < b if a < b
return b return b
else else
@ -875,7 +829,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Return the min of two signed 16-bit numbers // Return the min of two signed 16-bit numbers
def _min(a, b) export def min(a, b)
if a < b if a < b
return a return a
else else
@ -895,7 +849,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Read a string from the keyboard using the font manager, and intern it to the heap. // Read a string from the keyboard using the font manager, and intern it to the heap.
def _getStringResponse() export def getStringResponse()
word p word p
rawGetStr() rawGetStr()
rawDisplayStr("\n") // so Outlaw user doesn't have to remember to make a newline rawDisplayStr("\n") // so Outlaw user doesn't have to remember to make a newline
@ -908,7 +862,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Setter functions for library use // Setter functions for library use
def _setPlural(flg) export def setPlural(flg)
isPlural = flg isPlural = flg
end end
@ -931,7 +885,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Print a formatted string a'la C printf, with up to three parameters. // Print a formatted string a'la C printf, with up to three parameters.
def _printf3(str, arg1, arg2, arg3) export def printf3(str, arg1, arg2, arg3)
word pos word pos
word curArg word curArg
word p word p
@ -962,18 +916,18 @@ def _printf3(str, arg1, arg2, arg3)
loop loop
end end
def _printf1(str, arg1); printf3(str, arg1, 0, 0); end export def printf1(str, arg1); printf3(str, arg1, 0, 0); end
def _printf2(str, arg1, arg2); printf3(str, arg1, arg2, 0); end export def printf2(str, arg1, arg2); printf3(str, arg1, arg2, 0); end
// Like printf, but displays text using font engine // Like printf, but displays text using font engine
def _displayf3(str, arg1, arg2, arg3) export def displayf3(str, arg1, arg2, arg3)
buildString(@addToString) buildString(@addToString)
printf3(str, arg1, arg2, arg3) printf3(str, arg1, arg2, arg3)
displayStr(finishString(isPlural)) displayStr(finishString(isPlural))
end end
def _displayf1(str, arg1); displayf3(str, arg1, 0, 0); end export def displayf1(str, arg1); displayf3(str, arg1, 0, 0); end
def _displayf2(str, arg1, arg2); displayf3(str, arg1, arg2, 0); end export def displayf2(str, arg1, arg2); displayf3(str, arg1, arg2, 0); end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def parseDec(str) def parseDec(str)
@ -1019,7 +973,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Get a keystroke and convert it to upper case // Get a keystroke and convert it to upper case
def _getUpperKey() export def getUpperKey()
byte key byte key
while ^kbd < 128 while ^kbd < 128
*seed = *seed + 1 *seed = *seed + 1
@ -1038,7 +992,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Pause for a specified count period, advancing the animation periodically. // Pause for a specified count period, advancing the animation periodically.
def _pause(count) export def pause(count)
while count >= 0 while count >= 0
animPauseCt = animPauseCt - 1 animPauseCt = animPauseCt - 1
if animPauseCt < 0 if animPauseCt < 0
@ -1052,12 +1006,12 @@ def _pause(count)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _encodeDice(nDice, dieSize, add) // ndice=0..15, dieSize=0..15, add=0..255 export def encodeDice(nDice, dieSize, add) // ndice=0..15, dieSize=0..15, add=0..255
return (nDice << 12) | (dieSize << 8) | add return (nDice << 12) | (dieSize << 8) | add
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _rollDice(encoded) export def rollDice(encoded)
byte i, nDice, dieSize, add, result byte i, nDice, dieSize, add, result
nDice = encoded >> 12 nDice = encoded >> 12
dieSize = (encoded >> 8) & $F dieSize = (encoded >> 8) & $F
@ -1072,7 +1026,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Set the sky color (relevant to 3D display only) // Set the sky color (relevant to 3D display only)
def _setSky(num) export def setSky(num)
skyNum = num skyNum = num
setColor(0, skyNum) setColor(0, skyNum)
needRender = TRUE needRender = TRUE
@ -1086,7 +1040,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Set the ground color (relevant to 3D display only) // Set the ground color (relevant to 3D display only)
def _setGround(num) export def setGround(num)
groundNum = num groundNum = num
setColor(1, groundNum) setColor(1, groundNum)
needRender = TRUE needRender = TRUE
@ -1117,27 +1071,27 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Window for the map name bar // Window for the map name bar
def _setWindow1() export def setWindow1()
setWindow(8, 18, 35, 119) // Top, Bottom, Left, Right setWindow(8, 18, 35, 119) // Top, Bottom, Left, Right
mapNameHash = 0 // on the assumption that it's being set because somebody's going to print there mapNameHash = 0 // on the assumption that it's being set because somebody's going to print there
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Window for the large upper right bar // Window for the large upper right bar
def _setWindow2() export def setWindow2()
displayChar('N'-$40) // Set normal mode - clear all special modes (like underline, etc.) displayChar('N'-$40) // Set normal mode - clear all special modes (like underline, etc.)
setWindow(24, 132, 154, 269) // Top, Bottom, Left, Right setWindow(24, 132, 154, 269) // Top, Bottom, Left, Right
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Window for the mid-size lower right bar // Window for the mid-size lower right bar
def _setWindow3() export def setWindow3()
setWindow(144, 180, 154, 269) // Top, Bottom, Left, Right setWindow(144, 180, 154, 269) // Top, Bottom, Left, Right
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Window for the map area (used for clearing it) // Window for the map area (used for clearing it)
def _setMapWindow() export def setMapWindow()
if frameLoaded == 3 // don't check mapIs3D, since we might be in an engine if frameLoaded == 3 // don't check mapIs3D, since we might be in an engine
setWindow(24, 153, 14, 140) // Top, Bottom, Left, Right setWindow(24, 153, 14, 140) // Top, Bottom, Left, Right
else else
@ -1186,7 +1140,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Display the party data on the screen // Display the party data on the screen
def _showParty() export def showParty()
word p word p
saveCursor() saveCursor()
@ -1319,7 +1273,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Display a portrait drawing (typically called from scripts) // Display a portrait drawing (typically called from scripts)
def _clearPortrait() export def clearPortrait()
if curPortrait if curPortrait
auxMmgr(FREE_MEMORY, curPortrait) auxMmgr(FREE_MEMORY, curPortrait)
curPortrait = 0 curPortrait = 0
@ -1392,7 +1346,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Move backward four steps (3D mode), or one step (2D mode) // Move backward four steps (3D mode), or one step (2D mode)
def _moveWayBackward() export def moveWayBackward()
adjustDir(8) adjustDir(8)
moveForward() moveForward()
if mapIs3D if mapIs3D
@ -1548,7 +1502,7 @@ def showPos()
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _queue_setMap(is3D, num, x, y, dir) export def queue_setMap(is3D, num, x, y, dir)
q_mapIs3D = is3D q_mapIs3D = is3D
q_mapNum = num q_mapNum = num
q_x = x q_x = x
@ -1557,7 +1511,7 @@ def _queue_setMap(is3D, num, x, y, dir)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _queue_teleport(x, y, dir) export def queue_teleport(x, y, dir)
queue_setMap(mapIs3D, mapNum, x, y, dir) queue_setMap(mapIs3D, mapNum, x, y, dir)
end end
@ -1591,7 +1545,7 @@ def kbdLoop()
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _showMapName(mapName) export def showMapName(mapName)
word newNameHash word newNameHash
newNameHash = hashString(mapName) newNameHash = hashString(mapName)
@ -1609,7 +1563,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Set initial info for the scripts on this map: the name of the map, its trigger table, and the // Set initial info for the scripts on this map: the name of the map, its trigger table, and the
// maximum extent (width, height). This is called by the init function for the scripts. // maximum extent (width, height). This is called by the init function for the scripts.
def _setScriptInfo(mapName, trigTbl, wdt, hgt) export def setScriptInfo(mapName, trigTbl, wdt, hgt)
// Grab the trigger table origins (used so the table can be more compact) // Grab the trigger table origins (used so the table can be more compact)
triggerOriginX = trigTbl=>0 triggerOriginX = trigTbl=>0
@ -1635,21 +1589,21 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Called by scripts to display a string. We set the flag noting that something has been // Called by scripts to display a string. We set the flag noting that something has been
// displayed, then use an assembly routine to do the work. // displayed, then use an assembly routine to do the work.
def _scriptDisplayStr(str) export def scriptDisplayStr(str)
textDrawn = TRUE textDrawn = TRUE
flipToPage1() flipToPage1()
displayStr(str) displayStr(str)
tossStrings() tossStrings()
end end
def _scriptDisplayStrNL(str) export def scriptDisplayStrNL(str)
scriptDisplayStr(str) scriptDisplayStr(str)
displayStr("\n") displayStr("\n")
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Get a key, and don't return until it's Y or N (or lower-case of those). Returns 1 for Y. // Get a key, and don't return until it's Y or N (or lower-case of those). Returns 1 for Y.
def _getYN() export def getYN()
byte key byte key
while TRUE while TRUE
key = getUpperKey() key = getUpperKey()
@ -1738,7 +1692,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Display a portrait drawing (typically called from scripts) // Display a portrait drawing (typically called from scripts)
def _setPortrait(portraitNum) export def setPortrait(portraitNum)
word srcData word srcData
byte cx, cy byte cx, cy
@ -1802,7 +1756,7 @@ def prevPortrait()
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _countList(p) export def countList(p)
byte n byte n
n = 0 n = 0
while p while p
@ -1813,7 +1767,7 @@ def _countList(p)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _countListFiltered(p, offset, filterFunc) export def countListFiltered(p, offset, filterFunc)
byte n byte n
n = 0 n = 0
while p while p
@ -1826,7 +1780,7 @@ def _countListFiltered(p, offset, filterFunc)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _randomFromListFiltered(p, offset, filterFunc) export def randomFromListFiltered(p, offset, filterFunc)
byte n byte n
n = rand16() % countListFiltered(p, offset, filterFunc) n = rand16() % countListFiltered(p, offset, filterFunc)
while p while p
@ -1841,7 +1795,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Call like this: addToList(@player=>p_items, itemToAdd) // Call like this: addToList(@player=>p_items, itemToAdd)
def _addToList(addTo, p) export def addToList(addTo, p)
// Get to the end of the list // Get to the end of the list
while *addTo while *addTo
addTo = (*addTo) + p_nextObj addTo = (*addTo) + p_nextObj
@ -1852,7 +1806,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Call like this: removeFromList(@player=>items, itemToRemove) // Call like this: removeFromList(@player=>items, itemToRemove)
def _removeFromList(pList, toRemove) export def removeFromList(pList, toRemove)
word p word p
p = *pList p = *pList
@ -1920,7 +1874,7 @@ def showPlayer3()
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _addEncounterZone(code, x, y, dist, chance) export def addEncounterZone(code, x, y, dist, chance)
word p; p = mmgr(HEAP_ALLOC, TYPE_ENCOUNTER_ZONE) word p; p = mmgr(HEAP_ALLOC, TYPE_ENCOUNTER_ZONE)
p=>s_name = mmgr(HEAP_INTERN, code) p=>s_name = mmgr(HEAP_INTERN, code)
p=>w_encX = x p=>w_encX = x
@ -1932,7 +1886,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Compare two strings for equality, ignoring case. // Compare two strings for equality, ignoring case.
def _streqi(a, b) export def streqi(a, b)
word limit, leneq word limit, leneq
leneq = ^a == ^b leneq = ^a == ^b
limit = a + min(^a, ^b) limit = a + min(^a, ^b)
@ -1946,7 +1900,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Called by user-defined map scripts to initiate a combat encounter. // Called by user-defined map scripts to initiate a combat encounter.
def _scriptCombat(mapCode) export def scriptCombat(mapCode)
word pScripts word pScripts
word result word result
@ -2154,7 +2108,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Set up the small-object heap. Set loadedSize to zero on initial, or non-zero for loaded game. // Set up the small-object heap. Set loadedSize to zero on initial, or non-zero for loaded game.
def _initHeap(loadedSize) export def initHeap(loadedSize)
byte i byte i
if !heapLocked if !heapLocked
@ -2181,41 +2135,19 @@ def _initHeap(loadedSize)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
def _getGlobals() export def getGlobals()
return global return global
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Set up the library vectors so we can share the library routines
def setLibVecs()
word sp, dp
// We're going to put the vectors at a known location, and lock that space
_mmgr(SET_MEM_TARGET, gameLibVecs)
_mmgr(REQUEST_MEMORY, $100)
_mmgr(LOCK_MEMORY, gameLibVecs)
// Now set up the jump vectors
sp = @gameLib_addrs
dp = gameLibVecs
while *sp
dp->0 = $4c
dp=>1 = *sp
sp = sp + 2
dp = dp + 3
loop
end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Return a random entry from an array, given its size in number of elements. // Return a random entry from an array, given its size in number of elements.
def _randomFromArray(arr, siz) export def randomFromArray(arr, siz)
return *(((rand16() % siz) << 1) + arr) return *(((rand16() % siz) << 1) + arr)
end end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Constructor: create a modifier given its name and value // Constructor: create a modifier given its name and value
def _makeModifier(name, value) export def makeModifier(name, value)
word p; p = mmgr(HEAP_ALLOC, TYPE_MODIFIER) word p; p = mmgr(HEAP_ALLOC, TYPE_MODIFIER)
p=>s_name = mmgr(HEAP_INTERN, name) p=>s_name = mmgr(HEAP_INTERN, name)
p=>w_modValue = value p=>w_modValue = value
@ -2224,7 +2156,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Recalculate player's armor score based on their currently equipped armor // Recalculate player's armor score based on their currently equipped armor
def _calcPlayerArmor(player) export def calcPlayerArmor(player)
word pItem word pItem
player->b_armor = 0 player->b_armor = 0
pItem = player=>p_items pItem = player=>p_items
@ -2244,8 +2176,6 @@ def startGame()
mmgr(START_LOAD, 1) // code is in partition 1 mmgr(START_LOAD, 1) // code is in partition 1
p_module = mmgr(QUEUE_LOAD, MODULE_DISKOPS<<8 | RES_TYPE_MODULE) p_module = mmgr(QUEUE_LOAD, MODULE_DISKOPS<<8 | RES_TYPE_MODULE)
mmgr(FINISH_LOAD, LEAVE_OPEN) mmgr(FINISH_LOAD, LEAVE_OPEN)
printf1("Outer testFunc=$%x\n", @testFunc)
printf1("Outer fooFunc=$%x\n", @fooFunc)
if p_module()=>diskops_newOrLoadGame() if p_module()=>diskops_newOrLoadGame()
mapIs3D = q_mapIs3D mapIs3D = q_mapIs3D
mapNum = q_mapNum mapNum = q_mapNum
@ -2260,7 +2190,6 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Main code. // Main code.
// //
setLibVecs()
loadTitle() loadTitle()
startGame() startGame()
kbdLoop() kbdLoop()