Skip to content

Commit

Permalink
Renamed bios lookup table and ordered functions alphabetically.
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed Jun 19, 2024
1 parent ce0bfdd commit 68481ad
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 67 deletions.
26 changes: 13 additions & 13 deletions cpm/cpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,53 +370,53 @@ func New(logger *slog.Logger, prn string, condriver string, ccp string) (*CPM, e
//
// Create and populate our syscall table for the BIOS syscalls.
//
b := make(map[uint8]CPMHandler)
b[0] = CPMHandler{
bios := make(map[uint8]CPMHandler)
bios[0] = CPMHandler{
Desc: "BOOT",
Handler: BiosSysCallBoot,
}
b[1] = CPMHandler{
bios[1] = CPMHandler{
Desc: "WBOOT",
Handler: BiosSysCallBoot,
}
b[2] = CPMHandler{
bios[2] = CPMHandler{
Desc: "CONST",
Handler: BiosSysCallConsoleStatus,
}
b[3] = CPMHandler{
bios[3] = CPMHandler{
Desc: "CONIN",
Handler: BiosSysCallConsoleInput,
}
b[4] = CPMHandler{
bios[4] = CPMHandler{
Desc: "CONOUT",
Handler: BiosSysCallConsoleOutput,
}
b[5] = CPMHandler{
bios[5] = CPMHandler{
Desc: "LIST",
Handler: BiosSysCallPrintChar,
Fake: true,
}
b[15] = CPMHandler{
bios[15] = CPMHandler{
Desc: "LISTST",
Handler: BiosSysCallPrinterStatus,
Fake: true,
}
b[17] = CPMHandler{
bios[17] = CPMHandler{
Desc: "CONOST",
Handler: BiosSysCallScreenOutputStatus,
Fake: true,
}
b[18] = CPMHandler{
bios[18] = CPMHandler{
Desc: "AUXIST",
Handler: BiosSysCallAuxInputStatus,
Fake: true,
}
b[19] = CPMHandler{
bios[19] = CPMHandler{
Desc: "AUXOST",
Handler: BiosSysCallAuxOutputStatus,
Fake: true,
}
b[31] = CPMHandler{
bios[31] = CPMHandler{
Desc: "RESERVE1",
Handler: BiosSysCallReserved1,
Fake: true,
Expand All @@ -431,7 +431,7 @@ func New(logger *slog.Logger, prn string, condriver string, ccp string) (*CPM, e
// Create the emulator object and return it
tmp := &CPM{
BDOSSyscalls: sys,
BIOSSyscalls: b,
BIOSSyscalls: bios,
Logger: logger,
ccp: ccp,
dma: 0x0080,
Expand Down
108 changes: 54 additions & 54 deletions cpm/cpm_bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,60 +117,6 @@ func BiosSysCallAuxOutputStatus(cpm *CPM) error {
return nil
}

// BiosHandler is involved when a BIOS syscall needs to be executed,
// which is handled via a small trampoline.
//
// These are looked up in the BIOSSyscalls map.
func (cpm *CPM) BiosHandler(val uint8) {

// Lookup the handler
handler, ok := cpm.BIOSSyscalls[val]

// If it doesn't exist we don't have it implemented.
if !ok {
cpm.Logger.Error("Unimplemented BIOS syscall",
slog.Int("syscall", int(val)),
slog.String("syscallHex", fmt.Sprintf("0x%02X", val)))

// record the error
cpm.biosErr = ErrUnimplemented
// halt processing.
cpm.CPU.HALT = true

// stop now.
return
}

// Log the call we're going to make
cpm.Logger.Info("BIOS",
slog.String("name", handler.Desc),
slog.Int("syscall", int(val)),
slog.String("syscallHex", fmt.Sprintf("0x%02X", val)),
slog.Group("registers",
slog.String("A", fmt.Sprintf("%02X", cpm.CPU.States.AF.Hi)),
slog.String("B", fmt.Sprintf("%02X", cpm.CPU.States.BC.Hi)),
slog.String("C", fmt.Sprintf("%02X", cpm.CPU.States.BC.Lo)),
slog.String("D", fmt.Sprintf("%02X", cpm.CPU.States.DE.Hi)),
slog.String("E", fmt.Sprintf("%02X", cpm.CPU.States.DE.Lo)),
slog.String("F", fmt.Sprintf("%02X", cpm.CPU.States.AF.Lo)),
slog.String("H", fmt.Sprintf("%02X", cpm.CPU.States.HL.Hi)),
slog.String("L", fmt.Sprintf("%02X", cpm.CPU.States.HL.Lo)),
slog.String("BC", fmt.Sprintf("%04X", cpm.CPU.States.BC.U16())),
slog.String("DE", fmt.Sprintf("%04X", cpm.CPU.States.DE.U16())),
slog.String("HL", fmt.Sprintf("%04X", cpm.CPU.States.HL.U16()))))

// Otherwise invoke it, and look for any error
err := handler.Handler(cpm)

// If there was an error then record it for later notice.
if err != nil {
// record the error
cpm.biosErr = err
// halt processing.
cpm.CPU.HALT = true
}
}

// BiosSysCallReserved1 is a helper to get/set the values of the CPM interpreter from
// within the system. Neat.
func BiosSysCallReserved1(cpm *CPM) error {
Expand Down Expand Up @@ -382,3 +328,57 @@ func BiosSysCallReserved1(cpm *CPM) error {

return nil
}

// BiosHandler is involved when a BIOS syscall needs to be executed,
// which is handled via a small trampoline.
//
// These are looked up in the BIOSSyscalls map.
func (cpm *CPM) BiosHandler(val uint8) {

// Lookup the handler
handler, ok := cpm.BIOSSyscalls[val]

// If it doesn't exist we don't have it implemented.
if !ok {
cpm.Logger.Error("Unimplemented BIOS syscall",
slog.Int("syscall", int(val)),
slog.String("syscallHex", fmt.Sprintf("0x%02X", val)))

// record the error
cpm.biosErr = ErrUnimplemented
// halt processing.
cpm.CPU.HALT = true

// stop now.
return
}

// Log the call we're going to make
cpm.Logger.Info("BIOS",
slog.String("name", handler.Desc),
slog.Int("syscall", int(val)),
slog.String("syscallHex", fmt.Sprintf("0x%02X", val)),
slog.Group("registers",
slog.String("A", fmt.Sprintf("%02X", cpm.CPU.States.AF.Hi)),
slog.String("B", fmt.Sprintf("%02X", cpm.CPU.States.BC.Hi)),
slog.String("C", fmt.Sprintf("%02X", cpm.CPU.States.BC.Lo)),
slog.String("D", fmt.Sprintf("%02X", cpm.CPU.States.DE.Hi)),
slog.String("E", fmt.Sprintf("%02X", cpm.CPU.States.DE.Lo)),
slog.String("F", fmt.Sprintf("%02X", cpm.CPU.States.AF.Lo)),
slog.String("H", fmt.Sprintf("%02X", cpm.CPU.States.HL.Hi)),
slog.String("L", fmt.Sprintf("%02X", cpm.CPU.States.HL.Lo)),
slog.String("BC", fmt.Sprintf("%04X", cpm.CPU.States.BC.U16())),
slog.String("DE", fmt.Sprintf("%04X", cpm.CPU.States.DE.U16())),
slog.String("HL", fmt.Sprintf("%04X", cpm.CPU.States.HL.U16()))))

// Otherwise invoke it, and look for any error
err := handler.Handler(cpm)

// If there was an error then record it for later notice.
if err != nil {
// record the error
cpm.biosErr = err
// halt processing.
cpm.CPU.HALT = true
}
}

0 comments on commit 68481ad

Please sign in to comment.