c64.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // C64 control via Ultimate 1541 II(+) API calls
  2. //
  3. // See U1541's official docs for details
  4. // https://1541u-documentation.readthedocs.io/en/latest/api/api_calls.html
  5. package main
  6. import (
  7. "fmt"
  8. "log"
  9. "net/url"
  10. "strconv"
  11. "github.com/hypebeast/go-osc/osc"
  12. )
  13. // Your C64 controller structure
  14. type C64 struct {
  15. u1541_host string
  16. }
  17. // Reset (warm start) your C64 via U1541
  18. func (c64 *C64) reset(msg *osc.Message) {
  19. if _, err := put(c64.u1541_host + "/v1/machine:reset"); err != nil {
  20. log.Print(err)
  21. }
  22. }
  23. // Reboot a C64 and U1541 cartridge
  24. func (c64 *C64) reboot(msg *osc.Message) {
  25. if _, err := put(c64.u1541_host + "/v1/machine:reboot"); err != nil {
  26. log.Print(err)
  27. }
  28. }
  29. // Run PRG from U1541
  30. // String in OSC message is your PRG file path on Ultimate cart
  31. func (c64 *C64) runPRG(msg *osc.Message) {
  32. params := url.Values{}
  33. params.Add("file", getOSC[string](msg))
  34. if _, err := put(c64.u1541_host + "/v1/runners:run_prg?" + params.Encode()); err != nil {
  35. log.Print(err)
  36. }
  37. }
  38. // Mount disk image on an U1541 emulating disk insertion to 1541 floppy drive
  39. // String in OSC message is your disk image file
  40. func (c64 *C64) insertDisk(msg *osc.Message) {
  41. params := url.Values{}
  42. params.Add("image", getOSC[string](msg))
  43. if _, err := put(c64.u1541_host + "/v1/drives/a:mount?" + params.Encode()); err != nil {
  44. log.Print(err)
  45. }
  46. }
  47. // Play SID file
  48. // String in OSC message is a path
  49. // If there is int in a OSC message use it as song number
  50. func (c64 *C64) sidplay(msg *osc.Message) {
  51. params := url.Values{}
  52. params.Add("file", getOSC[string](msg))
  53. if songnr := getOSC[int](msg); songnr != 0 {
  54. params.Add("songnr", strconv.Itoa(songnr))
  55. }
  56. if _, err := put(c64.u1541_host + "/v1/runners:sidplay?" + params.Encode()); err != nil {
  57. log.Print(err)
  58. }
  59. }
  60. // Send key strokes via Keyboardcache
  61. func (c64 *C64) sendKeys(msg *osc.Message) {
  62. // Load buffer
  63. for _, char := range getOSC[string](msg) {
  64. params := url.Values{}
  65. params.Add("address", "277")
  66. params.Add("data", fmt.Sprintf("%02x", char))
  67. log.Printf("sent %02x", char)
  68. if _, err := put(c64.u1541_host + "/v1/machine:writemem?" + params.Encode()); err != nil {
  69. log.Print(err)
  70. return
  71. }
  72. params = url.Values{}
  73. params.Add("address", "c6")
  74. params.Add("data", "01")
  75. if _, err := put(c64.u1541_host + "/v1/machine:writemem?" + params.Encode()); err != nil {
  76. log.Print(err)
  77. return
  78. }
  79. }
  80. }