Skip to content

Commit

Permalink
Use standard SD library for example sketches.
Browse files Browse the repository at this point in the history
- Stopped using custom (smaller) SdFat library so examples can be used
out of the box.
- Fixed a bug in PlayDRO where long files would not play.
- PlayIMF and PlayDRO examples now have same example tunes as on the
Raspberry Pi.
  • Loading branch information
DhrBaksteen committed Jun 12, 2017
1 parent bdeaf2a commit 65a93e7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
46 changes: 23 additions & 23 deletions examples/PlayDRO/PlayDRO.ino
Expand Up @@ -22,16 +22,15 @@


#include <SPI.h>
#include <SdFat.h>
#include <SD.h>
#include <OPL2.h>

OPL2 opl2;
SdFat SD;
SdFile file;
File droFile;

long offset = 0;
long songLength = 0;
long songDuration = 0;
unsigned long offset = 0;
unsigned long songLength = 0;
unsigned long songDuration = 0;
byte codeShortDelay = 0;
byte codeLongDelay = 0;
byte registerMapLength = 0;
Expand All @@ -43,6 +42,7 @@ void setup() {
SD.begin(7);

loadDroSong("phemopop.dro");
// loadDroSong("strikefo.dro");
}


Expand All @@ -58,33 +58,33 @@ void loop() {


void loadDroSong(char* fileName) {
file.open(fileName);
file.seekSet(12);
droFile = SD.open(fileName, FILE_READ);
droFile.seek(12);

songLength = file.read();
songLength += file.read() << 8;
songLength += file.read() << 16;
songLength += file.read() << 24;
songLength = droFile.read();
songLength += droFile.read() << 8;
songLength += droFile.read() << 16;
songLength += droFile.read() << 24;

songDuration = file.read();
songDuration += file.read() << 8;
songDuration += file.read() << 16;
songDuration += file.read() << 24;
songDuration = droFile.read();
songDuration += droFile.read() << 8;
songDuration += droFile.read() << 16;
songDuration += droFile.read() << 24;

file.seekSet(23);
codeShortDelay = file.read();
codeLongDelay = file.read();
registerMapLength = file.read();
droFile.seek(23);
codeShortDelay = droFile.read();
codeLongDelay = droFile.read();
registerMapLength = droFile.read();

for (byte i = 0; i < registerMapLength; i ++) {
registerMap[i] = file.read();
registerMap[i] = droFile.read();
}
}


int playDroSong() {
byte code = file.read();
byte data = file.read();
byte code = droFile.read();
byte data = droFile.read();

if (code == codeShortDelay) {
return data + 1;
Expand Down
Binary file added examples/PlayDRO/strikeforce.dro
Binary file not shown.
33 changes: 18 additions & 15 deletions examples/PlayIMF/PlayIMF.ino
Expand Up @@ -16,27 +16,30 @@
* http://www.shikadi.net/moddingwiki/IMF_Format
*
* Code by Maarten Janssen (maarten@cheerful.nl) 2016-12-17
* Song from the game Keen5 by Bobby Prince 1991
* Songs from the games Bio Menace and Duke Nukem II by Bobby Prince
* Most recent version of the library can be found at my GitHub: https://github.com/DhrBaksteen/ArduinoOPL2
*/


#include <SPI.h>
#include <SdFat.h>
#include <SD.h>
#include <OPL2.h>

OPL2 opl2;
SdFat SD;
SdFile file;
File imfFile;

float imfSpeed;
long songLength = 0;
float imfSpeed = 560.0;

void setup() {
opl2.init();
SD.begin(7);

loadImfSong("k5t06.imf");
imfSpeed = 560.0;
loadImfSong("city.imf");

// imfSpeed = 280.0;
// loadImfSong("kickbuta.imf");
}

void loop() {
Expand All @@ -51,23 +54,23 @@ void loop() {


void loadImfSong(char* fileName) {
file.open(fileName);
file.seekSet(0);
imfFile = SD.open(fileName, FILE_READ);
imfFile.seek(0);

songLength = file.read();
songLength += file.read() << 8;
songLength = imfFile.read();
songLength += imfFile.read() << 8;
if (songLength == 0) {
songLength = 65535;
file.seekSet(4);
imfFile.seek(4);
}
}


int playImfSong() {
byte reg = file.read();
byte data = file.read();
float wait = file.read();
wait += file.read() << 8;
byte reg = imfFile.read();
byte data = imfFile.read();
float wait = imfFile.read();
wait += imfFile.read() << 8;

if (reg != 0x00) {
opl2.write(reg, data);
Expand Down
Binary file added examples/PlayIMF/city.imf
Binary file not shown.
Binary file removed examples/PlayIMF/k5t06.imf
Binary file not shown.
Binary file added examples/PlayIMF/kickbuta.imf
Binary file not shown.

0 comments on commit 65a93e7

Please sign in to comment.