More work on PLASMA loading.

This commit is contained in:
Martin Haye 2014-07-03 08:53:50 -07:00
parent 5334bca39c
commit 64c3c8298f
3 changed files with 157 additions and 60 deletions

View File

@ -1158,7 +1158,7 @@ disk_finishLoad: !zone
jsr closeFile
lda #0 ; zero out...
sta partFileRef ; ... the file reference so we know it's no longer open
+ lda nFixups ; any fixups encountered?
+ lda .nFixups ; any fixups encountered?
bne +
jsr doAllFixups ; found fixups - execute and free them
+ !if DEBUG { jsr printMem }
@ -1630,48 +1630,161 @@ setupDecomp:
; Apply fixups to all modules that were loaded this round, and free the fixup
; resources from memory.
doAllFixups: !zone
ldx #1 ; start at first aux mem segment (0=main mem, 1=aux)
.loop: lda tSegType,x ; grab flags & type
and #$F ; just type now
; copy the shadow code down to $100, so we can read aux mem bytes
ldx #.fixupShadow_end - .fixupShadow - 1
- lda .fixupShadow,x
sta .getFixupByte,x
dex
bpl -
; Now scan aux mem for fixup segments
ldx #1 ; start at first aux mem segment (0=main mem, 1=aux)
.loop: lda tSegType,x ; grab flags & type
and #$F ; just type now
cmp #RES_TYPE_FIXUP
bne .next
beq .found
.next: lda tSegLink,x ; next in chain
tax ; to X reg index
bne .loop ; non-zero = not end of chain - loop again
rts ; fail with X=0
.found ; Found one fixup seg.
lda tSegAdrLo,x ; grab its address
sta pSrc ; save to the accessor routine
lda tSegAdrHi,x ; hi byte too
sta pSrc+1
; Find the corresponding main-mem seg
stx .resume+1 ; save scan position so we can resume later
lda tSegRes,x ; get seg num for this fixup
sta resNum ; that's what we're looking for
lda #RES_TYPE_MODULE ; type module is in main mem
sta resType ; that's the type
lda #0 ; look in main mem
sta isAuxCmd
jsr scanForResource
bne + ; we better find it
brk
+ lda tSegAdrLo,x ; get the segment's address
sta .mainBase ; and save it
lda tSegAdrHi,x ; hi byte too
sta .mainBase+1
; Find the corresponding aux-mem seg
lda #RES_TYPE_BYTECODE ; it's of type bytecode
sta resType
inc isAuxCmd ; it'll be in aux mem
jsr scanForResource
bne + ; we better find it
brk
+ lda tSegAdrLo,x
sta .auxBase
lda tSegAdrHi,x
sta .auxBase+1
; Process the fixups
.proc jsr .fetchFixup ; get key byte
tay ; save it aside, and also check the hi bit
bmi .fxAux ; yes, it's aux mem fixup
.fxMain jsr .fetchFixup ; get the lo byte of the offset
clc
adc .mainBase
sta pDst
tya
adc .mainBase+1
sta pDst+1
ldy #0
clc
jsr .adMain
iny
jsr .adMain
bne .proc ; always taken
.adMain lda (pDst),y
adc .mainBase,y
sta (pDst),y
rts
.fxAux cmp #$FF ; end of fixups?
beq .resume ; if so, resume scanning
jsr .fetchFixup ; get lo byte of offset
clc
adc .auxBase
sta pDst
tya
and #$7F ; mask off the hi bit flag
adc .auxBase+1
sta pDst+1
ldy #0
sta setAuxWr
jsr .adAux
iny
jsr .adAux
sta clrAuxWr
bne .proc ; always taken
.adAux jsr .getBytecode
adc .mainBase,y
sta (pDst),y
rts
.resume ldx #11 ; self-modified earlier
; fix up the stubs
lda .mainBase
sta pDst
lda .mainBase+1
sta pDst+1
.stub ldy #0
lda (pDst),y
cmp #$20 ; stubs start with JSR $3xx
bne .estub
ldy #2
lda (pDst),y
cmp #3
bne .estub
clc
ldx #0
jsr .adStub
inx
jsr .adStub
lda pDst
clc
adc #5
sta pDst
bcc .stub
inc pDst+1
bne .stub ; always taken
.adStub iny
lda (pDst),y
adc .auxBase,x
sta (pDst),y
rts
.estub ; done with stubs
jmp .next ; go scan for more fixup blocks
.fetchFixup:
jsr .getFixupByte ; get a byte from aux mem
inc pSrc ; and advance the pointer
bne +
inc pSrc+1 ; hi byte too, if necessary
+ rts
lda pTmp ; compare pTmp
cmp tSegAdrLo,x ; to this seg addr
lda pTmp+1 ; including...
sbc tSegAdrHi,x ; ...hi byte
bcc .next ; if pTmp < seg addr then keep searching
lda pTmp ; compare pTmp
cmp tSegAdrLo,y ; to *next* seg addr
lda pTmp+1 ; including...
sbc tSegAdrHi,y ; ...hi byte
bcc .found ; if pTmp < next seg addr then perfect!
.next: lda tSegLink,x ; next in chain
tax ; to X reg index
bne .loop ; non-zero = not end of chain - loop again
rts ; fail with X=0
.fixupShadow:
!pseudopc $100 {
.getFixupByte:
sta setAuxRd
.fixupAddr = *+1
lda $1111
lda (pSrc),y
sta clrAuxRd
rts
.getBytecode:
sta setAuxRd
.bytecodeAddr = *+1
lda $1111
lda (pDst),y
sta clrAuxRd
rts
}
.fixupShadow_end = *
.mainBase !word 0
.auxBase !word 0
;------------------------------------------------------------------------------
; Segment tables
!if DEBUG { !align 255,0 }
!if DEBUG { !align 255,0 }
tSegLink = * : !fill MAX_SEGS
tSegType = * : !fill MAX_SEGS

View File

@ -6,6 +6,7 @@
TOP_LINE = $2180 ; 24 lines down from top
NLINES = 128
TEX_SIZE = $555 ; 32x32 + 16x16 + 8x8 + 4x4 + 2x2 + 1x1
PLASMA_FRAME_SIZE = $200
; Byte offset for each pixel in the blit unroll
BLIT_OFF0 = 5
@ -55,6 +56,7 @@ mapWidth = $62 ; len 1
mapHeight = $63 ; len 1
spriteX = $64 ; len 2
spriteY = $66 ; len 2
plasmaFrames = $68 ; len 2
; Sprite calculations zero page
bSgnSinT = $90
@ -87,24 +89,20 @@ expandVec = $800
;---------------------------------
; Main-mem tables and buffers
tableStart = $A000
decodeTo01 = $A000
decodeTo01b = $A100
decodeTo23 = $A200
decodeTo23b = $A300
decodeTo45 = $A400
decodeTo56 = $A500
decodeTo57 = $A600
clrBlitRollE = $A700 ; size 3*(128/2) = $C0, plus 2 for tya and rts
clrBlitRollO = $A7C2 ; size 3*(128/2) = $C0, plus 2 for tya and rts
texAddrLo = $A884
tableStart = $A700
decodeTo01 = $A700
decodeTo01b = $A800
decodeTo23 = $A900
decodeTo23b = $AA00
decodeTo45 = $AB00
decodeTo56 = $AC00
decodeTo57 = $AD00
clrBlitRollE = $AE00 ; size 3*(128/2) = $C0, plus 2 for tya and rts
clrBlitRollO = $AEC2 ; size 3*(128/2) = $C0, plus 2 for tya and rts
texAddrLo = $AF84
texAddrHi = texAddrLo + MAX_TEXTURES
blitRoll = $A900 ; Unrolled blitting code. Size 29*128 = $E80, plus 1 for rts
tableEnd = $B781
plasmaCode = $B800
plasmaFrames = $BD00
plasmaEnd = $BF00
blitRoll = $B000 ; Unrolled blitting code. Size 29*128 = $E80, plus 1 for rts
tableEnd = $BE81
; mipmap level offsets
MIP_OFFSET_0 = 0

View File

@ -13,7 +13,7 @@ start:
; Conditional assembly flags
DOUBLE_BUFFER = 1 ; whether to double-buffer
DEBUG = 1 ; 1=some logging, 2=lots of logging
DEBUG = 0 ; 1=some logging, 2=lots of logging
DEBUG_COLUMN = -1
; temporary hack to try blocker sprites
@ -1568,14 +1568,12 @@ initMem: !zone
ldy #>(tableEnd-tableStart)
jsr mainLoader
; Reserve memory for the PLASMA frame stack
lda #SET_MEM_TARGET
ldx #<plasmaFrames
ldy #>plasmaFrames
jsr mainLoader
lda #REQUEST_MEMORY
ldx #<(plasmaEnd-plasmaFrames)
ldy #>(plasmaEnd-plasmaFrames)
ldx #0
ldy #>PLASMA_FRAME_SIZE
jsr mainLoader
stx plasmaFrames
sty plasmaFrames+1
; Load the font engine
!if DEBUG { +prStr : !text "Loading font engine.",0 }
lda #SET_MEM_TARGET
@ -1586,16 +1584,6 @@ initMem: !zone
ldx #RES_TYPE_CODE
ldy #3 ; hard coded for now: code #3 is the font engine
jsr mainLoader
; Load the font engine
!if DEBUG { +prStr : !text "Loading game loop.",0 }
lda #SET_MEM_TARGET
ldx #<plasmaCode
ldy #>plasmaCode
jsr mainLoader
lda #QUEUE_LOAD
ldx #RES_TYPE_CODE
ldy #4 ; hard coded for now: code #4 is the game loop
jsr mainLoader
!if DEBUG { +prStr : !text "Loading expansion code.",0 }
; Load the texture expansion code into aux mem.
lda #SET_MEM_TARGET
@ -1642,8 +1630,6 @@ initMem: !zone
pla
tax ; and hi byte in X
jsr setFONT
; Test PLASMA
jsr plasmaCode
; Set to write text on both hi-res pages at the same time
lda #pHGR3
jsr displayMODE