1#![no_std]
46#![feature(const_option)]
47#![allow(incomplete_features)]
48#![feature(generic_const_exprs)]
49#![feature(error_in_core)]
50#![feature(iter_advance_by)]
51#![feature(iter_next_chunk)]
52#![feature(cfg_version)]
53#![allow(clippy::bad_bit_mask)]
54extern crate alloc;
55extern crate static_assertions;
56
57#[cfg(feature = "c64")]
58pub mod c64;
59pub mod cbm_kernal;
60#[cfg(feature = "cia")]
61pub mod cia;
62#[cfg(feature = "cx16")]
63pub mod cx16;
64#[cfg(feature = "mega65")]
65pub mod mega65;
66#[cfg(feature = "petscii")]
67pub mod petscii;
68#[cfg(feature = "sid")]
69pub mod sid;
70#[cfg(feature = "vera")]
71pub mod vera;
72#[cfg(feature = "vic2")]
73pub mod vic2;
74
75#[macro_export]
82macro_rules! peek {
83 ($address:expr) => {{
84 core::ptr::read_volatile($address)
85 }};
86}
87
88#[macro_export]
95macro_rules! poke {
96 ($address:expr, $value:expr) => {{
97 core::ptr::write_volatile($address, $value)
98 }};
99}
100
101#[macro_export]
103macro_rules! add {
104 ($value1:expr, $value2:expr) => {{
105 $value1.wrapping_add($value2)
106 }};
107}
108
109#[macro_export]
111macro_rules! sub {
112 ($value1:expr, $value2:expr) => {{
113 $value1.wrapping_sub($value2)
114 }};
115}
116
117#[macro_export]
127macro_rules! highbyte {
128 ($word:expr) => {{
129 ((&$word as *const u16) as *const u8)
130 .offset(1)
131 .read_volatile()
132 }};
134}
135
136#[macro_export]
145macro_rules! lowbyte {
146 ($word:expr) => {{
147 ((&$word as *const u16) as *const u8)
148 .offset(0)
149 .read_volatile()
150 }};
152}
153
154pub fn repeat_element<T: Clone>(
159 it: impl Iterator<Item = T>,
160 cnt: usize,
161) -> impl Iterator<Item = T> {
162 it.flat_map(move |n| core::iter::repeat(n).take(cnt))
163}
164
165pub const fn make_sine(divide: u8, add: u8) -> [u8; SINETABLE.len()] {
178 let mut array = SINETABLE;
179 let mut i: usize = 0;
180 while i < array.len() {
181 array[i] = array[i] / divide + add;
182 i += 1;
183 }
184 array
185}
186
187pub const fn sine(index: u8) -> u8 {
189 SINETABLE[index as usize]
190}
191
192pub const SINETABLE: [u8; 256] = [
194 0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a, 0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52,
195 0x4f, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3f, 0x3c, 0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28,
196 0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x18, 0x16, 0x15, 0x13, 0x11, 0x10, 0x0f, 0x0d, 0x0c,
197 0x0b, 0x0a, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04, 0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
198 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0a,
199 0x0b, 0x0c, 0x0d, 0x0f, 0x10, 0x11, 0x13, 0x15, 0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24,
200 0x26, 0x28, 0x2b, 0x2d, 0x2f, 0x32, 0x34, 0x37, 0x39, 0x3c, 0x3f, 0x41, 0x44, 0x47, 0x4a, 0x4d,
201 0x4f, 0x52, 0x55, 0x58, 0x5b, 0x5e, 0x61, 0x64, 0x67, 0x6a, 0x6d, 0x70, 0x74, 0x77, 0x7a, 0x7d,
202 0x80, 0x83, 0x86, 0x89, 0x8c, 0x90, 0x93, 0x96, 0x99, 0x9c, 0x9f, 0xa2, 0xa5, 0xa8, 0xab, 0xae,
203 0xb1, 0xb3, 0xb6, 0xb9, 0xbc, 0xbf, 0xc1, 0xc4, 0xc7, 0xc9, 0xcc, 0xce, 0xd1, 0xd3, 0xd5, 0xd8,
204 0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xeb, 0xed, 0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