diff --git a/README.md b/README.md index 8f0572c..7a5877c 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,12 @@ Address | PRG | Description ```$0000 - $0001``` | no | hardware ```$0002 - $00FF``` | no | zero page pointers ```$0100 - $07FF``` | no | *free ram* -```$0800 - $0FFF``` | yes | data segment + BASIC autostart +```$0800 - $0FFF``` | yes | initialized data segment (incl. const) + BASIC autostart ```$1000 - $1FFF``` | yes | SID tune ```$2000 - $27FF``` | yes | custom char ```$2800 - $xxxx``` | yes | program logic (only needed part used) -```$xxxx - $CDFF``` | no | *free ram* +```$xxxx - $CCFF``` | no | *free ram* +```$CD00 - $CDFF``` | no | data segment (not-initialized vars) ```$CE00 - $CEFF``` | no | list X ```$CF00 - $CFFF``` | no | list Y ```$D000 - $DFFF``` | no | I/O diff --git a/res.org/levels.txt b/res.org/levels.txt index 03f86ce..db4c5b1 100644 --- a/res.org/levels.txt +++ b/res.org/levels.txt @@ -1,7 +1,6 @@ TITLE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -x x -x x +x fffffffffff x x x x x x x @@ -38,8 +37,7 @@ TITLE 2 ..................x..................... ..................x..................... ..................x..................... -..................x..................... -..................x..................... +..................x........f............ ..................x..................... ..................x..................... ..................x..................... diff --git a/src/data.asm b/src/data.asm index 2a7b0e5..66ea614 100644 --- a/src/data.asm +++ b/src/data.asm @@ -1,4 +1,4 @@ -; Data section +; Data section - Not initialized variables ($CD00 - $CDFF) ; ---------------------------------------------------------------------- ; Number of interrupt ; Used as counter to be decremented to do some things less frequently @@ -36,18 +36,4 @@ random: status: BYTE -; Intro counter -introCounter: - BYTE #$4 - -; Intro string x position, and next increment -introX: - BYTE #$0 -introXinc: - BYTE #$1 - -; Outro delay -outroDelay - BYTE #$ff - diff --git a/src/game.asm b/src/game.asm index 290b99a..db957a4 100644 --- a/src/game.asm +++ b/src/game.asm @@ -239,6 +239,15 @@ genFoodY: ; calculate `random` modulo 22 (22 = SCREEN_H - 1) cmp snakeY beq genFood foodOK: +#if DEBUG = 1 + ; print choosen X,Y for food + ldy #$18 + lda calcTileX + jsr printByte + ldy #$1b + lda calcTileY + jsr printByte +#endif ldy #0 jsr calcTileMem ; calc food address in memory @@ -306,12 +315,8 @@ checkEndWallHit: lda #$20 ; just put a space to erase snake tail tile sta (tileMem),y -checkLevel: - ; TODO - lda #WALL_TILE - sta $460 - lda #WALL_COLOR - sta $d860 +; lda #WALL_COLOR +; sta $d860,y skipPauseTests: diff --git a/src/gamereset.asm b/src/gamereset.asm index e675d3a..5c57eed 100644 --- a/src/gamereset.asm +++ b/src/gamereset.asm @@ -38,8 +38,6 @@ upperbarLoop: jsr printStatus ; Init game variables - lda #FOOD_TILE - sta $500 ; Put first piece of food lda #4 sta irqn ; Initialize interrupt divider lda #6 @@ -65,5 +63,11 @@ clearListLoop: cpx #$00 bne clearListLoop + ; Set current level pointer to list start + lda #levelsList + sta levelPointer + 1 + rts diff --git a/src/const.asm b/src/initdata.asm similarity index 65% rename from src/const.asm rename to src/initdata.asm index a5abdaa..74270c6 100644 --- a/src/const.asm +++ b/src/initdata.asm @@ -1,13 +1,32 @@ +; Initialized variables +; ---------------------------------------------------------------------- + +; Intro counter +introCounter: + BYTE #$4 + +; Intro string x position, and next increment +introX: + BYTE #$0 +introXinc: + BYTE #$1 + +; Outro delay +outroDelay + BYTE #$ff + + ; Costants ; ---------------------------------------------------------------------- ; Status of the game (costants pre-processor defined, sort of enum) -ST_INTRO0 = 0 -ST_INTRO1 = 1 -ST_PLAY = 2 -ST_OUTRO = 3 -ST_END = 4 -ST_PAUSE = 255 +ST_INTRO0 = 0 +ST_INTRO1 = 1 +ST_LEVELSELECT = 2 +ST_PLAY = 3 +ST_OUTRO = 4 +ST_END = 5 +ST_PAUSE = 255 ; Screen features SCREEN_W = 40 @@ -54,3 +73,8 @@ scoreString: BYTE "POINTS" BYTE #0 +; Levels +; ---------------------------------------------------------------------- +levelsList: + INCBIN "../res.bin/levels.bin" + diff --git a/src/levels.asm b/src/levels.asm new file mode 100644 index 0000000..a36ec89 --- /dev/null +++ b/src/levels.asm @@ -0,0 +1,72 @@ +statusLevelSelect: ; select new level + + ldy #39 + sty tempPointer + ldy #$04 + sty tempPointer + 1 + +writeLevelLoop: + ldy #0 + lda (levelPointer),y + + pha + + lda #levelPointer + sta nextPointerPointer + ldx #1 + jsr nextPointer + + ldy #0 + lda (levelPointer),y + + pha + + lda #levelPointer + sta nextPointerPointer + ldx #1 + jsr nextPointer + + pla + + tay + tax + pla + + cmp #0 + beq writeLevelEnd +writeLevelElement: + sta (tempPointer),y + dey + bne writeLevelElement + + lda #tempPointer + sta nextPointerPointer + ; x still holds the total number + jsr nextPointer + jmp writeLevelLoop + +writeLevelEnd: + lda #ST_PLAY + 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/main.asm b/src/main.asm index 9da991e..a878648 100644 --- a/src/main.asm +++ b/src/main.asm @@ -22,13 +22,12 @@ ; Initialized segments ; ---------------------------------------------------------------------- - SEG dataSegment + SEG constSegment org $801 INCLUDE "basic.asm" ; BASIC must stay at this address - INCLUDE "data.asm" - INCLUDE "const.asm" + INCLUDE "initdata.asm" #if DEBUG = 1 - ECHO "End of Data + Basic Segment. Space left: ",($1000 - .) + ECHO "End of Initialized Data (const) + Basic Segment. Space left: ",($1000 - .) #endif @@ -65,9 +64,10 @@ tggsFont: INCLUDE "outro.asm" INCLUDE "program.asm" INCLUDE "subroutines.asm" + INCLUDE "levels.asm" #if DEBUG = 1 - ECHO "End of program at: ",.,"Space left:",($ce00 - .) + ECHO "End of program at: ",.,"Space left:",($cd00 - .) #endif #if DEBUG = 1 @@ -75,8 +75,19 @@ tggsFont: ECHO "PRG size:",([. - $801 + 2]d),"dec" #endif -; Uninitialized list segment +; Uninitialized segments ; ---------------------------------------------------------------------- +; Data variables +; ----------------- + SEG.U dataSegment + org $cd00 + INCLUDE "data.asm" +# if DEBUG = 1 + ECHO "End of Data segment. Space left:",($ce00 - .) +#endif + +; Lists +; ----------------- SEG.U listSegment org $ce00 listX DS 256 diff --git a/src/program.asm b/src/program.asm index fb411b8..af60580 100644 --- a/src/program.asm +++ b/src/program.asm @@ -75,8 +75,9 @@ intro0end: ; Set init variables of the game jsr gamereset - ; Set status as game playing - lda #ST_PLAY + ; Set status as level select + ; (then it will enter in status play) + lda #ST_LEVELSELECT sta status endless: @@ -115,24 +116,29 @@ irq: ; Sort of switch-case lda status cmp #ST_INTRO0 - bne checkStatus1 + bne checkStatusIntro1 jsr statusIntro0 jmp checkEndStatus -checkStatus1: +checkStatusIntro1: cmp #ST_INTRO1 - bne checkStatus2 + bne checkStatusPlay jsr statusIntro1 jmp checkEndStatus -checkStatus2 +checkStatusPlay: cmp #ST_PLAY - bne checkStatus3 + bne checkStatusOutro jsr statusPlay jmp checkEndStatus -checkStatus3 +checkStatusOutro: cmp #ST_OUTRO - bne checkEndStatus + bne checkStatusLevelSelect jsr statusOutro jmp checkEndStatus +checkStatusLevelSelect: + cmp #ST_LEVELSELECT + bne checkEndStatus + jsr statusLevelSelect + jmp checkEndStatus checkEndStatus: #if DEBUG = 1 diff --git a/src/zeropage.asm b/src/zeropage.asm index 0df0ee4..9cf9ea6 100644 --- a/src/zeropage.asm +++ b/src/zeropage.asm @@ -12,6 +12,18 @@ printIntroString DS 2 ; Pointer to screen position where to print intro string introScreenStart DS 2 +; Pointer to level struct +levelPointer DS 2 + +; Temporary pointer -- Use when you don't call a subroutine +tempPointer DS 2 + +; Pointer for Pointer in the NextPointer routine +nextPointerPointer DS 2 + +; Pointer to string for strlen routine +strlenString DS 2 + ; Note: Locations $90-$FF in zeropage are used by kernal diff --git a/util/rlevel.cpp b/util/rlevel.cpp index 800f81e..71fbd9d 100644 --- a/util/rlevel.cpp +++ b/util/rlevel.cpp @@ -4,13 +4,16 @@ using namespace std; const int MAXLEN = 64; void flush(char last, int count) { + char tile; switch(last) { case 'x': - cout << (char)91; break; + tile = (char)91; break; + case 'f': + tile = (char)90; break; default: - cout << (char)32; break; + tile = (char)32; break; } - cout << (char)count; + cout << tile << (char)count; } int main(int argc, char** argv) { @@ -20,17 +23,18 @@ int main(int argc, char** argv) { while (true) { cin.getline(line, MAXLEN); if (line[0] == 'Z') break; - cout << line << '\0'; /* the title */ + // cout << line << '\0'; /* the title */ int count = 0; char last = '\0'; char current = '\0'; - while(true) { //for (int i = 0; i < 25; ++i) { + while(true) { cin.getline(line, MAXLEN); if (line[0] == 'z') { flush(current, count); + cout << '\0' << '\0'; break; } @@ -47,4 +51,6 @@ int main(int argc, char** argv) { } } } + cout << '\0' << '\0'; } +