Browse Source

starting to work on loading programs to the system

master
Isabelle L. 5 years ago
parent
commit
86497070b3
6 changed files with 37 additions and 7 deletions
  1. +6
    -1
      Cargo.lock
  2. +2
    -2
      Cargo.toml
  3. +0
    -2
      ceres-asm/Cargo.toml
  4. +1
    -2
      ceres-sys/Cargo.toml
  5. +10
    -0
      ceres-sys/src/lib.rs
  6. +18
    -0
      ceres-sys/src/memory.rs

+ 6
- 1
Cargo.lock View File

@@ -72,7 +72,7 @@ version = "0.1.0"
dependencies = [
"ceres-asm 0.1.0",
"ceres-sys 0.1.0",
"offbrand 0.1.0",
"offbrand 0.1.0 (git+https://github.com/izzabelle/offbrand)",
"structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -88,6 +88,9 @@ dependencies = [
[[package]]
name = "ceres-sys"
version = "0.1.0"
dependencies = [
"thiserror 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "cfg-if"
@@ -427,6 +430,7 @@ dependencies = [
[[package]]
name = "offbrand"
version = "0.1.0"
source = "git+https://github.com/izzabelle/offbrand#e4ec4d2a8081595d6412acd60c2448d37a1614f4"
dependencies = [
"image 0.23.5 (registry+https://github.com/rust-lang/crates.io-index)",
"minifb 0.16.0 (git+https://github.com/emoon/rust_minifb)",
@@ -1065,6 +1069,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num-rational 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"
"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
"checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
"checksum offbrand 0.1.0 (git+https://github.com/izzabelle/offbrand)" = "<none>"
"checksum once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
"checksum orbclient 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b18f57ab94fbd058e30aa57f712ec423c0bb7403f8493a6c58eef0c36d9402"
"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"


+ 2
- 2
Cargo.toml View File

@@ -5,8 +5,8 @@ authors = ["Izzy <me@izzabelle.dev>"]
edition = "2018"

[dependencies]
#offbrand = { git = "https://github.com/izzabelle/offbrand" }
offbrand = { path = "../offbrand" }
offbrand = { git = "https://github.com/izzabelle/offbrand" }
#offbrand = { path = "../offbrand" }
structopt = "0.3.14"
ceres-sys = { path = "ceres-sys" }
ceres-asm = { path = "ceres-asm" }


+ 0
- 2
ceres-asm/Cargo.toml View File

@@ -4,8 +4,6 @@ version = "0.1.0"
authors = ["Isabelle L. <me@izzabelle.dev>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
logos = "0.11.4"
thiserror = "1.0.20"

+ 1
- 2
ceres-sys/Cargo.toml View File

@@ -4,6 +4,5 @@ version = "0.1.0"
authors = ["Isabelle L. <me@izzabelle.dev>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
thiserror = "1.0.20"

+ 10
- 0
ceres-sys/src/lib.rs View File

@@ -13,6 +13,16 @@ pub const SCREEN_HEIGHT: usize = 144;
/// ceres video memory buffer length
pub const VIDEO_MEMORY_LEN: usize = SCREEN_HEIGHT * SCREEN_WIDTH;

/// result type
pub type Result<T> = std::result::Result<T, CeresSystemError>;

/// error type
#[derive(Debug, thiserror::Error)]
pub enum CeresSystemError {
#[error(transparent)]
StdIo(#[from] std::io::Error),
}

/// the core system structure of ceres
pub struct System {
pub registers: Registers,


+ 18
- 0
ceres-sys/src/memory.rs View File

@@ -1,3 +1,6 @@
use crate::Result;
use std::{io::Read, path::PathBuf};

/// all the memory as one big fat fucking slice
pub struct Memory {
data: [u16; std::u16::MAX as usize],
@@ -8,6 +11,21 @@ impl Memory {
pub fn init() -> Memory {
Memory { data: [0x00; std::u16::MAX as usize] }
}

/// loads a program to the memory
pub fn load_program(&mut self, path: PathBuf) -> Result<()> {
// load bytes
let mut file = std::fs::File::open(path)?;
let mut raw_data: Vec<u8> = Vec::new();
file.read(&mut raw_data)?;

// construct words
(0..(raw_data.len() / 2)).for_each(|i| {
let bytes: [u8; 2] = [raw_data[i * 2], raw_data[i * 2 + 1]];
self.data[i] = u16::from_le_bytes(bytes);
});
Ok(())
}
}

impl std::ops::Index<u16> for Memory {


Loading…
Cancel
Save