c64vice

VICE is an emulator for the Commodore 64.

{c64vice} is an interface to the binary monitor of a running VICE emulator.

With {c64vice} commands can be sent to the running emulator to:

{c64vice} uses socketConnection() to send/receive raw bytes from the running emulator.

What’s in the box

Installation

You can install from GitHub with:

# install.package('remotes')
# remotes::install_github('coolbutuseless/c64vice')
install.packages("c64vice", repos = c('https://coolbutuseless.r-universe.dev', 'https://cloud.r-project.org'))

Setting up VICE

In order for {c64vice} to be able to communicate with the running VICE process, the VICE executable must have the binary monitor activated.

If running from the command line, this can be enabled with the -binarymonitor flag i.e.

x64sc -binarymonitor

The binary monitor can also e configured in the settings when running VICE:

Transferring and running code

In this example

library(c64asm)
library(c64vice)

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Write somd 6502 Assembly
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
asm <- r"(
; This program rapidly updates the border colour

*=$c000   ; starting address of the program 

start   inc $d020  ; increase border colour
        jmp start  ; repeat
)"

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Use {c64asm} to compile ASM to a c64 PRG executable.
# This ends up being a PRG made up of 8 bytes
#   - the first 2 bytes are the address into which to load the program
#   - everything else is the actual machine code.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prg <- c64asm::compile(asm)
prg
#> [1] 00 c0 ee 20 d0 4c 00 c0
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Load and run the PRG in the current VICE session.
# Note: The first 2 bytes of a PRG are the address, so strip these off
#       before transferring to the c64
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
req_memory_set(prg[-c(1,2)], start = 0xc000) |>
  send_req()

req_keyboard_feed("SYS 49152\r") |>
  send_req()

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Note: an alternate way to start program execution is to directly 
# set the Program Counter (PC) register to the address
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# req_registers_set(PC = 0xc000) |> 
#   send_req()


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' Take a screenshot and plot
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ras <- c64vice::take_screenshot()
plot(ras, interpolate = FALSE)

c64-verse

Acknowledgements