From 85ac2cf9714d34e6799b6867d7ec2abc7a438771 Mon Sep 17 00:00:00 2001 From: giomba Date: Sun, 7 Nov 2021 18:14:59 +0100 Subject: [PATCH] refactoring: wip: move code segments --- Makefile | 6 +-- res.org/amour.sid | Bin 3983 -> 0 bytes res.org/amour2.sid | Bin 0 -> 4236 bytes src/cart.asm | 6 +-- src/game.asm | 1 + src/intro1.asm | 13 +++++- src/levels.asm | 6 +++ src/loader.asm | 6 +-- src/lzgmini.asm | 106 +++++++++++++++++++++++--------------------- src/macro.asm | 6 +-- src/main.asm | 6 ++- src/subroutines.asm | 12 +++++ src/zeropage.asm | 18 +------- 13 files changed, 101 insertions(+), 85 deletions(-) delete mode 100644 res.org/amour.sid create mode 100644 res.org/amour2.sid diff --git a/Makefile b/Makefile index 31accc5..4df18a2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .POSIX: ASM=$(wildcard src/*.asm) -RES=res.bin/amour.sid res.bin/levels.bin res.bin/unlzg.bin +RES=res.bin/amour2.sid res.bin/levels.bin res.bin/unlzg.bin .PHONY: debug env clean all @@ -43,8 +43,8 @@ env: bin/explodefont: util/explodefont.cpp g++ -o bin/explodefont util/explodefont.cpp -res.bin/amour.sid: - cp res.org/amour.sid res.bin/amour.sid +res.bin/amour2.sid: + cp res.org/amour2.sid res.bin/amour2.sid res.bin/levels.bin: bin/level res.org/levels.txt bin/level < res.org/levels.txt > res.bin/levels.bin diff --git a/res.org/amour.sid b/res.org/amour.sid deleted file mode 100644 index 14bd82a30ebb74fa4c2424f4a9c26101ba87d509..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3983 zcmbUjZE#f8^}hYyWs`j`pXad&`(j`)fKHj)uwb@E^7h1=)d5{R$eYJL8odpXTl>X>cz~m`bDR#3x_iYlF>d+}C zd+xdSo^#Lly?NfNtamHtE#POayz_ox!Q4vW_Ep0B^{eKcT6XUp_1>B8`EHNkTxp=x#eOMm*Re8rC6f9c-*+i#ZiezxS-_D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hiRa9#euaUc$!Cs`d6Wi^WY)XJ zXjRsStgo-{ z?8G4pI`KFWGG zq$_;XVzrHp=29-@7!7C=kN0BdX~thfZJ#KE(QtJ0Vpa`AX-I)L2noD}c$9=277OKz z!#>jCvo_PY(Co8^8#;vYj{4V<%-Yl z-}Fg?f%rIoovDE__)7enbos36o9?e$+`yQ8v;B492FBuBNM0N|?{qr#4o0UhDJdZi zgVCf>v&E{>FuILkwwUotTAxEW;Xjnh#@HVUcPsccNY`Ed1w!9cSo}^QsoJ_4q&2CUY7MJvFuE4|+BRp4 z{Tg(&KwCCW$Mv^pZxc{HgU}|>)>s>8boM;tUh8ae2i9g!U3AxVg987fIveLM@My-} zsQ-pB-Lug%*R#Nb$|@IBE<&uT^dLp7@>Eq))QmJ@AexaIp=nz|<_n4vlbll_`{t!!!gJeJn}D5j1`jSsgTd6d_*1{s-X^FKz$; diff --git a/res.org/amour2.sid b/res.org/amour2.sid new file mode 100644 index 0000000000000000000000000000000000000000..8df7eeb6f1bfb1077223c7662cfdd28c5be16d0b GIT binary patch literal 4236 zcmbtWYj7LY6}~H3*3;IJWy#XY&)}Mvd{-kEU)_AT{)zN zPJi@h_ug~QIeYGTUR|jqAUz$BR)zh<1|oi)aS#~cEnsAc8#dn3v$lTCruwxv-FWNG zH%V8n>*?ybwNpwgUDmR!WvMC8I!YNEa$^$oO>Q=T6>~GzEIK=dQnpTXHrPtpX3@?{ zYywzzz5``eEw=eyqw5CzggkAO`Nt7}Lmf`UV=zM zGC|Ut->jreC237C5m-4z?gLoZ>YJzHOUYt^N<{w%tWcoPjb~{CQNc@ zGE+rzc(Ql!eDB~)Qr$qBkjw<=4IAs5Gg-eNrBJrIOUrrx)nc*{_Yh6VudqZq+CVN*5#%zT#x#Q#2-PrvxQl27Zn3N$> z21%JBWtw`WKL%l{h%X_rmDJs&d8`C7WgAH=Dstz?;b@S1U~J{~?<8p^2oJb{s1hU` zPHZJFOYy^`?a_ zeY{enx**&v$8t9*y9ql=Z@~nuNi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F39Q`d0W=Pv*J z6<4;lEx%^<+O7>Z-MVS(U0?0n`|!RezH>13qB=48?%6r@Rl;TEPTVXqzu@(m;PrYuVSq;vs9>`NTqaahxLlzSNB#bSjg^;|mpV(G z))=fTgL9x-;KY4#6JY;cdpGT6cBj{0A=Wir!9xWW69ilz%}XLC#0)n^W@86BM;jU% zMm~8*hN2uIqeIc|1EWJd-3Ksnc4r_k%CE8|PCJx4S&7^0WBw_h$K|jKY-&+RV^ig2 zl25`d)ZOIsLDbK$h$FZz7T5@5dIxpb7`b$pi~0Di5mdjA8JI`e08AP%21*8CA^*8t z+`c-dKlsSVk8@{(%eSPwqi=t4_c2#EzH8{|4`L=%18Qn&YHMrjESMWG0EOduHrEj_ zLWXFBjlx_v+bbZHJ`lwQ!=iFl=&D4Tv@)(9b6at^X4*?deMXW^;{1EseV8J?!bvO)u0DRs; z3)V#|0*H?hutuPv5MLKZprXjv#Sv&Y%-6*cXyF8}8K1#@Ft{@&26fhBa*5MIoNHm& z!g@?@h;v2GwJ>aGJtjB6xna(=Fl=us;C1){*jMpbN|AyYSOZD8x}I@mV8|lEH*RM3=VDCT5KU ziVhP>5Iws<1|9sLl)_v+S{1QCbD515H@gl*-ipmeVhNaw@y_z97utBK@}W4R)_Jk> zp*W+;7s|L6Qml&LMTeT^6)}%FK8wbS7q!i6V;*ya^6dCRng|+doL33tOw93Fv@qmQ P>%3kdXJU>|(F*?tsqCb+ literal 0 HcmV?d00001 diff --git a/src/cart.asm b/src/cart.asm index a3263b1..33e5b10 100644 --- a/src/cart.asm +++ b/src/cart.asm @@ -2,11 +2,10 @@ SEG.U zeropageSegment org $02 - INCLUDE "zeropage.asm" - - SEG cartridgeSegment + SEG loaderSegment org $8000 + SEG loaderSegment cartridge SUBROUTINE WORD .coldstart WORD .warmstart @@ -55,4 +54,3 @@ cartridge SUBROUTINE ; force filler for the *PROM . = $9fff BYTE #$ff - diff --git a/src/game.asm b/src/game.asm index 31e65aa..8675f42 100644 --- a/src/game.asm +++ b/src/game.asm @@ -2,6 +2,7 @@ LASTINIT SET . #endif + SEG programSegment statusPlay: ; do Game ; Check counter ldx irqn diff --git a/src/intro1.asm b/src/intro1.asm index b4373c6..7d2a0e6 100644 --- a/src/intro1.asm +++ b/src/intro1.asm @@ -2,6 +2,12 @@ LASTINIT SET . #endif + SEG zeropageSegment +; Generic src/dst copy pointers +srcPointer DS 2 +dstPointer DS 2 + + SEG programSegment introreset SUBROUTINE jsr multicolorOff @@ -425,7 +431,7 @@ statusMenuReset SUBROUTINE ; Print Game Title: big "SNAKE" ; color first - MEMSET #$d800, #$02, #200 + MEMSET #$d800, #$02, #150 ; actual "text" lda #$00 sta dstPointer @@ -514,6 +520,11 @@ SnakeText: HEX 80 80 80 80 80 80 80 80 80 80 80 a0 80 a0 80 80 a0 80 a0 80 80 a0 80 a0 a0 f7 80 a0 80 80 80 80 80 80 80 80 80 80 80 80 HEX 80 80 80 80 80 80 80 80 f6 a0 a0 f9 80 f8 80 80 f8 80 f9 80 80 f8 80 a0 f8 f9 80 f8 a0 a0 f7 80 80 80 80 80 80 80 80 80 +;ParabolicSpaceChars: +; HEX 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +;ParabolicSpaceScroll: +; HEX 00 01 01 01 01 01 01 01 02 02 02 03 03 04 04 05 06 06 07 00 00 01 02 03 04 05 06 07 00 01 02 04 05 06 00 01 02 04 05 07 00 02 04 05 07 00 01 03 04 06 00 01 03 04 06 07 00 02 03 04 06 07 00 01 02 03 04 05 06 07 00 01 02 02 03 04 04 05 05 06 06 06 07 06 07 07 07 07 07 07 07 + setupXScrollInterrupt SUBROUTINE ldx #XScrollInterruptH diff --git a/src/levels.asm b/src/levels.asm index 333903b..8a57499 100644 --- a/src/levels.asm +++ b/src/levels.asm @@ -2,6 +2,12 @@ LASTINIT SET . #endif + SEG zeropageSegment +; Pointer to video memory used in the level loading routine +levelVideoPointer WORD +levelColorPointer WORD + + SEG programSegment ; load new level on the screen statusLevelTitle SUBROUTINE jsr multicolorOff diff --git a/src/loader.asm b/src/loader.asm index 50dfd21..46567d8 100644 --- a/src/loader.asm +++ b/src/loader.asm @@ -1,10 +1,9 @@ processor 6502 - SEG.U + SEG.U zeropageSegment org $02 - INCLUDE "zeropage.asm" - SEG autostart + SEG loaderSegment org $801 autostartRoutine SUBROUTINE ; this is at $801 @@ -50,6 +49,7 @@ autostartRoutine SUBROUTINE ; DATA ; ------------------------------------- + SEG loaderSegment packFileName: BYTE "PACKLZ" packFileNameEnd: diff --git a/src/lzgmini.asm b/src/lzgmini.asm index 66a7370..c74f970 100644 --- a/src/lzgmini.asm +++ b/src/lzgmini.asm @@ -1,44 +1,48 @@ -inflate SUBROUTINE -.inEnd EQU 2 -.offset EQU 4 -.length EQU 6 -.symbol EQU 25 -.marker1 EQU 30 -.marker2 EQU 31 -.marker3 EQU 32 -.marker4 EQU 33 -.copy EQU 34 + SEG zeropageSegment +srcPointer WORD +dstPointer WORD +inEnd WORD +offset WORD +length BYTE +symbol BYTE +marker1 BYTE +marker2 BYTE +marker3 BYTE +marker4 BYTE +copy WORD + SEG loaderSegment +inflate SUBROUTINE clc ldy #10 lda (srcPointer),y adc srcPointer - sta .inEnd + sta inEnd dey lda (srcPointer),y adc srcPointer + 1 - sta .inEnd + 1 + sta inEnd + 1 clc - lda .inEnd + lda inEnd adc #16 - sta .inEnd - lda .inEnd + 1 + sta inEnd + lda inEnd + 1 adc #0 - sta .inEnd + 1 + sta inEnd + 1 ; Get the marker symbols ldy #16 lda (srcPointer),y - sta .marker1 + sta marker1 iny lda (srcPointer),y - sta .marker2 + sta marker2 iny lda (srcPointer),y - sta .marker3 + sta marker3 iny lda (srcPointer),y - sta .marker4 + sta marker4 ; Skip header + marker symbols (16 + 4 bytes) clc @@ -53,30 +57,30 @@ inflate SUBROUTINE ldy #0 ; Make sure that Y is zero .mainloop: lda srcPointer ; done? - cmp .inEnd + cmp inEnd bne .notdone lda srcPointer + 1 - cmp .inEnd + 1 + cmp inEnd + 1 bne .notdone rts .notdone: lda (srcPointer),y ; A = symbol - sta .symbol + sta symbol sta $d020 inc srcPointer bne .noinc1 inc srcPointer + 1 .noinc1: - cmp .marker1 ; Marker1? + cmp marker1 ; Marker1? beq .domarker1 - cmp .marker2 ; Marker2? + cmp marker2 ; Marker2? beq .domarker2 - cmp .marker3 ; Marker3? + cmp marker3 ; Marker3? beq .domarker3 - cmp .marker4 ; Marker4? + cmp marker4 ; Marker4? beq .domarker4 .literal: - lda .symbol + lda symbol sta (dstPointer),y ; Plain copy inc dstPointer bne .mainloop @@ -101,15 +105,15 @@ inflate SUBROUTINE lsr lsr lsr - sta .offset - inc .offset + sta offset + inc offset lda #0 - sta .offset + 1 ; offset = (b >> 5) + 1 + sta offset + 1 ; offset = (b >> 5) + 1 txa and #$1f tax lda .LZG_LENGTH_DECODE_LUT,x - sta .length ; length = .LZG_LENGTH_DECODE_LUT[b & 0x1f] + sta length ; length = .LZG_LENGTH_DECODE_LUT[b & 0x1f] jmp .docopy ; marker3 - "Short copy" @@ -130,13 +134,13 @@ inflate SUBROUTINE lsr clc adc #3 - sta .length ; length = (b >> 6) + 3 + sta length ; length = (b >> 6) + 3 txa and #$3f adc #8 - sta .offset + sta offset lda #0 - sta .offset + 1 ; offset = (b & 0x3f) + 8 + sta offset + 1 ; offset = (b & 0x3f) + 8 beq .docopy ; marker2 - "Medium copy" @@ -154,7 +158,7 @@ inflate SUBROUTINE lsr lsr lsr - sta .offset + 1 + sta offset + 1 lda (srcPointer),y inc srcPointer bne .noinc6 @@ -162,15 +166,15 @@ inflate SUBROUTINE .noinc6: clc adc #8 - sta .offset + sta offset bcc .noinc7 - inc .offset + 1 ; offset = (((b & 0xe0) << 3) | b2) + 8 + inc offset + 1 ; offset = (((b & 0xe0) << 3) | b2) + 8 .noinc7: txa and #$1f tax lda .LZG_LENGTH_DECODE_LUT,x - sta .length ; length = .LZG_LENGTH_DECODE_LUT[b & 0x1f] + sta length ; length = .LZG_LENGTH_DECODE_LUT[b & 0x1f] bne .docopy .literal2: @@ -188,13 +192,13 @@ inflate SUBROUTINE and #$1f tax lda .LZG_LENGTH_DECODE_LUT,x - sta .length ; length = .LZG_LENGTH_DECODE_LUT[b & 0x1f] + sta length ; length = .LZG_LENGTH_DECODE_LUT[b & 0x1f] lda (srcPointer),y inc srcPointer bne .noinc9 inc srcPointer + 1 .noinc9: - sta .offset + 1 + sta offset + 1 lda (srcPointer),y inc srcPointer bne .noinc10 @@ -202,31 +206,31 @@ inflate SUBROUTINE .noinc10: clc adc #$08 - sta .offset - lda .offset + 1 + sta offset + lda offset + 1 adc #$08 - sta .offset + 1 ; offset = ((b2 << 8) | (*src++)) + 2056 + sta offset + 1 ; offset = ((b2 << 8) | (*src++)) + 2056 ; Copy corresponding data from history window .docopy: sec lda dstPointer - sbc .offset - sta .copy + sbc offset + sta copy lda dstPointer + 1 - sbc .offset + 1 - sta .copy + 1 + sbc offset + 1 + sta copy + 1 .loop1: - lda (.copy),y + lda (copy),y sta (dstPointer),y iny - cpy .length + cpy length bne .loop1 ldy #0 ; Make sure that Y is zero clc lda dstPointer - adc .length + adc length sta dstPointer bcc .noinc11 inc dstPointer + 1 diff --git a/src/macro.asm b/src/macro.asm index 70c253e..0d151c9 100644 --- a/src/macro.asm +++ b/src/macro.asm @@ -1,8 +1,6 @@ SEG zeropageSegment -ptrDstStart: - WORD -ptrDstEnd: - WORD +ptrDstStart WORD +ptrDstEnd WORD MACRO MEMSET SEG programSegment diff --git a/src/main.asm b/src/main.asm index 72dcafd..e6dd253 100644 --- a/src/main.asm +++ b/src/main.asm @@ -13,7 +13,6 @@ ; ---------------------------------------------------------------------- SEG.U zeropageSegment org $02 - INCLUDE "zeropage.asm" #if VERBOSE = 1 ; Locations $90-$FF in zeropage are used by kernal @@ -74,8 +73,11 @@ sidtune: listX DS 256 listY DS 256 +; Includes + INCLUDE "zeropage.asm" + ; -; coded 2017, 2018, 2019, 2020 +; coded 2017, 2018, 2019, 2020, 2021 ; by giomba -- giomba at glgprograms.it ; this software is free software and is distributed ; under the terms of GNU GPL v3 license diff --git a/src/subroutines.asm b/src/subroutines.asm index 76d0fed..b021179 100644 --- a/src/subroutines.asm +++ b/src/subroutines.asm @@ -4,7 +4,12 @@ LASTINIT SET . ; Subroutines ; ---------------------------------------------------------------------- + SEG zeropageSegment +; Where is the snake head in video memory? Do math to calculate address +; using pointer at tileMem +tileMem WORD + SEG programSegment ; Clear screen -- easy clearScreen SUBROUTINE ldx #$ff @@ -91,6 +96,13 @@ printByte SUBROUTINE rts + SEG zeropageSegment +; Pointer to string +srcStringPointer WORD +; Pointer to screen position where to print intro string +dstScreenPointer DS 2 + + SEG programSegment printString SUBROUTINE ; Print string ; Input parameters: diff --git a/src/zeropage.asm b/src/zeropage.asm index 9b3e834..d44b9fb 100644 --- a/src/zeropage.asm +++ b/src/zeropage.asm @@ -1,31 +1,15 @@ ; Zero page utility pointers ; ---------------------------------------------------------------------- -; Where is the snake head in video memory? Do math to calculate address -; using pointer at tileMem,tileMem+1 -tileMem DS 2 - -; Pointer to string -srcStringPointer DS 2 -; Pointer to screen position where to print intro string -dstScreenPointer DS 2 - + SEG zeropageSegment ; Pointer to level struct levelPointer DS 2 -; Pointer to video memory used in the level loading routine -levelVideoPointer DS 2 -levelColorPointer DS 2 - ; Pointer for Pointer in the NextPointer routine nextPointerPointer DS 2 ; Pointer to string for strlen routine strlenString DS 2 -; Generic src/dst copy pointers -srcPointer DS 2 -dstPointer DS 2 - ; Interrupt counter counter DS 2