Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Sep 2, 2024
2 parents 09375c9 + 1e849c3 commit e8523de
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 41 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

*

## [0.10.13] - 2024-09-02

### Changed

* Bumped EmuKit to improve Web runtime performance

## [0.10.12] - 2024-08-30

### Fixed
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "boytacean"
description = "A Game Boy emulator that is written in Rust."
version = "0.10.12"
version = "0.10.13"
authors = ["João Magalhães <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/joamag/boytacean"
Expand All @@ -25,9 +25,9 @@ cpulog = []
gen-mock = []

[dependencies]
boytacean-common = { path = "crates/common", version = "0.10.12" }
boytacean-encoding = { path = "crates/encoding", version = "0.10.12" }
boytacean-hashing = { path = "crates/hashing", version = "0.10.12" }
boytacean-common = { path = "crates/common", version = "0.10.13" }
boytacean-encoding = { path = "crates/encoding", version = "0.10.13" }
boytacean-hashing = { path = "crates/hashing", version = "0.10.13" }
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true }
pyo3 = { version = "0.20", optional = true }
Expand Down Expand Up @@ -67,7 +67,7 @@ members = [
"crates/encoding",
"crates/hashing"
]
package = { version = "0.10.12", authors = ["João Magalhães <[email protected]>"], edition = "2021" }
package = { version = "0.10.13", authors = ["João Magalhães <[email protected]>"], edition = "2021" }

[package.metadata.docs.rs]
features = ["wasm", "gen-mock"]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "boytacean-common"
description = "Commons library for Boytacen."
version = "0.10.12"
version = "0.10.13"
authors = ["João Magalhães <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
Expand Down
7 changes: 5 additions & 2 deletions crates/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum Error {
InvalidKey,
RomSize,
IncompatibleBootRom,
NotImplemented,
MissingOption(String),
IoError(String),
InvalidParameter(String),
Expand All @@ -33,7 +34,8 @@ impl Error {
Error::InvalidData => String::from("Invalid data format"),
Error::InvalidKey => String::from("Invalid key"),
Error::RomSize => String::from("Invalid ROM size"),
Error::IncompatibleBootRom => String::from("Incompatible Boot ROM"),
Error::IncompatibleBootRom => String::from("Incompatible boot ROM"),
Error::NotImplemented => String::from("Not implemented"),
Error::MissingOption(option) => format!("Missing option: {option}"),
Error::IoError(message) => format!("IO error: {message}"),
Error::InvalidParameter(message) => format!("Invalid parameter: {message}"),
Expand All @@ -48,7 +50,8 @@ impl error::Error for Error {
Error::InvalidData => "Invalid data format",
Error::InvalidKey => "Invalid key",
Error::RomSize => "Invalid ROM size",
Error::IncompatibleBootRom => "Incompatible Boot ROM",
Error::IncompatibleBootRom => "Incompatible boot ROM",
Error::NotImplemented => "Not implemented",
Error::MissingOption(_) => "Missing option",
Error::IoError(_) => "IO error",
Error::InvalidParameter(_) => "Invalid parameter",
Expand Down
6 changes: 3 additions & 3 deletions crates/encoding/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "boytacean-encoding"
description = "Codecs library for Boytacen."
version = "0.10.12"
version = "0.10.13"
authors = ["João Magalhães <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
Expand All @@ -10,8 +10,8 @@ edition = "2021"
simd = ["boytacean-hashing/simd"]

[dependencies]
boytacean-common = { path = "../common", version = "0.10.12" }
boytacean-hashing = { path = "../hashing", version = "0.10.12" }
boytacean-common = { path = "../common", version = "0.10.13" }
boytacean-hashing = { path = "../hashing", version = "0.10.13" }

[[bin]]
name = "zippy"
Expand Down
4 changes: 2 additions & 2 deletions crates/hashing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "boytacean-hashing"
description = "Hashing library for Boytacen."
version = "0.10.12"
version = "0.10.13"
authors = ["João Magalhães <[email protected]>"]
license = "Apache-2.0"
edition = "2021"
Expand All @@ -10,4 +10,4 @@ edition = "2021"
simd = []

[dependencies]
boytacean-common = { path = "../common", version = "0.10.12" }
boytacean-common = { path = "../common", version = "0.10.13" }
4 changes: 2 additions & 2 deletions frontends/libretro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boytacean-libretro"
version = "0.10.12"
version = "0.10.13"
authors = ["João Magalhães <[email protected]>"]
description = "A Libretro frontend for Boytacen"
license = "Apache-2.0"
Expand All @@ -17,4 +17,4 @@ pedantic = ["boytacean/pedantic"]
cpulog = ["boytacean/cpulog"]

[dependencies]
boytacean = { path = "../..", version = "0.10.12" }
boytacean = { path = "../..", version = "0.10.13" }
2 changes: 1 addition & 1 deletion frontends/libretro/res/boytacean_libretro.info
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ corename = "Boytacean"
categories = "Emulator"
license = "Apache-2."
permissions = ""
display_version = "0.10.12"
display_version = "0.10.13"

# Hardware Information
manufacturer = "Nintendo"
Expand Down
6 changes: 3 additions & 3 deletions frontends/sdl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "boytacean-sdl"
version = "0.10.12"
version = "0.10.13"
authors = ["João Magalhães <[email protected]>"]
description = "An SDL frontend for Boytacen"
license = "Apache-2.0"
Expand All @@ -15,8 +15,8 @@ pedantic = ["boytacean/pedantic"]
cpulog = ["boytacean/cpulog"]

[dependencies]
boytacean = { path = "../..", version = "0.10.12" }
boytacean-common = { path = "../../crates/common", version = "0.10.12" }
boytacean = { path = "../..", version = "0.10.13" }
boytacean-common = { path = "../../crates/common", version = "0.10.13" }
clap = { version = "4", features = ["derive"] }
image = "0.24"
chrono = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions frontends/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "boytacean-web",
"version": "0.10.12",
"version": "0.10.13",
"description": "The web version of Boytacean",
"repository": {
"type": "git",
Expand All @@ -24,7 +24,7 @@
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"buffer": "^6.0.3",
"emukit": "^0.10.12",
"emukit": "^0.10.13",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react-hooks": "^4.6.2",
Expand Down
49 changes: 36 additions & 13 deletions frontends/web/ts/gb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
RomInfo,
SaveState,
SectionInfo,
Size
Size,
TickParams,
Validation
} from "emukit";
import { loadAsync } from "jszip";

Expand All @@ -30,6 +32,7 @@ import {
GameBoySpeed,
Info,
PadKey,
SaveStateFormat,
StateManager
} from "../lib/boytacean";
import info from "../package.json";
Expand Down Expand Up @@ -189,20 +192,17 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {
* - Triggers the frame event in case there's a frame to be processed.
* - Triggers the audio event, allowing the deferred retrieval of the audio buffer.
* - Flushes the RAM to the local storage in case the cartridge is battery backed.
*
* @params params The parameters to be used in the tick operation.
*/
async tick() {
async tick(params: TickParams) {
// in case the reference to the system is not set then
// returns the control flow immediately (not possible to tick)
if (!this.gameBoy) return;

// calculates the number of cycles that are going to be
// processed in the current tick operation, this value is
// calculated using the logic and visual frequencies and
// the current Game Boy multiplier (DMG vs CGB)
const tickCycles = Math.round(
(this.logicFrequency * (this.gameBoy?.multiplier() ?? 1)) /
this.visualFrequency
);
// uses the Game Boy multiplier to re-calculate the number
// of cycles to be used for the tick
const tickCycles = params.cycles * (this.gameBoy?.multiplier() ?? 1);

// calculates the target cycles for clocking in the current
// tick operation, this is the ideal value and the concrete
Expand All @@ -218,7 +218,7 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {
);
const executedCycles = Number(this.clockFrame.cycles);
if (this.clockFrame.frames > 0) {
this.trigger("frame");
this.trigger("frame", { count: this.clockFrame.frames });
}

// triggers the audio event, meaning that the audio should be
Expand Down Expand Up @@ -470,6 +470,7 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {
Feature.RomTypeInfo,
Feature.Cyclerate,
Feature.Animationrate,
Feature.SkippedTicks,
Feature.EmulationSpeed
]
: [])
Expand Down Expand Up @@ -535,6 +536,10 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {
return ["gb", "gbc", "zip"];
}

get stateExts(): string[] {
return ["sav", ...Array.from({ length: 10 }, (_, i) => `s${i + 1}`)];
}

get pixelFormat(): PixelFormat {
return PixelFormat.RGB;
}
Expand Down Expand Up @@ -738,12 +743,26 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {

async buildState(index: number, data: Uint8Array): Promise<SaveState> {
try {
const state = StateManager.read_bos_auto_wa(data);
let state = null;
const format = StateManager.format_wa(data);
switch (format) {
case SaveStateFormat.Bos:
case SaveStateFormat.Bosc:
state = StateManager.read_bos_auto_wa(data);
break;
case SaveStateFormat.Bess:
state = StateManager.read_bess_wa(data);
break;
default:
throw new Error(`Invalid state format ${format}`);
}
const timestamp = Number(state.timestamp_wa());
return {
index: index,
timestamp: Number(state.timestamp_wa()),
timestamp: timestamp > 0 ? timestamp : undefined,
agent: state.agent_wa(),
model: state.model_wa(),
title: state.title_wa(),
format: StateManager.format_str_wa(data),
size: data.length,
thumbnail: state.has_image_wa()
Expand All @@ -758,6 +777,10 @@ export class GameboyEmulator extends EmulatorLogic implements Emulator {
}
}

async validateState(data: Uint8Array, validation: Validation) {
StateManager.validate_wa(data, validation.title);
}

pauseVideo() {
this.gameBoy?.set_ppu_enabled(false);
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

setuptools.setup(
name="boytacean",
version="0.10.12",
version="0.10.13",
author="João Magalhães",
author_email="[email protected]",
description="A Game Boy emulator that is written in Rust",
Expand Down
6 changes: 6 additions & 0 deletions src/gb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ impl From<&str> for GameBoyMode {
}
}

impl From<GameBoyMode> for String {
fn from(value: GameBoyMode) -> Self {
value.to_string(Some(true))
}
}

#[cfg_attr(feature = "wasm", wasm_bindgen)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum GameBoySpeed {
Expand Down
Loading

0 comments on commit e8523de

Please sign in to comment.