Guest User

LazyHDMA

a guest
Sep 4th, 2015
329
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @include
  2. ;===============================================================================
  3. ; LazyHDMA by ExoticMatter
  4. ;
  5. ; This library is a simple way to manage multiple HDMA effects without having
  6. ; to copy/paste a lot of code.
  7. ;
  8. ; To use LazyHDMA, incsrc lazyhdma.asm once from uberASM or levelASM. Then, use
  9. ; code such as the following:
  10. ;
  11. ; level105init:
  12. ;     %LazyInitEffect(MyGradient)
  13. ;     RTS
  14. ;
  15. ; MyGradient:
  16. ;     %LazyBGDouble(3, .RedGreen)
  17. ;     %LazyBGSingle(4, .Blue)
  18. ;     %LazyEnd()
  19. ;
  20. ; .RedGreen and .Blue are HDMA tables. Using sublabels is not required.
  21. ; To use a table that is in a different bank, use the _Long suffix. Otherwise,
  22. ; the table must be in the same bank as the descriptor.
  23. ;
  24. ; Make sure to apply IceMan's HDMA patch to prevent common HDMA problems
  25. ; including disappearing HDMA, flickering, and gradients that briefly appear
  26. ; when going through a pipe or door.
  27. ; http://www.smwcentral.net/?p=section&a=details&id=4176
  28. ;===============================================================================
  29. ; Main macros:
  30. ;
  31. ; %LazyInitEffect[_Tail](effect) - Initializes an HDMA effect.
  32. ;   This macro will set A, X, and Y to 8-bit and overwrite scratch RAM.
  33. ;   The _Tail suffix causes the subroutine to not return. This can only be
  34. ;   used where RTS can be used. (Or RTL, if !LongCall is nonzero.)
  35. ;   %LazyInitEffect only needs to be called once. Initializing an effect
  36. ;   that contains a scrolling gradient every frame will induce slowdown.
  37. ;
  38. ; %LazyRunEffect[_Tail](effect) - Runs an HDMA effect.
  39. ;   Like %LazyInitEffect, this macro sets A, X, and Y to 8-bit and overwrite
  40. ;   scratch RAM.
  41. ;   Only scrolling gradients need to be run every frame.
  42. ;   LazyHDMA does not update parallax effects at this point in time.
  43. ;===============================================================================
  44. ; Definition macros:
  45. ;
  46. ; %LazyBaseBG(color) - Defines the background color in BGR15 format.
  47. ;   Use rgb(r, g, b) to create a BGR15 color:
  48. ;   %LazyBaseBG(rgb(31,31,31))
  49. ;
  50. ; %LazyHDMA[_Long](channel, parameters, register, address) - Defines an HDMA
  51. ;   channel with the specified properties.
  52. ;   <register> must be between $2100-$21FF, although $00-$FF are also
  53. ;   allowed.
  54. ;
  55. ; %LazyBGSingle[_Long](channel, address) - Defines a background HDMA channel
  56. ;   that writes once per scanline, i.e. transfer mode 0.
  57. ;
  58. ; %LazyBGDouble[_Long](channel, address) - Defines a background HDMA channel
  59. ;   that writes twice per scanline, i.e. transfer mode 2.
  60. ;
  61. ; %LazyCGRAM[_Long](channel, address) - Defines a palette HDMA channel that
  62. ;   writes to two registers twice per scanline, i.e. transfer mode 3.
  63. ;
  64. ; %LazyBrightness[_Long](channel, address) - Defines a brightness HDMA channel
  65. ;   that writes to one register once per scanline, i.e. transfer mode 0.
  66. ;
  67. ; %LazyScroll[_Long](channelAB, channelC, address) - Defines a scrolling
  68. ;   background HDMA gradient that is decompressed into memory.
  69. ;   For the scrolling to occur, you must call %Lazy
  70. ;
  71. ; %LazyEnd() - Marks the end of the effect.
  72. ;===============================================================================
  73. ; Configuration:
  74. ;
  75. ; !LongCall: If set to a nonzero value, LazyHDMA will use JSL/JSR, allowing
  76. ; LazyHDMA to be called from a different bank. Off by default.
  77. ;
  78. ; !IncludeScrollingGradientCode: If set to a nonzero value, the scrolling
  79. ; gradient routines will be included. Off by default.
  80. ;
  81. ; !ScrollingFreeRAM_(AB|C): The location to put decompressed scrolling gradient
  82. ; tables. By default, $7F:B260 and $7F:B830 are used, respectively.
  83. ;
  84. ; To configure LazyHDMA, set one or more of these defines before incsrc.
  85. ;===============================================================================
  86. !LongCall ?= 0
  87. !IncludeScrollingGradientCode ?= 0
  88.  
  89. !ScrollingFreeRAM_AB ?= $7FB260
  90. !ScrollingFreeRAM_C ?= $7FB830
  91.  
  92. if !LongCall
  93.     !LazyHDMA_Call = JSL : !LazyHDMA_CallS = "JSL "
  94.     !LazyHDMA_Tail = JML : !LazyHDMA_TailS = "JML "
  95.     !LazyHDMA_Return = RTL : !LazyHDMA_ReturnS = "RTL "
  96. else
  97.     !LazyHDMA_Call = JSR.w : !LazyHDMA_CallS = "JSR.w "
  98.     !LazyHDMA_Tail = JMP.w : !LazyHDMA_TailS = "JMP.w "
  99.     !LazyHDMA_Return = RTS : !LazyHDMA_ReturnS = "RTS "
  100. endif
  101.  
  102. macro _LazyHDMA_LoadLong(effect)
  103.     SEP #$30
  104.     LDA.b #<effect>
  105.     LDY.b #<effect>>>8
  106.     LDX.b #<effect>>>16
  107. endmacro
  108.  
  109. _LazyHDMA:
  110.  
  111. macro LazyInitEffect(effect)
  112.     %_LazyHDMA_LoadLong(<effect>)
  113.     !LazyHDMA_Call _LazyHDMA_InitializeEffect
  114. endmacro
  115.  
  116. macro LazyInitEffect_Tail(effect)
  117.     %_LazyHDMA_LoadLong(<effect>)
  118.     !LazyHDMA_Tail _LazyHDMA_InitializeEffect
  119. endmacro
  120.  
  121. if !IncludeScrollingGradientCode
  122.     macro LazyRunEffect(effect)
  123.         %_LazyHDMA_LoadLong(<effect>)
  124.         !LazyHDMA_Call _LazyHDMA_RunEffect
  125.     endmacro
  126.  
  127.     macro LazyRunEffect_Tail(effect)
  128.         %_LazyHDMA_LoadLong(<effect>)
  129.         !LazyHDMA_Tail _LazyHDMA_RunEffect
  130.     endmacro
  131. else
  132.     macro LazyRunEffect(effect)
  133.     endmacro
  134.     macro LazyRunEffect_Tail(effect)
  135.     endmacro
  136. endif
  137.  
  138. ; These registers can be written to by HDMA:
  139.  
  140. !INIDISP    = $2100 ; Display Control 1
  141. !OBSEL      = $2101 ; Object Size and Object Base
  142. !OAMADDL    = $2102 ; OAM Address (lower 8bit)
  143. !OAMADDH    = $2103 ; OAM Address (upper 1bit) and Priority Rotation
  144. !OAMDATA    = $2104 ; OAM Data Write (write-twice)
  145. !BGMODE     = $2105 ; BG Mode and BG Character Size
  146. !MOSAIC     = $2106 ; Mosaic Size and Mosaic Enable
  147. !BG1SC      = $2107 ; BG1 Screen Base and Screen Size
  148. !BG2SC      = $2108 ; BG2 Screen Base and Screen Size
  149. !BG3SC      = $2109 ; BG3 Screen Base and Screen Size
  150. !BG4SC      = $210A ; BG4 Screen Base and Screen Size
  151. !BG12NBA    = $210B ; BG Character Data Area Designation
  152. !BG34NBA    = $210C ; BG Character Data Area Designation
  153. !BG1HOFS    = $210D ; BG1 Horizontal Scroll (X) (write-twice) / M7HOFS
  154. !BG1VOFS    = $210E ; BG1 Vertical Scroll (Y)   (write-twice) / M7VOFS
  155. !BG2HOFS    = $210F ; BG2 Horizontal Scroll (X) (write-twice)
  156. !BG2VOFS    = $2110 ; BG2 Vertical Scroll (Y)   (write-twice)
  157. !BG3HOFS    = $2111 ; BG3 Horizontal Scroll (X) (write-twice)
  158. !BG3VOFS    = $2112 ; BG3 Vertical Scroll (Y)   (write-twice)
  159. !BG4HOFS    = $2113 ; BG4 Horizontal Scroll (X) (write-twice)
  160. !BG4VOFS    = $2114 ; BG4 Vertical Scroll (Y)   (write-twice)
  161. !VMAIN      = $2115 ; VRAM Address Increment Mode
  162. !VMADDL     = $2116 ; VRAM Address (lower 8bit)
  163. !VMADDH     = $2117 ; VRAM Address (upper 8bit)
  164. !VMDATAL    = $2118 ; VRAM Data Write (lower 8bit)
  165. !VMDATAH    = $2119 ; VRAM Data Write (upper 8bit)
  166. !M7SEL      = $211A ; Rotation/Scaling Mode Settings
  167. !M7A        = $211B ; Rotation/Scaling Parameter A & Maths 16bit operand
  168. !M7B        = $211C ; Rotation/Scaling Parameter B & Maths 8bit operand
  169. !M7C        = $211D ; Rotation/Scaling Parameter C         (write-twice)
  170. !M7D        = $211E ; Rotation/Scaling Parameter D         (write-twice)
  171. !M7X        = $211F ; Rotation/Scaling Center Coordinate X (write-twice)
  172. !M7Y        = $2120 ; Rotation/Scaling Center Coordinate Y (write-twice)
  173. !CGADD      = $2121 ; Palette CGRAM Address
  174. !CGDATA     = $2122 ; Palette CGRAM Data Write             (write-twice)
  175. !W12SEL     = $2123 ; Window BG1/BG2 Mask Settings
  176. !W34SEL     = $2124 ; Window BG3/BG4 Mask Settings
  177. !WOBJSEL    = $2125 ; Window OBJ/MATH Mask Settings
  178. !WH0        = $2126 ; Window 1 Left Position (X1)
  179. !WH1        = $2127 ; Window 1 Right Position (X2)
  180. !WH2        = $2128 ; Window 2 Left Position (X1)
  181. !WH3        = $2129 ; Window 2 Right Position (X2)
  182. !WBGLOG     = $212A ; Window 1/2 Mask Logic (BG1-BG4)
  183. !WOBJLOG    = $212B ; Window 1/2 Mask Logic (OBJ/MATH)
  184. !TM     = $212C ; Main Screen Designation
  185. !TS     = $212D ; Sub Screen Designation
  186. !TMW        = $212E ; Window Area Main Screen Disable
  187. !TSW        = $212F ; Window Area Sub Screen Disable
  188. !CGWSEL     = $2130 ; Color Math Control Register A
  189. !CGADSUB    = $2131 ; Color Math Control Register B
  190. !COLDATA    = $2132 ; Color Math Sub Screen Backdrop Color
  191. !SETINI     = $2133 ; Display Control 2
  192.  
  193. ; These can be used as transfer modes:
  194.  
  195. !OneRegisterWriteOnce       = 0 ; 1 byte:  p
  196. !TwoRegistersWriteOnce      = 1 ; 2 bytes: p, p+1
  197. !OneRegisterWriteTwice      = 2 ; 2 bytes: p, p
  198. !TwoRegistersWriteTwice     = 3 ; 4 bytes: p, p,   p+1, p+1
  199. !FourRegistersWriteOnce     = 4 ; 4 bytes: p, p+1, p+2, p+3
  200. !TwoRegistersWriteTwiceAlt  = 5 ; 4 bytes: p, p+1, p,   p+1
  201.  
  202. !HDMA_FixedPtr          = 8  ; Use a fixed CPU memory pointer
  203. !HDMA_DecrementPtr      = 16 ; CPU memory pointer decreases
  204. !HDMA_IndirectHDMA      = 64 ; The table uses pointers instead of data
  205.  
  206. !LazyHDMA_CommandMask = $1F
  207. !LazyHDMA_ChannelMask = $E0
  208.  
  209. macro _LazyHDMA_LoadArgs()
  210.     STA $00 ; Descriptor pointer, LSB
  211.     STY $01 ; Descriptor pointer, MSB
  212.     STX $02 ; Descriptor pointer, Bank
  213. ;   STX $03 ; Other address bank (initialization only)
  214.  
  215.     ;   $04 ; HDMA index (channel << 4)
  216.     ;   $05 ; second HDMA index (scrolling gradients only)
  217. endmacro
  218.  
  219. .InitializeEffect
  220.     %_LazyHDMA_LoadArgs()
  221.     STX $03
  222.  
  223.  -  SEP #$30    ; 8-bit A, X, Y
  224.     LDA [$00]
  225.     AND #!LazyHDMA_CommandMask
  226.     BEQ +
  227.     ASL
  228.     TAX
  229.     LDA [$00]
  230.     AND #!LazyHDMA_ChannelMask
  231.     LSR
  232.     STA $04
  233.  
  234.     REP #$20    ; 16-bit A
  235.     INC $00
  236.     JSR (.Subroutines-2, X)
  237.     BRA -
  238.  
  239.  +  !LazyHDMA_Return
  240.  
  241. !_LazySubroutine = 1
  242. !_LazySubroutineSizes = 1
  243.  
  244. macro _LazySubroutine(name, size)
  245.     assert !_LazySubroutine <= !LazyHDMA_CommandMask
  246.     !LazyHDMA_<name> #= !_LazySubroutine
  247.     !_LazySubroutine #= !_LazySubroutine+1
  248.     !_LazySubroutineSizes += ,<size>
  249.     dw .Set<name>
  250. endmacro
  251.  
  252. macro _LazySkip()
  253.     dw $0000
  254.     !_LazySubroutine #= !_LazySubroutine+1
  255.     !_LazySubroutineSizes += ,<size>
  256. endmacro
  257.  
  258. .Subroutines
  259.     %_LazySubroutine(LongPtr, 2)
  260.     %_LazySubroutine(BG, 3)
  261.     %_LazySubroutine(BGDouble, 3)
  262.     %_LazySubroutine(CGRAM, 3)
  263.     %_LazySubroutine(Brightness, 3)
  264. if !IncludeScrollingGradientCode
  265.     %_LazySubroutine(ScrollGradient, 4)
  266. else
  267.     %_LazySkip(4)
  268. endif
  269.     %_LazySubroutine(HDMA, 5)
  270.     %_LazySubroutine(BGFill, 3)
  271.  
  272. if !IncludeScrollingGradientCode
  273.     .SubroutineSizes db !_LazySubroutineSizes
  274. endif
  275.  
  276. !LazyHDMA_Invalid = !_LazySubroutine
  277.  
  278. .SetLongPtr
  279.     SEP #$20    ; \ 8-bit A
  280.     LDA [$00]   ; | \ Set the source bank number
  281.     STA $03     ; | /
  282.     REP #$20    ; / 16-bit A
  283.     INC $00     ; Next
  284.     RTS
  285.  
  286. .SetBGFill
  287.     LDA [$00]
  288.     STA $0701
  289.     INC $00
  290.     INC $00
  291.     RTS
  292.  
  293. .SetBG
  294.     LDA.w #!COLDATA<<8
  295. .SimpleCommon
  296.     LDX $04
  297.     STA $4300,X
  298.     LDA [$00]
  299.     STA $4302,X
  300.     SEP #$20 ; 8-bit A
  301.     LDA $03
  302.     STA $4304,X
  303.     TXA
  304.     LSR #4
  305.     TAX
  306.     LDA .Bits,X
  307.     TSB $0D9F
  308.     REP #$20 ; 16-bit A
  309.     INC $00
  310.     INC $00
  311.     LDX $02 ; \ Restore the data table bank
  312.     STX $03 ; / to the same bank as the descriptor
  313.     RTS
  314.  
  315. .SetBGDouble
  316.     LDA.w #(!COLDATA<<8)|!OneRegisterWriteTwice
  317.     BRA .SimpleCommon
  318. .SetCGRAM
  319.     LDA.w #(!CGADD<<8)|!TwoRegistersWriteTwice
  320.     BRA .SimpleCommon
  321. .SetBrightness
  322.     LDA.w #!INIDISP<<8
  323.     BRA .SimpleCommon
  324. .SetHDMA
  325.     LDA [$00]
  326.     INC $00
  327.     INC $00
  328.     BRA .SimpleCommon
  329.  
  330. .Bits   db %00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000
  331.  
  332. if !IncludeScrollingGradientCode
  333. .SetScrollGradient
  334.     LDY #$02    ; \
  335.     LDA [$00],Y ; | Load the second HDMA channel
  336.     TAX     ; | number and store it to scratch RAM
  337.     STX  $05    ; /
  338.  
  339.     PEI ($04)   ; \
  340.     LDX  $02    ; | Preserve scratch RAM
  341.     PHX     ; |
  342.     PEI ($00)   ; /
  343.     LDA [$00]   ; Load table pointer
  344.     PHB     ; Preserve data bank
  345.     LDX  $03    ; \
  346.     PHX     ; | Set data bank
  347.     PLB     ; /
  348.  
  349.     REP #$30    ; 16-bit A, X, Y
  350.     STA  $02
  351.     INC
  352.     STA  $04
  353.     INC
  354.     STA  $06
  355.     INC
  356.     STA  $08
  357.     LDA.w #!ScrollingFreeRAM_AB
  358.     STA  $0A
  359.     LDA.w #!ScrollingFreeRAM_C
  360.     STA  $0D
  361.     SEP #$20    ; 8-bit A
  362.     LDA #!ScrollingFreeRAM_AB>>16
  363.     STA  $0C
  364. if !ScrollingFreeRAM_AB>>16 != !ScrollingFreeRAM_C>>16
  365.     LDA #!ScrollingFreeRAM_C>>16
  366. endif
  367.     STA  $0F
  368. -   LDA ($02)
  369.     BEQ +
  370.     STA  $00
  371. --  LDA #$01
  372.     STA [$0A]
  373.     STA [$0D]
  374.     LDY #$0001
  375.     LDA ($04)
  376.     STA [$0A],y
  377.     LDA ($08)
  378.     STA [$0D],y
  379.     INY
  380.     LDA ($06)
  381.     STA [$0A],y
  382.     REP #$20
  383.     INC  $0A
  384.     INC  $0A
  385.     INC  $0A
  386.     INC  $0D
  387.     INC  $0D
  388.     SEP #$20
  389.     DEC  $00
  390.     BPL --
  391.     REP #$20
  392.     LDA  $02
  393.     CLC
  394.     ADC #$0004
  395.     STA  $02
  396.     INC
  397.     STA  $04
  398.     INC
  399.     STA  $06
  400.     INC
  401.     STA  $08
  402.     SEP #$20
  403.     BRA -
  404.  
  405. +   PLB     ; Restore previous data bank number
  406.     SEP #$10    ; Restore 8-bit X, Y
  407.     REP #$20    ; Restore 16-bit A
  408.     PLA     ; \
  409.     INC A       ; | \
  410.     INC A       ; | | Advance the command pointer
  411.     INC A       ; | /
  412.     STA $00     ; |
  413.     PLX     ; | Restore scratch RAM
  414.     STX $02     ; |
  415.     STX $03     ; | | Restore the data source bank
  416.     PLA     ; |
  417.     STA $04     ; /
  418.  
  419.     TAX     ; \ Load the HDMA indexes
  420.     LDY $05     ; /
  421.  
  422.     LDA.w #(!COLDATA<<8)|2      ; \
  423.     STA $4300,X         ; | Set HDMA channel types
  424.     LDA.w #!COLDATA<<8      ; |
  425.     STA $4300,Y         ; /
  426.  
  427.     SEP #$20    ; 8-bit A
  428.     TXA     ; \
  429.     LSR #4      ; |
  430.     TAX     ; | Enable gradient A
  431.     LDA .Bits,X ; |
  432.     TSB $0D9F   ; /
  433.     TYA     ; \
  434.     LSR #4      ; |
  435.     TAX     ; | Enable gradient B
  436.     LDA .Bits,X ; |
  437.     TSB  $0D9F  ; /
  438.     REP #$20    ; 16-bit A
  439.  
  440. .ScrollGradient:
  441.     LDA  $20    ; \ Load the Y-position of BG2
  442.     LDX  $1414  ; | \ Check how much the gradient should be shifted upward
  443.     CPX #$01    ; | | \
  444.     BEQ .Const  ; | | / #$01: Constant
  445.     CPX #$02    ; | | \
  446.     BEQ .Var    ; | | / #$02: Variable
  447.     CPX #$03    ; | | \
  448.     BEQ .Slow   ; | | / #$03: Slow
  449.             ; | |
  450. .None           ; | | \ No scrolling (consider using fixed HDMA)
  451.     SEC     ; | | |
  452.     SBC #$00C0  ; | | | shift 192 pixels downward
  453.     BRA .Const  ; | | / Continue
  454.             ; | |
  455. .Slow           ; | | \ Slow scrolling (consider using fixed HDMA)
  456.     SEC     ; | | |
  457.     SBC #$00A8  ; | | | shift 168 pixels downward
  458.     BRA .Const  ; | | /
  459.             ; | |
  460. .Var            ; | | \ Variable scrolling
  461.     SEC     ; | | |
  462.     SBC #$0060  ; | | / shift 96 pixels downward
  463.             ; | |
  464. .Const          ; | / < Constant scrolling (BG2:Camera = 1:1)
  465.             ; |
  466.             ; | \ Put an LSR/ASL or two here to change the rate at which
  467.             ; | / the gradient scrolls.
  468.             ; |
  469.     STA $06     ; / and store it to scratch RAM.
  470.  
  471.     LDX $04     ; \ Load the HDMA indexes
  472.     LDY $05     ; /
  473.  
  474.     LDA $06
  475.     ASL     ; \
  476.     CLC     ; | This transforms the Y-pos of BG2
  477.     ADC $06     ; | into the address at which the HDMA
  478.     CLC     ; | gradient should start
  479.     ADC.w #!ScrollingFreeRAM_AB
  480.     STA $4302,X ; HDMA Channel A table starting address.
  481.  
  482.     LDA $06     ; \
  483.     ASL     ; | Y-pos of BG2 to
  484.     CLC     ; | HDMA table offset
  485.     ADC.w #!ScrollingFreeRAM_C
  486.     STA $4302,Y ; HDMA Channel B table starting address.
  487.  
  488.     SEP #$20    ; 8-bit A
  489.     LDA.b #!ScrollingFreeRAM_AB>>16
  490.     STA $4304,X
  491. if !ScrollingFreeRAM_AB>>16 != !ScrollingFreeRAM_C>>16
  492.     LDA.b #!ScrollingFreeRAM_C>>16
  493. endif
  494.     STA $4304,Y
  495.  
  496.     RTS
  497.  
  498. .RunEffect:
  499.     %_LazyHDMA_LoadArgs()
  500.  
  501.  -  SEP #$30    ; 8-bit A, X, Y
  502.     LDA [$00]
  503.     AND #!LazyHDMA_CommandMask
  504.     BEQ +
  505.     CMP.b #!LazyHDMA_ScrollGradient
  506.     BEQ ++
  507.     TAX
  508.     LDA .SubroutineSizes,X
  509.     CLC
  510.     REP #$20    ; 16-bit A
  511.     AND #$00FF
  512.     ADC  $00
  513.     STA  $00
  514.     BRA -       ; Repeat
  515.  
  516.  ++ LDA [$00]
  517.     AND #!LazyHDMA_ChannelMask
  518.     LSR
  519.     STA $04
  520.  
  521.     LDY #$04    ; \
  522.     LDA [$00],Y ; | Load the second channel number
  523.     STA $05     ; /
  524.  
  525.     REP #$20    ; 16-bit A
  526.     INC  $00
  527.     JSR .ScrollGradient
  528.     REP #$20    ; 16-bit A
  529.     INC  $00
  530.     INC  $00
  531.     INC  $00
  532.     BRA -
  533.  
  534.  +  !LazyHDMA_Return
  535. endif
  536.  
  537. macro LazyBaseBG(color)
  538.     assert <color> >= 0 && <color> < $8000, "Invalid color"
  539.     db !LazyHDMA_BGFill
  540.     dw <color>
  541. endmacro
  542.  
  543. function rgb(r, g, b) = r|(g<<5)|(b<<10)
  544.  
  545. macro LazyHDMA(channel, params, register, address)
  546.     assert <channel> >= 0 && <channel> < 8, "Invalid HDMA channel"
  547.     assert <params> >= 0 && <params> < $80, "Invalid HDMA parameters"
  548.     if <register> >= $00 && <register> < $100
  549.     elseif <register> >= $2100 && <register> < $2200
  550.     else
  551.         error "Invalid HDMA target register"
  552.     endif
  553.     db !LazyHDMA_HDMA|(<channel><<5)
  554.     db <params>, <register>
  555.     dw <address>
  556. endmacro
  557.  
  558. macro LazyHDMA_Long(channel, params, register, address)
  559.     db !LazyHDMA_LongPtr, (<address>>>16)
  560.     %LazyHDMA(channel, params, register, address)
  561. endmacro
  562.  
  563. macro LazySimple(type, channel, address)
  564.     assert <type> > 0 && <type> < !LazyHDMA_Invalid, "Invalid channel type"
  565.     assert <channel> >= 0 && <channel> < 8, "Invalid HDMA channel"
  566.     db <type>|(<channel><<5)
  567.     dw <address>
  568. endmacro
  569.  
  570. macro LazyBGSingle(channel, address)
  571.     %LazySimple(!LazyHDMA_BG, <channel>, <address>)
  572. endmacro
  573. macro LazyBGDouble(channel, address)
  574.     %LazySimple(!LazyHDMA_BGDouble, <channel>, <address>)
  575. endmacro
  576. macro LazyCGRAM(channel, address)
  577.     %LazySimple(!LazyHDMA_CGRAM, <channel>, <address>)
  578. endmacro
  579. macro LazyBrightness(channel, address)
  580.     %LazySimple(!LazyHDMA_Brightness, <channel>, <address>)
  581. endmacro
  582.  
  583. macro LazySimple_Long(type, channel, address)
  584.     db !LazyHDMA_LongPtr, (<address>>>16)
  585.     %LazySimple(<type>, <channel>, <address>)
  586. endmacro
  587.  
  588. macro LazyBGSingle_Long(channel, address)
  589.     %LazySimple_Long(!LazyHDMA_BG, <channel>, <address>)
  590. endmacro
  591. macro LazyBGDouble_Long(channel, address)
  592.     %LazySimple_Long(!LazyHDMA_BGDouble, <channel>, <address>)
  593. endmacro
  594. macro LazyCGRAM_Long(channel, address)
  595.     %LazySimple_Long(!LazyHDMA_CGRAM, <channel>, <address>)
  596. endmacro
  597. macro LazyBrightness_Long(channel, address)
  598.     %LazySimple_Long(!LazyHDMA_Brightness, <channel>, <address>)
  599. endmacro
  600.  
  601. if !IncludeScrollingGradientCode
  602.     macro LazyScroll(channel, secondchannel, address)
  603.         %LazySimple(!LazyHDMA_ScrollGradient, <channel>, <address>)
  604.         db <secondchannel><<4
  605.     endmacro
  606.     macro LazyScroll_Long(channel, secondchannel, address)
  607.         %LazySimple_Long(!LazyHDMA_ScrollGradient, <channel>, <address>)
  608.         db <secondchannel><<4
  609.     endmacro
  610. endif
  611.  
  612. macro LazyEnd()
  613.     db $00
  614. endmacro
RAW Paste Data