Candle, Candle Burning Bright

Type
Education
Category
Science simulation (candle under a jar)
Author
Linda M. Schreiber
Published in
Antic, December 1982 (Vol. 1, No. 5); reprinted in The Best of Antic, Volume 1
Year
1982
Language
Atari BASIC (with two short machine-language strings)
Requirements
16K RAM, Atari BASIC
A blue glass jar lowered over a green candle on a grey dish, with blue oxygen dots scattered in the black sky around it

About the program

Linda Schreiber wrote this for Antic's December 1982 issue. The article starts with a survey of educational software: drill and practice ("electronic flash cards"), tutorials, and "educational games" that sometimes teach nothing but hand-eye coordination. She argued that simulation was the category where computers could do the most good, and that there were very few good simulation programs.

Her example is the classic school experiment. A candle stands on a dish with a glass jar hovering above it. Light the candle, lower the jar, and the drifting dots, which stand for oxygen, are used up one by one inside the jar until the flame dies. Young children can see the experiment "safely", as she put it, and repeat it as often as they like.

Typing it in

Lines 50 and 60 are machine code stored in strings, and the article warns that they must be typed exactly. {inv}…{/inv} means inverse video (press the Atari key before and after). {CTRL-,} is CTRL with comma (the heart character) and {CTRL-.} is CTRL with full stop. {INS CHAR} in line 60 is character 255. Inside quotes you get it by pressing ESC, then CTRL-INSERT. Line 360 has inverse START and SELECT, which are just for show.

How to use it

  • SELECT lights the candle. Hold it until the flame appears.
  • START lowers the jar (or raises it again). Hold it until the jar starts to move.

The candle can't be lit while the jar is down. With the jar down, one oxygen dot vanishes on each pass round the loop and the flame flickers until none are left. Then it goes out. Raise the jar before that happens and fresh oxygen comes back, and the candle keeps burning.

How it works

  • Player/missile graphics. Line 40 reserves memory 32 pages below the top of RAM. Line 90 turns on single-line player/missile graphics (POKE 559,62, POKE 53277,3). Player 0 is the flame, player 1 the candle and player 2 the jar. The jar is a quadruple-width player (POKE 53258,3) drawn as a 255 byte for the top and 129 bytes for the sides.
  • The flame flickers because line 530 POKEs one of three shapes (DATA 531–533) into player 0 at random.
  • The machine code. UP$ and DOWN$ are each about a dozen bytes. They copy every byte of player 2's 256-byte area one place up or down, using the pointer the program stores in locations 205–206. Calling one of them 51 times slides the whole jar smoothly, much faster than BASIC could.
  • The oxygen is GRAPHICS 7 pixels. Their positions are kept in arrays OS (outside the jar) and OJ (inside), so the program can erase and re-plot them to make them drift. The dish is filled with the OS fill command (XIO 18).

Listing

10 REM *** BURNING CANDLE SIMULATION ***
20 REM BY LINDA M. SCHREIBER FOR ANTIC DEC. 1982
30 DIM OS(50,2),OJ(10,2),UP$(13),DOWN$(13)
40 A=PEEK(106)-32:REM SET ASIDE 2K FOR PLAYER/MISSILE GRAPHICS - GRAPHICS 7 NEEDS 4K
50 UP$="h{inv} {/inv}{CTRL-,}{inv}H1M{CTRL-H}{CTRL-Q}MHPw{/inv}{CTRL-.}"
60 DOWN$="h{inv} {/inv}{INS CHAR}{inv}{CTRL-H}1MH{CTRL-Q}M{CTRL-H}Pw{/inv}{CTRL-.}"
70 GRAPHICS 7:REM HIGH RESOLUTION WITH TEXT WINDOW
80 POKE 54279,A:PMBASE=A*256:REM TELL ANTIC WHERE P/M GRAPHICS BEGIN
90 POKE 559,62:POKE 53277,3:REM ENABLE P/M GRAPHICS FOR SINGLE LINE RESOLUTION
100 POKE 704,104:REM COLOR OF FLAME
110 POKE 705,200:REM COLOR OF CANDLE
120 POKE 706,120:REM COLOR OF JAR
130 POKE 708,154:REM COLOR OF OXYGEN
140 POKE 709,8:REM COLOR OF DISH
150 FOR X=PMBASE+1024 TO PMBASE+2043:POKE X,0:NEXT X:REM CLEAR MEMORY FOR GRAPHICS
160 COLOR 2:PLOT 100,75:DRAWTO 110,70:DRAWTO 40,70:POSITION 50,75
170 POKE 765,2:XIO 18,#6,0,0,"S:"
180 CANDLE=PMBASE+1426:REM LOCATION OF CANDLE IN P/M MEMORY
190 RESTORE 510:FOR X=0 TO 25:READ B:POKE CANDLE+X,B:NEXT X:REM READ IN THE DATA FOR CANDLE
200 POKE 53249,120:REM PUT CANDLE ON SCREEN
210 FLAME=PMBASE+1157:REM LOCATION OF FLAME IN P/M MEMORY
220 JAR=PMBASE+1606:POKE 206,INT(PMBASE+1536)/256:POKE 205,(PMBASE+1536)-INT((PMBASE+1536)/256)*256:REM JAR IN P/M
230 POKE JAR,255:FOR X=1 TO 50:POKE JAR+X,129:NEXT X:REM DRAW THE JAR
240 POKE 53258,3:POKE 53250,107:REM PUT THE JAR ON THE SCREEN
250 COLOR 1:FOR X=1 TO 50:REM PUT OXYGEN ON SCREEN
260 C=INT(RND(1)*160):REM COLUMN OF OXYGEN
270 R=INT(RND(1)*80):REM ROW OF OXYGEN
280 IF C>60 AND C<90 THEN IF R>43 THEN 270:REM DON'T PLACE IT IN THE JAR
290 IF C>40 AND C<110 THEN IF R>69 THEN 270:REM OR ON SAUCER
300 OS(X,1)=C:OS(X,2)=R:REM PLACE THE OXYGEN LOCATION IN THE ARRAY
310 PLOT C,R:NEXT X:REM DO IT 50 TIMES
320 FOR X=1 TO 10:REM OXYGEN IN JAR
330 C=INT(RND(1)*23)+63:R=INT(RND(1)*23)+46:REM AREA OF JAR
340 OJ(X,1)=C:OJ(X,2)=R:REM PLACE IN JAR ARRAY
350 PLOT C,R:NEXT X:OX=10:REM DO IT 10 TIMES
360 POKE 752,1:? "PRESS {inv}START{/inv} TO MOVE JAR":? :? "PRESS {inv}SELECT{/inv} TO LIGHT CANDLE";:REM INSTRUCTIONS
370 IF PEEK(53279)=7 THEN 400:REM NO KEY PRESSED - MOVE OXYGEN & FLAME IF LIT
380 POKE 77,0:IF PEEK(53279)=5 AND FL=0 AND JU=0 THEN 410:REM TURN OFF ATTRACT - LIGHT FLAME?
390 IF PEEK(53279)=6 THEN GOSUB 430:IF JU=0 THEN COLOR 1:FOR X=1 TO 10:PLOT OJ(X,1),OJ(X,2):NEXT X
400 IF FL=0 THEN GOSUB 540:GOTO 370:REM FLAME NOT LIT
410 FL=1:POKE 53248,120:GOSUB 520:REM ANIMATE FLAME ON SCREEN
420 GOTO 370
430 IF JU=0 THEN FOR Q=1 TO 51:M=USR(ADR(DOWN$)):NEXT Q:JU=1:RETURN :REM MOVE JAR DOWN
440 FOR Q=1 TO 51:M=USR(ADR(UP$)):NEXT Q:JU=0:OX=10:RETURN :REM MOVE JAR UP
500 REM DATA FOR CANDLE
510 DATA 8,8,12,28,28,30,62,62,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126
520 F=INT(RND(1)*3)+1:REM PICK ONE OF THREE FLAME POSITIONS
530 RESTORE 530+F:FOR X=0 TO 9:READ B:POKE FLAME+X,B:NEXT X:REM READ IN THE DATA FOR FLAME
531 DATA 16,8,12,28,62,62,28,24,8,4
532 DATA 8,4,6,12,60,60,28,48,16,8
533 DATA 32,16,24,56,30,30,12,12,4,2
539 REM DECREASE THE OXYGEN IF FLAME IS ON AND JAR IS DOWN. FLAME GOES OUT WHEN THERE IS NO OXYGEN
540 IF JU=1 AND FL=1 THEN COLOR 4:PLOT OJ(OX,1),OJ(OX,2):OX=OX-1:IF OX=0 THEN FL=0:POKE 53248,0:RETURN
550 IF OX=0 THEN 580:REM NO OXYGEN IN JAR
560 FOR X=1 TO OX STEP 2:R=INT(RND(1)*23)+63:C=INT(RND(1)*23)+46:COLOR 4:PLOT OJ(X,1),OJ(X,2):OJ(X,1)=R:OJ(X,2)=C
570 COLOR 1:PLOT R,C:NEXT X
580 FOR X=1 TO 50 STEP 5:COLOR 4:PLOT OS(X,1),OS(X,2):C=INT(RND(1)*160):REM GET A NEW COLUMN
590 R=INT(RND(1)*80):IF C>60 AND C<90 THEN IF R>43 THEN 590:REM IN THE JAR!
600 IF C>40 AND C<110 THEN IF R>69 THEN 590:REM ON THE SAUCER!!
610 OS(X,1)=C:OS(X,2)=R:COLOR 1:PLOT C,R:NEXT X:RETURN

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: CANDLE.BAS.

Credits