Comments (1)
Others' code:
let mut begin_cpu = time::PreciseTime::now();
let mut begin_display = begin_cpu.clone();
'running: loop {
let now = time::PreciseTime::now();
let delta_cpu = begin_cpu.to(now);
if delta_cpu.num_milliseconds() >= (1000.0 / CPU_FREQUENCY).round() as i64 {
begin_cpu = now.clone();
if chip.running {
chip.cycle();
}
}
let delta_display = begin_display.to(now);
if delta_display.num_milliseconds() >= (1000.0 / DRAW_FREQUENCY).round() as i64 {
begin_display = now.clone();
display.update(&mut chip);
if display.should_close() {
break 'running;
}
display.draw(&chip);
}
}
// Delay & sound timers are decreased by 1 at a rate of 60Hz
let now = time::precise_time_ns();
if now - self.clock > 16666000 {
self.clock = now;
if self.delay_timer != 0 {
self.delay_timer -= 1;
}
if self.sound_timer != 0 {
self.sound_timer -= 1;
}
}
extern crate time;
const BEEP_SAMPLE_RATE: u32 = 44100;
const BEEP_FREQUENCY: f32 = 1000.0;
fn generate_beep() -> Vec<i16> {
const SAMPLES: usize = BEEP_SAMPLE_RATE as usize / 2;
let mut data: Vec<i16> = Vec::new();
data.resize(SAMPLES, 0);
// generate half a second of a sine wave
for i in 0..SAMPLES {
let t = i as f32 / BEEP_SAMPLE_RATE as f32;
data[i] = ((BEEP_FREQUENCY * t * 2.0 * 3.1415).sin() * 32767.0).round() as i16;
}
data
}
from deca.
Related Issues (15)
- Callbacks HOT 1
- deca panics on stack overflow HOT 1
- Separate opcodes and instructions?
- Control flow enum
- Support Octo symbol file HOT 1
- Support breakpoints
- Halt/error messages HOT 1
- Change from using Quirks to the new octopt crate HOT 1
- Derive Default for modules?
- Add crate documentation
- Add XO-CHIP audio
- Add XO-CHIP planes
- Set up CI
- Add tick counter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deca.