2023-04-04 11:32:39 +02:00
|
|
|
package asm
|
2023-04-03 09:22:01 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-04-04 11:32:39 +02:00
|
|
|
|
|
|
|
"git.defalsify.org/festive/vm"
|
2023-04-03 09:22:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type BatchCode uint16
|
|
|
|
|
|
|
|
const (
|
2023-04-03 10:14:45 +02:00
|
|
|
_MENU_OFFSET = 256
|
|
|
|
MENU_DOWN = _MENU_OFFSET
|
|
|
|
MENU_UP = _MENU_OFFSET + 1
|
|
|
|
MENU_NEXT = _MENU_OFFSET + 2
|
|
|
|
MENU_PREVIOUS = _MENU_OFFSET + 3
|
|
|
|
//MENU_BROWSE = _MENU_OFFSET + 4
|
2023-04-03 09:22:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
batchCode = map[string]BatchCode{
|
|
|
|
"DOWN": MENU_DOWN,
|
|
|
|
"UP": MENU_UP,
|
|
|
|
"NEXT": MENU_NEXT,
|
|
|
|
"PREVIOUS": MENU_PREVIOUS,
|
2023-04-03 10:14:45 +02:00
|
|
|
//"BROWSE": MENU_BROWSE,
|
2023-04-03 09:22:01 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
type menuItem struct {
|
|
|
|
code BatchCode
|
|
|
|
choice string
|
|
|
|
display string
|
|
|
|
target string
|
|
|
|
}
|
|
|
|
|
|
|
|
type MenuProcessor struct {
|
|
|
|
items []menuItem
|
|
|
|
size uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMenuProcessor() MenuProcessor {
|
|
|
|
return MenuProcessor{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func(mp *MenuProcessor) Add(bop string, choice string, display string, target string) error {
|
|
|
|
bopCode := batchCode[bop]
|
|
|
|
if bopCode == 0 {
|
|
|
|
return fmt.Errorf("unknown menu instruction: %v", bop)
|
|
|
|
}
|
|
|
|
m := menuItem{
|
|
|
|
code: bopCode,
|
|
|
|
choice: choice,
|
|
|
|
display: display,
|
|
|
|
target: target,
|
|
|
|
}
|
|
|
|
mp.items = append(mp.items, m)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mp *MenuProcessor) ToLines() []byte {
|
|
|
|
preLines := []byte{}
|
|
|
|
postLines := []byte{}
|
|
|
|
|
|
|
|
for _, v := range mp.items {
|
2023-04-04 11:32:39 +02:00
|
|
|
preLines = vm.NewLine(preLines, vm.MOUT, []string{v.choice, v.display}, nil, nil)
|
2023-04-03 09:22:01 +02:00
|
|
|
switch v.code {
|
|
|
|
case MENU_UP:
|
2023-04-04 11:32:39 +02:00
|
|
|
postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, "_"}, nil, nil)
|
2023-04-03 09:22:01 +02:00
|
|
|
case MENU_NEXT:
|
|
|
|
_ = postLines
|
|
|
|
case MENU_PREVIOUS:
|
|
|
|
_ = postLines
|
|
|
|
default:
|
2023-04-04 11:32:39 +02:00
|
|
|
postLines = vm.NewLine(postLines, vm.INCMP, []string{v.choice, v.target}, nil, nil)
|
2023-04-03 09:22:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 11:32:39 +02:00
|
|
|
preLines = vm.NewLine(preLines, vm.HALT, nil, nil, nil)
|
2023-04-03 09:22:01 +02:00
|
|
|
return append(preLines, postLines...)
|
|
|
|
}
|
2023-04-04 11:32:39 +02:00
|
|
|
|
|
|
|
|