From 0ba0d793ca60189fa8378399d32d6299a1dd9db5 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Fri, 1 Dec 2023 20:12:52 +1100 Subject: fixed CR with terminal & VRAM --- src/apple.c | 2 +- src/cpu/instructions.c | 5 ++--- src/video/ncurses.c | 54 +++++++++++++++++++++++++++++++------------------- 3 files changed, 37 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/apple.c b/src/apple.c index ba2cfb6..18f1763 100644 --- a/src/apple.c +++ b/src/apple.c @@ -104,7 +104,7 @@ void SetMemory(address x, byte y){ byte UserInput() { #ifdef GRAPHICAL - + // SDL code #else int c = getch(); #endif diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index cb80855..da093ec 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -44,7 +44,7 @@ void fSTY(Addressing addr, address val){ // Arithmetic Instructions void fADC(Addressing addr, address val){ - int buffer = acc + idata.value; + int buffer = (int)acc + idata.value; SetFlagV(buffer, acc); if (buffer > 255) @@ -139,8 +139,7 @@ void fJMP(Addressing addr, address val){ PC = val; PC -= 2; } -void fBCC(Addressing addr, address val){ //FINISH ALL BRANCH INSTRUCTIONS - //signed char val down to BVC +void fBCC(Addressing addr, address val){ if (getFlag(flag_C) == 0) PC += (char)val; } diff --git a/src/video/ncurses.c b/src/video/ncurses.c index c7cf3fb..242a3e1 100644 --- a/src/video/ncurses.c +++ b/src/video/ncurses.c @@ -105,31 +105,45 @@ void DisplayInput(byte n) return; } - n &= 0b01111111; - - // Place character + // Clear @ mvwaddch(AppleWindow, TermY, TermX, ' '); - mvwaddch(AppleWindow, TermY, TermX, n); + + if (n == CR) { + // Add spacing characters into VRAM + do { + *VRAM_Position = ' '; + VRAM_Position++; + } while (((int)(VRAM_Position - VRAM) % 40) > 0); + + // Set display to next line + TermX = 0; + TermY++; + } + else { + // Place character + mvwaddch(AppleWindow, TermY, TermX, n & 0x7F); - // Add character to register - *VRAM_Position = n; - VRAM_Position++; - if (VRAM_Position >= (VRAM + 960)) - VRAM_Position = VRAM; - - TermX++; - // If X is past width.. - if (TermX >= 40) { - //.. move to start of next line. - TermX = 0; - TermY++; - } + // Add character to VRAM + *VRAM_Position = n & 0x7f; + VRAM_Position++; + + // Set display to next character/next line + TermX++; + if (TermX >= 40) { + TermX = 0; + TermY++; + } + } + // Reset VRAM_Position if it's value is too great. + if (VRAM_Position >= (VRAM + 960)) + VRAM_Position -= 960; + // If Y is past height.. if (TermY >= 24) { + //.. discard the first line.. VRAM_Offset += 40; - //.. verify the register offset.. if (VRAM_Offset >= 960) VRAM_Offset = VRAM; @@ -141,7 +155,7 @@ void DisplayInput(byte n) for (int i = 0; i < 23; i++) { for (int j = 0; j < 40; j++) { if (offset >= (VRAM + 960)) - offset -= VRAM; + offset -= 960; mvwaddch(AppleWindow, i, j, *offset ); offset++; }} @@ -153,7 +167,7 @@ void DisplayInput(byte n) " "); } - // @ prompt. + // Place @ mvwaddch(AppleWindow, TermY, TermX, '@' | A_BLINK); wrefresh(AppleWindow); } -- cgit v1.2.3