Turn Coat
- Type
- Education
- Category
- Graphics mode 1/2 tutorial program
- Author
- Ted Murdoch
- Published in
- ANTIC Vol. 2 No. 5 (August 1983), "Starting Line" column
- Year
- 1983
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, 16K RAM, Atari BASIC
- Tags
- antic, starting-line, graphics-2, text-modes, locate, character-sets, simulation, beginner, atari-basic
- Related
- Holiday Greetings, Snowfall, Snowflakes, Bats, Black Box, Bounce
About the program
"Starting Line" was ANTIC's column for beginners, and in August 1983 Ted Murdoch used it to teach the two big-text graphics modes with a tiny simulation. Turn Coat fills a GRAPHICS 2 screen with a block of letter O's in four different colours. Then it starts picking two cells at random and copying one over the other. Sometimes the colour changes and sometimes it doesn't. Leave it running and, sooner or later, one colour takes over the whole block. You can't predict which.
Murdoch pointed out that this is a very simple model of species dying out by pure chance. The real lesson, though, is how GRAPHICS 1 and 2 get four text colours without a single COLOR or SETCOLOR statement.
What you need
Any 8-bit Atari with Atari BASIC. No joystick is needed.
Typing it in
Lines 260 and 270 contain an inverse-video letter. In this listing, {inverse}O{/inverse} means: press the Atari (inverse) key, type O, then press the Atari key again. Line 250 uses a lower-case o, and line 270 an inverse lower-case o. Those four ways of typing the letter are what give the four colours. If your keyboard makes inverse awkward, PRINT #6;CHR$(207) and PRINT #6;CHR$(239) do the same job.
Line 200 must read NROWS=8 with no space. Most commands have a line to themselves, so that you can change things easily, as the article intended. The REM lines can be left out.
How to use it
RUN it and watch. Press BREAK to stop, and type GRAPHICS 0 to get the normal screen back. The article suggested a series of experiments:
- Change
NROWS(line 200) andNCLMS(line 205). More than 11 rows or 19 columns gives error 141 (cursor out of range). Rows beyond 9 hide behind the text window. - Change
GRAPHICS 2toGRAPHICS 1for smaller letters, or to 17/18 to lose the text window. - Add
311 PRINT " ";CHN2;to see the codes that LOCATE reads back: 79, 111, 207 and 239. - Add
211 POKE 756,226to switch to the second 64-character set. The O's become lower case, and the blank cells fill with hearts.
How it works
- In GRAPHICS 1 and 2 each character cell can show 64 different shapes. The low six bits of the character code pick the shape, and the top two bits pick one of four colour registers. Upper case, lower case, inverse upper and inverse lower versions of the same letter therefore show the same shape in four colours.
LOCATE(line 310) reads the code of the character at a screen position.PRINT #6;CHR$(CHN2)(line 325) writes that same code, colour bits included, somewhere else.- Location 756 (CHBAS) sets which page of the ROM font is used. 224 is the default, and 226 is the set with lower case and the graphics symbols.
Variations to try
- Delete lines 315 and 320 to let the "extinction" run at full speed.
- Add SETCOLOR statements after line 210 (or after the block is drawn, at line 275) to change the four colours.
Listing
199 REM * Initialize number of rows and columns
200 NROWS=8
205 NCLMS=12
210 GRAPHICS 2
219 REM * Draw random array of cells
220 FOR RN=1 TO NROWS:FOR CN=1 TO NCLMS
225 POSITION CN,RN
229 REM * Select cell type
230 R=INT(RND(0)*4)+1
235 ON R GOTO 240,250,260,270
240 PRINT #6;"O"
245 GOTO 275
250 PRINT #6;"o"
255 GOTO 275
260 PRINT #6;"{inverse}O{/inverse}"
265 GOTO 275
270 PRINT #6;"{inverse}o{/inverse}"
275 NEXT CN:NEXT RN
276 REM * End of initial array
284 REM * Select cell to remove
285 ROW1=INT(RND(0)*NROWS)+1:CLM1=INT(RND(0)*NCLMS)+1
294 REM * Select cell to duplicate
295 ROW2=INT(RND(0)*NROWS)+1:CLM2=INT(RND(0)*NCLMS)+1
304 REM * Check that cells are different
305 IF ROW1=ROW2 AND CLM1=CLM2 THEN GOTO 295
309 REM * Find contents of cell to duplicate
310 LOCATE CLM2,ROW2,CHN2
314 REM * Remove cell
315 POSITION CLM1,ROW1:PRINT #6;" "
320 FOR T=1 TO 150:NEXT T
324 REM * Replace cell
325 POSITION CLM1,ROW1:PRINT #6;CHR$(CHN2)
329 REM * Continue to remove and replace
330 GOTO 285
Credits
- Program listing: Turn Coat — program listing (ANTIC Vol. 2 No. 5 (August 1983), "Starting Line" column) — Ted Murdoch
- Picture: Turn Coat a few seconds in: cells are being copied at random, and one cell is blank mid-swap. — Ted Murdoch (program); screenshot by the site
- ANTIC Vol. 2 No. 5 (August 1983) — Starting Line: Turn Coat, by Ted Murdoch — Ted Murdoch, 1983
