A sample programming session in wAx

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

A sample programming session in wAx

Post by chysn »

Hi, y'all!

Let's pretend we got a wAx cartridge from my Etsy shop. How about translating the well known "Coloured Birds" example of the VIC User's Manual (see p. 41) to machine language?

If this intro seems familiar, it's because I'm using Mike's VICMON sessions to compare the wAx workflow to the VICMON workflow. After all, I've used VICMON for my projects, and I had VICMON's weaknesses fully in my sights as I developed the wAx assembler. So I'm going to go through Mike's first two projects in the first two posts here, the "Birds" and "Bouncing Ball" BASIC examples.

Code: Select all

1 A$="{BLK,WHT,RED,CYN,PUR,GRN,BLU,YEL}"
2 N=INT(RND(1)*8)+1
3 B$=MID$(A$,N,1)
4 PRINTB$"{SHIFT-U,SHIFT-Q,SHIFT-I,SHIFT-J,SHIFT-Q,SHIFT-K}"
5 GOTO2
Here we go:
Birds1.png
At first, we need to take care of the two strings in the program. Fortunately, wAx makes it really easy to enter strings as data. Simply include the strings in double quotes with the Assemble (@) tool.

Like Mike's example, the VIA #2 timer will be sufficient to generate a random number. We likewise get the low byte, then mask off the lowest three bits to get an index to the color characters. Then, we use that index (as X) to print the color with the CHAROUT KERNAL routine ($FFD2), then print the bird string the same way. Then we check for the STOP key and, if it's not pressed, we go back to the start.

Also shown is wAx's syntax to save the program. Note that the device is the last one used, so you can switch to tape with LOAD+STOP, or by setting the location $BA with

@00BA :01
Birds3.png
Below, the run is shown. You may use the left arrow to start an ML program with a hex address, or you can use SYS. There are some key differences between the left arrow and SYS. In this case, we're using left arrow because it turns on BRK handling:
Birds4.png
Note that you never leave the BASIC environment with wAx. In the next project, we'll use some slightly more advanced features.
Last edited by chysn on Sat Aug 22, 2020 10:33 pm, edited 1 time in total.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: A sample programming session in wAx

Post by chysn »

...the saga continues...

Here's the reference program:

Code: Select all

10 PRINT "{CLR}"
20 POKE 36879, 14
30 POKE 36878, 15
40 X = 1
50 Y = 1
60 DX = 1
70 DY = 1
80 POKE 7680 + X + 22*Y, 81
90 FOR T=1 TO 10: NEXT
100 POKE 7680 + X + 22*Y, 32
110 X = X + DX
120 IF X=0 OR X=21 THEN DX=-DX: POKE 36876, 220
130 Y = Y + DY
140 IF Y=0 OR Y=22 THEN DY=-DY: POKE 36876, 230
150 POKE 36876,0
160 GOTO 80
My approach is a bit different from Mike's, since I'm more interested in showing the wAx workflow than in duplicating the program exactly. I'll be using the KERNAL routine PLOT to position the ball.

A couple of wAx tricks are shown right at the top. The first is that wAx offers several immediate operand formats, including a character byte. The second is that there's a numeric converter tool that will help us find the hex equivalents of the decimal addresses in the BASIC program:
Ball1.png
Next, we initialize the data. I'm doing this exactly like Mike did, with the X,Y, and direction registers at the same zero page addresses, all set to 1. Note another immediate operand option, the decimal number. Note also the -M syntax at $1818. This sets the label -M to the value $1818, which is the start of the main loop. You don't need to remember, or write down, $1818.
Ball2.png
Here I'm setting up the PLOT call and drawing the ball:
Ball3.png
Then I'll add a delay of 30 jiffies (more on this later). Note the use of the label -@ in the loop. The -@ label is designed to be a local looping label. Its value is set to $182A, and then the branch instruction at $182C uses that address as its operand.
Ball4.png
Now, I write a backspace and a space, to delete the ball after the delay, and add the X and Y directions to the X and Y positions:
Ball5.png
The pitch starts at 0, and is set to either 220 or 230, based on which direction is changed. The pitch is initialized to 0 in the Y register at $1838.

Please take note of the forward reference syntax at $1841. Sometimes, we don't know the address we're jumping to as we code. If you specify -> as the target address, this reference can be resolved later with -@. You can actually use any label as a forward reference; the special thing about -> and -@ is that it can be used as a forward reference over and over again within the program. -> is specifically designed for the kind of jumps you see here: numerous short-range decision points.

When the ball hits the wall, its direction can be reversed, from 1 to -1 ($FF), or from -1 to 1 ($01). When a direction is changed, Y is set to the pitch of the bounce.
Ball6.png
At $186c, note that I'm using the -@ label on a line by itself. wAx lets you do this, or put an instruction after the label. In either case, the forward reference from $1864 is resolved.

Note also $186f, in which there's a JMP -M, which uses the -M address of $1818.
Ball7.png
Now, after I've run this program, I noticed that it moves too slowly. It takes a half-second ($1e jiffies) for the ball to move. wAx helps us out with a code search tool. You may do searches by byte patterns, text, or 6502 instructions. Code search capability has turned out to be way more useful in practice than I thought it would be, enabling me to find starting points of routines by referring to the source code.
Ball8.png
wAx is available on cartridge at https://www.etsy.com/listing/856409783/ ... for-vic-20
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: A sample programming session in wAx

Post by Noizer »

Explained very well. Looks easy. Certainly is wAx well suited for all those who shy away from machine language coding out there. 😙
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: A sample programming session in wAx

Post by chysn »

Noizer wrote: Sun Aug 23, 2020 12:05 am Certainly is wAx well suited for all those who shy away from machine language coding out there. 😙
I don’t think that it has anything to offer such a person. It's a machine language monitor.

Edit Perhaps you mean that it would be well-suited for people who have shied away from ML coding, but who want to learn. I hope this could be the case.
Last edited by chysn on Sun Aug 23, 2020 9:32 am, edited 4 times in total.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: A sample programming session in wAx

Post by Mike »

Nice to see the VICMON examples being reprised for wAx. 8)
Noizer wrote:Certainly is wAx well suited for all those who shy away from machine language coding out there. 😙
I have to concur with chysn here. If anything, wAx and MINIMON are examples addressing your inquiry in the thread "Chance to change", applied to native programming tools.

Chysn and I took different paths here: while he concentrated on embedding the tools into BASIC and providing a rich feature set (yet still refraining from anything bordering to feature creep), I put the main aspect on a minimal yet still necessary and indispensible set of features for a monitor (the determining reason being able to fit the tool in 2 KB so it can go into the I/O area). But then, we both also wanted to eliminate annoyances and bugs found in the contemporary tools while re-implementing them on our own.

As always, tea can be brewed in different strengths, and both tools most probably are at their best when used at a scene/demo party, when we just do not want to use a PC for cross development ... or training games for infinite lives. :mrgreen:
Post Reply