More work on 2D script triggers.

This commit is contained in:
Martin Haye 2015-03-03 09:03:22 -08:00
parent 152fa2bd8b
commit 315c6b6936
4 changed files with 96 additions and 39 deletions

View File

@ -32,7 +32,7 @@
<!-- Build sub-projects --> <!-- Build sub-projects -->
<echo>Building core.</echo> <echo>Building core.</echo>
<ant dir="${src.dir}/core" target="build" useNativeBasedir="true" inheritAll="false"/> <ant dir="${src.dir}/core" target="build" useNativeBasedir="true" inheritAll="false"/>
<echo>Building PLASMA.</echo> <echo>Building game loop.</echo>
<ant dir="${src.dir}/plasma" target="build" useNativeBasedir="true" inheritAll="false"/> <ant dir="${src.dir}/plasma" target="build" useNativeBasedir="true" inheritAll="false"/>
<echo>Building raycast.</echo> <echo>Building raycast.</echo>
<ant dir="${src.dir}/raycast" target="build" useNativeBasedir="true" inheritAll="false"/> <ant dir="${src.dir}/raycast" target="build" useNativeBasedir="true" inheritAll="false"/>

View File

@ -88,7 +88,7 @@ partFileRef: !byte 0
fixupHint: !word 0 fixupHint: !word 0
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
!source "../include/debug.i" !if DEBUG { !source "../include/debug.i" }
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
grabSegment: !zone grabSegment: !zone
@ -238,9 +238,11 @@ main_dispatch: !zone
+ cmp #FREE_MEMORY + cmp #FREE_MEMORY
bne + bne +
jmp main_free jmp main_free
!if DEBUG {
+ cmp #DEBUG_MEM + cmp #DEBUG_MEM
bne + bne +
jmp main_debug jmp main_debug
}
+ cmp #CALC_FREE + cmp #CALC_FREE
bne shared_dispatch bne shared_dispatch
jmp main_calcFree jmp main_calcFree
@ -276,9 +278,11 @@ aux_dispatch: !zone
+ cmp #FREE_MEMORY + cmp #FREE_MEMORY
bne + bne +
jmp aux_free jmp aux_free
!if DEBUG {
+ cmp #DEBUG_MEM + cmp #DEBUG_MEM
bne + bne +
jmp aux_debug jmp aux_debug
}
+ cmp #CALC_FREE + cmp #CALC_FREE
bne + bne +
jmp aux_calcFree jmp aux_calcFree
@ -287,7 +291,7 @@ aux_dispatch: !zone
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Sanity check mode ; Sanity check mode
!if SANITY_CHECK { !if SANITY_CHECK {
saneStart: !zone saneStart: !zone {
pha pha
tya tya
pha pha
@ -298,23 +302,33 @@ saneStart: !zone
tax tax
pla pla
tay tay
+prChr 'M'+$80 +prChr 'M'
pla : pha : +prA pla : pha : +prA
+prX : +prY +prX : +prY
pla pla
rts rts
}
saneCheck: !zone saneCheck: !zone {
rts lda $BF00
cmp #$4C
beq +
brk
+ lda $E1
cmp #$BE
bcc +
brk
+ rts
}
saneEnd: !zone saneEnd: !zone {
pha pha
tya tya
pha pha
txa txa
pha pha
jsr saneCheck jsr saneCheck
+prChr 'm'+$80 +prChr 'm'
+crout +crout
pla pla
tax tax
@ -323,6 +337,7 @@ saneEnd: !zone
pla pla
rts rts
} }
}
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Print fatal error message (custom or predefined) and print the ; Print fatal error message (custom or predefined) and print the
@ -397,7 +412,13 @@ fatalError: !zone
init: !zone init: !zone
; put something interesting on the screen :) ; put something interesting on the screen :)
jsr home jsr home
+prStr : !text "Welcome to MythOS.",0 ldx #0
- lda .welcomeStr,x
beq +
jsr cout
inx
bne -
+
; close all files ; close all files
lda #0 lda #0
jsr closeFile jsr closeFile
@ -489,14 +510,20 @@ init: !zone
cpy #MAX_SEGS ; did all segments yet? cpy #MAX_SEGS ; did all segments yet?
bne .loop ; no, loop again bne .loop ; no, loop again
; Allocate space for the PLASMA frame stack ; Allocate space for the PLASMA frame stack
!if SANITY_CHECK {
lda #$20
sta framePtr+1 ; because sanity check verifies it's not $BE or $BF
}
ldx #0 ldx #0
ldy #2 ; 2 pages ldy #2 ; 2 pages
lda #REQUEST_MEMORY lda #REQUEST_MEMORY
jsr mainLoader jsr mainLoader
stx framePtr stx framePtr
stx outerFramePtr
iny ; twice for 2 pages: initial pointer at top of new space iny ; twice for 2 pages: initial pointer at top of new space
iny iny
sty framePtr+1 sty framePtr+1
sty outerFramePtr+1
dey dey
dey dey
lda #LOCK_MEMORY ; lock it in place forever lda #LOCK_MEMORY ; lock it in place forever
@ -518,8 +545,10 @@ init: !zone
jsr mainLoader jsr mainLoader
ldx #$10 ; initial eval stack index ldx #$10 ; initial eval stack index
.gomod: jmp $1111 ; jump to module for further bootstrapping .gomod: jmp $1111 ; jump to module for further bootstrapping
.welcomeStr !text "Welcome to MythOS.",$8D,0
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
!if DEBUG {
printMem: !zone printMem: !zone
jsr main_debug jsr main_debug
jmp aux_debug jmp aux_debug
@ -561,6 +590,7 @@ aux_debug:
jsr cout jsr cout
txa txa
jmp prbyte jmp prbyte
}
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
reset: !zone reset: !zone

View File

@ -2,3 +2,4 @@
evalStkL = $C0 evalStkL = $C0
evalStkH = $D0 evalStkH = $D0
framePtr = $E0 framePtr = $E0
outerFramePtr = $E2

View File

@ -98,10 +98,6 @@ const wndbtm = $73 // bottom+1 of text window
const cursh = $74 // Cursor H-pos 0-39 const cursh = $74 // Cursor H-pos 0-39
const cursv = $75 // Cursor V-pos 0-23 const cursv = $75 // Cursor V-pos 0-23
///////////////////////////////////////////////////////////////////////////////////////////////////
// Strings.
byte helloStr[] = "Loading Lawless Legends.\n"
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Global variables // Global variables
byte mapNum = OVERMAP_NUM byte mapNum = OVERMAP_NUM
@ -121,7 +117,7 @@ byte cacheSky, cacheGround
word cacheX, cacheY word cacheX, cacheY
byte cacheDir byte cacheDir
byte resetLocFromCache = FALSE byte resetLocFromCache = FALSE
byte anyText = FALSE byte textDrawn = FALSE
// 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
@ -448,6 +444,14 @@ asm goMon
jmp $FF69 jmp $FF69
end end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Jump straight to the system monitor
// Params: None
asm brk
bit setROM
brk
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
@ -470,9 +474,6 @@ asm displayStr
bit setROM bit setROM
txa txa
pha pha
; record that text was drawn - for clear window on next script phase
lda #1
sta textDrawn
lda evalStkL,x lda evalStkL,x
sta pTmp sta pTmp
lda evalStkH,x lda evalStkH,x
@ -569,6 +570,9 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Is there a script attached to the player's current position? // Is there a script attached to the player's current position?
def isScripted() def isScripted()
puts("avatarTile=")
printHex(^avatarTile)
crout()
return ^avatarTile & $20 return ^avatarTile & $20
end end
@ -700,7 +704,7 @@ def initMap3D()
// Initialize the map scripts // Initialize the map scripts
setWindow2() setWindow2()
clearWindow() clearWindow()
anyText = FALSE textDrawn = FALSE
prevX = -1 prevX = -1
prevY = -1 prevY = -1
@ -760,16 +764,17 @@ def initMap2D()
// Start up the font engine // Start up the font engine
initFontEngine(pFont) initFontEngine(pFont)
// Start up the tile engine
initDisplayEngine(mapNum)
// For now // For now
prevX = -1 prevX = -1
prevY = -1 prevY = -1
triggerTbl = NULL triggerTbl = NULL
prevMapNum = mapNum prevMapNum = mapNum
prevMapIs3D = mapIs3D prevMapIs3D = mapIs3D
pScripts = NULL
// Start up the tile engine
initDisplayEngine(mapNum)
// And do the first draw.
renderFrame() renderFrame()
redraw = FALSE redraw = FALSE
end end
@ -832,15 +837,17 @@ def callScripts(x, y)
word p word p
word pNext word pNext
word script word script
printHex($1001) puts("callScripts: x=")
printHex(x) printHex(x)
crout() crout()
p = triggerTbl p = triggerTbl
while TRUE while TRUE
printHex($1002) ^$c051
puts("y loop, p=")
printHex(p) printHex(p)
puts("^p=")
printHex(^p) printHex(^p)
crout() crout()
getUpperKey getUpperKey
@ -848,22 +855,33 @@ def callScripts(x, y)
if ^p == $FF if ^p == $FF
return return
fin fin
pNext = p + p.1 pNext = p + p->1
puts("p->1=")
printHex(p->1)
crout()
puts("pNext=")
printHex(pNext)
crout()
if ^p == y if ^p == y
p = p + 2
while p < pNext while p < pNext
printHex($1003) puts(" x loop, p=")
printHex(p) printHex(p)
puts("^p=")
printHex(^p) printHex(^p)
puts("x=")
printHex(x)
crout() crout()
if ^p == x if x == ^p
script = p:1 script = p->>x
printHex($1004) puts(" script=")
printHex(script) printHex(script)
crout() crout()
*script *script
fin fin
p = p + 3 p = p + 3
getUpperKey
loop loop
fin fin
p = pNext p = pNext
@ -875,6 +893,9 @@ end
def checkScripts() def checkScripts()
word x word x
word y word y
puts("checkScripts: triggerTbl=")
printHex(triggerTbl)
crout()
if !triggerTbl if !triggerTbl
return return
fin fin
@ -885,17 +906,20 @@ def checkScripts()
x = ^avatarX x = ^avatarX
y = ^avatarY y = ^avatarY
fin fin
puts("x=")
printHex(x)
puts(", y=")
printHex(y)
crout()
if x <> prevX or y <> prevY if x <> prevX or y <> prevY
prevX = x prevX = x
prevY = y prevY = y
if anyText if textDrawn
clearWindow() clearWindow()
anyText = FALSE textDrawn = FALSE
fin fin
if isScripted() if isScripted()
textDrawn = FALSE
callScripts(x, y) callScripts(x, y)
anyText = ^textDrawn
fin fin
fin fin
if (mapNum <> prevMapNum) or (mapIs3D <> prevMapIs3D) if (mapNum <> prevMapNum) or (mapIs3D <> prevMapIs3D)
@ -1018,7 +1042,7 @@ def teleport(x, y, dir)
prevX = x prevX = x
prevY = y prevY = y
clearWindow() clearWindow()
anyText = FALSE textDrawn = FALSE
^playerDir = dir ^playerDir = dir
redraw = TRUE redraw = TRUE
end end
@ -1056,7 +1080,7 @@ 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) def scriptDisplayStr(str)
anyText = TRUE textDrawn = TRUE
displayStr(str) displayStr(str)
end end
@ -1070,7 +1094,7 @@ def getYN()
return 1 return 1
elsif key == 'N' elsif key == 'N'
clearWindow() clearWindow()
anyText = FALSE textDrawn = FALSE
return 0 return 0
fin fin
beep() beep()
@ -1119,14 +1143,16 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Load and display the title screen. // Load and display the title screen.
def loadTitle() def loadTitle()
puts(@helloStr) puts("Loading Lawless Legends.\n")
// Load the title screen // Load the title screen
puts("Loading title screen.\n")
loader(SET_MEM_TARGET, MAIN_MEM, $2000) loader(SET_MEM_TARGET, MAIN_MEM, $2000)
loader(QUEUE_LOAD, MAIN_MEM, 1<<8 | RES_TYPE_SCREEN) // title screen is fixed at #1 loader(QUEUE_LOAD, MAIN_MEM, 1<<8 | RES_TYPE_SCREEN) // title screen is fixed at #1
loader(LOCK_MEMORY, MAIN_MEM, $2000) loader(LOCK_MEMORY, MAIN_MEM, $2000)
loader(FINISH_LOAD, MAIN_MEM, 1) // 1 = keep open loader(FINISH_LOAD, MAIN_MEM, 1) // 1 = keep open
titleLoaded = TRUE titleLoaded = TRUE
puts("Title loaded.\n")
^$c050 ^$c050
^$c057 ^$c057
^$c054 ^$c054