X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=ROM2%2Fmain_basic.c;h=27d6e0bee9ddfb90af0faad6397dc422adce830d;hb=dc87be12e6cb8428ab33c0984c5f871e6e1c5587;hp=5c35aab32751094018ce99b0d0bcfdecbdfdc68a;hpb=f5bc521c83d95d35e852747402a44d1411252c2b;p=uccvend-snackrom.git diff --git a/ROM2/main_basic.c b/ROM2/main_basic.c index 5c35aab..27d6e0b 100644 --- a/ROM2/main_basic.c +++ b/ROM2/main_basic.c @@ -13,6 +13,8 @@ #include "motors.h" #include "sci.h" #include "vend.h" +#include "xmodem.h" +//#include "sha1.h" u8 last_standalone; u8 last_switch_input; @@ -182,7 +184,7 @@ u8 hexchar2u8(char b) { char nibble2hexchar(u8 b) { if (b <= 9) return b+'0'; - if (b >= 10 && b <= 15) return b+'A'; + if (b >= 10 && b <= 15) return b+'A'-10; return 'X'; } @@ -203,7 +205,7 @@ void do_chime() { if (sci_rx_buf[1] == '\0') chime_start(); else if (sci_rx_buf[2] != '\0' && sci_rx_buf[3] == '\0') - chime_start(hex2u8(sci_rx_buf[1], sci_rx_buf[2])); + chime_for(hex2u8(sci_rx_buf[1], sci_rx_buf[2])); else { send_string("510 Unknown chime duration." CRLF); return; @@ -289,6 +291,8 @@ void moo() { " -------------| " CRLF " | | | | " CRLF " <__/ \\__>" CRLF +"" CRLF +" ... Where's the cheese?" CRLF ); } @@ -304,10 +308,73 @@ void help() { " B[nn] beep for a duration nn (optional)" CRLF " S[...] query all internal switch states" CRLF " H[...] this help screen" CRLF + " GETROM download the ROM source code using xmodem" CRLF "Comments start with a #" CRLF ); } +extern const char _rom_src_data[]; +extern const u16 _rom_src_len; +void getrom() { + if (!my_strncmp("ETROM", (char*)sci_rx_buf+1, 5)) { + unknown_command(); + return; + } + char s[4]; + send_string("Writing to serial port (maybe). Size is 0x"); + send_string(u82hex(_rom_src_len >> 8)); + send_string(u82hex(_rom_src_len & 0xff)); + send_string("@0x"); + send_string(u82hex((u16)(&_rom_src_data) >> 8)); + send_string(u82hex((u16)(&_rom_src_data) & 0xff)); + send_string(" with signature "); + s[0] = _rom_src_data[0]; + s[1] = _rom_src_data[1]; + s[2] = _rom_src_data[2]; + s[3] = '\0'; + send_string(s); + send_string(CRLF " Type YES to download rom.tar.bz2 via XMODEM: "); + msg_clr(); + while (!sci_have_packet); /* spin */ + if (!my_strncmp("YES", (char*)sci_rx_buf, 3)) { + send_string(CRLF "Transfer cancelled." CRLF); + return; + } + + sci_init(); + sci_doing_xmodem = 1; + if (!xmodem_init_xfer()) { + sci_doing_xmodem = 0; + send_string("XMODEM init failed. Nobody's listening :(" CRLF); + return; + } + char *p = (char*)_rom_src_data; + char *end = (char*)_rom_src_data+_rom_src_len; + bool aborted = 0; + while (1) { + if (p + 128 > end) { + /* send partial packet */ + if (!xmodem_send_packet((char*)p, end-p)) aborted = 1; + break; + } if ((u16)p == 0xb600) { + /* we have an eeprom here. skip it. */ + p += 0x0200; + continue; + } else if (!xmodem_send_packet((char*)p, 128)) { + aborted = 1; + break; + } + p += 128; + } + + xmodem_finish_xfer(); + sci_doing_xmodem = 0; + if (aborted) + send_string(CRLF "Transfer aborted." CRLF); + else + send_string(CRLF "Transfer complete." CRLF); +} + void quit() { if (my_strncmp("UIT", (char*)sci_rx_buf+1, 3)) send_string("013 You can't quit you doofus." CRLF); @@ -315,6 +382,9 @@ void quit() { unknown_command(); } +//SHA1_CTX ctx; +//u8 sha1_digest[SHA1_SIGNATURE_SIZE]; + int main() { u8 i; for (i = 0; i < 11; i++) @@ -336,7 +406,6 @@ int main() { set_msg(" CRUEL "); - //comm_init(); //coinmech_init(); sci_init(); keypad_init(); @@ -394,6 +463,11 @@ int main() { } if (sci_have_packet) { + if (must_verify()) { + //SHA1_Init(&ctx); + //SHA1_Update(&ctx, sci_rx_buf, my_strlen(sci_rx_buf)); + //SHA1_Final(sha1_digest, &ctx); + } switch (sci_rx_buf[0]) { case '\0': case '#': @@ -429,6 +503,9 @@ int main() { case 'Q': quit(); break; + case 'G': + getrom(); + break; default: // shurg unknown_command();