Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; =============== S U B R O U T I N E =======================================
- TokenBitmask:
- dc.w $1FF
- dc.w $3FF
- dc.w $7FF
- dc.w $FFF
- ; -----------------------------------------------------------------------
- ; INPUT:
- ; a0 - Target VRAM address
- ; a1 - Compressed data pointer
- ; -----------------------------------------------------------------------
- DoLoadCompressed2Tiles: ; CODE XREF: LoadUncOrComp2Tiles+16↑p
- ; LoadCompressed2Tiles+10↑p
- movem.l d2-d7/a2-a6,-(sp)
- moveq #0,d2
- moveq #0,d3
- move.w #$102,d4
- moveq #9,d5 ; set token size to 9 bits
- move.w #$200,d6
- lea (TokenBitmask).l,a2 ; set mask to 9 bits
- lea ($FF58D4).l,a6 ; A5 and A6 point to the same location, but A5 has some base displacement ($408 bytes)
- lea ($FF54CC).l,a5 ; A5 points to a table of size $400 bytes (likely)
- move #$2700,sr
- ; Setup writes at VRAM address specified by A0
- subq.w #2,a0 ; -2, because programmer's drunk
- jsr VRAMReadOne ; read from `start_address-2`, because programmer's drunk
- jsr VRAMWriteOne ; write what we've read to `start_address-2`, so the next write goes to `start_address`, because programmer's drunk
- movea.l a1,a0
- subq.w #2,sp
- movea.l sp,a1
- Decomp_Loop: ; CODE XREF: DoLoadCompressed2Tiles+AE↓j
- ; DoLoadCompressed2Tiles+B6↓j ...
- ; Read next token of length 9, 10 or 11 bits (see D5, (A2)) from the compressed stream
- move.l d3,d1 ; d1 = X
- lsr.l #3,d1 ; d1 = X/8
- move.b 1(a0,d1.w),d0 ; d0 = MM -- read middle byte
- lsl.w #8,d0 ; d0 = MM 00 -- make space for lower byte
- move.b (a0,d1.w),d0 ; d0 = MM LL -- read lower byte
- swap d0
- move.b 2(a0,d1.w),d0 ; d0 = HH -- read high byte
- swap d0 ; d0 = HH MM LL
- move.l d3,d1
- add.l d5,d3 ; increment compressed stream pointer (in bits)
- andi.w #7,d1
- lsr.l d1,d0
- and.w (a2),d0 ; mask out bits (9, 10 or 11)
- cmpi.w #$101,d0 ; is token $101?
- beq.s Decomp_Quit ; if yes, halt decompression
- cmpi.w #$100,d0 ; is token $100?
- bne.s loc_F5B3E ; if not, don't reload decompressor
- ; Token $100: Reset decompression state
- move.w #$102,d4
- moveq #9,d5 ; reset token size to 9 bits
- move.w #$200,d6
- lea (TokenBitmask).l,a2 ; reset mask to 9 bits
- lea ($FF58D4).l,a6 ; reset unknown dictionary
- ; Read next token of length 9 bits (see D5, (A2)) from the compressed stream
- move.l d3,d1
- lsr.l #3,d1
- move.b 1(a0,d1.w),d0
- lsl.w #8,d0
- move.b (a0,d1.w),d0
- swap d0
- move.b 2(a0,d1.w),d0
- swap d0
- move.l d3,d1
- add.l d5,d3 ; increment compressed stream pointer (in bits)
- andi.w #7,d1
- lsr.l d1,d0
- and.w (a2),d0
- move.w d0,d7
- movea.w d0,a3
- move.b d0,(a1)+ ; put raw uncompressed byte
- move.w a1,d0 ; get stack variable address
- btst #0,d0 ; are we doing the second byte already?
- bne.s Decomp_Loop ; branch if not
- move.w -(a1),($C00000).l ; dump 2 bytes to VRAM
- bra.s Decomp_Loop
- ; ---------------------------------------------------------------------------
- Decomp_Quit: ; CODE XREF: DoLoadCompressed2Tiles+62↑j
- move #$2500,sr
- addq.w #2,sp
- movem.l (sp)+,d2-d7/a2-a6
- rts
- ; ---------------------------------------------------------------------------
- loc_F5B3E: ; CODE XREF: DoLoadCompressed2Tiles+68↑j
- movea.w d0,a4
- cmp.w d4,d0
- blt.s loc_F5B4C
- move.w a3,d0
- move.b d0,-(sp)
- move.w d7,d0
- loc_F5B4A: ; CODE XREF: DoLoadCompressed2Tiles+E4↓j
- addq.w #1,d2 ; increment copy counter
- loc_F5B4C: ; CODE XREF: DoLoadCompressed2Tiles+C8↑j
- cmpi.w #$FF,d0
- bls.s loc_F5B60
- add.w d0,d0 ; records in table A5 are 4 bytes long
- add.w d0,d0 ; ^
- move.b 1(a5,d0.w),-(sp) ; put raw uncompressed byte
- move.w 2(a5,d0.w),d0 ; next index or token to process
- bra.s loc_F5B4A
- ; ---------------------------------------------------------------------------
- loc_F5B60: ; CODE XREF: DoLoadCompressed2Tiles+D6↑j
- movea.w d0,a3
- swap d7
- move.w d0,d7 ; prepare uncompressed byte for unknown dictionary
- swap d7 ; store it so it's read back by 1(a5,d0.w) (see above)
- move.b d0,-(sp) ; put raw uncompressed byte
- loc_F5B6A: ; CODE XREF: DoLoadCompressed2Tiles:loc_F5B7A↓j
- move.b (sp)+,(a1)+ ; put raw uncompressed byte
- move.w a1,d0 ; get stack variable address
- btst #0,d0 ; are we doing the second byte already?
- bne.s loc_F5B7A ; branch if not
- move.w -(a1),($C00000).l ; dump 2 bytes to VRAM
- loc_F5B7A: ; CODE XREF: DoLoadCompressed2Tiles+F8↑j
- dbf d2,loc_F5B6A
- moveq #0,d2
- move.l d7,(a6)+ ; write 4 bytes to unknown dictionary:
- ; $00 .b - always $00 (ignored)
- ; $01 .b - read back via 1(a5,d0.w) -- uncompressed byte
- ; $02 .w - read back via 2(a5,d0.w) -- next index in table or token to process
- addq.w #1,d4
- move.w a4,d7
- cmp.w d6,d4
- blt.w Decomp_Loop
- cmpi.w #$B,d5 ; is current token size 11 bits already?
- beq.w Decomp_Loop ; if yes, back to the loop
- addq.w #1,d5 ; increase token size by 1 bit (9->10 bits, 10->11 bits)
- add.w d6,d6
- addq.l #2,a2 ; use next bit mask (for 10 or 11 bits)
- bra.w Decomp_Loop
- ; End of function DoLoadCompressed2Tiles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement