uint16_t ti89_get_word(uint32_t adr) { // RAM access if(IN_BOUNDS(0x000000, adr, 0x1fffff)) { return get_w(tihw.ram, adr, RAM_SIZE_TI89 - 1); } // FLASH access else if(IN_BOUNDS(0x200000, adr, 0x5fffff)) { return get_w(tihw.rom, adr, ROM_SIZE_TI89 - 1) | wsm.ret_or; } // memory-mapped I/O else if(IN_BOUNDS(0x600000, adr, 0x6fffff)) { return io_get_word(adr); } // memory-mapped I/O (hw2) else if(IN_RANGE(adr, 0x700000, IO2_SIZE_TI89)) { return io2_get_word(adr); } return 0x1414; }
uint16_t ti89t_get_word(uint32_t adr) { // RAM access if(IN_BOUNDS(0x000000, adr, 0x03ffff) || IN_BOUNDS(0x200000, adr, 0x23ffff) || IN_BOUNDS(0x400000, adr, 0x43ffff)) { return get_w(tihw.ram, adr, 0x03ffff); } // FLASH access else if(IN_BOUNDS(0x800000, adr, 0xbfffff)) { return FlashReadWord(adr); } // memory-mapped I/O else if(IN_BOUNDS(0x600000, adr, 0x6fffff)) { return io_get_word(adr); } // memory-mapped I/O (hw2) else if(IN_RANGE(adr, 0x700000, IO2_SIZE_TI89T)) { return io2_get_word(adr); } // memory-mapped I/O (hw3) else if(IN_RANGE(adr, 0x710000, IO3_SIZE_TI89T)) { return io3_get_word(adr); } return 0x1414; }
void * receiver(void *args) { char word[SZ]; int i; struct line *on; struct alias *a; while(1) { if(io_get_word(word) <= 0) { usleep(300000); continue; } // queue management ui_print("<-- %s\n", word); // trigger on event exec_on(word); if(strcmp(wait_queue_head(), "bin") == 0) { bin = atoi(word); for(i = 0;; ) { a = get_alias("bin", i++); if(!a) break; if(a->num == bin) a->arg++; } wait_queue_pop(); } else if(strcmp(word, wait_queue_head()) == 0 || strcmp(wait_queue_head(), "X") == 0) { wait_queue_pop(); } } return NULL; }
uint32_t io_get_long(uint32_t addr) { return (((uint32_t)io_get_word(addr))<<16) | io_get_word(addr+2); }
int exec_line(int argc, char *argv[]) { struct alias *al; int i; if(!argc) return 0; ui_print("do action: "); for(i = 0; i < argc; i++) ui_print("%s ", argv[i]); ui_print("\n"); if(strcmp(argv[0], "load") == 0) { ui_animation(1); } else if(strcmp(argv[0], "unload") == 0) { ui_animation(3); } else if(strcmp(argv[0], "poweron") == 0) { power_state = 1; } else if(strcmp(argv[0], "poweroff") == 0) { power_state = 1; } else if(strcmp(argv[0], "putbin") == 0) { for(i = 0;;) { al = get_alias("bin", i++); if(al) ui_bin_update(i, al->arg); else break; } al = get_alias("timeout", 0); if(al) ui_bin_update(i, al->arg); } else if(strncmp(argv[0], "send", 4) == 0) { if(strcmp(argv[0], "send_txt") == 0) { io_send("\002"); ui_print("--> <STX>\n"); } for(i = 1; i < argc; i++) { const char *s = argv[i]; if(strcmp(s, "power_state") == 0) s = power_state? "1": "NULL"; al = get_alias(s, 0); ui_print("--> %s\n", al? al->str: s); io_send(al? al->str: s); } if(strcmp(argv[0], "send_txt") == 0) { io_send("\003"); ui_print("--> <ETX>\n"); } } else if(strcmp(argv[0], "wait") == 0) { for(i = 1; i < argc; i++) wait_queue_add_tail(argv[i]); for(;!wait_queue_empty(); ui_animation(2)); } else if(strcmp(argv[0], "wait_timeout") == 0) { struct timeval a, b, d; int t; al = get_alias("timeout", 0); t = al? al->num: TIMEOUT; for(i = 1; i < argc; i++) wait_queue_add_tail(argv[i]); gettimeofday(&a, NULL); for(;!wait_queue_empty(); ui_animation(2)) { gettimeofday(&b, NULL); timersub(&b, &a, &d); if(d.tv_sec > t) { ui_print("timeout for waiting %s\n", wait_queue_head()); al->arg++; return -1; } } } else if(strcmp(argv[0], "handshake") == 0) { char word[SZ]; ui_print("--> %s\n", argv[1]); io_send(argv[1]); while(io_get_word(word) <= 0); ui_print("<-- %s\n", word); if(strcmp(word, argv[2]) != 0) return -1; } return 0; }