PR003: implement audio status-first returns for play operations
This commit is contained in:
@@ -7,7 +7,9 @@ use prometeu_hal::sprite::Sprite;
|
||||
use prometeu_hal::syscalls::Syscall;
|
||||
use prometeu_hal::tile::Tile;
|
||||
use prometeu_hal::vm_fault::VmFault;
|
||||
use prometeu_hal::{HostContext, HostReturn, NativeInterface, SyscallId, expect_bool, expect_int};
|
||||
use prometeu_hal::{
|
||||
AudioOpStatus, HostContext, HostReturn, NativeInterface, SyscallId, expect_bool, expect_int,
|
||||
};
|
||||
|
||||
impl VirtualMachineRuntime {
|
||||
const GFX_STATUS_OK: i64 = 0;
|
||||
@@ -201,22 +203,36 @@ impl NativeInterface for VirtualMachineRuntime {
|
||||
Ok(())
|
||||
}
|
||||
Syscall::AudioPlaySample => {
|
||||
let sample_id = expect_int(args, 0)? as u32;
|
||||
let voice_id = expect_int(args, 1)? as usize;
|
||||
let volume = expect_int(args, 2)? as u8;
|
||||
let pan = expect_int(args, 3)? as u8;
|
||||
let sample_id_raw = expect_int(args, 0)?;
|
||||
let voice_id_raw = expect_int(args, 1)?;
|
||||
let volume_raw = expect_int(args, 2)?;
|
||||
let pan_raw = expect_int(args, 3)?;
|
||||
let pitch = expect_number(args, 4, "pitch")?;
|
||||
|
||||
hw.audio_mut().play(
|
||||
if sample_id_raw < 0
|
||||
|| sample_id_raw > u16::MAX as i64
|
||||
|| voice_id_raw < 0
|
||||
|| voice_id_raw >= 16
|
||||
|| !(0..=255).contains(&volume_raw)
|
||||
|| !(0..=255).contains(&pan_raw)
|
||||
|| !pitch.is_finite()
|
||||
|| pitch <= 0.0
|
||||
{
|
||||
ret.push_int(AudioOpStatus::ArgRangeInvalid as i64);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let status = hw.audio_mut().play(
|
||||
0,
|
||||
sample_id as u16,
|
||||
voice_id,
|
||||
volume,
|
||||
pan,
|
||||
sample_id_raw as u16,
|
||||
voice_id_raw as usize,
|
||||
volume_raw as u8,
|
||||
pan_raw as u8,
|
||||
pitch,
|
||||
0,
|
||||
prometeu_hal::LoopMode::Off,
|
||||
);
|
||||
ret.push_int(status as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::AudioPlay => {
|
||||
@@ -227,19 +243,44 @@ impl NativeInterface for VirtualMachineRuntime {
|
||||
Value::String(s) => s.clone(),
|
||||
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string asset_name".into())),
|
||||
};
|
||||
let sample_id = expect_int(args, 1)? as u16;
|
||||
let voice_id = expect_int(args, 2)? as usize;
|
||||
let volume = expect_int(args, 3)? as u8;
|
||||
let pan = expect_int(args, 4)? as u8;
|
||||
let sample_id_raw = expect_int(args, 1)?;
|
||||
let voice_id_raw = expect_int(args, 2)?;
|
||||
let volume_raw = expect_int(args, 3)?;
|
||||
let pan_raw = expect_int(args, 4)?;
|
||||
let pitch = expect_number(args, 5, "pitch")?;
|
||||
let loop_mode = match expect_int(args, 6)? {
|
||||
0 => prometeu_hal::LoopMode::Off,
|
||||
_ => prometeu_hal::LoopMode::On,
|
||||
};
|
||||
|
||||
let bank_id =
|
||||
hw.assets().find_slot_by_name(&asset_name, BankType::SOUNDS).unwrap_or(0);
|
||||
hw.audio_mut().play(bank_id, sample_id, voice_id, volume, pan, pitch, 0, loop_mode);
|
||||
if sample_id_raw < 0
|
||||
|| sample_id_raw > u16::MAX as i64
|
||||
|| voice_id_raw < 0
|
||||
|| voice_id_raw >= 16
|
||||
|| !(0..=255).contains(&volume_raw)
|
||||
|| !(0..=255).contains(&pan_raw)
|
||||
|| !pitch.is_finite()
|
||||
|| pitch <= 0.0
|
||||
{
|
||||
ret.push_int(AudioOpStatus::ArgRangeInvalid as i64);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let Some(bank_id) = hw.assets().find_slot_by_name(&asset_name, BankType::SOUNDS) else {
|
||||
ret.push_int(AudioOpStatus::AssetNotFound as i64);
|
||||
return Ok(());
|
||||
};
|
||||
let status = hw.audio_mut().play(
|
||||
bank_id,
|
||||
sample_id_raw as u16,
|
||||
voice_id_raw as usize,
|
||||
volume_raw as u8,
|
||||
pan_raw as u8,
|
||||
pitch,
|
||||
0,
|
||||
loop_mode,
|
||||
);
|
||||
ret.push_int(status as i64);
|
||||
Ok(())
|
||||
}
|
||||
Syscall::FsOpen => {
|
||||
|
||||
Reference in New Issue
Block a user