-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadBlockToVRAM.asm
More file actions
74 lines (66 loc) · 2.9 KB
/
LoadBlockToVRAM.asm
File metadata and controls
74 lines (66 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;============================================================================
; Author: bazz
; Borrowed from: https://wiki.superfamicom.org/working-with-vram-initializing-tiles-and-tile-maps
;============================================================================
;============================================================================
; LoadBlockToVRAM -- Macro that simplifies calling LoadVRAM to copy data to VRAM
;----------------------------------------------------------------------------
; In: SRC_ADDR -- 24 bit address of source data
; DEST -- VRAM address to write to (WORD address!!)
; SIZE -- number of BYTEs to copy
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
; Modifies: A, X, Y
;----------------------------------------------------------------------------
;============================================================================
;LoadBlockToVRAM SRC_ADDRESS, DEST, SIZE
; requires: mem/A = 8 bit, X/Y = 16 bit
;============================================================================
macro LoadBlockToVRAM(SRC_ADDR_BANK, SRC_ADDR, DEST, SIZE)
ldx.w #<DEST> ; DEST
stx $2116 ; $2116: Word address for accessing VRAM.
lda.b #<SRC_ADDR_BANK> ; SRCBANK
ldx.w #<SRC_ADDR> ; SRCOFFSET
ldy.w #<SIZE> ; SIZE
jsr LoadVRAM
endmacro
;============================================================================
;============================================================================
; LoadVRAM -- Load data into VRAM
;----------------------------------------------------------------------------
; In: A:X -- points to the data
; Y -- Number of bytes to copy (0 to 65535) (assumes 16-bit index)
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
; Modifies: none
;----------------------------------------------------------------------------
; Notes: Assumes VRAM address has been previously set!!
;----------------------------------------------------------------------------
LoadVRAM:
pha
phx
phy
phb
php ;Preserve registers
sep #$20 ;Careful not to SEP $10, or it will erase upper half of Y!
stz $420B ;Clear the DMA control register
stx $4302 ;Store the data offset into DMA source offset
sty $4305 ;Store the size of the data block
sta $4304 ;Store the data bank of the source data
lda #$80
sta $2115 ;set VRAM transfer mode to word-access, increment by 1
lda #$01 ;Set the DMA mode (word, normal increment)
sta $4300
lda #$18 ;Set the destination register (VRAM gate)
sta $4301
lda #$01 ;Initiate the DMA transfer
sta $420B
plp ;Restore registers
plb
ply
plx
pla
rts ;Return to caller
;============================================================================