Adds ALL op back in (allocate)
This commit is contained in:
parent
0f2e5ecb60
commit
b69d1500bf
|
@ -52,6 +52,10 @@ func LoadProg(b []byte) {
|
|||
for i := range b {
|
||||
vm.Prog[i] = b[i]
|
||||
}
|
||||
if len(b) < 2 {
|
||||
return
|
||||
}
|
||||
vm.HP = To16(vm.Prog[0], vm.Prog[1])
|
||||
}
|
||||
|
||||
func DumpVm() {
|
||||
|
|
30
main.go
30
main.go
|
@ -6,60 +6,72 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
/*
|
||||
TODO
|
||||
- Change GCH and GST to RCH and RST (From G/Get to R/Read)
|
||||
- Remove PHX
|
||||
- Add SST (set string: move a string from the stack to memory)
|
||||
- Add a flag that lets the heap pointer move after the write?
|
||||
- If this isn't present then GST and RST have to add a length
|
||||
to TOS so that a length can be known
|
||||
- Add GST (get string: move a string from an address to the stack)
|
||||
|
||||
*/
|
||||
|
||||
// This has room for up to 255 ops, but just uses these right now.
|
||||
// Once a screen device is enable there will likely be more. Screen
|
||||
// and sound, really.
|
||||
var ops = []func(bool, *Stack){
|
||||
// Regular ops
|
||||
opNop, opSet, opGet, opSei, opGei, opAlo, opNop,
|
||||
opNop, opSet, opGet, opSei, opGei, opAll, opNop,
|
||||
opPsh, opPop, opOvr, opSwp, opRot, opDup, opSsw, // <-13
|
||||
opAdd, opSub, opMul, opDiv, opInc, opDec, opNop,
|
||||
opAnd, opBor, opXor, opShr, opShl, opNop, opNop, // <-27
|
||||
opJmp, opCal, opJcd, opRet, opNop, opNop, opNop,
|
||||
opGch, opGst, opPch, opPst, opHlt, opPhx, opNop,
|
||||
opGch, opGst, opPut, opPst, opHlt, opNop, opNop,
|
||||
opGrt, opLst, opGte, opLte, opEql, opNeq, opNop, //<-48
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop,
|
||||
|
||||
// r ops
|
||||
opNop, opSet, opGet, opSei, opGei, opAlo, opNop,
|
||||
opNop, opSet, opGet, opSei, opGei, opAll, opNop,
|
||||
opPsh, opPop, opOvr, opSwp, opRot, opDup, opSsw,
|
||||
opAdd, opSub, opMul, opDiv, opInc, opDec, opNop,
|
||||
opAnd, opBor, opXor, opShr, opShl, opNop, opNop,
|
||||
opJmp, opCal, opJcd, opRet, opNop, opNop, opNop,
|
||||
opGch, opGst, opPch, opPst, opHlt, opPhx, opNop,
|
||||
opGch, opGst, opPut, opPst, opHlt, opNop, opNop,
|
||||
opGrt, opLst, opGte, opLte, opEql, opNeq, opNop, //<-112
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop,
|
||||
|
||||
// 2 ops
|
||||
opNop, opSet, opGet, opSei, opGei, opAlo, opNop,
|
||||
opNop, opSet, opGet, opSei, opGei, opAll, opNop,
|
||||
opPsh, opPop, opOvr, opSwp, opRot, opDup, opNop,
|
||||
opAdd, opSub, opMul, opDiv, opInc, opDec, opNop,
|
||||
opAnd, opBor, opXor, opShr, opShl, opNop, opNop,
|
||||
opJmp, opCal, opJcd, opRet, opNop, opNop, opNop,
|
||||
opNop, opNop, opPch, opNop, opNop, opPhx, opNop,
|
||||
opGch, opGst, opPut, opPst, opHlt, opNop, opNop,
|
||||
opGrt, opLst, opGte, opLte, opEql, opNeq, opNop, //<-176
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop,
|
||||
|
||||
// 2r ops
|
||||
opNop, opSet, opGet, opSei, opGei, opAlo, opNop,
|
||||
opNop, opSet, opGet, opSei, opGei, opAll, opNop,
|
||||
opPsh, opPop, opOvr, opSwp, opRot, opDup, opNop,
|
||||
opAdd, opSub, opMul, opDiv, opInc, opDec, opNop,
|
||||
opAnd, opBor, opXor, opShr, opShl, opNop, opNop,
|
||||
opJmp, opCal, opJcd, opRet, opNop, opNop, opNop,
|
||||
opNop, opNop, opPch, opNop, opNop, opPhx, opNop,
|
||||
opGch, opGst, opPut, opPst, opHlt, opNop, opNop,
|
||||
opGrt, opLst, opGte, opLte, opEql, opNeq, opNop, //<-176
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop, opNop, opNop, opNop, opNop, opNop, opNop,
|
||||
opNop,
|
||||
}
|
||||
var jump bool
|
||||
var vm Vm = Vm{0, [MaxUint16]byte{0}, [MaxUint16]byte{0}, Stack{0, [MaxByte]byte{0}}, Stack{0, [MaxByte]byte{0}}}
|
||||
var vm Vm = Vm{0, [MaxUint16]byte{0}, [MaxUint16]byte{0}, Stack{0, [MaxByte]byte{0}}, Stack{0, [MaxByte]byte{0}}, 0}
|
||||
var dumpVmData bool
|
||||
var debug bool
|
||||
var halt = -1
|
||||
|
|
67
ops.go
67
ops.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
@ -349,17 +350,36 @@ func opGst(longOp bool, s *Stack){
|
|||
vm.Data.Push(b[0])
|
||||
}
|
||||
|
||||
func opPch(longOp bool, s *Stack){
|
||||
if longOp {
|
||||
hi, lo := s.Pop2()
|
||||
fmt.Print(string([]byte{hi, lo}))
|
||||
func opPut(longOp bool, s *Stack) {
|
||||
format, dest := s.Pop2()
|
||||
d := os.Stdout
|
||||
if dest == 2 {
|
||||
d = os.Stderr
|
||||
}
|
||||
if format == 'c' || format == 'C' {
|
||||
if longOp {
|
||||
hi, lo := s.Pop2()
|
||||
fmt.Fprint(d, string([]byte{hi, lo}))
|
||||
return
|
||||
}
|
||||
ch := s.Pop()
|
||||
fmt.Fprint(d, string(ch))
|
||||
return
|
||||
}
|
||||
ch := s.Pop()
|
||||
fmt.Print(string(ch))
|
||||
if format < 2 || format > 36 {
|
||||
return
|
||||
}
|
||||
var o string
|
||||
if longOp {
|
||||
o = strconv.FormatUint(uint64(s.PopLong()), int(format))
|
||||
} else {
|
||||
o = strconv.FormatUint(uint64(s.Pop()), int(format))
|
||||
}
|
||||
fmt.Fprint(d, o)
|
||||
}
|
||||
|
||||
func opPst(longOp bool, s *Stack){}
|
||||
func opPst(longOp bool, s *Stack){
|
||||
}
|
||||
|
||||
// Halt execution
|
||||
// ( exitCode -- )
|
||||
|
@ -367,15 +387,6 @@ func opHlt(longOp bool, s *Stack){
|
|||
halt = int(vm.Data.Pop())
|
||||
}
|
||||
|
||||
// Print hex
|
||||
func opPhx(longOp bool, s *Stack){
|
||||
if longOp {
|
||||
fmt.Printf("%04x", PopAddress())
|
||||
return
|
||||
}
|
||||
fmt.Printf("%02x", vm.Data.Pop())
|
||||
}
|
||||
|
||||
func opGrt(longOp bool, s *Stack){
|
||||
if longOp {
|
||||
l := s.PopLong()
|
||||
|
@ -484,18 +495,18 @@ func opNeq(longOp bool, s *Stack){
|
|||
}
|
||||
}
|
||||
|
||||
// Allocate memory in the heap area _count_ long
|
||||
// in bytes. Return the address as a long.
|
||||
// ( [count] count -- addrHigh addrLow )
|
||||
func opAlo(longOp bool, s *Stack){
|
||||
// if longOp {
|
||||
// count := PopAddress()
|
||||
// vm.Data.PushLong(vm.HP)
|
||||
// vm.HP += count
|
||||
// return
|
||||
// }
|
||||
// count := uint16(vm.Data.Pop())
|
||||
// vm.Data.PushLong(vm.HP)
|
||||
// vm.HP += count
|
||||
|
||||
// Remove this?
|
||||
func opAll(longOp bool, s *Stack){
|
||||
if longOp {
|
||||
count := PopAddress()
|
||||
s.PushLong(vm.HP)
|
||||
vm.HP += count
|
||||
return
|
||||
}
|
||||
count := uint16(vm.Data.Pop())
|
||||
vm.Data.PushLong(vm.HP)
|
||||
vm.HP += count
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue