Skip to content

Commit

Permalink
add: Implement simple BIOS
Browse files Browse the repository at this point in the history
  • Loading branch information
yamatcha committed Jun 14, 2020
1 parent 59b9bfe commit 9d08d82
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
37 changes: 37 additions & 0 deletions emulator/bios.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package emulator

import "fmt"

var biosToTerminal []int = []int{
30, 34, 32, 36, 31, 35, 33, 37}

func putString(s string) {
for _, i := range s {
ioOut8(0x03f8, uint8(i))
}
}

func biosVideoTeletype(emu *Emulator) {
color := emu.Registers.getRegister8(BL) & 0x0f
ch := emu.Registers.getRegister8(AL)
var buf string
var bright int
terminalColor := biosToTerminal[color&0x07]
if color&0x08 == 1 {
bright = 1
} else {
bright = 0
}
buf = fmt.Sprintf("\x1b[%d;%dm%c\x1b[0m", bright, terminalColor, ch)
putString(buf)
}

func biosVideo(emu *Emulator) {
function := emu.Registers.getRegister8(AH)
switch function {
case 0x0e:
biosVideoTeletype(emu)
default:
fmt.Printf("not implemented BIOS video function 0x%02x\n", function)
}
}
4 changes: 3 additions & 1 deletion emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const (
RegistersCount = 8
MemorySize = 1024 * 1024
AL = 0
BL = 3
AH = 4
EAX = 0
EDX = 2
ESP = 4
Expand Down Expand Up @@ -104,7 +106,7 @@ func (reg *Registers) setRegister8(index byte, value byte) {
r := reg.GetRegister32(index) & 0xffffff00
reg.setRegister32(index, r|uint32(value))
} else {
r := reg.GetRegister32(index-4) & 0xffffff00
r := reg.GetRegister32(index-4) & 0xffff00ff
reg.setRegister32(index-4, r|uint32(value)<<8)
}
}
Expand Down
15 changes: 15 additions & 0 deletions emulator/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ func outDxAl(emu *Emulator) {
emu.Eip++
}

func swi(emu *Emulator) {
intIndex := GetCode8(emu, 1)
emu.Eip += 2
switch intIndex {
case 0x10:
biosVideo(emu)
default:
fmt.Printf("unknown interrupt: 0x%02x\n", intIndex)
}
}

func Instructions(index byte) (func(emu *Emulator), error) {
switch {
case 0x01 == index:
Expand Down Expand Up @@ -369,6 +380,10 @@ func Instructions(index byte) (func(emu *Emulator), error) {
return movRm32Imm32, nil
case 0xc9 == index:
return leave, nil

case 0xcd == index:
return swi, nil

case 0xe8 == index:
return callRel32, nil
case 0xe9 == index:
Expand Down

0 comments on commit 9d08d82

Please sign in to comment.