From db8707bebf04068d90d5df753fbb2bbbf0665d11 Mon Sep 17 00:00:00 2001 From: giomba Date: Sun, 7 Nov 2021 20:35:46 +0100 Subject: [PATCH] refactoring: reorganize syntax sugar for segments handling --- Makefile | 6 ++-- src/data.asm | 13 +++---- src/font.asm | 13 ++++--- src/game.asm | 9 ----- src/gameover.asm | 9 +---- src/initdata.asm | 9 +---- src/intro1.asm | 8 ----- src/levelreset.asm | 9 +---- src/levels.asm | 10 ++---- src/macro.asm | 2 +- src/main.asm | 83 ++++++++++++++------------------------------- src/multicolor.asm | 11 +----- src/outro.asm | 9 +---- src/program.asm | 15 ++++---- src/sidtune.asm | 6 ++++ src/subroutines.asm | 15 +++----- src/zeropage.asm | 18 ---------- 17 files changed, 63 insertions(+), 182 deletions(-) create mode 100644 src/sidtune.asm diff --git a/Makefile b/Makefile index 552494b..ccfea6b 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ RES=res.bin/amour2.sid res.bin/levels.bin res.bin/unlzg.bin all: bin/snake6502.bin bin/snake6502.d64 bin/snake6502.bin: bin/snake.pack.lz - dasm src/cart.asm -Isrc/ -DVERBOSE=$(VERBOSE) -f3 -sbuild/cart.symbols.txt -obin/snake6502.bin + dasm src/cart.asm -Isrc/ -DVERBOSE=$(VERBOSE) -f3 -T1 -sbuild/cart.symbols.txt -obin/snake6502.bin bin/snake6502.d64: bin/loader.prg c1541 -format "snake6502,01" d64 bin/snake6502.d64 @@ -19,10 +19,10 @@ bin/loader.prg: bin/snake.pack.lz.prg dasm src/loader.asm -Isrc/ -DVERBOSE=$(VERBOSE) -f1 -sbuild/loader.sybols.txt -obin/loader.prg bin/snake.prg: bin/snake.pack - dasm src/prg.asm -Isrc/ -DVERBOSE=$(VERBOSE) -f1 -sbuild/prg.symbols.txt -obin/snake.prg + dasm src/prg.asm -Isrc/ -DVERBOSE=$(VERBOSE) -f1 -T1 -sbuild/prg.symbols.txt -obin/snake.prg bin/snake.pack: env $(ASM) $(RES) bin/explodefont - dasm src/main.asm -Isrc/ -DSYSTEM=64 -DDEBUG=$(DEBUG) -DVERBOSE=$(VERBOSE) -f3 -sbuild/pack.symbols.txt -obin/snake.pack + dasm src/main.asm -Isrc/ -DSYSTEM=64 -DDEBUG=$(DEBUG) -DVERBOSE=$(VERBOSE) -f3 -T1 -sbuild/pack.symbols.txt -obin/snake.pack bin/snake.pack.lz: bin/snake.pack liblzg/src/tools/lzg liblzg/src/tools/lzg bin/snake.pack > bin/snake.pack.lz diff --git a/src/data.asm b/src/data.asm index 74b3ba1..bc9416b 100644 --- a/src/data.asm +++ b/src/data.asm @@ -1,9 +1,4 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - -; Data section - Not initialized variables ($CD00 - $CDFF) -; ---------------------------------------------------------------------- + SEG.U dataSegment ; Number of interrupt ; Used as counter to be decremented to do some things less frequently irqn: @@ -70,6 +65,6 @@ XScrollDirection: XCharOffset: BYTE -#if VERBOSE = 1 - ECHO "data.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif \ No newline at end of file +; Lists for snake head and tail +listX DS 256 +listY DS 256 diff --git a/src/font.asm b/src/font.asm index 1a84a47..444879d 100644 --- a/src/font.asm +++ b/src/font.asm @@ -1,7 +1,10 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif +; Character ROM starts at $2000, but SID must reside at $1000 and is +; longer than $1000, then first characters are just ignored, and game +; uses only characters $80-$ff. +; Normally, character ROM is 2kB long ($800), but this binary data +; is exactly 1kB long ($400), because only the upper chars are defined. + SEG fontSegment ; char 0x80, 128 BYTE #%00000000 BYTE #%00000000 @@ -1282,7 +1285,3 @@ LASTINIT SET . BYTE #%10000001 BYTE #%10000001 BYTE #%11111111 - -#if VERBOSE = 1 - ECHO "font.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif diff --git a/src/game.asm b/src/game.asm index 8675f42..0bc9f8d 100644 --- a/src/game.asm +++ b/src/game.asm @@ -1,7 +1,3 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - SEG programSegment statusPlay: ; do Game ; Check counter @@ -336,9 +332,4 @@ checkEndWallHit: sta (tileMem),y skipPauseTests: - rts - -#if VERBOSE = 1 - ECHO "game.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif \ No newline at end of file diff --git a/src/gameover.asm b/src/gameover.asm index 21cd655..371da6f 100644 --- a/src/gameover.asm +++ b/src/gameover.asm @@ -1,7 +1,4 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - + SEG programSegment ; Game is over ; ---------------------------------------------------------------------- gameover: @@ -24,7 +21,3 @@ gameover: lda #ST_DELAY sta status rts - -#if VERBOSE = 1 - ECHO "gameover.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif \ No newline at end of file diff --git a/src/initdata.asm b/src/initdata.asm index ac86a5b..2362dc1 100644 --- a/src/initdata.asm +++ b/src/initdata.asm @@ -1,7 +1,4 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - + SEG programSegment ; Initialized variables ; ---------------------------------------------------------------------- @@ -113,7 +110,3 @@ introStringA6: ; ---------------------------------------------------------------------- levelsList: INCBIN "../res.bin/levels.bin" - -#if VERBOSE = 1 - ECHO "initdata.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif diff --git a/src/intro1.asm b/src/intro1.asm index 7d2a0e6..ba29a1c 100644 --- a/src/intro1.asm +++ b/src/intro1.asm @@ -1,7 +1,3 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - SEG zeropageSegment ; Generic src/dst copy pointers srcPointer DS 2 @@ -700,7 +696,3 @@ XScrollInterruptMoveAll SUBROUTINE statusMenu SUBROUTINE jsr setupXScrollInterrupt rts - -#if VERBOSE = 1 - ECHO "intro1.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif \ No newline at end of file diff --git a/src/levelreset.asm b/src/levelreset.asm index 88983bc..36f3bb5 100644 --- a/src/levelreset.asm +++ b/src/levelreset.asm @@ -1,7 +1,4 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - + SEG programSegment ; Reset variables for a new level ; ---------------------------------------------------------------------- levelresetvar: @@ -35,7 +32,3 @@ clearListLoop: bne clearListLoop rts - -#if VERBOSE = 1 - ECHO "levelreset.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif \ No newline at end of file diff --git a/src/levels.asm b/src/levels.asm index 8a57499..12c2f2c 100644 --- a/src/levels.asm +++ b/src/levels.asm @@ -1,11 +1,9 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - SEG zeropageSegment ; Pointer to video memory used in the level loading routine levelVideoPointer WORD levelColorPointer WORD +; Pointer to level struct +levelPointer WORD SEG programSegment ; load new level on the screen @@ -173,7 +171,3 @@ writeLevelEnd: lda #ST_PLAY sta status rts - -#if VERBOSE = 1 - ECHO "levels.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif diff --git a/src/macro.asm b/src/macro.asm index 0d151c9..fc3ef39 100644 --- a/src/macro.asm +++ b/src/macro.asm @@ -2,8 +2,8 @@ ptrDstStart WORD ptrDstEnd WORD + SEG programSegment MACRO MEMSET - SEG programSegment clc lda <{1} sta ptrDstStart diff --git a/src/main.asm b/src/main.asm index e6dd253..efa03fb 100644 --- a/src/main.asm +++ b/src/main.asm @@ -1,46 +1,34 @@ processor 6502 -; Platform specific code -; Code yet to be developed, example to use: -; ---------------------------------------------------------------------- -#if SYSTEM = 64 - ; Commodore64 specific code -#else - ; Commodore16 specific code -#endif - -; Uninitialized zeropage segment -; ---------------------------------------------------------------------- SEG.U zeropageSegment - org $02 +ORG_ZEROPAGE EQU $02 + org ORG_ZEROPAGE -#if VERBOSE = 1 - ; Locations $90-$FF in zeropage are used by kernal - ECHO "End of zeropage variables. Space left: ",($90 - .) -#endif - -; SID tune (previously properly cleaned, see HVSC) -; ---------------------------------------------------------------------- SEG sidSegment - org $1000 -sidtune: - INCBIN "../res.bin/amour2.sid" -#if VERBOSE = 1 - ECHO "top $2000: End of SIDtune at ",.,"Space left:",($2000 - .) - ECHO "top $2400: End of SIDtune at ",.,"Space left:",($2400 - .) -#endif - -; Font Data -; ---------------------------------------------------------------------- +ORG_SID EQU $1000 + org ORG_SID +ORG_FONT EQU $2400 SEG fontSegment - org $2400 -; This binary data that defines the font is exactly 2kB long ($800) - INCLUDE "font.asm" - -; Program Segment -; ---------------------------------------------------------------------- + org ORG_FONT +ORG_PROGRAM EQU $2800 SEG programSegment - org $2800 + org ORG_PROGRAM + +ORG_DATA EQU $cd00 + SEG.U dataSegment + org ORG_DATA + +; INCLUDE +; ----------------------------------------------------------------------------- +LASTINIT SET ORG_SID + INCLUDE "sidtune.asm" + ECHO "sidtune : start ",LASTINIT," end ",.," size ",(. - LASTINIT) + +LASTINIT SET ORG_FONT + INCLUDE "font.asm" + ECHO "font : start ",LASTINIT," end ",.," size ",(. - LASTINIT) + +LASTINIT SET ORG_PROGRAM INCLUDE "program.asm" INCLUDE "initdata.asm" INCLUDE "game.asm" @@ -51,30 +39,9 @@ sidtune: INCLUDE "multicolor.asm" INCLUDE "levelreset.asm" INCLUDE "outro.asm" -#if VERBOSE = 1 - ECHO "End of program segment at:",. - ECHO "PACK SIZE:",(. - $1000),"=",[(. - $1000)d] -#endif - -; Data variables -; ----------------- - SEG.U dataSegment - org $cd00 INCLUDE "data.asm" INCLUDE "macro.asm" -#if VERBOSE = 1 - ECHO "End of Data segment. Space left:",($ce00 - .) -#endif - -; Lists -; ----------------- - SEG.U listSegment - org $ce00 -listX DS 256 -listY DS 256 - -; Includes - INCLUDE "zeropage.asm" + ECHO "program : start ",LASTINIT," end ",.," size ",(. - LASTINIT) ; ; coded 2017, 2018, 2019, 2020, 2021 diff --git a/src/multicolor.asm b/src/multicolor.asm index f5537a2..9081608 100644 --- a/src/multicolor.asm +++ b/src/multicolor.asm @@ -1,9 +1,4 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - - processor 6502 - + SEG programSegment multicolor SUBROUTINE ; Prepare data struct for MultiColor mode @@ -43,7 +38,3 @@ multicolorOff: and #$ef sta $d016 rts - -#if VERBOSE = 1 - ECHO "multicolor.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif \ No newline at end of file diff --git a/src/outro.asm b/src/outro.asm index a8d36e2..4715a44 100644 --- a/src/outro.asm +++ b/src/outro.asm @@ -1,7 +1,4 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - + SEG programSegment ; Wait for some delay statusDelay SUBROUTINE ldy delay ; load outroDelay and decrement @@ -14,7 +11,3 @@ statusDelay SUBROUTINE lda delayStatus sta status rts - -#if VERBOSE = 1 - ECHO "outro.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif \ No newline at end of file diff --git a/src/program.asm b/src/program.asm index 03c074b..3aa9236 100644 --- a/src/program.asm +++ b/src/program.asm @@ -1,9 +1,10 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif + SEG zeropageSegment + ; Interrupt counter +counter DS 2 -; ENTRY OF PROGRAM -; ---------------------------------------------------------------------- + SEG programSegment + ; this is the entry point of the program and must stay at this address + org $2800 start: ; Clear screen, initialize keyboard, restore interrupts jsr $ff81 @@ -253,7 +254,3 @@ checkEndStatus: ; Go to original system routine jmp $ea31 - -#if VERBOSE = 1 - ECHO "program.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif diff --git a/src/sidtune.asm b/src/sidtune.asm new file mode 100644 index 0000000..91e3dc8 --- /dev/null +++ b/src/sidtune.asm @@ -0,0 +1,6 @@ + SEG sidSegment +sidtune: + INCBIN "../res.bin/amour2.sid" + +; Note: the SID tune must be properly cleaned (eg. header removed) +; See HVSC for .sid music format diff --git a/src/subroutines.asm b/src/subroutines.asm index b021179..7882e77 100644 --- a/src/subroutines.asm +++ b/src/subroutines.asm @@ -1,9 +1,3 @@ -#if VERBOSE = 1 -LASTINIT SET . -#endif - -; Subroutines -; ---------------------------------------------------------------------- SEG zeropageSegment ; Where is the snake head in video memory? Do math to calculate address ; using pointer at tileMem @@ -156,6 +150,11 @@ printString SUBROUTINE .end: rts + SEG zeropageSegment + ; Pointer for Pointer in the NextPointer routine +nextPointerPointer DS 2 + + SEG programSegment ; Increment a pointer in the zeropage ; Input parameters: ; nextPointerPointer pointer to the pointer in zeropage @@ -176,7 +175,3 @@ nextPointer: sta (nextPointerPointer),y rts - -#if VERBOSE = 1 - ECHO "subroutines.asm @ ",LASTINIT,"len:",(. - LASTINIT) -#endif diff --git a/src/zeropage.asm b/src/zeropage.asm index d44b9fb..e69de29 100644 --- a/src/zeropage.asm +++ b/src/zeropage.asm @@ -1,18 +0,0 @@ -; Zero page utility pointers -; ---------------------------------------------------------------------- - SEG zeropageSegment -; Pointer to level struct -levelPointer DS 2 - -; Pointer for Pointer in the NextPointer routine -nextPointerPointer DS 2 - -; Pointer to string for strlen routine -strlenString DS 2 - -; Interrupt counter -counter DS 2 - -; Note: Locations $90-$FF in zeropage are used by kernal - -