-
Notifications
You must be signed in to change notification settings - Fork 18
/
mega65_dmagic.s
142 lines (95 loc) · 2.84 KB
/
mega65_dmagic.s
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
;; #LAYOUT# M65 KERNAL_1 #TAKE
;; #LAYOUT# * * #IGNORE
; Helper routines for DMAgic usage
; See:
; - https://c65gs.blogspot.com/2019/03/auto-detecting-required-revision-of.html
; - https://c65gs.blogspot.com/2018/01/improving-dmagic-controller-interface.html
m65_dmagic_oper_fill:
; To configure job parameters, use:
; - M65_DMAJOB_SIZE_*
; - M65_DMAJOB_DST_*
; - .A - byte for filling
; Afterwards, consider M65_DMAJOB_DST_2 and M65_DMAJOB_*_3 destroyed.
; Set fill address
sta M65_DMAJOB_SRC_0
; Set operation type
lda #$03 ; operation: FILL
sta M65_DMAGIC_LIST+6
; Put this into M65_DMAJOB_SRC_2 too - to make sure flags (4 most significant bits) are cleared
sta M65_DMAJOB_SRC_2
; Adapt the addresses, launch the job
jsr m65_dmagic_adapt_dst
bra m65_dmagic_launch
m65_dmagic_oper_copy:
; To configure job parameters, use:
; - M65_DMAJOB_SIZE_*
; - M65_DMAJOB_SRC_*
; - M65_DMAJOB_DST_*
; Afterwards, consider M65_DMAJOB_*_2 and M65_DMAJOB_*_3 destroyed.
; Set operation type
lda #$00 ; operation: COPY
sta M65_DMAGIC_LIST+6
; Adapt the addresses, launch the job
jsr m65_dmagic_adapt_src
jsr m65_dmagic_adapt_dst
; XXX possibly prepare separate version for the opposite direction - change direction
; by setting bit 6 of M65_DMAJOB_*_2
; FALLTROUGH
m65_dmagic_launch:
; Launch the DMA list
lda #$00
sta DMA_ADDRBANK ; $D702
sta DMA_ADDRMB ; $D704
lda #>M65_DMAGIC_LIST
sta DMA_ADDRMSB ; $D701
lda #<M65_DMAGIC_LIST
sta DMA_ETRIG ; $D705
rts
m65_dmagic_adapt_src:
; We need to adapt the addresses:
; - M65_DMAJOB_SRC_2 - contain bits 16-23, should contain 16-19
; - M65_DMAJOB_SRC_3 - contain bits 24-27, should contain 20-27
lda M65_DMAJOB_SRC_2
pha
asl
rol M65_DMAJOB_SRC_3
asl
rol M65_DMAJOB_SRC_3
asl
rol M65_DMAJOB_SRC_3
asl
rol M65_DMAJOB_SRC_3
pla
and #%00001111
sta M65_DMAJOB_SRC_2
rts
m65_dmagic_adapt_dst:
; We need to adapt the addresses:
; - M65_DMAJOB_DST_2 - contain bits 16-23, should contain 16-19
; - M65_DMAJOB_DST_3 - contain bits 24-27, should contain 20-27
lda M65_DMAJOB_DST_2
pha
asl
rol M65_DMAJOB_DST_3
asl
rol M65_DMAJOB_DST_3
asl
rol M65_DMAJOB_DST_3
asl
rol M65_DMAJOB_DST_3
pla
and #%00001111
sta M65_DMAJOB_DST_2
rts
m65_dmagic_init:
; Set common job parameters
lda #$0A
sta M65_DMAGIC_LIST+0 ; <- $0A = use F018A list format (it is shorter by 1 byte)
lda #$80
sta M65_DMAGIC_LIST+1 ; <- $80 = next byte is highest 8 bits of source address
inc
sta M65_DMAGIC_LIST+3 ; <- $81 = next byte is highest 8 bits of destination address
lda #$00
sta M65_DMAGIC_LIST+5 ; <- end of options
; Modulo is never used - thus our list is 15 bytes, not 17
rts