memoryclear.asm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. ;partially clears wram to predefined value
  3. ;in: a,8bit: number of word to clear memory with.
  4. ; x,16bit: target word adress in wram bank $7e
  5. ; y,16bit: transfer length
  6. ;how to use:
  7. rep #$31
  8. sep #$20
  9. lda.b #0 ;clear word: $0000
  10. ldy.w #$200
  11. ldx.w #PaletteBuffer&$ffff
  12. jsr ClearWRAM
  13. */
  14. ClearWRAM:
  15. php
  16. phb
  17. sep #$20
  18. pha
  19. lda.b #$80
  20. pha
  21. plb
  22. pla
  23. REP #$31 ; mem/A = 8 bit, X/Y = 16 bit
  24. and.w #$7 ;calculate adress of clear pattern word(8 entries max)
  25. asl a
  26. adc.w #ClearWramBytePatterns
  27. sta.w $4312 ;dma source
  28. SEP #$20
  29. lda.b #(:ClearWramBytePatterns+BaseAdress>>16)
  30. STA $4314 ;Set source bank to $00
  31. stx.w $2181 ;store target wram adress in bank $7e
  32. stz.w $2183 ;bank $7e
  33. LDX #$800a
  34. STX $4310 ;Set DMA mode to fixed source, WORD to $2180
  35. sty.w $4315 ;Set transfer size
  36. LDA #$02
  37. STA $420B ;Initiate transfer
  38. plb
  39. plp
  40. RTS
  41. ;byte patterns to clear wram with.(8 entries max)
  42. ClearWramBytePatterns:
  43. .dw 0 ;zeros
  44. .dw $eaea ;nops
  45. .dw $2480 ;bg3 tilemap clear word
  46. .dw $00c9 ;oam buffer
  47. .dw $2907 ;bg1 tilemap clear
  48. ;clears whole vram
  49. ClearVRAM:
  50. pha
  51. phx
  52. php
  53. REP #$30 ; mem/A = 8 bit, X/Y = 16 bit
  54. SEP #$20
  55. LDA #$80
  56. sta.w $2100 ;set blanking active
  57. stz.w $4200 ;disable irqs
  58. STA $2115 ;Set VRAM port to word access
  59. LDX #$1809
  60. STX $4310 ;Set DMA mode to fixed source, WORD to $2118/9
  61. LDX #$0000
  62. STX $2116 ;Set VRAM port address to $0000
  63. STX $0000 ;Set $00:0000 to $0000 (assumes scratchpad ram)
  64. STX $4312 ;Set source address to $xx:0000
  65. LDA #$00
  66. STA $4314 ;Set source bank to $00
  67. LDX #$FFFF
  68. STX $4315 ;Set transfer size to 64k-1 bytes
  69. LDA #$02
  70. STA $420B ;Initiate transfer
  71. STZ $2119 ;clear the last byte of the VRAM
  72. lda.b ScreenBrightness
  73. sta.w $2100 ;reenable screen and irqs
  74. lda.b InterruptEnableFlags
  75. sta.w $4200
  76. plp
  77. plx
  78. pla
  79. RTS
  80. ;copy random data to wram
  81. ;in: TempBuffer0-2 - source pointer
  82. ; x - wram bank $7e target
  83. ; y - transfer length
  84. DmaToWRAM:
  85. php
  86. phb
  87. sep #$20
  88. pha
  89. lda.b #$80
  90. pha
  91. plb
  92. pla
  93. REP #$31 ; mem/A = 8 bit, X/Y = 16 bit
  94. lda.b TempBuffer
  95. sta.w $4312 ;dma source
  96. SEP #$20
  97. lda.b TempBuffer+2
  98. STA $4314 ;Set source bank to $00
  99. stx.w $2181 ;store target wram adress in bank $7e
  100. stz.w $2183 ;bank $7e
  101. LDX #$8002
  102. STX $4310 ;Set DMA mode to inc source, WORD to $2180
  103. sty.w $4315 ;Set transfer size
  104. LDA #$02
  105. STA $420B ;Initiate transfer
  106. plb
  107. plp
  108. RTS
  109. ;uploads 1 hirom bank to ram bank $7f
  110. ROMToWRAM:
  111. php
  112. phb
  113. sep #$20
  114. pha
  115. lda.b #$80
  116. pha
  117. plb
  118. pla
  119. REP #$31 ; mem/A = 8 bit, X/Y = 16 bit
  120. stz.w $4315 ;Set transfer size
  121. stz.w $4312 ;dma source
  122. stz.w $2181 ;$7f0000
  123. SEP #$20
  124. lda.b #$c0
  125. STA $4314 ;Set source bank to $00
  126. lda.b #1
  127. sta.w $2183 ;bank $7e
  128. LDX #$8002
  129. STX $4310 ;Set DMA mode to inc source, WORD to $2180
  130. LDA #$02
  131. STA $420B ;Initiate transfer
  132. plb
  133. plp
  134. RTS