diff --git a/Makefile b/Makefile index ebf6834..f9fc98b 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,16 @@ ASM=$(wildcard src/*.asm) RES=res.bin/amour.sid res.bin/levels.bin +ifeq "$(CARTRIDGE)" "1" + FORMAT:=3 +else + FORMAT:=1 +endif + .PHONY: debug env clean -bin/snake.prg: env $(ASM) $(RES) - dasm src/main.asm -Isrc/ -DSYSTEM=64 -DDEBUG=0 -sbuild/symbols.txt -obin/snake.prg +bin/snake.prg: env $(ASM) $(RES) bin/explodefont + dasm src/main.asm -Isrc/ -DSYSTEM=64 -DDEBUG=$(DEBUG) -DVERBOSE=$(VERBOSE) -DCARTRIDGE=$(CARTRIDGE) -f$(FORMAT) -sbuild/symbols.txt -obin/snake.prg clean: rm -rf {build,bin,res.bin} @@ -14,9 +20,8 @@ clean: env: mkdir -p {build,bin,res.bin} -debug: env $(ASM) $(RES) +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 res.bin/amour.sid: cp res.org/amour.sid res.bin/amour.sid diff --git a/README.md b/README.md index 0c5c147..7d42f23 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,13 @@ You need the GNU compiler collection and the [dasm](https://dasm-assembler.githu ``` $ make ``` -You can also make it output useful extra info with: -``` -$ make debug -``` +You can also define the following environment variables: + +```$ DEBUG=1 make``` build with debugging artifacts + +```$ VERBOSE=1 make``` output useful info during compilation + +```$ CARTRIDGE=1 make``` produces an 8K bin ready to be burnt to an *PROM ## Developer docs ### Memory map @@ -25,10 +28,10 @@ Address | PRG | Description ```$0000 - $0001``` | no | hardware ```$0002 - $00FF``` | no | zero page pointers ```$0100 - $07FF``` | no | *free ram* -```$0800 - $0FFF``` | yes | initialized data segment (incl. const) + BASIC autostart -```$1000 - $1FFF``` | yes | SID tune +```$0800 - $0FFF``` | yes | autostart (BASIC or cartridge) + Low Program Segment +```$1000 - $1FFF``` | yes | SID tune + Middle Program Segment ```$2000 - $27FF``` | yes | custom char -```$2800 - $xxxx``` | yes | program logic (only needed part used) +```$2800 - $xxxx``` | yes | High Program Segment (only needed part used) ```$xxxx - $CCFF``` | no | *free ram* ```$CD00 - $CDFF``` | no | data segment (not-initialized vars) ```$CE00 - $CEFF``` | no | list X @@ -36,6 +39,8 @@ Address | PRG | Description ```$D000 - $DFFF``` | no | I/O ```$E000 - $FFFF``` | no | Kernal +Note: program (code) segments have been put in all possible free spots in order to squeeze the game into an 8K cartridge. + ### Custom charset Index | Description ----------------|------------- @@ -45,3 +50,8 @@ Index | Description ```$50 - $5F``` | hex digits, reversed ```$60 - ``` | game tiles +### Cartridge +Cartridge version is at $8000 and simply copies itself back at $800. + +Cartridge version can not be built with DEBUG=1 flag due to size constraints. + diff --git a/src/basic.asm b/src/basic.asm index 9c80788..08051aa 100644 --- a/src/basic.asm +++ b/src/basic.asm @@ -1,2 +1,17 @@ - ; 10 SYS10240 ($2800) BASIC autostart - BYTE #$0b,#$08,#$0a,#$00,#$9e,#$31,#$30,#$32,#$34,#$30,#$00,#$00,#$00 +#if VERBOSE = 1 +LASTINIT SET . +#endif + + ; this is at $801 + ; and it MUST be exactly at this location in order to autostart + ; 10 SYS2060 ($80c) BASIC autostart + BYTE #$0b,#$08,#$0a,#$00,#$9e,#$32,#$30,#$36,#$31,#$00,#$00,#$00 + + ; this is at (2061 dec)=($80d) + ; and it MUST be exactly after the above BASIC statement +. = $80d + jmp start + +#if VERBOSE = 1 + ECHO "basic.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif diff --git a/src/cart.asm b/src/cart.asm new file mode 100644 index 0000000..8126107 --- /dev/null +++ b/src/cart.asm @@ -0,0 +1,47 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + +cartridge SUBROUTINE + + WORD #$8009 + WORD #$801a + + ; CBM80 in PETSCII (cartridge signature for autostart) + BYTE #$c3,#$c2,#$cd,#$38,#$30 + +.coldstart: + sei + stx $d016 + jsr $fda3 + jsr $fd50 + jsr $fd15 + jsr $ff5b + cli + +.warmstart: + ; Copy cartridge content into proper memory location + ldx #$20 + lda #$0 + tay + sta srcPointer + sta dstPointer + lda #>cartridgeStart + sta srcPointer + 1 + lda #$08 + sta dstPointer + 1 +.loop: + lda (srcPointer),y + sta (dstPointer),y + iny + bne .loop + inc srcPointer + 1 + inc dstPointer + 1 + dex + bne .loop + + jmp start + +#if VERBOSE = 1 + ECHO "cart.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/data.asm b/src/data.asm index e644466..bfe32d3 100644 --- a/src/data.asm +++ b/src/data.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Data section - Not initialized variables ($CD00 - $CDFF) ; ---------------------------------------------------------------------- ; Number of interrupt @@ -50,3 +54,6 @@ delayStatus: score: WORD +#if VERBOSE = 1 + ECHO "data.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/game.asm b/src/game.asm index cee09b0..31e65aa 100644 --- a/src/game.asm +++ b/src/game.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + statusPlay: ; do Game ; Check counter ldx irqn @@ -334,4 +338,6 @@ 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 37ff5fe..21cd655 100644 --- a/src/gameover.asm +++ b/src/gameover.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Game is over ; ---------------------------------------------------------------------- gameover: @@ -21,4 +25,6 @@ gameover: 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 c9fceb7..282abe7 100644 --- a/src/initdata.asm +++ b/src/initdata.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Initialized variables ; ---------------------------------------------------------------------- @@ -95,3 +99,6 @@ noMoreLevelsString: levelsList: INCBIN "../res.bin/levels.bin" +#if VERBOSE = 1 + ECHO "initdata.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/intro1.asm b/src/intro1.asm index 9f2625b..f504feb 100644 --- a/src/intro1.asm +++ b/src/intro1.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Currently statusIntro0 is the same as statusIntro1 ; statusIntro1 has just been reserved for future use statusIntro0: @@ -77,4 +81,6 @@ status1okset: ; For now, just return. rts - +#if VERBOSE = 1 + ECHO "intro1.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/introreset.asm b/src/introreset.asm index 8efa028..4351ef5 100644 --- a/src/introreset.asm +++ b/src/introreset.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Intro reset ; ---------------------------------------------------------------------- introreset: @@ -44,4 +48,6 @@ introresetColorShade rts - +#if VERBOSE = 1 + ECHO "introreset.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/levelreset.asm b/src/levelreset.asm index 73be5ef..88983bc 100644 --- a/src/levelreset.asm +++ b/src/levelreset.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Reset variables for a new level ; ---------------------------------------------------------------------- levelresetvar: @@ -32,3 +36,6 @@ 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 458dd91..301392b 100644 --- a/src/levels.asm +++ b/src/levels.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; load new level on the screen statusLevelTitle SUBROUTINE jsr clearScreen @@ -162,3 +166,6 @@ writeLevelEnd: sta status rts +#if VERBOSE = 1 + ECHO "levels.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/main.asm b/src/main.asm index 1776923..e8daa60 100644 --- a/src/main.asm +++ b/src/main.asm @@ -15,21 +15,38 @@ org $02 INCLUDE "zeropage.asm" -#if DEBUG = 1 +#if VERBOSE = 1 ; Locations $90-$FF in zeropage are used by kernal ECHO "End of zeropage variables. Space left: ",($90 - .) #endif ; Initialized segments ; ---------------------------------------------------------------------- - SEG constSegment + SEG autostartSegment +#if CARTRIDGE = 0 org $801 - INCLUDE "basic.asm" ; BASIC must stay at this address - INCLUDE "initdata.asm" -#if DEBUG = 1 - ECHO "End of Initialized Data (const) + Basic Segment. Space left: ",($1000 - .) + INCLUDE "basic.asm" ; BASIC _MUST_ stay at this address +#else + org $800 + INCLUDE "cart.asm" #endif + INCLUDE "initdata.asm" +; Program "Segment" Low +; ---------------------------------------------------------------------- +; You just have to fill this empty space, don't you think so? ;-) + INCLUDE "game.asm" + INCLUDE "gameover.asm" + INCLUDE "introreset.asm" + INCLUDE "program.asm" + INCLUDE "subroutines.asm" + INCLUDE "levels.asm" + INCLUDE "intro1.asm" +; Note: some code had to be included at an higher address + +#if VERBOSE = 1 + ECHO "End of Low Program Segment. Space left:",($1000 - .) +#endif ; SID tune (previously properly cleaned, see HVSC) ; ---------------------------------------------------------------------- @@ -37,8 +54,14 @@ org $1000 sidtune: INCBIN "../res.bin/amour.sid" -#if DEBUG = 1 - ECHO "End of SIDtune. Space left: ",($2000 - .) +#if VERBOSE = 1 + ECHO "End of SIDtune at ",. +#endif + INCLUDE "multicolor.asm" + INCLUDE "levelreset.asm" + INCLUDE "outro.asm" +#if VERBOSE = 1 + ECHO "End of Middle Program Segment. Space left:",($2000 - .) #endif ; Font Data @@ -49,40 +72,36 @@ sidtune: tggsFont: INCLUDE "tggs.asm" -; Include program +; Program Segment High ; ---------------------------------------------------------------------- - SEG programSegment - org $2800 - jmp start - INCLUDE "game.asm" - INCLUDE "gameover.asm" - INCLUDE "levelreset.asm" - INCLUDE "introreset.asm" - INCLUDE "intro1.asm" - INCLUDE "multicolor.asm" - INCLUDE "outro.asm" - INCLUDE "program.asm" - INCLUDE "subroutines.asm" - INCLUDE "levels.asm" - -#if DEBUG = 1 - ECHO "End of program at: ",.,"Space left:",($cd00 - .) +#if VERBOSE = 1 + ECHO "End of High Program Segment at: ",.,"Space left:",($cd00 - .) #endif -#if DEBUG = 1 +#if VERBOSE = 1 +#if CARTRIDGE = 0 ; +2 because of PRG header ECHO "PRG size:",([. - $801 + 2]d),"dec" +#else + ECHO "BIN size:",([. - $800]d),"dec" +#endif #endif ; Uninitialized segments ; ---------------------------------------------------------------------- +; Cartridge locations +; ------------------- + SEG.U cartridgeSegment + org $8000 +cartridgeStart: + ; Data variables ; ----------------- SEG.U dataSegment org $cd00 INCLUDE "data.asm" -# if DEBUG = 1 +#if VERBOSE = 1 ECHO "End of Data segment. Space left:",($ce00 - .) #endif diff --git a/src/multicolor.asm b/src/multicolor.asm index fa55e50..f5537a2 100644 --- a/src/multicolor.asm +++ b/src/multicolor.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + processor 6502 multicolor SUBROUTINE @@ -39,3 +43,7 @@ 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 d283c2b..a8d36e2 100644 --- a/src/outro.asm +++ b/src/outro.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Wait for some delay statusDelay SUBROUTINE ldy delay ; load outroDelay and decrement @@ -11,3 +15,6 @@ statusDelay SUBROUTINE 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 9b8387e..9954bee 100644 --- a/src/program.asm +++ b/src/program.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; ENTRY OF PROGRAM ; ---------------------------------------------------------------------- start: @@ -186,4 +190,6 @@ checkEndStatus: ; Go to original system routine jmp $ea31 - +#if VERBOSE = 1 + ECHO "program.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/subroutines.asm b/src/subroutines.asm index 8ef8b91..47fdb0d 100644 --- a/src/subroutines.asm +++ b/src/subroutines.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; Subroutines ; ---------------------------------------------------------------------- @@ -161,3 +165,6 @@ nextPointer: rts +#if VERBOSE = 1 + ECHO "subroutines.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/tggs.asm b/src/tggs.asm index 189ccd5..d7f1294 100644 --- a/src/tggs.asm +++ b/src/tggs.asm @@ -1,3 +1,7 @@ +#if VERBOSE = 1 +LASTINIT SET . +#endif + ; char 0x0, 0 BYTE #%00000000 BYTE #%00000000 @@ -2558,3 +2562,7 @@ BYTE #%11100001 BYTE #%01010101 BYTE #%00000000 + +#if VERBOSE = 1 + ECHO "tggs.asm @ ",LASTINIT,"len:",(. - LASTINIT) +#endif \ No newline at end of file diff --git a/src/zeropage.asm b/src/zeropage.asm index b95927a..4c9a5b0 100644 --- a/src/zeropage.asm +++ b/src/zeropage.asm @@ -22,6 +22,10 @@ nextPointerPointer DS 2 ; Pointer to string for strlen routine strlenString DS 2 +; Generic src/dst copy pointers +srcPointer DS 2 +dstPointer DS 2 + ; Note: Locations $90-$FF in zeropage are used by kernal