Skip to content

Commit

Permalink
CD Changer will now display 'CD TRK SCAN' oscillatiing with 'CD ERROR…
Browse files Browse the repository at this point in the history
…'. Unrelated: The g_dev is not properly set, this needs to be done
  • Loading branch information
archi committed Mar 16, 2016
1 parent caa9cca commit 3be2a3c
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 78 deletions.
28 changes: 20 additions & 8 deletions emulator/cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ enum Cmd {
NextDisc,
PrevDisc,
NopAck,
Wait //pseudo CMD -> waiting for a CMD
Wait, //pseudo CMD -> waiting for a CMD
PowerUp,
PowerDown,
FFWD,
FREW,
ScanMode,
RndMode
};

struct cmd_t {
Expand All @@ -23,18 +29,18 @@ struct cmd_t {
const struct cmd_t g_cmdTable[g_cmdTableSize] = {
{Init, 3, {0x07, 0x1a, 0xee}},
{InitIgn, 3, {0x00, 0x1c, 0xed}},
{TrackInfo, 5, {0x1b, 0xe0, 0x01, 0x08, 0x10}}, //evtl no 0x10?
{TrackInfo, 4, {0x1b, 0xe0, 0x01, 0x08}}, //evtl no 0x10?
{CartInfo, 2, {0x1e, 0xef}},
{NextTrack, 4, {0x1b, 0x2d, 0x40, 0x01}},
{PrevTrack, 4, {0x1b, 0x2d, 0x00, 0x01}},
{NextDisc, 3, {0x1a, 0x50, 0x41}},
{PrevDisc, 3, {0x1a, 0x50, 0x01}},
{NopAck, 2, {0x19, 0x2f}}, //PowerUp
{NopAck, 2, {0x19, 0x22}}, //PowerDown
{NopAck, 2, {0x19, 0x29}}, //FastFwd
{NopAck, 2, {0x19, 0x26}}, //FastRew
{NopAck, 2, {0x19, 0x2e}}, //ScanMode
{NopAck, 2, {0x19, 0x52}} //RndMode
{PowerUp, 2, {0x19, 0x2f}}, //PowerUp
{PowerDown, 2, {0x19, 0x22}}, //PowerDown
{FFWD, 2, {0x19, 0x29}}, //FastFwd
{FREW, 2, {0x19, 0x26}}, //FastRew
{ScanMode, 2, {0x19, 0x2e}}, //ScanMode
{RndMode, 2, {0x19, 0x52}} //RndMode
};

#ifdef ENABLE_SERIAL
Expand All @@ -52,6 +58,12 @@ void printCmd (Cmd c) {
PCMD (NopAck);
PCMD (InitWaiting);
PCMD (Wait);
PCMD (PowerUp);
PCMD (PowerDown);
PCMD (FFWD);
PCMD (FREW);
PCMD (ScanMode);
PCMD (RndMode);
}
#undef PCMD
}
Expand Down
59 changes: 46 additions & 13 deletions emulator/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,65 @@ inline void sendByteRaw (const unsigned char b) {
} else {
writePin (DATA_PIN, 0);
}

if (readPin (CLK_PIN)) {
while (readPin (CLK_PIN)) {
blinkTX(Fast);
}
}
while (!readPin (CLK_PIN))
{
blinkTX(Fast);
}
}
}

while (readPin (CLK_PIN)) { blinkTX(Fast); };
while (!readPin (CLK_PIN)) { blinkTX(Fast); };
inline void sendByteRawClkd (const unsigned char b) {
for (int bitPos = 7; bitPos >= 0; bitPos--) {
writePin (CLK_PIN, 0);
delayMicroseconds(8);

bool val = b & (1 << bitPos);
if (val) {
writePin (DATA_PIN, 1);
} else {
writePin (DATA_PIN, 0);
}

writePin (CLK_PIN, 1);
delayMicroseconds(8);
}
}

void sendBuffer (unsigned char* buf, int len, int offset = 0) {
return;
void sendBuffer (unsigned char* buf, int len) {
unsigned char b;

//output mode
intFastOff;
ioCfgData (false); //output mode
ioCfgData (false);
ioCfgClock (false);
ioCfgBusy (true);

for (int bytePos = offset; bytePos < len; bytePos++) {
sendByteRaw (buf[bytePos]);
for (int bytePos = 0; bytePos < len; bytePos++) {
b = buf[bytePos];
sendByteRawClkd (b);
}


//input mode
ioCfgBusy (false);
ioCfgClock (true);
ioCfgData (true);
intFastOn;

blinkClear ();

#ifdef ENABLE_SERIAL
Serial.print ("SENT BUFFER: ");
for (int bytePos = offset; bytePos < len-1; bytePos++) {
Serial.print (buf[bytePos]);
Serial.print ("> ");
for (int bytePos = 0; bytePos < len - 1; bytePos++) {
Serial.print (buf[bytePos], HEX);
Serial.print (" ");
}
Serial.println (buf[len-1]);
Serial.println (buf[len-1], HEX);
#endif
}

Expand Down Expand Up @@ -169,7 +202,7 @@ void setup_comm () {
g_inCurrentByte = 0x0;

ioCfgData (true);
ioCfgClock ();
ioCfgClock (true);
attachInterrupt (CLK_INT, isr_clock, RISING);
}

4 changes: 2 additions & 2 deletions emulator/config_uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define CLK_INT 0
#define CLK_INTx INT0

#define TXLED0
#define TXLED1
#define TXLED0 digitalWrite (13, LOW)
#define TXLED1 digitalWrite (13, HIGH)
#define RXLED0
#define RXLED1
84 changes: 44 additions & 40 deletions emulator/devices.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
struct device_t {
const unsigned char name[4];
const unsigned char baseId;
const unsigned char respId;
bool enabled;
bool initialized;
unsigned char info[15];
};

//init, {TRACK + CART} 0 1 2 3 4 5 6 7 8 ||| 9 10 11 12 13 14
#define DEV_DEFAULT false, {0x00, 0x02, 0x00, 0x01, 0x80, 0x01, 0xff, 0x60, 0x60, 0x00, 0x0f, 0xff, 0x4a, 0xfc, 0xff }
/*
0 ?
1 02 stop, 08 play
2 08 ? 0f rand
3 [01..0a] CDx
4 track related?
5 track related?
6 ?
7 time min
8 time sec
*/

#ifdef MDC
#define ENABLE_MDC true
#else
#define ENABLE_MDC false
#endif

#ifdef CDC
#define ENABLE_CDC true
#else
#define ENABLE_CDC false
#endif

#define g_devicesSize 2
struct device_t g_devices[g_devicesSize] = {
{"MDC", 0xd8, 0xde, ENABLE_MDC, DEV_DEFAULT} //MD-C
, {"CDC", 0x8e, 0xee, ENABLE_CDC, DEV_DEFAULT} //CD-C
};
struct device_t {
const unsigned char name[4];
const unsigned char baseId;
const unsigned char respId;
bool enabled;
bool initialized;
unsigned char trackInfo[9];
unsigned char cartInfo[6];
};

//init, {TRACK}, {CART} 0 1 2 3 4 5 6 7 8 ||| 9 10 11 12 13 14
#define DEV_DEFAULT false, {0x00, 0x02, 0x00, 0x01, 0x80, 0x01, 0xff, 0x60, 0x60}, {0x00, 0x0f, 0xff, 0x4a, 0xfc, 0xff }
/*
0 ?
1 02 stop, 08 play
2 08 ? 0f rand
3 [01..0a] CDx
4 track related?
5 track related?
6 ?
7 time min
8 time sec
*/

#ifdef MDC
#define ENABLE_MDC true
#else
#define ENABLE_MDC false
#endif

#ifdef CDC
#define ENABLE_CDC true
#else
#define ENABLE_CDC false
#endif

#define g_devicesSize 2
struct device_t g_devices[g_devicesSize] = {
{"MDC", 0xd8, 0xde, ENABLE_MDC, DEV_DEFAULT} //MD-C
, {"CDC", 0xe8, 0xee, ENABLE_CDC, DEV_DEFAULT} //CD-C
};

unsigned char fakeCI[6] = {0x00, 0x0f, 0xff, 0x4a, 0xfc, 0xff };
unsigned char fakeTI[9] = {0x00, 0x02, 0x00, 0x01, 0x80, 0x01, 0xff, 0x60, 0x60};
4 changes: 2 additions & 2 deletions emulator/emulator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void setup () {
g_printHex = false;
Serial.begin(230400,SERIAL_8N1);
Serial.setTimeout (5000);
char x;
Serial.readBytes (&x, 1);
// char x;
// Serial.readBytes (&x, 1);
Serial.println (F("Starting up!"));
#endif
blinkClear ();
Expand Down
11 changes: 8 additions & 3 deletions emulator/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ inline void ioCfgBusy (bool input) {
}
}

inline void ioCfgClock () {
SET0 (DDRx, CLK_PIN); //input
SET1 (PORTx, CLK_PIN); //pull up
inline void ioCfgClock (bool input) {
if (input) {
SET0 (DDRx, CLK_PIN); //input
SET1 (PORTx, CLK_PIN); //pull up
} else {
SET1 (DDRx, CLK_PIN); //output
SET1 (PORTx, CLK_PIN); //default to HIGH
}
}
30 changes: 20 additions & 10 deletions emulator/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ bool handleCmd (Cmd in) {
//do nothing, just wait...
break;

case PowerUp:
case PowerDown:
case FFWD:
case FREW:
case ScanMode:
case RndMode:
case NopAck:
sendAck ();
break;
Expand Down Expand Up @@ -95,44 +101,48 @@ bool handleCmd (Cmd in) {
return false;

case TrackInfo:
sendBuffer (g_dev->info, 9);
sendBuffer (g_dev->trackInfo, 9);
// sendBuffer (fakeTI, 9);
break;

case CartInfo:
sendBuffer (g_dev->info, 6, 9);
sendBuffer (g_dev->cartInfo, 6);
// sendBuffer (fakeCI, 6);
break;

case NextTrack:
{
unsigned char n = g_dev->info[5]+1;
unsigned char n = g_dev->trackInfo[5];
n++;
if (n > 0x99) n = 0x99;
if ((n & 0x0f) > 0x09) n += 6;
g_dev->info[5] = n;
g_dev->trackInfo[5] = n;
break;
}

case PrevTrack:
{
char n = g_dev->info[5]-1;
char n = g_dev->trackInfo[5];
n--;
if (n == 0x00) n = 0x01;
if ((n & 0x0f) == 0x0f) n -= 6;
g_dev->info[5] = n;
g_dev->trackInfo[5] = n;
break;
}

case PrevDisc:
case NextDisc:
{
char n = g_dev->info[3];
char n = g_dev->trackInfo[3];
if (c == NextDisc)
n++;
else
n--;

if (n > 0x0a)
n = 0x0a;
g_dev->info[3] = n;
g_dev->info[5] = 0x01;
g_dev->trackInfo[3] = n;
g_dev->trackInfo[5] = 0x01;
sendAck ();
break;
}
Expand All @@ -142,4 +152,4 @@ bool handleCmd (Cmd in) {

g_currentCmd = Wait;
return false;
}
}

0 comments on commit 3be2a3c

Please sign in to comment.