From 5f85203028ccaff273f83e42c2ad81a1d9369136 Mon Sep 17 00:00:00 2001 From: giomba Date: Thu, 2 Apr 2020 17:09:57 +0200 Subject: [PATCH] commented code for level loading --- Makefile | 2 +- src/gamereset.asm | 12 ---------- src/levels.asm | 56 +++++++++++++++++++++------------------------ src/subroutines.asm | 20 ++++++++++++++++ src/zeropage.asm | 4 ++-- 5 files changed, 49 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index e29eb52..e16f64f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/gamereset.asm b/src/gamereset.asm index 5c57eed..7b4fd93 100644 --- a/src/gamereset.asm +++ b/src/gamereset.asm @@ -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 diff --git a/src/levels.asm b/src/levels.asm index a36ec89..1be8657 100644 --- a/src/levels.asm +++ b/src/levels.asm @@ -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 - diff --git a/src/subroutines.asm b/src/subroutines.asm index bcc2926..6a7a0b1 100644 --- a/src/subroutines.asm +++ b/src/subroutines.asm @@ -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 diff --git a/src/zeropage.asm b/src/zeropage.asm index 9cf9ea6..3fe9d66 100644 --- a/src/zeropage.asm +++ b/src/zeropage.asm @@ -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