From 269770da90c9c5bcbe108912ef3f91a8f50897f9 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Thu, 3 Jul 2014 10:51:24 -0700 Subject: [PATCH] Debugging PLASMA loader. --- .../src/org/demo/PackPartitions.groovy | 18 +++- Platform/Apple/virtual/src/core/mem.s | 90 ++++++++++++++----- Platform/Apple/virtual/src/include/debug.i | 12 +++ Platform/Apple/virtual/src/raycast/render.s | 8 +- 4 files changed, 103 insertions(+), 25 deletions(-) diff --git a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy index fac786bb..b807167b 100644 --- a/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy +++ b/Platform/Apple/tools/PackPartitions/src/org/demo/PackPartitions.groovy @@ -626,7 +626,7 @@ class PackPartitions // Extract offsets of the bytecode functions from the fixup table def sp = 0 - def defs = [initStart-byteCodeStart] + def defs = [initStart-byteCodeStart+2] def invDefs = [:] (1.. queued for load iny ; not set, not queued, so skip over it iny @@ -1253,7 +1267,6 @@ disk_finishLoad: !zone +prStr : !text "num=",0 +prByte resNum +prStr : !text "isAux=",0 - +prByte isAuxCmd rts .debug2:+prStr : !text "reqLen=",0 +prWord reqLen @@ -1630,6 +1643,7 @@ setupDecomp: ; Apply fixups to all modules that were loaded this round, and free the fixup ; resources from memory. doAllFixups: !zone + !if DEBUG { +prStr : !text "Doing all fixups.",0 } ; copy the shadow code down to $100, so we can read aux mem bytes ldx #.fixupShadow_end - .fixupShadow - 1 - lda .fixupShadow,x @@ -1645,9 +1659,12 @@ doAllFixups: !zone .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 + lda #1 + sta isAuxCmd + jmp coalesce ; really free up the fixup blocks by coalescing them into free mem .found ; Found one fixup seg. + sta tSegLink,x ; just the type (getting rid of 'active' flag) lda tSegAdrLo,x ; grab its address sta pSrc ; save to the accessor routine lda tSegAdrHi,x ; hi byte too @@ -1681,18 +1698,20 @@ doAllFixups: !zone lda tSegAdrHi,x sta .auxBase+1 + !if DEBUG { jsr .debug1 } + ; Process the fixups .proc jsr .fetchFixup ; get key byte - tay ; save it aside, and also check the hi bit + tax ; 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 + txa adc .mainBase+1 sta pDst+1 - ldy #0 + !if DEBUG { jsr .debug2 } clc jsr .adMain iny @@ -1703,16 +1722,16 @@ doAllFixups: !zone sta (pDst),y rts .fxAux cmp #$FF ; end of fixups? - beq .resume ; if so, resume scanning + beq .stubs ; if so, go do the stubs jsr .fetchFixup ; get lo byte of offset clc adc .auxBase sta pDst - tya + txa and #$7F ; mask off the hi bit flag adc .auxBase+1 sta pDst+1 - ldy #0 + !if DEBUG { jsr .debug3 } sta setAuxWr jsr .adAux iny @@ -1723,20 +1742,25 @@ doAllFixups: !zone adc .mainBase,y sta (pDst),y rts -.resume ldx #11 ; self-modified earlier - ; fix up the stubs +.stubs ; 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 + cmp #$20 ; aux mem stubs marked by JSR $3DC + bne .resume ; not a stub, resume scanning + iny lda (pDst),y - cmp #3 - bne .estub + cmp #$DC + bne .resume ; not a stub, resume scanning + iny + lda (pDst),y + cmp #$03 + bne .resume ; not a stub, resume scanning + ; found a stub, adjust it. + !if DEBUG { jsr .debug4 } clc ldx #0 jsr .adStub @@ -1754,10 +1778,11 @@ doAllFixups: !zone adc .auxBase,x sta (pDst),y rts -.estub ; done with stubs +.resume ldx #11 ; self-modified earlier jmp .next ; go scan for more fixup blocks .fetchFixup: + ldy #0 jsr .getFixupByte ; get a byte from aux mem inc pSrc ; and advance the pointer bne + @@ -1778,6 +1803,31 @@ doAllFixups: !zone rts } .fixupShadow_end = * +!if DEBUG { +.debug1 +prStr : !text "Found fixup, res=",0 + +prByte resNum + +prStr : !text "mainBase=",0 + +prWord .mainBase + +prStr : !text "auxBase=",0 + +prWord .auxBase + +crout + rts +.debug2 +prStr : !text " main fixup, addr=",0 + +prWord pDst + +crout + +waitKey + rts +.debug3 +prStr : !text " aux fixup, addr=",0 + +prWord pDst + +crout + +waitKey + rts +.debug4 +prStr : !text " main stub, addr=",0 + +prWord pDst + +crout + +waitKey + rts +} .mainBase !word 0 .auxBase !word 0 diff --git a/Platform/Apple/virtual/src/include/debug.i b/Platform/Apple/virtual/src/include/debug.i index cf7124a0..375a9d48 100644 --- a/Platform/Apple/virtual/src/include/debug.i +++ b/Platform/Apple/virtual/src/include/debug.i @@ -44,6 +44,18 @@ jsr _prSpace } +!macro prYA { + jsr _prY + jsr _prA + jsr _prSpace +} + +!macro prAY { + jsr _prA + jsr _prY + jsr _prSpace +} + !macro prXY { jsr _prX jsr _prY diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index 6ee4e1db..1af3e9b4 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -13,7 +13,7 @@ start: ; Conditional assembly flags DOUBLE_BUFFER = 1 ; whether to double-buffer -DEBUG = 0 ; 1=some logging, 2=lots of logging +DEBUG = 1 ; 1=some logging, 2=lots of logging DEBUG_COLUMN = -1 ; temporary hack to try blocker sprites @@ -1604,6 +1604,12 @@ initMem: !zone ldx #RES_TYPE_SCREEN ldy #1 jsr mainLoader + ; Load the game loop module + !if DEBUG { +prStr : !text "Loading game loop.",0 } + lda #QUEUE_LOAD + ldx #RES_TYPE_MODULE + ldy #1 ; hard coded for now: module #1 is the game loop + jsr mainLoader ; Load the map into main mem !if DEBUG { +prStr : !text "Loading map.",0 } lda #QUEUE_LOAD