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:
BYTE
; Level temporary vars
levelT:
BYTE
levelC:
BYTE
levelN:
BYTE

View File

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

View File

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

View File

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