Skip to content

Commit

Permalink
Release 0.8.6 From Google Code.
Browse files Browse the repository at this point in the history
  • Loading branch information
trash80 committed Jul 26, 2015
1 parent fee719e commit 5b60926
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 39 deletions.
8 changes: 5 additions & 3 deletions Arduinoboy/Arduinoboy.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************
* A R D U I N O B O Y *
* *
* Version: 0.8.5 *
* Version: 0.8.6 *
* Date: March 07 2008 *
* Name: Timothy Lamb *
* Email: [email protected] *
Expand Down Expand Up @@ -111,7 +111,7 @@ int countGbClockTicks =0;
int countClockPause =0;
int countIncommingMidiByte =0;
int countStatusLedOn =0;

unsigned int waitClock =0;
/***************************************************************************
* Inbound Data Placeholders
***************************************************************************/
Expand All @@ -123,7 +123,9 @@ int incomingMidiData[] = {0, 0, 0};
int incomingMidiNote = 0;
int incomingMidiVel = 0;
byte readToggleMode;

byte serialWriteBuffer[256];
int writePosition=0;
int readPosition=0;
/***************************************************************************
* LSDJ Keyboard mode settings
***************************************************************************/
Expand Down
99 changes: 63 additions & 36 deletions Arduinoboy/Mode_LSDJ_Keyboard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

void modeLSDJKeyboardSetup()
{
sendByteToGameboy(0);
for(int rst=0;rst<5;rst++) sendByteToGameboy(keyboardOctDn);
for(int rst=0;rst<41;rst++) sendByteToGameboy(keyboardInsDn);
for(int rst=0;rst<41;rst++) sendByteToGameboy(keyboardTblDn);
addGameboyByte(0);
for(int rst=0;rst<5;rst++) addGameboyByte(keyboardOctDn);
for(int rst=0;rst<41;rst++) addGameboyByte(keyboardInsDn);
for(int rst=0;rst<41;rst++) addGameboyByte(keyboardTblDn);
keyboardCurrentOct = 0;
keyboardCurrentIns = 0;
keyboardCurrentTbl = 0;
Expand All @@ -27,8 +27,7 @@ void modeLSDJKeyboardSetup()
void modeLSDJKeyboard()
{
while(1){
setMode();
updateStatusLed();

if (Serial.available() > 0) {
incomingMidiByte = Serial.read();
Serial.print(incomingMidiByte, BYTE);
Expand All @@ -37,22 +36,27 @@ void modeLSDJKeyboard()
case 0x90:
midiNoteOnMode = true;
incomingMidiData[0] = incomingMidiByte;
incomingMidiData[1] = false;
break;
case 0xC0:
midiProgramChange = true;
midiNoteOnMode = false;
incomingMidiData[0] = incomingMidiByte - 48;
break;
default:
midiNoteOnMode = false;
midiProgramChange = false;
incomingMidiData[1] = false;
break;

}
} else if(midiNoteOnMode) {
if(!incomingMidiData[1]) {
incomingMidiData[1] = incomingMidiByte;
} else {
incomingMidiData[2] = incomingMidiByte;
playLSDJKeyboard();
midiNoteOnMode=false;
incomingMidiData[0] = false;
incomingMidiData[1] = false;
incomingMidiData[2] = false;
}
} else if (midiProgramChange) {
incomingMidiData[1] = incomingMidiByte;
Expand All @@ -61,13 +65,19 @@ void modeLSDJKeyboard()
incomingMidiData[0] = false;
incomingMidiData[1] = false;
}
updateGameboyByteFrame();
updateStatusLed();
setMode();
} else {
updateGameboyByteFrame();
updateStatusLed();
setMode();
}
}
}
void playLSDJKeyboard()
{
if(incomingMidiData[0] == keyboardInstrumentMidiChannel) {
if(incomingMidiData[0] == keyboardInstrumentMidiChannel && incomingMidiData[2] > 0x00) {
playLSDJKeyboardNote();
}
}
Expand All @@ -79,12 +89,12 @@ void playLSDJProgramChange()
if(keyboardCurrentIns > keyboardLastIns) {
keyboardDiff = keyboardCurrentIns - keyboardLastIns;
for(keyboardCount=0;keyboardCount<keyboardDiff;keyboardCount++) {
sendByteToGameboy(keyboardInsUp);
addGameboyByte(keyboardInsUp);
}
} else {
keyboardDiff = keyboardLastIns - keyboardCurrentIns;
for(keyboardCount=0;keyboardCount<keyboardDiff;keyboardCount++) {
sendByteToGameboy(keyboardInsDn);
addGameboyByte(keyboardInsDn);
}
}
keyboardLastIns = keyboardCurrentIns;
Expand All @@ -93,9 +103,7 @@ void playLSDJProgramChange()

void playLSDJKeyboardNote()
{
if(incomingMidiData[1] >= 0x3C
&& incomingMidiData[2] > 0x00
) {
if(incomingMidiData[1] >= 0x3C) {
incomingMidiData[1] = incomingMidiData[1] - 0x3C;
if(incomingMidiData[1] >= 0x30) {
keyboardCurrentOct = 4;
Expand All @@ -115,67 +123,88 @@ void playLSDJKeyboardNote()
keyboardDiff = keyboardCurrentOct - keyboardLastOct;
for(keyboardCount=0;keyboardCount<keyboardDiff;keyboardCount++)
{
sendByteToGameboy(keyboardOctUp);
addGameboyByte(keyboardOctUp);
}
} else {
keyboardDiff = keyboardLastOct - keyboardCurrentOct;
for(keyboardCount=0;keyboardCount<keyboardDiff;keyboardCount++)
{
sendByteToGameboy(keyboardOctDn);
addGameboyByte(keyboardOctDn);
}
}
}

incomingMidiData[1] = incomingMidiData[1] % 12;
sendByteToGameboy(keyboardNotes[incomingMidiData[1]]);
addGameboyByte(keyboardNotes[incomingMidiData[1]]);
keyboardLastOct = keyboardCurrentOct;
keyboardLastIns = keyboardCurrentIns;
} else {
switch(incomingMidiData[1]) {
case 0x30:
sendByteToGameboy(keyboardMut1);
addGameboyByte(keyboardMut1);
break;
case 0x31:
sendByteToGameboy(keyboardMut2);
addGameboyByte(keyboardMut2);
break;
case 0x32:
sendByteToGameboy(keyboardMut3);
addGameboyByte(keyboardMut3);
break;
case 0x33:
sendByteToGameboy(keyboardMut4);
addGameboyByte(keyboardMut4);
break;
case 0x34:
sendByteToGameboy(keyboardEntr);
addGameboyByte(keyboardEntr);
break;
case 0x35:
sendByteToGameboy(0xE0);
sendByteToGameboy(keyboardCurL);
addGameboyByte(0xE0);
addGameboyByte(keyboardCurL);
break;
case 0x36:
sendByteToGameboy(0xE0);
sendByteToGameboy(keyboardCurR);
addGameboyByte(0xE0);
addGameboyByte(keyboardCurR);
break;
case 0x37:
sendByteToGameboy(0xE0);
sendByteToGameboy(keyboardCurD);
addGameboyByte(0xE0);
addGameboyByte(keyboardCurU);
break;
case 0x38:
sendByteToGameboy(0xE0);
sendByteToGameboy(keyboardCurU);
addGameboyByte(0xE0);
addGameboyByte(keyboardCurD);
break;
case 0x39:
sendByteToGameboy(keyboardTblDn);
addGameboyByte(keyboardTblDn);
break;
case 0x3A:
sendByteToGameboy(keyboardTblUp);
addGameboyByte(keyboardTblUp);
break;
case 0x3B:
sendByteToGameboy(keyboardTblCue);
addGameboyByte(keyboardTblCue);
break;
}
}
}

void addGameboyByte(byte send_byte)
{
serialWriteBuffer[writePosition] = send_byte;
writePosition++;
writePosition = writePosition % 256;
}

void updateGameboyByteFrame()
{
if(readPosition != writePosition){
waitClock++;
if(waitClock > 100) {
waitClock=0;
statusLedOn();
sendByteToGameboy(serialWriteBuffer[readPosition]);
readPosition++;
readPosition = readPosition % 256;
}
}
}

void sendByteToGameboy(byte send_byte)
{
for(countLSDJTicks=0;countLSDJTicks<8;countLSDJTicks++) {
Expand All @@ -189,7 +218,5 @@ void sendByteToGameboy(byte send_byte)
digitalWrite(pinGBClock,LOW);
}
digitalWrite(pinGBSerialOut,LOW);
delayMicroseconds(1600);
statusLedOn();
}

0 comments on commit 5b60926

Please sign in to comment.