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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// copyright 2022 mikael lund aka wombat
//
// licensed under the apache license, version 2.0 (the "license");
// you may not use this file except in compliance with the license.
// you may obtain a copy of the license at
//
// http://www.apache.org/licenses/license-2.0
//
// unless required by applicable law or agreed to in writing, software
// distributed under the license is distributed on an "as is" basis,
// without warranties or conditions of any kind, either express or implied.
// see the license for the specific language governing permissions and
// limitations under the license.
//
// originally from cc65 header file; modififed from original version.
//
// cx16.h
//
// CX16 system-specific definitions
// For prerelease 39
//
//
// This software is provided "as-is", without any expressed or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated, but is not required.
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source
// distribution.
//! Registers for the Versatile Embedded Retro Adapter (VERA) graphics chip.
//!
//! VERA consists of:
//! - Video generator featuring:
//! - Multiple output formats (VGA, NTSC Composite, NTSC S-Video, RGB video) at a fixed resolution of 640x480 at 60Hz
//! - Support for two layers, both supporting either tile or bitmap mode.
//! - Support for up to 128 sprites.
//! - Embedded video RAM of 128kB.
//! - Palette with 256 colors selected from a total range of 4096 colors.
//! - 16-channel Programmable Sound Generator with multiple waveforms (Pulse, Sawtooth, Triangle, Noise)
//! - High quality PCM audio playback from 4 kB FIFO buffer with up to 48kHz 16-bit stereo sound.
//! - SPI controller for SecureDigital storage.
//! - [VERA Reference Guide](https://github.com/commanderx16/x16-docs/blob/master/VERA%20Programmer's%20Reference.md)
use bitflags;
use ManuallyDrop;
use ;
pub const VIDEOMODE_80X60: u8 = 0;
pub const VIDEOMODE_80X30: u8 = 1;
pub const VIDEOMODE_40X60: u8 = 2;
pub const VIDEOMODE_40X30: u8 = 3;
pub const VIDEOMODE_40X15: u8 = 4;
pub const VIDEOMODE_20X30: u8 = 5;
pub const VIDEOMODE_20X15: u8 = 6;
pub const VIDEOMODE_80COL: u8 = 0;
pub const VIDEOMODE_40COL: u8 = 3;
pub const VIDEOMODE_320X240: u8 = 128;
pub const VIDEOMODE_SWAP: i32 = -1;
pub const IRQ_VSYNC: u8 = 1;
pub const IRQ_RASTER: u8 = 2;
pub const IRQ_SPR_COLL: u8 = 4;
pub const IRQ_AUDIO_LOW: u8 = 8;
pub const INC_0: u8 = convert_stride;
pub const INC_2: u8 = convert_stride;
pub const INC_4: u8 = convert_stride;
pub const INC_8: u8 = convert_stride;
pub const INC_16: u8 = convert_stride;
pub const INC_32: u8 = convert_stride;
pub const INC_64: u8 = convert_stride;
pub const INC_128: u8 = convert_stride;
pub const INC_256: u8 = convert_stride;
pub const INC_512: u8 = convert_stride;
pub const INC_40: u8 = convert_stride;
pub const INC_80: u8 = convert_stride;
pub const INC_160: u8 = convert_stride;
pub const INC_320: u8 = convert_stride;
pub const INC_640: u8 = convert_stride;
pub const DEC_0: u8 = convert_stride;
pub const DEC_2: u8 = convert_stride;
pub const DEC_4: u8 = convert_stride;
pub const DEC_8: u8 = convert_stride;
pub const DEC_16: u8 = convert_stride;
pub const DEC_32: u8 = convert_stride;
pub const DEC_64: u8 = convert_stride;
pub const DEC_128: u8 = convert_stride;
pub const DEC_256: u8 = convert_stride;
pub const DEC_512: u8 = convert_stride;
pub const DEC_40: u8 = convert_stride;
pub const DEC_80: u8 = convert_stride;
pub const DEC_160: u8 = convert_stride;
pub const DEC_320: u8 = convert_stride;
pub const DEC_640: u8 = convert_stride;
/// Convert stride to register value.
///
/// By setting the 'Address Increment' field in `ADDRx_H`, the address will be incremented after each access to the data register.
/// Setting the `DECR` bit, will decrement instead of increment.
/// More [information](https://github.com/commanderx16/x16-docs/blob/master/VERA%20Programmer's%20Reference.md#video-ram-access)
///
/// Example:
/// ~~~
/// const DEC_8: u8 = convert_stride(-8); // negative stride
/// const INC_127: u8 = convert_stride(127); // compile time error: invalid stride
/// ~~~
pub const
/// Versatile Embedded Retro Adapter (VERA) graphics chip
bitflags!
pub union DisplayComposer
bitflags!
/// Active when Display Composer (DC) SEL=0
/// Active when Display Composer (DC) `SEL=1`
///
/// `HSTART`/`HSTOP` and `VSTART`/`VSTOP` determines the active part of the screen.
/// The values here are specified in the native 640x480 display space.
/// `HSTART=0`, `HSTOP=640`, `VSTART=0`, `VSTOP=480` will set the active area to the full resolution.
/// Note that the lower 2 bits of `HSTART`/`HSTOP` and the lower 1 bit of `VSTART`/`VSTOP` isn't available.
/// This means that horizontally the start and stop values can be set at a multiple of 4 pixels,
/// vertically at a multiple of 2 pixels.
/// Video layer registers
///
/// The features of the two VERA layers are the same.
/// Each layer supports a few different modes which are specified using T256C / 'Bitmap Mode' / 'Color Depth' in `Lx_CONFIG`.
/// The layer can either operate in tile mode or bitmap mode.
/// This is selected using the 'Bitmap Mode' bit; 0 selects tile mode, 1 selects bitmap mode.
/// The handling of 1 bpp tile mode is different from the other tile modes.
/// Depending on the T256C bit the tiles use either a 16-color foreground and background color or a 256-color foreground color.
/// Other modes ignore the T256C bit.
/// VERA audio
///
/// The audio functionality consists of two independent systems:
/// 1. The PSG or Programmable Sound Generator.
/// 2. The PCM (or Pulse-Code Modulation) playback system.
/// SPI controller connected to the SD card connector
///
/// The speed of the clock output of the SPI controller can be controlled by the 'Slow Clock' bit.
/// When this bit is 0 the clock is 12.5MHz, when 1 the clock is about 390kHz.
/// The slow clock speed is to be used during the initialization phase of the SD card.
/// Some SD cards require a clock less than 400kHz during part of the initialization.
/// A transfer can be started by writing to `SPI_DATA`.
/// While the transfer is in progress the BUSY bit will be set.
/// After the transfer is done, the result can be read from the SPI_DATA register.
/// The chip select can be controlled by writing the `SELECT` bit.
/// Writing 1 will assert the chip-select (logic-0) and writing 0 will release the chip-select (logic-1).
/// VRAM, 0x00000 - 0x1F9BF
pub const VIDEO_RAM: *mut u8 = as *mut u8;
/// PSG registers, 0x1F9C0 - 0x1F9FF
pub const PSG_REGISTERS: *mut u8 = as *mut u8;
/// Palette, 0x1FA00 - 0x1FBFF
pub const PALETTE: *mut u8 = as *mut u8;
/// Sprite attributes, 0x1FC00 - 0x1FFFF
pub const SPRITE_ATTRIBUTES: *mut u8 = as *mut u8;