+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(" 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 via XMODEM: ");
+ msg_clr();
+ while (!sci_have_packet); /* spin */
+ if (!my_strncmp("YES", (char*)sci_rx_buf, 3)) 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 (!xmodem_send_packet((char*)p, 128)) {
+ aborted = 1;
+ break;
+ }
+ p += 128;
+ if (p + 128 > end) {
+ /* send partial packet */
+ if (!xmodem_send_packet((char*)p, end-p)) aborted = 1;
+ break;
+ }
+ }
+
+ xmodem_finish_xfer();
+ sci_doing_xmodem = 0;
+ if (aborted)
+ send_string(CRLF "Transfer aborted." CRLF);
+ else
+ send_string(CRLF "Transfer complete." CRLF);
+}
+