diff options
Diffstat (limited to 'home/pic.asm')
-rw-r--r-- | home/pic.asm | 218 |
1 files changed, 109 insertions, 109 deletions
diff --git a/home/pic.asm b/home/pic.asm index 4bc7b31c..81629055 100644 --- a/home/pic.asm +++ b/home/pic.asm @@ -1,5 +1,5 @@ ; bankswitches and runs _UncompressSpriteData -; bank is given in a, sprite input stream is pointed to in W_SPRITEINPUTPTR +; bank is given in a, sprite input stream is pointed to in wSpriteInputPtr UncompressSpriteData:: ; 24fd (0:24fd) ld b, a ld a, [H_LOADEDROMBANK] @@ -25,29 +25,29 @@ _UncompressSpriteData:: ; 251a (0:251a) xor a call FillMemory ; clear sprite buffer 1 and 2 ld a, $1 - ld [W_SPRITEINPUTBITCOUNTER], a + ld [wSpriteInputBitCounter], a ld a, $3 - ld [W_SPRITEOUTPUTBITOFFSET], a + ld [wSpriteOutputBitOffset], a xor a - ld [W_SPRITECURPOSX], a - ld [W_SPRITECURPOSY], a - ld [W_SPRITELOADFLAGS], a + ld [wSpriteCurPosX], a + ld [wSpriteCurPosY], a + ld [wSpriteLoadFlags], a call ReadNextInputByte ; first byte of input determines sprite width (high nybble) and height (low nybble) in tiles (8x8 pixels) ld b, a and $f add a add a add a - ld [W_SPRITEHEIGHT], a + ld [wSpriteHeight], a ld a, b swap a and $f add a add a add a - ld [W_SPRITEWITDH], a + ld [wSpriteWidth], a call ReadNextInputBit - ld [W_SPRITELOADFLAGS], a ; initialite bit1 to 0 and bit0 to the first input bit + ld [wSpriteLoadFlags], a ; initialite bit1 to 0 and bit0 to the first input bit ; this will load two chunks of data to S_SPRITEBUFFER1 and S_SPRITEBUFFER2 ; bit 0 decides in which one the first chunk is placed ; fall through @@ -57,13 +57,13 @@ _UncompressSpriteData:: ; 251a (0:251a) ; note that this is an endless loop which is terminated during a call to MoveToNextBufferPosition by manipulating the stack UncompressSpriteDataLoop:: ; 2556 (0:2556) ld hl, S_SPRITEBUFFER1 - ld a, [W_SPRITELOADFLAGS] + ld a, [wSpriteLoadFlags] bit 0, a jr z, .useSpriteBuffer1 ; check which buffer to use ld hl, S_SPRITEBUFFER2 .useSpriteBuffer1 call StoreSpriteOutputPointer - ld a, [W_SPRITELOADFLAGS] + ld a, [wSpriteLoadFlags] bit 1, a jr z, .startDecompression ; check if last iteration call ReadNextInputBit ; if last chunk, read 1-2 bit unpacking mode @@ -72,7 +72,7 @@ UncompressSpriteDataLoop:: ; 2556 (0:2556) call ReadNextInputBit ; 1 0 -> mode 1 inc a ; 1 1 -> mode 2 .unpackingMode0 - ld [W_SPRITEUNPACKMODE], a + ld [wSpriteUnpackMode], a .startDecompression call ReadNextInputBit and a @@ -146,69 +146,69 @@ UncompressSpriteDataLoop:: ; 2556 (0:2556) ; also cancels the calling function if the all output is done (by removing the return pointer from stack) ; and calls postprocessing functions according to the unpack mode MoveToNextBufferPosition:: ; 25d8 (0:25d8) - ld a, [W_SPRITEHEIGHT] + ld a, [wSpriteHeight] ld b, a - ld a, [W_SPRITECURPOSY] + ld a, [wSpriteCurPosY] inc a cp b jr z, .curColumnDone - ld [W_SPRITECURPOSY], a - ld a, [W_SPRITEOUTPUTPTR] + ld [wSpriteCurPosY], a + ld a, [wSpriteOutputPtr] inc a - ld [W_SPRITEOUTPUTPTR], a + ld [wSpriteOutputPtr], a ret nz - ld a, [W_SPRITEOUTPUTPTR+1] + ld a, [wSpriteOutputPtr+1] inc a - ld [W_SPRITEOUTPUTPTR+1], a + ld [wSpriteOutputPtr+1], a ret .curColumnDone xor a - ld [W_SPRITECURPOSY], a - ld a, [W_SPRITEOUTPUTBITOFFSET] + ld [wSpriteCurPosY], a + ld a, [wSpriteOutputBitOffset] and a jr z, .bitOffsetsDone dec a - ld [W_SPRITEOUTPUTBITOFFSET], a - ld hl, W_SPRITEOUTPUTPTRCACHED + ld [wSpriteOutputBitOffset], a + ld hl, wSpriteOutputPtrCached ld a, [hli] - ld [W_SPRITEOUTPUTPTR], a + ld [wSpriteOutputPtr], a ld a, [hl] - ld [W_SPRITEOUTPUTPTR+1], a + ld [wSpriteOutputPtr+1], a ret .bitOffsetsDone ld a, $3 - ld [W_SPRITEOUTPUTBITOFFSET], a - ld a, [W_SPRITECURPOSX] + ld [wSpriteOutputBitOffset], a + ld a, [wSpriteCurPosX] add $8 - ld [W_SPRITECURPOSX], a + ld [wSpriteCurPosX], a ld b, a - ld a, [W_SPRITEWITDH] + ld a, [wSpriteWidth] cp b jr z, .allColumnsDone - ld a, [W_SPRITEOUTPUTPTR] + ld a, [wSpriteOutputPtr] ld l, a - ld a, [W_SPRITEOUTPUTPTR+1] + ld a, [wSpriteOutputPtr+1] ld h, a inc hl jp StoreSpriteOutputPointer .allColumnsDone pop hl xor a - ld [W_SPRITECURPOSX], a - ld a, [W_SPRITELOADFLAGS] + ld [wSpriteCurPosX], a + ld a, [wSpriteLoadFlags] bit 1, a jr nz, .done ; test if there is one more sprite to go xor $1 set 1, a - ld [W_SPRITELOADFLAGS], a + ld [wSpriteLoadFlags], a jp UncompressSpriteDataLoop .done jp UnpackSprite -; writes 2 bits (from a) to the output buffer (pointed to from W_SPRITEOUTPUTPTR) +; writes 2 bits (from a) to the output buffer (pointed to from wSpriteOutputPtr) WriteSpriteBitsToBuffer:: ; 2649 (0:2649) ld e, a - ld a, [W_SPRITEOUTPUTBITOFFSET] + ld a, [wSpriteOutputBitOffset] and a jr z, .offset0 cp $2 @@ -224,9 +224,9 @@ WriteSpriteBitsToBuffer:: ; 2649 (0:2649) .offset2 swap e .offset0 - ld a, [W_SPRITEOUTPUTPTR] + ld a, [wSpriteOutputPtr] ld l, a - ld a, [W_SPRITEOUTPUTPTR+1] + ld a, [wSpriteOutputPtr+1] ld h, a ld a, [hl] or e @@ -235,32 +235,32 @@ WriteSpriteBitsToBuffer:: ; 2649 (0:2649) ; reads next bit from input stream and returns it in a ReadNextInputBit:: ; 2670 (0:2670) - ld a, [W_SPRITEINPUTBITCOUNTER] + ld a, [wSpriteInputBitCounter] dec a jr nz, .curByteHasMoreBitsToRead call ReadNextInputByte - ld [W_SPRITEINPUTCURBYTE], a + ld [wSpriteInputCurByte], a ld a, $8 .curByteHasMoreBitsToRead - ld [W_SPRITEINPUTBITCOUNTER], a - ld a, [W_SPRITEINPUTCURBYTE] + ld [wSpriteInputBitCounter], a + ld a, [wSpriteInputCurByte] rlca - ld [W_SPRITEINPUTCURBYTE], a + ld [wSpriteInputCurByte], a and $1 ret ; reads next byte from input stream and returns it in a ReadNextInputByte:: ; 268b (0:268b) - ld a, [W_SPRITEINPUTPTR] + ld a, [wSpriteInputPtr] ld l, a - ld a, [W_SPRITEINPUTPTR+1] + ld a, [wSpriteInputPtr+1] ld h, a ld a, [hli] ld b, a ld a, l - ld [W_SPRITEINPUTPTR], a + ld [wSpriteInputPtr], a ld a, h - ld [W_SPRITEINPUTPTR+1], a + ld [wSpriteInputPtr+1], a ld a, b ret @@ -285,7 +285,7 @@ LengthEncodingOffsetList:: ; 269f (0:269f) ; unpacks the sprite data depending on the unpack mode UnpackSprite:: ; 26bf (0:26bf) - ld a, [W_SPRITEUNPACKMODE] + ld a, [wSpriteUnpackMode] cp $2 jp z, UnpackSpriteMode2 and a @@ -299,10 +299,10 @@ UnpackSprite:: ; 26bf (0:26bf) ; input bit value 0 preserves the current bit value and input bit value 1 toggles it (starting from initial value 0). SpriteDifferentialDecode:: ; 26d4 (0:26d4) xor a - ld [W_SPRITECURPOSX], a - ld [W_SPRITECURPOSY], a + ld [wSpriteCurPosX], a + ld [wSpriteCurPosY], a call StoreSpriteOutputPointer - ld a, [W_SPRITEFLIPPED] + ld a, [wSpriteFlipped] and a jr z, .notFlipped ld hl, DecodeNybble0TableFlipped @@ -313,18 +313,18 @@ SpriteDifferentialDecode:: ; 26d4 (0:26d4) ld de, DecodeNybble1Table .storeDecodeTablesPointers ld a, l - ld [W_SPRITEDECODETABLE0PTR], a + ld [wSpriteDecodeTable0Ptr], a ld a, h - ld [W_SPRITEDECODETABLE0PTR+1], a + ld [wSpriteDecodeTable0Ptr+1], a ld a, e - ld [W_SPRITEDECODETABLE1PTR], a + ld [wSpriteDecodeTable1Ptr], a ld a, d - ld [W_SPRITEDECODETABLE1PTR+1], a + ld [wSpriteDecodeTable1Ptr+1], a ld e, $0 ; last decoded nybble, initialized to 0 .decodeNextByteLoop - ld a, [W_SPRITEOUTPUTPTR] + ld a, [wSpriteOutputPtr] ld l, a - ld a, [W_SPRITEOUTPUTPTR+1] + ld a, [wSpriteOutputPtr+1] ld h, a ld a, [hl] ld b, a @@ -338,47 +338,47 @@ SpriteDifferentialDecode:: ; 26d4 (0:26d4) call DifferentialDecodeNybble ; decode low nybble or d ld b, a - ld a, [W_SPRITEOUTPUTPTR] + ld a, [wSpriteOutputPtr] ld l, a - ld a, [W_SPRITEOUTPUTPTR+1] + ld a, [wSpriteOutputPtr+1] ld h, a ld a, b ld [hl], a ; write back decoded data - ld a, [W_SPRITEHEIGHT] + ld a, [wSpriteHeight] add l ; move on to next column jr nc, .noCarry inc h .noCarry - ld [W_SPRITEOUTPUTPTR], a + ld [wSpriteOutputPtr], a ld a, h - ld [W_SPRITEOUTPUTPTR+1], a - ld a, [W_SPRITECURPOSX] + ld [wSpriteOutputPtr+1], a + ld a, [wSpriteCurPosX] add $8 - ld [W_SPRITECURPOSX], a + ld [wSpriteCurPosX], a ld b, a - ld a, [W_SPRITEWITDH] + ld a, [wSpriteWidth] cp b jr nz, .decodeNextByteLoop ; test if current row is done xor a ld e, a - ld [W_SPRITECURPOSX], a - ld a, [W_SPRITECURPOSY] ; move on to next row + ld [wSpriteCurPosX], a + ld a, [wSpriteCurPosY] ; move on to next row inc a - ld [W_SPRITECURPOSY], a + ld [wSpriteCurPosY], a ld b, a - ld a, [W_SPRITEHEIGHT] + ld a, [wSpriteHeight] cp b jr z, .done ; test if all rows finished - ld a, [W_SPRITEOUTPUTPTRCACHED] + ld a, [wSpriteOutputPtrCached] ld l, a - ld a, [W_SPRITEOUTPUTPTRCACHED+1] + ld a, [wSpriteOutputPtrCached+1] ld h, a inc hl call StoreSpriteOutputPointer jr .decodeNextByteLoop .done xor a - ld [W_SPRITECURPOSY], a + ld [wSpriteCurPosY], a ret ; decodes the nybble stored in a. Last decoded data is assumed to be in e (needed to determine if initial value is 0 or 1) @@ -389,7 +389,7 @@ DifferentialDecodeNybble:: ; 276d (0:276d) ld c, $1 .evenNumber ld l, a - ld a, [W_SPRITEFLIPPED] + ld a, [wSpriteFlipped] and a jr z, .notFlipped ; determine if initial value is 0 or one bit 3, e ; if flipped, consider MSB of last data @@ -399,14 +399,14 @@ DifferentialDecodeNybble:: ; 276d (0:276d) .selectLookupTable ld e, l jr nz, .initialValue1 ; load the appropriate table - ld a, [W_SPRITEDECODETABLE0PTR] + ld a, [wSpriteDecodeTable0Ptr] ld l, a - ld a, [W_SPRITEDECODETABLE0PTR+1] + ld a, [wSpriteDecodeTable0Ptr+1] jr .tableLookup .initialValue1 - ld a, [W_SPRITEDECODETABLE1PTR] + ld a, [wSpriteDecodeTable1Ptr] ld l, a - ld a, [W_SPRITEDECODETABLE1PTR+1] + ld a, [wSpriteDecodeTable1Ptr+1] .tableLookup ld h, a ld a, e @@ -464,25 +464,25 @@ DecodeNybble1TableFlipped:: ; 27bf (0:27bf) ; combines the two loaded chunks with xor (the chunk loaded second is the destination). The source chunk is differeintial decoded beforehand. XorSpriteChunks:: ; 27c7 (0:27c7) xor a - ld [W_SPRITECURPOSX], a - ld [W_SPRITECURPOSY], a + ld [wSpriteCurPosX], a + ld [wSpriteCurPosY], a call ResetSpriteBufferPointers - ld a, [W_SPRITEOUTPUTPTR] ; points to buffer 1 or 2, depending on flags + ld a, [wSpriteOutputPtr] ; points to buffer 1 or 2, depending on flags ld l, a - ld a, [W_SPRITEOUTPUTPTR+1] + ld a, [wSpriteOutputPtr+1] ld h, a call SpriteDifferentialDecode ; decode buffer 1 or 2, depending on flags call ResetSpriteBufferPointers - ld a, [W_SPRITEOUTPUTPTR] ; source buffer, points to buffer 1 or 2, depending on flags + ld a, [wSpriteOutputPtr] ; source buffer, points to buffer 1 or 2, depending on flags ld l, a - ld a, [W_SPRITEOUTPUTPTR+1] + ld a, [wSpriteOutputPtr+1] ld h, a - ld a, [W_SPRITEOUTPUTPTRCACHED] ; destination buffer, points to buffer 2 or 1, depending on flags + ld a, [wSpriteOutputPtrCached] ; destination buffer, points to buffer 2 or 1, depending on flags ld e, a - ld a, [W_SPRITEOUTPUTPTRCACHED+1] + ld a, [wSpriteOutputPtrCached+1] ld d, a .xorChunksLoop - ld a, [W_SPRITEFLIPPED] + ld a, [wSpriteFlipped] and a jr z, .notFlipped push de @@ -506,24 +506,24 @@ XorSpriteChunks:: ; 27c7 (0:27c7) xor b ld [de], a inc de - ld a, [W_SPRITECURPOSY] + ld a, [wSpriteCurPosY] inc a - ld [W_SPRITECURPOSY], a ; go to next row + ld [wSpriteCurPosY], a ; go to next row ld b, a - ld a, [W_SPRITEHEIGHT] + ld a, [wSpriteHeight] cp b jr nz, .xorChunksLoop ; test if column finished xor a - ld [W_SPRITECURPOSY], a - ld a, [W_SPRITECURPOSX] + ld [wSpriteCurPosY], a + ld a, [wSpriteCurPosX] add $8 - ld [W_SPRITECURPOSX], a ; go to next column + ld [wSpriteCurPosX], a ; go to next column ld b, a - ld a, [W_SPRITEWITDH] + ld a, [wSpriteWidth] cp b jr nz, .xorChunksLoop ; test if all columns finished xor a - ld [W_SPRITECURPOSX], a + ld [wSpriteCurPosX], a ret ; reverses the bits in the nybble given in register a @@ -537,9 +537,9 @@ ReverseNybble:: ; 2837 (0:2837) ld a, [de] ret -; resets sprite buffer pointers to buffer 1 and 2, depending on W_SPRITELOADFLAGS +; resets sprite buffer pointers to buffer 1 and 2, depending on wSpriteLoadFlags ResetSpriteBufferPointers:: ; 2841 (0:2841) - ld a, [W_SPRITELOADFLAGS] + ld a, [wSpriteLoadFlags] bit 0, a jr nz, .buffer2Selected ld de, S_SPRITEBUFFER1 @@ -550,13 +550,13 @@ ResetSpriteBufferPointers:: ; 2841 (0:2841) ld hl, S_SPRITEBUFFER1 .storeBufferPointers ld a, l - ld [W_SPRITEOUTPUTPTR], a + ld [wSpriteOutputPtr], a ld a, h - ld [W_SPRITEOUTPUTPTR+1], a + ld [wSpriteOutputPtr+1], a ld a, e - ld [W_SPRITEOUTPUTPTRCACHED], a + ld [wSpriteOutputPtrCached], a ld a, d - ld [W_SPRITEOUTPUTPTRCACHED+1], a + ld [wSpriteOutputPtrCached+1], a ret ; maps each nybble to its reverse @@ -566,26 +566,26 @@ NybbleReverseTable:: ; 2867 (0:2867) ; combines the two loaded chunks with xor (the chunk loaded second is the destination). Both chunks are differeintial decoded beforehand. UnpackSpriteMode2:: ; 2877 (0:2877) call ResetSpriteBufferPointers - ld a, [W_SPRITEFLIPPED] + ld a, [wSpriteFlipped] push af xor a - ld [W_SPRITEFLIPPED], a ; temporarily clear flipped flag for decoding the destination chunk - ld a, [W_SPRITEOUTPUTPTRCACHED] + ld [wSpriteFlipped], a ; temporarily clear flipped flag for decoding the destination chunk + ld a, [wSpriteOutputPtrCached] ld l, a - ld a, [W_SPRITEOUTPUTPTRCACHED+1] + ld a, [wSpriteOutputPtrCached+1] ld h, a call SpriteDifferentialDecode call ResetSpriteBufferPointers pop af - ld [W_SPRITEFLIPPED], a + ld [wSpriteFlipped], a jp XorSpriteChunks ; stores hl into the output pointers StoreSpriteOutputPointer:: ; 2897 (0:2897) ld a, l - ld [W_SPRITEOUTPUTPTR], a - ld [W_SPRITEOUTPUTPTRCACHED], a + ld [wSpriteOutputPtr], a + ld [wSpriteOutputPtrCached], a ld a, h - ld [W_SPRITEOUTPUTPTR+1], a - ld [W_SPRITEOUTPUTPTRCACHED+1], a + ld [wSpriteOutputPtr+1], a + ld [wSpriteOutputPtrCached+1], a ret |