c64.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package bar
  2. // c64 player dependencies
  3. //import "io"
  4. //import "os"
  5. //import "bytes"
  6. //import "mime/multipart"
  7. import "fmt"
  8. //import "net/http"
  9. import "net/url"
  10. import "strconv"
  11. import "log"
  12. import "github.com/hypebeast/go-osc/osc"
  13. // C64 object
  14. type C64 struct {
  15. u1541_host string
  16. }
  17. func (c64 *C64) reset(msg *osc.Message) {
  18. if _, err := put(c64.u1541_host+"/v1/machine:reset"); err != nil {
  19. log.Print(err)
  20. }
  21. }
  22. func (c64 *C64) reboot(msg *osc.Message) {
  23. if _, err := put(c64.u1541_host+"/v1/machine:reboot"); err != nil {
  24. log.Print(err)
  25. }
  26. }
  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. func (c64 *C64) insertDisk(msg *osc.Message) {
  35. params := url.Values{}
  36. params.Add("image", getOSC[string](msg))
  37. if _, err := put(c64.u1541_host+"/v1/drives/a:mount?" + params.Encode()); err != nil {
  38. log.Print(err)
  39. }
  40. }
  41. func (c64 *C64) sidplay(msg *osc.Message) {
  42. params := url.Values{}
  43. params.Add("file", getOSC[string](msg))
  44. if songnr := getOSC[int](msg); songnr != 0 {
  45. params.Add("songnr", strconv.Itoa(songnr))
  46. }
  47. if _, err := put(c64.u1541_host+"/v1/runners:sidplay?" + params.Encode()); err != nil {
  48. log.Print(err)
  49. }
  50. }
  51. // Send key strokes via Keyboardcache
  52. func (c64 *C64) sendKeys(msg *osc.Message) {
  53. // Load buffer
  54. for _, char := range getOSC[string](msg) {
  55. params := url.Values{}
  56. params.Add("address", "277")
  57. params.Add("data", fmt.Sprintf("%02x", char))
  58. log.Printf("sent %02x", char)
  59. if _, err := put(c64.u1541_host+"/v1/machine:writemem?" + params.Encode()); err != nil {
  60. log.Print(err)
  61. return
  62. }
  63. params = url.Values{}
  64. params.Add("address", "c6")
  65. params.Add("data", "01")
  66. if _, err := put(c64.u1541_host+"/v1/machine:writemem?" + params.Encode()); err != nil {
  67. log.Print(err)
  68. return
  69. }
  70. }
  71. }