LoadGraphics.asm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ;============================================================================
  2. ; Macros
  3. ;============================================================================
  4. ;============================================================================
  5. ;LoadPalette - Macro that loads palette information into CGRAM
  6. ;----------------------------------------------------------------------------
  7. ; In: SRC_ADDR -- 24 bit address of source data,
  8. ; START -- Color # to start on,
  9. ; SIZE -- # of COLORS to copy
  10. ;----------------------------------------------------------------------------
  11. ; Out: None
  12. ;----------------------------------------------------------------------------
  13. ; Modifies: A,X
  14. ; Requires: mem/A = 8 bit, X/Y = 16 bit
  15. ;----------------------------------------------------------------------------
  16. .MACRO LoadPalette
  17. lda #\2
  18. sta $2121 ; Start at START color
  19. lda #:\1 ; Using : before the parameter gets its bank.
  20. ldx #\1 ; Not using : gets the offset address.
  21. ldy #(\3 * 2) ; 2 bytes for every color
  22. jsr DMAPalette
  23. .ENDM
  24. ;============================================================================
  25. ; LoadBlockToVRAM -- Macro that simplifies calling LoadVRAM to copy data to VRAM
  26. ;----------------------------------------------------------------------------
  27. ; In: SRC_ADDR -- 24 bit address of source data
  28. ; DEST -- VRAM address to write to (WORD address!!)
  29. ; SIZE -- number of BYTEs to copy
  30. ;----------------------------------------------------------------------------
  31. ; Out: None
  32. ;----------------------------------------------------------------------------
  33. ; Modifies: A, X, Y
  34. ;----------------------------------------------------------------------------
  35. ;LoadBlockToVRAM SRC_ADDRESS, DEST, SIZE
  36. ; requires: mem/A = 8 bit, X/Y = 16 bit
  37. .MACRO LoadBlockToVRAM
  38. lda #$80
  39. sta $2115
  40. ldx #\2 ; DEST
  41. stx $2116 ; $2116: Word address for accessing VRAM.
  42. lda #:\1 ; SRCBANK
  43. ldx #\1 ; SRCOFFSET
  44. ldy #\3 ; SIZE
  45. jsr LoadVRAM
  46. .ENDM
  47. ;============================================================================
  48. ; Routines
  49. ;============================================================================
  50. .BANK 0
  51. .ORG 0
  52. .SECTION "LoadVRAMCode" SEMIFREE
  53. ;============================================================================
  54. ; LoadVRAM -- Load data into VRAM
  55. ;----------------------------------------------------------------------------
  56. ; In: A:X -- points to the data
  57. ; Y -- Number of bytes to copy (0 to 65535) (assumes 16-bit index)
  58. ;----------------------------------------------------------------------------
  59. ; Out: None
  60. ;----------------------------------------------------------------------------
  61. ; Modifies: none
  62. ;----------------------------------------------------------------------------
  63. ; Notes: Assumes VRAM address has been previously set!!
  64. ;----------------------------------------------------------------------------
  65. LoadVRAM:
  66. pha
  67. phx
  68. phy
  69. phb
  70. php ; Preserve Registers
  71. sep #$20
  72. stx $4302 ; Store Data offset into DMA source offset
  73. sta $4304 ; Store data Bank into DMA source bank
  74. sty $4305 ; Store size of data block
  75. lda #$01
  76. sta $4300 ; Set DMA mode (word, normal increment)
  77. lda #$18 ; Set the destination register (VRAM write register)
  78. sta $4301
  79. lda #$01 ; Initiate DMA transfer (channel 1)
  80. sta $420B
  81. plp ; restore registers
  82. plb
  83. ply
  84. plx
  85. pla
  86. rts ; return
  87. ;============================================================================
  88. .ENDS
  89. .BANK 0
  90. .ORG 0
  91. .SECTION "DMAPaletteCode" SEMIFREE
  92. ;============================================================================
  93. ; DMAPalette -- Load entire palette using DMA
  94. ;----------------------------------------------------------------------------
  95. ; In: A:X -- points to the data
  96. ; Y -- Size of data
  97. ;----------------------------------------------------------------------------
  98. ; Out: None
  99. ;----------------------------------------------------------------------------
  100. ; Modifies: none
  101. ;----------------------------------------------------------------------------
  102. DMAPalette:
  103. pha
  104. phx
  105. phb
  106. php ; Preserve Registers
  107. sep #$20
  108. stx $4302 ; Store data offset into DMA source offset
  109. sta $4304 ; Store data bank into DMA source bank
  110. sty $4305 ; Store size of data block
  111. stz $4300 ; Set DMA Mode (byte, normal increment)
  112. lda #$22 ; Set destination register ($2122 - CGRAM Write)
  113. sta $4301
  114. lda #$01 ; Initiate DMA transfer
  115. sta $420B
  116. plp ; Restore registers
  117. plb
  118. plx
  119. pla
  120. rts ; return from subroutine
  121. ;============================================================================
  122. .ENDS