/
dsurf.asm
258 lines (215 loc) · 5.61 KB
/
dsurf.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
;
; RRPGE User Library functions - Destination surfaces
;
; Author Sandor Zsuga (Jubatian)
; Copyright 2013 - 2015, GNU GPLv3 (version 3 of the GNU General Public
; License) extended as RRPGEvt (temporary version of the RRPGE
; License): see LICENSE.GPLv3 and LICENSE.RRPGEvt in the project
; root.
;
;
; Destination surface management for assisting accelerator usage.
;
; Uses the following CPU RAM locations:
;
; 0xFDBF: Double buffering flipflop on bit 0 (0: 'A' is the display surface)
; 0xFDC0 - 0xFDC7: Default surface definition (just a surface structure)
;
; Uses surface structures (objects) of the following layout:
;
; Word0: PRAM Write mask for the surface, high (for 0x0000)
; Word1: PRAM Write mask for the surface, low (for 0x0001)
; Word2: Surface A bank select (for 0x0002)
; Word3: Surface B bank select (for 0x0002)
; Word4: Surface A partition select (for 0x0003)
; Word5: Surface B partition select (for 0x0003)
; Word6: Width of destination in cells (for 0x0004)
; Word7: Partition size (only destination, for 0x0014)
;
include "rrpge.asm"
section code
; 0xFDBF: Double buffering flipflop (bit 0)
us_dsurf_ff equ 0xFDBF
; 0xFDC0: Default surface
us_dsurf_defs equ 0xFDC0
;
; Implementation of us_dsurf_set
;
us_dsurf_new_i:
.tgp equ 0 ; Target pointer
.bnk equ 1 ; Bank select for A & B
.prt equ 2 ; Partition select for A & B
.wdt equ 3 ; Width
.psz equ 4 ; Partition size (low 4 bits)
mov x3, [$.tgp]
not c, 0 ; Load 0xFFFF for masks
mov [x3], c
mov [x3], c ; Mask high & low
mov c, [$.psz]
shl c, 12 ; To dest. partition
mov [x3], c ; Partition size
mov c, [$.bnk]
mov [x3], c
mov [x3], c ; Surface A & B bank select
mov c, [$.prt]
mov [x3], c
mov [x3], c ; Surface A & B partition select
mov c, [$.wdt]
mov [x3], c ; Width
rfn c:x3, 0
;
; Implementation of us_dsurf_setdbuf
;
us_dsurf_newdbuf_i:
.tgp equ 0 ; Target pointer
.bna equ 1 ; Bank select for A
.pra equ 2 ; Partition select for A
.bnb equ 3 ; Bank select for B
.prb equ 4 ; Partition select for B
.wdt equ 5 ; Width
.psz equ 6 ; Partition size (low 4 bits)
mov x3, [$.tgp]
not c, 0 ; Load 0xFFFF for masks
mov [x3], c
mov [x3], c ; Mask high & low
mov c, [$.psz]
shl c, 12 ; To dest. partition
mov [x3], c ; Partition size
mov c, [$.bna]
mov [x3], c
mov c, [$.bnb]
mov [x3], c ; Surface A & B bank select
mov c, [$.pra]
mov [x3], c
mov c, [$.prb]
mov [x3], c ; Surface A & B partition select
mov c, [$.wdt]
mov [x3], c ; Width
rfn c:x3, 0
;
; Implementation of us_dsurf_setm
;
us_dsurf_newm_i:
.tgp equ 0 ; Target pointer
.msh equ 1 ; Mask, high
.msl equ 2 ; Mask, low
.bnk equ 3 ; Bank select for A & B
.prt equ 4 ; Partition select for A & B
.wdt equ 5 ; Width
.psz equ 6 ; Partition size (low 4 bits)
mov x3, [$.tgp]
mov c, [$.msh]
mov [x3], c
mov c, [$.msl]
mov [x3], c ; Mask high & low
mov c, [$.psz]
shl c, 12 ; To dest. partition
mov [x3], c ; Partition size
mov c, [$.bnk]
mov [x3], c
mov [x3], c ; Surface A & B bank select
mov c, [$.prt]
mov [x3], c
mov [x3], c ; Surface A & B partition select
mov c, [$.wdt]
mov [x3], c ; Width
rfn c:x3, 0
;
; Implementation of us_dsurf_setmdbuf
;
us_dsurf_newmdbuf_i:
.tgp equ 0 ; Target pointer
.msh equ 1 ; Mask, high
.msl equ 2 ; Mask, low
.bna equ 3 ; Bank select for A
.pra equ 4 ; Partition select for A
.bnb equ 5 ; Bank select for B
.prb equ 6 ; Partition select for B
.wdt equ 7 ; Width
.psz equ 8 ; Partition size (low 4 bits)
mov x3, [$.tgp]
mov c, [$.msh]
mov [x3], c
mov c, [$.msl]
mov [x3], c ; Mask high & low
mov c, [$.psz]
shl c, 12 ; To dest. partition
mov [x3], c ; Partition size
mov c, [$.bna]
mov [x3], c
mov c, [$.bnb]
mov [x3], c ; Surface A & B bank select
mov c, [$.pra]
mov [x3], c
mov c, [$.prb]
mov [x3], c ; Surface A & B partition select
mov c, [$.wdt]
mov [x3], c ; Width
rfn c:x3, 0
;
; Implementation of us_dsurf_get
;
us_dsurf_get_i:
.srp equ 0 ; Source pointer
jfa us_dbuf_getlist_i ; Wait for frame end if necessary
.entr: mov x3, [$.srp]
xbs [us_dsurf_ff], 0
add x3, 1 ; If clear, B is the work surface
add x3, 3 ; Selects A or B bank select
mov c, [x3] ; Bank
add x3, 1
rfn x3, [x3] ; Partition
;
; Implementation of us_dsurf_getacc
;
us_dsurf_getacc_i:
.srp equ 0 ; Source pointer
jfa us_dbuf_getlist_i ; Wait for frame end if necessary
mov x3, [$.srp]
mov c, 0x0000
mov [P_GFIFO_ADDR], c
mov c, [x3]
mov [P_GFIFO_DATA], c ; Write mask, high
mov c, [x3]
mov [P_GFIFO_DATA], c ; Write mask, low
mov c, [x3] ; Load partitioning setting
xbs [us_dsurf_ff], 0
add x3, 1 ; If clear, B is the work surface
or c, [x3]
mov [P_GFIFO_DATA], c ; Destination bank select & Partition size
add x3, 1
mov c, [x3]
mov [P_GFIFO_DATA], c ; Destination partition select
xbc [us_dsurf_ff], 0
add x3, 1 ; Restore offset in 'x3'
mov c, [x3]
mov [P_GFIFO_DATA], c ; Destination width (post-add whole)
mov c, 0
mov [P_GFIFO_DATA], c ; Destination width (post-add fraction)
jms us_dsurf_get_i.entr ; Tail-transfer for return value
;
; Implementation of us_dsurf_getwp
;
us_dsurf_getpw_i:
.srp equ 0 ; Source pointer
mov x3, [$.srp]
add x3, 7
mov c, [x3]
sub x3, 6
mov x3, [x3]
shr x3, 12
xch c, x3
rfn
;
; Implementation of us_dsurf_init
;
us_dsurf_init_i:
bts [us_dsurf_ff], 0
rfn
;
; Implementation of us_dsurf_flip
;
us_dsurf_flip_i:
mov c, 1
xor [us_dsurf_ff], c
rfn c:x3, 0