Authors
Publication
Pub Details
Date
Pages
BASIC Terms
Here we are again, in the Machine Code Corner. This month, I am going to show you some ROM routines that use the TS2040 printer! But first, an apology.
Last month, I gave you two routines that scrolled part of the screen left and right. For one reason or another, the BASIC loader did not get printed. For those who looked all over the newsletter for it, please forgive me. You will find it at the end of this month’s column, along with a reprint of the HEX codes and mnemonics.
Now some of you, I am sure, know how to print things to the printer from machine code already. For those of you who do not, this month’s discussion should help you along.
First, the PRINTER BUFFER. Located at 23296 decimal, 5B00 hex, it contains information to be dumped to the printer itself. The buffer is only 256 bytes long (FF hex), so the computer can send only so much at one time.
The buffer is set up just like the display file (oh no!), only it is one line of data, 32 bytes wide, and 8 bytes deep, exactly like one line in the display file. This allows you to send bits of information to the printer, instead of just character codes, like other printers.
Now we get to the good stuff. The printer dump routine itself is not that long, if you don’t count the subroutines that it uses. It is located at 2595 decimal, or 0A23 hex. This routine simply takes what is in the printer buffer and sends it to the printer. Then it clears the buffer and returns to where it came from. For those of you who go through the function dispatcher for the printer routines, you no longer need to punish youself with such travesty! You can go straight to the source.
The COPY command from BASIC is just as easily done in machine code as it is to type COPY from the keyboard. The routine to do it is located at 2562 decimal, 0A02 hex. It sets up a loop (for the 22 lines of the screen to be copied), loads the printer buffer with the first 8 “scan” lines (when I say “scan” lines in this column, I mean the 8 horizontal bytes used to form a character on the screen) of the display file, and calls the printer dump routine. Then it counts down the loop, loading the buffer with the next line of data from the display file, dumping it, and so on and so forth until all 22 lines are copied. But what about the bottom two lines of the screen? There are a lot of programs that use those lines and how in the world can I get them to the printer? Read on, my friend…
There is a way to print all 24 lines of the screen to the printer, but it requires just a teensy bit of preparation to do so. Also, you need to call a different address in the ROM. Here is what you need to do. Load your hex loader or assembler, or if you don’t have one, get out the BASIC loader below and type the routine in. After doing so, PLEASE (!!!) save it to tape. Here is the HEX codes with mnemonics, with the BASIC loader following:
24 Line Screen Dump
(This routine can be located anywhere in memory.)
FF46 F3 DI TAKE OUT INTERRUPTS FF47 06 C0 LD B,C0H LET B=192 FF49 CD 05 0A CALL 0A05H RANDOMIZE USR 2565 FF4C C9 RET BACK TO CALLER
10 FOR N=65350 TO 65356: READ X: POKE N,X: NEXT N
15 DATA 243,6,192,205,5,10,201
There you have it. All 24 lines to the printer. You can change the 192 in the BASIC loader or the C0 in the hex listing, so that you could copy only 8 lines of the screen… Just change it to 64 decimal in the BASIC loader and in the hex listing, to 40 hex. Very simple!
If you want to print more or less than that, all you must do is change the B register to however many “scan” lines you want printed. Keep in mind that it counts from the top of the screen, so you can’t copy the middle of the screen, unless you use yet another routine…
The next routine I am going to give you can be used to copy nearly any part of the screen, 32 columns across (I haven’t worked out a way to print only 16 columns yet).
You must first find out the address of the first byte to copy (it can be anywhere in the display file), and then find out how many “scan” lines you want to print. Then you call the ROM routine! Here it is:
Part-Copy Routine
(This routine can be located anywhere in memory.)
21 NN NN LD HL,NNNN HL=START OF COPY\n06 NN LD B,NN B=# OF SCAN LINES F3 DI TAKE OUT INTERRUPTS CD 08 0A CALL 0A08H RANDOMIZE USR 2568 C9 RET BACK TO CALLER
10 FOR N=65350 TO 65359: READ X: POKE N,X: NEXT N
15 DATA 33,NN,NN,6,NN,243,205,8,10,201
NOTE: “NN” means you put in your own numbers or ones off of the following table! Here are some key spots on the screen:
| Hex | Decimal | Comment | |
|---|---|---|---|
| 4000 | 16384 | (0,64) | AT 0,0 |
| 4020 | 16416 | (32,64) | AT 1,0 |
| 4040 | 16448 | (64,64) | AT 2,0 |
| 4060 | 16480 | (96,64) | AT 3,0 |
| 4080 | 16512 | (128,64) | AT 4,0 |
| 40A0 | 16544 | (160,64) | AT 5,0 |
| 40C0 | 16576 | (192,64)1 | AT 6,0 |
| 40E0 | 16608 | (224,64) | AT 7,0 |
| 4800 | 18432 | (0,72) | AT 8,0 |
| 4820 | 18464 | (32,72) | AT 9,0 |
| 4840 | 18496 | (64,72) | AT 10,0 |
| 4860 | 18528 | (96,72) | AT 11,0 |
| 4880 | 18560 | (128,72) | AT 12,0 |
| 48A0 | 18592 | (160,72) | AT 13,0 |
| 48C0 | 18624 | (192,72) | AT 14,0 |
| 48E0 | 18656 | (224,72) | AT 15,0 |
| 5000 | 20480 | (0,80) | AT 16,0 |
| 5020 | 20512 | (32,80) | AT 17,0 |
| 5040 | 20544 | (64,80) | AT 18,0 |
| 5060 | 20576 | (96,80) | AT 19,0 |
| 5080 | 20608 | (128,80) | AT 20,0 |
| 50A0 | 20640 | (160,80) | AT 21,0 |
| 50C0 | 20672 | (192,80) | AT 22,0 — INPUT AREA |
| 50E0 | 20704 | (224,80) | AT 23,0 — INPUT AREA |
Well, there you have it. All you have to do is copy the numbers in parentheses () off of the table and into the BASIC loader. Then set up the B register with the number of scan lines, and call the routine!
Now, for that BASIC loader for SCREEN SCROLL:
1 REM SCREEN SCROLL- USR 65280 FOR LEFT, USR 65298 FOR RIGHT.
5 CLEAR 65279
10 FOR N=65280 TO 65315: READ X: POKE N,X: NEXT N
15 DATA 33,255,71,14,32,167,203,22,43,13,32,250,62,64,188,32,242,201
20 DATA 33,0,64,14,32,167,203,30,35,13,32,250,62,72,188,32,242,201
Here is the HEX dump:
TOP THIRD TO THE LEFT FF00 21 FF 47 LD HL,47FFH HL=18431 FF03 0E 20 LD C,20H C=32 FF05 A7 AND A CLEAR CARRY FF06 CB 16 RL (HL) SEE JULY NEWSLETTER FF08 2B DEC HL HL=HL-1 FF09 0D DEC C C=C-1 FF0A 20 FA JR NZ,FF06H GOTO FF06 IF C<>0 FF0C 3E 40 LD A,40H A=64 FF0E BC CP H IF A=H THEN SET Z FLAG FF0F 20 F2 JR NZ,FF03H GOTO FF03 IF H<>A FF11 C9 RET BACK TO CALLER TOP THIRD TO THE RIGHT FF12 21 00 40 LD HL,4000H HL=16384 FF15 0E 20 LD C,20H C=32 FF17 A7 AND A RESET CARRY FLAG FF18 CB 1E RR (HL) SEE JULY NEWSLETTER FF1A 23 INC HL HL=HL+1 FF1B 0D DEC C C=C-1 FF1C 20 FA JR NZ,FF18H GOTO FF18 IF C<>0 FF1E 3E 48 LD A,48H A=72 FF20 BC CP H IF A=H THEN SET Z FLAG FF21 20 F2 JR NZ,FF15H GOTO FF15 IF Z FLAG NOT SET FF23 C9 RET BACK TO CALLER
Products
Media
Image Gallery
Source Code
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.