Created
August 18, 2012 01:47
-
-
Save steventroughtonsmith/3383882 to your computer and use it in GitHub Desktop.
Still Alive written in C for the RPC8/e 65el02 CPU in Minecraft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <conio.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <peekpoke.h> | |
#include <time.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
extern unsigned setMappedRedbusDevice(unsigned char); | |
extern unsigned short getMappedRedbusDevice(); | |
extern void enableRedbus(); | |
extern void disableRedbus(); | |
#define RedBusOff 0 | |
#define RedBusWhite 1 | |
#define RedBusOrange 2 | |
#define RedBusMagenta 4 | |
#define RedBusLightBlue 8 | |
#define RedBusYellow 16 | |
#define RedBusLime 32 | |
#define RedBusPink 64 | |
#define RedBusGray 128 | |
#define RedBusLightGray 256 | |
#define RedBusCyan 512 | |
#define RedBusPurple 1024 | |
#define RedBusBlue 2048 | |
#define RedBusBrown 4096 | |
#define RedBusGreen 8192 | |
#define RedBusRed 16384 | |
#define RedBusBlack 32768 | |
#define octaveShift 4096 | |
#undef G | |
#undef Af | |
#undef A | |
#undef Bf | |
#undef B | |
#undef C | |
#undef Cs | |
#undef D | |
#undef Ef | |
#undef E | |
#undef F | |
#undef Fs | |
#define G RedBusWhite | |
#define Af RedBusOrange | |
#define A RedBusMagenta | |
#define Bf RedBusLightBlue | |
#define B RedBusYellow | |
#define C RedBusLime | |
#define Cs RedBusPink | |
#define D RedBusGray | |
#define Ef RedBusLightGray | |
#define E RedBusCyan | |
#define F RedBusPurple | |
#define Fs RedBusBlue | |
#define G2 RedBusWhite + octaveShift | |
#define Af2 RedBusOrange + octaveShift | |
#define A2 RedBusMagenta + octaveShift | |
#define Bf2 RedBusLightBlue + octaveShift | |
#define B2 RedBusYellow + octaveShift | |
#define C2 RedBusLime + octaveShift | |
#define Cs2 RedBusPink + octaveShift | |
#define D2 RedBusGray + octaveShift | |
#define Ef2 RedBusLightGray + octaveShift | |
#define E2 RedBusCyan + octaveShift | |
#define F2 RedBusPurple + octaveShift | |
#define Fs2 RedBusBlue + octaveShift | |
#define SKIP 0 | |
#define POKE16(addr,val) (*(unsigned short*) (addr) = (val)) | |
#define PEEK16(addr) (*(unsigned short*) (addr)) | |
extern unsigned WAIT(); // just a WAI or .byte $CB | |
extern void SWITCHTO8BIT(); // sep #30 | |
extern void SWITCHTO16BIT(); // rep #30 | |
void reset(unsigned char device) | |
{ | |
setMappedRedbusDevice(device); | |
POKE( 0x302, 0 ); //reset iox | |
} | |
void setCursorMode(short mode) | |
{ | |
POKE( 0x303, mode ); | |
} | |
void musicsleep( unsigned char ms ) | |
{ | |
unsigned char tick = 0; | |
unsigned char count = ms/50; | |
for (tick = 0; tick < count; tick++) | |
{ | |
WAIT(); | |
} | |
} | |
unsigned short lastDevice; | |
void playnote(unsigned short note) | |
{ | |
unsigned short wantedDevice; | |
if (note > octaveShift) | |
{ | |
wantedDevice = 4; | |
note -= octaveShift; | |
} | |
else | |
wantedDevice = 3; | |
if (lastDevice != wantedDevice) | |
{ | |
lastDevice = wantedDevice; | |
while (wantedDevice != getMappedRedbusDevice()) | |
{ | |
// the IO Expander is incredibly slow to switch | |
reset(wantedDevice); | |
setMappedRedbusDevice(wantedDevice); | |
musicsleep(150); | |
} | |
} | |
while (PEEK16( 0x302) != note) | |
POKE16( 0x302, note); | |
musicsleep(150); | |
while (PEEK16( 0x302) != SKIP) | |
POKE16( 0x302, SKIP); | |
musicsleep(100); | |
} | |
void play() | |
{ | |
lastDevice = 3; | |
/* | |
F, E, D, D, E, SKIP,\ | |
SKIP, SKIP, SKIP, SKIP,\ | |
G, F, E, D, D, SKIP, E, SKIP, C, SKIP, D, G,\ | |
SKIP, SKIP,\ | |
G, D, SKIP, E, F, D, B, C, D, G, G, E,\ | |
SKIP, SKIP, SKIP, SKIP,\ | |
F, E, D, D, E, SKIP,\ | |
SKIP, SKIP, SKIP, SKIP,\ | |
G, F, E, D, D, SKIP, E, SKIP, C, SKIP, D, G,\ | |
SKIP, SKIP,\ | |
G, D, E, F, D, B, C, D, G, C, D, Ef, D, C, Bf,\ | |
SKIP, SKIP, SKIP, SKIP,\ | |
G, Af, Bf, SKIP, Ef, SKIP, D, C, C, Bf, C, Bf, Bf, SKIP, Bf,\ | |
SKIP,\ | |
G, Af, Bf, SKIP, Ef, SKIP, F, Ef, D, C, C, D, Ef, SKIP, Ef,\ | |
SKIP,\ | |
F, G2, Af2, Af2, G2,SKIP, F, SKIP, Ef, F, G2, G2, F,SKIP, Ef,\ | |
SKIP,\ | |
C, Bf, C, Ef, Ef, D, SKIP, D, Ef, Ef\ | |
*/ | |
setMappedRedbusDevice(3); | |
// Fugly, I know; couldn't do an array of shorts because of how cc65 handles them | |
playnote(F); | |
playnote(E); | |
playnote(D); | |
playnote(D); | |
playnote(E); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(G); | |
playnote(F); | |
playnote(E); | |
playnote(D); | |
playnote(D); | |
playnote(SKIP); | |
playnote(E); | |
playnote(SKIP); | |
playnote(C); | |
playnote(SKIP); | |
playnote(D); | |
playnote(G); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(G); | |
playnote(D); | |
playnote(SKIP); | |
playnote(E); | |
playnote(F); | |
playnote(D); | |
playnote(B); | |
playnote(C); | |
playnote(D); | |
playnote(G); | |
playnote(G); | |
playnote(E); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(F); | |
playnote(E); | |
playnote(D); | |
playnote(D); | |
playnote(E); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(G); | |
playnote(F); | |
playnote(E); | |
playnote(D); | |
playnote(D); | |
playnote(SKIP); | |
playnote(E); | |
playnote(SKIP); | |
playnote(C); | |
playnote(SKIP); | |
playnote(D); | |
playnote(G); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(G); | |
playnote(D); | |
playnote(E); | |
playnote(F); | |
playnote(D); | |
playnote(B); | |
playnote(C); | |
playnote(D); | |
playnote(G); | |
playnote(C); | |
playnote(D); | |
playnote(Ef); | |
playnote(D); | |
playnote(C); | |
playnote(Bf); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(SKIP); | |
playnote(G); | |
playnote(Af); | |
playnote(Bf); | |
playnote(SKIP); | |
playnote(Ef); | |
playnote(SKIP); | |
playnote(D); | |
playnote(C); | |
playnote(C); | |
playnote(Bf); | |
playnote(C); | |
playnote(Bf); | |
playnote(Bf); | |
playnote(SKIP); | |
playnote(Bf); | |
playnote(SKIP); | |
playnote(G); | |
playnote(Af); | |
playnote(Bf); | |
playnote(SKIP); | |
playnote(Ef); | |
playnote(SKIP); | |
playnote(F); | |
playnote(Ef); | |
playnote(D); | |
playnote(C); | |
playnote(C); | |
playnote(D); | |
playnote(Ef); | |
playnote(SKIP); | |
playnote(Ef); | |
playnote(SKIP); | |
playnote(F); | |
//swap expander for octave change | |
setMappedRedbusDevice(4); | |
playnote(G); | |
playnote(Af); | |
playnote(Af); | |
playnote(G); | |
setMappedRedbusDevice(3); | |
//back | |
playnote(SKIP); | |
playnote(F); | |
playnote(SKIP); | |
playnote( Ef); | |
playnote(F); | |
//swap expander | |
setMappedRedbusDevice(4); | |
playnote(G); | |
playnote(G); | |
setMappedRedbusDevice(3); | |
//back | |
playnote(F); | |
playnote(SKIP); | |
playnote(Ef); | |
playnote(SKIP); | |
playnote(C); | |
playnote(Bf); | |
playnote(C); | |
playnote(Ef); | |
playnote(Ef); | |
playnote(D); | |
playnote(SKIP); | |
playnote( D); | |
playnote(Ef); | |
playnote(Ef); | |
} | |
int main() | |
{ | |
enableRedbus(); | |
reset(3); | |
reset(4); | |
setMappedRedbusDevice(1); | |
setCursorMode(1); | |
clrscr(); | |
cputs( "Beginning Music Playback\n"); | |
setCursorMode(2); | |
SWITCHTO16BIT(); | |
play(); | |
SWITCHTO8BIT(); | |
setMappedRedbusDevice(1); | |
cputs( "End Music Playback"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment