Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update for language changes and go runtimeless!

  • Loading branch information...
commit 8b6fcfab9646915edc58d7db2d621e88d5e2763b 1 parent 9cd05be
Patrick Walton authored
16 apu.rs
View
@@ -394,7 +394,7 @@ impl Apu {
fn update_status(&mut self, val: u8) {
self.regs.status = ApuStatus(val);
- for uint::range(0, 2) |i| {
+ for i in range(0, 2) {
if !self.regs.status.pulse_enabled(i as u8) {
self.regs.pulses[i].envelope.length.remaining = 0;
}
@@ -461,7 +461,7 @@ impl Apu {
// 120 Hz operations: length counter and sweep.
if self.ticks % 2 == 0 {
// TODO: Remember that triangle wave has a different length disable bit.
- for uint::range(0, 2) |i| {
+ for i in range(0, 2) {
let pulse = &mut self.regs.pulses[i];
// Length counter.
@@ -520,7 +520,7 @@ impl Apu {
return Some(buffer);
}
- for buffer.mut_iter().advance |dest| {
+ for dest in buffer.mut_iter() {
*dest = 0;
}
None
@@ -543,7 +543,7 @@ impl Apu {
let mut waveform_index = pulse.waveform_index;
let mut wavelen_count = pulse.timer.wavelen_count;
- for buffer.mut_iter().advance |dest| {
+ for dest in buffer.mut_iter() {
wavelen_count += 1;
if wavelen_count >= wavelen {
wavelen_count = 0;
@@ -571,7 +571,7 @@ impl Apu {
let mut waveform_index = triangle.waveform_index;
let mut wavelen_count = triangle.timer.wavelen_count;
- for buffer.mut_iter().advance |dest| {
+ for dest in buffer.mut_iter() {
wavelen_count += 1;
if wavelen_count >= wavelen {
wavelen_count = 0;
@@ -602,7 +602,7 @@ impl Apu {
let mut rng = noise.rng;
let mut on = 1;
- for buffer.mut_iter().advance |dest| {
+ for dest in buffer.mut_iter() {
timer_count += 1;
if timer_count >= timer {
timer_count = 0;
@@ -629,9 +629,9 @@ impl Apu {
// First, mix all sample buffers into the first one.
//
// FIXME: This should not be a linear mix, for accuracy.
- for uint::range(0, self.sample_buffers[0].samples.len()) |i| {
+ for i in range(0, self.sample_buffers[0].samples.len()) {
let mut val = 0;
- for uint::range(0, 5) |j| {
+ for j in range(0, 5) {
val += self.sample_buffers[j].samples[i] as i32;
}
2  audio.rs
View
@@ -27,7 +27,7 @@ fn audio_callback(samples: &mut [u8], output_buffer: &mut OutputBuffer) {
let play_offset = output_buffer.play_offset;
let output_buffer_len = output_buffer.samples.len();
- for uint::range(0, samples.len()) |i| {
+ for i in range(0, samples.len()) {
if i + play_offset >= output_buffer_len {
break;
}
2  cpu.rs
View
@@ -363,7 +363,7 @@ impl<M:Mem> Cpu<M> {
// Performs DMA to the OAMDATA ($2004) register.
fn dma(&mut self, hi_addr: u8) {
- for range(hi_addr as uint << 8, (hi_addr + 1) as uint << 8) |addr| {
+ for addr in range(hi_addr as uint << 8, (hi_addr + 1) as uint << 8) {
let val = self.loadb(addr as u16);
self.storeb(0x2004, val);
16 gfx.rs
View
@@ -162,11 +162,11 @@ fn draw_glyph(pixels: &mut [u8],
White => 0xff,
Black => 0x00,
};
- for int::range(0, 10) |y_index| {
+ for y_index in range(0, 10) {
let row = FONT_GLYPHS[glyph_index * 10 + y_index as uint];
- for int::range(0, 8) |x_index| {
+ for x_index in range(0, 8) {
if ((row >> (7 - x_index)) & 1) != 0 {
- for int::range(0, 3) |channel| {
+ for channel in range(0, 3) {
let mut index = (y + y_index) * (surface_width as int) * 3 + (x + x_index) * 3;
index += channel;
@@ -180,7 +180,7 @@ fn draw_glyph(pixels: &mut [u8],
}
pub fn draw_text(pixels: &mut [u8], surface_width: uint, mut x: int, y: int, string: &str) {
- for uint::range(0, string.len()) |i| {
+ for i in range(0, string.len()) {
let glyph_index = (string[i] - 32) as uint;
if glyph_index < FONT_ADVANCES.len() {
draw_glyph(pixels, surface_width, x, y + 1, Black, glyph_index); // Shadow
@@ -276,8 +276,8 @@ macro_rules! scaler(
let mut src_y = 0;
while src_y < SCREEN_HEIGHT {
- let src_scanline_start = src_start.offset(src_y * SCREEN_WIDTH * 3);
- let src_scanline_end = src_scanline_start.offset(SCREEN_WIDTH * 3);
+ let src_scanline_start = src_start.offset((src_y * SCREEN_WIDTH * 3) as int);
+ let src_scanline_end = src_scanline_start.offset((SCREEN_WIDTH * 3) as int);
// Ugh, LLVM isn't inlining properly.
//
@@ -312,8 +312,8 @@ macro_rules! scaler(
impl Gfx {
pub fn new(scale: Scale) -> Gfx {
sdl::init([ InitVideo, InitAudio, InitTimer ]);
- let screen = video::set_video_mode(SCREEN_WIDTH * scale.factor() as int,
- SCREEN_HEIGHT * scale.factor() as int,
+ let screen = video::set_video_mode((SCREEN_WIDTH * scale.factor()) as int,
+ (SCREEN_HEIGHT * scale.factor()) as int,
32,
[ SWSurface ],
[]);
24 main.rs
View
@@ -17,6 +17,7 @@ use rom::Rom;
use util::{Fd, ForReading, ForWriting, Save, println};
use util;
+use std::libc::c_char;
use std::os;
use std::str;
@@ -52,26 +53,25 @@ fn usage() {
println(" -3 scale by 3x");
}
-fn parse_args() -> Option<Options> {
+fn parse_args(argc: u32, argv: **c_char) -> Option<Options> {
let mut options = Options { rom_path: ~"", scale: Scale1x };
- let args = os::args();
- for args.iter().enumerate().advance |(i, arg)| {
- if i == 0 {
- loop;
- }
+ for i in range(1, argc as int) {
+ let arg = unsafe {
+ str::raw::from_c_str(*argv.offset(i))
+ };
- if str::eq_slice(*arg, "-1") {
+ if "-1" == arg {
options.scale = Scale1x;
- } else if str::eq_slice(*arg, "-2") {
+ } else if "-2" == arg {
options.scale = Scale2x;
- } else if str::eq_slice(*arg, "-3") {
+ } else if "-3" == arg {
options.scale = Scale3x;
} else if arg[0] == ('-' as u8) {
usage();
return None;
} else {
- options.rom_path = arg.to_str();
+ options.rom_path = arg;
}
}
@@ -87,8 +87,8 @@ fn parse_args() -> Option<Options> {
// Entry point and main loop
//
-pub fn start() {
- let options = match parse_args() {
+pub fn start(argc: u32, argv: **c_char) {
+ let options = match parse_args(argc, argv) {
Some(options) => options,
None => return,
};
9 nes.rc
View
@@ -4,8 +4,12 @@
// Author: Patrick Walton
//
+#[no_main];
+
extern mod sdl;
+use std::libc::c_char;
+
// NB: This must be first to pick up the macro definitions. What a botch.
#[macro_escape]
pub mod util;
@@ -26,7 +30,8 @@ pub mod rom;
// C library support
pub mod speex;
-fn main() {
- sdl::start::start(main::start);
+#[no_mangle]
+pub extern fn SDL_main(argc: u32, argv: **c_char) {
+ main::start(argc, argv);
}
19 ppu.rs
View
@@ -10,7 +10,6 @@ use util::{Fd, Save, debug_assert};
use std::cast::transmute;
use std::libc::c_void;
-use std::uint::range;
//
// Constants
@@ -558,14 +557,13 @@ impl Ppu {
}
#[inline(always)]
- fn each_sprite(&mut self, f: &fn(&mut Ppu, &Sprite, u8) -> bool) -> bool {
- for range(0, 64) |i| {
+ fn each_sprite(&mut self, f: &fn(&mut Ppu, &Sprite, u8) -> bool) {
+ for i in range(0, 64) {
let sprite = self.make_sprite_info(i as u16);
if !f(self, &sprite, i as u8) {
- break
+ return
}
}
- true
}
//
@@ -639,7 +637,7 @@ impl Ppu {
x: u8,
background_opaque: bool)
-> Option<SpriteColor> {
- for visible_sprites.iter().advance |&visible_sprite_opt| {
+ for &visible_sprite_opt in visible_sprites.iter() {
match visible_sprite_opt {
None => return None,
Some(index) => {
@@ -693,15 +691,18 @@ impl Ppu {
fn compute_visible_sprites(&mut self) -> [Option<u8>, ..8] {
let mut count = 0;
let mut result = [None, ..8];
- for self.each_sprite |this, sprite, index| {
+ do self.each_sprite |this, sprite, index| {
if sprite.on_scanline(this, this.scanline as u8) {
if count < 8 {
result[count] = Some(index);
count += 1;
+ true
} else {
this.regs.status.set_sprite_overflow(true);
- return result;
+ false
}
+ } else {
+ true
}
}
result
@@ -714,7 +715,7 @@ impl Ppu {
let backdrop_color_index = self.vram.loadb(0x3f00) & 0x3f;
let backdrop_color = self.get_color(backdrop_color_index);
- for range(0, SCREEN_WIDTH) |x| {
+ for x in range(0, SCREEN_WIDTH) {
// FIXME: For performance, we shouldn't be recomputing the tile for every pixel.
let mut background_color = None;
if self.regs.mask.show_background() {
10 speex.rs
View
@@ -21,7 +21,7 @@ extern {
fn speex_resampler_destroy(st: *SpeexResamplerState);
fn speex_resampler_process_int(st: *SpeexResamplerState,
channel_index: u32,
- in: *i16,
+ input: *i16,
in_len: *mut u32,
out: *i16,
out_len: *mut u32)
@@ -56,16 +56,16 @@ impl Resampler {
}
}
- pub fn process(&self, channel_index: u32, in: &[i16], out: &mut [u8]) -> (u32, u32) {
+ pub fn process(&self, channel_index: u32, input: &[i16], out: &mut [u8]) -> (u32, u32) {
unsafe {
- assert!(in.len() <= 0xffffffff);
+ assert!(input.len() <= 0xffffffff);
assert!(out.len() / 2 <= 0xffffffff);
- let (in_len, out_len) = (in.len() as u32, out.len() as u32 / 2);
+ let (in_len, out_len) = (input.len() as u32, out.len() as u32 / 2);
let mut in_len = in_len;
let mut out_len = out_len;
let err = speex_resampler_process_int(self.speex_resampler,
channel_index,
- &in[0],
+ &input[0],
&mut in_len,
transmute(&out[0]),
&mut out_len);
7 util.rs
View
@@ -9,7 +9,6 @@ use std::libc::{O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY, SEEK_CUR, c_int, c_void, o
use std::libc::time_t;
use std::libc;
use std::ptr::null;
-use std::str;
use std::uint;
//
@@ -38,7 +37,7 @@ impl Fd {
ForReading => O_RDONLY,
ForWriting => O_WRONLY | O_CREAT | O_TRUNC
} as c_int;
- do str::as_c_str(path) |c_path| {
+ do path.as_c_str |c_path| {
Fd {
contents: libc::open(c_path, fd_mode, 493),
}
@@ -117,7 +116,7 @@ impl Save for u16 {
impl Save for u64 {
fn save(&mut self, fd: &Fd) {
let mut buf = [ 0, ..8 ];
- for uint::range(0, 8) |i| {
+ for i in range(0, 8) {
buf[i] = ((*self) >> (i * 8)) as u8;
}
fd.write(buf);
@@ -126,7 +125,7 @@ impl Save for u64 {
let mut buf = [ 0, ..8 ];
fd.read(buf);
*self = 0;
- for uint::range(0, 8) |i| {
+ for i in range(0, 8) {
*self = *self | (buf[i] as u64 << (i * 8));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.