level layout is unpacked on screen correctly

This commit is contained in:
giomba 2020-04-02 16:17:48 +02:00
parent f628645740
commit 5fb94c3162
11 changed files with 180 additions and 55 deletions

View File

@ -19,11 +19,12 @@ Address | PRG | Description
```$0000 - $0001``` | no | hardware ```$0000 - $0001``` | no | hardware
```$0002 - $00FF``` | no | zero page pointers ```$0002 - $00FF``` | no | zero page pointers
```$0100 - $07FF``` | no | *free ram* ```$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 ```$1000 - $1FFF``` | yes | SID tune
```$2000 - $27FF``` | yes | custom char ```$2000 - $27FF``` | yes | custom char
```$2800 - $xxxx``` | yes | program logic (only needed part used) ```$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 ```$CE00 - $CEFF``` | no | list X
```$CF00 - $CFFF``` | no | list Y ```$CF00 - $CFFF``` | no | list Y
```$D000 - $DFFF``` | no | I/O ```$D000 - $DFFF``` | no | I/O

View File

@ -1,7 +1,6 @@
TITLE TITLE
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x x x fffffffffff x
x x
x x x x
x x x x
x x x x
@ -38,8 +37,7 @@ TITLE 2
..................x..................... ..................x.....................
..................x..................... ..................x.....................
..................x..................... ..................x.....................
..................x..................... ..................x........f............
..................x.....................
..................x..................... ..................x.....................
..................x..................... ..................x.....................
..................x..................... ..................x.....................

View File

@ -1,4 +1,4 @@
; Data section ; Data section - Not initialized variables ($CD00 - $CDFF)
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
; Number of interrupt ; Number of interrupt
; Used as counter to be decremented to do some things less frequently ; Used as counter to be decremented to do some things less frequently
@ -36,18 +36,4 @@ random:
status: status:
BYTE BYTE
; Intro counter
introCounter:
BYTE #$4
; Intro string x position, and next increment
introX:
BYTE #$0
introXinc:
BYTE #$1
; Outro delay
outroDelay
BYTE #$ff

View File

@ -239,6 +239,15 @@ genFoodY: ; calculate `random` modulo 22 (22 = SCREEN_H - 1)
cmp snakeY cmp snakeY
beq genFood beq genFood
foodOK: 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 ldy #0
jsr calcTileMem ; calc food address in memory jsr calcTileMem ; calc food address in memory
@ -306,12 +315,8 @@ checkEndWallHit:
lda #$20 ; just put a space to erase snake tail tile lda #$20 ; just put a space to erase snake tail tile
sta (tileMem),y sta (tileMem),y
checkLevel: ; lda #WALL_COLOR
; TODO ; sta $d860,y
lda #WALL_TILE
sta $460
lda #WALL_COLOR
sta $d860
skipPauseTests: skipPauseTests:

View File

@ -38,8 +38,6 @@ upperbarLoop:
jsr printStatus jsr printStatus
; Init game variables ; Init game variables
lda #FOOD_TILE
sta $500 ; Put first piece of food
lda #4 lda #4
sta irqn ; Initialize interrupt divider sta irqn ; Initialize interrupt divider
lda #6 lda #6
@ -65,5 +63,11 @@ clearListLoop:
cpx #$00 cpx #$00
bne clearListLoop bne clearListLoop
; Set current level pointer to list start
lda #<levelsList
sta levelPointer
lda #>levelsList
sta levelPointer + 1
rts rts

View File

@ -1,12 +1,31 @@
; 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 ; Costants
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
; Status of the game (costants pre-processor defined, sort of enum) ; Status of the game (costants pre-processor defined, sort of enum)
ST_INTRO0 = 0 ST_INTRO0 = 0
ST_INTRO1 = 1 ST_INTRO1 = 1
ST_PLAY = 2 ST_LEVELSELECT = 2
ST_OUTRO = 3 ST_PLAY = 3
ST_END = 4 ST_OUTRO = 4
ST_END = 5
ST_PAUSE = 255 ST_PAUSE = 255
; Screen features ; Screen features
@ -54,3 +73,8 @@ scoreString:
BYTE "POINTS" BYTE "POINTS"
BYTE #0 BYTE #0
; Levels
; ----------------------------------------------------------------------
levelsList:
INCBIN "../res.bin/levels.bin"

72
src/levels.asm Normal file
View File

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

View File

@ -22,13 +22,12 @@
; Initialized segments ; Initialized segments
; ---------------------------------------------------------------------- ; ----------------------------------------------------------------------
SEG dataSegment SEG constSegment
org $801 org $801
INCLUDE "basic.asm" ; BASIC must stay at this address INCLUDE "basic.asm" ; BASIC must stay at this address
INCLUDE "data.asm" INCLUDE "initdata.asm"
INCLUDE "const.asm"
#if DEBUG = 1 #if DEBUG = 1
ECHO "End of Data + Basic Segment. Space left: ",($1000 - .) ECHO "End of Initialized Data (const) + Basic Segment. Space left: ",($1000 - .)
#endif #endif
@ -65,9 +64,10 @@ tggsFont:
INCLUDE "outro.asm" INCLUDE "outro.asm"
INCLUDE "program.asm" INCLUDE "program.asm"
INCLUDE "subroutines.asm" INCLUDE "subroutines.asm"
INCLUDE "levels.asm"
#if DEBUG = 1 #if DEBUG = 1
ECHO "End of program at: ",.,"Space left:",($ce00 - .) ECHO "End of program at: ",.,"Space left:",($cd00 - .)
#endif #endif
#if DEBUG = 1 #if DEBUG = 1
@ -75,8 +75,19 @@ tggsFont:
ECHO "PRG size:",([. - $801 + 2]d),"dec" ECHO "PRG size:",([. - $801 + 2]d),"dec"
#endif #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 SEG.U listSegment
org $ce00 org $ce00
listX DS 256 listX DS 256

View File

@ -75,8 +75,9 @@ intro0end:
; Set init variables of the game ; Set init variables of the game
jsr gamereset jsr gamereset
; Set status as game playing ; Set status as level select
lda #ST_PLAY ; (then it will enter in status play)
lda #ST_LEVELSELECT
sta status sta status
endless: endless:
@ -115,24 +116,29 @@ irq:
; Sort of switch-case ; Sort of switch-case
lda status lda status
cmp #ST_INTRO0 cmp #ST_INTRO0
bne checkStatus1 bne checkStatusIntro1
jsr statusIntro0 jsr statusIntro0
jmp checkEndStatus jmp checkEndStatus
checkStatus1: checkStatusIntro1:
cmp #ST_INTRO1 cmp #ST_INTRO1
bne checkStatus2 bne checkStatusPlay
jsr statusIntro1 jsr statusIntro1
jmp checkEndStatus jmp checkEndStatus
checkStatus2 checkStatusPlay:
cmp #ST_PLAY cmp #ST_PLAY
bne checkStatus3 bne checkStatusOutro
jsr statusPlay jsr statusPlay
jmp checkEndStatus jmp checkEndStatus
checkStatus3 checkStatusOutro:
cmp #ST_OUTRO cmp #ST_OUTRO
bne checkEndStatus bne checkStatusLevelSelect
jsr statusOutro jsr statusOutro
jmp checkEndStatus jmp checkEndStatus
checkStatusLevelSelect:
cmp #ST_LEVELSELECT
bne checkEndStatus
jsr statusLevelSelect
jmp checkEndStatus
checkEndStatus: checkEndStatus:
#if DEBUG = 1 #if DEBUG = 1

View File

@ -12,6 +12,18 @@ printIntroString DS 2
; Pointer to screen position where to print intro string ; Pointer to screen position where to print intro string
introScreenStart DS 2 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 ; Note: Locations $90-$FF in zeropage are used by kernal

View File

@ -4,13 +4,16 @@ using namespace std;
const int MAXLEN = 64; const int MAXLEN = 64;
void flush(char last, int count) { void flush(char last, int count) {
char tile;
switch(last) { switch(last) {
case 'x': case 'x':
cout << (char)91; break; tile = (char)91; break;
case 'f':
tile = (char)90; break;
default: default:
cout << (char)32; break; tile = (char)32; break;
} }
cout << (char)count; cout << tile << (char)count;
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
@ -20,17 +23,18 @@ int main(int argc, char** argv) {
while (true) { while (true) {
cin.getline(line, MAXLEN); cin.getline(line, MAXLEN);
if (line[0] == 'Z') break; if (line[0] == 'Z') break;
cout << line << '\0'; /* the title */ // cout << line << '\0'; /* the title */
int count = 0; int count = 0;
char last = '\0'; char last = '\0';
char current = '\0'; char current = '\0';
while(true) { //for (int i = 0; i < 25; ++i) { while(true) {
cin.getline(line, MAXLEN); cin.getline(line, MAXLEN);
if (line[0] == 'z') { if (line[0] == 'z') {
flush(current, count); flush(current, count);
cout << '\0' << '\0';
break; break;
} }
@ -47,4 +51,6 @@ int main(int argc, char** argv) {
} }
} }
} }
cout << '\0' << '\0';
} }