// C64 control via Ultimate 1541 II(+) API calls // // See U1541's official docs for details // https://1541u-documentation.readthedocs.io/en/latest/api/api_calls.html package main import ( "fmt" "log" "net/url" "strconv" "github.com/hypebeast/go-osc/osc" ) // Your C64 controller structure type C64 struct { u1541_host string } // Reset (warm start) your C64 via U1541 func (c64 *C64) reset(msg *osc.Message) { if _, err := put(c64.u1541_host + "/v1/machine:reset"); err != nil { log.Print(err) } } // Reboot a C64 and U1541 cartridge func (c64 *C64) reboot(msg *osc.Message) { if _, err := put(c64.u1541_host + "/v1/machine:reboot"); err != nil { log.Print(err) } } // Run PRG from U1541 // String in OSC message is your PRG file path on Ultimate cart func (c64 *C64) runPRG(msg *osc.Message) { params := url.Values{} params.Add("file", getOSC[string](msg)) if _, err := put(c64.u1541_host + "/v1/runners:run_prg?" + params.Encode()); err != nil { log.Print(err) } } // Mount disk image on an U1541 emulating disk insertion to 1541 floppy drive // String in OSC message is your disk image file func (c64 *C64) insertDisk(msg *osc.Message) { params := url.Values{} params.Add("image", getOSC[string](msg)) if _, err := put(c64.u1541_host + "/v1/drives/a:mount?" + params.Encode()); err != nil { log.Print(err) } } // Play SID file // String in OSC message is a path // If there is int in a OSC message use it as song number func (c64 *C64) sidplay(msg *osc.Message) { params := url.Values{} params.Add("file", getOSC[string](msg)) if songnr := getOSC[int](msg); songnr != 0 { params.Add("songnr", strconv.Itoa(songnr)) } if _, err := put(c64.u1541_host + "/v1/runners:sidplay?" + params.Encode()); err != nil { log.Print(err) } } // Send key strokes via Keyboardcache func (c64 *C64) sendKeys(msg *osc.Message) { // Load buffer for _, char := range getOSC[string](msg) { params := url.Values{} params.Add("address", "277") params.Add("data", fmt.Sprintf("%02x", char)) log.Printf("sent %02x", char) if _, err := put(c64.u1541_host + "/v1/machine:writemem?" + params.Encode()); err != nil { log.Print(err) return } params = url.Values{} params.Add("address", "c6") params.Add("data", "01") if _, err := put(c64.u1541_host + "/v1/machine:writemem?" + params.Encode()); err != nil { log.Print(err) return } } }