refactoring: reorganize syntax sugar for segments handling

This commit is contained in:
giomba 2021-11-07 20:35:46 +01:00
parent f67017c9a6
commit db8707bebf
17 changed files with 63 additions and 182 deletions

View File

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

View File

@ -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
; Lists for snake head and tail
listX DS 256
listY DS 256

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,8 +2,8 @@
ptrDstStart WORD
ptrDstEnd WORD
SEG programSegment
MACRO MEMSET
SEG programSegment
clc
lda <{1}
sta ptrDstStart

View File

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

View File

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

View File

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

View File

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

6
src/sidtune.asm Normal file
View File

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

View File

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

View File

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