Skip to content

Commit

Permalink
Merge pull request #10 from YushiOMOTE/actions
Browse files Browse the repository at this point in the history
Actions
  • Loading branch information
YushiOMOTE authored Dec 14, 2019
2 parents 9d706d2 + 3a277b6 commit 0c3d6e5
Show file tree
Hide file tree
Showing 18 changed files with 539 additions and 91 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Rust

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Prepare
run: sudo apt install libasound2-dev libxcursor-dev
- name: Build (stable)
run: cargo build --verbose
- name: Build examples (stable)
run: cargo build --verbose --examples
- name: Test (stable)
run: cargo test --verbose
- name: Install nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Build (nightly)
run: |
cd core
cargo build --verbose --features readme
- name: Build examples (nightly)
run: |
cd core
cargo build --verbose --examples --features readme
- name: Test (nightly)
run: |
cd core
cargo test --verbose --features readme
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# rGB
# rgy

Try emulating Game Boy in Rust
No-std cross-platform Rust GameBoy emulator library. Rust GameboY (RGY, or Real GaY).

[![Latest version](https://img.shields.io/crates/v/rgy.svg)](https://crates.io/crates/rgy)
[![Documentation](https://docs.rs/rgy/badge.svg)](https://docs.rs/rgy)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Actions Status](https://github.com/YushiOMOTE/rgy/workflows/Rust/badge.svg)](https://github.com/YushiOMOTE/rgy/actions)

![demo](https://raw.github.com/wiki/YushiOMOTE/gbr/media/demo.gif)
![screens](https://raw.github.com/wiki/YushiOMOTE/gbr/media/demo_screens.jpg)
2 changes: 2 additions & 0 deletions codegen/templates/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ fn op_{{i.code | hex}}(arg: u16, cpu: &mut Cpu, mmu: &mut Mmu) -> (usize, usize)
}
{% endfor %}

/// Return the mnemonic string for the given opcode.
pub fn mnem(code: u16) -> &'static str {
MNEMONICS.get(&code).unwrap_or(&"(unknown opcode)")
}

/// Decodes the opecode and actually executes one instruction.
pub fn decode(code: u16, arg: u16, cpu: &mut Cpu, mmu: &mut Mmu) -> (usize, usize) {
trace!("{:04x}: {:04x}: {}", cpu.get_pc(), code, mnem(code));

Expand Down
8 changes: 8 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ name = "rgy"
version = "0.1.0"
authors = ["Yushi Omote <yushiomote@gmail.com>"]
edition = "2018"
keywords = ["gameboy", "emulator"]
description = "No-std Rust GameBoy emulator library"
homepage = "https://github.com/yushiomote/rgy"
repository = "https://github.com/yushiomote/rgy"
documentation = "https://docs.rs/rgy"
license = "MIT"
readme = "README.md"

[dependencies]
lazy_static = { version = "1.2", features = ["spin_no_std"] }
Expand All @@ -22,3 +29,4 @@ core_affinity = "0.5"
[features]
default = []
color = []
readme = []
81 changes: 81 additions & 0 deletions core/examples/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use rgy::{Config, Key, Stream, VRAM_HEIGHT, VRAM_WIDTH};

struct Hardware {
display: Vec<Vec<u32>>,
}

impl Hardware {
fn new() -> Self {
// Create a frame buffer with the size VRAM_WIDTH * VRAM_HEIGHT.
let display = vec![vec![0u32; VRAM_HEIGHT]; VRAM_WIDTH];

Self { display }
}
}

impl rgy::Hardware for Hardware {
fn vram_update(&mut self, line: usize, buffer: &[u32]) {
// `line` corresponds to the y coordinate.
let y = line;

for (x, col) in buffer.iter().enumerate() {
self.display[x][y] = *col;
}
}

fn joypad_pressed(&mut self, key: Key) -> bool {
// Read a keyboard device and check if the `key` is pressed or not.
println!("Check if {:?} is pressed", key);
false
}

fn sound_play(&mut self, _stream: Box<dyn Stream>) {
// Play the wave provided `Stream`.
}

fn clock(&mut self) -> u64 {
// Return the epoch in microseconds.
let epoch = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Couldn't get epoch");
epoch.as_micros() as u64
}

fn send_byte(&mut self, _b: u8) {
// Send a byte to a serial port.
}

fn recv_byte(&mut self) -> Option<u8> {
// Try to read a byte from a serial port.
None
}

fn sched(&mut self) -> bool {
// `true` to continue, `false` to stop the emulator.
println!("It's running!");
true
}

fn load_ram(&mut self, size: usize) -> Vec<u8> {
// Return save data.
vec![0; size]
}

fn save_ram(&mut self, _ram: &[u8]) {
// Store save data.
}
}

fn main() {
// Create the default config.
let cfg = Config::new();

// Create the hardware instance.
let hw = Hardware::new();

// The content of a ROM file, which can be downloaded from the Internet.
let rom = vec![0u8; 1024];

// Run the emulator.
rgy::run(cfg, &rom, hw);
}
4 changes: 2 additions & 2 deletions core/examples/pc/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::sync::{
};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

use rgy::hardware::{self, Key, Stream, VRAM_HEIGHT, VRAM_WIDTH};
use rgy::{Key, Stream, VRAM_HEIGHT, VRAM_WIDTH};

#[derive(Clone)]
pub struct Hardware {
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Hardware {
}
}

impl hardware::Hardware for Hardware {
impl rgy::Hardware for Hardware {
fn vram_update(&mut self, line: usize, buf: &[u32]) {
let mut vram = self.vram.lock().unwrap();
for i in 0..buf.len() {
Expand Down
4 changes: 2 additions & 2 deletions core/examples/pc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ fn main() {
set_affinity();

if opt.debug {
rgy::run_debug(to_cfg(opt), rom, hw1, Debugger::new());
rgy::run_debug(to_cfg(opt), &rom, hw1, Debugger::new());
} else {
rgy::run(to_cfg(opt), rom, hw1);
rgy::run(to_cfg(opt), &rom, hw1);
}
});

Expand Down
1 change: 1 addition & 0 deletions core/src/cgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Cgb {
wram_bank: Vec<Vec<u8>>,
}

#[allow(unused)]
impl Cgb {
pub fn new() -> Self {
Self {
Expand Down
Loading

0 comments on commit 0c3d6e5

Please sign in to comment.