fixes
Former-commit-id: bfa963ac13e76b7e3cf2eb2e23651eb3189d3cbb Former-commit-id: 6602c3b0a22327d5ceb85063c9934b3490e1da01
This commit is contained in:
parent
407818d32a
commit
0f64f07133
|
@ -76,10 +76,6 @@ impl IoDevices {
|
||||||
pub fn set_sysbus_ptr(&mut self, ptr: SysBusPtr) {
|
pub fn set_sysbus_ptr(&mut self, ptr: SysBusPtr) {
|
||||||
self.sysbus_ptr = ptr;
|
self.sysbus_ptr = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_key_state(&mut self, state: u16) {
|
|
||||||
self.keyinput = state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InterruptConnect for IoDevices {
|
impl InterruptConnect for IoDevices {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[derive(Debug, Primitive, PartialEq, Eq)]
|
#[derive(Debug, Primitive, PartialEq, Eq, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Keys {
|
pub enum Keys {
|
||||||
ButtonA = 0,
|
ButtonA = 0,
|
||||||
|
|
|
@ -18,7 +18,6 @@ use crate::audio::{self, connector::AudioJNIConnector, thread::AudioThreadComman
|
||||||
struct Hardware {
|
struct Hardware {
|
||||||
sample_rate: i32,
|
sample_rate: i32,
|
||||||
audio_producer: Option<Producer<i16>>,
|
audio_producer: Option<Producer<i16>>,
|
||||||
key_state: u16,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioInterface for Hardware {
|
impl AudioInterface for Hardware {
|
||||||
|
@ -192,9 +191,8 @@ impl EmulatorContext {
|
||||||
let hw = Rc::new(RefCell::new(Hardware {
|
let hw = Rc::new(RefCell::new(Hardware {
|
||||||
sample_rate: audio::util::get_sample_rate(env, audio_player),
|
sample_rate: audio::util::get_sample_rate(env, audio_player),
|
||||||
audio_producer: None,
|
audio_producer: None,
|
||||||
key_state: 0xffff,
|
|
||||||
}));
|
}));
|
||||||
let mut gba = GameBoyAdvance::new(bios, gamepak, hw.clone(), hw.clone());
|
let mut gba = GameBoyAdvance::new(bios, gamepak, hw.clone());
|
||||||
if skip_bios != 0 {
|
if skip_bios != 0 {
|
||||||
info!("skipping bios");
|
info!("skipping bios");
|
||||||
gba.skip_bios();
|
gba.skip_bios();
|
||||||
|
@ -242,9 +240,8 @@ impl EmulatorContext {
|
||||||
let hw = Rc::new(RefCell::new(Hardware {
|
let hw = Rc::new(RefCell::new(Hardware {
|
||||||
sample_rate: audio::util::get_sample_rate(env, audio_player),
|
sample_rate: audio::util::get_sample_rate(env, audio_player),
|
||||||
audio_producer: None,
|
audio_producer: None,
|
||||||
key_state: 0xffff,
|
|
||||||
}));
|
}));
|
||||||
let gba = GameBoyAdvance::from_saved_state(&savestate, bios, rom, hw.clone(), hw.clone())
|
let gba = GameBoyAdvance::from_saved_state(&savestate, bios, rom, hw.clone())
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
format!(
|
format!(
|
||||||
"failed to create GameBoyAdvance from saved savestate, error {:?}",
|
"failed to create GameBoyAdvance from saved savestate, error {:?}",
|
||||||
|
|
|
@ -11,10 +11,11 @@ use libretro_backend::{
|
||||||
use bit::BitIndex;
|
use bit::BitIndex;
|
||||||
use unsafe_unwrap::UnsafeUnwrap;
|
use unsafe_unwrap::UnsafeUnwrap;
|
||||||
|
|
||||||
use rustboyadvance_core::keypad::Keys as GbaButton;
|
use rustboyadvance_core::keypad::Keys as _GbaButton;
|
||||||
use rustboyadvance_core::prelude::*;
|
use rustboyadvance_core::prelude::*;
|
||||||
use rustboyadvance_utils::audio::AudioRingBuffer;
|
use rustboyadvance_utils::audio::AudioRingBuffer;
|
||||||
|
|
||||||
|
use std::ops::Deref;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -42,21 +43,33 @@ struct RustBoyAdvanceCore {
|
||||||
audio: Option<Rc<RefCell<AudioDevice>>>,
|
audio: Option<Rc<RefCell<AudioDevice>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_button_state(key_state: &mut u16, button: JoypadButton, is_pressed: bool) {
|
#[repr(transparent)]
|
||||||
let mapped_button = match button {
|
struct GbaButton(_GbaButton);
|
||||||
JoypadButton::A => GbaButton::ButtonA,
|
|
||||||
JoypadButton::B => GbaButton::ButtonB,
|
impl Deref for GbaButton {
|
||||||
JoypadButton::Start => GbaButton::Start,
|
type Target = _GbaButton;
|
||||||
JoypadButton::Select => GbaButton::Select,
|
fn deref(&self) -> &Self::Target {
|
||||||
JoypadButton::Left => GbaButton::Left,
|
return &self.0
|
||||||
JoypadButton::Up => GbaButton::Up,
|
}
|
||||||
JoypadButton::Right => GbaButton::Right,
|
}
|
||||||
JoypadButton::Down => GbaButton::Down,
|
|
||||||
JoypadButton::L1 => GbaButton::ButtonL,
|
impl From<JoypadButton> for GbaButton {
|
||||||
JoypadButton::R1 => GbaButton::ButtonR,
|
fn from(button: JoypadButton) -> Self {
|
||||||
_ => unreachable!(),
|
let mapped = match button {
|
||||||
|
JoypadButton::A => _GbaButton::ButtonA,
|
||||||
|
JoypadButton::B => _GbaButton::ButtonB,
|
||||||
|
JoypadButton::Start => _GbaButton::Start,
|
||||||
|
JoypadButton::Select => _GbaButton::Select,
|
||||||
|
JoypadButton::Left => _GbaButton::Left,
|
||||||
|
JoypadButton::Up => _GbaButton::Up,
|
||||||
|
JoypadButton::Right => _GbaButton::Right,
|
||||||
|
JoypadButton::Down => _GbaButton::Down,
|
||||||
|
JoypadButton::L1 => _GbaButton::ButtonL,
|
||||||
|
JoypadButton::R1 => _GbaButton::ButtonR,
|
||||||
|
_ => panic!("unimplemented button {:?}", button),
|
||||||
};
|
};
|
||||||
key_state.set_bit(mapped_button as usize, !is_pressed);
|
GbaButton(mapped)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl libretro_backend::Core for RustBoyAdvanceCore {
|
impl libretro_backend::Core for RustBoyAdvanceCore {
|
||||||
|
@ -125,17 +138,17 @@ impl libretro_backend::Core for RustBoyAdvanceCore {
|
||||||
let gba = unsafe { self.gba.as_mut().unsafe_unwrap() };
|
let gba = unsafe { self.gba.as_mut().unsafe_unwrap() };
|
||||||
let audio = unsafe { self.audio.as_mut().unsafe_unwrap() };
|
let audio = unsafe { self.audio.as_mut().unsafe_unwrap() };
|
||||||
|
|
||||||
let key_state = gba.borrow_mut().get_key_state_mut();
|
let key_state = gba.get_key_state_mut();
|
||||||
macro_rules! update_controllers {
|
macro_rules! update_controllers {
|
||||||
( $( $button:ident ),+ ) => (
|
( $( $button:ident ),+ ) => (
|
||||||
$(
|
$(
|
||||||
set_button_state(key_state, JoypadButton::$button, handle.is_joypad_button_pressed( joypad_port, JoypadButton::$button ) );
|
key_state.set_bit(*GbaButton::from(JoypadButton::$button) as usize, !handle.is_joypad_button_pressed( joypad_port, JoypadButton::$button ));
|
||||||
)+
|
)+
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
drop(key_state);
|
|
||||||
|
|
||||||
update_controllers!(A, B, Start, Select, Left, Up, Right, Down, L1, R1);
|
update_controllers!(A, B, Start, Select, Left, Up, Right, Down, L1, R1);
|
||||||
|
drop(key_state);
|
||||||
|
|
||||||
gba.frame();
|
gba.frame();
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ mod input;
|
||||||
mod video;
|
mod video;
|
||||||
|
|
||||||
use audio::{create_audio_player, create_dummy_player};
|
use audio::{create_audio_player, create_dummy_player};
|
||||||
use input;
|
|
||||||
use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH};
|
use video::{create_video_interface, SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||||
|
|
||||||
use rustboyadvance_core::cartridge::BackupType;
|
use rustboyadvance_core::cartridge::BackupType;
|
||||||
|
@ -189,7 +188,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
} else {
|
} else {
|
||||||
Rc::new(RefCell::new(create_audio_player(&sdl_context)))
|
Rc::new(RefCell::new(create_audio_player(&sdl_context)))
|
||||||
};
|
};
|
||||||
let input = Rc::new(RefCell::new(create_input()));
|
|
||||||
|
|
||||||
let mut savestate_path = get_savestate_path(&Path::new(&rom_path));
|
let mut savestate_path = get_savestate_path(&Path::new(&rom_path));
|
||||||
|
|
||||||
|
@ -212,7 +210,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
gamepak,
|
gamepak,
|
||||||
video.clone(),
|
video.clone(),
|
||||||
audio.clone(),
|
audio.clone(),
|
||||||
input.clone(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if skip_bios {
|
if skip_bios {
|
||||||
|
|
Reference in a new issue