Advertisement
vladikcomper

Untitled

Jan 26th, 2025
745
0
3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; =============== S U B R O U T I N E =======================================
  2.  
  3. TokenBitmask:    
  4.                 dc.w $1FF
  5.                 dc.w $3FF
  6.                 dc.w $7FF
  7.                 dc.w $FFF
  8.  
  9. ; -----------------------------------------------------------------------
  10. ; INPUT:
  11. ;       a0      - Target VRAM address
  12. ;       a1      - Compressed data pointer
  13. ; -----------------------------------------------------------------------
  14.  
  15. DoLoadCompressed2Tiles:                ; CODE XREF: LoadUncOrComp2Tiles+16↑p
  16.                                         ; LoadCompressed2Tiles+10↑p
  17.                 movem.l d2-d7/a2-a6,-(sp)
  18.                 moveq   #0,d2
  19.                 moveq   #0,d3
  20.                 move.w  #$102,d4
  21.                 moveq   #9,d5                   ; set token size to 9 bits
  22.                 move.w  #$200,d6
  23.                 lea     (TokenBitmask).l,a2     ; set mask to 9 bits
  24.                 lea     ($FF58D4).l,a6  ; A5 and A6 point to the same location, but A5 has some base displacement ($408 bytes)
  25.                 lea     ($FF54CC).l,a5  ; A5 points to a table of size $400 bytes (likely)
  26.                 move    #$2700,sr
  27.  
  28.                 ; Setup writes at VRAM address specified by A0
  29.                 subq.w  #2,a0           ; -2, because programmer's drunk
  30.                 jsr     VRAMReadOne     ; read from `start_address-2`, because programmer's drunk
  31.                 jsr     VRAMWriteOne    ; write what we've read to `start_address-2`, so the next write goes to `start_address`, because programmer's drunk
  32.                 movea.l a1,a0
  33.                 subq.w  #2,sp
  34.                 movea.l sp,a1
  35.  
  36. Decomp_Loop:                             ; CODE XREF: DoLoadCompressed2Tiles+AE↓j
  37.                                         ; DoLoadCompressed2Tiles+B6↓j ...
  38.                 ; Read next token of length 9, 10 or 11 bits (see D5, (A2)) from the compressed stream
  39.                 move.l  d3,d1                   ; d1 = X
  40.                 lsr.l   #3,d1                   ; d1 = X/8
  41.                 move.b  1(a0,d1.w),d0           ; d0 = MM  -- read middle byte
  42.                 lsl.w   #8,d0                   ; d0 = MM 00 -- make space for lower byte
  43.                 move.b  (a0,d1.w),d0            ; d0 = MM LL -- read lower byte
  44.                 swap    d0
  45.                 move.b  2(a0,d1.w),d0           ; d0 = HH -- read high byte
  46.                 swap    d0                      ; d0 = HH MM LL
  47.                 move.l  d3,d1
  48.                 add.l   d5,d3                   ; increment compressed stream pointer (in bits)
  49.                 andi.w  #7,d1
  50.                 lsr.l   d1,d0
  51.                 and.w   (a2),d0                 ; mask out bits (9, 10 or 11)
  52.  
  53.                 cmpi.w  #$101,d0                ; is token $101?
  54.                 beq.s   Decomp_Quit             ; if yes, halt decompression
  55.                 cmpi.w  #$100,d0                ; is token $100?
  56.                 bne.s   loc_F5B3E               ; if not, don't reload decompressor
  57.  
  58.                 ; Token $100: Reset decompression state
  59.                 move.w  #$102,d4
  60.                 moveq   #9,d5                   ; reset token size to 9 bits
  61.                 move.w  #$200,d6
  62.                 lea     (TokenBitmask).l,a2     ; reset mask to 9 bits
  63.                 lea     ($FF58D4).l,a6          ; reset unknown dictionary
  64.  
  65.                 ; Read next token of length 9 bits (see D5, (A2)) from the compressed stream
  66.                 move.l  d3,d1
  67.                 lsr.l   #3,d1
  68.                 move.b  1(a0,d1.w),d0
  69.                 lsl.w   #8,d0
  70.                 move.b  (a0,d1.w),d0
  71.                 swap    d0
  72.                 move.b  2(a0,d1.w),d0
  73.                 swap    d0
  74.                 move.l  d3,d1
  75.                 add.l   d5,d3                   ; increment compressed stream pointer (in bits)
  76.                 andi.w  #7,d1
  77.                 lsr.l   d1,d0
  78.                 and.w   (a2),d0
  79.  
  80.                 move.w  d0,d7
  81.                 movea.w d0,a3
  82.                 move.b  d0,(a1)+                ; put raw uncompressed byte
  83.                 move.w  a1,d0                   ; get stack variable address
  84.                 btst    #0,d0                   ; are we doing the second byte already?
  85.                 bne.s   Decomp_Loop             ; branch if not
  86.                 move.w  -(a1),($C00000).l       ; dump 2 bytes to VRAM
  87.                 bra.s   Decomp_Loop
  88. ; ---------------------------------------------------------------------------
  89.  
  90. Decomp_Quit:                             ; CODE XREF: DoLoadCompressed2Tiles+62↑j
  91.                 move    #$2500,sr
  92.                 addq.w  #2,sp
  93.                 movem.l (sp)+,d2-d7/a2-a6
  94.                 rts
  95. ; ---------------------------------------------------------------------------
  96.  
  97. loc_F5B3E:                             ; CODE XREF: DoLoadCompressed2Tiles+68↑j
  98.                 movea.w d0,a4
  99.                 cmp.w   d4,d0
  100.                 blt.s   loc_F5B4C
  101.                 move.w  a3,d0
  102.                 move.b  d0,-(sp)
  103.                 move.w  d7,d0
  104.  
  105. loc_F5B4A:                             ; CODE XREF: DoLoadCompressed2Tiles+E4↓j
  106.                 addq.w  #1,d2                   ; increment copy counter
  107.  
  108. loc_F5B4C:                             ; CODE XREF: DoLoadCompressed2Tiles+C8↑j
  109.                 cmpi.w  #$FF,d0
  110.                 bls.s   loc_F5B60
  111.                 add.w   d0,d0                   ; records in table A5 are 4 bytes long
  112.                 add.w   d0,d0                   ; ^
  113.                 move.b  1(a5,d0.w),-(sp)        ; put raw uncompressed byte
  114.                 move.w  2(a5,d0.w),d0           ; next index or token to process
  115.                 bra.s   loc_F5B4A
  116. ; ---------------------------------------------------------------------------
  117.  
  118. loc_F5B60:                             ; CODE XREF: DoLoadCompressed2Tiles+D6↑j
  119.                 movea.w d0,a3
  120.                 swap    d7
  121.                 move.w  d0,d7                   ; prepare uncompressed byte for unknown dictionary
  122.                 swap    d7                      ; store it so it's read back by 1(a5,d0.w) (see above)
  123.                 move.b  d0,-(sp)                ; put raw uncompressed byte
  124.  
  125. loc_F5B6A:                             ; CODE XREF: DoLoadCompressed2Tiles:loc_F5B7A↓j
  126.                 move.b  (sp)+,(a1)+             ; put raw uncompressed byte
  127.                 move.w  a1,d0                   ; get stack variable address
  128.                 btst    #0,d0                   ; are we doing the second byte already?
  129.                 bne.s   loc_F5B7A               ; branch if not
  130.                 move.w  -(a1),($C00000).l       ; dump 2 bytes to VRAM
  131.  
  132. loc_F5B7A:                             ; CODE XREF: DoLoadCompressed2Tiles+F8↑j
  133.                 dbf     d2,loc_F5B6A
  134.                 moveq   #0,d2
  135.                 move.l  d7,(a6)+                ; write 4 bytes to unknown dictionary:
  136.                                                 ; $00 .b - always $00 (ignored)
  137.                                                 ; $01 .b - read back via 1(a5,d0.w) -- uncompressed byte
  138.                                                 ; $02 .w - read back via 2(a5,d0.w) -- next index in table or token to process
  139.                 addq.w  #1,d4
  140.                 move.w  a4,d7
  141.                 cmp.w   d6,d4
  142.                 blt.w   Decomp_Loop
  143.                 cmpi.w  #$B,d5                  ; is current token size 11 bits already?
  144.                 beq.w   Decomp_Loop             ; if yes, back to the loop
  145.                 addq.w  #1,d5                   ; increase token size by 1 bit (9->10 bits, 10->11 bits)
  146.                 add.w   d6,d6
  147.                 addq.l  #2,a2                   ; use next bit mask (for 10 or 11 bits)
  148.                 bra.w   Decomp_Loop
  149. ; End of function DoLoadCompressed2Tiles
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement