From 7df3e2ced2a8efc082e7f38de8da53cadc7e4ccd Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Wed, 3 Aug 2016 07:54:14 -0700 Subject: [PATCH] Raycaster with split-expander working now. --- .../Apple/virtual/src/raycast/expand_hdr.i | 27 +++++++++------- Platform/Apple/virtual/src/raycast/render.s | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Platform/Apple/virtual/src/raycast/expand_hdr.i b/Platform/Apple/virtual/src/raycast/expand_hdr.i index 68ca4b23..cf741756 100644 --- a/Platform/Apple/virtual/src/raycast/expand_hdr.i +++ b/Platform/Apple/virtual/src/raycast/expand_hdr.i @@ -9,29 +9,33 @@ ;**************************************************************************************** ; Select mipmap level 0 (64x64 pixels = 32x32 bytes) +; On entry, txColumn should be in A-reg selectMip0: ; pTex is already pointing at level 0, no need to adjust its level. ; However, we do need to move it to the correct column. Currently txColumn ; is 0..255 pixels, which we need to translate to 0..31 columns; that's ; a divide by 8. But then we need to multiply by 32 bytes per column, ; so (1/8)*32 = 4, so we need to multiply by 4 after masking. - lda #0 - sta tmp - lda txColumn - and #$F8 ; retain upper 5 bits + sta clrAuxZP + ldy #0 + sty tmp + and #$F8 ; retain upper 5 bits of txColumn asl rol tmp ; multiplied by 2 asl rol tmp ; multiplied by 4 ldy tmp mipReady: + sta clrAuxZP clc ; adjust pTex by that much adc pTex - sta pTex + tax tya adc pTex+1 - sta pTex+1 ldy pixNum ; get offset into the blit roll for this column + sta setAuxZP + stx pTex + sta pTex+1 ldx .blitOffsets,y ldy #$FF ; default to copying from top of column (will be 0 after initial INY in unrolled code) clv ; so code can use BVC to branch always without BRA @@ -39,25 +43,25 @@ mipReady: .blitOffsets: !byte BLIT_OFF0,BLIT_OFF1,BLIT_OFF2,BLIT_OFF3,BLIT_OFF4,BLIT_OFF5,BLIT_OFF6 ; Select mipmap level 0 (32x32 pixels = 16x16 bytes) +; On entry, txColumn should be in A-reg selectMip1: ; pTex is pointing at level 0, so we need to move it to level 1. ; Then we need to move it to the correct column. Currently txColumn ; is 0..255 pixels, which we need to translate to 0..15 columns; that's ; a divide by 16. But then we need to multiply by 16 bytes per column, ; so (1/16)*16 = 1 ==> no multiply needed. - lda txColumn and #$F0 ; retain upper 4 bits ldy #>MIP_OFFSET_1 ; adjust to mip level 1 bne mipReady ; always taken ; Select mipmap level 2 (16x16 pixels = 8x8 bytes) +; On entry, txColumn should be in A-reg selectMip2: ; pTex is pointing at level 0, so we need to move it to level 2. ; Then we need to move it to the correct column. Currently txColumn ; is 0..255 pixels, which we need to translate to 0..8 columns; that's ; a divide by 32. But then we need to multiply by 8 bytes per column, ; so (1/32)*8 = 1/4 ==> overall we need to divide by 4. - lda txColumn and #$E0 ; retain upper 3 bits lsr ; div by 2 lsr ; div by 4 @@ -66,13 +70,13 @@ selectMip2: bne mipReady ; always taken ; Select mipmap level 3 (8x8 pixels = 4x4 bytes) +; On entry, txColumn should be in A-reg selectMip3: ; pTex is pointing at level 0, so we need to move it to level 3. ; Then we need to move it to the correct column. Currently txColumn ; is 0..255 pixels, which we need to translate to 0..3 columns; that's ; a divide by 64. But then we need to multiply by 4 bytes per column, ; so (1/64)*4 = 1/16 ==> overall we need to divide by 16. - lda txColumn and #$C0 ; retain upper 2 bits lsr ; div by 2 lsr ; div by 4 @@ -84,13 +88,13 @@ selectMip3: bne mipReady ; always taken ; Select mipmap level 4 (4x4 pixels = 2x2 bytes) +; On entry, txColumn should be in A-reg selectMip4: ; pTex is pointing at level 0, so we need to move it to level 4. ; Then we need to move it to the correct column. Currently txColumn ; is 0..255 pixels, which we need to translate to 0..1 columns; that's ; a divide by 128. But then we need to multiply by 2 bytes per column, ; so (1/128)*2 = 1/64 ==> overall we need to divide by 64 - lda txColumn and #$80 ; retain the high bit beq + ; if not set, result should be zero lda #64 ; else result should be 64 @@ -100,10 +104,9 @@ selectMip4: bne mipReady ; always taken ; Select mipmap level 5 (2x2 pixels = 1x1 bytes) +; On entry, txColumn should be in A-reg selectMip5: ; Mip level 5 is super-easy: it's one byte. Not much choice there. lda #MIP_OFFSET_5 bne mipReady ; always taken - - diff --git a/Platform/Apple/virtual/src/raycast/render.s b/Platform/Apple/virtual/src/raycast/render.s index be4e9ae5..4c35b583 100644 --- a/Platform/Apple/virtual/src/raycast/render.s +++ b/Platform/Apple/virtual/src/raycast/render.s @@ -34,7 +34,6 @@ start: jmp pl_setAvatar ; params: A=tile number ; Conditional assembly flags -DOUBLE_BUFFER = 1 ; whether to double-buffer DEBUG = 0 ; 1=some logging, 2=lots of logging DEBUG_COLUMN = -1 @@ -78,6 +77,7 @@ plasmaStk: !byte 0 nTextures: !byte 0 scripts: !word 0 ; pointer to loaded scripts module expanderRelocd: !byte 0 ; flag so we only reloc expander once +shadow_pTex: !word 0 ; backup of pTmp space on aux (because it gets overwritten by expander) skyColorEven: !byte $20 skyColorOdd: !byte $22 @@ -1256,6 +1256,7 @@ drawRay: !zone sta pTex+1 ; jump to the unrolled expansion code for the selected height !if DEBUG >= 2 { +prStr : !text "Calling expansion code.",0 } + ldx txColumn lda lineCt sei ; prevent interrupts while in aux mem sta setAuxZP @@ -1263,7 +1264,8 @@ drawRay: !zone bcc + lda #254 ; clamp max height + sta expanderJmp+1 ; set vector offset - lda setLcRW+lcBank2 ; part of expander split and relocated to LC bank 2 + bit setLcRW+lcBank2 ; part of expander split and relocated to LC bank 2 + txa jsr callExpander ; was copied from .callIt to $100 at init time sta clrAuxZP cli ; interrupts ok after we get back from aux @@ -1394,6 +1396,12 @@ makeClrBlit: !zone ; Clear the blit clearBlit: !zone + sta setAuxZP + lda pTex ; save screen addr that gets overwritten by expander + sta shadow_pTex + lda pTex+1 + sta shadow_pTex+1 + sta clrAuxZP lda byteNum and #2 bne .alt @@ -1686,7 +1694,7 @@ pl_texControl: !zone { graphInit: !zone lda #0 sta frontBuf - !if DOUBLE_BUFFER { lda #1 } + lda #1 sta backBuf !if DEBUG >= 2 { +prStr : !text "Staying in text mode.",0 @@ -1892,7 +1900,7 @@ castAllRays: !zone ;------------------------------------------------------------------------------- ; Render one whole frame renderFrame: !zone - !if DOUBLE_BUFFER { jsr setBackBuf } + jsr setBackBuf jsr castAllRays @@ -1919,7 +1927,11 @@ renderFrame: !zone iny sei sta setAuxZP - jsr blitRoll + lda shadow_pTex ; restore screen addr that gets overwritten by expander + sta pTex + lda shadow_pTex+1 + sta pTex+1 + jsr blitRoll ; go do the blitting sta clrAuxZP cli lda #0 @@ -1944,22 +1956,13 @@ pl_flipToPage1: !zone ;------------------------------------------------------------------------------- ; Flip back buffer onto the screen flip: !zone -!if DOUBLE_BUFFER { ldy backBuf lda frontBuf sta backBuf sty frontBuf lda page1,y -} - ; Hack for real (not emulated) IIc: sometimes displays only lo-bit graphics - ; unless we do this. *HUGE* thanks to Brendan Robert for the fix! - sta $C07E ; disable double-hi-res - lda $C05F ; disable double-hi-res rts -;------------------------------------------------------------------------------- -+ jmp flip - ;------------------------------------------------------------------------------- copyScreen: !zone ; Copy all screen data from page 1 to page 2