Skip to content

Commit

Permalink
Banked RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
breqdev committed Nov 22, 2023
1 parent e204a4b commit e18d3d6
Showing 1 changed file with 128 additions and 7 deletions.
135 changes: 128 additions & 7 deletions src/systems/aiie/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::{io::Write, sync::Arc};
use std::{cell::Cell, io::Write, rc::Rc, sync::Arc};

use crate::{
cpu::{MemoryIO, Mos6502},
keyboard::{KeyAdapter, SymbolAdapter},
memory::{
ActiveInterrupt, BlockMemory, BranchMemory, LoggingMemory, Memory, NullMemory, SystemInfo,
ActiveInterrupt, BankedMemory, BlockMemory, BranchMemory, LoggingMemory, Memory, NullMemory,
SystemInfo,
},
platform::{Color, PlatformProvider, WindowConfig},
systems::{aiie::keyboard::AppleIISymbolAdapter, System},
Expand All @@ -29,6 +30,7 @@ const CHAR_WIDTH: u32 = 7;

struct AiieSoftSwitches {
platform: Arc<dyn PlatformProvider>,
selectors: AiieBankSelectors,
previous_key: Option<u8>,

pub keypress_waiting: bool,
Expand All @@ -48,9 +50,10 @@ struct AiieSoftSwitches {
}

impl AiieSoftSwitches {
fn new(platform: Arc<dyn PlatformProvider>) -> Self {
fn new(platform: Arc<dyn PlatformProvider>, selectors: AiieBankSelectors) -> Self {
Self {
platform,
selectors,
previous_key: None,
keypress_waiting: false,
eighty_col_memory: false,
Expand Down Expand Up @@ -97,6 +100,14 @@ impl AiieSoftSwitches {

_ => todo!("unimplemented softswitch"),

Check warning on line 101 in src/systems/aiie/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/aiie/mod.rs#L101

Added line #L101 was not covered by tests
};

self.selectors.set(
self.eighty_col_memory,
self.read_aux_48k,
self.write_aux_48k,
self.text_page2,
self.hi_res,
);
}

Check warning on line 111 in src/systems/aiie/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/aiie/mod.rs#L104-L111

Added lines #L104 - L111 were not covered by tests

/// Read one of the "RD" locations.
Expand Down Expand Up @@ -209,6 +220,66 @@ impl Memory for AiieSoftSwitches {
/// Configuration for a Apple IIe system.
pub struct AiieSystemConfig {}

struct AiieBankSelectors {
zp_stack: Rc<Cell<(usize, usize)>>,
low_segment: Rc<Cell<(usize, usize)>>,
text_page_1: Rc<Cell<(usize, usize)>>,
text_page_2: Rc<Cell<(usize, usize)>>,
hires_page_1: Rc<Cell<(usize, usize)>>,
hires_page_2: Rc<Cell<(usize, usize)>>,
}

impl AiieBankSelectors {
fn new() -> AiieBankSelectors {
AiieBankSelectors {
zp_stack: Rc::new(Cell::new((0, 0))),
low_segment: Rc::new(Cell::new((0, 0))),
text_page_1: Rc::new(Cell::new((0, 0))),
text_page_2: Rc::new(Cell::new((0, 0))),
hires_page_1: Rc::new(Cell::new((0, 0))),
hires_page_2: Rc::new(Cell::new((0, 0))),
}
}

Check warning on line 242 in src/systems/aiie/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/aiie/mod.rs#L233-L242

Added lines #L233 - L242 were not covered by tests

fn set(
&mut self,
eighty_col_memory: bool,
read_aux_48k: bool,
write_aux_48k: bool,
text_page2: bool,
hi_res: bool,
) {
if !eighty_col_memory {
self.zp_stack.set((0, 0));

let selector_value = (read_aux_48k as usize, write_aux_48k as usize);
self.low_segment.set(selector_value);
self.text_page_1.set(selector_value);
self.text_page_2.set(selector_value);
self.hires_page_1.set(selector_value);
self.hires_page_2.set(selector_value);
} else {
self.zp_stack.set((0, 0));

if text_page2 {
self.text_page_1.set((1, 1));
} else {
self.text_page_1.set((0, 0));
}

Check warning on line 268 in src/systems/aiie/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/aiie/mod.rs#L244-L268

Added lines #L244 - L268 were not covered by tests

self.text_page_2.set((0, 0));

if hi_res && text_page2 {
self.hires_page_1.set((1, 1));
} else {
self.hires_page_1.set((0, 0));
}

Check warning on line 276 in src/systems/aiie/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/aiie/mod.rs#L270-L276

Added lines #L270 - L276 were not covered by tests

self.hires_page_2.set((0, 0));

Check warning on line 278 in src/systems/aiie/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/aiie/mod.rs#L278

Added line #L278 was not covered by tests
}
}

Check warning on line 280 in src/systems/aiie/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/aiie/mod.rs#L280

Added line #L280 was not covered by tests
}

/// A factory for creating a Commodore 64 system.
pub struct AiieSystemBuilder;

Expand All @@ -224,17 +295,67 @@ impl SystemBuilder<AiieSystem, AiieSystemRoms, AiieSystemConfig> for AiieSystemB
2.0,
));

let ram = BlockMemory::ram(0xC000);
let io = AiieSoftSwitches::new(platform);
let selectors = AiieBankSelectors::new();

let peripheral_card =

Check warning on line 300 in src/systems/aiie/mod.rs

View workflow job for this annotation

GitHub Actions / WASM Build, Docs Build, and Web Deploy

unused variable: `peripheral_card`
LoggingMemory::new(Box::new(NullMemory::new()), "Peripheral Card", 0xC100);
//let applesoft_interpreter = BlockMemory::from_file(0x2800, roms.applesoft);
//let monitor = BlockMemory::from_file(0x4000, roms.monitor);
let rom = BlockMemory::from_file(16128, roms.rom);

let memory = BranchMemory::new()
.map(0x0000, Box::new(ram))
.map(0x1000, Box::new(NullMemory::new()))
.map(
0x0000,
Box::new(
BankedMemory::new(selectors.zp_stack.clone())
.bank(Box::new(BlockMemory::ram(0x0200))) // Main memory
.bank(Box::new(BlockMemory::ram(0x0200))), // Aux memory
),
)
.map(
0x0200,
Box::new(
BankedMemory::new(selectors.low_segment.clone())
.bank(Box::new(BlockMemory::ram(0x0200))) // Main memory
.bank(Box::new(BlockMemory::ram(0x0200))), // Aux memory
),
)
.map(
0x0400,
Box::new(
BankedMemory::new(selectors.text_page_1.clone())
.bank(Box::new(BlockMemory::ram(0x0400))) // Text Page 1
.bank(Box::new(BlockMemory::ram(0x0400))), // Text Page 1X
),
)
.map(
0x0800,
Box::new(
BankedMemory::new(selectors.text_page_2.clone())
.bank(Box::new(BlockMemory::ram(0x1800))) // Text Page 2
.bank(Box::new(BlockMemory::ram(0x1800))), // Text Page 2X
),
)
.map(
0x2000,
Box::new(
BankedMemory::new(selectors.hires_page_1.clone())
.bank(Box::new(BlockMemory::ram(0x2000))) // HiRes Page 1
.bank(Box::new(BlockMemory::ram(0x2000))), // HiRes Page 1X
),
)
.map(
0x4000,
Box::new(
BankedMemory::new(selectors.hires_page_2.clone())
.bank(Box::new(BlockMemory::ram(0x8000))) // HiRes Page 1
.bank(Box::new(BlockMemory::ram(0x8000))), // HiRes Page 1X
),
);

let io = AiieSoftSwitches::new(platform, selectors);

let memory = memory
.map(
0xC000,
Box::new(io),
Expand Down

0 comments on commit e18d3d6

Please sign in to comment.