wAx the VIC-20
By Michael Doornbos
- 4 minutes read - 696 wordsWax
Over the years, I’ve looked for an Assembler for the VIC-20. Sure, there are great cross-assemblers like Kick Assembler, but I wanted something that would run on the VIC-20 itself.
Is the VIC-20 a good machine on which to write assembly? Maybe not ON the machine. The 22-column screen is a bit limiting, but after spending so much time in Turbo Macro Pro on the C64, I wanted to see what I could do on the VIC-20 natively.
I came across a cool assembler by Jason Justian a few years ago called wAx.
This is a previous version of the cart. The current version has some improvements; we’ll be using the current version, called wAX2.
wAx is a set of machine language monitor tools for the Commodore VIC-20. It works as a BASIC extension, allowing assembly, disassembly, and a comprehensive set of debugging and memory management features, all integrated with the BASIC environment.
Is it weird to mix assembly and BASIC? I don’t think so. I think it’s cool. I can hear some of you screaming about it though.
10PRINT
Let’s do my favorite thing, 10 PRINT to get a feel for wAx.
10 S=6400
20 .A 'S' @L JSR $E09B
30 .A * LDA #205
40 .A * ADC #0
50 .A * JSR $FFD2
60 .A * BMI @L
1000 .D 'S' *
1010 SYS 6400
S=6400
sets a variable we’ll use as the start of our assembly code.
.A 'S'
tells wAx to assemble the following code at the address stored in S
.
@L
is a label we can jump to. Labels are prefixed with @
in wAx and seem to be limited to a single character.
Calling JSR $E09B
is the same as RND(0)
, but we’re not actually using the value. We’re just calling it to randomize the carry flag. It creates “enough” randomness for our purposes.
Fun to try: If you were to CLC
before the ADC
, you’d get the same number every time and it would just print 205 which is /
in PETSCII.
Fibonacci in WAX
Let’s try something slightly more complex. How about a Fibonacci sequence?
5 REM FIBONACCI 10 WITH WAX2 ASSEMBLER
10 S=6400:M=6500:REM S=START, M=STORE
15 D=4096:C=37888: REM SCREEN ON EXPANDED VIC
17 I=11
20 .A 'S' LDA #0
30 .A * STA $FC
40 .A * LDA #1
50 .A * STA $FB
60 .A * LDX #0
65 .A * SED
70 .A * @L LDA $FB
90 .A * STA 'M',X
100 .A * STA $FD
110 .A * ADC $FC
120 .A * STA $FB
130 .A * LDA $FD
140 .A * STA $FC
150 .A * INX
160 .A * CPX #'I'
170 .A * BNE @L
200 .A * LDY #$00
210 .A * @Q
220 .A * LDA 'M',Y
230 .A * JSR @P
240 .A * LDA #32
250 .A * JSR $FFD2
260 .A * INY
270 .A * CPY #'I'
280 .A * BNE @Q
290 .A * RTS
300 REM HEX PRINT
305 .A * @P
310 .A * PHA
320 .A * AND #$F0
330 .A * LSR A
340 .A * LSR A
350 .A * LSR A
360 .A * LSR A
370 .A * JSR @C
380 .A * JSR $FFD2
390 .A * PLA
400 .A * AND #$0F
410 .A * JSR @C
420 .A * JSR $FFD2
430 .A * RTS
500 .A * @C
510 .A * SED
520 .A * CLC
530 .A * ADC #$90
540 .A * ADC #$40
550 .A * CLD
560 .A * RTS
1000 .D 'S' *
1020 PRINT CHR$(147)
1030 SYS 6400
1035 PRINT:PRINT:PRINT
1040 .M 1964 196E
Here, we store the Fibonacci sequence in memory starting at M
and print it to the screen in hex.
Starting in line 300, we have a subroutine to print the hex value of the accumulator so we can see how to use labels and subroutines in wAx.
Extra Credit
The documentation is excellent. To get a quick overview of the commands, type.? in wAx.
Can you modify the Fibonacci program to generate the first 20 Fibonacci numbers?
Have Fun!