#include #include #include #include "addrs.h" #include "screen.h" #include "edbox.h" /* TODO: tab completion */ // static int edbox_visible = 0; /* don't think we'll ever need it */ static u16 edbox_pos; /* range 0 to EDBOX_SIZE - 1 */ void (*edbox_callback)(void); static void hide_cursor(void) { edit_box[edbox_pos] &= 0x7f; } static void show_cursor(void) { edit_box[edbox_pos] |= 0x80; } void edbox_clear(void) { memset(edit_box, 0, EDBOX_SIZE); edbox_pos = 0; show_cursor(); } void edbox_show(void) { u16 addr; if(edbox_pos < 80) addr = (u16)edit_box; else addr = (u16)edit_box + edbox_pos - 79; scr_waitvcount(116); *dlist_bottom_lms = addr; } void edbox_hide(void) { scr_refresh(); } void edbox_putc(char c) { if(!c) return; /* no inserting nulls */ if((c != CH_EOL) && (edbox_pos == EDBOX_SIZE - 1)) return; edit_box[edbox_pos++] = c; edbox_show(); } static void special_keystroke(char c) { OS.ch = 0xff; edbox_putc(c); } static void backspace(void) { if(!edbox_pos) return; edit_box[--edbox_pos] = 0; edbox_show(); } static void del_word(void) { } static void normal_keystroke(void) { char c; c = cgetc(); switch(c) { case CH_EOL: edbox_putc(c); if(edbox_callback) (*edbox_callback)(); /* fall thru */ case CH_CLR: edbox_hide(); /* fall thru */ case CH_DELLINE: case 0x15: /* ^U */ edbox_clear(); break; case CH_DEL: backspace(); break; case 0x17: /* ^W */ del_word(); break; default: edbox_putc(c); break; } } void edbox_keystroke(void) { char c; hide_cursor(); edbox_show(); OS.invflg = c = 0; /* XXX: these keys don't click. */ switch(OS.ch) { case 0xa0: /* key: ctrl [ */ c = 0x7b; /* ascii: { */ break; case 0xa2: /* key: ctrl ] */ c = 0x7d; /* ascii: } */ break; case 0x1c: /* key: ESC */ c = 0x60; /* ascii: ` */ break; case 0x5c: /* key: shift ESC */ case 0x9c: /* key: ctrl ESC */ c = 0x7e; /* ascii: ~ */ break; case 0x27: /* atari key */ case 0x67: /* ...w/shift */ case 0x97: /* ...w/ctrl */ return; /* ignore it! */ break; default: break; } if(c) { special_keystroke(c); } else { normal_keystroke(); } show_cursor(); }