AkumaYin

DMA map queues (wip)

May 14th, 2021 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ===========================================================================
  2. ; ---------------------------------------------------------------------------
  3. ; Reset the tile map queue linked lists
  4. ; ---------------------------------------------------------------------------
  5.  
  6. InitMapQueues:
  7.         moveq   #0,d0
  8.         lea r_DMAMapRows_Head.w,a0
  9.         lea $08(a0),a1
  10.         lea $00FF4202.l,a2      ; this shouldn't be hard-coded here
  11.  
  12.         movem.l d0/a0,(a0)
  13.         movem.l d0/a1/a2,(a1)
  14.         rts
  15.  
  16. ; ===========================================================================
  17. ; ---------------------------------------------------------------------------
  18. ; Add a tile row queue
  19. ; ---------------------------------------------------------------------------
  20. ; INPUTS:
  21. ;   d0.w = number of rows to draw (-1 for loop)
  22. ;   d1.w = length of row (in tiles)
  23. ;   d2.w = VRAM address
  24. ;
  25. ; USAGE:
  26. ;   moveq   #XX-1,d0
  27. ;   moveq   #XX,d1
  28. ;   jsr AddMapRowQueue
  29. ; ---------------------------------------------------------------------------
  30.  
  31. AddMapRowQueue:
  32.         move.l  r_NextFreeMapQueue.w,a0     ; 16    ; load next free map queue
  33.         move.l  r_DMAMapRows_Tail.w,a1      ; 16    ; load last added queue
  34.         move.l  a0,r_DMAMapRows_Tail.w      ; 16    ; update pointer to last added queue
  35.         bra.s   AddMapQueue         ; 10
  36.  
  37. ; ---------------------------------------------------------------------------
  38. ; Add a tile column queue
  39. ; ---------------------------------------------------------------------------
  40. ; INPUTS:
  41. ;   d0.w = number of rows to draw (-1 for loop)
  42. ;   d1.w = length of row (in tiles)
  43. ;   d2.w = VRAM address
  44. ;
  45. ; USAGE:
  46. ;   moveq   #XX-1,d0
  47. ;   moveq   #XX,d1
  48. ;   jsr AddMapRowQueue
  49. ; ---------------------------------------------------------------------------
  50.  
  51. AddMapColumnQueue:
  52.         move.l  r_NextFreeMapQueue.w,a0     ; 16    ; load next free map queue
  53.         move.l  r_DMAMapColumns_Tail.w,a1   ; 16    ; load last added queue
  54.         move.l  a0,r_DMAMapColumns_Tail.w   ; 16    ; update pointer to last added queue
  55.  
  56. ; ---------------------------------------------------------------------------
  57. ; INPUTS:
  58. ;   a0 = queue space
  59. ;   a1 = previous queue
  60. ; ---------------------------------------------------------------------------
  61. ; OUTPUTS:
  62. ;   a0 = buffer for nametables
  63. ;   a1 =
  64. ; ---------------------------------------------------------------------------
  65.  
  66. AddMapQueue:
  67.         move.l  a0,(a1)             ; 12    ; link current queue into previous one
  68.         moveq   #0,d3               ; 4 ; clear "next queue" link
  69.         move.l  d3,(a0)+            ; 12    ; ''
  70.  
  71.         move.b  d0,(a0)+            ; 8 ; set number of rows for this queue
  72.         move.b  d1,(a0)+            ; 8 ; set length of row (bytes/2; number of nametables to dump)
  73.  
  74.         move.w  d2,(a0)+            ; 8 ; set VRAM address
  75.  
  76.         add.w   d1,d1               ; 4 ; double row/column length (get number of bytes)
  77.         move.w  d0,d3               ; 4
  78.         addq.w  #1,d3               ; 4 ; fuck
  79.         mulu.w  d1,d3               ; ? ; >->
  80.  
  81.         lea (a0,d3.w),a1            ; 12
  82.         move.l  a1,r_NextFreeMapQueue.w     ; 16
  83.         rts                 ; 16
  84.  
  85. ; ---------------------------------------------------------------------------
  86.  
  87. DMA_RowQueues:
  88.         lea r_DMAMapRows_Head.w,a0
  89.         move.l  #$00800000,-(sp)
  90.         bra.s   DMA_MapQueue
  91.  
  92. DMA_ColumnQueues:
  93.         lea r_DMAMapColumns_Head.w,a0
  94.         pea .Return(pc)
  95.         move.l  #$00020000,-(sp)
  96.         move.w  #$8F80,$C00004.l
  97.         bra.s   DMA_MapQueue
  98.  
  99. .Return:
  100.         move.w  #$8F02,(a6)
  101.         rts
  102.  
  103. ; ---------------------------------------------------------------------------
  104. ;   (a0).w  =
  105. ;   (sp).l  =
  106.  
  107. DMA_MapQueue:
  108.         lea $C00000.l,a5
  109.         lea 4(a5),a6
  110.         move.l  #$94009300,d6
  111.         move.l  #$00009500,d5
  112.         move.l  #$00009600,d4
  113.         move.l  #$00009700,d3
  114.         move.l  #$C0003FFF,d2
  115.  
  116. .Loop:
  117.         move.l  (a0),d0         ; get link to next queue
  118.         beq.s   .Return         ; if null, return (this is the last in the list)
  119.         move.l  d0,a0           ; load queue
  120.         lea 4(a0),a1        ; ''
  121.         moveq   #0,d7           ; get repeat times for rows
  122.         move.b  (a1)+,d7        ; ''
  123.         move.b  (a1)+,d6        ; get length
  124.  
  125.         move.l  d2,d0           ; generate VDP command for VRAM address
  126.         and.w   (a1),d0         ; ''
  127.         addi.w  #$4000,d0       ; ''
  128.         swap    d0          ; ''
  129.         and.w   (a1)+,d0
  130.         rol.w   #2,d0
  131.         bset    #7,d0
  132.  
  133. .GetSource:
  134.         move.l  a1,d1           ; copy buffer position to d1 (source)
  135.         lsr.l   #1,d1  
  136.         move.b  d1,d5
  137.  
  138.         ror.w   #8,d1
  139.         move.b  d1,d4
  140.         swap    d1
  141.         move.b  d1,d3
  142.  
  143.         move.l  d6,(a6)
  144.         move.w  d5,(a6)
  145.         move.w  d4,(a6)
  146.         move.w  d3,(a6)
  147.  
  148.         move.l  d0,-(sp)
  149.         move.w  (sp)+,(a6)
  150.         move.w  (sp)+,(a6)
  151.  
  152.         dbf d7,.Next
  153.         bra.s   .Loop
  154.  
  155. .Next:
  156.         add.l   (sp),d0
  157.         moveq   #0,d1
  158.         move.b  d6,d1
  159.         add.w   d1,d1
  160.         lea (a1,d1.w),a1
  161.         bra.s   .GetSource
  162.  
  163. .Return:
  164.         clr.l   r_DMAMapRows_Head.w
  165.         addq.w  #4,sp
  166.         rts
Add Comment
Please, Sign In to add comment