Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more tests - fixed issue with using CPU.Memory #152

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cpm/cpm_bdos.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func BdosSysCallReadString(cpm *CPM) error {
}

// First byte is the max len
max := cpm.CPU.Memory.Get(addr)
max := cpm.Memory.Get(addr)

// read the input
text, err := cpm.input.ReadLine(max)
Expand All @@ -245,12 +245,12 @@ func BdosSysCallReadString(cpm *CPM) error {

// addr[0] is the size of the input buffer
// addr[1] should be the size of input read, set it:
cpm.CPU.Memory.Set(addr+1, uint8(len(text)))
cpm.Memory.Set(addr+1, uint8(len(text)))

// addr[2+] should be the text
i := 0
for i < len(text) {
cpm.CPU.Memory.Set(uint16(addr+2+uint16(i)), text[i])
cpm.Memory.Set(uint16(addr+2+uint16(i)), text[i])
i++
}

Expand Down
44 changes: 44 additions & 0 deletions cpm/cpm_bdos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,54 @@ import (
"os"
"testing"

"github.com/skx/cpmulator/consolein"
"github.com/skx/cpmulator/fcb"
"github.com/skx/cpmulator/memory"
)

func TestReadLine(t *testing.T) {

// Create a new helper
c, err := New()
if err != nil {
t.Fatalf("failed to create CPM")
}
c.Memory = new(memory.Memory)

// Stuff some fake input
c.input = consolein.New()
c.input.StuffInput("steve")

// Setup a buffer, so we can read 5 characters
c.Memory.Set(0x0100, 5)
c.CPU.States.DE.SetU16(0x0100)

// Read it
err = BdosSysCallReadString(c)
if err != nil {
t.Fatalf("error reading CPM")
}

// How much did we get
got := c.Memory.Get(0x0101)
if got != 05 {
t.Fatalf("returned wrong amount")
}

// What did we get?
text := ""
i := 0
for i < int(got) {
text += string(c.Memory.Get(uint16(0x0102 + i)))
i++
}

if text != "steve" {
t.Fatalf("wrong text received")
}

}

func TestDriveGetSet(t *testing.T) {

// Create a new helper
Expand Down
Loading