Fixed input bugs.
Input from stdin now works as expected in the emulator. New program to demo input from the command line.
This commit is contained in:
@@ -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."
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user