From c512f07305a96ae8b08e44dc562431e866993b71 Mon Sep 17 00:00:00 2001 From: Anachronaut <75824887+RealBusinessAccount@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:41:25 -0400 Subject: [PATCH] Fixed input bugs. Input from stdin now works as expected in the emulator. New program to demo input from the command line. --- Programs/inputTest.asm | 55 ++++++++++++++++++++++++++++++++++ Source/Emulator/cpu.c | 14 ++++----- SplitBit Programming Manual.md | 6 ++-- 3 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 Programs/inputTest.asm diff --git a/Programs/inputTest.asm b/Programs/inputTest.asm new file mode 100644 index 0000000..9eaf0a5 --- /dev/null +++ b/Programs/inputTest.asm @@ -0,0 +1,55 @@ +; This program asks the user for input, then prints whatever they input back to the console again. +; It stores the input string in a buffer in the Data Memory. + +#Include Libraries/print.asm + +#Program + +start: + SETD Message0 ; Set the Data Pointer to the explanation message. + CALL printString ; Print it out. + CALL lineFeed + SETD Buffer ; Set the Data Pointer to the start of the buffer. + INIB 0x0A ; Load the value of a linefeed into B. + inputLoop: + INA 0x00 ; Poll the command line. + CCF + SUB + BRQ inputEnd ; If we encountered a linefeed, the string is over, proceed to processing. + STA ; Store A into the buffer. + INCD ; Increment to the next spot in the buffer. + BRI inputLoop ; Loop again to grab more string. + inputEnd: + INIA 0x00 ; Set A to 0. + STA ; Store it in the buffer. + SETD Buffer ; Set the Data Pointer to the start of the buffer again. + CALL printString ; Print it out. + CALL lineFeed + HALT ; End the program. + +#Data + +; A 256 character buffer for the input string. +; There will need to be some kind of way to define large arrays better than this... +Buffer: +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + +Message0: + "Input Test: Will echo anything you put in." + + diff --git a/Source/Emulator/cpu.c b/Source/Emulator/cpu.c index 6dbe6be..1d3a4ad 100644 --- a/Source/Emulator/cpu.c +++ b/Source/Emulator/cpu.c @@ -372,21 +372,17 @@ uint8_t executeOperation(uint8_t Instruction, CPURegisters *cpu) { // Ex - Input Operations: // case 0xE0: - // CIN - Read Input Select to A. - // cpu->A = InputSelect; - break; - case 0xE1: - // RDA - Read an Input to A. + // INA - Read an Input to A. cpu->ProgramCounter++; cpu->A = InputHandler(cpu->Program[cpu->ProgramCounter]); break; - case 0xE2: - // RDB - Read an Input to B. + case 0xE1: + // INB - Read an Input to B. cpu->ProgramCounter++; cpu->B = InputHandler(cpu->Program[cpu->ProgramCounter]); break; - case 0xE3: - // RDD - Read an Input to Data Memory. + case 0xE2: + // IND - Read an Input to Data Memory. cpu->ProgramCounter++; cpu->Data[cpu->DataPointer] = InputHandler(cpu->Program[cpu->ProgramCounter]); break; diff --git a/SplitBit Programming Manual.md b/SplitBit Programming Manual.md index 510f7fe..9c3ff6c 100644 --- a/SplitBit Programming Manual.md +++ b/SplitBit Programming Manual.md @@ -92,9 +92,9 @@ D2 | OUTB | Writes the value of B to an Output specified by the next byte of Pro ### Input Operations: 3 Instructions Hex Code | Mnemonic | Description -- | -- | -- -E1 | INA | Writes the value of an Input to A. The input port is specified the next byte of Program Memory. -E2 | INB | Writes the value of an Input to B. The input port is specified the next byte of Program Memory. -E3 | IND | Writes the value of an Input to Data Memory at the location referenced by the Data Pointer. The input port is specified by the next byte of Program Memory. +E0 | INA | Writes the value of an Input to A. The input port is specified the next byte of Program Memory. +E1 | INB | Writes the value of an Input to B. The input port is specified the next byte of Program Memory. +E2 | IND | Writes the value of an Input to Data Memory at the location referenced by the Data Pointer. The input port is specified by the next byte of Program Memory. ### Special Operations: 2 Instructions Hex Code | Mnemonic | Description