Updating Master

Also, new gogs host, so testing that
This commit is contained in:
Brian Buller 2015-07-13 09:41:21 -05:00
parent 6b7d6385b5
commit 4902cd6946
8 changed files with 373 additions and 0 deletions

8
cursor.go Normal file
View File

@ -0,0 +1,8 @@
package main
type Cursor struct {
node_x int
node_y int
x int
y int
}

80
main.go Normal file
View File

@ -0,0 +1,80 @@
package main
import (
"github.com/nsf/termbox-go"
"os"
//"syscall"
"time"
)
const PROGRAM_NAME = "tis100e"
func readUserInput(e chan termbox.Event) {
for {
e <- termbox.PollEvent()
}
}
func sendNoneEvent(e chan termbox.Event) {
for {
time.Sleep(60 * time.Millisecond)
e <- termbox.Event{Type: termbox.EventNone}
}
}
func mainLoop(style Style) {
screens := defaultScreens()
display_screen := screens[MAIN_SCREEN_INDEX]
layoutAndDrawScreen(display_screen, style)
eventchan := make(chan termbox.Event)
go readUserInput(eventchan)
go sendNoneEvent(eventchan)
for {
event := <-eventchan // := termbox.PollEvent()
if event.Type == termbox.EventKey {
if event.Key == termbox.KeyCtrlZ || event.Key == termbox.KeyCtrlC {
/*
process, _ := os.FindProcess(os.Getpid())
termbox.Close()
process.Signal(syscall.SIGSTOP)
termbox.Init()
*/
break
}
new_screen_index := display_screen.handleKeyEvent(event)
if new_screen_index < len(screens) {
display_screen = screens[new_screen_index]
layoutAndDrawScreen(display_screen, style)
} else if new_screen_index == EXIT_SCREEN_INDEX {
break
}
}
if event.Type == termbox.EventResize || event.Type == termbox.EventNone {
layoutAndDrawScreen(display_screen, style)
}
}
}
func main() {
var err error
err = termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
style := defaultStyle()
termbox.SetOutputMode(termbox.Output256)
mainLoop(style)
}
func WriteToLog(d string) {
f, err := os.OpenFile("tis100e_log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0664)
if err != nil {
panic(err)
}
f.WriteString(d)
f.Close()
}

43
screen.go Normal file
View File

@ -0,0 +1,43 @@
package main
import "github.com/nsf/termbox-go"
type Screen interface {
handleKeyEvent(event termbox.Event) int
performLayout()
drawScreen(style Style)
}
type ViewPort struct {
bytes_per_row int
number_of_rows int
first_row int
}
const (
MAIN_SCREEN_INDEX = iota
ABOUT_SCREEN_INDEX
EXIT_SCREEN_INDEX
)
func defaultScreens() []Screen {
//var view_port ViewPort
main_screen := MainScreen{}
about_screen := AboutScreen(0)
screens := [...]Screen{
&main_screen,
&about_screen,
}
return screens[:]
}
func drawBackground(bg termbox.Attribute) {
termbox.Clear(0, bg)
}
func layoutAndDrawScreen(screen Screen, style Style) {
screen.performLayout()
drawBackground(style.default_bg)
screen.drawScreen(style)
termbox.Flush()
}

81
screen_about.go Normal file
View File

@ -0,0 +1,81 @@
package main
import (
"fmt"
"github.com/nsf/termbox-go"
"gogs.bullercodeworks.com/brian/termbox-util"
)
type Command struct {
key string
description string
}
type AboutScreen int
func drawCommandsAtPoint(commands []Command, x int, y int, style Style) {
x_pos, y_pos := x, y
for index, cmd := range commands {
termbox_util.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), x_pos, y_pos, style.default_fg, style.default_bg)
termbox_util.DrawStringAtPoint(cmd.description, x_pos+8, y_pos, style.default_fg, style.default_bg)
y_pos++
if index > 2 && index%2 == 1 {
y_pos++
}
}
}
func (screen *AboutScreen) handleKeyEvent(event termbox.Event) int {
return MAIN_SCREEN_INDEX
}
func (screen *AboutScreen) performLayout() {}
func (screen *AboutScreen) drawScreen(style Style) {
default_fg := style.default_fg
default_bg := style.default_bg
width, height := termbox.Size()
template := [...]string{
" ______________________ ____ ",
" /_ __/ _/ ___< / __ \\/ __ \\___ ",
" / / / / \\__ \\/ / / / / / / / _ \\",
" / / _/ / ___/ / / /_/ / /_/ / __/",
"/_/ /___//____/_/\\____/\\____/\\___/ ",
" ",
}
first_line := template[0]
start_x := (width - len(first_line)) / 2
start_y := ((height - 2*len(template)) / 2) - 2
x_pos, y_pos := start_x, start_y
if height < 15 {
start_y = 0
y_pos = 0
}
for _, line := range template {
x_pos = start_x
for _, runeValue := range line {
bg := default_bg
displayRune := ' '
if runeValue != ' ' {
displayRune = runeValue
termbox.SetCell(x_pos, y_pos, displayRune, default_fg, bg)
}
x_pos++
}
y_pos++
}
commands1 := [...]Command{
{"Ctrl+←", "Move to Node Left"},
{"Ctrl+↓", "Move to Node Down"},
{"Ctrl+↑", "Move to Node Up"},
{"Ctrl+→", "Move to Node Right"},
}
x_pos = start_x
y_pos++
drawCommandsAtPoint(commands1[:], x_pos, y_pos+1, style)
exit_txt := "Press any key to return to emulator"
termbox_util.DrawStringAtPoint(exit_txt, (width-len(exit_txt))/2, height-1, style.title_fg, style.title_bg)
}

46
screen_main.go Normal file
View File

@ -0,0 +1,46 @@
package main
import (
"github.com/br0xen/termbox-util"
"github.com/nsf/termbox-go"
//"strings"
"fmt"
)
const (
MODE_INIT = iota
MODE_DEV
MODE_RUN
MODE_DEBUG
)
type MainScreen struct {
the_cpu *TIS_CPU
GameMode int
}
func (screen *MainScreen) handleKeyEvent(event termbox.Event) int {
if event.Type == termbox.EventKey {
if event.Key == termbox.KeyEsc {
return EXIT_SCREEN_INDEX
}
}
return MAIN_SCREEN_INDEX
}
func (screen *MainScreen) performLayout() {}
func (screen *MainScreen) drawScreen(style Style) {
if screen.GameMode == MODE_INIT {
screen.the_cpu = GetDefaultCPU()
screen.GameMode = MODE_DEV
}
for i := range screen.the_cpu.nodes {
WriteToLog(fmt.Sprintf("Node Row: %d\n", i))
for j, _ := range screen.the_cpu.nodes[i] {
WriteToLog(fmt.Sprintf("Node Col: %d\n", j))
x_pos, y_pos := (18 * j), (18 * i)
termbox_util.DrawBorder(x_pos, y_pos, x_pos+16, y_pos+16, style.default_fg, style.default_bg)
}
}
}

23
style.go Normal file
View File

@ -0,0 +1,23 @@
package main
import "github.com/nsf/termbox-go"
type Style struct {
default_bg termbox.Attribute
default_fg termbox.Attribute
title_bg termbox.Attribute
title_fg termbox.Attribute
cursor_bg termbox.Attribute
cursor_fg termbox.Attribute
}
func defaultStyle() Style {
var style Style
style.default_bg = termbox.ColorBlack
style.default_fg = termbox.ColorWhite
style.title_bg = style.default_bg
style.title_fg = style.default_fg | termbox.AttrBold
style.cursor_bg = termbox.ColorWhite
style.cursor_fg = termbox.ColorBlack
return style
}

BIN
tis100e Executable file

Binary file not shown.

92
tis_structs.go Normal file
View File

@ -0,0 +1,92 @@
package main
import (
"fmt"
)
type TIS_CPU struct {
nodes [][]TIS_Node
nodes_per_row int
}
type NodeType int
const (
NODE_TYPE_CODE = iota
NODE_TYPE_STACK
)
func GetDefaultCPU() *TIS_CPU {
t := &TIS_CPU{nodes_per_row: 4}
t.addRow()
t.addRow()
return t
}
func (t *TIS_CPU) addRow() bool {
t.nodes = append(t.nodes, make([]TIS_Node, t.nodes_per_row))
for i := 0; i < t.nodes_per_row; i++ {
t.addNode(len(t.nodes) - 1)
}
return true
}
func (t *TIS_CPU) addNode(row int) bool {
if row >= len(t.nodes) {
return false
}
t.nodes[row] = append(t.nodes[row], NewTISCodeNode())
return true
}
func (t *TIS_CPU) ChangeNodeType(x, y int, new_type NodeType) {
}
func (t *TIS_CPU) GetNode(x, y int) *TIS_Node {
if x < t.nodes_per_row && y < len(t.nodes) {
return &t.nodes[y][x]
}
return nil
}
type TIS_Node interface {
}
type TIS_CodeNode struct {
Reg_ACC int
Reg_BAK int
// Code: 18w by 15h
code [15]string
UpBuffer *TIS_Buffer
RightBuffer *TIS_Buffer
DownBuffer *TIS_Buffer
LeftBuffer *TIS_Buffer
}
func NewTISCodeNode() *TIS_CodeNode {
return &TIS_CodeNode{}
}
type TIS_StackNode struct {
stack []int
max_size int
}
func NewTISStackNode() *TIS_StackNode {
return &TIS_StackNode{max_size: 15}
}
func (n *TIS_StackNode) addToStack(p int) bool {
if len(n.stack) < 15 {
n.stack = append(n.stack, p)
return true
}
return false
}
/* Buffers are the go-betweens for nodes */
type TIS_Buffer interface {
}