Really running scripts on the map now.

This commit is contained in:
Martin Haye 2014-07-08 19:11:03 -07:00
parent d06884c0e9
commit e56ad5e7da
3 changed files with 73 additions and 23 deletions

View File

@ -1191,9 +1191,11 @@ class ScriptModule
println " text: '$text'" println " text: '$text'"
emitCodeByte(0x26) // LA emitCodeByte(0x26) // LA
emitCodeFixup(addString(text) + ((nScripts+1)*5)) // offset to skip over stubs def textAddr = addString(text)
emitCodeFixup(textAddr)
emitCodeByte(0x54) // CALL emitCodeByte(0x54) // CALL
emitCodeWord(vec_displayStr) emitCodeWord(vec_displayStr)
emitCodeByte(0x30) // DROP
} }
def makeInit(scripts) def makeInit(scripts)
@ -1203,16 +1205,17 @@ class ScriptModule
script.locationTrigger.each { trig -> script.locationTrigger.each { trig ->
def x = trig.@x.toInteger() def x = trig.@x.toInteger()
def y = trig.@y.toInteger() def y = trig.@y.toInteger()
emitCodeByte(0x26) // LA
emitCodeFixup((idx+1) * 5)
emitCodeByte(0x2A) // CB emitCodeByte(0x2A) // CB
assert x >= 0 && x < 255 assert x >= 0 && x < 255
emitCodeByte(x) emitCodeByte(x)
emitCodeByte(0x2A) // CB emitCodeByte(0x2A) // CB
assert y >= 0 && y < 255 assert y >= 0 && y < 255
emitCodeByte(y) emitCodeByte(y)
emitCodeByte(0x26) // LA
emitCodeFixup((idx+1) * 5)
emitCodeByte(0x54) // CALL emitCodeByte(0x54) // CALL
emitCodeWord(vec_locationTrigger) emitCodeWord(vec_locationTrigger)
emitCodeByte(0x30) // DROP
} }
} }
finishFunc() finishFunc()

View File

@ -19,7 +19,7 @@ MAX_SEGS = 96
DO_COMP_CHECKSUMS = 0 ; during compression debugging DO_COMP_CHECKSUMS = 0 ; during compression debugging
DEBUG_DECOMP = 0 DEBUG_DECOMP = 0
DEBUG = 1 DEBUG = 0
; Zero page temporary variables ; Zero page temporary variables
tmp = $2 ; len 2 tmp = $2 ; len 2
@ -1150,7 +1150,6 @@ disk_finishLoad: !zone
+ lda .nFixups ; any fixups encountered? + lda .nFixups ; any fixups encountered?
beq + beq +
jsr doAllFixups ; found fixups - execute and free them jsr doAllFixups ; found fixups - execute and free them
+prStr : !text "Fixups done.",0
+ rts + rts
.notEnd bmi .load ; hi bit set -> queued for load .notEnd bmi .load ; hi bit set -> queued for load
iny ; not set, not queued, so skip over it iny ; not set, not queued, so skip over it

View File

@ -53,11 +53,11 @@ const CALC_FREE = $19
const CHAIN_LOADER = $1E const CHAIN_LOADER = $1E
const FATAL_ERROR = $1F const FATAL_ERROR = $1F
const printVec = $300 const callbacks = $300
;================================================================================================== ;==================================================================================================
; Predefined functions, for circular calls ; Predefined functions, for circular calls
predef moveBackward predef moveBackward, setWindow2
;================================================================================================== ;==================================================================================================
; Raycaster variables ; Raycaster variables
@ -90,6 +90,12 @@ word pFont
word pMap word pMap
word pScripts word pScripts
word cmdTbl[64] word cmdTbl[64]
word nLocTrig = 0
word locTrig_x[30]
word locTrig_y[30]
word locTrig_func[30]
word prevX
word prevY
; Movement amounts when walking at each angle ; Movement amounts when walking at each angle
; Each entry consists of an X bump and a Y bump, in 8.8 fixed point ; Each entry consists of an X bump and a Y bump, in 8.8 fixed point
@ -200,7 +206,7 @@ end
asm crout asm crout
bit setROM bit setROM
jsr crout jsr crout
inx ; don't-care return value dex ; don't-care return value
bit setLcRW+lcBank2 bit setLcRW+lcBank2
rts rts
end end
@ -317,11 +323,24 @@ asm goMon
jmp $FF69 jmp $FF69
end end
asm clearWindow
bit setROM
txa
pha
jsr clearWINDOW
bit setLcRW+lcBank2
pla
tax
dex ; don't-care return value
rts
end
; Display a string using the font engine ; Display a string using the font engine
asm displayStr(str) asm displayStr ; (str)
txa txa
pha pha
bit setROM bit setROM
txa
ldy evalStkL,x ldy evalStkL,x
lda evalStkH,x lda evalStkH,x
tax tax
@ -366,25 +385,28 @@ def initMap()
; Load everything that we just queued ; Load everything that we just queued
loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open
; Load the scripts for this map
pScripts = loader(QUEUE_LOAD, MAIN_MEM, ((mapNum+$20)<<8) | RES_TYPE_MODULE)
loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open
; Start up the font engine ; Start up the font engine
initFontEngine(pFont) initFontEngine(pFont)
; Start up the raycaster ; Start up the raycaster
initRaycaster(pMap) initRaycaster(pMap)
; Load the scripts for this map
^$c051
pScripts = loader(QUEUE_LOAD, MAIN_MEM, ((mapNum+$20)<<8) | RES_TYPE_MODULE)
printHex(pScripts)
loader(FINISH_LOAD, MAIN_MEM, 1) ; 1 = keep open
; Set initial player position ; Set initial player position
^playerDir = 1 ^playerDir = 1
*playerX = $280 *playerX = $280
*playerY = $380 *playerY = $380
; Initialize the map scripts
setWindow2()
*pScripts()
prevX = -1
prevY = -1
; Draw the first frame ; Draw the first frame
printHex($BBCC)
renderFrame() renderFrame()
end end
@ -427,13 +449,36 @@ def initCmd(key, func)
cmdTbl[key-$20] = func cmdTbl[key-$20] = func
end end
def checkScript()
word x
word y
word i
word func
x = playerX.1 - 1
y = playerY.1 - 1
if x <> prevX or y <> prevY
prevX = x
prevY = y
clearWindow()
for i = 0 to nLocTrig-1
if x == locTrig_x[i] and y == locTrig_y[i]
func = locTrig_func[i]
*func()
fin
next
fin
end
def moveForward() def moveForward()
word wasBlocked word wasBlocked
word func
wasBlocked = isBlocked() wasBlocked = isBlocked()
*playerX = *playerX + walkDirs[^playerDir * 2] *playerX = *playerX + walkDirs[^playerDir * 2]
*playerY = *playerY + walkDirs[^playerDir * 2 + 1] *playerY = *playerY + walkDirs[^playerDir * 2 + 1]
if !wasBlocked and isBlocked() if !wasBlocked and isBlocked()
moveBackward() moveBackward()
else
checkScript()
fin fin
end end
@ -520,8 +565,11 @@ def kbdLoop()
loop loop
end end
def foofunc def setLocationTrigger(x, y, func)
puts(@loopStr) locTrig_x[nLocTrig] = x
locTrig_y[nLocTrig] = y
locTrig_func[nLocTrig] = func
nLocTrig = nLocTrig + 1
end end
;================================================================================================== ;==================================================================================================
@ -551,17 +599,17 @@ initCmd('N', @nextMap)
initCmd('Y', @nextSky) initCmd('Y', @nextSky)
initCmd('G', @nextGround) initCmd('G', @nextGround)
callbacks.0 = $4c
callbacks:1 = @setLocationTrigger
callbacks.3 = $4c
callbacks:4 = @displayStr
initMap() initMap()
setWindow2() setWindow2()
printVec.0 = $4c
printVec:1 = displayStr
; Main keyboard loop ; Main keyboard loop
puts(@loopStr) puts(@loopStr)
kbdLoop() kbdLoop()
goMon()
done done