Sei sulla pagina 1di 4
eK ECB. The third in a series of tutorials for the beginner to intermediate machine language programmer Machine Language Made BASIC Part III: What a Dump! ‘umps are simply programs that Die images from the screen to paper by way of a printer, The programs shown in Listings 1 and 2 are for a seven-dot printer that adds 128 to the total value of the dots used for graphic printing. Listing | is the BASIC version and Listing 2isa machine language version.The seven dots in a column have a value of 1, 2,4, 8, 16, 32, and 64, starting from the top. The values of the dots you want to print are added together and then added to 128, The total value is sent to the printer as a CHRS value, Printer commands used in this program are: CHRS(18) - set for graphics CHRS(27) 3 CHRS( 16) - position the print head CHRS (0) ; CHRS(50) -50 spaces over CHRS(30) - end graphics mode Check your printer manual for any changes to these CHRS, Location S6F tells the computer Bill Nee bucked the “snowbird” trend by retiring to Wisconsin from a banking career in Florida. He spends the long, cold winters writing programs for his CoCo. 98 © THERAINGOW September 1988 —— EE ————————————————— By William P. Nee which device will display or receive information as follows: SOF Device -2(HSFE) printer -1(HSFF) tape recorder @ sereen 2-15 disk Locations $84 and BB give the location of beginning graphics — usually at 5622, or SE@@ with disk. The BIT command is a quick way to test each bit in a byte and branch accordingly. We will check each bit to see if it is a zero, and we'll branch if it is, The BIT command €NDs a number in registers A or B with any other number you select; but unlike the AND com- mand, the number in registers A or B remains unchanged — only the values of the condition codes (CC) register are affected. The CC register is the register to which all branches look to see if the conditions for a branch have been met (plus, minus, equal, zero, etc.). The rules for AND are AND O=0 OND I 1ANDO=0 Tend 1=1 Another way to think of this is: any number AND 0 = 0, any number AND 1 = the same number. Now, how do we test the left bit (Bit 7) in Register A to see if it is a0 or a 1 We must BITA with the number 128, This is easier to see when written in the binary format (Base 2): let Register A = 149 = 10010101 BITA with #128 = 10000000 CC register = 10000000 Since the result is not 0, the CC register will not be set to 0 and a BEQ (Branch if EQual to 0) will not execute, so the program. will continue with its next command, If you continue to BTA with 64, 32, 16, 8, 4, 2 and 1, you can check each bit and branch accordingly. Since the printer can type a column seven bytes high, this program will look at the left bit in each of the seven stacked bytes, then the next bit over, and the next, etc., until reaching the right bit (Bit 0). If a bit is 1, the value of the CHRS to be printed is increased by the dot’s value according to its location in the column: Dot Value 1 2 4 8 16 32 64 Nausea Finally, 128 is added to the total value ‘and the result is sent to the printer as a CHRS (value). The routine at $8002 sends the value in Register A to what- ever deviceisindicated by Location $F. ‘The brackets around PRINT in the program mean to use the values in 59002 and $A@03 as the JSR address Those values may differ in various Color Computer models, but the 58002 should remain the same. ‘The end of the program uses CLR S6F to set Location $6F to 0, the device number for the sereen. CLR is the fastest ‘command available to set any memory byte or single-byte register such as A, B or CC to 0. CLRA executes more quickly and uses less memory than LDA Fe. In one portion of the program we used LENE (Long Branch if Not Equal) instead of BNE. This is because a regular Branch can only move backward -128 spaces or forward +127 spaces (re- member “signed” numbers?); a Long Branch can branch anywhere in the program but consumes a little more ‘memory. Use the regular branch when- ever possible; EDTASM* will let you know if a Long Branch is necessary. It is good, though, to use JSR when ref- erring to ROM routines. Listing 1: DUMPBAS 1p CLEAR299 , &H3999-1 29 ‘SAMPLE GRAPHICS PROGRAN 39 PMODE 4,1:PCLS5:SCREENL,1 49 FOR X=f 10 254 STEP 2 59 1 69 NEXT 79 FOR Y=199 TO 9 STEP -2 89 LINE(g,¥)-(255,191-¥) , PRESET 99 NEXT 198 DRAW"CSEMSS, 69M+6 , +1 PESFSM+6 1-1 #BR6DSNDSR1SNUSD5BRGE1PFENL12 F4BRIGULPNLIPRIB" 119 DRAW"BM129 , 199E19F6NL12F4" on 129 DRAW" BMA@, 13BU1PR18F2D6G2NL1 @5R@SU2NUSF2R14E2U8BD19BR6M+S ,-1 BESESM+6 , +19BR6U1PR18F2D3G2L18" 139 'THE' DUMP PROGRAM 14p 'EXEC GHSpp9 OR - 158 PRINT#-2,CHRS (18) 166 FOR V=p TO 182 STEP 7 179 PRINTE=2,CHRS (27) ;CHRS(16) 7¢ HRS (@) ;CERS (52) 186 FOR Heg TO 255:P=p 198 FOR N=p To 6 299 IF PPOINT(H,V+N)<>$ THEN 420N 21p 228 239 PRINT#-2:NEXT V 249 PRINT#-2,CHRS (3) NEXT W © eS (X,9)~(255-X, 191) , PRESET. PRINT#-2, CHR$ (P+128) ;:NEXT H ‘The BASIC program for the “dump” takes advantage of the BASIC PPOINT command to see if each bitin the seven- byte column is set or not. If itis set, the value of the CHRS is increased and’128 is added to the total value, The resulting character is sent to the printer, Sample printout using a Radio Shack DMP-105 ‘The PPOINT method could have been used in the machine language program, but itis still a slow command, We wil however, use this command in futu articles to write programs involving graphics. Both programs will run for a while without printing anything since the printer buffer must be filled before printing. The buffer stores what the computer has been sending it until Supports ‘soe ‘The commands Tandy Tete out! any palettes you wanton power=up, Shove” a joystler at's HaiSoft KEYBOARD CABLE... foot extender cable for Coco IT and 3. ready. Then it prints it all at once, rather than printing out one CHRS at a time, Both programs also skip printing the bottom three lines of graphics. You can add your own routines if you want them, Be sure to clear space before running the machine language program from BASIC: CLEAR 200, 8H13000-1 The time difference between the two programs is amazing. The BASIC pro- gram can take up to twenty minutes to copy a graphics page, while the machine language program can do the job in about three minutes. It’s a longer pro- gram, but if you're doing a lot of repe- titious dumping (Christmas cards, for example) it is quite a time-saver, The machine language program is designed for PHODE 4, since we're not using a color printer. Try experimenting with a program that dumps from top to bottom of the page rather than from left to right. This prints the picture sideways but allows you to double its size. You might also iry to reverse the picture. (Questions or comments concerning this tutorial may be addressed 10 the author at Route 2, Box 216C, Mason, WI 54856-9302. Please enclose an SASE when requesting a reply.) the "Rise" "ang bea RS Speech Paks Screen echo and SAV command. for Ineeai tation ‘Si2-7he-s0e4 September 1960 THERAINGOW 99 Listing 2: OUMPEIN 3999 ooigs onc (93999 agg2 gil PRINT EQU —«$A9B2_-PRINT ROUTINE 2999 86 FE ggi2g START LDA #-2. ‘USING THE PRINTER 3992 97 6F go.39 STA $6F 399% 86 12 9g139 LDA #18._——“TEXT TO GRAPHICS 3996 AD OF Agg2 gplég JSR [PRINT] 39a BE 39CC LIB Lx WVTABLE 399D DE BA gpieg LDU $BA START OF GRAPHICS 399F 86 1B gp199 LDA #27 NUMBER OF ROWS 3g11 B7 3gca 99299 STA DOWN agls 86 1B 9219 LOOPS. «LDA «#27 MOVE THE 3gl6 AD SF age2 gg22g Jsk [PRINT] 3pla 86 1g 99239 WDA #16 PRINTER HEAD aplc aD 9F agg2 gp2ag JsR [PRINT] 3g29 86 9p 99259 WA Wg OVER 3922 aD OF Agg2 gp26g JsR [PRINT] 3926 88 32 90279 LDA #5859 SPACES 3928 AD 9F Agg2 gp2eg JsR [PRINT] 3g2c 86g 99299 ‘LDA #32 BYTES PER LINE 392E BT 3969 99399 STA ROW 3931 C6 8 99319 LOOP2 = LDB #8 BITS PER BYTE 3933 7F 390B ©9328 LOOP] CLR VALUE 3936 A649 99339 WA g,U_—FIRST BIT IN THE COLUMN 3938 AS 85 99349 BITA BX AND A WITH B,X 393A 27 93 99359 BEQ NEXT? 3g3c 76 | 39CB 99369 INC VALUE 393F a6 CB O29 99379 NEXT2 LDA 32,0 SECOND BIT IN THE COLUMN 3942 aS a5 go30g BITA BX AND A WITH B,X 3944 27° 98 99399 BEQ NEXT3 3946 BE = 39CB gauge ‘LDA VALUE 3949 8B 92 Peas ADDA #2 3948 B7 3gcB. gang STA VALUE 3948 A6 C3 49 © G943P NEXT3 LDA «64, THIRD BIT IN THE COLUMN 3951 AS 85 99449 BITA BX AND A WITH B,X 3953 27 98 99459 BEQ.—NEXT4 355 Bs 39cR gana LA VALUE 3958 8B Bd. gg479 ADDA #4 395A 87 3pcRgp4ag STA VALUE 395d A6 CB 69 ©—U49B NEXT4 LDA 96, FOURTH BIT IN THE COLUMN ageg a5 a5 90599 BITA BX AND A WITH B,X 3962 27 98 ggsig BEQ NEXTS 3964 BE | 39CB G9529 LDA VALUE 3p67 88 98 99539 ADDA #8 3969 87 3pcn sug STA VALUE 3péc a6 C9 pag POSS NEXTS LDA 128,U FIFTH BIT IN THE COLUMN 3978 AS 8S 99569 BITA BX. AND A WITH B,x 3972 27 98 99579 BEQ -NEXTS 3g74 B6 3gcB | gseg WA VALUE 3977 Bg 99599 ADDA #16 3979 B7 39CB pega STA VALUE 397C A6 C9 PAG BO6LP NEXTS LDA —169,U_ SIXTH BIT IN THE COLUMN 3gep as 85 99629 BITA BX. AND A WITH B,X 3982 27 98 99639 BEQ NEXT? 3984 36 3p0 —gpsag WDA VALUE 3987 88 29 99659 ADA #32 3989 87 3pca seg STA VALUE 3gac AS C9 PCP AV67H NEXT? LDA «192, SEVENTH BIT IN THE COLUMN. 399g AS a5 ggceg BITA B,X AND A WITH B,X 3992 27 98 99699 BEQ PANT 3994 BE _39CB 99799 LDA VALUE 3997 8B 4p gg7lg ADDA #64 100 THERAINBOW — September 1988, _—