From d74e6f4f5d10befe745156bd2525b32679eab8ee Mon Sep 17 00:00:00 2001 From: Brad Grantham Date: Mon, 14 Nov 2016 13:41:57 -0800 Subject: [PATCH] Better textport output and timing Only output the textport every 16ms, and only if it's changed. Be more consistent with throttling to ~1.023MHz by using a constant. Fix bug where timeslice wasn't reduce when # of instructions was reduced --- apple2e.cpp | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/apple2e.cpp b/apple2e.cpp index ffd7481..37418d1 100644 --- a/apple2e.cpp +++ b/apple2e.cpp @@ -84,15 +84,16 @@ const int textport_row_base_addresses[] = 0x7D0, }; -void textport_change(unsigned char *textport) +bool textport_changed = false; +unsigned char textport[24][40]; + +void textport_display() { - printf("TEXTPORT:\n"); printf("------------------------------------------\n"); for(int row = 0; row < 24; row++) { printf("|"); for(int col = 0; col < 40; col++) { - int addr = textport_row_base_addresses[row] - 0x400 + col; - int ch = textport[addr] & 0x7F; + int ch = textport[row][col]; printf("%c", isprint(ch) ? ch : '?'); } printf("|\n"); @@ -100,6 +101,18 @@ void textport_change(unsigned char *textport) printf("------------------------------------------\n"); } +void textport_change(unsigned char *region) +{ + for(int row = 0; row < 24; row++) { + for(int col = 0; col < 40; col++) { + int addr = textport_row_base_addresses[row] - 0x400 + col; + int ch = region[addr] & 0x7F; + textport[row][col] = ch; + } + } + textport_changed = true; +} + struct region { string name; @@ -1420,6 +1433,8 @@ string read_bus_and_disassemble(bus_controller &bus, int pc) return dis; } +int millis_per_slice = 16; + int main(int argc, char **argv) { char *progname = argv[0]; @@ -1497,10 +1512,10 @@ int main(int argc, char **argv) if(have_key) { if(key == '') { - debugging = true; - clear_strobe(); - stop_keyboard(); - continue; + debugging = true; + clear_strobe(); + stop_keyboard(); + continue; } else { mainboard->enqueue_key(key); clear_strobe(); @@ -1508,7 +1523,8 @@ int main(int argc, char **argv) } chrono::time_point then; - for(int i = 0; i < 25575; i++) { // ~ 1/10th second + const int inst_per_slice = 255750 * millis_per_slice / 1000; + for(int i = 0; i < inst_per_slice; i++) { string dis = read_bus_and_disassemble(bus, cpu.pc); if(debug & DEBUG_DECODE) printf("%s\n", dis.c_str()); @@ -1517,10 +1533,14 @@ int main(int argc, char **argv) else cpu.cycle(bus); } + if(textport_changed) { + textport_display(); + textport_changed = false; + } chrono::time_point now; auto elapsed_millis = chrono::duration_cast(now - then); - this_thread::sleep_for(chrono::milliseconds(100) - elapsed_millis); + this_thread::sleep_for(chrono::milliseconds(millis_per_slice) - elapsed_millis); } else { @@ -1552,6 +1572,10 @@ int main(int argc, char **argv) step6502(); else cpu.cycle(bus); + if(textport_changed) { + textport_display(); + textport_changed = false; + } } } }