c64.go 2.2 KB

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