tiles loaded from level RLE binary now have color

This commit is contained in:
giomba 2020-04-02 18:12:39 +02:00
parent 5f85203028
commit e828776a14
4 changed files with 54 additions and 33 deletions

View File

@ -36,4 +36,11 @@ random:
status: status:
BYTE BYTE
; Level temporary vars
levelT:
BYTE
levelC:
BYTE
levelN:
BYTE

View File

@ -7,58 +7,72 @@ statusLevelSelect:
ldy #$04 ldy #$04
sty levelVideoPointer + 1 sty levelVideoPointer + 1
ldy #39
sty levelColorPointer
ldy #$d8
sty levelColorPointer + 1
; Level data is compressed with RLE. Array example: ; Level data is compressed with RLE. Array example:
; +---+---+---+---+---+-..-+---+---+ ; +---+---+---+---+---+---+--..--+---+---+---+
; | T | C | T | C | . | | 0 | 0 | ; | T | C | N | T | C | N | .. | 0 | 0 | 0 |
; +---+---+---+---+---+-..-+---+---+ ; +---+---+---+---+---+---+--..--+---+---+---+
; T tile char ; T tile char
; C count (how many repeated tile chars) ; C tile color
; N count (how many repeated tile chars)
; 0 end of level ; 0 end of level
writeLevelLoop: writeLevelLoop:
; read `T`, and save onto stack ; read `T`
ldy #0 ldy #0
lda (levelPointer),y lda (levelPointer),y
pha sta levelT
; increment array pointer ; read `C`
lda #levelPointer iny
sta nextPointerPointer
ldx #1
jsr nextPointer
; read `C`, and save onto stack
ldy #0
lda (levelPointer),y lda (levelPointer),y
pha sta levelC
; read `N`
iny
lda (levelPointer),y
sta levelN
; increment array pointer ; increment array pointer
lda #levelPointer iny
sta nextPointerPointer tya
ldx #1
jsr nextPointer
; retrieve `C` from stack and put in X and Y
pla
tay
tax tax
; retrieve `T` from stack lda #levelPointer
pla sta nextPointerPointer
jsr nextPointer
; check array end ; check for array end
lda levelN
cmp #0 cmp #0
beq writeLevelEnd beq writeLevelEnd
; retrieve `N` and put in Y
ldy levelN
; unpack char from RLE to the screen ; unpack char from RLE to the screen
writeLevelElement: writeLevelElement:
lda levelT
sta (levelVideoPointer),y sta (levelVideoPointer),y
lda levelC
sta (levelColorPointer),y
dey dey
bne writeLevelElement bne writeLevelElement
; increment dest video memory pointer
lda #levelVideoPointer lda #levelVideoPointer
sta nextPointerPointer sta nextPointerPointer
; reg X is still holding the original `C` ldx levelN
jsr nextPointer jsr nextPointer
lda #levelColorPointer
sta nextPointerPointer
ldx levelN
jsr nextPointer
jmp writeLevelLoop jmp writeLevelLoop
writeLevelEnd: writeLevelEnd:

View File

@ -17,6 +17,7 @@ levelPointer DS 2
; Pointer to video memory used in the level loading routine ; Pointer to video memory used in the level loading routine
levelVideoPointer DS 2 levelVideoPointer DS 2
levelColorPointer DS 2
; Pointer for Pointer in the NextPointer routine ; Pointer for Pointer in the NextPointer routine
nextPointerPointer DS 2 nextPointerPointer DS 2

View File

@ -4,16 +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; char tile, color;
switch(last) { switch(last) {
case 'x': case 'x':
tile = (char)91; break; tile = (char)91; color = (char)11; break;
case 'f': case 'f':
tile = (char)90; break; tile = (char)90; color = (char)11; break;
default: default:
tile = (char)32; break; tile = (char)32; break;
} }
cout << tile << (char)count; cout << tile << color << (char)count;
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
@ -34,7 +34,7 @@ int main(int argc, char** argv) {
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'; cout << '\0' << '\0' << '\0';
break; break;
} }
@ -51,6 +51,5 @@ int main(int argc, char** argv) {
} }
} }
} }
cout << '\0' << '\0';
} }