From 22a5feb2a1ecd165e8517ef780bc7379e3c60c3a Mon Sep 17 00:00:00 2001 From: giomba Date: Mon, 6 Apr 2020 22:53:28 +0200 Subject: [PATCH] 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 --- src/data.asm | 2 -- src/game.asm | 11 ++++------- src/initdata.asm | 28 ++++++++++++++++++++-------- src/levels.asm | 19 +++++++++---------- src/tggs.asm | 24 ++++++++++++------------ util/rlevel.cpp | 10 +++++----- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/data.asm b/src/data.asm index 39f86e4..906dd6b 100644 --- a/src/data.asm +++ b/src/data.asm @@ -39,8 +39,6 @@ status: ; Level temporary vars levelT: BYTE -levelC: - BYTE levelN: BYTE diff --git a/src/game.asm b/src/game.asm index 3f951ef..dbaa478 100644 --- a/src/game.asm +++ b/src/game.asm @@ -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 diff --git a/src/initdata.asm b/src/initdata.asm index 06ca9c4..2ea22e0 100644 --- a/src/initdata.asm +++ b/src/initdata.asm @@ -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 ; ---------------------------------------------------------------------- diff --git a/src/levels.asm b/src/levels.asm index f2b723c..3743610 100644 --- a/src/levels.asm +++ b/src/levels.asm @@ -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 diff --git a/src/tggs.asm b/src/tggs.asm index f0e0b91..189ccd5 100644 --- a/src/tggs.asm +++ b/src/tggs.asm @@ -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 diff --git a/util/rlevel.cpp b/util/rlevel.cpp index b99a1c9..b1a17c9 100644 --- a/util/rlevel.cpp +++ b/util/rlevel.cpp @@ -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; }