// ncurses.c // Implements interface.h // Provides an in-terminal interface to the emulator. #include"interface.h" #include"signetics.c" #include int TermX = 0; int TermY = 0; void TerminalInit() { initscr(); cbreak(); noecho(); curs_set(0); TerminalShiftRegister = (byte*)malloc(960); TerminalShiftRegisterPosition = TerminalShiftRegister; TerminalShiftRegisterOffset = 0; } void TerminalClose() { free(TerminalShiftRegister); curs_set(0); endwin(); } void TerminalInput(char n) { mvaddch(TermY,TermX,n); *TerminalShiftRegisterPosition = n; TerminalShiftRegisterPosition++; if (TerminalShiftRegisterPosition >= (TerminalShiftRegister + 960)) TerminalShiftRegisterPosition = TerminalShiftRegister; TermX++; if (n == KEY_ENTER) { TermY++; } if (TermX >= 40) { TermX = 0; TermY++; } if (TermY >= 24) { TerminalShiftRegisterOffset += 40; // Discard first line if (TerminalShiftRegisterOffset >= 960) TerminalShiftRegisterOffset = TerminalShiftRegister; byte *offset = TerminalShiftRegister + TerminalShiftRegisterOffset; // For every position, fill with contents of the terminal shift register for (int i = 0; i < 23; i++) { for (int j = 0; j < 40; j++) { if (offset >= (TerminalShiftRegister + 960)) offset -= 960; mvaddch(i,j, *(offset)); offset++; }} TermY = 23; TermX = 0; // Clear bottom line. mvwprintw(stdscr, TermY, TermX, " "); } mvaddch(TermY, TermX, '@' | A_BLINK); }