Mem manager fixes, and added ground/sky/map changing to ray caster.

This commit is contained in:
Martin Haye 2014-01-30 09:27:39 -08:00
parent 83f0e24afa
commit e506a361bf
3 changed files with 138 additions and 31 deletions

View File

@ -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

View File

@ -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

View File

@ -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
ldy #>start
jsr mainLoader
lda #RESET_MEMORY ; clear everything else
jsr mainLoader
; Reserve memory for our tables
lda #SET_MEM_TARGET
ldx #<tableStart
@ -876,14 +910,6 @@ initMem:
ldx #RES_TYPE_CODE
ldy #2 ; hard coded for now: code #2 is texture expander
jsr auxLoader
; Load the map into main mem
DEBUG_STR "Loading map."
lda #QUEUE_LOAD
ldx #RES_TYPE_3D_MAP
ldy #1 ; map 1 is for now the only map
jsr mainLoader
stx mapHeader
sty mapHeader+1
DEBUG_STR "Loading frame."
; Load the UI frame
lda #SET_MEM_TARGET
@ -894,6 +920,14 @@ initMem:
ldx #RES_TYPE_SCREEN
ldy #1
jsr mainLoader
; Load the map into main mem
DEBUG_STR "Loading map."
lda #QUEUE_LOAD
ldx #RES_TYPE_3D_MAP
ldy mapNum ; hard-coded for now
jsr mainLoader
stx mapHeader
sty mapHeader+1
; Force the loads to complete now
lda #FINISH_LOAD
ldx #1 ; keep queue open
@ -1208,6 +1242,50 @@ copyScreen:
bne @outer
rts
;-------------------------------------------------------------------------------
setGndColor:
jsr readKbdColor
bcs :+
sta gndColorEven
stx gndColorOdd
: rts
setSkyColor:
jsr readKbdColor
bcs :+
sta skyColorEven
stx skyColorOdd
: rts
readKbdColor:
jsr rdkey
and #$7F
sec
sbc #'0'
bcc @bad
cmp #8
bcs @bad
tay
ldx skyGndTbl1,y
lda skyGndTbl2,y
rts
@bad:
jsr bell
sec
rts
;-------------------------------------------------------------------------------
nextMap:
ldx mapNum
inx
cpx #4
bne :+
ldx #1
: stx mapNum
bit setText
bit page1
jmp main ; re-init everything
;-------------------------------------------------------------------------------
; The real action
main:
@ -1263,8 +1341,21 @@ main:
jsr rotateRight
jmp @nextFrame
: cmp #$1B ; ESC to exit
beq @done
jmp @pauseLup ; unrecognized key: go back and get another one.
bne :+
jmp @done
: cmp #'G' ; G to set ground color
bne :+
jsr setGndColor
jmp @nextFrame
: cmp #'K' ; K to set sky color
bne :+
jsr setSkyColor
jmp @nextFrame
: cmp #'M' ; M to switch maps
bne :+
jmp nextMap
: jsr bell ; beep for unrecognized key
jmp @pauseLup ; go back and get another one.
@done:
; back to text mode
bit setText