Programming the original JP1 remote controls with Arduino

Part 2:

void cmd_lookup() {
switch ((char) jp1_cmd) {
case 'R': R(); break;
case 'S': S(); break;
case 'C': C(); break;
case 'E': E(); break;
case 'I': I(); break;
case 'V': V(); break;
case 'd': d(); break;
case 'f': f(); break;
case 'z': z(); break;
case 't': t(); break;
case '1': _1(); break;
case '2': _2(); break;
case '4': C04(); break;
case '8': C08(); break;
case '6': C16(); break;
case '3': C32(); break;
case 'x': x(); break;
case '?': info(); break;
default: break;
};
};

void send_msg(char s) {
int i = 0;
while (s
) {*
jp1_chk ^= s*;
_ SerTx(s);
i++;
}
}
void ACK() {
SerTx(6);
}
// --- Ping*
// -> E
// <-
void E() {
* ACK();
}
// --- Identity*
// -> I
// <- [data]
void I() {
* jp1_chk = 0;
send_msg("eeprom");
SerTx(jp1_chk);*

}
// --- Version
// -> V
// <- [data]
//
// - Flash size is in units of 128 bytes. Get max MSB of EE address * 2_

// - EEPROM base address MSB
// - EEPROM base address LSB
void V() {
jp1_chk = 2 * ee_size;
* SerTx(jp1_chk);
_ SerTx(0);
SerTx(0);_
SerTx(jp1_chk);
_}
// --- Read*
// -> R
// <- r [data]
void R() {
* jp1_chk=(byte)'R';
get_addr_len();*

* byte chk = SerRx();_
if ( chk ^ jp1_chk ) {
// bad_checksum*

* return;*
* }*
* jp1_chk = (byte)'r';
SerTx(jp1_chk);
for (int i=0; i<jp1_len; i++) {
byte b = eeprom_read_byte(DEVADDR, i + addrl + 256addrh);

* jp1_chk ^= b;
_ SerTx(b);
}_
SerTx(jp1_chk);
_}
// --- Write*
// -> S [data]
// <-
void S() {
* jp1_chk=(byte)'S';*
* byte b;_
get_addr_len();*

* for (int i=0; i<jp1_len; i++) {
_ b = SerRxChk();_
data_buf=b;
_ }
b = SerRx();_

if (b ^ jp1_chk) {
// bad_checksum*

* return;*
* }*
* ACK();*
eeprom_write_pages(DEVADDR, addrl + addrh * 256, jp1_len, data_buf);
}
// --- Erase
// -> C
// <-
void C() {
* get_addr_len();
_ countl = SerRx();_
jp1_chk ^= countl;
_ byte b = SerRx();_
if (b ^ jp1_chk) {
// bad_checksum*

* } else {*
* // add code to clear EEPROM here*
* ACK();*
* }*
}
// --- d - Display EEPROM contents
// code for content dump taken from davekw7x (not from K. Timmerman code) ;
void d() {
* SerCRLF();*

unsigned numPages = (ee_size * 2 * 256) / 16;

* for (unsigned i = 0; i < numPages; i++) {*
* byte buffer[16]; // Hold a page of EEPROM*
* char outbuf[6]; //Room for three hex digits and ':' and ' ' and '\0'*
* sprintf(outbuf, "%03x: ", i);*
_ Serial.print(outbuf);
* for (int j = 0; j < 16; j++) {_
buffer[j]=eeprom_read_byte(DEVADDR, j+i16);

* if (j == 8) {*
_ Serial.print(" ");
* }
sprintf(outbuf, "%02x ", buffer[j]);
Serial.print(outbuf);
}
Serial.print(" |");
for (int j = 0; j < 16; j++) {
if (isprint(buffer[j])) {
Serial.print(buffer[j]);
}
else {
Serial.print('.');
}
}
Serial.println("|");
}
SerCRLF();
}
// 1 - One byte addressing*

void _1() {
* fTwoByteAddress = false;
ACK();
}
// 2 - Two byte addressing*

void _2() {
* fTwoByteAddress=true;
ACK();
}
// 4 - 24C04 - 512 byte EEPROM*

void C04() {
* ee_size = 0x02;
1();*
}

// 8 - 24C08 - 1K byte EEPROM
void C08() {
* ee_size = 0x04;
1();*
}
// 6 - 24C16 - 2K byte EEPROM
void C16() {
* ee_size = 0x08;
1();*
}

// 3 - 24C32 - 4K byte EEPROM
void C32() {
* ee_size = 0x10;
2();*
}
// f - Fill EEPROM with 0xFF
void f() {
* ee_fill = 0xFF;*
* fFillTestPattern = false;
fill();
}
// z - Fill EEPROM with 0x00*

void z() {
* ee_fill = 0;*
* fFillTestPattern = false;
fill();
}
// t - Fill EEPROM with test pattern*

void t() {
* fFillTestPattern = true;
fill();
}
// x - Release remote reset*

void x() {
}
[/quote]_