Browse Source

Redox support

pull/16/head^2
Jeremy Soller 4 years ago
parent
commit
17e375fafa
5 changed files with 340 additions and 21 deletions
  1. +1
    -0
      .gitignore
  2. +279
    -0
      Cargo.lock
  3. +3
    -1
      Cargo.toml
  4. +6
    -6
      src/c64/mod.rs
  5. +51
    -14
      src/c64/sid.rs

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
/target/

+ 279
- 0
Cargo.lock View File

@ -0,0 +1,279 @@
[root]
name = "rust64"
version = "0.6.0"
dependencies = [
"minifb 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "conv"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "custom_derive"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gcc"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gdi32-sys"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kernel32-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "magenta"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "magenta-sys"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "minifb"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kernel32-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"orbclient 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-dl 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-iter"
version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "orbclient"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "pkg-config"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sdl2"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sdl2"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"sdl2-sys 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sdl2-sys"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sdl2-sys"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "user32-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "x11-dl"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72cd7314bd4ee024071241147222c706e80385a1605ac7d4cd2fcc339da2ae46"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299"
"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "65256ec4dc2592e6f05bfc1ca3b956a4e0698aa90b1dff1f5687d55a5a3fd59a"
"checksum kernel32-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e014dab1082fd9d80ea1fa6fcb261b47ed3eb511612a14198bb507701add083e"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9e5e58fa1a4c3b915a561a78a22ee0cac6ab97dca2504428bc1cb074375f8d5"
"checksum libc 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "d1419b2939a0bc44b77feb34661583c7546b532b192feab36249ab584b86856c"
"checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527"
"checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699"
"checksum minifb 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "de031ff6a2afd2b59a437fcb0d910b7e04a5b7526e969a8e703bba2907f81379"
"checksum num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "a311b77ebdc5dd4cf6449d81e4135d9f0e3b153839ac90e648a8ef538f923525"
"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba"
"checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01"
"checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0"
"checksum orbclient 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "6e5d8d9900998fb4b9394e27058aa22a6d3509fb67dd860f74ba0507d4406943"
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
"checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf"
"checksum redox_syscall 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "8dde11f18c108289bef24469638a04dce49da56084f2d50618b226e47eb04509"
"checksum sdl2 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e15a33054d1b982ca8eec453666757046af6f95e7dd09e2747d67ab0aeca1bd"
"checksum sdl2 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "63066036ad426250ac56d23e38fd05063b38b661556acd596f4046cc92d98415"
"checksum sdl2-sys 0.25.0 (registry+https://github.com/rust-lang/crates.io-index)" = "79698e1a87967badc92c3d559f5a73157a05a644f85cdada02de91d4639edc00"
"checksum sdl2-sys 0.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b48638b7882759f3421038fcd38ad5f1ea19b119d80c99f1601933004629e34d"
"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520"
"checksum user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6717129de5ac253f5642fc78a51d0c7de6f9f53d617fc94e9bae7f6e71cf5504"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
"checksum x11-dl 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "326c500cdc166fd7c70dd8c8a829cd5c0ce7be5a5d98c25817de2b9bdc67faf8"

+ 3
- 1
Cargo.toml View File

@ -4,7 +4,9 @@ version = "0.6.0"
authors = [ "Krzysztof Kondrak <krzysztof.kondrak@gmail.com>" ]
[dependencies]
sdl2 = "0.15.0"
minifb = "0.10"
rand = "0.3.14"
time = "0.1.34"
[target.'cfg(not(target_os = "redox"))'.dependencies]
sdl2 = "0.25.0"

+ 6
- 6
src/c64/mod.rs View File

@ -76,14 +76,14 @@ impl C64 {
c64.vic.borrow_mut().set_references(memory.clone(), cpu.clone());
c64.sid.borrow_mut().set_references(memory.clone());
c64.cpu.borrow_mut().set_references(memory.clone(), vic.clone(), cia1.clone(), cia2.clone(), sid.clone());
drop(memory);
drop(cia1);
drop(cia2);
drop(vic);
drop(cpu);
drop(sid);
c64
}
@ -95,17 +95,17 @@ impl C64 {
self.cia2.borrow_mut().reset();
self.sid.borrow_mut().reset();
}
pub fn run(&mut self) {
// attempt to load a program supplied with command line
if !self.boot_complete {
// $A480 is the BASIC warm start sequence - safe to assume we can load a cmdline program now
self.boot_complete = self.cpu.borrow_mut().pc == 0xA480;
if self.boot_complete {
let prg_file = &self.file_to_load.to_owned()[..];
if prg_file.len() > 0 {
self.boot_complete = true; self.load_prg(prg_file);
}
@ -124,7 +124,7 @@ impl C64 {
self.cia2.borrow_mut().process_irq();
self.cia1.borrow_mut().update();
self.cia2.borrow_mut().update();
self.cpu.borrow_mut().update(self.cycle_count);
// update the debugger window if it exists


+ 51
- 14
src/c64/sid.rs View File

@ -1,7 +1,9 @@
// SID chip
extern crate rand;
#[cfg(not(target_os = "redox"))]
extern crate sdl2;
#[cfg(not(target_os = "redox"))]
use self::sdl2::audio::{ AudioCallback, AudioSpecDesired };
use c64::memory;
use c64::sid_tables::*;
@ -126,9 +128,11 @@ impl SIDVoice {
// the SID chip with associated SDL2 audio device
pub struct SID {
mem_ref: Option<memory::MemShared>,
#[cfg(not(target_os = "redox"))]
audio_device: sdl2::audio::AudioDevice<SIDAudioDevice>,
}
#[cfg(not(target_os = "redox"))]
impl SID {
pub fn new_shared() -> SIDShared {
let sdl_context = sdl2::init().unwrap();
@ -139,7 +143,7 @@ impl SID {
channels: Some(1), // mono
samples: Some(512), // default sample size
};
Rc::new(RefCell::new(SID {
mem_ref: None,
audio_device: audio_subsystem.open_playback(None, &desired_spec, |spec| {
@ -204,6 +208,38 @@ impl SID {
}
#[cfg(target_os = "redox")]
impl SID {
pub fn new_shared() -> SIDShared {
Rc::new(RefCell::new(SID {
mem_ref: None,
}))
}
pub fn set_references(&mut self, memref: memory::MemShared) {
self.mem_ref = Some(memref);
}
pub fn reset(&mut self) {}
pub fn update(&mut self) {}
pub fn read_register(&mut self, addr: u16) -> u8 {
0
}
pub fn write_register(&mut self, addr: u16, value: u8) {}
pub fn update_audio(&mut self) {}
}
// SDL2 audio device along with necessary SID parameters
// this is where the actual SID calculations are being performed
struct SIDAudioDevice {
@ -223,7 +259,7 @@ struct SIDAudioDevice {
xn2: f32,
yn1: f32,
yn2: f32,
voices: Vec<SIDVoice>,
sample_buffer: [u8; NUM_SAMPLES],
sample_idx: usize
@ -250,7 +286,7 @@ impl SIDAudioDevice {
sample_buffer: [0; NUM_SAMPLES],
sample_idx: 0
};
// calculate triangle table values
unsafe {
for i in 0..0x1000 {
@ -266,7 +302,7 @@ impl SIDAudioDevice {
sid_audio_device.voices[1].modulatee = 2;
sid_audio_device.voices[2].modulator = 1;
sid_audio_device.voices[2].modulatee = 0;
sid_audio_device
}
@ -328,7 +364,7 @@ impl SIDAudioDevice {
}
}
}
pub fn write_register(&mut self, addr: u16, value: u8) {
self.last_sid_byte = value;
@ -419,7 +455,7 @@ impl SIDAudioDevice {
self.voices[0].filter = (value & 1) != 0;
self.voices[1].filter = (value & 2) != 0;
self.voices[2].filter = (value & 4) != 0;
if self.filter_resonance != (value >> 4) {
self.filter_resonance = value >> 4;
self.calculate_filter();
@ -476,7 +512,7 @@ impl SIDAudioDevice {
let f = self.filter_freq as f32;
let resonance: f32;
let mut arg: f32;
match self.filter_type {
FilterType::None => {
self.d1 = 0.0;
@ -558,12 +594,12 @@ impl SIDAudioDevice {
8 => WaveForm::Noise,
_ => panic!("Impossible waveform value!"),
};
let gate_on = (value & 1) != 0;
let sync_on = (value & 2) != 0;
let ring_on = (value & 4) != 0;
let test_on = (value & 8) != 0;
if gate_on != self.voices[v_num].gate {
if gate_on {
self.voices[v_num].state = VoiceState::Attack;
@ -584,11 +620,12 @@ impl SIDAudioDevice {
if test_on {
self.voices[v_num].wf_cnt = 0;
}
}
}
}
}
// SDL2 audio callback implementation - this is where the samples are being converted to output sound
#[cfg(not(target_os = "redox"))]
impl AudioCallback for SIDAudioDevice {
type Channel = i16;
@ -600,14 +637,14 @@ impl AudioCallback for SIDAudioDevice {
let g2 = self.g2;
let mut sample_count = (self.sample_idx + NUM_SAMPLES/2) << 16;
for x in out.iter_mut() {
let master_volume: u8 = self.sample_buffer[(sample_count >> 16) % NUM_SAMPLES];
sample_count += ((50 * NUM_SAMPLES/2) << 16) / SAMPLE_FREQ as usize;
let mut total_output: i32 = (SAMPLE_TABLE[master_volume as usize] as i32) << 8;
let mut total_output_filter: i32 = 0;
for i in 0..3 {
let envelope: f32;
@ -646,11 +683,11 @@ impl AudioCallback for SIDAudioDevice {
envelope = ((self.voices[i].level as f32) * master_volume as f32) / (0xFFFFFF * 0xF) as f32;
let modulatee = self.voices[i].modulatee;
let modulator = self.voices[i].modulator;
if self.voices[i].mute {
continue;
}
if !self.voices[i].test {
self.voices[i].wf_cnt += self.voices[i].wf_add;
}


Loading…
Cancel
Save