User Tools

Site Tools


base:using_a_running_vice_session_for_development

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
base:using_a_running_vice_session_for_development [2016-06-30 14:43] compyxbase:using_a_running_vice_session_for_development [2016-07-01 12:06] – Makefile example updates compyx
Line 11: Line 11:
 This article attempts to explain that process. For now, only for *nix systems. This article attempts to explain that process. For now, only for *nix systems.
  
 +Please note that I use a SVN snapshot of VICE, installed into /usr/local, so you may have to adjust a few paths, such as the location of the C64 kernal image.
 + 
  
 ==== Requirements ==== ==== Requirements ====
Line 21: Line 23:
   * make for making things easier   * 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).+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, r1184 added support for scoped labels, eg: .foo:bar).
  
-And of course a decent editor, one which can at least syntax highlight Makefile's and whatever assembler you use.+And of course a decent editor, one which can at least syntax highlight Makefile's and whatever assembler you use, and allows you to change tab settings on a per-buffer base: Makefile's require tabs for indentation.
  
  
Line 61: Line 63:
  
 <code bash> <code bash>
-cp /usr/lib/vice/C64/kernal kernal-quick-memtest+cp /usr/local/lib64/vice/C64/kernal kernal-quick-memtest
 echo "1d69: 9f" | xxd -r - kernal-quick-memtest echo "1d69: 9f" | xxd -r - kernal-quick-memtest
 </code> </code>
 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. 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!)+This makes the BASIC memtest finish almost 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: VICE still needs to know about this new KERNAL, so the command to start VICE becomes:
Line 83: Line 85:
    
 <code make> <code make>
-# x64 binary +VICE'x64 binary 
-X64 = /usr/local/bin/x64+X64=/usr/local/bin/x64 
 +# Standard flags to pass to VICE during startup 
 +X64_FLAGS=
  
 # Original KERNAL # Original KERNAL
-KERNAL=/usr/lib/vice/C64/kernal+KERNAL=/usr/local/lib64/vice/C64/kernal
 # Patched KERNAL # Patched KERNAL
 KERNAL_PATCHED=kernal-quick-memtest KERNAL_PATCHED=kernal-quick-memtest
Line 120: Line 124:
 </code> </code>
  
 +== Access VICE's output ==
 +
 +If you want to see VICE's messages, you redirect stdout and stderr to log files, which you inspect later, or just tail -f them.
 +
 +<code make>
 +# VICE's x64 binary
 +X64=/usr/local/bin/x64
 +# Standard flags to pass to VICE during startup
 +X64_FLAGS=
 +
 +# Log file for x64's stdout (VICE's warning/error messages also go here)
 +X64_STDOUT=vice.log
 +# Log file for x64's stderr
 +X64_STDERR=vice.err (useful when debug VICE itself)
 +
 +
 +# Rule to start VICE with remote monitor, with patched KERNAl for quicker
 +# reset and running it in the background with any output of VICE redirected to
 +# log files
 +session: $(KERNAL_PATCHED)
 + $(X64) $(X64_FLAGS) -remotemonitor -kernal $(KERNAL_PATCHED) \
 + 1>$(X64_STDOUT) 2>$(X64_STDERR) &
 +</code>
  
 ==== Setting up the client side ==== ==== Setting up the client side ====
Line 177: Line 204:
 Again giving VICE time to process the 'clear_labels' command before sending the 'load_labels' command. Obviously not needed when issuing these commands from the shell, but using a Makefile, this is required. Again giving VICE time to process the 'clear_labels' command before sending the 'load_labels' command. Obviously not needed when issuing these commands from the shell, but using a Makefile, this is required.
  
-So, lets update our Makefile once again (full Makefile now):+So, lets update our Makefile once again (nearly complete Makefile now):
 <code make> <code make>
-# x64 binary +vim: noet ts=8 sw=8 sts=8 
-X64=/usr/local/bin/x64 +
-# Assembler+# Makefile for CB64 article 'Using a running VICE session for development' 
 + 
 +# This uses an SVN build of VICE, so adjust the paths to the x64 binary and 
 +# the KERNAL if using the 2.4 stable build (which is way too old) 
 + 
 + 
 +# Assembler (Soci's 64tass)
 ASM=64tass ASM=64tass
 +# Assembler flags (see the 64tass manual)
 +ASM_FLAGS=--ascii --case-sensitive --shadow-check --m6502
 +# Flags needed to output VICE labels (see the 64tass manual)
 +ASM_LABELS=--vice-labels -l $(LABEL_FILE)
 +
 +# file to output VICE labels to
 +LABEL_FILE=labels.txt
 +
 +
 +# VICE's x64 binary
 +X64=/usr/local/bin/x64
 +# Standard flags to pass to VICE during startup
 +X64_FLAGS=
 +# Log file for x64's stdout output
 +X64_STDOUT=vice.log
 +# Log file for x64's stderr output
 +X64_STDERR=vice.err
 +
 +
 +# Our demo binary
 +TARGET=demo.prg
  
 # Original KERNAL # Original KERNAL
-KERNAL=/usr/lib/vice/C64/kernal+KERNAL=/usr/local/lib64/vice/C64/kernal
 # Patched KERNAL # Patched KERNAL
 KERNAL_PATCHED=kernal-quick-memtest KERNAL_PATCHED=kernal-quick-memtest
  
  
-Generate patched KERNAL for faster reset (skip BASIC memtest)+Default make target, just our binary 
 +all: $(TARGET) 
 + 
 + 
 +# Rule to assemble our binary and output labels for VICE 
 +$(TARGET): demo.s 
 + $(ASM) $(ASM_FLAGS) $(ASM_LABELS) -o $@ $< 
 + 
 + 
 +# Rule to patch the KERNAL for quicker reset
 $(KERNAL_PATCHED): $(KERNAL) $(KERNAL_PATCHED): $(KERNAL)
  cp $(KERNAL) $(KERNAL_PATCHED)  cp $(KERNAL) $(KERNAL_PATCHED)
  echo "1d69: 9f" | xxd -r - $(KERNAL_PATCHED)  echo "1d69: 9f" | xxd -r - $(KERNAL_PATCHED)
-all: demo.prg 
  
  
-Assemble program and output VICE labels file +Rule to start VICE with remote monitor, with patched KERNAl for quicker 
-demo.prgdemo.s +# reset and running it in the background with any output of VICE redirected to 
-        $(ASM) --C -o demo.prg demo.s --vice-labels -l labels.txt+# log file files 
 +session$(KERNAL_PATCHED) 
 + $(X64) $(X64_FLAGS) -remotemonitor -kernal $(KERNAL_PATCHED) \ 
 + 1>$(X64_STDOUT) 2>$(X64_STDERR) &
  
  
-Inject program into VICE session and run it +Rule to inject the program file and run it 
-run: demo.prg +run: $(TARGET) 
-        we need to wait one second for the reset to finish, so we use -q +reset machine and wait for 1 second after EOF from machine 
-        echo 'reset 0' | netcat -q 1 localhost 6510 + echo 'reset 0' | netcat -q1 localhost 6510 
-        clear and (re)load labels +  
-        echo 'clear_labels' | netcat -q 1 localhost 6510 + optional: load labels (we have to wait for one second to allow the 
-        echo 'load_labels "labels.txt"' | netcat localhost 6510 + # command to complete) 
-        # load demo.prg from the virtual FS, our host OS + echo 'clear_labels' | netcat -q1 localhost 6510 
-        echo 'l "demo.prg 0"' | netcat localhost 6510 + echo 'load_labels "$(LABEL_FILE)"' | netcat localhost 6510 
-        # this assumes demo.prg starts at $080d+ 
 + # load binary 
 + echo 'l "$(TARGET)0' | netcat localhost 6510 
 +        # execute binary, ignoring BASIC interpreter
         echo 'g 080d' | netcat localhost 6510         echo 'g 080d' | netcat localhost 6510
  
- 
-# Start VICE session with remote monitor and patched KERNAL in the background 
-# redirecting VICE's output to a black hole 
-session: $(KERNAL_PATCHED) 
-        $(X64) -remotemonitor -kernal $(KERNAL_PATCHED) \ 
-                > /dev/null 2>&1 & 
  
 # Clean up # Clean up
Line 235: Line 297:
 Since we bypass the C64's OS (the BASIC interpreter), when we execute code using the above method, the C64 doesn't know we executed a program and keeps the IRQ of the interpreter running, resulting in a nice blinking cursor. Since we bypass the C64's OS (the BASIC interpreter), when we execute code using the above method, the C64 doesn't know we executed a program and keeps the IRQ of the interpreter running, resulting in a nice blinking cursor.
  
-So we need a way to do a proper 'RUN' after injecting our program. We can do this with a simple SYS line and some tweaking of the <del>BASIC end-of-program pointer and</de> keyboard buffer.+So we need a way to do a proper 'RUN' after injecting our program. We can do this with a simple SYS line and some tweaking of the <del>BASIC end-of-program pointer and</del> keyboard buffer.
  
 Let's assume our demo.s looks like this: Let's assume our demo.s looks like this:
Line 270: Line 332:
 Putting this in our Makefile, we end up with this: Putting this in our Makefile, we end up with this:
 <code make> <code make>
-# x64 binary +vim: noet ts=8 sw=8 sts=8 
-X64 = /usr/local/bin/x64 +
-# Assembler+# Makefile for CB64 article 'Using a running VICE session for development' 
 + 
 +# This uses an SVN build of VICE, so adjust the paths to the x64 binary and 
 +# the KERNAL if using the 2.4 stable build (which is way too old) 
 + 
 + 
 +# Assembler (Soci's 64tass)
 ASM=64tass ASM=64tass
 +# Assembler flags (see the 64tass manual)
 +ASM_FLAGS=--ascii --case-sensitive --shadow-check --m6502
 +# Flags needed to output VICE labels (see the 64tass manual)
 +ASM_LABELS=--vice-labels -l $(LABEL_FILE)
 +
 +# file to output VICE labels to
 +LABEL_FILE=labels.txt
 +
 +
 +# VICE's x64 binary
 +X64=/usr/local/bin/x64
 +# Standard flags to pass to VICE during startup
 +X64_FLAGS=
 +# Log file for x64's stdout output
 +X64_STDOUT=vice.log
 +# Log file for x64's stderr output
 +X64_STDERR=vice.err
 +
 +
 +# Our demo binary
 +TARGET=demo.prg
  
 # Original KERNAL # Original KERNAL
-KERNAL=/usr/lib/vice/C64/kernal+KERNAL=/usr/local/lib64/vice/C64/kernal
 # Patched KERNAL # Patched KERNAL
 KERNAL_PATCHED=kernal-quick-memtest KERNAL_PATCHED=kernal-quick-memtest
  
  
-Generate patched KERNAL for faster reset (skip BASIC memtest)+Default make target, just our binary 
 +all: $(TARGET) 
 + 
 + 
 +# Rule to assemble our binary and output labels for VICE 
 +$(TARGET): demo.s 
 + $(ASM) $(ASM_FLAGS) $(ASM_LABELS) -o $@ $< 
 + 
 + 
 +# Rule to patch the KERNAL for quicker reset
 $(KERNAL_PATCHED): $(KERNAL) $(KERNAL_PATCHED): $(KERNAL)
  cp $(KERNAL) $(KERNAL_PATCHED)  cp $(KERNAL) $(KERNAL_PATCHED)
  echo "1d69: 9f" | xxd -r - $(KERNAL_PATCHED)  echo "1d69: 9f" | xxd -r - $(KERNAL_PATCHED)
-all: demo.prg 
  
  
-Assemble program and output VICE labels file +Rule to start VICE with remote monitor, with patched KERNAl for quicker 
-demo.prgdemo.s +# reset and running it in the background with any output of VICE redirected to 
-        $(ASM) --C -o demo.prg demo.s --vice-labels -l labels.txt+# log file files 
 +session$(KERNAL_PATCHED) 
 + $(X64) $(X64_FLAGS) -remotemonitor -kernal $(KERNAL_PATCHED) \ 
 + 1>$(X64_STDOUT) 2>$(X64_STDERR) &
  
  
-Inject program into VICE session and run it +Rule to inject the program file and run it 
-run: demo.prg +run: $(TARGET) 
-        we need to wait one second for the reset to finish, so we use -q +reset machine and wait for 1 second after EOF from machine 
-        echo 'reset 0' | netcat -q 1 localhost 6510 + echo 'reset 0' | netcat -q1 localhost 6510 
-        clear and (re)load labels +  
-        echo 'clear_labels' | netcat -q 1 localhost 6510 + optional: load labels (we have to wait for one second to allow the 
-        echo 'load_labels "labels.txt"' | netcat localhost 6510 + # command to complete) 
-        # load demo.prg from the virtual FS, our host OS + echo 'clear_labels' | netcat -q1 localhost 6510 
-        echo 'l "demo.prg 0"' | netcat localhost 6510 + echo 'load_labels "$(LABEL_FILE)"' | netcat localhost 6510
-        # put 'RUN\r' into the keyboard buffer +
-        echo 'f 0277 027a 52 55 4e 0d' | netcat localhost 6510 +
-        # set keyboard buffer size to $04 -> strlen("RUN\r"+
-        echo 'f 00c6 00c6 04' | netcat localhost 6510+
  
 + # load binary
 + echo 'l "$(TARGET)" 0' | netcat localhost 6510
 + # run binary by putting 'RUN\r' into the keyboard buffer
 + echo 'f 0277 027a 52 55 4e 0d' | netcat localhost 6510
 + echo 'f 00c6 00c6 04' | netcat localhost 6510
 +        # now the BASIC interpreter notices it has data in its buffer and parses that,
 +        # resulting in a proper RUN being executed for our program. Even the KERNAL
 +        # itself does it, just look at $e5ee, the handler for Shift+Run/Stop
  
-# Start VICE session with remote monitor and patched KERNAL in the background 
-# redirecting VICE's output to a black hole 
-session: $(KERNAL_PATCHED) 
-        $(X64) -remotemonitor -kernal $(KERNAL_PATCHED) \ 
-                > /dev/null 2>&1 & 
  
-# Clean up 
 .PHONY: clean .PHONY: clean
 clean: clean:
-        rm -f demo.prg + rm -f $(KERNAL_PATCHED) 
-        rm -f $(KERNAL_PATCHED)+ rm -f $(LABEL_FILE) $(X64_STDOUT) $(X64_STDERR) 
 + rm -f $(TARGET)
 </code> </code>
  
Line 327: Line 426:
   * attaching disk images   * attaching disk images
   * debugging via telnet   * debugging via telnet
-  * writing a proper Makefile (perhaps putting all those echo's into a file, updating it with sed)+  * <del>writing a proper Makefile (perhaps putting all those echo's into a file, updating it with sed)</del>
   * VIM integration   * VIM integration
  
base/using_a_running_vice_session_for_development.txt · Last modified: 2016-07-01 13:35 by compyx