Skip to content

Commit

Permalink
Release 0.9.9 from Google Code.
Browse files Browse the repository at this point in the history
  • Loading branch information
trash80 committed Jul 26, 2015
1 parent 2ec6adb commit c9438b7
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 9 deletions.
28 changes: 20 additions & 8 deletions Arduinoboy/Arduinoboy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
***************************************************************************
***************************************************************************
* *
* Version: 0.9.8 *
* Date: March 11 2008 *
* Version: 0.9.9.1 *
* Date: Sept 12 2008 *
* Name: Timothy Lamb *
* Email: trash80@gmail.com *
* *
Expand Down Expand Up @@ -74,17 +74,21 @@ int masterNotePositionMidiChannel = 16; //LSDJ in master mode will send its so
int keyboardInstrumentMidiChannel = 16; //midi channel for keyboard instruments in lsdj.

boolean keyboardCompatabilityMode = true; //Set to true if you are using LSDJ version lower then 2.6, not working right now
boolean keyboardMidiChannelToInstrument = true; //Set to true if you want to have midi channel set the instrument number

//Mode 0: Midi Input to LSDJ Sync
//Mode 1: LSDJ MASTER to Midi output
//Mode 2: LSDJ Keyboard
//Mode 3: Midi Input to Nanoloop
int mode = 0;
int numberOfModes = 4; //Right now there are 4 modes, Might be more in the future

int numberOfModes = 5; //Right now there are 5 modes, Might be more in the future
boolean usbMode = false;
//Enforces the mode above, without reading from memory, use this to force the mode if you dont have a push button setup.
boolean forceMode = false;

int gameboyBitPause = 1; //Bit pause for gbmidi mode .... 1 to 20
int gameboyBytePause= 20; //Byte pause for gbmidi mode ... if having trouble communicating with gb try playing with these values... 20 to 100

/***************************************************************************
* Lets Assign our Arduino Pins .....
***************************************************************************/
Expand Down Expand Up @@ -114,11 +118,15 @@ boolean midiSyncEffectsTime = false;
boolean midiNoteOnMode =false;
boolean midiNoteOffMode =false;
boolean midiProgramChange=false;
boolean midiAddressMode =false;
boolean midiValueMode =false;

boolean statusLedIsOn =false;
boolean statusLedBlink =false;

boolean nanoState =false;
boolean nanoSkipSync =false;

/***************************************************************************
* Counter vars
***************************************************************************/
Expand All @@ -139,6 +147,7 @@ byte readgbClockLine;
byte readGbSerialIn;
byte bit;
int incomingMidiData[] = {0, 0, 0};
int lastMidiData[] = {0, 0, 0};

int incomingMidiNote = 0;
int incomingMidiVel = 0;
Expand Down Expand Up @@ -203,17 +212,20 @@ void setup() {

pinMode(pinGBClock,OUTPUT);
pinMode(pinGBSerialOut,OUTPUT);
pinMode(pinMidiInputPower,OUTPUT);
pinMode(pinGBSerialIn,INPUT);
/*
Set MIDI Serial Rate
*/
Serial.begin(31250); //31250

if(usbMode == true) {
Serial.begin(38400); //31250
} else {
pinMode(pinMidiInputPower,OUTPUT);
digitalWrite(pinMidiInputPower,HIGH); // turn on the optoisolator
Serial.begin(31250); //31250
}
/*
Set Pin States
*/
digitalWrite(pinMidiInputPower,HIGH); // turn on the optoisolator
digitalWrite(pinGBClock,HIGH); // gameboy wants a HIGH line
digitalWrite(pinGBSerialOut,LOW); // no data to send
/*
Expand Down
5 changes: 4 additions & 1 deletion Arduinoboy/Mode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
void setMode()
{
if(digitalRead(pinButtonMode)) { //if the button is pressed
if(!forceMode && digitalRead(pinButtonMode)) { //if the button is pressed
mode++; //increment the mode number
if(mode > (numberOfModes - 1)) mode=0; //if the mode is greater then 4 it will wrap back to 0
if(!forceMode) EEPROM.write(eepromMemoryByte, mode); //write mode to eeprom if we arnt forcing a mode in the config
Expand Down Expand Up @@ -67,6 +67,9 @@ void switchMode()
case 3:
modeNanoloopSetup();
break;
case 4:
modeMidiGbSetup();
break;
}
}

Expand Down
20 changes: 20 additions & 0 deletions Arduinoboy/Mode_LSDJ_Keyboard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,23 @@ void sendByteToGameboy(byte send_byte)
}
digitalWrite(pinGBSerialOut,LOW); //make sure the serial state returns to 0 after its done sending the bits
}

void sendByteToGameboy__(byte send_byte) //changed by firestARTer: send routine changed MST is send out first!!!!!!!
{
for(countLSDJTicks=0;countLSDJTicks<8;countLSDJTicks++) { //we are going to send 8 bits, so do a loop 8 times
// digitalWrite(pinGBClock,HIGH); //Set our clock output to 1
if(send_byte & 0x80) { //if the first bit is equal to 1
digitalWrite(pinGBSerialOut,HIGH); //then send a 1
} else {
digitalWrite(pinGBSerialOut,LOW); //send a 0
}
send_byte <<= 1; //bitshift right once for the next bit we are going to send
digitalWrite(pinGBClock,LOW); //send a 0 to the clock, we finished sending the bit

delayMicroseconds(30); // firestARter : play around with this value, sometimes the gameboy needs more time between messages
digitalWrite(pinGBClock,HIGH); //send a 0 to the clock, we finished sending the bit

}
digitalWrite(pinGBSerialOut,LOW); //make sure the serial state returns to 0 after its done sending the bits
delayMicroseconds(30); // firestARter : play around with this value, sometimes the gameboy needs more time between messages
}
115 changes: 115 additions & 0 deletions Arduinoboy/Mode_MidiGb.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
void modeMidiGbSetup()
{
digitalWrite(pinStatusLed,LOW);
pinMode(pinGBClock,OUTPUT); //make sure our gameboy Clock is set for OUTPUT mode
//digitalWrite(pinGBClock,LOW); //Generally this should be HIGH ie: 1, on, whatever. but since we are emulating a pc keyboard it should be LOW/0/off
modeMidiGb();
}

void modeMidiGb()
{
while(1){ //Loop foreverrrr

if (Serial.available() > 0) { //If MIDI is sending
incomingMidiByte = Serial.read(); //Get the byte sent from MIDI
//addFSGameboyByte(incomingMidiByte);
//if(!usbMode) Serial.print(incomingMidiByte, BYTE); //Echo the Byte to MIDI Output
if(incomingMidiByte > 0x7F) {
switch (incomingMidiByte & 0xF0) {
case 0xF0:
midiValueMode = false;
break;
default:
incomingMidiData[0] = incomingMidiByte;
midiValueMode = false;
midiAddressMode = true;
break;
}
} else if (midiAddressMode){
midiAddressMode = false;
midiValueMode = true;
incomingMidiData[1] = incomingMidiByte;
} else if (midiValueMode) {
incomingMidiData[2] = incomingMidiByte;
midiAddressMode = true;
midiValueMode = false;

if(lastMidiData[0] != incomingMidiData[0] ||
lastMidiData[1] != incomingMidiData[1] ||
lastMidiData[2] != incomingMidiData[2]) {
if(lastMidiData[0] != incomingMidiData[0]) {
addFSGameboyByte(incomingMidiData[0]);
}

addFSGameboyByte(incomingMidiData[1]);
addFSGameboyByte(incomingMidiData[2]);

lastMidiData[0] = incomingMidiData[0];
lastMidiData[1] = incomingMidiData[1];
lastMidiData[2] = incomingMidiData[2];
}
}
}
updateFSGameboyByteFrame(); // Send out Bytes to LSDJ
setMode(); // Check if mode button was depressed
}
}

boolean checkGbSerialStopped()
{
countClockPause++; //Increment the counter
if(countClockPause > 16000) { //if we've reached our waiting period
countClockPause = 0; //reset our clock
Serial.print(0xFC, BYTE); //send the transport stop message
return true;
}
return false;
}

void addFSGameboyByte(byte send_byte)
{
serialWriteBuffer[writePosition] = send_byte; //assign new byte
writePosition++; //increment the write position
writePosition = writePosition % 256; //make sure our write position is between 0 to 255 by using a mod of 256
}

/*
updateGameboyByteFrame is responcible responsibel resp.... job is to wait a period of time,
and then send a byte to the gameboy byte output function.
*/
void updateFSGameboyByteFrame()
{
if(readPosition != writePosition){ //if we have something to read out
waitClock++; //then increment our counter
if(waitClock > gameboyBytePause) { //if we've exceeded our wait time
waitClock=0; //reset the counter
//statusLedOn(); //turn on the awesome visuals
sendFSByteToGameboy(serialWriteBuffer[readPosition]); //send the byte out
readPosition++; //increment our read position
readPosition = readPosition % 256; //wrap our reading range from 0 to 255
}
}
}
/*
sendByteToGameboy does what it says. yay magic
*/
void sendFSByteToGameboy(byte send_byte) //changed by firestARTer: send routine changed MST is send out first!!!!!!!
{
for(countLSDJTicks=0;countLSDJTicks<8;countLSDJTicks++) { //we are going to send 8 bits, so do a loop 8 times
// digitalWrite(pinGBClock,HIGH); //Set our clock output to 1
if(send_byte & 0x80) { //if the first bit is equal to 1
digitalWrite(pinGBSerialOut,HIGH); //then send a 1
} else {
digitalWrite(pinGBSerialOut,LOW); //send a 0
}
send_byte <<= 1; //bitshift right once for the next bit we are going to send
digitalWrite(pinGBClock,LOW); //send a 0 to the clock, we finished sending the bit

delayMicroseconds(gameboyBitPause); // firestARter : play around with this value, sometimes the gameboy needs more time between messages
digitalWrite(pinGBClock,HIGH); //send a 0 to the clock, we finished sending the bit

}
digitalWrite(pinGBSerialOut,LOW); //make sure the serial state returns to 0 after its done sending the bits
delayMicroseconds(gameboyBitPause); // firestARter : play around with this value, sometimes the gameboy needs more time between messages

}

0 comments on commit c9438b7

Please sign in to comment.