commented code for level loading

This commit is contained in:
giomba 2020-04-02 17:09:57 +02:00
parent 5fb94c3162
commit 5f85203028
5 changed files with 49 additions and 45 deletions

View File

@ -14,7 +14,7 @@ clean:
env:
mkdir -p {build,bin,res.bin}
debug: $(ASM) $(RES)
debug: env $(ASM) $(RES)
g++ -o bin/explodefont util/explodefont.cpp
dasm src/main.asm -Isrc/ -DSYSTEM=64 -DDEBUG=1 -sbuild/symbols.txt -obin/snake.prg

View File

@ -4,18 +4,6 @@ gamereset:
; Turn MultiColor mode on
jsr multicolorOn
; Clear screen
ldx #$00
lda #$20
fullresetCLS:
dex
sta $400,x
sta $500,x
sta $600,x
sta $700,x
cpx #$00
bne fullresetCLS
; Set overscan
lda #11
sta $d020

View File

@ -1,47 +1,63 @@
statusLevelSelect: ; select new level
; load new level on the screen
statusLevelSelect:
; initialize video pointer with first video memory address
; (skip first line, used for the status bar)
ldy #39
sty tempPointer
sty levelVideoPointer
ldy #$04
sty tempPointer + 1
sty levelVideoPointer + 1
; Level data is compressed with RLE. Array example:
; +---+---+---+---+---+-..-+---+---+
; | T | C | T | C | . | | 0 | 0 |
; +---+---+---+---+---+-..-+---+---+
; T tile char
; C count (how many repeated tile chars)
; 0 end of level
writeLevelLoop:
; read `T`, and save onto stack
ldy #0
lda (levelPointer),y
pha
; increment array pointer
lda #levelPointer
sta nextPointerPointer
ldx #1
jsr nextPointer
; read `C`, and save onto stack
ldy #0
lda (levelPointer),y
pha
; increment array pointer
lda #levelPointer
sta nextPointerPointer
ldx #1
jsr nextPointer
; retrieve `C` from stack and put in X and Y
pla
tay
tax
; retrieve `T` from stack
pla
; check array end
cmp #0
beq writeLevelEnd
; unpack char from RLE to the screen
writeLevelElement:
sta (tempPointer),y
sta (levelVideoPointer),y
dey
bne writeLevelElement
lda #tempPointer
lda #levelVideoPointer
sta nextPointerPointer
; x still holds the total number
; reg X is still holding the original `C`
jsr nextPointer
jmp writeLevelLoop
@ -50,23 +66,3 @@ writeLevelEnd:
sta status
rts
; Input:
; regX = count
nextPointer:
lda #0
sta nextPointerPointer + 1
txa
clc
ldy #0
adc (nextPointerPointer),y
sta (nextPointerPointer),y
ldy #1
lda (nextPointerPointer),y
adc #0
sta (nextPointerPointer),y
rts

View File

@ -132,4 +132,24 @@ printIntroEndCheck:
printIntroEnd:
rts
; Increment a pointer in the zeropage
; Input parameters:
; nextPointerPointer pointer to the pointer in zeropage
; regX value to increment
nextPointer:
lda #0
sta nextPointerPointer + 1
txa
clc
ldy #0
adc (nextPointerPointer),y
sta (nextPointerPointer),y
ldy #1
lda (nextPointerPointer),y
adc #0
sta (nextPointerPointer),y
rts

View File

@ -15,8 +15,8 @@ introScreenStart DS 2
; Pointer to level struct
levelPointer DS 2
; Temporary pointer -- Use when you don't call a subroutine
tempPointer DS 2
; Pointer to video memory used in the level loading routine
levelVideoPointer DS 2
; Pointer for Pointer in the NextPointer routine
nextPointerPointer DS 2