From e506a361bf40bc3e28b1801e213a5a1c11a2a4e7 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Thu, 30 Jan 2014 09:27:39 -0800 Subject: [PATCH] Mem manager fixes, and added ground/sky/map changing to ray caster. --- Platform/Apple/virtual/src/core/mem.s | 38 ++++-- Platform/Apple/virtual/src/raycast/render.i | 4 - Platform/Apple/virtual/src/raycast/render.s | 127 +++++++++++++++++--- 3 files changed, 138 insertions(+), 31 deletions(-) diff --git a/Platform/Apple/virtual/src/core/mem.s b/Platform/Apple/virtual/src/core/mem.s index 40b5d28a..d1a82b52 100644 --- a/Platform/Apple/virtual/src/core/mem.s +++ b/Platform/Apple/virtual/src/core/mem.s @@ -32,9 +32,6 @@ jmp main_dispatch jmp aux_dispatch -DEBUG = 0 - .include "../include/debug.i" - ;------------------------------------------------------------------------------ ; Variables targetAddr: @@ -52,6 +49,10 @@ curPartition: partitionFileRef: .byte 0 +;------------------------------------------------------------------------------ +DEBUG = 0 + .include "../include/debug.i" + ;------------------------------------------------------------------------------ grabSegment: ; Output: Y-reg = segment grabbed @@ -276,9 +277,10 @@ fatalError: jsr orCout iny bne :- +: .if DEBUG ; Print call stack -: ldy #0 + ldy #0 : lda stackMsg,y beq :+ jsr orCout @@ -548,10 +550,10 @@ reset: jmp nextLoaderVec ; and allow chained loaders to reset also @inactivate: lda tSegType,x ; get flag byte for this segment - tax + tay and #$40 ; segment locked? bne @next ; yes, skip it - txa ; no, get back flags + tya ; no, get back flags and #$7F ; mask off the 'active' bit sta tSegType,x ; save it back @next: @@ -659,8 +661,7 @@ shared_alloc: lda #$80 ; flag segment as active, not locked, not holding a resource sta tSegType,x ; save the flags and type lda #0 - sta targetAddr ; clear targetAddr for next future request - sta targetAddr+1 + sta targetAddr+1 ; clear target address for next time sta tSegResNum,x ; might as well clear resource number too lda tSegAdrLo,x ; get address for return ldy tSegAdrHi,x ; all 16 bits @@ -745,6 +746,7 @@ shared_queueLoad: sty resNum ; save resource number jsr scanForResource ; scan to see if we already have this resource in mem beq @notFound ; nope, pass to next loader + stx segNum ; save seg num for later lda tSegType,x ; get flags ora #$80 ; reactivate if necessary sta tSegType,x ; save modified flag @@ -752,7 +754,23 @@ shared_queueLoad: tay ; in Y for return lda tSegAdrLo,x ; addr lo tax ; in X for return + lda targetAddr+1 ; was specific address requested? + beq @noChkTarg ; if not, skip target check + cpx targetAddr ; verify addr lo + bne @redo + cpy targetAddr ; verify addr hi + bne @redo +@noChkTarg: + lda #0 + sta targetAddr+1 ; clear targ addr for next time rts ; all done +@redo: + ; different address requested than what we have: clear current block. + lda #0 + ldx segNum + sta tSegType,x + sta tSegResNum,x + ; fall through to re-load the resource @notFound: ldx resType ; restore res type ldy resNum ; and number @@ -780,6 +798,7 @@ diskLoader: ;------------------------------------------------------------------------------ openPartition: + DEBUG_STR "Opening part file." ; complete the partition file name lda curPartition clc @@ -1033,7 +1052,8 @@ disk_finishLoad: bne @scan ; always taken @keepOpenChk: lda #11 ; self-modified to 0 or 1 at start of routine - beq @keepOpen + bne @keepOpen + DEBUG_STR "Closing part file." jsr mli ; now that we're done loading, we can close the partition file .byte MLI_CLOSE .word @closeParams diff --git a/Platform/Apple/virtual/src/raycast/render.i b/Platform/Apple/virtual/src/raycast/render.i index ce0a4f0a..051894aa 100644 --- a/Platform/Apple/virtual/src/raycast/render.i +++ b/Platform/Apple/virtual/src/raycast/render.i @@ -5,10 +5,6 @@ ; Constants TOP_LINE = $2180 ; 24 lines down from top NLINES = 128 -SKY_COLOR_E = $22 ; blue -SKY_COLOR_O = $20 ; hi-bit black -GROUND_COLOR_E = $28 ; orange -GROUND_COLOR_O = $20 ; hi-bit black TEX_SIZE = $555 ; 32x32 + 16x16 + 8x8 + 4x4 + 2x2 + 1x1 ; Byte offset for each pixel in the blit unroll diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index 0b5fc67b..4365e230 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -1,6 +1,8 @@ .org $6000 +start: + ; This code is written bottom-up. That is, simple routines first, ; then routines that call those to build complexity. The main ; code is at the very end. We jump to it now. @@ -23,6 +25,32 @@ frontBuf: .byte 0 ; (value 0 or 1) mapHeader: .word 0 ; map with header first mapBase: .word 0 ; first byte after the header mapRayOrigin: .word 0 +mapNum: .byte 1 + +; Sky / ground colors +skyGndTbl1: + .byte $20 ; hi-bit black + .byte $20 ; hi-bit black + .byte $20 ; hi-bit black + .byte $22 ; blue + .byte $28 ; orange + .byte $2A ; hi-bit white + .byte $2A ; hi-bit white + .byte $2A ; hi-bit white +skyGndTbl2: + .byte $20 ; hi-bit black + .byte $22 ; blue + .byte $28 ; orange + .byte $22 ; blue + .byte $28 ; orange + .byte $22 ; blue + .byte $28 ; orange + .byte $2A ; hi-bit white + +skyColorEven: .byte $20 +skyColorOdd: .byte $22 +gndColorEven: .byte $20 +gndColorOdd: .byte $28 ;------------------------------------------------------------------------------- ; Multiply two bytes, quickly but somewhat inaccurately, using logarithms. @@ -732,18 +760,18 @@ clearBlit: ldx #BLIT_OFF6 jmp @clear2 @clear1: - ldy #GROUND_COLOR_E - lda #SKY_COLOR_E + ldy gndColorEven + lda skyColorEven jsr clrBlitRollO - ldy #GROUND_COLOR_O - lda #SKY_COLOR_O + ldy gndColorOdd + lda skyColorOdd jmp clrBlitRollE @clear2: - ldy #GROUND_COLOR_E - lda #SKY_COLOR_E + ldy gndColorEven + lda skyColorEven jsr clrBlitRollE - ldy #GROUND_COLOR_O - lda #SKY_COLOR_O + ldy gndColorOdd + lda skyColorOdd jmp clrBlitRollO ; Construct the pixel decoding tables @@ -857,6 +885,12 @@ setBackBuf: ;------------------------------------------------------------------------------- initMem: DEBUG_STR "Raycast: setting up memory." + lda #LOCK_MEMORY ; lock ourselves in before reset + ldx #start + jsr mainLoader + lda #RESET_MEMORY ; clear everything else + jsr mainLoader ; Reserve memory for our tables lda #SET_MEM_TARGET ldx #