Greetings programmers! As promised we will be installing the rest of the code, completing our machine language version of CLASSY! Some anxious users have sent for advanced copies of CLASSY and many others have written with suggestions and comments. We will look at these as well. (And thanks again for all your letters!)
First let us review what we have done up until now:
-In PART ONE (Mar/Apr ’87) was the stand-alone BASIC CFE.
-In PART TWO (Jul/Aug ’87) we discussed the design of a machine code version and all the font code was given as DATA statements (comprising lines 1000 thru 1190).
-In PART THREE (Sep/Oct ’87) The beginning code was given (comprising lines 1 thru 90, the rest being a demo).
-In this portion (PART FOUR) we will add the last code and try out all of its features!
Before we add the new code, there are a change or two we need to make to the code from parts Two and Three. The needed alterations are shown in Figure B (and in Listing 3’s first small block if you are using an assembler). The +350 in line 7 must also now become +1501. Some refinements to the letter “N” and chr$ 199 are given in Figure C, but these can be left out if you wish.
If you have lines 1000 thru 1190 of Part Three and have made the changes as noted, we can add the final code! This is Listing 1, lines 100 thru 220. (A disassembly of this code appears as Listing 3). When this has been entered our CLASSY coded version is complete. It contains all of the code to function as well as all of the new font data and the BASIC version will load itself when RUN.
But in order to see CLASSY in action, we need to give it something to do! Listing 2 is a demo which produces the dummy menu screen shown in Figure A. If Listing 2 is too long for you just type in lines 2000 thru 2100 and it will produce the same screen (minus the window). Once this is in place (and SAVEd on tape) RUN the program and enjoy. The initial POKE loop to load the 1501 bytes of code takes 18 seconds. After a first run you can redraw th screen with a simple GO TO 2000 (no need to re-RUN and wait eighteen seconds to re-load code already in place.
Let’s look at the demo (Listing 2) in detail to better see the features CLASSY has built into it and how to work with them. A quick glance at the listing will show many lines with REM statements and “RANDOMIZE USER print”. The REM statement contain the PRINT coordinates and the items for CLASSY to print. The USER calls are always in the line just previous to a REM line and call CLASSY into action. There can be many other commands in the same line with the user call (see line 2005) as long as the very next thing is a new REM line. If not you will get an ERROR A.

The demo screen (Figure A) shows the complete CLASSY font as produced by lines 2050, 2070, and 2090. Most of the symbols are similar in the CLASSY font with the few exceptions as discussed in PART TWO. You will notice in line 2050 two apostrophes after the “!” in that line. This is a departure from Sinclair BASIC (Clive, forgive me!). In CLASSY two apostrophes = one quote symbol.
In lines 2070 and 2090 you will notice several ATs. AT is the kerning keyword to fit letters (like “A” and “T”) closer together. Each AT equals one pixel backspace. Line 2270 is replete with them. Another keyword (line 2010) is OR. This toggles in and out of inverse mode. Note that the word DEMO and arrow are printed inversely. Now since CLASSY printing is always in OVER mode, OR can also be used with INK and PAPER to erase words or we can use the old stand-by: PRINT “(spaces) “.
The keyword TO appears in line 2250 and toggles the vertical print mode. TO is real handy for columns! Notice that this line prints the dots downward in the demo’s window area. Not the last keyword you’ll find is NOT. NOT is the “Number of test” keyword. Since each CLASSY symbol has its own width, it would be nearly impossible to calculate a line’s length without NOT. With NOT once in line (see line 2290) the sum (up to 255) is tucked away in the 38th byte of CLASSY’s code. It needs only to be PEEKed (see lines 2300). But repeated PEEKing can be a chore. Using NOT twice in a line (see line 2340) will halt the program with ERROR = n. Looking up the chr$ code for “n” reveals it equals 110. And in this case 110 is the exact length of the line. NOT calculates all symbols, spaces, and ATs.
In order to get out of an ERROR loop just hit SHIFT+BREAK. The other ERROR messages are ERROR A for an improper word after REM, ERROR B for improper coordinate or variable, and ERROR C for an unknown symbol in the quotes. It’s conceivable you could crash CLASSY but with these error traps it’s pretty unlikely. Notwithstanding, it’s always wise to “Save it” ‘fore ya run it!”
The code also sorts for four more keywords which I’ve left user-definable. These are STEP, AND, THEN, and STOP. The jump table for these is eight bytes long and starts at the 530th byte in the code (at B1D9 in Listing 3). These are set now to jump to ERROR C, but you could reset these to your own custom routines. Where to put custom routines? Pretty simple, really. The font data sits on CLASSY like a cap. If we move the font data up we can gain the room we need. Just put the new offset number to the data into two pairs of bytes starting with the 507th byte (B1C2, Listing 3) and the 700th byte (B283, Listing 3). Then from the 711th byte (B28h) onward is room for new code!. There are also eight empty storage or flag bytes near the code’s beginning starting at the 30th byte (AFE5, Listing 3).
Figure B
“` 10 DATA 0,0,0,0,0,0,0,0,0,0,0, 0,0,213,197,229,245,217,8,213,19 7,229,245,237,91,176,92,24,13,0, 0,0,0 20 DATA 0,0,0,0,0,225,35,24,7, 42,85,92,1,5,0,9,126,254,173,32, 6,235,54,2,235,24,77,254,172,32, 6,235,54,1,235,24,67
1000 DATA 4,0,0,0,0,0,0,0.,3,0,9 4,94,0,0,0,0.,5,0,7,0,0,7,0,0.,6 ,34,255,34,34,255,34,0.,6,0,44,1 10,255,74,48,0 “`
Figure C
“` 1090 DATA 7,0,126,126,4,8,4,126. ,7,0,126,126,12,48,126,126.,6,0, 60,126,66,66,60,0.,6,0,126,126,1 8,18,12,0.,6,0,60,126,62,98,252, 0
1190 DATA 5,0,24,60,231,36,0,0., 6,255,119,219,119,219,255,0.,3,0 ,24,24,0,0,0,0.,7,24,48,96,48,8, 4,2 “`
HEART OF CFE “PRINTING” ROUTINE (m.c. version)
“` EXX swap 3 register-pair’s contents POP BC let C=X value, B=Y value EXX swap contents back LD B,A put width in B SYMBOL: INC HL point to next graphic byte XOR A zero carry flag LD A, (HL) put next graphic byte in A PUSH BC save width LD B, 8 set counter to eight (8 bits!) NEXTBIT: RLA A’s left-most bit into carry EXX swap contents JR NC,Y_UP if carry=0 jump to Y UP (in inverse plotting this becomes JR C,Y_UP) PUSH BC save X,Y values PUSH AF save graphic byte & carry flag CALL 9790 (263Eh) call ROM plot routine POP AF restore AF POP BC restore BC Y UP: INC B increase Y value by one EXX swap contents back DJNZ, NEXTBIT if 8 bits not done, to NEXTBIT POP BC width restored EXX swap contents (BC=X,Y values) INC C add one to X LD A, B drop Y value by eight ADD A, 248 (F8h) LD B, A EXX swap contents back DJNZ, SYMBOL if all bytes not seen to SYMBOL “`
Figure D
Now a couple of other tips before we move on. The REM lines 2030 and 2050 show that REM acts as PRINT does in a BASIC print statement. AT and the absence of coordinates is accepted as in Sinclair BASIC. TAB is also accepted. TAB can act even as a backspace. A line like REM TAB 10;”B”;TAB 9;”3″ will print 38!. If you use variables (a thru h) the values must first be POKEd into place. This was shown in the demo in PART III. INK and PAPER can be changed but must be done outside a REM line. Such commands in quotes will give ERROR C.
In the interest of space and time (‘sounds like Carl Sagan!), I can’t possibly detail every machine code routine in CLASSY, so I’ll review the heart of CLASSY’s crazy printing abilities. This 35 byte code is found in line 180, also at B1E9 in Listing 3, and is also shown in Figure D. We enter this routine with the following: The top stack values are the X and Y plot values, HL has the address of the first of eight bytes of font data for a particular symbol, and A contains the contents of that first byte (the width). If you are unfamiliar with Z80 code, I would recommend studying Syd Wyncoop‘s eleven lessons on Z80 code starting with the March/April ’86 issue of Time Designs to present (all eleven issues are still in stock for $3 each). Specifically if you are not familiar with XOR, RLA, or EXX read lessons #6 and #7 (in Jan/Feb ’87 and Mar/Apr ’87). Lessons #4 and #5 contain almost all the other machine language instructions found in this print routine. Study Figure D and the remarks for each instruction and you will see how it was relatively easy to plot pixels vertically to form characters instead of horizontally like the ROM does it. This routine calls a 114 byte ROM plot routine starting at 9790 (263Eh) for each pixel plotted. The ROM routine actually starts at 9784 (2638h) but we by-pass 36 bytes of un-needed temp color code by entering late. In either case BC must contain the plot coordinates before the call. The order is C = X and B = Y.
I hope no matter what you level of skill in programming, that you will enjoy CLASSY FRONT END. It is truly fun to play around with. And you must play around with it to become familiar with it. If you have any questions or comments, please write. Now you may save yourself some embarrasment (and me some paper) if you read PART II, III, and IV carefully first…many of the recent questions I answered by referring to a past article. Nonetheless, if you have a problem, write. No question is a bad one if your learning! Next time perhaps we will tackle true windowing in conjunction with our new program. Until then, may all your drives be snappy–and all your monitors be bright! And HAPPY HOLIDAYS!
***If you would like a copy of the complete machine code version of CLASSY FRONT END on a new cassette, just send $5.00. I also offer a cassette of many past programs called “BINGHAM’s BEST” which also contains the BASIC and the machine code versions of CLASSY all for $9.95. Just send it to: Paul Bingham, PO Box 2034, Mesa, AZ 85214.
Listing 1
“` 100 DATA 35,24,2,24,141,126,254 ,34,32,51,35,126,254,58,32,18,22 9,33,38,0,229,46,11,124,25,119,3 5,126,214,8,119,225,25,233,254,5 9,40,5 110 DATA 33,126,0,24,233,35,126 ,254,13,32,5,33,126,0,25,233,43, 229,33,38,0,25,233,254,39,32,14, 35,126,254,39,32,4,62,34,24,8,43 ,126,24,4 120 DATA 203,127,32,20,6,7,229, 213,22,0,95,213,225,25,16,253,20 9,229,24,122,198,185,24,236,254, 199,40,248,254,200,40,244,254,20 1,40,240 130 DATA 24,5,235,22,67,24,136, 254,197,40,77,254,195,40,114,254 ,172,40,120,254,204,40,18,254,20 3,40,104,254,198,40,102,254,205, 40,100,254,226,40,98 140 DATA 24,217,229,213,225,35, 126,254,1,40,7,54,1,1,138,24,24, 5,54,0,1,217,229,33,73,2,25,112, 35,113,24,123,229,8,217,197,245, 121,193,144 150 DATA 193,79,120,198,248,71, 8,24,101,229,33,45,2,25,126,254, 56,40,4,54,56,24,2,54,48,24,88 160 DATA 193,33,198,1,25,9,8,12 6,8,126,213,229,33,11,0,25,78,35 ,70,225,197,24,18 170 DATA 24,68,24,162,24,160,24 ,158,24,156,229,33,11,0,25,53,24 ,47 180 DATA 217,193,217,71,35,175, 126,197,6,8,23,217,48,7,197,245, 205,62,38,241,193,4,217,16,241,1 93,217,12,120,198,248,71,217,16, 225 190 DATA 209,33,11,0,25,229,217 ,225,113,35,112,217,33,26,1,25,2 33 200 DATA 62,0,50,119,92,35,126, 254,34,40,37,254,195,32,46,213,2 25,1,116,0,9,54,61,35,35,35,58,1 19,92,6,2,79,175,121,23,56,4,16, 251,14,32,121,119,33,92,0,25,233 210 DATA 33,37,0,25,58,119,92,1 19,33,126,0,25,233,203,127,40,21 ,1,199,2,185,40,13,12,16,250,254 ,172,32,183,58,119,92,61,24,174, 198,185 220 DATA 229,213,6,7,22,0,95,21 3,225,25,16,253,209,229,193,33,1 98,1,25,9,58,119,92,134,225,24,1 45 “`



