Skip to content

Commit

Permalink
Fix compilation errors and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
alloncm committed May 3, 2023
1 parent 40b0260 commit ecfc383
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
build-and-test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: armv7a-none-eabihf
components: rust-src
- name: Build baremetal
run: cargo +nightly build -Z build-std=core --verbose --package baremetal
- name: Build gb
run: cargo build --verbose --package gb
- name: Run tests
run: cargo test --verbose --workspace --exclude bcm_host
run: cargo test --verbose --package lib_gb
6 changes: 3 additions & 3 deletions baremetal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::panic::PanicInfo;

use peripherals::*;

use lib_gb::{ppu::gfx_device::GfxDevice, keypad::{joypad_provider::JoypadProvider}, apu::audio_device::AudioDevice, machine::{gameboy::GameBoy, mbc_initializer::initialize_mbc}};
use lib_gb::{ppu::gfx_device::GfxDevice, keypad::{joypad_provider::JoypadProvider}, apu::audio_device::AudioDevice, machine::{gameboy::GameBoy, mbc_initializer::initialize_mbc}, mmu::external_memory_bus::Bootrom};

struct BlankGfxDevice;
impl GfxDevice for BlankGfxDevice {
Expand Down Expand Up @@ -41,13 +41,13 @@ pub extern "C" fn _start_rust()->!{
log::info!("running at exec mode: {:#X}", boot::get_cpu_execution_mode());

let mut gpio = unsafe{PERIPHERALS.get_gpio()};
let mbc = initialize_mbc(ROM, None);
let mbc = initialize_mbc(ROM, None, None);
// let joypad_provider = GpioJoypadProvider::new(gpio);
let joypad_provider = BlankJoypadProvider;

let gfx = drivers::Ili9341GfxDevice::new(&mut gpio, unsafe{PERIPHERALS.take_timer()}, RESET_PIN_BCM, LED_PIN_BCM, 1, 0);
log::info!("Init joypad");
let mut gameboy = GameBoy::new(mbc, joypad_provider, BlankAudioDevice, gfx);
let mut gameboy = GameBoy::new(mbc, joypad_provider, BlankAudioDevice, gfx, Bootrom::None, None);
log::info!("Initialized gameboy!");
loop{
gameboy.cycle_frame();
Expand Down
10 changes: 8 additions & 2 deletions image_inter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub unsafe fn scale_nearest<const INPUT_WIDTH:usize,const INPUT_HEIGHT:usize, co
for x in 0..OUTPUT_WIDTH{
// This does not compile on no_std
// maybe round like this -> (x + 0.5) as int
let proj_x = (x as f32 / scale_x).round() as usize;
let proj_y = (y as f32 / scale_y).round() as usize;
let proj_x = round_f32(x as f32 / scale_x) as usize;
let proj_y = round_f32(y as f32 / scale_y) as usize;
let pixel = *input_buffer.add((proj_y * INPUT_WIDTH) + proj_x);
let output_index = (y * OUTPUT_WIDTH) + x;
*output_buffer.add(output_index * 2) = (pixel >> 8) as u8;
Expand All @@ -77,6 +77,12 @@ pub unsafe fn scale_nearest<const INPUT_WIDTH:usize,const INPUT_HEIGHT:usize, co
}
}

#[inline]
fn round_f32(mut f:f32)->u32{
f += 0.5;
return f as u32;
}

pub unsafe fn scale_biliniear_c<const INPUT_WIDTH:usize,const INPUT_HEIGHT:usize, const OUTPUT_WIDTH:usize, const OUTPUT_HEIGHT:usize>(input_buffer: *const u16, output_buffer: *mut u8){
scale_buffer(
input_buffer,
Expand Down
3 changes: 1 addition & 2 deletions lib_gb/src/machine/gameboy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub struct GameBoy<'a, JP: JoypadProvider, AD:AudioDevice, GFX:GfxDevice> {

impl<'a, JP:JoypadProvider, AD:AudioDevice, GFX:GfxDevice> GameBoy<'a, JP, AD, GFX>{
pub fn new(mbc:&'a mut dyn Mbc, joypad_provider:JP, audio_device:AD, gfx_device:GFX, boot_rom:Bootrom, mode:Option<Mode>)->GameBoy<JP, AD, GFX>{
let default_mode = mbc.get_compatibility_mode().into();
let mode = mode.unwrap_or(default_mode);
let mode = mode.unwrap_or(mbc.get_compatibility_mode().into());

let mut cpu = GbCpu::default();
if boot_rom == Bootrom::None{
Expand Down
2 changes: 1 addition & 1 deletion lib_gb/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn run_integration_test(program:Vec<u8>, boot_rom:Bootrom, frames_to_execute:u32
let mut last_hash:u64 = 0;
let mut found = false;
let mut gameboy = GameBoy::new(
&mut mbc,
mbc,
StubJoypadProvider{},
StubAudioDevice{},
CheckHashGfxDevice{hash:expected_hash,last_hash_p:&mut last_hash, found_p:&mut found},
Expand Down
6 changes: 3 additions & 3 deletions lib_gb/tests/vram_dma_controller_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Mbc for EmptyMbc{
fn vram_dma_transfer_test(){
let mut controller = VramDmaController::new();
let mut ppu = GbPpu::new(StubGfxDevice, lib_gb::machine::Mode::CGB);
let mut mbc:Box<dyn Mbc> = Box::new(EmptyMbc{memory:[22;MEMORY_SIZE]});
let mut mbc = EmptyMbc{memory:[22;MEMORY_SIZE]};
let mut memory = ExternalMemoryBus::new(&mut mbc, lib_gb::mmu::external_memory_bus::Bootrom::None);
let dma_len_reg = 100;

Expand All @@ -42,10 +42,10 @@ fn vram_dma_transfer_test(){
}

#[test]
fn vram_hblank_dma_transfer_test(){
fn vram_hblank_dma_transfer_test<'a>(){
let mut controller = VramDmaController::new();
let mut ppu = GbPpu::new(StubGfxDevice, lib_gb::machine::Mode::CGB);
let mut mbc:Box<dyn Mbc> = Box::new(EmptyMbc{memory:[22;MEMORY_SIZE]});
let mut mbc = EmptyMbc{memory:[22;MEMORY_SIZE]};
let mut memory = ExternalMemoryBus::new(&mut mbc, lib_gb::mmu::external_memory_bus::Bootrom::None);
let dma_len_reg = 100;

Expand Down

0 comments on commit ecfc383

Please sign in to comment.