diff --git a/README.md b/README.md index 0f85b01..d378675 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,13 @@ A small library to provide bindings for the [Nuked-OPL3 library](https://github. # Usage Nuked-OPL3 is not a turn-key implementation of the OPL3 chip - functions such as the status register, timers and -interrupts are left as implementation details. Eventually this library will aim to provide a wrapper type that will -provide example implementations for easier integrations with emulators. +interrupts are left as implementation details. -For now, you can access the Nuked-OPL3 API via the `Opl3Chip` struct. +You can access the Nuked-OPL3 API via the `Opl3Chip` struct, if needed, but with the caveat that directly writing +registers to Nuked-OPL3 will prevent you from reading the OPL registers correctly. + +If you intend to utilize `opl3-rs` in an emulator, you will probably want to use the `Opl3Device` wrapper which provides +a full, device-oriented OPL3 implementation including the status, address and data registers, plus the OPL3 timers. # Docs @@ -24,6 +27,9 @@ Documentation can be found on [docs.rs](https://docs.rs/opl3-rs/latest/opl3_rs/) An example of music playback is provided in the play_tune directory under /examples. This example uses the rodio library for audio playback and crossbeam channels for inter-thread communication. +opl3-rs was primarily built for use with the [MartyPC PC emulator](https://github.com/dbalsom/martypc). It is used to +implement an AdLib Music Card device. + # Credits [Nuked-OPL3](https://github.com/nukeykt/Nuked-OPL3) is (C) 2013-2020 Nuke.YKT and licensed under LGPL 2.1 diff --git a/src/docs.md b/src/docs.md index 654dca6..6b00b6a 100644 --- a/src/docs.md +++ b/src/docs.md @@ -1,12 +1,18 @@ # opl3-rs + `opl3-rs` is a small library to provide bindings for the [Nuked-OPL3 library](https://github.com/nukeykt/Nuked-OPL3). # Usage + Nuked-OPL3 is not a turn-key implementation of the OPL3 chip - functions such as the status register, timers and -interrupts are left as implementation details. Eventually this library will aim to provide a wrapper type that will -provide example implementations for easier integrations with emulators. +interrupts are left as implementation details. -For now, you can access the Nuked-OPL3 API via the `Opl3Chip` struct. +You can access the Nuked-OPL3 API via the `Opl3Chip` struct, if needed, but with the caveat that directly writing +registers to Nuked-OPL3 will prevent you from reading the OPL registers correctly. + +If you intend to utilize `opl3-rs` in an emulator, you will probably want to use the `Opl3Device` wrapper which provides +a full OPL3 implementation including the status registers and timers. # Credits + [Nuked-OPL3](https://github.com/nukeykt/Nuked-OPL3) is (C) 2013-2020 Nuke.YKT and licensed under LGPL 2.1 \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index f7af59f..f9f6470 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -456,6 +456,16 @@ pub struct Opl3Chip { chip: *mut bindings::Opl3Chip, } +impl Drop for Opl3Chip { + /// Drop the Opl3Chip instance by deallocating the memory used by the Nuked-OPL3 instance. + fn drop(&mut self) { + unsafe { + let layout = std::alloc::Layout::new::(); + std::alloc::dealloc(self.chip as *mut u8, layout); + } + } +} + impl Opl3Chip { /// Creates a new OPL3 chip instance. The chip is initialized with the given sample rate. /// The internal chip device is Pinned to ensure that it is not moved in memory. The Nuked-OPL3