use crate::sid::*;
use crate::vic2::*;
use crate::{peek, petscii, poke};
pub mod iomap;
pub mod libc;
pub mod math;
mod memory;
pub mod random;
pub use memory::*;
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum DefaultPalette {
Black = 0,
White = 1,
Red = 2,
Cyan = 3,
Purple = 4,
Green = 5,
Blue = 6,
Yellow = 7,
Orange = 8,
Brown = 9,
LightRed = 10,
DarkGrey = 11,
MediumGrey = 12,
LightGreen = 13,
LightBlue = 14,
LightGrey = 15,
GuruMeditation = 16,
Rambutan = 17,
Carrot = 18,
LemonTart = 19,
Pandan = 20,
SeasickGreen = 21,
SoylentGreen = 22,
SlimerGreen = 23,
TheOtherCyan = 24,
SeaSky = 25,
SmurfBlue = 26,
ScreenOfDeath = 27,
PlumSauce = 28,
SourGrape = 29,
Bubblegum = 30,
HotTamales = 31,
}
pub const DEFAULT_SCREEN: *mut u8 = (0x0800) as *mut u8;
pub const DEFAULT_UPPERCASE_FONT: *mut u8 = (0x1000) as *mut u8;
pub const DEFAULT_MIXEDCASE_FONT: *mut u8 = (0x1800) as *mut u8;
pub const VICII: *const MOSVideoInterfaceControllerII =
(0xd000) as *const MOSVideoInterfaceControllerII;
pub const SID0: *const MOSSoundInterfaceDevice = (0xd400) as *const MOSSoundInterfaceDevice;
pub const SID1: *const MOSSoundInterfaceDevice = (0xd420) as *const MOSSoundInterfaceDevice;
pub const SID2: *const MOSSoundInterfaceDevice = (0xd440) as *const MOSSoundInterfaceDevice;
pub const SID3: *const MOSSoundInterfaceDevice = (0xd460) as *const MOSSoundInterfaceDevice;
pub const COLOR_RAM: *mut u8 = (0xd800) as *mut u8;
pub const MATH_STATUS: *const volatile_register::RO<math::StatusFlags> =
(0xd70f) as *const volatile_register::RO<math::StatusFlags>;
pub const MATH_ACCELERATOR: *const math::MathAccelerator = (0xd768) as *const math::MathAccelerator;
pub enum VicBank {
Region0000 = 0x11, Region4000 = 0x10, Region8000 = 0x01, RegionC000 = 0x00, }
pub const fn vic2() -> &'static MOSVideoInterfaceControllerII {
unsafe { &*VICII }
}
pub const fn sid0() -> &'static MOSSoundInterfaceDevice {
unsafe { &*SID0 }
}
pub const fn sid1() -> &'static MOSSoundInterfaceDevice {
unsafe { &*SID1 }
}
pub const fn sid2() -> &'static MOSSoundInterfaceDevice {
unsafe { &*SID2 }
}
pub const fn sid3() -> &'static MOSSoundInterfaceDevice {
unsafe { &*SID3 }
}
pub const fn math_accelerator() -> &'static math::MathAccelerator {
unsafe { &*MATH_ACCELERATOR }
}
pub fn speed_mode1() {
unsafe {
let mut val: u8 = peek!(0xd031 as *mut u8) & 0b1011_1111; poke!(0xd031 as *mut u8, val);
val = peek!(0xd054 as *mut u8) & 0b1011_1111; poke!(0xd054 as *mut u8, val);
}
}
pub fn speed_mode3() {
unsafe {
let mut val: u8 = peek!(0xd031 as *mut u8) | 0b0100_0000; poke!(0xd031 as *mut u8, val);
val = peek!(0xd054 as *mut u8) & 0b1011_1111; poke!(0xd054 as *mut u8, val);
}
}
pub fn speed_mode40() {
unsafe {
let mut val: u8 = peek!(0xd031 as *mut u8) | 0b0100_0000; poke!(0xd031 as *mut u8, val);
val = peek!(0xd054 as *mut u8) | 0b0100_0000; poke!(0xd054 as *mut u8, val);
}
}
#[derive(Default)]
pub struct Resolution<T> {
pub width: T,
pub height: T,
}
pub fn get_screen_size() -> Resolution<u8> {
let mut resolution = Resolution::default();
unsafe {
libc::getscreensize(&mut resolution.width, &mut resolution.height);
}
resolution
}
pub fn conio_init() {
unsafe {
libc::conioinit();
}
}
pub fn set_lower_case() {
unsafe {
libc::setlowercase();
}
}
pub fn set_upper_case() {
unsafe {
libc::setuppercase();
}
}
pub fn clear_screen() {
unsafe {
libc::clrscr();
}
}
pub fn go_home() {
unsafe {
libc::gohome();
}
}
pub fn goto_xy(x: u8, y: u8) {
unsafe {
libc::gotoxy(x, y);
}
}
pub fn cputs_xy(x: u8, y: u8, screen_codes: &[u8]) {
assert_eq!(*screen_codes.last().unwrap(), 0u8);
unsafe {
libc::cputsxy(x, y, screen_codes.as_ptr());
}
}
pub fn cputs(screen_codes: &[u8]) {
assert_eq!(*screen_codes.last().unwrap(), 0u8);
unsafe {
libc::cputs(screen_codes.as_ptr());
}
}
pub fn flush_keyboard_buffer() {
unsafe {
libc::flushkeybuf();
}
}
pub fn cgetc() -> petscii::Petscii {
unsafe { libc::cgetc() }.into()
}
pub fn set_border_color(color: u8) {
unsafe {
libc::bordercolor(color);
}
}
pub fn set_background_color(color: u8) {
unsafe {
libc::bgcolor(color);
}
}
pub fn set_text_color(color: u8) {
unsafe {
libc::textcolor(color);
}
}
pub fn get_real_time_clock() -> libc::m65_tm {
let mut rtc = libc::m65_tm::default();
unsafe {
libc::getrtc(&mut rtc);
}
rtc
}
pub fn set_extended_attributes() {
unsafe {
libc::setextendedattrib(1);
}
}
pub fn unset_extended_attributes() {
unsafe {
libc::setextendedattrib(0);
}
}
pub fn set_charset_address(address: u16) {
unsafe {
libc::setcharsetaddr(address as i32);
}
}