diff --git a/src/bios.rs b/src/bios.rs index ed6caf9..4f9b87d 100644 --- a/src/bios.rs +++ b/src/bios.rs @@ -2,4 +2,4 @@ use rust_embed::RustEmbed; #[derive(RustEmbed)] #[folder = "bios"] -pub(crate) struct Bios; \ No newline at end of file +pub(crate) struct Bios; diff --git a/src/data_input_stream.rs b/src/data_input_stream.rs index e576a87..7aeb420 100644 --- a/src/data_input_stream.rs +++ b/src/data_input_stream.rs @@ -1,5 +1,5 @@ -use std::{fs, io}; use std::path::Path; +use std::{fs, io}; use crate::int; @@ -12,15 +12,8 @@ pub(crate) struct DataInputStream { impl DataInputStream { pub(crate) fn new(file: &Path) -> io::Result { match fs::read(file) { - Ok(bytes) => { - Ok(DataInputStream { - bytes, - pos: 0, - }) - } - Err(e) => { - Err(e) - } + Ok(bytes) => Ok(DataInputStream { bytes, pos: 0 }), + Err(e) => Err(e), } } @@ -30,8 +23,7 @@ impl DataInputStream { b as int } - pub fn len(&self) -> usize { self.bytes.len() } -} \ No newline at end of file +} diff --git a/src/gui.rs b/src/gui.rs index 6cdfb98..4d911c1 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -2,11 +2,11 @@ use std::sync::mpsc::{Receiver, Sender}; use log::error; use speedy2d::dimen::{UVec2, Vec2}; -use speedy2d::Graphics2D; use speedy2d::image::ImageDataType::RGB; use speedy2d::image::ImageHandle; use speedy2d::image::ImageSmoothingMode::NearestNeighbor; use speedy2d::window::{KeyScancode, ModifiersState, VirtualKeyCode, WindowHandler, WindowHelper}; +use speedy2d::Graphics2D; use crate::hardware::keyboard::vkey::map_virtual_key_code; use crate::hardware::screen::{DEFAULT_PIXEL_SIZE, HEIGHT, WIDTH}; @@ -21,11 +21,14 @@ pub(crate) struct Gui { } impl Gui { - pub(crate) fn new(user_input_sender: Sender, image_data_receiver: Receiver>) -> Self { + pub(crate) fn new( + user_input_sender: Sender, + image_data_receiver: Receiver>, + ) -> Self { Gui { image: None, user_input_sender, - image_data_receiver + image_data_receiver, } } } @@ -37,12 +40,19 @@ impl WindowHandler for Gui { let image = graphics.create_image_from_raw_pixels( RGB, NearestNeighbor, - UVec2::new((DEFAULT_PIXEL_SIZE * WIDTH) as u32, (DEFAULT_PIXEL_SIZE * HEIGHT) as u32), - raw); + UVec2::new( + (DEFAULT_PIXEL_SIZE * WIDTH) as u32, + (DEFAULT_PIXEL_SIZE * HEIGHT) as u32, + ), + raw, + ); if image.is_ok() { self.image = Some(image.unwrap()); } else { - error!("Error creating image from raw pixels {:?}", image.err().unwrap()); + error!( + "Error creating image from raw pixels {:?}", + image.err().unwrap() + ); } } @@ -53,11 +63,22 @@ impl WindowHandler for Gui { helper.request_redraw(); } - fn on_key_down(&mut self, _: &mut WindowHelper<()>, virtual_key_code: Option, scancode: KeyScancode) { + fn on_key_down( + &mut self, + _: &mut WindowHelper<()>, + virtual_key_code: Option, + scancode: KeyScancode, + ) { match virtual_key_code { - Some(VirtualKeyCode::F2) => {self.user_input_sender.send(OpenK7File).ok();} - Some(VirtualKeyCode::F7) => {self.user_input_sender.send(SoftReset).ok();} - Some(VirtualKeyCode::F8) => {self.user_input_sender.send(HardReset).ok();} + Some(VirtualKeyCode::F2) => { + self.user_input_sender.send(OpenK7File).ok(); + } + Some(VirtualKeyCode::F7) => { + self.user_input_sender.send(SoftReset).ok(); + } + Some(VirtualKeyCode::F8) => { + self.user_input_sender.send(HardReset).ok(); + } _ => { if let Some(vk) = map_virtual_key_code(virtual_key_code, scancode) { self.user_input_sender.send(UserInput::KeyDown(vk)).ok(); @@ -66,13 +87,20 @@ impl WindowHandler for Gui { } } - fn on_key_up(&mut self, _: &mut WindowHelper<()>, virtual_key_code: Option, scancode: KeyScancode) { + fn on_key_up( + &mut self, + _: &mut WindowHelper<()>, + virtual_key_code: Option, + scancode: KeyScancode, + ) { if let Some(vk) = map_virtual_key_code(virtual_key_code, scancode) { self.user_input_sender.send(UserInput::KeyUp(vk)).ok(); } } fn on_keyboard_modifiers_changed(&mut self, _: &mut WindowHelper<()>, state: ModifiersState) { - self.user_input_sender.send(UserInput::KeyboardModifierChanged(state)).ok(); + self.user_input_sender + .send(UserInput::KeyboardModifierChanged(state)) + .ok(); } -} \ No newline at end of file +} diff --git a/src/hardware/M6809.rs b/src/hardware/M6809.rs index b4112e1..8fa904e 100644 --- a/src/hardware/M6809.rs +++ b/src/hardware/M6809.rs @@ -137,40 +137,47 @@ impl M6809 { // let m2; let mut M; match m { - 0x80 => { //i_d_P1_X + 0x80 => { + //i_d_P1_X M = self.X; self.X = (self.X + 1) & 0xFFFF; self.cl += 2; return M; } - 0x81 => { //i_d_P2_X + 0x81 => { + //i_d_P2_X M = self.X; self.X = (self.X + 2) & 0xFFFF; self.cl += 3; return M; } - 0x82 => { //i_d_M1_X + 0x82 => { + //i_d_M1_X self.X = (self.X - 1) & 0xFFFF; M = self.X; self.cl += 2; return M; } - 0x83 => { //i_d_M2_X + 0x83 => { + //i_d_M2_X self.X = (self.X - 2) & 0xFFFF; M = self.X; self.cl += 3; return M; } - 0x84 => { //i_d_X + 0x84 => { + //i_d_X M = self.X; return M; } - 0x85 => { //i_d_B_X + 0x85 => { + //i_d_B_X M = (self.X + signedChar(self.B)) & 0xFFFF; self.cl += 1; return M; } - 0x86 => { //i_d_A_X; + 0x86 => { + //i_d_A_X; M = (self.X + signedChar(self.A)) & 0xFFFF; self.cl += 1; return M; @@ -178,14 +185,16 @@ impl M6809 { 0x87 => { return 0; //i_undoc; /* empty */ } - 0x88 => { //i_d_8_X; + 0x88 => { + //i_d_8_X; self.m2 = mem.read(self.PC); self.PC += 1; M = (self.X + signedChar(self.m2)) & 0xFFFF; self.cl += 1; return M; } - 0x89 => { //i_d_16_X; + 0x89 => { + //i_d_16_X; self.m2 = mem.read_16(self.PC); self.PC += 2; M = (self.X + signed16bits(self.m2)) & 0xFFFF; @@ -195,25 +204,22 @@ impl M6809 { 0x8A => { return 0; //i_undoc; /* empty */ } - 0x8B => { //i_d_D_X; + 0x8B => { + //i_d_D_X; M = (self.X + signed16bits((self.A << 8) | self.B)) & 0xFFFF; self.cl += 4; return M; } - 0x8C | - 0xAC | - 0xCC | - 0xEC => { //i_d_PC8; + 0x8C | 0xAC | 0xCC | 0xEC => { + //i_d_PC8; m = mem.read(self.PC); self.PC = (self.PC + 1) & 0xFFFF; M = (self.PC + signedChar(m)) & 0xFFFF; self.cl += 1; return M; } - 0x8D | - 0xAD | - 0xCD | - 0xED => { //i_d_PC16; + 0x8D | 0xAD | 0xCD | 0xED => { + //i_d_PC16; M = mem.read_16(self.PC); self.PC = (self.PC + 2) & 0xFFFF; M = (self.PC + signed16bits(M)) & 0xFFFF; @@ -229,7 +235,8 @@ impl M6809 { 0x90 => { return 0; //i_undoc; /* empty */ } - 0x91 => { //i_i_P2_X; + 0x91 => { + //i_i_P2_X; M = mem.read_16(self.X); self.X = (self.X + 2) & 0xFFFF; self.cl += 6; @@ -238,24 +245,28 @@ impl M6809 { 0x92 => { return 0; //i_undoc; /* empty */ } - 0x93 => { //i_i_M2_X; + 0x93 => { + //i_i_M2_X; self.X = (self.X - 2) & 0xFFFF; M = mem.read_16(self.X); self.cl += 6; return M; } - 0x94 => { //i_i_0_X; + 0x94 => { + //i_i_0_X; M = mem.read_16(self.X); self.cl += 3; return M; } - 0x95 => { //i_i_B_X; + 0x95 => { + //i_i_B_X; M = (self.X + signedChar(self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; return M; } - 0x96 => { //i_i_A_X; + 0x96 => { + //i_i_A_X; M = (self.X + signedChar(self.A)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; @@ -264,7 +275,8 @@ impl M6809 { 0x97 => { return 0; //i_undoc; /* empty */ } - 0x98 => { //i_i_8_X; + 0x98 => { + //i_i_8_X; self.m2 = mem.read(self.PC); self.PC = (self.PC + 1) & 0xFFFF; M = (self.X + signedChar(self.m2)) & 0xFFFF; @@ -272,7 +284,8 @@ impl M6809 { self.cl += 4; return M; } - 0x99 => { //i_i_16_X; + 0x99 => { + //i_i_16_X; self.m2 = mem.read_16(self.PC); self.PC = (self.PC + 2) & 0xFFFF; M = (self.X + signed16bits(self.m2)) & 0xFFFF; @@ -283,16 +296,15 @@ impl M6809 { 0x9A => { return 0; //i_undoc; /* empty */ } - 0x9B => { //i_i_D_X; + 0x9B => { + //i_i_D_X; M = (self.X + signed16bits((self.A << 8) | self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 7; return M; } - 0x9C | - 0xBC | - 0xDC | - 0xFC => { //i_i_PC8; + 0x9C | 0xBC | 0xDC | 0xFC => { + //i_i_PC8; self.m2 = mem.read(self.PC); self.PC = (self.PC + 1) & 0xFFFF; M = (self.PC + signedChar(self.m2)) & 0xFFFF; @@ -300,10 +312,8 @@ impl M6809 { self.cl += 4; return M; } - 0x9D | - 0xBD | - 0xDD | - 0xFD => { //i_i_PC16; + 0x9D | 0xBD | 0xDD | 0xFD => { + //i_i_PC16; self.m2 = mem.read_16(self.PC); self.PC = (self.PC + 2) & 0xFFFF; M = (self.PC + signed16bits(self.m2)) & 0xFFFF; @@ -314,10 +324,8 @@ impl M6809 { 0x9E => { return 0; //i_undoc; /* empty */ } - 0x9F | - 0xBF | - 0xDF | - 0xFF => { //i_i_e16; + 0x9F | 0xBF | 0xDF | 0xFF => { + //i_i_e16; self.m2 = mem.read_16(self.PC); self.PC = (self.PC + 2) & 0xFFFF; M = mem.read_16(self.m2); @@ -325,40 +333,47 @@ impl M6809 { return M; // Y } - 0xA0 => { //i_d_P1_Y; + 0xA0 => { + //i_d_P1_Y; M = self.Y; self.Y = (self.Y + 1) & 0xFFFF; self.cl += 2; return M; } - 0xA1 => { //i_d_P2_Y; + 0xA1 => { + //i_d_P2_Y; M = self.Y; self.Y = (self.Y + 2) & 0xFFFF; self.cl += 3; return M; } - 0xA2 => { //i_d_M1_Y; + 0xA2 => { + //i_d_M1_Y; self.Y = (self.Y - 1) & 0xFFFF; M = self.Y; self.cl += 2; return M; } - 0xA3 => { //i_d_M2_Y; + 0xA3 => { + //i_d_M2_Y; self.Y = (self.Y - 2) & 0xFFFF; M = self.Y; self.cl += 3; return M; } - 0xA4 => { //i_d_Y; + 0xA4 => { + //i_d_Y; M = self.Y; return M; } - 0xA5 => { //i_d_B_Y; + 0xA5 => { + //i_d_B_Y; M = (self.Y + signedChar(self.B)) & 0xFFFF; self.cl += 1; return M; } - 0xA6 => { //i_d_A_Y; + 0xA6 => { + //i_d_A_Y; M = (self.Y + signedChar(self.A)) & 0xFFFF; self.cl += 1; return M; @@ -366,14 +381,16 @@ impl M6809 { 0xA7 => { return 0; //i_undoc; /* empty */ } - 0xA8 => { //i_d_8_Y; + 0xA8 => { + //i_d_8_Y; self.m2 = mem.read(self.PC); self.PC += 1; M = (self.Y + signedChar(self.m2)) & 0xFFFF; self.cl += 1; return M; } - 0xA9 => { //i_d_16_Y; + 0xA9 => { + //i_d_16_Y; self.m2 = mem.read_16(self.PC); self.PC += 2; M = (self.Y + signed16bits(self.m2)) & 0xFFFF; @@ -383,7 +400,8 @@ impl M6809 { 0xAA => { return 0; //i_undoc; /* empty */ } - 0xAB => { //i_d_D_Y; + 0xAB => { + //i_d_D_Y; M = (self.Y + signed16bits((self.A << 8) | self.B)) & 0xFFFF; self.cl += 4; return M; @@ -397,7 +415,8 @@ impl M6809 { 0xB0 => { return 0; //i_undoc; /* empty */ } - 0xB1 => { //i_i_P2_Y; + 0xB1 => { + //i_i_P2_Y; M = mem.read_16(self.Y); self.Y = (self.Y + 2) & 0xFFFF; self.cl += 6; @@ -406,24 +425,28 @@ impl M6809 { 0xB2 => { return 0; //i_undoc; /* empty */ } - 0xB3 => { //i_i_M2_Y; + 0xB3 => { + //i_i_M2_Y; self.Y = (self.Y - 2) & 0xFFFF; M = mem.read_16(self.Y); self.cl += 6; return M; } - 0xB4 => { //i_i_0_Y; + 0xB4 => { + //i_i_0_Y; M = mem.read_16(self.Y); self.cl += 3; return M; } - 0xB5 => { //i_i_B_Y; + 0xB5 => { + //i_i_B_Y; M = (self.Y + signedChar(self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; return M; } - 0xB6 => { //i_i_A_Y; + 0xB6 => { + //i_i_A_Y; M = (self.Y + signedChar(self.A)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; @@ -432,7 +455,8 @@ impl M6809 { 0xB7 => { return 0; //i_undoc; /* empty */ } - 0xB8 => { //i_i_8_Y; + 0xB8 => { + //i_i_8_Y; self.m2 = mem.read(self.PC); self.PC = (self.PC + 1) & 0xFFFF; M = (self.Y + signedChar(self.m2)) & 0xFFFF; @@ -440,7 +464,8 @@ impl M6809 { self.cl += 4; return M; } - 0xB9 => { //i_i_16_Y; + 0xB9 => { + //i_i_16_Y; self.m2 = mem.read_16(self.PC); self.PC = (self.PC + 2) & 0xFFFF; M = (self.Y + signed16bits(self.m2)) & 0xFFFF; @@ -451,7 +476,8 @@ impl M6809 { 0xBA => { return 0; //i_undoc; /* empty */ } - 0xBB => { //i_i_D_Y; + 0xBB => { + //i_i_D_Y; M = (self.Y + signed16bits((self.A << 8) | self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 7; @@ -462,40 +488,47 @@ impl M6809 { // U } - 0xC0 => { //i_d_P1_U; + 0xC0 => { + //i_d_P1_U; M = self.U; self.U = (self.U + 1) & 0xFFFF; self.cl += 2; return M; } - 0xC1 => { //i_d_P2_U; + 0xC1 => { + //i_d_P2_U; M = self.U; self.U = (self.U + 2) & 0xFFFF; self.cl += 3; return M; } - 0xC2 => { //i_d_M1_U; + 0xC2 => { + //i_d_M1_U; self.U = (self.U - 1) & 0xFFFF; M = self.U; self.cl += 2; return M; } - 0xC3 => { //i_d_M2_U; + 0xC3 => { + //i_d_M2_U; self.U = (self.U - 2) & 0xFFFF; M = self.U; self.cl += 3; return M; } - 0xC4 => { //i_d_U; + 0xC4 => { + //i_d_U; M = self.U; return M; } - 0xC5 => { //i_d_B_U; + 0xC5 => { + //i_d_B_U; M = (self.U + signedChar(self.B)) & 0xFFFF; self.cl += 1; return M; } - 0xC6 => { //i_d_A_U; + 0xC6 => { + //i_d_A_U; M = (self.U + signedChar(self.A)) & 0xFFFF; self.cl += 1; return M; @@ -503,14 +536,16 @@ impl M6809 { 0xC7 => { return 0; //i_undoc; /* empty */ } - 0xC8 => { //i_d_8_U; + 0xC8 => { + //i_d_8_U; self.m2 = mem.read(self.PC); self.PC += 1; M = (self.U + signedChar(self.m2)) & 0xFFFF; self.cl += 1; return M; } - 0xC9 => { //i_d_16_U; + 0xC9 => { + //i_d_16_U; self.m2 = mem.read_16(self.PC); self.PC += 2; M = (self.U + signed16bits(self.m2)) & 0xFFFF; @@ -520,7 +555,8 @@ impl M6809 { 0xCA => { return 0; //i_undoc; /* empty */ } - 0xCB => { //i_d_D_U; + 0xCB => { + //i_d_D_U; M = (self.U + signed16bits((self.A << 8) | self.B)) & 0xFFFF; self.cl += 4; return M; @@ -534,7 +570,8 @@ impl M6809 { 0xD0 => { return 0; //i_undoc; /* empty */ } - 0xD1 => { //i_i_P2_U; + 0xD1 => { + //i_i_P2_U; M = mem.read_16(self.U); self.U = (self.U + 2) & 0xFFFF; self.cl += 6; @@ -543,24 +580,28 @@ impl M6809 { 0xD2 => { return 0; //i_undoc; /* empty */ } - 0xD3 => { //i_i_M2_U; + 0xD3 => { + //i_i_M2_U; self.U = (self.U - 2) & 0xFFFF; M = mem.read_16(self.U); self.cl += 6; return M; } - 0xD4 => { //i_i_0_U; + 0xD4 => { + //i_i_0_U; M = mem.read_16(self.U); self.cl += 3; return M; } - 0xD5 => { //i_i_B_U; + 0xD5 => { + //i_i_B_U; M = (self.U + signedChar(self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; return M; } - 0xD6 => { //i_i_A_U; + 0xD6 => { + //i_i_A_U; M = (self.U + signedChar(self.A)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; @@ -569,7 +610,8 @@ impl M6809 { 0xD7 => { return 0; //i_undoc; /* empty */ } - 0xD8 => { //i_i_8_U; + 0xD8 => { + //i_i_8_U; self.m2 = mem.read(self.PC); self.PC = (self.PC + 1) & 0xFFFF; M = (self.U + signedChar(self.m2)) & 0xFFFF; @@ -577,7 +619,8 @@ impl M6809 { self.cl += 4; return M; } - 0xD9 => { //i_i_16_U; + 0xD9 => { + //i_i_16_U; self.m2 = mem.read_16(self.PC); self.PC = (self.PC + 2) & 0xFFFF; M = (self.U + signed16bits(self.m2)) & 0xFFFF; @@ -588,7 +631,8 @@ impl M6809 { 0xDA => { return 0; //i_undoc; /* empty */ } - 0xDB => { //i_i_D_U; + 0xDB => { + //i_i_D_U; M = (self.U + signed16bits((self.A << 8) | self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 7; @@ -599,40 +643,47 @@ impl M6809 { // S } - 0xE0 => { //i_d_P1_S; + 0xE0 => { + //i_d_P1_S; M = self.S; self.S = (self.S + 1) & 0xFFFF; self.cl += 2; return M; } - 0xE1 => { //i_d_P2_S; + 0xE1 => { + //i_d_P2_S; M = self.S; self.S = (self.S + 2) & 0xFFFF; self.cl += 3; return M; } - 0xE2 => { //i_d_M1_S; + 0xE2 => { + //i_d_M1_S; self.S = (self.S - 1) & 0xFFFF; M = self.S; self.cl += 2; return M; } - 0xE3 => { //i_d_M2_S; + 0xE3 => { + //i_d_M2_S; self.S = (self.S - 2) & 0xFFFF; M = self.S; self.cl += 3; return M; } - 0xE4 => { //i_d_S; + 0xE4 => { + //i_d_S; M = self.S; return M; } - 0xE5 => { //i_d_B_S; + 0xE5 => { + //i_d_B_S; M = (self.S + signedChar(self.B)) & 0xFFFF; self.cl += 1; return M; } - 0xE6 => { //i_d_A_S; + 0xE6 => { + //i_d_A_S; M = (self.S + signedChar(self.A)) & 0xFFFF; self.cl += 1; return M; @@ -640,14 +691,16 @@ impl M6809 { 0xE7 => { return 0; //i_undoc; /* empty */ } - 0xE8 => { //i_d_8_S; + 0xE8 => { + //i_d_8_S; self.m2 = mem.read(self.PC); self.PC += 1; M = (self.S + signedChar(self.m2)) & 0xFFFF; self.cl += 1; return M; } - 0xE9 => { //i_d_16_S; + 0xE9 => { + //i_d_16_S; self.m2 = mem.read_16(self.PC); self.PC += 2; M = (self.S + signed16bits(self.m2)) & 0xFFFF; @@ -657,7 +710,8 @@ impl M6809 { 0xEA => { return 0; //i_undoc; /* empty */ } - 0xEB => { //i_d_D_S; + 0xEB => { + //i_d_D_S; M = (self.S + signed16bits((self.A << 8) | self.B)) & 0xFFFF; self.cl += 4; return M; @@ -671,7 +725,8 @@ impl M6809 { 0xF0 => { return 0; //i_undoc; /* empty */ } - 0xF1 => { //i_i_P2_S; + 0xF1 => { + //i_i_P2_S; M = mem.read_16(self.S); self.S = (self.S + 2) & 0xFFFF; self.cl += 6; @@ -680,24 +735,28 @@ impl M6809 { 0xF2 => { return 0; //i_undoc; /* empty */ } - 0xF3 => { //i_i_M2_S; + 0xF3 => { + //i_i_M2_S; self.S = (self.S - 2) & 0xFFFF; M = mem.read_16(self.S); self.cl += 6; return M; } - 0xF4 => { //i_i_0_S; + 0xF4 => { + //i_i_0_S; M = mem.read_16(self.S); self.cl += 3; return M; } - 0xF5 => { //i_i_B_S; + 0xF5 => { + //i_i_B_S; M = (self.S + signedChar(self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; return M; } - 0xF6 => { //i_i_A_S; + 0xF6 => { + //i_i_A_S; M = (self.S + signedChar(self.A)) & 0xFFFF; M = mem.read_16(M); self.cl += 4; @@ -706,7 +765,8 @@ impl M6809 { 0xF7 => { return 0; //i_undoc; /* empty */ } - 0xF8 => { //i_i_8_S; + 0xF8 => { + //i_i_8_S; self.m2 = mem.read(self.PC); self.PC = (self.PC + 1) & 0xFFFF; M = (self.S + signedChar(self.m2)) & 0xFFFF; @@ -714,7 +774,8 @@ impl M6809 { self.cl += 4; return M; } - 0xF9 => { //i_i_16_S; + 0xF9 => { + //i_i_16_S; self.m2 = mem.read_16(self.PC); self.PC = (self.PC + 2) & 0xFFFF; M = (self.S + signed16bits(self.m2)) & 0xFFFF; @@ -725,7 +786,8 @@ impl M6809 { 0xFA => { return 0; //i_undoc; /* empty */ } - 0xFB => { //i_i_D_S; + 0xFB => { + //i_i_D_S; M = (self.S + signed16bits((self.A << 8) | self.B)) & 0xFFFF; M = mem.read_16(M); self.cl += 7; @@ -842,24 +904,23 @@ impl M6809 { // only for javac // of match r1 let k: int = match r1 { - 0x00 => { (self.A << 8) | self.B } - 0x01 => { self.X } - 0x02 => { self.Y } - 0x03 => { self.U } - 0x04 => { self.S } - 0x05 => { self.PC } - 0x06 => { self.getcc() } - 0x07 => { self.getcc() } - 0x08 => { self.A } - 0x09 => { self.B } - 0x0A => { self.getcc() } - 0x0B => { self.DP } - 0x0C => { self.getcc() } - 0x0D => { self.getcc() } - 0x0E => { self.getcc() } - 0x0F => { self.getcc() } - _ => { 0 } - // only for javac + 0x00 => (self.A << 8) | self.B, + 0x01 => self.X, + 0x02 => self.Y, + 0x03 => self.U, + 0x04 => self.S, + 0x05 => self.PC, + 0x06 => self.getcc(), + 0x07 => self.getcc(), + 0x08 => self.A, + 0x09 => self.B, + 0x0A => self.getcc(), + 0x0B => self.DP, + 0x0C => self.getcc(), + 0x0D => self.getcc(), + 0x0E => self.getcc(), + 0x0F => self.getcc(), + _ => 0, // only for javac }; let mut l = 0; let r2 = m & 0x0F; @@ -993,23 +1054,23 @@ impl M6809 { // only for javac // of match r1 let k: int = match r1 { - 0x00 => { (self.A << 8) | self.B } - 0x01 => { self.X } - 0x02 => { self.Y } - 0x03 => { self.U } - 0x04 => { self.S } - 0x05 => { self.PC } - 0x06 => { self.getcc() } - 0x07 => { self.getcc() } - 0x08 => { self.A } - 0x09 => { self.B } - 0x0A => { self.getcc() } - 0x0B => { self.DP } - 0x0C => { self.getcc() } - 0x0D => { self.getcc() } - 0x0E => { self.getcc() } - 0x0F => { self.getcc() } - _ => { 0 } + 0x00 => (self.A << 8) | self.B, + 0x01 => self.X, + 0x02 => self.Y, + 0x03 => self.U, + 0x04 => self.S, + 0x05 => self.PC, + 0x06 => self.getcc(), + 0x07 => self.getcc(), + 0x08 => self.A, + 0x09 => self.B, + 0x0A => self.getcc(), + 0x0B => self.DP, + 0x0C => self.getcc(), + 0x0D => self.getcc(), + 0x0E => self.getcc(), + 0x0F => self.getcc(), + _ => 0, }; let r2 = m & 0x0F; match r2 { @@ -1407,7 +1468,7 @@ impl M6809 { fn ANDCC(&mut self, adr: int, c: int, mem: &mut Memory) { let val = mem.read(adr); -// getcc(); + // getcc(); self.CC &= val; self.setcc(self.CC); self.cl += c; @@ -2062,7 +2123,8 @@ impl M6809 { let m = mem.read(self.PC); self.PC += 1; if ((self.res & 0xff) == 0) - || (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) != 0) { + || (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) != 0) + { self.PC += signedChar(m); } self.cl += 3; @@ -2076,7 +2138,8 @@ impl M6809 { self.PC += 1; off |= m; if ((self.res & 0xff) == 0) - || (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) != 0) { + || (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) != 0) + { self.PC = (self.PC + off) & 0xFFFF; self.cl += 6; } else { @@ -2112,7 +2175,8 @@ impl M6809 { let m = mem.read(self.PC); self.PC += 1; if ((self.res & 0xff) != 0) - && (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) == 0) { + && (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) == 0) + { self.PC += signedChar(m); } self.cl += 3; @@ -2126,7 +2190,8 @@ impl M6809 { self.PC += 1; off |= m; if ((self.res & 0xff) != 0) - && (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) == 0) { + && (((self.sign ^ ((!(self.m1 ^ self.m2)) & (self.m1 ^ self.ovfl))) & 0x80) == 0) + { self.PC = (self.PC + off) & 0xFFFF; self.cl += 6; } else { @@ -2393,7 +2458,13 @@ impl M6809 { self.cl += 20; } - pub(crate) fn FetchUntil(&mut self, clock: int, mem: &mut Memory, screen: &mut Screen, sound: &mut Sound) -> int { + pub(crate) fn FetchUntil( + &mut self, + clock: int, + mem: &mut Memory, + screen: &mut Screen, + sound: &mut Sound, + ) -> int { while self.cl < clock { self.Fetch(mem, screen, sound); } @@ -2412,7 +2483,6 @@ impl M6809 { } match opcode { - // the mystery undocumented opcode 0x01 => { self.PC += 1; @@ -2477,7 +2547,7 @@ impl M6809 { let M = self.INDEXE(mem); self.D = self.LD16(M, 5, mem); self.CALCAB(); - } + } // LDU 0xCE => { let M = self.IMMED16(); @@ -2525,7 +2595,7 @@ impl M6809 { let M = self.INDEXE(mem); self.ST8(self.A, M, 4, mem); } -// STB + // STB 0xD7 => { let M = self.DIREC(mem); self.ST8(self.B, M, 4, mem); @@ -2538,7 +2608,7 @@ impl M6809 { let M = self.INDEXE(mem); self.ST8(self.B, M, 4, mem); } -// STD + // STD 0xDD => { self.CALCD(); let M = self.DIREC(mem); @@ -2554,7 +2624,7 @@ impl M6809 { let M = self.INDEXE(mem); self.ST16(self.D, M, 6, mem); } -// STU + // STU 0xDF => { let adr = self.DIREC(mem); self.ST16(self.U, adr, 5, mem); @@ -2567,7 +2637,7 @@ impl M6809 { let adr = self.INDEXE(mem); self.ST16(self.U, adr, 5, mem); } -// STX + // STX 0x9F => { let M = self.DIREC(mem); self.ST16(self.X, M, 5, mem); @@ -2580,15 +2650,23 @@ impl M6809 { let M = self.INDEXE(mem); self.ST16(self.X, M, 5, mem); } -// LEAS - 0x32 => { self.S = self.INDEXE(mem); } -// LEAU - 0x33 => { self.U = self.INDEXE(mem); } -// LEAX - 0x30 => { self.X = self.LEA(mem); } -// LEAY - 0x31 => { self.Y = self.LEA(mem); } -// CLRA + // LEAS + 0x32 => { + self.S = self.INDEXE(mem); + } + // LEAU + 0x33 => { + self.U = self.INDEXE(mem); + } + // LEAX + 0x30 => { + self.X = self.LEA(mem); + } + // LEAY + 0x31 => { + self.Y = self.LEA(mem); + } + // CLRA 0x4F => { self.A = 0; self.m1 = self.ovfl; @@ -2596,7 +2674,7 @@ impl M6809 { self.res = 0; self.cl += 2; } -// CLRB + // CLRB 0x5F => { self.B = 0; self.m1 = self.ovfl; @@ -2604,7 +2682,7 @@ impl M6809 { self.res = 0; self.cl += 2; } -// CLR + // CLR 0x0F => { let M = self.DIREC(mem); self.CLR(M, 6, mem); @@ -2617,16 +2695,32 @@ impl M6809 { let M = self.INDEXE(mem); self.CLR(M, 6, mem); } - 0x1E => { self.EXG(mem); } - 0x1F => { self.TFR(mem); } -// PSH/PUL - 0x34 => { self.PSHS(mem); } - 0x36 => { self.PSHU(mem); } - 0x35 => { self.PULS(mem); } - 0x37 => { self.PULU(mem); } -// INC - 0x4C => { self.INCA(); } - 0x5C => { self.INCB(); } + 0x1E => { + self.EXG(mem); + } + 0x1F => { + self.TFR(mem); + } + // PSH/PUL + 0x34 => { + self.PSHS(mem); + } + 0x36 => { + self.PSHU(mem); + } + 0x35 => { + self.PULS(mem); + } + 0x37 => { + self.PULU(mem); + } + // INC + 0x4C => { + self.INCA(); + } + 0x5C => { + self.INCB(); + } 0x7C => { let M = self.ETEND(mem); self.INC(M, 7, mem); @@ -2639,9 +2733,13 @@ impl M6809 { let M = self.INDEXE(mem); self.INC(M, 6, mem); } -// DEC - 0x4A => { self.DECA(); } - 0x5A => { self.DECB(); } + // DEC + 0x4A => { + self.DECA(); + } + 0x5A => { + self.DECB(); + } 0x7A => { let M = self.ETEND(mem); self.DEC(M, 7, mem); @@ -2654,7 +2752,7 @@ impl M6809 { let M = self.INDEXE(mem); self.DEC(M, 6, mem); } -// BIT + // BIT 0x85 => { let M = self.IMMED8(); self.BIT(self.A, M, 2, mem); @@ -2687,7 +2785,7 @@ impl M6809 { let M = self.INDEXE(mem); self.BIT(self.B, M, 4, mem); } -// CMP + // CMP 0x81 => { let M = self.IMMED8(); self.CMP8(self.A, M, 2, mem); @@ -2736,9 +2834,13 @@ impl M6809 { let M = self.INDEXE(mem); self.CMP16(self.X, M, 7, mem); } -// TST - 0x4D => { self.TSTAi(); } - 0x5D => { self.TSTBi(); } + // TST + 0x4D => { + self.TSTAi(); + } + 0x5D => { + self.TSTBi(); + } 0x0D => { let M = self.DIREC(mem); self.TST(M, 6, mem); @@ -2751,7 +2853,7 @@ impl M6809 { let M = self.INDEXE(mem); self.TST(M, 6, mem); } -// AND + // AND 0x84 => { let M = self.IMMED8(); self.ANDA(M, 2, mem); @@ -2788,7 +2890,7 @@ impl M6809 { let M = self.IMMED8(); self.ANDCC(M, 3, mem); } -// OR + // OR 0x8A => { let M = self.IMMED8(); self.ORA(M, 2, mem); @@ -2825,7 +2927,7 @@ impl M6809 { let M = self.IMMED8(); self.ORCC(M, 3, mem); } -// EOR + // EOR 0x88 => { let M = self.IMMED8(); self.EORA(M, 2, mem); @@ -2858,9 +2960,13 @@ impl M6809 { let M = self.INDEXE(mem); self.EORB(M, 4, mem); } -// COM - 0x43 => { self.COMA(); } - 0x53 => { self.COMB(); } + // COM + 0x43 => { + self.COMA(); + } + 0x53 => { + self.COMB(); + } 0x03 => { let M = self.DIREC(mem); self.COM(M, 6, mem); @@ -2873,9 +2979,13 @@ impl M6809 { let M = self.INDEXE(mem); self.COM(M, 6, mem); } -// NEG - 0x40 => { self.NEGA(); } - 0x50 => { self.NEGB(); } + // NEG + 0x40 => { + self.NEGA(); + } + 0x50 => { + self.NEGB(); + } 0x00 => { let M = self.DIREC(mem); self.NEG(M, 6, mem); @@ -2888,8 +2998,10 @@ impl M6809 { let M = self.INDEXE(mem); self.NEG(M, 6, mem); } - 0x3A => { self.ABX(); } -//ADD + 0x3A => { + self.ABX(); + } + //ADD 0x8B => { let M = self.IMMED8(); self.ADDA(M, 2, mem); @@ -2938,7 +3050,7 @@ impl M6809 { let M = self.INDEXE(mem); self.ADDD(M, 6, mem); } -// ADC + // ADC 0x89 => { let M = self.IMMED8(); self.ADCA(M, 2, mem); @@ -2971,8 +3083,10 @@ impl M6809 { let M = self.INDEXE(mem); self.ADCB(M, 4, mem); } - 0x3D => { self.MUL(); } -// SBC + 0x3D => { + self.MUL(); + } + // SBC 0x82 => { let M = self.IMMED8(); self.SBCA(M, 2, mem); @@ -3005,7 +3119,7 @@ impl M6809 { let M = self.INDEXE(mem); self.SBCB(M, 4, mem); } -//SUB + //SUB 0x80 => { let M = self.IMMED8(); self.SUBA(M, 2, mem); @@ -3054,10 +3168,16 @@ impl M6809 { let M = self.INDEXE(mem); self.SUBD(M, 6, mem); } - 0x1D => { self.SEX(); } -// ASL - 0x48 => { self.ASLA(); } - 0x58 => { self.ASLB(); } + 0x1D => { + self.SEX(); + } + // ASL + 0x48 => { + self.ASLA(); + } + 0x58 => { + self.ASLB(); + } 0x08 => { let M = self.DIREC(mem); self.ASL(M, 6, mem); @@ -3070,9 +3190,13 @@ impl M6809 { let M = self.INDEXE(mem); self.ASL(M, 6, mem); } -// ASR - 0x47 => { self.ASRA(); } - 0x57 => { self.ASRB(); } + // ASR + 0x47 => { + self.ASRA(); + } + 0x57 => { + self.ASRB(); + } 0x07 => { let M = self.DIREC(mem); self.ASR(M, 6, mem); @@ -3085,9 +3209,13 @@ impl M6809 { let M = self.INDEXE(mem); self.ASR(M, 6, mem); } -// LSR - 0x44 => { self.LSRA(); } - 0x54 => { self.LSRB(); } + // LSR + 0x44 => { + self.LSRA(); + } + 0x54 => { + self.LSRB(); + } 0x04 => { let M = self.DIREC(mem); self.LSR(M, 6, mem); @@ -3100,9 +3228,13 @@ impl M6809 { let M = self.INDEXE(mem); self.LSR(M, 6, mem); } -// ROL - 0x49 => { self.ROLA(); } - 0x59 => { self.ROLB(); } + // ROL + 0x49 => { + self.ROLA(); + } + 0x59 => { + self.ROLB(); + } 0x09 => { let M = self.DIREC(mem); self.ROL(M, 6, mem); @@ -3115,9 +3247,13 @@ impl M6809 { let M = self.INDEXE(mem); self.ROL(M, 6, mem); } -// ROR - 0x46 => { self.RORA(); } - 0x56 => { self.RORB(); } + // ROR + 0x46 => { + self.RORA(); + } + 0x56 => { + self.RORB(); + } 0x06 => { let M = self.DIREC(mem); self.ROR(M, 6, mem); @@ -3130,48 +3266,110 @@ impl M6809 { let M = self.INDEXE(mem); self.ROR(M, 6, mem); } -// BRA - 0x20 => { self.BRA(mem); } - 0x16 => { self.LBRA(mem); } -// JMP - 0x0E => { self.JMPd(mem); } - 0x7E => { self.JMPe(mem); } - 0x6E => { self.JMPx(mem); } -// BSR - 0x8D => { self.BSR(mem); } - 0x17 => { self.LBSR(mem); } -// JSR - 0x9D => { self.JSRd(mem); } - 0xBD => { self.JSRe(mem); } - 0xAD => { self.JSRx(mem); } - 0x12 => { self.NOP(); } - 0x39 => { self.RTS(mem); } -// Bxx - 0x21 => { self.BRN(mem); } - 0x24 => { self.BCC(mem); } - 0x25 => { self.BCS(mem); } - 0x27 => { self.BEQ(mem); } - 0x26 => { self.BNE(mem); } - 0x2C => { self.BGE(mem); } - 0x2F => { self.BLE(mem); } - 0x23 => { self.BLS(mem); } - 0x2E => { self.BGT(mem); } - 0x2D => { self.BLT(mem); } - 0x22 => { self.BHI(mem); } - 0x2B => { self.BMI(mem); } - 0x2A => { self.BPL(mem); } - 0x28 => { self.BVC(mem); } - 0x29 => { self.BVS(mem); } - 0x3F => { self.SWI(mem); } - 0x3B => { self.RTI(mem); } - 0x19 => { self.DAA(); } - 0x3C => { self.CWAI(mem); } + // BRA + 0x20 => { + self.BRA(mem); + } + 0x16 => { + self.LBRA(mem); + } + // JMP + 0x0E => { + self.JMPd(mem); + } + 0x7E => { + self.JMPe(mem); + } + 0x6E => { + self.JMPx(mem); + } + // BSR + 0x8D => { + self.BSR(mem); + } + 0x17 => { + self.LBSR(mem); + } + // JSR + 0x9D => { + self.JSRd(mem); + } + 0xBD => { + self.JSRe(mem); + } + 0xAD => { + self.JSRx(mem); + } + 0x12 => { + self.NOP(); + } + 0x39 => { + self.RTS(mem); + } + // Bxx + 0x21 => { + self.BRN(mem); + } + 0x24 => { + self.BCC(mem); + } + 0x25 => { + self.BCS(mem); + } + 0x27 => { + self.BEQ(mem); + } + 0x26 => { + self.BNE(mem); + } + 0x2C => { + self.BGE(mem); + } + 0x2F => { + self.BLE(mem); + } + 0x23 => { + self.BLS(mem); + } + 0x2E => { + self.BGT(mem); + } + 0x2D => { + self.BLT(mem); + } + 0x22 => { + self.BHI(mem); + } + 0x2B => { + self.BMI(mem); + } + 0x2A => { + self.BPL(mem); + } + 0x28 => { + self.BVC(mem); + } + 0x29 => { + self.BVS(mem); + } + 0x3F => { + self.SWI(mem); + } + 0x3B => { + self.RTI(mem); + } + 0x19 => { + self.DAA(); + } + 0x3C => { + self.CWAI(mem); + } // extended mode 0x10 => { let opcode0x10 = mem.read(self.PC); self.PC += 1; match opcode0x10 { -// LDS + // LDS 0xCE => { let M = self.IMMED16(); self.S = self.LD16(M, 3, mem); @@ -3188,7 +3386,7 @@ impl M6809 { let M = self.INDEXE(mem); self.S = self.LD16(M, 5, mem); } -// LDY + // LDY 0x8E => { let M = self.IMMED16(); self.Y = self.LD16(M, 3, mem); @@ -3205,7 +3403,7 @@ impl M6809 { let M = self.INDEXE(mem); self.Y = self.LD16(M, 5, mem); } -// STS + // STS 0xDF => { let M = self.DIREC(mem); self.ST16(self.S, M, 5, mem); @@ -3218,7 +3416,7 @@ impl M6809 { let M = self.INDEXE(mem); self.ST16(self.S, M, 5, mem); } -// STY + // STY 0x9F => { let M = self.DIREC(mem); self.ST16(self.Y, M, 5, mem); @@ -3231,7 +3429,7 @@ impl M6809 { let M = self.INDEXE(mem); self.ST16(self.Y, M, 5, mem); } -// CMP + // CMP 0x83 => { self.CALCD(); let M = self.IMMED16(); @@ -3268,22 +3466,52 @@ impl M6809 { let M = self.INDEXE(mem); self.CMP16(self.Y, M, 7, mem); } -// Bxx - 0x21 => { self.LBRN(mem); } - 0x24 => { self.LBCC(mem); } - 0x25 => { self.LBCS(mem); } - 0x27 => { self.LBEQ(mem); } - 0x26 => { self.LBNE(mem); } - 0x2C => { self.LBGE(mem); } - 0x2F => { self.LBLE(mem); } - 0x23 => { self.LBLS(mem); } - 0x2E => { self.LBGT(mem); } - 0x2D => { self.LBLT(mem); } - 0x22 => { self.LBHI(mem); } - 0x2B => { self.LBMI(mem); } - 0x2A => { self.LBPL(mem); } - 0x28 => { self.LBVC(mem); } - 0x29 => { self.LBVS(mem); } + // Bxx + 0x21 => { + self.LBRN(mem); + } + 0x24 => { + self.LBCC(mem); + } + 0x25 => { + self.LBCS(mem); + } + 0x27 => { + self.LBEQ(mem); + } + 0x26 => { + self.LBNE(mem); + } + 0x2C => { + self.LBGE(mem); + } + 0x2F => { + self.LBLE(mem); + } + 0x23 => { + self.LBLS(mem); + } + 0x2E => { + self.LBGT(mem); + } + 0x2D => { + self.LBLT(mem); + } + 0x22 => { + self.LBHI(mem); + } + 0x2B => { + self.LBMI(mem); + } + 0x2A => { + self.LBPL(mem); + } + 0x28 => { + self.LBVC(mem); + } + 0x29 => { + self.LBVS(mem); + } _ => { eprintln!("opcode 10 {} not implemented", hex(opcode0x10, 2)); eprintln!("{}", self.print_state()); @@ -3295,7 +3523,6 @@ impl M6809 { self.PC += 1; match opcode0x11 { - // CMP 0x8C => { let M = self.IMMED16(); @@ -3342,20 +3569,21 @@ impl M6809 { } // of case opcode } // of method fetch() - // UNASSEMBLE/DEBUG PART pub(crate) fn print_state(&mut self) -> String { self.CC = self.getcc(); - let s = format!("A={} B={} X={} Y={}\nPC={} DP={} U={} S={} CC={}", - hex(self.A, 2), - hex(self.B, 2), - hex(self.X, 4), - hex(self.Y, 4), - hex(self.PC, 4), - hex(self.DP, 2), - hex(self.U, 4), - hex(self.S, 4), - hex(self.CC, 2)); + let s = format!( + "A={} B={} X={} Y={}\nPC={} DP={} U={} S={} CC={}", + hex(self.A, 2), + hex(self.B, 2), + hex(self.X, 4), + hex(self.Y, 4), + hex(self.PC, 4), + hex(self.DP, 2), + hex(self.U, 4), + hex(self.S, 4), + hex(self.CC, 2) + ); s } } @@ -3370,12 +3598,24 @@ fn hex(val: int, size: int) -> String { output.push_str(format!("{}", q).as_str()); } else { match q { - 10 => { output.push('A'); } - 11 => { output.push('B'); } - 12 => { output.push('C'); } - 13 => { output.push('D'); } - 14 => { output.push('E'); } - 15 => { output.push('F'); } + 10 => { + output.push('A'); + } + 11 => { + output.push('B'); + } + 12 => { + output.push('C'); + } + 13 => { + output.push('D'); + } + 14 => { + output.push('E'); + } + 15 => { + output.push('F'); + } _ => {} } } @@ -3423,29 +3663,67 @@ fn regx(m: int) -> String { fn r_tfr(m: int) -> String { let mut output = String::new(); match m & 0xF0 { - 0x80 => { output.push_str("A,"); } - 0x90 => { output.push_str("B,"); } - 0xA0 => { output.push_str("CC,"); } - 0x00 => { output.push_str("D,"); } - 0xB0 => { output.push_str("DP,"); } - 0x50 => { output.push_str("PC,"); } - 0x40 => { output.push_str("S,"); } - 0x30 => { output.push_str("U,"); } - 0x10 => { output.push_str("X,"); } - 0x20 => { output.push_str("Y,"); } + 0x80 => { + output.push_str("A,"); + } + 0x90 => { + output.push_str("B,"); + } + 0xA0 => { + output.push_str("CC,"); + } + 0x00 => { + output.push_str("D,"); + } + 0xB0 => { + output.push_str("DP,"); + } + 0x50 => { + output.push_str("PC,"); + } + 0x40 => { + output.push_str("S,"); + } + 0x30 => { + output.push_str("U,"); + } + 0x10 => { + output.push_str("X,"); + } + 0x20 => { + output.push_str("Y,"); + } _ => {} }; match m & 0x0F { - 0x8 => { output.push('A'); } - 0x9 => { output.push('B'); } - 0xA => { output.push_str("CC"); } - 0x0 => { output.push('D'); } - 0xB => { output.push_str("DP"); } + 0x8 => { + output.push('A'); + } + 0x9 => { + output.push('B'); + } + 0xA => { + output.push_str("CC"); + } + 0x0 => { + output.push('D'); + } + 0xB => { + output.push_str("DP"); + } 0x5 => output.push_str("PC"), - 0x4 => { output.push('S'); } - 0x3 => { output.push('U'); } - 0x1 => { output.push('X'); } - 0x2 => { output.push('Y'); } + 0x4 => { + output.push('S'); + } + 0x3 => { + output.push('U'); + } + 0x1 => { + output.push('X'); + } + 0x2 => { + output.push('Y'); + } _ => {} } output @@ -3726,7 +4004,6 @@ pub(crate) fn unassemble(start: int, maxLines: int, mem: &mut Memory) -> String /* MUL */ MNEMO[0x3D] = "MUL -"; - /* SBC */ MNEMO[0x82] = "SBCAi"; MNEMO[0x92] = "SBCAd"; @@ -3880,7 +4157,6 @@ pub(crate) fn unassemble(start: int, maxLines: int, mem: &mut Memory) -> String /* RTI */ MNEMO[0x3B] = "RTI -"; - let mut _where = start; let mut output = String::new(); @@ -4205,4 +4481,3 @@ pub(crate) fn unassemble(start: int, maxLines: int, mem: &mut Memory) -> String } // of for ... maxLines output } - diff --git a/src/hardware/keyboard/mod.rs b/src/hardware/keyboard/mod.rs index 628941f..339e65d 100644 --- a/src/hardware/keyboard/mod.rs +++ b/src/hardware/keyboard/mod.rs @@ -31,68 +31,209 @@ impl Default for Keyboard { impl Keyboard { fn key_translator(&mut self, vk: CustomVirtualKeyCode, press: bool, mem: &mut Memory) { match vk { - Base(VirtualKeyCode::Backspace) => { key_memory(0x6c, press, mem); } - Base(VirtualKeyCode::Delete) => { key_memory(0x12, press, mem); } - Base(VirtualKeyCode::Return) => { key_memory(0x68, press, mem); } - Base(VirtualKeyCode::Insert) => { key_memory(0x12, press, mem); } - Base(VirtualKeyCode::Up) => { key_memory(0x62, press, mem); } - Base(VirtualKeyCode::Left) => { key_memory(0x52, press, mem); } - Base(VirtualKeyCode::Right) => { key_memory(0x32, press, mem); } - Base(VirtualKeyCode::Down) => { key_memory(0x42, press, mem); } - Base(VirtualKeyCode::LControl) => { key_memory(0x6a, press, mem); } - Base(VirtualKeyCode::Escape) => { key_memory(0x66, press, mem); } - Base(VirtualKeyCode::LShift) => { key_memory(0x70, press, mem); }//Shift - Base(VirtualKeyCode::F11) => { key_memory(0x72, press, mem); }// Basic + Base(VirtualKeyCode::Backspace) => { + key_memory(0x6c, press, mem); + } + Base(VirtualKeyCode::Delete) => { + key_memory(0x12, press, mem); + } + Base(VirtualKeyCode::Return) => { + key_memory(0x68, press, mem); + } + Base(VirtualKeyCode::Insert) => { + key_memory(0x12, press, mem); + } + Base(VirtualKeyCode::Up) => { + key_memory(0x62, press, mem); + } + Base(VirtualKeyCode::Left) => { + key_memory(0x52, press, mem); + } + Base(VirtualKeyCode::Right) => { + key_memory(0x32, press, mem); + } + Base(VirtualKeyCode::Down) => { + key_memory(0x42, press, mem); + } + Base(VirtualKeyCode::LControl) => { + key_memory(0x6a, press, mem); + } + Base(VirtualKeyCode::Escape) => { + key_memory(0x66, press, mem); + } + Base(VirtualKeyCode::LShift) => { + key_memory(0x70, press, mem); + } //Shift + Base(VirtualKeyCode::F11) => { + key_memory(0x72, press, mem); + } // Basic - Base(VirtualKeyCode::Key1) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x5e, press, mem); } - Base(VirtualKeyCode::Key2) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x4e, press, mem); } - Base(VirtualKeyCode::Key3) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x3e, press, mem); } - Base(VirtualKeyCode::Key4) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x2e, press, mem); } - Base(VirtualKeyCode::Key5) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x1e, press, mem); } - Base(VirtualKeyCode::Key6) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x0e, press, mem); } - Base(VirtualKeyCode::Key7) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x0c, press, mem); } - Base(VirtualKeyCode::Key8) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x1c, press, mem); } - Base(VirtualKeyCode::Key9) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x2c, press, mem); } - Base(VirtualKeyCode::Key0) => { if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x3c, press, mem); } - Base(VirtualKeyCode::Minus) => {if self.modifiers.shift() {key_memory(0x70, press, mem);} key_memory(0x4c, press, mem); } + Base(VirtualKeyCode::Key1) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x5e, press, mem); + } + Base(VirtualKeyCode::Key2) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x4e, press, mem); + } + Base(VirtualKeyCode::Key3) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x3e, press, mem); + } + Base(VirtualKeyCode::Key4) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x2e, press, mem); + } + Base(VirtualKeyCode::Key5) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x1e, press, mem); + } + Base(VirtualKeyCode::Key6) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x0e, press, mem); + } + Base(VirtualKeyCode::Key7) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x0c, press, mem); + } + Base(VirtualKeyCode::Key8) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x1c, press, mem); + } + Base(VirtualKeyCode::Key9) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x2c, press, mem); + } + Base(VirtualKeyCode::Key0) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x3c, press, mem); + } + Base(VirtualKeyCode::Minus) => { + if self.modifiers.shift() { + key_memory(0x70, press, mem); + } + key_memory(0x4c, press, mem); + } - Base(VirtualKeyCode::A) => { key_memory(0x5a, press, mem); } - Base(VirtualKeyCode::Z) => { key_memory(0x4a, press, mem); } - Base(VirtualKeyCode::E) => { key_memory(0x3a, press, mem); } - Base(VirtualKeyCode::R) => { key_memory(0x2a, press, mem); } - Base(VirtualKeyCode::T) => { key_memory(0x1a, press, mem); } - Base(VirtualKeyCode::Y) => { key_memory(0x0a, press, mem); } - Base(VirtualKeyCode::U) => { key_memory(0x08, press, mem); } - Base(VirtualKeyCode::I) => { key_memory(0x18, press, mem); } - Base(VirtualKeyCode::O) => { key_memory(0x28, press, mem); } - Base(VirtualKeyCode::P) => { key_memory(0x38, press, mem); } - Base(VirtualKeyCode::Caret) => { key_memory(0x48, press, mem); } + Base(VirtualKeyCode::A) => { + key_memory(0x5a, press, mem); + } + Base(VirtualKeyCode::Z) => { + key_memory(0x4a, press, mem); + } + Base(VirtualKeyCode::E) => { + key_memory(0x3a, press, mem); + } + Base(VirtualKeyCode::R) => { + key_memory(0x2a, press, mem); + } + Base(VirtualKeyCode::T) => { + key_memory(0x1a, press, mem); + } + Base(VirtualKeyCode::Y) => { + key_memory(0x0a, press, mem); + } + Base(VirtualKeyCode::U) => { + key_memory(0x08, press, mem); + } + Base(VirtualKeyCode::I) => { + key_memory(0x18, press, mem); + } + Base(VirtualKeyCode::O) => { + key_memory(0x28, press, mem); + } + Base(VirtualKeyCode::P) => { + key_memory(0x38, press, mem); + } + Base(VirtualKeyCode::Caret) => { + key_memory(0x48, press, mem); + } // Base(VirtualKeyCode::Dollar) => { key_memory(0x58, press, mem); } - - Base(VirtualKeyCode::Q) => { key_memory(0x56, press, mem); } - Base(VirtualKeyCode::S) => { key_memory(0x46, press, mem); } - Base(VirtualKeyCode::D) => { key_memory(0x36, press, mem); } - Base(VirtualKeyCode::F) => { key_memory(0x26, press, mem); } - Base(VirtualKeyCode::G) => { key_memory(0x16, press, mem); } - Base(VirtualKeyCode::H) => { key_memory(0x06, press, mem); } - Base(VirtualKeyCode::J) => { key_memory(0x04, press, mem); } - Base(VirtualKeyCode::K) => { key_memory(0x14, press, mem); } - Base(VirtualKeyCode::L) => { key_memory(0x24, press, mem); } - Base(VirtualKeyCode::M) => { key_memory(0x34, press, mem); } + Base(VirtualKeyCode::Q) => { + key_memory(0x56, press, mem); + } + Base(VirtualKeyCode::S) => { + key_memory(0x46, press, mem); + } + Base(VirtualKeyCode::D) => { + key_memory(0x36, press, mem); + } + Base(VirtualKeyCode::F) => { + key_memory(0x26, press, mem); + } + Base(VirtualKeyCode::G) => { + key_memory(0x16, press, mem); + } + Base(VirtualKeyCode::H) => { + key_memory(0x06, press, mem); + } + Base(VirtualKeyCode::J) => { + key_memory(0x04, press, mem); + } + Base(VirtualKeyCode::K) => { + key_memory(0x14, press, mem); + } + Base(VirtualKeyCode::L) => { + key_memory(0x24, press, mem); + } + Base(VirtualKeyCode::M) => { + key_memory(0x34, press, mem); + } // Base(VirtualKeyCode::Asterisk) => { key_memory(0x58, press, mem); } + Base(VirtualKeyCode::W) => { + key_memory(0x60, press, mem); + } + Base(VirtualKeyCode::X) => { + key_memory(0x50, press, mem); + } + Base(VirtualKeyCode::C) => { + key_memory(0x64, press, mem); + } + Base(VirtualKeyCode::V) => { + key_memory(0x54, press, mem); + } + Base(VirtualKeyCode::B) => { + key_memory(0x44, press, mem); + } + Base(VirtualKeyCode::N) => { + key_memory(0x00, press, mem); + } + Base(VirtualKeyCode::Comma) => { + key_memory(0x10, press, mem); + } + Base(VirtualKeyCode::Period) => { + key_memory(0x20, press, mem); + } + Base(VirtualKeyCode::At) => { + key_memory(0x30, press, mem); + } + Base(VirtualKeyCode::Asterisk) => { + key_memory(0x58, press, mem); + } - Base(VirtualKeyCode::W) => { key_memory(0x60, press, mem); } - Base(VirtualKeyCode::X) => { key_memory(0x50, press, mem); } - Base(VirtualKeyCode::C) => { key_memory(0x64, press, mem); } - Base(VirtualKeyCode::V) => { key_memory(0x54, press, mem); } - Base(VirtualKeyCode::B) => { key_memory(0x44, press, mem); } - Base(VirtualKeyCode::N) => { key_memory(0x00, press, mem); } - Base(VirtualKeyCode::Comma) => { key_memory(0x10, press, mem); } - Base(VirtualKeyCode::Period) => { key_memory(0x20, press, mem); } - Base(VirtualKeyCode::At) => { key_memory(0x30, press, mem); } - Base(VirtualKeyCode::Asterisk) => { key_memory(0x58, press, mem); } - - Base(VirtualKeyCode::Space) => { key_memory(0x40, press, mem); } + Base(VirtualKeyCode::Space) => { + key_memory(0x40, press, mem); + } _ => { info!("Unknown virtual key code: {:?}", vk); @@ -107,7 +248,11 @@ impl Keyboard { self.key_translator(virtual_key_code, true, mem); } - pub(crate) fn key_released(&mut self, virtual_key_code: CustomVirtualKeyCode, mem: &mut Memory) { + pub(crate) fn key_released( + &mut self, + virtual_key_code: CustomVirtualKeyCode, + mem: &mut Memory, + ) { self.key_translator(virtual_key_code, false, mem); } @@ -172,10 +317,7 @@ struct Key { impl Key { fn new(key: int) -> Self { - Key { - key, - key2: None, - } + Key { key, key2: None } } fn new_with_key2(key: int, key2: int) -> Self { diff --git a/src/hardware/keyboard/vkey.rs b/src/hardware/keyboard/vkey.rs index 6e875d9..aa058d2 100644 --- a/src/hardware/keyboard/vkey.rs +++ b/src/hardware/keyboard/vkey.rs @@ -4,15 +4,18 @@ use crate::hardware::keyboard::vkey::CustomVirtualKeyCode::Base; #[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)] pub(crate) enum CustomVirtualKeyCode { - Base(VirtualKeyCode) + Base(VirtualKeyCode), } -pub(crate) fn map_virtual_key_code(virtual_key_code: Option, scancode: KeyScancode) -> Option { +pub(crate) fn map_virtual_key_code( + virtual_key_code: Option, + scancode: KeyScancode, +) -> Option { match virtual_key_code { Some(vk) => Some(Base(vk)), None => { - println!("Unknown scancode: {:?}", scancode); - None + println!("Unknown scancode: {:?}", scancode); + None } } -} \ No newline at end of file +} diff --git a/src/hardware/machine.rs b/src/hardware/machine.rs index 499ba9b..1542217 100644 --- a/src/hardware/machine.rs +++ b/src/hardware/machine.rs @@ -8,10 +8,10 @@ use log::info; use rfd::FileDialog; use crate::hardware::keyboard::Keyboard; -use crate::hardware::M6809::M6809; use crate::hardware::memory::Memory; -use crate::hardware::screen::{DEFAULT_PIXEL_SIZE, Screen}; +use crate::hardware::screen::{Screen, DEFAULT_PIXEL_SIZE}; use crate::hardware::sound::Sound; +use crate::hardware::M6809::M6809; use crate::int; use crate::user_input::UserInput; @@ -22,11 +22,11 @@ pub(crate) struct Machine { pub(crate) screen: Screen, sound: Sound, pub(crate) keyboard: Keyboard, - pub(crate) testtimer:int, + pub(crate) testtimer: int, pub(crate) irq: bool, pub(crate) last_time: DateTime, pub(crate) keys: Vec, - pub(crate) keytimer:int, + pub(crate) keytimer: int, pub(crate) keypos: usize, pub(crate) typetext: Option, pub(crate) running: bool, @@ -35,7 +35,10 @@ pub(crate) struct Machine { } impl Machine { - pub(crate) fn new(image_data_sender: Sender>, user_input_receiver: Receiver) -> Self { + pub(crate) fn new( + image_data_sender: Sender>, + user_input_receiver: Receiver, + ) -> Self { info!("Machine::new()"); let screen = Screen::new(); info!("Machine::screen()"); @@ -121,19 +124,23 @@ impl Machine { /* 3.9 ms haut �cran (+0.3 irq)*/ if self.irq { self.irq = false; - self.micro.FetchUntil(3800, &mut self.mem, &mut self.screen, &mut self.sound); + self.micro + .FetchUntil(3800, &mut self.mem, &mut self.screen, &mut self.sound); } else { - self.micro.FetchUntil(4100, &mut self.mem, &mut self.screen, &mut self.sound); + self.micro + .FetchUntil(4100, &mut self.mem, &mut self.screen, &mut self.sound); } /* 13ms fenetre */ self.mem.set(0xA7E7, 0x80); self.mem.GA3 = 0x80; - self.micro.FetchUntil(13100, &mut self.mem, &mut self.screen, &mut self.sound); + self.micro + .FetchUntil(13100, &mut self.mem, &mut self.screen, &mut self.sound); self.mem.set(0xA7E7, 0x00); self.mem.GA3 = 0x00; - self.micro.FetchUntil(2800, &mut self.mem, &mut self.screen, &mut self.sound); + self.micro + .FetchUntil(2800, &mut self.mem, &mut self.screen, &mut self.sound); if (self.mem.CRB & 0x01) == 0x01 { self.irq = true; @@ -145,7 +152,8 @@ impl Machine { self.micro.IRQ(&mut self.mem); } /* 300 cycles sous interrupt */ - self.micro.FetchUntil(300, &mut self.mem, &mut self.screen, &mut self.sound); + self.micro + .FetchUntil(300, &mut self.mem, &mut self.screen, &mut self.sound); self.mem.CRB &= 0x7F; self.mem.set(0xA7C3, self.mem.CRB); } @@ -186,9 +194,10 @@ impl Machine { } } } - let real_time_millis:i64 = Local::now().timestamp_millis() - self.last_time.timestamp_millis(); + let real_time_millis: i64 = + Local::now().timestamp_millis() - self.last_time.timestamp_millis(); - let sleep_millis:i64 = 20i64 - real_time_millis - 1; + let sleep_millis: i64 = 20i64 - real_time_millis - 1; if sleep_millis < 0 { self.last_time = Local::now(); return; @@ -231,4 +240,3 @@ impl Machine { // unassemble(self.micro.PC, nblines, mem) // } } - diff --git a/src/hardware/memory.rs b/src/hardware/memory.rs index 3020fb7..8d5d4f6 100644 --- a/src/hardware/memory.rs +++ b/src/hardware/memory.rs @@ -20,18 +20,17 @@ pub(crate) struct Memory { pub(crate) light_pen_x: int, pub(crate) light_pen_y: int, -// 0 1 POINT 2 -// 2 3 COLOR 2 -// 4 5 6 7 RAM1 4 -// 8 9 10 11 RAM2 4 -// 12 LINEA 1 -// 13 LINEB 1 -// 14 15 16 17 ROM 4 - - mem:Vec>, - mapper:[int;16], - key:Vec, - dirty:Vec, + // 0 1 POINT 2 + // 2 3 COLOR 2 + // 4 5 6 7 RAM1 4 + // 8 9 10 11 RAM2 4 + // 12 LINEA 1 + // 13 LINEB 1 + // 14 15 16 17 ROM 4 + mem: Vec>, + mapper: [int; 16], + key: Vec, + dirty: Vec, /* Registres du 6821 */ ORA: int, @@ -39,25 +38,25 @@ pub(crate) struct Memory { DDRA: int, DDRB: int, CRA: int, - pub(crate) CRB:int, + pub(crate) CRB: int, pub(crate) sound_mem: u8, /* Registre du Gate Array */ - GA0:int, - GA1:int, - GA2:int, - pub(crate) GA3:int, - - k7_bit:int, - k7_char:int, - - k7_fis:Option, - k7_fos:Option>, - is_file_opened:bool, - is_file_opened_out:bool, - k7_in:Option, - k7_out:Option, - k7_out_name:Option, + GA0: int, + GA1: int, + GA2: int, + pub(crate) GA3: int, + + k7_bit: int, + k7_char: int, + + k7_fis: Option, + k7_fos: Option>, + is_file_opened: bool, + is_file_opened_out: bool, + k7_in: Option, + k7_out: Option, + k7_out_name: Option, } impl Default for Memory { @@ -67,7 +66,7 @@ impl Default for Memory { light_pen_x: 0, light_pen_y: 0, mem: vec![vec![0; 0x1000]; 18], - mapper: [0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,], + mapper: [0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], key: vec![false; 256], dirty: vec![false; 200], ORA: 0, @@ -121,7 +120,8 @@ impl Memory { if page == 0x0A { self.hardware(address, value); } else { - self.mem[self.mapper[page as usize] as usize][(address & 0xFFF) as usize] = value & 0xFF; + self.mem[self.mapper[page as usize] as usize][(address & 0xFFF) as usize] = + value & 0xFF; } } @@ -134,7 +134,8 @@ impl Memory { if page == 0x0A { self.hardware(address, value); } else { - self.mem[self.mapper[page as usize] as usize][(address & 0xFFF) as usize] = value & 0xFF; + self.mem[self.mapper[page as usize] as usize][(address & 0xFFF) as usize] = + value & 0xFF; } } @@ -149,12 +150,12 @@ impl Memory { self.mem[self.mapper[page as usize] as usize][(address & 0xFFF) as usize] = value & 0xFF; } - pub(crate) fn POINT(&mut self, address: int) ->int { + pub(crate) fn POINT(&mut self, address: int) -> int { let page = (address & 0xF000) >> 12; self.mem[page as usize][(address & 0xFFF) as usize] } - pub(crate) fn COLOR(&mut self, address: int) ->int { + pub(crate) fn COLOR(&mut self, address: int) -> int { let page = (address & 0xF000) >> 12; self.mem[(page + 2) as usize][(address & 0xFFF) as usize] } @@ -193,7 +194,10 @@ impl Memory { let embedded_bios = Bios::get("mo5.rom").unwrap(); let starting_address = 0xC000; for i in starting_address..0x10000 { - self.write_p(i, embedded_bios.data[(i - starting_address) as usize] as int); + self.write_p( + i, + embedded_bios.data[(i - starting_address) as usize] as int, + ); } // // let u = "bios/mo5.rom"; @@ -215,8 +219,9 @@ impl Memory { /* 6821 système */ /* acces à ORA ou DDRA */ if ADR == 0xA7C0 { - - if (self.CRA & 0x04) == 0x04 /* Accès à ORA */ { + if (self.CRA & 0x04) == 0x04 + /* Accès à ORA */ + { if (OP & 0x01) == 0x01 { self.mapper[0] = 0; self.mapper[1] = 1; @@ -236,10 +241,12 @@ impl Memory { self.DDRA = OP; self.mem[0xA + 2][0x7C0] = OP; } - } else if ADR == 0xA7C1/* accès à ORB ou DDRB */ + } else if ADR == 0xA7C1 + /* accès à ORB ou DDRB */ { if (self.CRB & 0x04) == 0x04 - /* Accès à ORB */ { + /* Accès à ORB */ + { self.ORB = (self.ORB & (self.DDRB ^ 0xFF)) | (OP & self.DDRB); /* GESTION HARD DU CLAVIER */ @@ -256,14 +263,15 @@ impl Memory { self.DDRB = OP; self.mem[0xA + 2][0x7C1] = OP; } - } else if ADR == 0xA7C2 {/* accès à CRA */ + } else if ADR == 0xA7C2 { + /* accès à CRA */ self.CRA = (self.CRA & 0xD0) | (OP & 0x3F); self.mem[0xA + 2][0x7C2] = self.CRA; - } else if ADR == 0xA7C3 {/* accès à CRB */ + } else if ADR == 0xA7C3 { + /* accès à CRB */ self.CRB = (self.CRB & 0xD0) | (OP & 0x3F); self.mem[0xA + 2][0x7C3] = self.CRB; } - } pub(crate) fn set_key(&mut self, i: int) { @@ -297,7 +305,11 @@ impl Memory { match DataInputStream::new(name) { Ok(data) => { - println!("Opened K7 {} of length {}", name.file_name().unwrap().to_str().unwrap(), data.len()); + println!( + "Opened K7 {} of length {}", + name.file_name().unwrap().to_str().unwrap(), + data.len() + ); self.k7_fis = Some(data); self.is_file_opened = true; self.k7_bit = 0; @@ -318,7 +330,6 @@ impl Memory { } fn create_k7file(&mut self) -> bool { - if self.k7_out_name.is_some() { return self.is_file_opened_out; } @@ -356,7 +367,6 @@ impl Memory { } fn readbit(&mut self, screen: &mut Screen) -> int { - if !self.is_file_opened { return 0; } @@ -392,12 +402,9 @@ impl Memory { 0 } - pub(crate) fn periph(&mut self, PC: int, S: int, A: int, screen: &mut Screen) { - if PC == 0xF169 { self.readbit(screen); - } /* Write K7 byte */ /* Merci … Olivier Tardieu pour le d‚sassemblage de la routine en ROM */ @@ -433,12 +440,11 @@ impl Memory { } fn patch_k7(&mut self) { - /* PATCH une partie des fonctions du moniteur - la s‚quence 02 39 correspond … + la s‚quence 02 39 correspond Illegal (instruction) NOP le TRAP active la gestion des @@ -451,7 +457,6 @@ impl Memory { self.set(0xf548, 0x02); // PER instruction émulateur self.set(0xf549, 0x39); // RTS - self.set(0xF1AF, 0x02); self.set(0xF1B0, 0x39); @@ -467,6 +472,5 @@ impl Memory { self.set(0xF16B, 0x39); } - fn unpatch_k7(&mut self) { - } + fn unpatch_k7(&mut self) {} } diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index 38026d5..877c5f0 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -1,6 +1,6 @@ +pub(crate) mod M6809; +pub(crate) mod keyboard; pub(crate) mod machine; -pub(crate) mod screen; pub(crate) mod memory; +pub(crate) mod screen; pub(crate) mod sound; -pub(crate) mod keyboard; -pub(crate) mod M6809; \ No newline at end of file diff --git a/src/hardware/screen.rs b/src/hardware/screen.rs index cbcf81c..4c1f000 100644 --- a/src/hardware/screen.rs +++ b/src/hardware/screen.rs @@ -2,22 +2,8 @@ use crate::hardware::memory::Memory; use crate::int; const PALETTE: [u32; 16] = [ - 0x000000, - 0xF00000, - 0x00F000, - 0xF0F000, - 0x0000F0, - 0xF000F0, - 0x00F0F0, - 0xF0F0F0, - 0x636363, - 0xF06363, - 0x63F063, - 0xF0F063, - 0x0063F0, - 0xF063F0, - 0x63F0F0, - 0xF06300, + 0x000000, 0xF00000, 0x00F000, 0xF0F000, 0x0000F0, 0xF000F0, 0x00F0F0, 0xF0F0F0, 0x636363, + 0xF06363, 0x63F063, 0xF0F063, 0x0063F0, 0xF063F0, 0x63F0F0, 0xF06300, ]; pub(crate) const WIDTH: usize = 320; diff --git a/src/hardware/sound/mod.rs b/src/hardware/sound/mod.rs index 9e8c9bd..5e343f5 100644 --- a/src/hardware/sound/mod.rs +++ b/src/hardware/sound/mod.rs @@ -14,7 +14,7 @@ pub(crate) struct Sound { pub buffer: Arc>>, sample_rate: u32, audio_stream: cpal::Stream, - audio: [u8;N_BYTES/4], + audio: [u8; N_BYTES / 4], } impl Sound { @@ -26,7 +26,7 @@ impl Sound { buffer, sample_rate: rate, audio_stream: stream, - audio: [0;N_BYTES/4], + audio: [0; N_BYTES / 4], }; apu.audio_stream.play().ok()?; Some(apu) @@ -39,7 +39,7 @@ impl Sound { self.audio[i / 4] = cpu.sound_buffer[i]; } let mut buffer = self.buffer.lock().unwrap(); - for i in 0..N_BYTES/4 { + for i in 0..N_BYTES / 4 { buffer.push(self.audio[i]); } } @@ -47,9 +47,7 @@ impl Sound { // Get audio stream and sample rate to use when processing audio. We pass the shared // buffer which will be used by the APU. -fn get_audio_stream( - buffer: Arc>>, -) -> Option<(cpal::Stream, cpal::SampleRate)> { +fn get_audio_stream(buffer: Arc>>) -> Option<(cpal::Stream, cpal::SampleRate)> { let device = cpal::default_host().default_output_device()?; let supported_configs = device.supported_output_configs().ok()?; let mut supported_config = None; @@ -97,7 +95,7 @@ fn get_audio_stream( ), _ => panic!("apu: unsupported audio sample format (supported options: F32, U16, I16)"), } - .ok()?; + .ok()?; Some((stream, sample_rate)) } @@ -111,4 +109,4 @@ fn write_audio_data_to_buffer>( for (i, v) in buffer.drain(..length).enumerate() { output[i] = T::from_sample(v); } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index cf3049b..0f586be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,12 +8,12 @@ use crate::hardware::machine::Machine; use crate::hardware::screen::{DEFAULT_PIXEL_SIZE, HEIGHT, WIDTH}; use crate::user_input::UserInput; +mod bios; +pub(crate) mod data_input_stream; mod gui; mod hardware; -pub(crate) mod data_input_stream; mod menu; mod user_input; -mod bios; pub(crate) type int = i32; @@ -22,10 +22,17 @@ fn main() { let (image_data_sender, image_data_receiver) = channel::>(); let (user_input_sender, user_input_receiver) = channel::(); // let machine = Machine::new(image_data_sender, user_input_receiver); - thread::spawn(move|| { + thread::spawn(move || { let mut machine = Machine::new(image_data_sender, user_input_receiver); machine.run_loop() }); - let window = Window::new_centered("Maurice", (DEFAULT_PIXEL_SIZE as u32 * WIDTH as u32, DEFAULT_PIXEL_SIZE as u32 * HEIGHT as u32)).unwrap(); + let window = Window::new_centered( + "Maurice", + ( + DEFAULT_PIXEL_SIZE as u32 * WIDTH as u32, + DEFAULT_PIXEL_SIZE as u32 * HEIGHT as u32, + ), + ) + .unwrap(); window.run_loop(Gui::new(user_input_sender, image_data_receiver)); } diff --git a/src/menu/mod.rs b/src/menu/mod.rs index e69de29..8b13789 100644 --- a/src/menu/mod.rs +++ b/src/menu/mod.rs @@ -0,0 +1 @@ + diff --git a/src/user_input.rs b/src/user_input.rs index dd21a18..ca03dba 100644 --- a/src/user_input.rs +++ b/src/user_input.rs @@ -11,4 +11,4 @@ pub(crate) enum UserInput { KeyDown(CustomVirtualKeyCode), KeyUp(CustomVirtualKeyCode), KeyboardModifierChanged(ModifiersState), -} \ No newline at end of file +}