Skip to content

Commit

Permalink
Console input tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Jul 10, 2024
1 parent 66a2d99 commit 515f236
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
19 changes: 19 additions & 0 deletions consolein/consolein.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func (ci *ConsoleIn) GetInterruptCount() int {
// and zork doesn't run.
func (ci *ConsoleIn) PendingInput() bool {

// Do we have faked/stuffed input to process?
if len(ci.stuffed) > 0 {
return true
}

// switch stdin into 'raw' mode
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
Expand All @@ -111,6 +116,13 @@ func (ci *ConsoleIn) PendingInput() bool {
// NOTE: This function should not echo keystrokes which are entered.
func (ci *ConsoleIn) BlockForCharacterNoEcho() (byte, error) {

// Do we have faked/stuffed input to process?
if len(ci.stuffed) > 0 {
c := ci.stuffed[0]
ci.stuffed = ci.stuffed[:1]
return c, nil
}

// Do we need to change state? If so then do it.
if ci.State != NoEcho {
ci.disableEcho()
Expand Down Expand Up @@ -145,6 +157,13 @@ func (ci *ConsoleIn) BlockForCharacterNoEcho() (byte, error) {
// NOTE: Characters should be echo'd as they are input.
func (ci *ConsoleIn) BlockForCharacterWithEcho() (byte, error) {

// Do we have faked/stuffed input to process?
if len(ci.stuffed) > 0 {
c := ci.stuffed[0]
ci.stuffed = ci.stuffed[:1]
return c, nil
}

// Do we need to change state? If so then do it.
if ci.State != Echo {
ci.enableEcho()
Expand Down
78 changes: 78 additions & 0 deletions cpm/cpm_bdos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,84 @@ import (
"github.com/skx/cpmulator/static"
)

func TestConsoleInput(t *testing.T) {
// Create a new helper
c, err := New()
if err != nil {
t.Fatalf("failed to create CPM")
}
c.Memory = new(memory.Memory)
c.fixupRAM()
defer c.Cleanup()

// ReadChar
c.input.StuffInput("s")
err = BdosSysCallReadChar(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}
if c.CPU.States.AF.Hi != 's' {
t.Fatalf("got the wrong input")
}

// AuxRead
c.input.StuffInput("k")
err = BdosSysCallAuxRead(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}
if c.CPU.States.AF.Hi != 'k' {
t.Fatalf("got the wrong input")
}

// RawIO
c.input.StuffInput("x")
c.CPU.States.DE.Lo = 0xFF
err = BdosSysCallRawIO(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}
if c.CPU.States.AF.Hi != 'x' {
t.Fatalf("got the wrong input")
}

c.input.StuffInput("x")
c.CPU.States.DE.Lo = 0xFE
err = BdosSysCallRawIO(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}
if c.CPU.States.AF.Hi != 0xFF {
t.Fatalf("got the wrong response")
}

c.input.StuffInput("1")
c.CPU.States.DE.Lo = 0xFD
err = BdosSysCallRawIO(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}
if c.CPU.States.AF.Hi != '1' {
t.Fatalf("got the wrong response")
}

c.input.StuffInput("1")
c.CPU.States.DE.Lo = 42
err = BdosSysCallRawIO(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}

c.input.StuffInput("1")
err = BdosSysCallConsoleStatus(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}
if c.CPU.States.AF.Hi != 0xFF {
t.Fatalf("got the wrong response")
}
}

func TestUnimplemented(t *testing.T) {
// Create a new helper
c, err := New()
Expand Down
31 changes: 30 additions & 1 deletion cpm/cpm_bios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ func TestStatus(t *testing.T) {
if err != nil {
t.Fatalf("failed to call CPM")
}

if c.CPU.States.AF.Hi != 0x00 {
t.Fatalf("console status was wrong")
}

c.input.StuffInput("S")
err = BiosSysCallConsoleStatus(c)
if err != nil {
t.Fatalf("failed to call CPM")
}
if c.CPU.States.AF.Hi != 0xFF {
t.Fatalf("console status was wrong")
}

err = BiosSysCallPrinterStatus(c)
if err != nil {
t.Fatalf("failed to call CPM")
Expand Down Expand Up @@ -277,3 +285,24 @@ func TestCustom(t *testing.T) {
}

}

func TestBIOSConsoleInput(t *testing.T) {
// Create a new helper
c, err := New()
if err != nil {
t.Fatalf("failed to create CPM")
}
c.Memory = new(memory.Memory)
c.fixupRAM()
defer c.Cleanup()

c.input.StuffInput("s")
err = BiosSysCallConsoleInput(c)
if err != nil {
t.Fatalf("failed to call CP/M")
}
if c.CPU.States.AF.Hi != 's' {
t.Fatalf("got the wrong input")
}

}

0 comments on commit 515f236

Please sign in to comment.