Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: quickload via remote monitor #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ format:
clang-format-3.9 -i **/*.[ch]

vice: package
x128 -config vicerc -autostart kasse.d71 +go64 -remotemonitor -80col
go run quickload.go &
x128 -config vicerc +go64 -80col -initbreak 0xc262 -remotemonitor

check:
go test -v
101 changes: 101 additions & 0 deletions quickload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package main

import (
"fmt"
"io"
"log"
"net"
"regexp"
"time"
)

var promptRe = regexp.MustCompile(`\(C:\$[0-9a-f]{4}\) `)

func discardUntilPrompt(r io.Reader) error {
log.Printf("discard")
for {
buf := make([]byte, 50)
n, err := r.Read(buf)
if err != nil {
return err
}
buf = buf[:n]

log.Printf("read: %q", string(buf))
if promptRe.Match(buf) {
log.Printf("prompt found")
return nil // prompt found
}
log.Printf("discarding until newline")
p := make([]byte, 1)
for p[0] != '\n' {
if _, err := r.Read(p); err != nil {
return err
}
}
log.Printf("newline found")
}
}

func dial() (net.Conn, error) {
const timeout = 10 * time.Second
var err error
start := time.Now()
for time.Since(start) < timeout {
var conn net.Conn
conn, err = net.Dial("tcp", "localhost:6510")
if err != nil {
if oe, ok := err.(*net.OpError); ok {
if oe.Op == "dial" {
log.Printf("could not dial x128 remote monitor: %v (retrying)", err)
time.Sleep(100 * time.Millisecond)
continue
}
}
return nil, err
}
return conn, err
}
return nil, fmt.Errorf("could not dial x128 remote monitor within %v: %v", timeout, err)
}

func quickload() error {
conn, err := dial()
if err != nil {
return err
}
defer conn.Close()

if err := discardUntilPrompt(conn); err != nil {
return err
}

if _, err := conn.Write([]byte("ll \"kasse.lbl\"\n")); err != nil {
return err
}
if err := discardUntilPrompt(conn); err != nil {
return err
}

if _, err := conn.Write([]byte("load \"kasse\" 0\n")); err != nil {
return err
}
if err := discardUntilPrompt(conn); err != nil {
return err
}

if _, err := conn.Write([]byte("keybuf run\\n\n")); err != nil {
return err
}
if _, err := conn.Write([]byte("x\n")); err != nil {
return err
}

return conn.Close()
}

func main() {
if err := quickload(); err != nil {
log.Fatal(err)
}
}