Advertisement
AkumaYin

68k/MegaDrive: load_1bpp_tiles

Jun 1st, 2022
2,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Function to convert 1bpp tiles to 4bpp for VRAM use
  2. ; --------------------------------------------------------------
  3. ; INPUTS:
  4. ;   d0.w - Number of tiles to load (-1 for loop)
  5. ;   d1.b - Color index
  6. ;
  7. ;   a0.l - Pointer to tiles to load
  8. ;   a1.l - Pointer to output buffer
  9. ;
  10. ; RETURNS:
  11. ;   (none)
  12. ;
  13. ; DESTROYS:
  14. ;   d0.w, d1.l, d2.l, d3.l, d4.l, d5.l
  15. ;   a0.l, a1.l, a2.l
  16. ; --------------------------------------------------------------
  17.  
  18. load_1bpp_tiles:
  19.     movem.l d4-d5,-(sp)
  20.  
  21.  
  22.     ; Lookup pixel mask
  23.     ; for chosen color index
  24.     ; ----------------------
  25.     moveq   #$0F,d2
  26.     and.b   d1,d2
  27.     add.w   d2,d2
  28.     add.w   d2,d2
  29.     lea .index_masks(pc),a2
  30.     move.l  (a2,d2.w),d1
  31.     lea .nybble_words-.index_masks(a2),a2
  32.     move.l  #$000F00F0,d2
  33.  
  34.  
  35.     ; Convert 1-bit pixels
  36.     ; to 4-bit
  37.     ; ----------------------
  38.     moveq   #0,d3
  39.  
  40. .loop:
  41.     REPT    8
  42.     move.b  (a0)+,d3
  43.     move.l  d2,d4
  44.     and.b   d3,d4
  45.     lsr.w   #3,d4
  46.     move.w  (a2,d4.w),d5
  47.     swap    d4
  48.     swap    d5
  49.     and.b   d3,d4
  50.     add.w   d4,d4
  51.     move.w  (a2,d4.w),d5
  52.     and.l   d1,d5
  53.     move.l  d5,(a1)+
  54.     ENDR
  55.     dbra    d0,.loop
  56.  
  57.  
  58.     ; Return
  59.     ; ----------------------
  60.     movem.l (sp)+,d4-d5
  61.     rts
  62.  
  63.  
  64. .index_masks:
  65.     dc.l    $00000000
  66.     dc.l    $11111111
  67.     dc.l    $22222222
  68.     dc.l    $33333333
  69.     dc.l    $44444444
  70.     dc.l    $55555555
  71.     dc.l    $66666666
  72.     dc.l    $77777777
  73.     dc.l    $88888888
  74.     dc.l    $99999999
  75.     dc.l    $AAAAAAAA
  76.     dc.l    $BBBBBBBB
  77.     dc.l    $CCCCCCCC
  78.     dc.l    $DDDDDDDD
  79.     dc.l    $EEEEEEEE
  80.     dc.l    $FFFFFFFF
  81.  
  82.  
  83. .nybble_words:
  84.     dc.w    $0000   ; %0000
  85.     dc.w    $000F   ; %0001
  86.     dc.w    $00F0   ; %0010
  87.     dc.w    $00FF   ; %0011
  88.     dc.w    $0F00   ; %0100
  89.     dc.w    $0F0F   ; %0101
  90.     dc.w    $0FF0   ; %0110
  91.     dc.w    $0FFF   ; %0111
  92.     dc.w    $F000   ; %1000
  93.     dc.w    $F00F   ; %1001
  94.     dc.w    $F0F0   ; %1010
  95.     dc.w    $F0FF   ; %1011
  96.     dc.w    $FF00   ; %1100
  97.     dc.w    $FF0F   ; %1101
  98.     dc.w    $FFF0   ; %1110
  99.     dc.w    $FFFF   ; %1111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement