mos_hardware/
cx16.rs

1// copyright 2022 mikael lund aka wombat
2//
3// licensed under the apache license, version 2.0 (the "license");
4// you may not use this file except in compliance with the license.
5// you may obtain a copy of the license at
6//
7//     http://www.apache.org/licenses/license-2.0
8//
9// unless required by applicable law or agreed to in writing, software
10// distributed under the license is distributed on an "as is" basis,
11// without warranties or conditions of any kind, either express or implied.
12// see the license for the specific language governing permissions and
13// limitations under the license.
14//
15// Loosely based on C headers from cc65, here modififed from the original version.
16//
17//                                  cx16.h
18//
19//                      CX16 system-specific definitions
20//                             For prerelease 39
21//
22//
23// This software is provided "as-is", without any expressed or implied
24// warranty.  In no event will the authors be held liable for any damages
25// arising from the use of this software.
26//
27// Permission is granted to anyone to use this software for any purpose,
28// including commercial applications, and to alter it and redistribute it
29// freely, subject to the following restrictions:
30//
31// 1. The origin of this software must not be misrepresented; you must not
32//    claim that you wrote the original software. If you use this software
33//    in a product, an acknowledgment in the product documentation would be
34//    appreciated, but is not required.
35// 2. Altered source versions must be plainly marked as such, and must not
36//    be misrepresented as being the original software.
37// 3. This notice may not be removed or altered from any source
38//    distribution.
39
40//! Commander X16 support.
41//!
42//! The Commander X16 (also known as the X16) is a modern hardware platform being development.
43//! It is built from modern, mostly off-the-shelf parts, with KERNAL
44//! compatibility with the Commodore family of computers. It was initiated by David "the 8 Bit Guy" Murray,
45//! who wanted an accessible and affordable platform with late-80s sound and graphics.
46
47use crate::vera::VersatileEmbeddedRetroAdapter;
48
49pub const CH_COLOR_SWAP: u8 = 1;
50pub const CH_UNDERLINE: u8 = 4;
51pub const CH_WHITE: u8 = 5;
52pub const CH_BOLD: u8 = 6;
53pub const CH_BACKSPACE: u8 = 8;
54pub const CH_ITALIC: u8 = 11;
55pub const CH_OUTLINE: u8 = 12;
56pub const CH_FONT_ISO: u8 = 15;
57pub const CH_RED: u8 = 28;
58pub const CH_GREEN: u8 = 30;
59pub const CH_BLUE: u8 = 31;
60pub const CH_ORANGE: u8 = 129;
61pub const CH_FONT_PET: u8 = 143;
62pub const CH_BLACK: u8 = 144;
63pub const CH_ATTR_CLEAR: u8 = 146;
64pub const CH_BROWN: u8 = 149;
65pub const CH_PINK: u8 = 150;
66pub const CH_LIGHTRED: u8 = 150;
67pub const CH_GRAY1: u8 = 151;
68pub const CH_GRAY2: u8 = 152;
69pub const CH_LIGHTGREEN: u8 = 153;
70pub const CH_LIGHTBLUE: u8 = 154;
71pub const CH_GRAY3: u8 = 155;
72pub const CH_PURPLE: u8 = 156;
73pub const CH_YELLOW: u8 = 158;
74pub const CH_CYAN: u8 = 159;
75pub const CH_SHIFT_SPACE: u8 = 160;
76pub const CH_SHIFT_TAB: u8 = 24;
77pub const CH_HELP: u8 = 132;
78pub const CH_F1: u8 = 133;
79pub const CH_F2: u8 = 137;
80pub const CH_F3: u8 = 134;
81pub const CH_F4: u8 = 138;
82pub const CH_F5: u8 = 135;
83pub const CH_F6: u8 = 139;
84pub const CH_F7: u8 = 136;
85pub const CH_F8: u8 = 140;
86pub const CH_F9: u8 = 16;
87pub const CH_F10: u8 = 21;
88pub const CH_F11: u8 = 22;
89pub const CH_F12: u8 = 23;
90
91pub const COLOR_BLACK: u8 = 0;
92pub const COLOR_WHITE: u8 = 1;
93pub const COLOR_RED: u8 = 2;
94pub const COLOR_CYAN: u8 = 3;
95pub const COLOR_PURPLE: u8 = 4;
96pub const COLOR_GREEN: u8 = 5;
97pub const COLOR_BLUE: u8 = 6;
98pub const COLOR_YELLOW: u8 = 7;
99pub const COLOR_ORANGE: u8 = 8;
100pub const COLOR_BROWN: u8 = 9;
101pub const COLOR_PINK: u8 = 10;
102pub const COLOR_LIGHTRED: u8 = 10;
103pub const COLOR_GRAY1: u8 = 11;
104pub const COLOR_GRAY2: u8 = 12;
105pub const COLOR_LIGHTGREEN: u8 = 13;
106pub const COLOR_LIGHTBLUE: u8 = 14;
107pub const COLOR_GRAY3: u8 = 15;
108
109pub const JOY_BTN_1_MASK: u8 = 128;
110pub const JOY_BTN_2_MASK: u8 = 64;
111pub const JOY_BTN_3_MASK: u8 = 32;
112pub const JOY_BTN_4_MASK: u8 = 16;
113pub const JOY_UP_MASK: u8 = 8;
114pub const JOY_DOWN_MASK: u8 = 4;
115pub const JOY_LEFT_MASK: u8 = 2;
116pub const JOY_RIGHT_MASK: u8 = 1;
117
118pub const JOY_BTN_A_MASK: u8 = 128;
119pub const JOY_BTN_B_MASK: u8 = 64;
120pub const JOY_SELECT_MASK: u8 = 32;
121pub const JOY_START_MASK: u8 = 16;
122pub const JOY_FIRE2_MASK: u8 = 64;
123
124pub const MOUSE_BTN_MIDDLE: u8 = 2;
125
126#[repr(C)]
127#[derive(Debug, Copy, Clone)]
128pub struct VersatileInterfaceAdapter65C22 {
129    /// Port B `prb`
130    pub port_b: u8,
131    /// Port A `pra`
132    pub port_a: u8,
133    /// Data direction B `ddrb`
134    pub data_direction_b: u8,
135    /// Data direction A `ddra`
136    pub data_direction_a: u8,
137    /// Timer 1 `t1`
138    pub timer1: u16,
139    /// Timer 1 latch `t1l`
140    pub timer1_latch: u16,
141    /// Timer 2 `t2`
142    pub timer2: u16,
143    /// Shift `sr`
144    pub shift: u8,
145    /// Auxiliary control `acr`
146    pub auxiliary_control: u8,
147    /// Peripheral control `pcr`
148    pub peripheral_control: u8,
149    /// Interrupt flag `ifr`
150    pub irq_flag: u8,
151    /// Interrupt enable `ier`
152    pub irq_enable: u8,
153    /// Port A w/o handshake `pra2`
154    pub port_a_no_handshape: u8,
155}
156
157#[repr(C)]
158#[derive(Debug, Copy, Clone)]
159/// Access to emulator specific features
160pub struct Emulator {
161    /// Boolean: debugging enabled
162    pub debug: u8,
163    /// Boolean: displaying VERA activity
164    pub vera_action: u8,
165    /// Boolean: displaying typed keys
166    pub keyboard: u8,
167    /// How to send Kernal output to host
168    pub echo: u8,
169    /// Boolean: save machine state on exit
170    pub save_on_exit: u8,
171    /// How GIF movie is being recorded
172    pub gif_method: u8,
173    /// Unused
174    pub unused1: [u8; 2],
175    /// Running total of CPU cycles (8 MHz.)
176    pub cycle_count: u32,
177    /// Unused
178    pub unused2: [u8; 1],
179    /// Keyboard layout number
180    pub keymap: u8,
181    /// "16" if running on x16emu
182    pub detect: [i8; 2],
183}
184
185// Memory layout
186pub const RAM_BANK: *mut u8 = (0x00) as *mut u8;
187pub const ROM_BANK: *mut u8 = (0x01) as *mut u8;
188
189/// Pointer to first Versatile Interface Adapter (VIA1)
190pub const VIA1: *const VersatileInterfaceAdapter65C22 =
191    (0x9f00) as *const VersatileInterfaceAdapter65C22;
192
193/// Pointer to second Versatile Interface Adapter (VIA2)
194pub const VIA2: *const VersatileInterfaceAdapter65C22 =
195    (0x9f10) as *const VersatileInterfaceAdapter65C22;
196
197/// Pointer to the Versatile Embedded Retro Adapter chip
198pub const VERA: *const VersatileEmbeddedRetroAdapter =
199    (0x9f20) as *const VersatileEmbeddedRetroAdapter;
200
201/// Pointer to Yamaha 2151 sound chip
202pub const YM2151: *mut u8 = (0x9f40) as *mut u8;
203
204/// Access to emulator specific features
205pub const EMULATOR: *const Emulator = (0x9fb0) as *const Emulator;
206
207pub const BANK_RAM: *mut u8 = (0xa000) as *mut u8;