Now loading scripts for 2D maps, and registering the new trigger table.

This commit is contained in:
Martin Haye 2015-02-23 08:01:47 -08:00
parent 3376930f85
commit abd63d0481
3 changed files with 132 additions and 84 deletions

View File

@ -785,13 +785,17 @@ class PackPartitions
{
if (!mapEl.scripts)
return [0, [] as Set]
ScriptModule module = new ScriptModule()
if (!module.packScripts(mapEl.scripts[0], xRange, yRange))
return [0, [] as Set]
def num = modules.size() + 1
def name = "mapScript$num"
println "Packing scripts for map $mapName, to module $num."
ScriptModule module = new ScriptModule()
if (!module.packScripts(mapEl.scripts[0], xRange, yRange)) {
println "...no scripts applied; will re-use module num"
return [0, [] as Set]
}
modules[name] = [num:num, buf:wrapByteList(module.data)]
bytecodes[name] = [num:num, buf:wrapByteList(module.bytecode)]
fixups[name] = [num:num, buf:wrapByteList(module.fixups)]

View File

@ -957,14 +957,9 @@ end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Associate a location with a trigger function (i.e. a script)
def setLocationTrigger(x, y, func)
if nLocTrig == MAX_LOC_TRIG
fatal(@tooManyTriggers)
fin
locTrig_x[nLocTrig] = x
locTrig_y[nLocTrig] = y
locTrig_func[nLocTrig] = func
nLocTrig = nLocTrig + 1
def setLocationTrigger(tbl)
printHex($1001)
printHex(tbl)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -1008,34 +1003,6 @@ def initCmds3D()
initCmd('Y', @nextSky)
initCmd('G', @nextGround)
// $300
callbacks.0 = $4c
callbacks:1 = @setLocationTrigger
// $303
callbacks.3 = $4c
callbacks:4 = @displayStr
// $306
callbacks.6 = $4c
callbacks:7 = @getYN
// $309
callbacks.9 = $4c
callbacks:10 = @setMap
// $30C
callbacks.12 = $4c
callbacks:13 = @setSky
// $30F
callbacks.15 = $4c
callbacks:16 = @setGround
// $312
callbacks.18 = $4c
callbacks:19 = @teleport
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -1071,10 +1038,44 @@ def loadTitle()
^$C05F // disable double-hi-res
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Set vectors so that scripts in PLASMA can call back to do things with this engine.
def setCallbacks()
// $300
callbacks.0 = $4c
callbacks:1 = @setLocationTrigger
// $303
callbacks.3 = $4c
callbacks:4 = @displayStr
// $306
callbacks.6 = $4c
callbacks:7 = @getYN
// $309
callbacks.9 = $4c
callbacks:10 = @setMap
// $30C
callbacks.12 = $4c
callbacks:13 = @setSky
// $30F
callbacks.15 = $4c
callbacks:16 = @setGround
// $312
callbacks.18 = $4c
callbacks:19 = @teleport
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Main code.
//
loadTitle()
setCallbacks()
initMap()
setWindow2()
kbdLoop()

View File

@ -12,7 +12,7 @@
!source "../include/mem.i"
!source "../include/plasma.i"
DEBUG = 0 ; 1=some logging, 2=lots of logging
DEBUG = 1 ; 1=some logging, 2=lots of logging
HEADER_LENGTH=6
SECTION_WIDTH=22
@ -77,6 +77,9 @@ Y_COUNTER = $67 ; Loop counter used during drawing
Y_LOC = $68 ; Current row being drawn (between 0 and VIEWPORT_WIDTH)
ROW_LOCATION = $69 ; Used for pointing at row offset in map data
TILE_SOURCE = $6D ; Location of tile data
SCRIPTS_LOC = $9A ; Location of script module
AVATAR_SECTION = $9C ; Location of section data the avatar is within
AVATAR_TILE = $9E ; Tile map entry under the avatar
;----------------------------------------------------------------------
; Vectors used to call in from the outside.
@ -134,16 +137,6 @@ LOAD_SECTION
STY ptr+1
}
;----------------------------------------------------------------------
; >> FINISH LOADING MAP SECTIONS
FINISH_MAP_LOAD
LDA #FINISH_LOAD
JMP mainLoader
!macro finishLoad keepOpen {
LDX #keepOpen ; 1 to keep open for next load, 0 for close so you can flip to HGR page 2
JSR FINISH_MAP_LOAD
}
;----------------------------------------------------------------------
; >> RELEASE MAP SECTION OR TILESET
!macro freeResource ptr {
@ -155,6 +148,7 @@ FINISH_MAP_LOAD
JSR mainLoader
+
}
;----------------------------------------------------------------------
; >> LOAD TILES
; Load tile resource (A = Resource ID)
@ -259,6 +253,61 @@ LOAD_ALL_TILES
JSR LOAD_ALL_TILES
}
FREE_SCRIPTS
+freeResource SCRIPTS_LOC
RTS
!macro freeScripts {
JSR FREE_SCRIPTS
}
!zone
LOAD_SCRIPTS
JSR CALC ; determine which map avatar is on
LDY #5
LDA (AVATAR_SECTION),Y
BNE .got
LDA #0
STA SCRIPTS_LOC
STA SCRIPTS_LOC+1
RTS
.got TAY ; resource # in Y
!if DEBUG {
+prStr : !text "loadScripts ",0
+prY
}
LDX #RES_TYPE_MODULE
LDA #QUEUE_LOAD
JSR mainLoader
!if DEBUG {
+prStr : !text "-> ",0
+prYX
+crout
}
STX SCRIPTS_LOC
STY SCRIPTS_LOC+1
RTS
!macro loadScripts {
JSR LOAD_SCRIPTS
}
!macro finishLoad keepOpen {
LDX #keepOpen ; 1 to keep open for next load, 0 for close so you can flip to HGR page 2
LDA #FINISH_LOAD
JSR mainLoader
}
FINISH_MAP_LOAD
+finishLoad 1 ; keep open for further loading
+loadAllTiles
+loadScripts
+finishLoad 0 ; all done
LDA SCRIPTS_LOC+1 ; are there scripts?
BNE .scr ; yes, go init them
RTS ; no, we're done
.scr JMP (SCRIPTS_LOC) ; the init function is always first in the script module
; >> CHECK CROSSINGS
!zone
CROSS
@ -295,6 +344,7 @@ CROSS_NORTH
TXA
PHA
+freeAllTiles
+freeScripts
+freeResource SW_MAP_LOC
+freeResource SE_MAP_LOC
LDA REL_Y
@ -314,12 +364,10 @@ CROSS_NORTH
PLA
STA NE_MAP_ID
+loadSection NE_MAP_LOC
+finishLoad 1 ; keep open for further loading
+loadAllTiles
+finishLoad 0 ; all done
RTS
JMP FINISH_MAP_LOAD
.noMap INC REL_Y
RTS
;----------------------------------------------------------------------
; >> CROSS EAST BOUNDARY (Load next section to the east)
!zone
@ -358,10 +406,7 @@ CROSS_EAST
PLA
STA SE_MAP_ID
+loadSection SE_MAP_LOC
+finishLoad 1 ; keep open for further loading
+loadAllTiles
+finishLoad 0 ; all done
RTS
jmp FINISH_MAP_LOAD
.noMap DEC REL_X
RTS
;----------------------------------------------------------------------
@ -402,10 +447,7 @@ CROSS_SOUTH
PLA
STA SE_MAP_ID
+loadSection SE_MAP_LOC
+finishLoad 1 ; keep open for further loading
+loadAllTiles
+finishLoad 0 ; all done
RTS
jmp FINISH_MAP_LOAD
.noMap DEC REL_Y
RTS
;----------------------------------------------------------------------
@ -443,10 +485,7 @@ CROSS_WEST
PLA
STA SW_MAP_ID
+loadSection SW_MAP_LOC
+finishLoad 1 ; keep open for further loading
+loadAllTiles
+finishLoad 0 ; all done
RTS
jmp FINISH_MAP_LOAD
.noMap INC REL_X
RTS
;----------------------------------------------------------------------
@ -583,11 +622,6 @@ ROW_OFFSET = 3
BMI .noDraw ; skip if draw height is negative
BEQ .noDraw ; ...or zero
LDA CALC_MODE ; check the mode
BEQ + ; zero is normal (draw)
JMP FinishCalc ; nonzero is calc mode
+ ; drawing begins
!if DEBUG >= 2 {
+prStr : !text " DR_X_ST=",0
+prByte DRAW_X_START
@ -665,7 +699,7 @@ ROW_OFFSET = 3
STY ROW_LOCATION + 1
LDX DRAW_X_START
; Display row of tiles
.next_col
.draw_col
; Get tile
TXA
TAY
@ -675,12 +709,16 @@ ROW_OFFSET = 3
LDA Y_LOC
CMP #VIEWPORT_VERT_PAD
BNE .notAvatar
LDA (ROW_LOCATION),Y
STA AVATAR_TILE
LDA DRAW_SECTION
STA AVATAR_SECTION
LDA DRAW_SECTION + 1
STA AVATAR_SECTION + 1
LDY GLOBAL_TILESET_LOC
LDA GLOBAL_TILESET_LOC+1
BNE .store_src ; always taken
.notAvatar
LDA #0
STA TILE_SOURCE+1
LDA (ROW_LOCATION), Y
BNE .not_empty ; zero means empty tile
.empty
@ -688,10 +726,12 @@ ROW_OFFSET = 3
LDA #>emptyTile+1
BNE .store_src ; always taken
.not_empty
; Calculate location of tile data == tile_base + (((tile & 31) - 1) * 32)
LDY #0
STY TILE_SOURCE+1
AND #31
SEC
SBC #1 ; tile map is 1-based, tile set indexes are 0-based
; Calculate location of tile data == tile_base + ((tile & 31) * 32)
AND #31
ASL
ASL
ASL
@ -707,6 +747,11 @@ ROW_OFFSET = 3
.store_src
STY TILE_SOURCE
STA TILE_SOURCE+1
LDA CALC_MODE ; check the mode
BEQ .doneCalculatingTileLocation ; zero is normal mode (draw)
JMP .next_col ; non-zero is calc mode (so don't draw)
.doneCalculatingTileLocation
; Is there a NPC there?
; No, use map tile
@ -731,13 +776,13 @@ ROW_OFFSET = 3
INY ;11
}
}
DEC X_COUNTER
BEQ .next_row
TXA ; Outside the drawing part we need to put X back (divide by 2)
LSR
TAX
.next_col DEC X_COUNTER
BEQ .next_row
INX
JMP .next_col
JMP .draw_col
; Increment row
.next_row
DEC Y_COUNTER
@ -783,14 +828,12 @@ INIT
LDA (SW_MAP_LOC),Y
STA SE_MAP_ID
+loadSection SE_MAP_LOC
+ +finishLoad 1 ; keep open for further loading
+loadAllTiles
+finishLoad 0 ; all done
; set up the X and Y coordinates
+ ; set up the starting X and Y coordinates
LDX #VIEWPORT_HORIZ_PAD
LDY #VIEWPORT_VERT_PAD
JSR SET_XY
RTS
; load tilesets and scripts
JMP FINISH_MAP_LOAD
tblHGRl
!byte $00,$80,$00,$80,$00,$80,$00,$80