Most animations working properly now.

This commit is contained in:
Martin Haye 2016-10-23 09:09:43 -07:00
parent 2ef692c537
commit ee16d7a0d6
4 changed files with 116 additions and 59 deletions

View File

@ -3470,8 +3470,8 @@ end
dbg("nFrames=${buffers.size()}") dbg("nFrames=${buffers.size()}")
outBuf.put((byte)flagByte) outBuf.put((byte)flagByte)
outBuf.put((byte)1) // used to store current anim dir; start with 1=forward outBuf.put((byte)1) // used to store current anim dir; start with 1=forward
outBuf.put((byte)0) // used to store current anim frame
outBuf.put((byte)(buffers.size())) // number of frames outBuf.put((byte)(buffers.size())) // number of frames
outBuf.put((byte)0) // used to store current anim frame
// Then each patch // Then each patch
buffers[1..-1].each { inBuf -> buffers[1..-1].each { inBuf ->

View File

@ -1746,7 +1746,7 @@ coalesce: !zone
ora tSegType,y ; and next seg ora tSegType,y ; and next seg
bne .next ; if either is active or has a type, can't combine bne .next ; if either is active or has a type, can't combine
; we can combine the next segment into this one. ; we can combine the next segment into this one.
!if DEBUG >= 2 { jsr .debug } !if DEBUG >= 3 { jsr .debug }
lda tSegLink,y lda tSegLink,y
sta tSegLink,x sta tSegLink,x
stx tmp stx tmp
@ -1756,7 +1756,7 @@ coalesce: !zone
tax ; to X reg index tax ; to X reg index
bne .loop ; non-zero = not end of chain - loop again bne .loop ; non-zero = not end of chain - loop again
.done rts .done rts
!if DEBUG >= 2 { !if DEBUG >= 3 {
.debug +prStr : !text "Coalesce ",0 .debug +prStr : !text "Coalesce ",0
pha pha
txa txa
@ -2351,9 +2351,9 @@ disk_finishLoad: !zone
!if DEBUG { jsr .debug2 } !if DEBUG { jsr .debug2 }
+callMLI MLI_SET_MARK, setMarkParams ; move the file pointer to the current block +callMLI MLI_SET_MARK, setMarkParams ; move the file pointer to the current block
bcs .prodosErr bcs .prodosErr
!if DEBUG >= 2 { +prStr : !text "Deco.",0 } !if DEBUG >= 3 { +prStr : !text "Deco.",0 }
jsr lz4Decompress ; decompress (or copy if uncompressed) jsr lz4Decompress ; decompress (or copy if uncompressed)
!if DEBUG >= 2 { +prStr : !text "Done.",0 } !if DEBUG >= 3 { +prStr : !text "Done.",0 }
.resume ldy .ysave .resume ldy .ysave
.next lda (pTmp),y ; lo byte of length .next lda (pTmp),y ; lo byte of length
clc clc
@ -2739,7 +2739,7 @@ nextSrcPage:
; Apply fixups to all modules that were loaded this round, and free the fixup ; Apply fixups to all modules that were loaded this round, and free the fixup
; resources from memory. ; resources from memory.
doAllFixups: !zone doAllFixups: !zone
!if DEBUG >= 2 { +prStr : !text "Doing all fixups.",0 } !if DEBUG >= 3 { +prStr : !text "Doing all fixups.",0 }
; Now scan aux mem for fixup segments ; Now scan aux mem for fixup segments
cli ; prevent interrupts while we mess around in aux mem cli ; prevent interrupts while we mess around in aux mem
ldx #1 ; start at first aux mem segment (0=main mem, 1=aux) ldx #1 ; start at first aux mem segment (0=main mem, 1=aux)
@ -2788,7 +2788,7 @@ doAllFixups: !zone
lda tSegAdrHi,x lda tSegAdrHi,x
sta .auxBase+1 sta .auxBase+1
!if DEBUG >= 2 { jsr .debug1 } !if DEBUG >= 3 { jsr .debug1 }
; Process the fixups ; Process the fixups
.proc jsr .fetchFixup ; get key byte .proc jsr .fetchFixup ; get key byte
@ -2807,7 +2807,7 @@ doAllFixups: !zone
and #$3F ; mask off the flags and #$3F ; mask off the flags
adc .mainBase+1 adc .mainBase+1
sta pDst+1 sta pDst+1
!if DEBUG >= 2 { jsr .debug2 } !if DEBUG >= 3 { jsr .debug2 }
clc clc
jsr .adMain ; recalc and store lo byte jsr .adMain ; recalc and store lo byte
iny iny
@ -2828,7 +2828,7 @@ doAllFixups: !zone
and #$3F ; mask off the flags and #$3F ; mask off the flags
adc .auxBase+1 adc .auxBase+1
sta pDst+1 sta pDst+1
!if DEBUG >= 2 { jsr .debug3 } !if DEBUG >= 3 { jsr .debug3 }
sta setAuxWr sta setAuxWr
jsr .adAux ; recalc and store lo byte jsr .adAux ; recalc and store lo byte
iny iny
@ -2861,7 +2861,7 @@ doAllFixups: !zone
cmp #$03 cmp #$03
bne .resume ; not a stub, resume scanning bne .resume ; not a stub, resume scanning
; found a stub, adjust it. ; found a stub, adjust it.
!if DEBUG >= 2 { jsr .debug4 } !if DEBUG >= 3 { jsr .debug4 }
clc clc
ldx #0 ldx #0
jsr .adStub jsr .adStub
@ -2893,7 +2893,7 @@ doAllFixups: !zone
bne + bne +
inc pSrc+1 ; hi byte too, if necessary inc pSrc+1 ; hi byte too, if necessary
+ rts + rts
!if DEBUG >= 2 { !if DEBUG >= 3 {
.debug1 +prStr : !text "Found fixup, res=",0 .debug1 +prStr : !text "Found fixup, res=",0
+prByte resNum +prByte resNum
+prStr : !text "mainBase=",0 +prStr : !text "mainBase=",0
@ -3003,7 +3003,8 @@ advanceAnims: !zone {
stx resType ; store direction-change stx resType ; store direction-change
sty resNum ; store frames-to-skip sty resNum ; store frames-to-skip
lda #0 lda #0
sta .ret+1 ; clear count of animated sta .ret1+1 ; clear count of animated resources found
sta .ret2+1 ; clear count of actual changes made
cli ; no interrupts while we read and write aux mem cli ; no interrupts while we read and write aux mem
ldx isAuxCmd ; grab starting segment for main or aux mem ldx isAuxCmd ; grab starting segment for main or aux mem
sta clrAuxRd,x ; read and sta clrAuxRd,x ; read and
@ -3024,24 +3025,23 @@ advanceAnims: !zone {
beq .next ; if zero, resource is not animated beq .next ; if zero, resource is not animated
txa ; save link number we're scanning txa ; save link number we're scanning
pha pha
inc .ret+1 ; mark the fact that we do have animated resources inc .ret1+1 ; mark the fact that we do have animated resources
jsr advSingleAnim ; do the work to advance this one resource jsr advSingleAnim ; do the work to advance this one resource
pla ; restore link number we're scanning pla ; restore link number we're scanning
tax tax
.next lda tSegLink,x ; next in chain .next lda tSegLink,x ; next in chain
tax ; to X reg index tax ; to X reg index
bne .loop ; non-zero = not end of chain - loop again bne .loop ; non-zero = not end of chain - loop again
.ret ldx #0 ; return count of number anim resources found (self-modified above) .ret1 ldx #0 ; return count of number anim resources found (self-modified above)
ldy #0 ; (hi byte of return - always zero) .ret2 ldy #0 ; return count of number we actually changed
sta clrAuxRd ; read and sta clrAuxRd ; read and
sta clrAuxWr ; write main mem sta clrAuxWr ; write main mem
sei ; allow interrupts again now that we're done with aux mem sei ; allow interrupts again now that we're done with aux mem
rts rts
}
; Advance a single animated resource. On entry: ; Advance a single animated resource. On entry:
; pTmp -> base (2-byte offset followed by main image data) ; pTmp -> base (2-byte offset followed by main image data)
advSingleAnim: !zone { advSingleAnim:
ldy #0 ldy #0
lda (pTmp),y ; grab offset lda (pTmp),y ; grab offset
clc clc
@ -3052,15 +3052,19 @@ advSingleAnim: !zone {
adc pTmp+1 adc pTmp+1
sta tmp+1 sta tmp+1
sta clrAuxRd iny ; now y=2, index number of frames
brk lda (tmp),y
adc #$FF ; minus one to get last frame (carry clear from prev add)
jsr applyPatch ; unpatch to get back to base frame data sta checksum+1 ; save it for later reference
iny ; now y=3, index current frame number
lda (tmp),y
sta checksum ; save it for comparison later
!if DEBUG = 2 { jsr .dbgB1 }
.chkr ldy #0 .chkr ldy #0
lda (tmp),y ; get animation type (1=Forward, 2=Forward/Backward, 3=Random) lda (tmp),y ; get animation type (1=Forward, 2=Forward/Backward, 3=Forward+Stop, 4=Random)
cmp #3 ; is it random? cmp #4 ; is it random?
bne .chkfb bne .chkfs
ldx resNum ; number of frames to skip ldx resNum ; number of frames to skip
- cpx #0 - cpx #0
beq .doptch ; if zero, done skipping beq .doptch ; if zero, done skipping
@ -3069,45 +3073,85 @@ advSingleAnim: !zone {
dex ; loop for... dex ; loop for...
jmp - ; ...specified number of skips jmp - ; ...specified number of skips
.chkfb iny ; index of current dir .chkfs iny ; index of current dir
cmp #2 ; is it a forward+backward anim? cmp #3 ; is it a forward+stop anim?
bne .setdir bne .chkfb
lda checksum ; compare cur frame
eor checksum+1 ; to (nFrames-1)
bne .adv ; if not there yet, advance.
rts ; we're at last frame; nothing left to do.
.chkfb cmp #2 ; is it a forward+backward anim?
bne .adv
lda resType ; get change to dir lda resType ; get change to dir
beq .adv ; not changing? just advance beq .adv ; not changing? just advance
.setdir lda #0 ; invert current dir (1->FF, or FF->1) .switch lda #0 ; invert current dir (1->FF, or FF->1)
sec sec
sbc (pTmp),y sbc (tmp),y
sta (pTmp),y ; store new dir sta (tmp),y ; store new dir
.adv lda (pTmp),y ; get current dir .adv lda (tmp),y ; get current dir
jsr .fwbk ; advance the frame number in that direction jsr .fwbk ; advance the frame number in that direction
.doptch jmp applyPatch ; apply patch for the new frame .doptch ldy #3 ; index current frame
lda (tmp),y
cmp checksum ; compare to what it was
bne + ; if not equal, we have work to do
rts ; no change, all done.
+ inc .ret2+1 ; advance count of number of things we actually changed
pha
lda checksum
jsr applyPatch ; un-patch old frame
pla
jmp applyPatch ; apply patch for the new frame
.fwbk ldy #3 ; index of current frame number .fwbk ldy #3 ; index of current frame number
clc clc
adc (tmp),y ; advance in direction adc (tmp),y ; advance in direction
dey ; index of number of frames dey ; index of number of frames
bcc + ; carry can only be set if dir=-1 and we wrapped around cmp #0
lda (tmp),y ; get number of frames bpl + ; can only be negative if dir=-1 and we wrapped around
sbc #1 ; minus one (we know carry is already set) lda checksum+1 ; go to (previously saved) last frame number
+ cmp (tmp),y ; are we at the limit of number of frames? + cmp (tmp),y ; are we at the limit of number of frames?
bne + bne +
lda #0 ; back to start lda #0 ; back to start
+ iny ; index of current frame number + iny ; index of current frame number
sta (tmp),y ; and store it sta (tmp),y ; and store it
!if DEBUG = 2 { jsr .dbgB2 }
rts rts
!if DEBUG = 2 {
.dbgin sta clrAuxRd
sta clrAuxWr
bit $c051
rts
.dbgout +crout
+waitKey
sta setAuxRd
sta setAuxWr
rts
.dbgB1 jsr .dbgin
+prStr : !text "single ",0
+prWord pTmp
+prWord tmp
+prByte checksum
+prByte checksum+1
jmp .dbgout
.dbgB2 jsr .dbgin
+prStr : !text "fwbk ",0
+prA
jmp .dbgout
} }
; Patch (or un-patch) an entry. On entry: ; Patch (or un-patch) an entry. On entry:
; pTmp -> offset just before main image ; A-reg - patch number to apply
; tmp -> anim hdr ; pTmp - offset just before main image
; tmp - anim hdr
; Those pointers are unmodified by this routine. ; Those pointers are unmodified by this routine.
applyPatch: !zone { applyPatch:
ldy #3 ; get current frame number tax ; patch zero?
lda (tmp),y beq .done ; if so, nothing to do
bne + sta reqLen ; index of patch number to find
.done rts ; if frame zero, nothing to do !if DEBUG = 2 { jsr .dbgC1 }
+ sta reqLen ; index of patch number to find
ldx #3 ldx #3
- lda tmp,x ; copy pointers to load/store data: tmp->pSrc, pTmp->pDst - lda tmp,x ; copy pointers to load/store data: tmp->pSrc, pTmp->pDst
@ -3121,7 +3165,9 @@ applyPatch: !zone {
jsr .srcadd jsr .srcadd
; loop to skip patches until we find the right one ; loop to skip patches until we find the right one
- ldy #0 - dec reqLen ; it starts at 1, which means first patch.
beq +
ldy #0
lda (pSrc),y ; low byte of patch len lda (pSrc),y ; low byte of patch len
pha ; save it pha ; save it
iny iny
@ -3130,8 +3176,8 @@ applyPatch: !zone {
jsr .ptradd ; skip by # pages in patch jsr .ptradd ; skip by # pages in patch
pla pla
jsr .srcadd ; skip pSrc past last partial page in patch jsr .srcadd ; skip pSrc past last partial page in patch
dec reqLen ; count and loop jmp -
bne - +
; pSrc now points at the patch to apply ; pSrc now points at the patch to apply
; pDst now points at the base data to modify ; pDst now points at the base data to modify
@ -3162,13 +3208,13 @@ applyPatch: !zone {
.ldsrc ldy #0 .ldsrc ldy #0
lda (pSrc),y ; pointer is self-modified lda (pSrc),y ; pointer is self-modified
inc pSrc inc pSrc
bne + bne .done
inc pSrc+1 inc pSrc+1
+ rts .done rts
; routine with two entry points; advances either pSrc or pDst ; routine with two entry points; advances either pSrc or pDst
.srcadd ldx #pSrc ; advance pSrc by A-reg bytes .srcadd ldx #pSrc ; advance pSrc by A-reg bytes
bne + ; always taken bne .ptradd ; always taken
.dstadd ldx #pDst ; advance pDst by A-reg bytes .dstadd ldx #pDst ; advance pDst by A-reg bytes
.ptradd clc .ptradd clc
adc 0,x adc 0,x
@ -3176,7 +3222,14 @@ applyPatch: !zone {
bcc + bcc +
inc 1,x inc 1,x
+ rts + rts
}
!if DEBUG = 2 {
.dbgC1 jsr .dbgin
+prStr : !text "apply ",0
+prByte reqLen
jmp .dbgout
} ; end of debug
} ; end of zone
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; Segment tables ; Segment tables

View File

@ -284,14 +284,15 @@ ADVANCE_ANIMS = $1C
; Y-reg - number of frames to skip. ; Y-reg - number of frames to skip.
; Only applied to resources marked as "random" order. ; Only applied to resources marked as "random" order.
; ;
; Output: Number of animated resources found. ; Output: X-reg - number of animated resources found.
; Y-reg - number actually changed.
; ;
; Checks for and advances each active animated resource to its next ; Checks for and advances each active animated resource to its next
; frame of animation. They are advanced based on their animation type: ; frame of animation. They are advanced based on their animation type:
; 1=Forward - e.g. 0 1 2 0 1 2 0 1 2 ; 1=Forward - e.g. 0 1 2 3, 0 1 2 3, 0 1 2...
; 2=Forward+Backward - e.g. 0 1 2 1 0 1 2 1 0 ; 2=Forward+Backward - e.g. 0 1 2 3 2 1, 0 1 2 3 2 1...
; 3=Forward+Stop - e.g. 0 1 2 2 2 2 2 2 2 ; 3=Forward+Stop - e.g. 0 1 2 3 3 3 3 3 3 3 3 3...
; 4=Random - e.g. 0 2 0 1 2 2 0 1 1 ; 4=Random - e.g. 0 3 2 0 1 3 2 2 3 0 1 1...
; ;
; Note that only animated resources in the specified memory bank (aux ; Note that only animated resources in the specified memory bank (aux
; or main) are processed. ; or main) are processed.

View File

@ -69,7 +69,7 @@ byte skipEncounterCheck = FALSE
word skyNum = 9 word skyNum = 9
word groundNum = 10 word groundNum = 10
byte portraitNum = 0 byte portraitNum = 1
word triggerOriginX, triggerOriginY word triggerOriginX, triggerOriginY
word triggerTbl word triggerTbl
@ -1697,6 +1697,7 @@ end
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// Advance to next frame of current animation, if any // Advance to next frame of current animation, if any
def nextAnimFrame() def nextAnimFrame()
word flags
if !curPortrait or !anyAnims; return; fin if !curPortrait or !anyAnims; return; fin
// Choose a new direction based on the flags. Do this the first time, and once every 3-7 frames. // Choose a new direction based on the flags. Do this the first time, and once every 3-7 frames.
@ -1708,10 +1709,12 @@ def nextAnimFrame()
// Advance animations. // Advance animations.
// First part is whether to switch directions on fwd/back anims. // First part is whether to switch directions on fwd/back anims.
// Second part is how many frames to advance random anims. // Second part is how many frames to advance random anims.
if auxMmgr(ADVANCE_ANIMS, animDirCt==0 | (rand16() % 5)) flags = auxMmgr(ADVANCE_ANIMS, (animDirCt==0) | (((rand16() % 10)+1)<<8))
// Animation is present - display the new frame if (flags >> 8)
// An animation was changed -- display it
showAnimFrame() showAnimFrame()
else elsif (flags & $FF) == 0
// No animations in memory; turn off future checking
anyAnims = FALSE anyAnims = FALSE
fin fin