Instant Character Set Copy with Strings
- Type
- Utility
- Category
- Character set utility / BASIC string trick
- Author
- David Small, Sandy Small and George Blank (editors)
- Published in
- The Creative Atari (Creative Computing Press, 1983), "Character Sets", Program 29
- Year
- 1983
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, 16K RAM, Atari BASIC
About the program
The Creative Atari (Creative Computing Press, 1983) gathered the Atari material from Creative Computing magazine, much of it by the book's editors David and Sandy Small and George Blank, together with new chapters. Its graphics tutorial works step by step from the TV picture up to player/missile graphics and character sets, with a short program at each step. Copying the 1024-byte character set from ROM to RAM with a FOR–NEXT loop of PEEKs and POKEs takes several seconds in Atari BASIC, and the chapter's earlier programs do exactly that. This one does it instantly. It uses the fact that Atari BASIC moves strings with fast internal machine code. The program tells BASIC that ROM$ lives at the ROM font's address and that RAM$ lives in a reserved 4K block at the top of RAM, and then copies one string to the other.
What you need
Any Atari 8-bit with Atari BASIC.
Typing it in
Plain ASCII, and nearly half the lines are REMs. One rule matters: RAM$ and ROM$ must be the first two variables BASIC knows about, because lines 330–480 rewrite variable table entries 0 and 1. Type NEW before you enter the program, and make line 10 the first line that names a variable. If you have been editing a lot, LIST the program to disk or cassette, type NEW and ENTER it back to clean out the variable table.
How to use it
RUN it. The screen clears, then the character set is copied in a blink and the screen uses the RAM copy. It looks exactly the same, because it is an exact copy, but now you can change it. For example, POKE PEEK(106)*256+8,255 alters the top row of the "!" character. Press RESET to return to the ROM font.
How it works
- Locations 134/135 (VVTP) point to the variable value table, and 140/141 (STARP) to the string/array area. Each table entry is 8 bytes long. For a string it holds a type byte (129 for a DIMmed string), the variable number, a 2-byte offset from STARP, and two 2-byte length fields.
- Lines 120–130 lower RAMTOP by 16 pages (4K) and reset the screen with GRAPHICS 0, which leaves a safe area for the new font.
- Lines 160–280 work out how far the new RAM area and the ROM font at 57344 (14×4096) are from the start of the string area, and split those offsets and the length into low and high bytes.
- Lines 330–480 POKE those values into the two table entries. After that,
RAM$is the reserved RAM andROM$is the ROM font, each 1025 bytes long. - Line 510 points CHBAS (756) at the RAM area, and line 520 does the copy with one string assignment.
Variations to try
- Use the same method to copy a redefined set from a DATA-loaded string, or to save and restore whole screens. Point a string at screen memory (
PEEK(88)+256*PEEK(89)). - After the copy, add a FOR loop that rewrites a few characters as game graphics.
Listing
5 REM PROGRAM TO COPY ROM TO RAM
6 REM USING STRING MANIPULATORS
7 REM
8 REM NOTE MOST CALCULATIONS ARE NOT
9 REM HARDCODED TO ALLOW OTHER USE
10 DIM RAM$(1),ROM$(1):REM VT ENTRY 1
90 REM GET ARRAY,VARIABLE,DL,DM LOC
105 AT=PEEK(140)+256*PEEK(141)
110 VT=PEEK(134)+256*PEEK(135)
120 POKE 106,PEEK(106)-16:REM 4K MOVE
125 GRAPHICS 0:REM RESET OUT OF TOP AREA
130 RAMLOC=PEEK(106)*256
150 REM CALCULATE OFFSET FROM AT
160 OFFRAM=RAMLOC-AT
170 OFFROM=(14*4096)-AT
220 REM CALCULATE LO,HI BYTES
225 LENS=1025:REM C-SET LENGTH
230 LENHI=INT(LENS/256)
240 LENLO=INT(LENS-(LENHI*256))
245 REM
250 OFFRAMH=INT(OFFRAM/256)
260 OFFRAML=INT(OFFRAM-(256*OFFRAMH))
270 OFFROMH=INT(OFFROM/256)
280 OFFROML=INT(OFFROM-(256*OFFROMH))
300 REM REWRITE RAMS DATA' IN VT
310 REM VT+0 = 129
320 REM VT+1 = 0 (VAR #0)
330 POKE VT+2,OFFRAML:REM OFFSET
340 POKE VT+3,OFFRAMH:REM OFFSET
350 POKE VT+4,LENLO:REM DIM LENGTH
360 POKE VT+5,LENHI:REM DIM LENGTH
370 POKE VT+6,LENLO:REM USED LENGTH
380 POKE VT+7,LENHI:REM USED LENGTH
400 REM REWRITE ROM$ DATA IN VT
410 REM VT+8 = 129
420 REM VT+9 = 1 (VAR #)0
430 POKE VT+10,OFFROML:REM OFFSET
440 POKE VT+11,OFFROMH:REM OFFSET
450 POKE VT+12,LENLO:REM DIM LENGTH
460 POKE VT+13,LENHI:REM DIM LENGTH
470 POKE VT+14,LENLO:REM USED LENGTH
480 POKE VT+15,LENHI:REM USED LENGTH
500 REM RESTORE CHBAS POINTER
510 POKE 756,PEEK(106)
520 RAM$=ROM$
Credits
- Program listing: Instant Character Set Copy with Strings — program listing (The Creative Atari (Creative Computing Press, 1983), "Character Sets", Program 29) — David Small, Sandy Small and George Blank (editors)
- The Creative Atari — Character Sets (atariarchives.org) — David Small, Sandy Small and George Blank (editors)
