Fixed backspace behavior

git-svn-id: svn+ssh://svn.phoenixbox.net/svn/apple1/trunk@92 64f78de7-aa59-e511-a0e8-0002a5492df0
This commit is contained in:
Daniel Loffgren 2016-04-09 23:53:31 +00:00
parent ad5f7d6a45
commit bb83465723
1 changed files with 19 additions and 9 deletions

View File

@ -17,6 +17,8 @@
#define KEYBOARD_READY 0xFF // This just needs to meet the requirements of being a negative number in the eyes of the 6502 #define KEYBOARD_READY 0xFF // This just needs to meet the requirements of being a negative number in the eyes of the 6502
#define KEYBOARD_NOTREADY 0x00 #define KEYBOARD_NOTREADY 0x00
#define ANSI_BGCOLOR_GREEN "\x1b[42;1m" #define ANSI_BGCOLOR_GREEN "\x1b[42;1m"
#define CURSES_BACKSPACE 0x7F
#define A1_BACKSPACE 0xDF
void saveFreeze(a1pia *pia, const char *fname) { void saveFreeze(a1pia *pia, const char *fname) {
FILE *f = fopen(fname, "w"); FILE *f = fopen(fname, "w");
@ -71,15 +73,23 @@ void loadFreeze(a1pia *pia, const char *fname) {
fclose(f); fclose(f);
} }
char asciiCharFromCursesKey(int key) { unsigned char asciiCharFromCursesKey(int key) {
return (char)key; return (unsigned char)key;
} }
char asciiCharFromA1Char(uint8_t c) { unsigned char asciiCharFromA1Char(uint8_t c) {
return (char)c & ~0x80; if (c == A1_BACKSPACE) {
return CURSES_BACKSPACE;
}
return (unsigned char)c & ~0x80;
} }
uint8_t a1CharFromAsciiChar(char c) { uint8_t a1CharFromAsciiChar(unsigned char c) {
if (c == CURSES_BACKSPACE) {
return A1_BACKSPACE;
}
if (c >= 'a' && c <= 'z') { if (c >= 'a' && c <= 'z') {
c -= 0x20; c -= 0x20;
} }
@ -89,14 +99,14 @@ uint8_t a1CharFromAsciiChar(char c) {
void videoWriteCharCallback(struct _v6502_memory *memory, uint16_t offset, uint8_t value, a1pia *context) { void videoWriteCharCallback(struct _v6502_memory *memory, uint16_t offset, uint8_t value, a1pia *context) {
if (value) { if (value) {
char c = asciiCharFromA1Char(value); unsigned char c = asciiCharFromA1Char(value);
if (c == '\r') { if (c == '\r') {
waddch(context->screen, '\n'); waddch(context->screen, '\n');
} }
if (c == 0x7f) { if (c == CURSES_BACKSPACE) {
int y, x; int y, x;
getyx(context->screen, y, x); getyx(context->screen, y, x);
if (x < 0) { if (x > 0) {
move(y, x-1); move(y, x-1);
} }
delch(); delch();
@ -140,7 +150,7 @@ uint8_t keyboardReadReadyCallback(struct _v6502_memory *memory, uint16_t offset,
wmove(context->screen, y, x); wmove(context->screen, y, x);
} }
int c = getch(); int c = wgetch(context->screen);
if (context->suspended) { if (context->suspended) {
printf("%c\r\n", c); printf("%c\r\n", c);
} }