From bf91ff680d86339637232da5691b592f64899c5a Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Tue, 18 Feb 2025 08:48:25 +0100 Subject: [PATCH] Added LCD window --- pat80-emulator/main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pat80-emulator/main.c b/pat80-emulator/main.c index d2d99ba..634bbeb 100644 --- a/pat80-emulator/main.c +++ b/pat80-emulator/main.c @@ -29,6 +29,7 @@ typedef struct { Z80 cpu; WINDOW *terminal_win; WINDOW *status_win; + WINDOW *lcd_win; } Machine; @@ -106,6 +107,7 @@ static zuint8 machine_cpu_in(Machine *self, zuint16 port) { refresh(); wrefresh(self->terminal_win); wrefresh(self->status_win); + wrefresh(self->lcd_win); } @@ -123,8 +125,8 @@ static void machine_cpu_out(Machine *self, zuint16 port, zuint8 value) { // Port 1 (0x20 to 0x3F): sound card (sn76489) wprintw(self->status_win, "sound_cmd[%#04x]\n", value); } else if (decoded <= 0x5F) { - // Port 2 (0x40 to 0x5F) - wprintw(self->status_win, "IO_ERROR_OUT: No device at port 2\n"); + // Port 2 (0x40 to 0x5F): lcd display 40x4 (mod. TM404A, based on 2 KS0066 chips, each one controlling 2 rows) + wprintw(self->lcd_win, "%c", value); } else if (decoded <= 0x7F) { // Port 3 (0x60 to 0x7F) wprintw(self->status_win, "IO_ERROR_OUT: No device at port 3\n"); @@ -148,6 +150,7 @@ static void machine_cpu_out(Machine *self, zuint16 port, zuint8 value) { refresh(); wrefresh(self->terminal_win); wrefresh(self->status_win); + wrefresh(self->lcd_win); } @@ -210,6 +213,7 @@ int main(int argc, char *argv[]) { start_color(); // Use colors init_pair(1, COLOR_WHITE, COLOR_BLUE); // Terminal window color init_pair(2, COLOR_YELLOW, COLOR_BLACK); // Status window color + init_pair(3, COLOR_BLACK, COLOR_GREEN); // LCD window color int x,y; getmaxyx(stdscr, y,x); @@ -219,13 +223,16 @@ int main(int argc, char *argv[]) { /*zusize*/ .cycles = 0, /*Z80*/ .cpu = pat80Cpu, .terminal_win = newwin(TERMINAL_HEIGHT, TERMINAL_WIDTH, INSTRUCTION_WINDOW_HEIGHT, 0), - .status_win = newwin(y, x - TERMINAL_WIDTH - SPACING_BETWEEN_WINDOWS, INSTRUCTION_WINDOW_HEIGHT, TERMINAL_WIDTH + SPACING_BETWEEN_WINDOWS) + .status_win = newwin(y, x - TERMINAL_WIDTH - SPACING_BETWEEN_WINDOWS, INSTRUCTION_WINDOW_HEIGHT, TERMINAL_WIDTH + SPACING_BETWEEN_WINDOWS), // To right of terminal window + .lcd_win = newwin(4, 40, INSTRUCTION_WINDOW_HEIGHT + TERMINAL_HEIGHT + SPACING_BETWEEN_WINDOWS, 0) // Below terminal window }; wbkgd(pat80.terminal_win, COLOR_PAIR(1)); // Ncurses: set terminal window color wbkgd(pat80.status_win, COLOR_PAIR(2)); + wbkgd(pat80.lcd_win, COLOR_PAIR(3)); scrollok(pat80.terminal_win, TRUE); // Ncurses: Allow scrolling when reached end of window scrollok(pat80.status_win, TRUE); + scrollok(pat80.lcd_win, FALSE); attron(A_BOLD); // Print instructions printw("Emulator commands\n"); attroff(A_BOLD); @@ -251,6 +258,7 @@ int main(int argc, char *argv[]) { // Stop ncurses delwin(pat80.terminal_win); delwin(pat80.status_win); + delwin(pat80.lcd_win); endwin(); return 0; }