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
```$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

View File

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

View File

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

View File

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

View File

@ -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
lda #>levelsList
sta levelPointer + 1
rts

View File

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

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

View File

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

View File

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

View File

@ -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';
}