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: env:
mkdir -p {build,bin,res.bin} mkdir -p {build,bin,res.bin}
debug: $(ASM) $(RES) debug: env $(ASM) $(RES)
g++ -o bin/explodefont util/explodefont.cpp g++ -o bin/explodefont util/explodefont.cpp
dasm src/main.asm -Isrc/ -DSYSTEM=64 -DDEBUG=1 -sbuild/symbols.txt -obin/snake.prg 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 ; Turn MultiColor mode on
jsr multicolorOn 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 ; Set overscan
lda #11 lda #11
sta $d020 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 ldy #39
sty tempPointer sty levelVideoPointer
ldy #$04 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: writeLevelLoop:
; read `T`, and save onto stack
ldy #0 ldy #0
lda (levelPointer),y lda (levelPointer),y
pha pha
; increment array pointer
lda #levelPointer lda #levelPointer
sta nextPointerPointer sta nextPointerPointer
ldx #1 ldx #1
jsr nextPointer jsr nextPointer
; read `C`, and save onto stack
ldy #0 ldy #0
lda (levelPointer),y lda (levelPointer),y
pha pha
; increment array pointer
lda #levelPointer lda #levelPointer
sta nextPointerPointer sta nextPointerPointer
ldx #1 ldx #1
jsr nextPointer jsr nextPointer
; retrieve `C` from stack and put in X and Y
pla pla
tay tay
tax tax
; retrieve `T` from stack
pla pla
; check array end
cmp #0 cmp #0
beq writeLevelEnd beq writeLevelEnd
; unpack char from RLE to the screen
writeLevelElement: writeLevelElement:
sta (tempPointer),y sta (levelVideoPointer),y
dey dey
bne writeLevelElement bne writeLevelElement
lda #tempPointer lda #levelVideoPointer
sta nextPointerPointer sta nextPointerPointer
; x still holds the total number ; reg X is still holding the original `C`
jsr nextPointer jsr nextPointer
jmp writeLevelLoop jmp writeLevelLoop
@ -50,23 +66,3 @@ writeLevelEnd:
sta status sta status
rts 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: printIntroEnd:
rts 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 ; Pointer to level struct
levelPointer DS 2 levelPointer DS 2
; Temporary pointer -- Use when you don't call a subroutine ; Pointer to video memory used in the level loading routine
tempPointer DS 2 levelVideoPointer DS 2
; Pointer for Pointer in the NextPointer routine ; Pointer for Pointer in the NextPointer routine
nextPointerPointer DS 2 nextPointerPointer DS 2