-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadGraphics.asm
142 lines (121 loc) · 4.23 KB
/
LoadGraphics.asm
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
;============================================================
; Macros
;============================================================
;============================================================
;LoadPalette - Macro that loads palette information into CGRAM
;------------------------------------------------------------
; In: SRC_ADDR -- 24 bit address of source data,
; START -- Color # to start on,
; SIZE -- # of COLORS to copy
;------------------------------------------------------------
; Out: None
;------------------------------------------------------------
; Modifies: A,X
; Requires: mem/A = 8 bit, X/Y = 16 bit
;------------------------------------------------------------
.MACRO LoadPalette
lda #\2
sta $2121 ; Start at START color
lda #:\1 ; Using : before the parameter gets its bank.
ldx #\1 ; Not using : gets the offset address.
ldy #(\3 * 2) ; 2 bytes for every color
jsr DMAPalette
.ENDM
;============================================================
; 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
lda #$80
sta $2115
ldx #\2 ; DEST
stx $2116 ; $2116: Word address for accessing VRAM.
lda #:\1 ; SRCBANK
ldx #\1 ; SRCOFFSET
ldy #\3 ; SIZE
jsr LoadVRAM
.ENDM
;============================================================
; Routines
;============================================================
.BANK 0 SLOT 1
.ORG 0
.SECTION "LoadVRAMCode" SEMIFREE
;============================================================
; 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
stx $4302 ; Store Data offset into DMA source offset
sta $4304 ; Store data Bank into DMA source bank
sty $4305 ; Store size of data block
lda #$01
sta $4300 ; Set DMA mode (word, normal increment)
lda #$18 ; Set the destination register (VRAM write register)
sta $4301
lda #$01 ; Initiate DMA transfer (channel 1)
sta $420B
plp ; restore registers
plb
ply
plx
pla
rts ; return
;===========================================================
.ENDS
.BANK 0 SLOT 1
.ORG 0
.SECTION "DMAPaletteCode" SEMIFREE
;==========================================================
; DMAPalette -- Load entire palette using DMA
; In: A:X -- points to the data
; Y -- Size of data
;----------------------------------------------------------
; Out: None
;----------------------------------------------------------
; Modifies: none
;----------------------------------------------------------
DMAPalette:
pha
phx
phb
php ; Preserve Registers
sep #$20
stx $4302 ; Store data offset into DMA source offset
sta $4304 ; Store data bank into DMA source bank
sty $4305 ; Store size of data block
stz $4300 ; Set DMA Mode (byte, normal increment)
lda #$22 ; Set destination register ($2122 - CGRAM Write)
sta $4301
lda #$01 ; Initiate DMA transfer
sta $420B
plp ; Restore registers
plb
plx
pla
rts ; return from subroutine
;==========================================================
.ENDS