User Tools

Site Tools


base:using_a_running_vice_session_for_development

This is an old revision of the document!


Using a running VICE session for development

note: work in progress

Introduction

Sometimes the assemble-run-debug cycle gets a little slow due to the start-up time of VICE. Luckily VICE has a remote monitor feature which can be (ab)used to speed up this process.

This process basically comes down to setting up a proper VICE session once with VICE listening on a specific port for monitor commands and then using this port to send commands from your shell, Makefile or IDE to load your code, your labels/breakpoints, attach/detach disks and run the program. All without rebooting VICE.

This article attempts to explain that process. For now, only for *nix systems.

Requirements

A few tools are needed to get this working:

  • VICE, preferably a current SVN build, I used 2.4.27 and onwards during my adventures
  • netcat for sending commands to the running VICE session
  • telnet for entering the remote monitor in interactive mode
  • make for making things easier

Obviously we need an assembler, one which can output VICE labels if you want to use that feature. I personally use 64tass (again, build a current version).

And of course a decent editor, one which can at least syntax highlight Makefile's and whatever assembler you use.

Setting up VICE

Getting VICE to act as a 'server' isn't hard:

x64 -remotemonitor

This will tell VICE to listen on port 6510 for connections. Now we can use netcat or telnet to send commands:

compyx@aspire-7740 ~ $ telnet localhost 6510
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
reset 0
(C:$e5cf) ^]quit 
 
telnet> quit
Connection closed.

We just told VICE to perform a soft reset. By using telnet we started an interactive session with the monitor, which halted the emulation, we can also send commands while the emulation keeps going, using netcat:

echo 'reset 0' | netcat localhost 6510

Same thing, but this command returns immediately, it doesn't wait for the reset to finish, which is actually a bit of a nuisance (more on that later). The advantage is with other commands, such as clearing or loading labels, attaching disk images, injecting code/data, etc.

Patching the KERNAL for faster reset

This is optional, but makes a big difference when it comes to eliminating start-up time.

When using the stock KERNAL, we must wait for about 3 seconds before sending the next command with netcat, otherwise this command is ignored by VICE. The BASIC memory test is what takes the most time, so we can patch the KERNAL to skip the memory test:

We need to store $9f in $fd69 in the KERNAL to achieve this. This cannot be done using the monitor, we need to patch the actual KERNAL file of VICE and then tell VICE to use the patched KERNAL. Patching goes something like this:

cp /usr/lib/vice/C64/kernal kernal-quick-memtest
echo "1d69: 9f" | xxd -r - kernal-quick-memtest

Any method of altering a binary can be used, I prefer to do it this way, so I can stick it in a Makefile and never have to worry about whether I patched the KERNAL or not.

This makes the BASIC memtest finish immediately and still report the correct number of bytes free. (Thanks a lot to iAN CooG for suggesting this!)

VICE still needs to know about this new KERNAL, so the command to start VICE becomes:

x64 -remotemonitor -kernal kernal-quick-memtest

These are all the commands VICE needs to start a proper session, the rest we can do with the remote monitor.

But first, let's automate something.

Automatic session setup

Makefile

To automate the tedious process of patching the kernal and starting VICE with the proper arguments, I use a Makefile. For now it looks like this:

# x64 binary
X64 = /usr/local/bin/x64
 
# Original KERNAL
KERNAL=/usr/lib/vice/C64/kernal
# Patched KERNAL
KERNAL_PATCHED=kernal-quick-memtest
 
 
# Generate patched KERNAL for faster reset (skip BASIC memtest)
$(KERNAL_PATCHED): $(KERNAL)
	cp $(KERNAL) $(KERNAL_PATCHED)
	echo "1d69: 9f" | xxd -r - $(KERNAL_PATCHED)
 
 
# Start VICE session with remote monitor and patched KERNAL
session: $(KERNAL_PATCHED)
        $(X64) -remotemonitor -kernal $(KERNAL_PATCHED)

This creates two rules: one to generate a patched KERNAL, and one to start the VICE remote monitor session. The session depends on the patched KERNAL, which is created if it doesn't exist.

So now the VICE session start up is as simple as:

make session

Of course this will keep your shell busy until you quit VICE, so if you just want to set up the session and return to the shell, you can do something like this:

make session > /dev/null 2>&1 &

This will run the the session in the background while redirecting VICE's stdout and stderr to /dev/null, this avoids having to open another shell for running other commands, and keeping the shell clean. You can also adjust the Makefile to do this for you:

# Start VICE session with remote monitor and patched KERNAL in the background
session: $(KERNAL_PATCHED)
        $(X64) -remotemonitor -kernal $(KERNAL_PATCHED) \
                > /dev/null 2>&1 &
base/using_a_running_vice_session_for_development.1467132872.txt.gz · Last modified: 2016-06-28 18:54 by compyx