level loading colors with memory saving

loading colors was done in a dummy way by reading color of each tile
from the RLE array; but actually a tile always have the same color, then
this info is redundant; anyhow the character set had to be reshaped
properly in order to make easy infer the tile color from the tile value
This commit is contained in:
giomba 2020-04-06 22:53:28 +02:00
parent 90cc0dbabd
commit 22a5feb2a1
6 changed files with 50 additions and 44 deletions

View File

@ -39,8 +39,6 @@ status:
; Level temporary vars
levelT:
BYTE
levelC:
BYTE
levelN:
BYTE

View File

@ -252,7 +252,7 @@ foodOK:
ldy #0
jsr calcTileMem ; calc food address in memory
lda (tileMem),y ; check if memory is empty
cmp #$00 ; is there a space?
cmp #EMPTY_TILE ; is this an empty tile?
bne genFood ; if not, must generate another number
lda #FOOD_TILE ; else, just put that fucking piece of food there
sta (tileMem),y
@ -261,7 +261,7 @@ foodOK:
clc
adc tileMem + 1
sta tileMem + 1
lda #FOOD_COLOR
lda FOOD_COLOR
sta (tileMem),y
; print score at $10th column
@ -299,7 +299,7 @@ checkEndWallHit:
clc ; correspondent), and put SNAKE_COLOR
adc tileMem + 1
sta tileMem + 1
lda #SNAKE_COLOR
lda SNAKE_COLOR
sta (tileMem),y
; Erase snake tail
@ -312,12 +312,9 @@ checkEndWallHit:
lda listY,x
sta calcTileY
jsr calcTileMem
lda #$00 ; just put a space to erase snake tail tile
lda #EMPTY_TILE ; erase snake tail tile
sta (tileMem),y
; lda #WALL_COLOR
; sta $d860,y
skipPauseTests:
rts

View File

@ -31,14 +31,26 @@ ST_PAUSE = 255
; Screen features
SCREEN_W = 40
SCREEN_H = 24
; Snake features
SNAKE_TILE = $60
SNAKE_COLOR = 13
; Food features
FOOD_TILE = $61
FOOD_COLOR = 10
; Wall features
WALL_TILE = $62
; Tiles
; -----
EMPTY_TILE = $60
SNAKE_TILE = $61
FOOD_TILE = $62
WALL_TILE = $63
; Tiles colors
; Note: these colors will be picked by the level select routine
; thus their order must match those of the values assigned to tiles
tilesColors:
EMPTY_COLOR:
BYTE $0
SNAKE_COLOR:
BYTE $d
FOOD_COLOR:
BYTE $a
WALL_COLOR:
BYTE $8
; Strings
; ----------------------------------------------------------------------

View File

@ -13,11 +13,10 @@ statusLevelSelect:
sty levelColorPointer + 1
; Level data is compressed with RLE. Array example:
; +---+---+---+---+---+---+--..--+---+---+---+
; | T | C | N | T | C | N | .. | 0 | 0 | 0 |
; +---+---+---+---+---+---+--..--+---+---+---+
; +---+---+---+---+--..--+---+---+
; | T | N | T | N | .. | 0 | 0 |
; +---+---+---+---+--..--+---+---+
; T tile char
; C tile color
; N count (how many repeated tile chars)
; 0 end of level
@ -27,11 +26,6 @@ writeLevelLoop:
lda (levelPointer),y
sta levelT
; read `C`
iny
lda (levelPointer),y
sta levelC
; read `N`
iny
lda (levelPointer),y
@ -57,7 +51,12 @@ writeLevelLoop:
writeLevelElement:
lda levelT
sta (levelVideoPointer),y
lda levelC
; tiles colors can be found in an array
; position in array = tile value - $60
sec
sbc #$60
tax
lda tilesColors,x
sta (levelColorPointer),y
dey
bne writeLevelElement

View File

@ -960,6 +960,16 @@
BYTE #%11111111
; char 0x60, 96
BYTE #%00000000
BYTE #%00000000
BYTE #%00000000
BYTE #%00000000
BYTE #%00000000
BYTE #%00000000
BYTE #%00000000
BYTE #%00000000
; char 0x61, 96
BYTE #%00000000
BYTE #%00101000
BYTE #%10101011
@ -969,7 +979,7 @@
BYTE #%00101000
BYTE #%00000000
; char 0x61, 97
; char 0x62, 97
BYTE #%00010101
BYTE #%10010101
BYTE #%10010101
@ -979,7 +989,7 @@
BYTE #%00100000
BYTE #%10000000
; char 0x62, 98
; char 0x63, 98
BYTE #%01010101
BYTE #%11010101
BYTE #%01011101
@ -989,16 +999,6 @@
BYTE #%11010101
BYTE #%01011101
; char 0x63, 99
BYTE #%11111111
BYTE #%10000001
BYTE #%10000001
BYTE #%10000001
BYTE #%10000001
BYTE #%10000001
BYTE #%10000001
BYTE #%11111111
; char 0x64, 100
BYTE #%11111111
BYTE #%10000001

View File

@ -7,13 +7,13 @@ void flush(char last, int count) {
char tile, color;
switch(last) {
case 'x':
tile = (char)0x62; color = (char)0x8; break;
tile = (char)0x63; break;
case 'f':
tile = (char)0x61; color = (char)0xa; break;
tile = (char)0x62; break;
default:
tile = (char)0x00; break;
tile = (char)0x60; break;
}
cout << tile << color << (char)count;
cout << tile << (char)count;
}
int main(int argc, char** argv) {
@ -34,7 +34,7 @@ int main(int argc, char** argv) {
cin.getline(line, MAXLEN);
if (line[0] == 'z') {
flush(current, count);
cout << '\0' << '\0' << '\0';
cout << '\0' << '\0';
break;
}