Skip to content

Commit

Permalink
Merge pull request #28 from skx/25-dma
Browse files Browse the repository at this point in the history
Implement function 12, SETDMA
  • Loading branch information
skx authored Apr 16, 2024
2 parents 31ab824 + ed9f653 commit f73d20a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
9 changes: 9 additions & 0 deletions cpm/cpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type CPMHandler struct {
// CPM is the object that holds our emulator state
type CPM struct {

// dma contains the offset of the DMA area which is used
// for block I/O.
dma uint16

// Syscalls contains the syscalls we know how to emulate.
Syscalls map[uint8]CPMHandler

Expand Down Expand Up @@ -121,6 +125,10 @@ func New(filename string, logger *slog.Logger) *CPM {
Desc: "C_READSTRING",
Handler: SysCallReadString,
}
sys[11] = CPMHandler{
Desc: "SETDMA",
Handler: SysCallSetDMA,
}
sys[13] = CPMHandler{
Desc: "DRV_ALLRESET",
Handler: SysCallDriveAllReset,
Expand Down Expand Up @@ -184,6 +192,7 @@ func New(filename string, logger *slog.Logger) *CPM {
Logger: logger,
Reader: bufio.NewReader(os.Stdin),
Syscalls: sys,
dma: 0x0080,
}
return tmp
}
Expand Down
23 changes: 16 additions & 7 deletions cpm/cpm_syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const blkSize = 128
// maxRC is the maximum read count
const maxRC = 128

// dma holds the default DMA address
const dma = 0x80

// SysCallExit implements the Exit syscall
func SysCallExit(cpm *CPM) error {
return ErrExit
Expand Down Expand Up @@ -112,6 +109,18 @@ func SysCallReadString(cpm *CPM) error {
return nil
}

// SysCallSetDMA updates the address of the DMA area, which is used for block I/O.
func SysCallSetDMA(cpm *CPM) error {

// Get the address from BC
addr := cpm.CPU.States.BC.U16()

// Update the DMA value.
cpm.dma = addr

return nil
}

// SysCallDriveAllReset resets the drives
func SysCallDriveAllReset(cpm *CPM) error {
if cpm.fileIsOpen {
Expand Down Expand Up @@ -290,7 +299,7 @@ func SysCallFindFirst(cpm *CPM) error {
// Create a new FCB and store it in the DMA entry
x := fcb.FromString(matches[0])
data := x.AsBytes()
cpm.Memory.PutRange(dma, data...)
cpm.Memory.PutRange(cpm.dma, data...)

// Return 0x00 to point to the first entry in the DMA area.
cpm.CPU.States.AF.Hi = 0x00
Expand Down Expand Up @@ -393,7 +402,7 @@ func SysCallRead(cpm *CPM) error {
}

// Copy the data to the DMA area
cpm.Memory.PutRange(dma, data[:]...)
cpm.Memory.PutRange(cpm.dma, data[:]...)

// Update the next read position
fcbPtr.IncreaseSequentialOffset()
Expand Down Expand Up @@ -429,7 +438,7 @@ func SysCallWrite(cpm *CPM) error {
offset := fcbPtr.GetSequentialOffset()

// Get the data range from the DMA area
data := cpm.Memory.GetRange(dma, 128)
data := cpm.Memory.GetRange(cpm.dma, 128)

// Move to the correct place
_, err := cpm.file.Seek(int64(offset), io.SeekStart)
Expand Down Expand Up @@ -544,7 +553,7 @@ func SysCallReadRand(cpm *CPM) error {
return 1
}

cpm.Memory.PutRange(dma, data[:]...)
cpm.Memory.PutRange(cpm.dma, data[:]...)
return 0
}

Expand Down

0 comments on commit f73d20a

Please sign in to comment.