Reflect (Mirrored Display Lists)
- Type
- Graphics
- Category
- Display list technique demo
- Author
- David Plotkin
- Published in
- Antic, September 1985 (Vol. 4, No. 5), "Mirrored Display Lists"
- Year
- 1985
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit computer, any memory size, Atari BASIC; disk or cassette
- Tags
- antic, display-list, lms, graphics-8, mirror, kaleidoscope, plotkin, tutorial, short-listing, 1985
About the program
The ANTIC chip doesn't care where its screen data comes from. Each line of a display list can carry a Load Memory Scan (LMS) instruction that points it at any address. David Plotkin's September 1985 article in Antic took that idea in an unusual direction. If the lines in the bottom half of the screen point at the top half's memory in reverse order, anything you draw at the top appears upside down at the bottom.
There are two pay-offs, and Plotkin pointed out both. The program only draws half as much, so effects such as stars streaming out from the centre of the screen run twice as fast. And both halves share one block of memory, which in GRAPHICS 8 saves about 4,000 bytes.
Typing it in
The listing is plain Atari BASIC with no special characters. Antic printed TYPO II checksums beside each line of the magazine listing, and they are not part of the program. Line 800 restores the top-of-RAM pointer in case you RUN the program twice.
How to use it
Just RUN it. A fan of lines sweeps across the top half of a GRAPHICS 8 screen, is wiped out and is drawn again, and the bottom half reflects every stroke. Press BREAK and then RESET (or type GRAPHICS 0) to get back to a normal screen.
How it works
- Line 1000 takes the top of RAM, sets aside 4K for the screen (
YSTART) and half a K below it for the new display list (DLS). Line 1010 lowers MEMTOP (locations 741–742) so that BASIC stays out of that area. - Lines 1010–1025 write three blank-line instructions (112), then a mode-15 (GRAPHICS 8) line with LMS pointing at
YSTART, then 95 more plain mode-15 lines. That's the normal top half, 96 scan lines. - Lines 1040–1060 are the trick. Every bottom-half line is written as
79(mode 15 + LMS) followed by its own address, starting at the middle of the screen and stepping back 40 bytes (one GRAPHICS 8 line) each time. The last line on the screen therefore shows the same bytes as the first. - Line 1070 ends the list with a jump-and-wait-for-vertical-blank (65) back to its own start. Line 1080 installs it through locations 560–561 and turns DMA back on.
- Locations 88–89 point the OS at
YSTART, so ordinaryPLOTandDRAWTOstatements draw into the shared memory.
Variations to try
Try your own drawing in place of lines 1100–1130. Random PLOTs with moving stars, or text drawn with PLOT, look striking. To mirror left to right as well, you would need to reverse the bytes themselves, which BASIC can't do quickly. The same up-and-down LMS trick works in other graphics modes if you change the mode number (15/79) and the bytes per line (40).
Listing
100 REM REFLECT
200 REM BY DAVID PLOTKIN
300 REM (c) 1985, ANTIC PUBLISHING
800 POKE 106,PEEK(740)
900 GRAPHICS 8+16:POKE 709,0:POKE 710,0
1000 YTOP=PEEK(106)*256-4*1024:YSTART=YTOP:DLS=YSTART-512:MEMTOP=DLS-1
1010 HIGH=INT(MEMTOP/256):LOW=MEMTOP-HIGH*256:POKE 741,LOW:POKE 742,HIGH:POKE DLS,112:POKE DLS+1,112
1020 POKE DLS+2,112:POKE DLS+3,79:HIGH=INT(YSTART/256):LOW=YSTART-HIGH*256:POKE DLS+4,LOW:POKE DLS+5,HIGH
1025 POKE 88,LOW:POKE 89,HIGH:FOR CNT=6 TO 100:POKE DLS+CNT,15:NEXT CNT:ADRS=YSTART+96*40
1040 FOR CNT=101 TO 389 STEP 3:ADRSH=INT(ADRS/256):ADRSL=ADRS-ADRSH*256
1050 POKE DLS+CNT,79:POKE DLS+CNT+1,ADRSL:POKE DLS+CNT+2,ADRSH
1060 ADRS=ADRS-40:NEXT CNT
1070 POKE DLS+392,65:HIGH=INT(DLS/256):LOW=DLS-HIGH*256:POKE DLS+393,LOW:POKE DLS+394,HIGH
1080 POKE 560,LOW:POKE 561,HIGH:POKE 709,202:POKE 54272,34
1090 PRINT #6;CHR$(125)
1100 FOR X=5 TO 315 STEP 5:COLOR 1
1110 FOR XX=0 TO 319 STEP 5:PLOT X,95:DRAWTO XX,0:NEXT XX
1120 COLOR 0:FOR XX=0 TO 319 STEP 5:PLOT X-5,95:DRAWTO XX,0:NEXT XX
1130 NEXT X:GOTO 1100
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: REFLECT.BAS.
Credits
- Program listing: Reflect (Mirrored Display Lists) — program listing (Antic, September 1985 (Vol. 4, No. 5), "Mirrored Display Lists") — David Plotkin
- Picture: Reflect at work: only the top half is ever drawn. The bottom half is the display list's mirror image. — David Plotkin (program); screenshot by the site
- Antic, September 1985 - Vol. 4 No. 5: article (atarimagazines.com) — David Plotkin, 1985
- Antic disk, September 1985 - Vol. 4 No. 5: REFLECT.BAS (detokenized listing) — AtariMagazines.com (Kevin Savetz), 1985
