VTL-2 is a curious thing. Created back in 1977 by Frank McCoy and Gary Shannon (Gary then went on to work for Apple). Michael T. Barry ( barrym95838) of this province did a port to the 6502 just over 10 years back in 2012.
So if TinyBasic is a poor mans alternative to MS Basic (as it was in the mid 1970s), then VTL is the poor mans alternative to TinyBasic. It's terse, compact, faster than TinyBasic and has absolutely no error handling whatsoever. It uses unsigned 16-bit integers, has a similar number of variables to TinyBasic (A-Z plus a few more) and can directly peek/poke memory to use as an array.
Porting - well not as easy as it might first look due in some part to the way the code works and Michaels hard work to squeeze it down to as few bytes as possible. The original on the 6800 CPU was just under 768 bytes long - the 6502 version round about 1000. (Actually currently exactly 1000 byes in my port which I can reduce if I use the monitor line-input subroutine).
Things that tripped me up; Moving all the data to the first 128 bytes of ZP. Not obvious - there is a define in the source file that might suggest where the start in ZP, but later on in the source there is a "calculation" to define the real start - and worse, this is the start of variables (A-Z, etc.) and not the start of the built in variables. In my system I have ZP from $00 through $EF. The 16 bytes at $Fx are hardware IO - not my ideal preference, but when you only have 4KB of ROM and you want to maximise that for code, then something has to give. Anyway, I had to make sure VTL-2s ZP usage was $00 through $7F - there are a few other bytes used by the monitor for serial IO which were handy to keep and I made sure they were up above all that.
The following comment was left by Michael:
Code: Select all
The method
; employed must correspond to the zero-page equates
; above, or strange and not-so-wonderful bugs will
; befall the weary traveller on his or her porting
; journey.Moving on, another thing that tripped me up; The location of the input buffer. In Project-28 it's at $0100. Bottom of the 6502 stack because who needs a stack that deep? Not my monitor and not my TinyBasic, so that's OK. And, like ZP, the top 16 bytes at $01Fx are reserved for hardware IO (The VIA in this instance) So the 6502 stack start at $01EF which is fine... An additional quirk of P28 is that I copy the IO vectors to page 1 - so $0160 is the address of the Monitor entry point, and there are entries for character IO and so on ... This takes up some 30 bytes or so in the middle of page 1 - again not big deal in my existing Monitor + TinyBasic setup...
But there were 2 oddities in VTL-2...
VTL-2 copies input text from the input buffer to the program storage space via the stack - it pushes the data byte by byte into the stack, then pops it out into the target space - this is, AIUI, a handy way to work out the length of the space needed to move memory up as lines are inserted... It's also a good way to fill the stack up and overwrite the vectors. Fortunately with an input line limit of about 80 characters it's not really an issue... It can overwrite these vectors, but as they're really intended for use by code in another ROM Bank and we're running in the same bank as the monitor, we just call the monitor IO routines directly, so that's ok, but something to be aware of.
The other oddity caused me some head scratching for a while...
In VTL code accesses the data from the input buffer via the following line:
Code: Select all
lda linbuf-1,x ; and push statement string onMy assembler, ca65 from the cc65 suite looked at it and said: "A-Ha! linbuf is $0100. subtract 1 and you get $FF. That's ZP, so I'll use the ZP addressing method for that statement (saves a byte, yay!)". The down-side is the LDA ZP,X wraps while LDA ABS,X doesn't. So the program was taking data from $00, $01, etc. and storing it into the program space (via the stack) rather than data from the input buffer at $100, $101, etc. ...
ca65 has a special flag to force absolute mode, so:
Code: Select all
lda a:linbuf-1,x ; and push statement string onSo what now... I can jump from the monitor into VTL (type 'v') and type in VTL programs. I can download via serial the same way as in my TinyBasic by getting the terminal program to simply send a text file down the line and off we go.
VTL-2 is faster than TinyBasic, but it's harder to read. Also, only one statement per line. Unsigned 16-bit numbers. But even in 1977 memory was still expensive (The first Apple IIs had a 4KB option!) so for the hobbyist it was a good way to enable you to write code. VTL-2 is good enough to write simple games, even an arbitrary precision arithmetic package to calculate factorials - the example given maxes out at 208! with 1KB of storage - I have 3.5KB of storage but I didn't let it run that long... also a nice lunar lander program - not bad for unsigned integers...
It's verging on the esoteric, but still very usable. Usable today for anything other than an historical curiosity? Mabe, maybe not. Same for TinyBasic I guess. But who knows.
If it's there, maybe someone will use it...
-Gordon