summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 20e4e4e5a91952a75bffccf3045b6c0005808b69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#![feature(bigint_helper_methods)]
#![feature(seek_stream_len)]
#![feature(unchecked_shifts)]

mod debug;
mod devices;
mod emulators;
mod types;

pub use debug::*;
pub use devices::*;
pub use emulators::*;
pub use types::*;

use bedrock_core::*;
use log::*;
use phosphor::*;

use std::num::NonZeroU32;
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};

pub const BATCH_SIZE: usize = 1000;
pub const TICK_DURATION: Duration = Duration::from_nanos( 1_000_000_000/256 );
pub const MIN_FRAME_DURATION: Duration = Duration::from_millis( 10 );
pub const MAX_FRAME_DURATION: Duration = Duration::from_millis( 500 );
pub const DEFAULT_SCREEN_SIZE: ScreenDimensions = ScreenDimensions::new(800,600);
pub const DEFAULT_SCREEN_SCALE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(1) };

pub type ScreenPosition = geometry::Point<u16>;
pub type ScreenDimensions = geometry::Dimensions<u16>;


pub fn run_program(bytecode: &[u8], config: EmulatorConfig) {
    let mut args = switchboard::Switchboard::from_env();
    args.named("verbose").short('v');
    if args.get("verbose").as_bool() {
        log::set_log_level(log::LogLevel::Info);
    }

    match Phosphor::new() {
        Ok(phosphor) => {
            info!("Starting graphical emulator");
            let mut emulator = GraphicalEmulator::new(config, false);
            emulator.load_program(&bytecode);
            emulator.run(phosphor, true);
        }
        Err(err) => {
            eprintln!("EventLoopError: {err:?}");
            fatal!("Could not start graphical event loop");
        }
    }
}