/
cpm_bdos.go
37 lines (32 loc) · 934 Bytes
/
cpm_bdos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package core
import (
"fmt"
"log"
)
// handleBDOS handles any CP/M BDOS calls (call 5)
// Basic usage in code:
// LD DE,parameter
// LD C,function
// CALL 5
// Information about the available functions can be found here:
// * http://seasip.info/Cpm/bdosfunc.html
// * http://www.gaby.de/cpm/manuals/archive/cpm22htm/ch5.htm#Section_5.6
// The most important ones are 2: Write Char and 9: Write String
// By implementing the above, the Zexdoc Z80 exerciser can be run on this system :D
func (z *Z80) handleBDOS() {
log.Printf("BDOS CALL: C=%v, DE=%#04x ", *z.C, *z.DE)
switch *z.C {
case 2: // Write char, E = the ascii character to write
fmt.Print(byte(*z.E))
case 9: // Write string, DE = points to start of string, terminated with the $ character
// a for loop to perform the printing
addr := *z.DE
for {
c := rune(z.Mem.read8Inc(&addr))
if c == '$' {
break
}
fmt.Printf("%c", c)
}
}
}