Weekly Calendar Planner (New Owners Column, Lesson 11)

Type
Utility
Category
Beginner's BASIC lesson program (ATASCII, PEEK and POKE) / appointment planner
Author
David Plotkin
Published in
Antic, February 1987 (Vol. 5, No. 10), New Owners Column, Lesson 11: ATASCII, PEEK and POKE
Year
1987
Language
Atari BASIC
Requirements
Any Atari 8-bit, Atari BASIC; disk drive to save months; any printer (optional)
Blue text screen ruled with horizontal dark lines like a notepad, listing SUN FEB 1 with DENTIST, MON FEB 2 with BOOK, then TUE FEB 3 to SAT FEB 7, and START=NEXT SELECT=PRINT OPTION=MENU at the bottom

About the program

Lesson 11 of David Plotkin's New Owners Column (Antic, February 1987) rounds off what he called "the nitty-gritty components of BASIC programming". It covers CHR$ and ASC, the ATASCII codes behind every character, and PEEK and POKE for reading and changing memory directly, with a warning that a wrong POKE can lock up the machine. So SAVE before you RUN. The next month's column was to start on "the fun stuff": colour, sound, graphics and animation.

The program is a Weekly Calendar Planner. Pick any month of any year and it shows one week at a time, with three lines for each day, where you can type appointments and things to do. Months can be saved to disk and loaded again, and any week can be printed. Two weeks fit on a sheet. Plotkin avoided printer graphics, so it works even with letter-quality printers.

Typing it in

Most of it is plain BASIC. {inv}…{/inv} marks inverse letters in the menus (type them with the Atari key), and {RIGHT}{LEFT} (ESC then CTRL-arrow) is printed to make the cursor appear or disappear. Two strings hold machine code. Line 830's "hhh{inv}*{/inv}LV{inv}d{/inv}" is the familiar three PLAs, TAX, and a jump into the operating system's CIO routine. The 25-byte memory-move routine in lines 1050–1060 is in DATA, so it's easy to type. Line 30000's BREAK-key disable is REMmed out, so BREAK still works.

How to use it

Press N for a new month and type the month and year, for example 2,1987. Type your notes in the space beside each date. The program won't let you write over the date labels, and it ignores CLEAR, insert line and delete line. START moves to the next week and wraps round after the fifth. SELECT prints the week, and OPTION returns to the menu. Back at the menu, S saves the month as a file named after it (D:FEB1987), O loads a saved month (with an optional directory), C clears the notes and E deletes a month from disk.

How it works

  • Day of the week. Lines 2010–2030 work out the weekday of the 1st with a Zeller-style formula. January and February count as months 13 and 14 of the year before. Line 5305 adds 29 February with the full Gregorian rule (every fourth year, but not centuries unless divisible by 400).
  • Notepad lines from players and missiles. Lines 3200–3250 set all four players and the missiles to quadruple width, spread them across the screen and give them single scan-line stripes every eight lines. The result is ruled paper behind the text, drawn in black.
  • A protective editor. Lines 600–680 read each key with GET and check the cursor position (locations 84 and 85) before printing it. Keys that would damage the layout are swapped for a harmless cursor move.
  • Fast storage. Each week is 880 bytes of screen memory, and a month's five weeks fit in the 4,500-byte SCR$. A small machine-language routine (in JJ$) copies 220 bytes at a time between the screen and the string. Saving and loading set up IOCB #1 directly, with the command at 850, the buffer address at 852/853 and the length at 856/857, then call CIO once to move all 4,400 bytes.
  • PEEKing the screen to print it. Screen memory holds internal character codes, not ATASCII. So line 3100 builds a 256-character lookup string, HOLD$, that converts one to the other, and line 3010 PEEKs each screen byte and looks it up before sending the line to the printer. That's the lesson's point in action.
  • Line 8, POKE 106,PEEK(740), puts RAMTOP back to the real top of memory, so running the program again doesn't keep lowering it.

Variations to try

Each "week" is seven days counted from the 1st (days 1–7, 8–14 and so on), so five screens always cover the month. You could add the year to the date labels, or change the program so that each week starts on a Sunday, like a printed diary.

Listing

2 REM THE NEW OWNERS COLUMN
4 REM BY DAVID PLOTKIN
6 REM (c) 1987, ANTIC PUBLISHING INC.
8 POKE 106,PEEK(740):GRAPHICS 0
10 DIM DAY$(21),M$(40),DY$(24),A$(1),FILE$(15),LINE(25),PP$(40),HOLD$(257),FN$(14),SCR$(4500),JJ$(25),LL$(40)
12 PRINT CHR$(125);"INITIALIZING..."
15 SCREEN=PEEK(88)+256*PEEK(89)+40:FOR J=1 TO 23:LINE(J)=SCREEN:SCREEN=SCREEN+40:NEXT J:GOSUB 3100
20 GOSUB 1000
99 REM MAIN MENU SCREEN
100 TRAP 100:GRAPHICS 0:POKE 559,62:POKE 53277,3:SETCOLOR 2,0,0:GOSUB 30000:POKE 82,0:INC=0
110 PRINT :PRINT :PRINT "**{inv}MAIN MENU{/inv}**":PRINT :PP$=CHR$(18):PP$(40)=PP$:PP$(2)=PP$:PRINT PP$
120 PRINT " SELECT YOUR CHOICE (PRESS A LETTER)":PRINT PP$
130 PRINT :PRINT "     {inv}N{/inv}EW MONTH EDIT":PRINT "     {inv}O{/inv}LD MONTH EDIT":PRINT "     {inv}S{/inv}AVE DATA":PRINT "     {inv}C{/inv}LEAR DATA"
140 PRINT "     {inv}E{/inv}RASE MONTH (DISK)":POKE 764,255:CLOSE #1:OPEN #1,4,0,"K:":GET #1,J:A$=CHR$(J)
150 IF A$="N" THEN 2000:REM GET NEW SCREEN
160 IF A$="O" THEN 2200:REM EDIT OLD SCREEN
170 IF A$="S" THEN 2400:REM SAVE CURRENT DATA
180 IF A$="C" THEN SCR$(1)=CHR$(0):SCR$(4500)=CHR$(0):SCR$(2)=SCR$:REM CLEAR THE DATA STRING
190 IF A$="E" THEN 2800:REM DELETE A FILE FROM DISK
195 PRINT CHR$(125):GOTO 110
599 REM SCREEN EDITOR ROUTINE
600 TRAP 100:CLOSE #1:OPEN #1,4,0,"K:":POKE 82,0:POKE 752,0:POSITION 11,1:PRINT "{RIGHT}{LEFT}";:POKE 764,255
610 IF PEEK(764)=255 THEN GOTO 670:REM NO KEY PRESSED
615 GET #1,K
620 IF K=125 OR K=156 OR K=157 THEN POKE 764,255:GOTO 670
630 YY=PEEK(84):XX=PEEK(85)
635 IF XX=39 THEN K=31
640 IF (XX<11 AND (YY-1)/3=INT((YY-1)/3)) AND (K<28 OR K>31) THEN K=31
645 IF (YY=1 AND K=28) OR (YY=22 AND (K=29 OR K=155)) THEN K=31
650 PRINT CHR$(K);:GOTO 610
670 BUTTON=PEEK(53279):IF BUTTON<>3 AND BUTTON<>6 AND BUTTON<>5 THEN 610
680 RETURN
699 REM WRITE DATA TO DISK
700 CLOSE #1:OPEN #1,8,0,FILE$:PUT #1,M:PUT #1,INT(Y/256):PUT #1,Y-(INT(Y/256))*256
710 HI=17:LO=48:REM 4400 BYTES
720 POKE 850,11:POKE 856,LO:POKE 857,HI:GOTO 820
799 REM READ DATA FROM DISK
800 CLOSE #1:OPEN #1,4,0,FILE$:GET #1,M:GET #1,Y1:GET #1,Y2:Y=Y1*256+Y2
810 POKE 850,7:POKE 856,255:POKE 857,255
820 NHI=INT(ADR(SCR$)/256):NLO=ADR(SCR$)-NHI*256
830 POKE 852,NLO:POKE 853,NHI:DQ=USR(ADR("hhh{inv}*{/inv}LV{inv}d{/inv}"),16):CLOSE #1
840 RETURN
899 REM DISK DIRECTORY
900 CLOSE #1:OPEN #1,4,0,"K:":PRINT CHR$(125);"DRIVE #";:GET #1,X:FN$="D1:*.*":FN$(2,2)=CHR$(X)
905 CLOSE #1:PRINT CHR$(X):OPEN #1,6,0,FN$
910 FOR X=1 TO 64:INPUT #1,FN$:FN$=FN$(3):IF FN$(3,12)="FREE SECTO" THEN 950
920 IF X/2=INT(X/2) THEN POSITION 15,(X+1)/2:? FN$:GOTO 940
930 POSITION 2,(X+2)/2:? FN$
940 NEXT X
950 RETURN
999 REM INITIALIZING STRINGS
1000 DAY$="SATSUNMONTUEWEDTHUFRI"
1010 M$="JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
1020 DY$="312831303130313130313031"
1030 SCR$(1)=CHR$(0):SCR$(4500)=CHR$(0):SCR$(2)=SCR$
1040 RESTORE 1050:FOR LOOP=1 TO 25:READ DT:JJ$(LOOP)=CHR$(DT):NEXT LOOP
1050 DATA 104,104,133,204,104,133,203,104,133,207,104,133,206,160,0,177
1060 DATA 206,145,203,200,192,220,208,247,96
1070 LL$="----------------------------------------"
1080 RETURN
1999 REM GET MONTH
2000 ? "INPUT DATE: MONTH,YEAR (XX,XXXX)":INPUT M,Y:D=1:IF M>12 OR M<1 THEN 2000
2010 IF M<3 THEN M=M+12:Y=Y-1
2020 N=2*M+INT(0.6*(M+1))+Y+INT(Y/4)-INT(Y/100)+INT(Y/400)+3
2030 N=INT((N/7-INT(N/7))*7+0.05):Q=N
2040 GOTO 5000
2199 REM EDIT OLD MONTH
2200 ? "DISK DIRECTORY? (Y OR N)":POKE 764,255:CLOSE #1:OPEN #1,4,0,"K:":GET #1,J:A$=CHR$(J)
2210 IF A$="Y" OR A$="y" THEN GOSUB 900
2230 ? "WHAT FILE TO EDIT":GOSUB 4000:REM GET FILENAME
2240 IF FN$="" THEN 100
2250 GOSUB 800:REM READ DATA FROM DISK
2260 GOTO 2010
2399 REM SAVE CURRENT DATA
2400 FILE$="D:":FILE$(3)=M$(M*3-2,M*3):FILE$(6)=STR$(Y)
2410 GOSUB 700
2420 GOTO 100
2799 REM DELETE A FILE
2800 ? "DISK DIRECTORY? (Y OR N)":POKE 764,255:CLOSE #1:OPEN #1,4,0,"K:":GET #1,J:A$=CHR$(J)
2805 IF A$="Y" OR A$="y" THEN GOSUB 900
2810 ? "WHAT FILE TO DELETE?":? :CLOSE #1:? "ENTER FILENAME OR PRESS":? "RETURN TO ABORT";:GOSUB 4000
2820 IF FN$="" THEN 195
2830 XIO 33,#3,0,0,FILE$:GOTO 195
2999 REM PRINT CURRENT SCREEN
3000 TRAP 600:POKE 752,1:PRINT "{RIGHT}{LEFT}":CLOSE #1:OPEN #1,4,0,"P:":FOR J=1 TO 22
3010 FOR I=1 TO 40:PP$(I)=HOLD$(PEEK(LINE(J)+I-1)+1):NEXT I:? #1;PP$
3015 IF J/3=INT(J/3) THEN ? #1;LL$
3020 NEXT J:FOR Q=1 TO 5:? #1:NEXT Q:CLOSE #1:GOTO 600
3099 REM ARRAY TO CHANGE INTERNAL CHARACTERS TO ATASCII CHARACTERS
3100 FOR II=0 TO 255:IC=II:IV=0:IF IC>127 THEN IV=1:IC=IC-128
3110 IF IC<64 THEN AC=IC+32+128*IV:GOTO 3140
3120 IF IC<96 THEN AC=IC-64+128*IV:GOTO 3140
3130 AC=IC+128*IV
3140 HOLD$(II+1)=CHR$(AC):NEXT II
3199 REM INITIALIZE PLAYER/MISSILE GRAPHICS
3200 PMBASE=PEEK(106)-16:POKE 54279,PMBASE:PMBASE=PMBASE*256
3210 FOR W=53256 TO 53259:POKE W,3:NEXT W:POKE 53260,255
3220 POKE 88,0:POKE 89,PEEK(106)-16:? CHR$(125):GRAPHICS 0:SCREEN=PEEK(88)+256*PEEK(89)+40
3230 FOR W=PMBASE+807 TO PMBASE+987 STEP 8:FOR J=0 TO 1024 STEP 256:POKE W+J,255:NEXT J:NEXT W
3240 FOR W=704 TO 707:POKE W,0:NEXT W:POKE 559,62:POKE 53277,3:POKE 623,1
3250 RESTORE 3260:FOR I=53248 TO 53255:READ J:POKE I,J:NEXT I:RETURN
3260 DATA 48,80,112,144,176,184,192,200
3999 REM HANDLE FILENAMES
4000 INPUT FN$:IF FN$="" THEN RETURN
4010 FOR J=1 TO LEN(FN$):IF FN$(J,J)=":" THEN POP :FILE$=FN$:RETURN
4020 NEXT J:FILE$="D:":FILE$(3)=FN$:RETURN
4999 REM PUT WEEKS ON SCREEN, GET AND SAVE STRINGS OF DATA.
5000 POKE 752,1:? CHR$(125):SETCOLOR 2,7,4
5015 IF M>12 THEN M=M-12:Y=Y+1
5300 DY=VAL(DY$(M*2-1,M*2))
5305 IF M=2 THEN IF (Y/4=INT(Y/4) AND Y/100<>INT(Y/100)) OR Y/400=INT(Y/400) THEN DY=DY+1
5310 GOSUB 7000:REM RECOVER STRING SCREEN
5315 FOR LOOP=1 TO 7:POSITION 0,LOOP*3-2
5316 IF LOOP+INC*7>DY THEN POSITION 0,LOOP*3-2:? "{inv}NOTES>>>{/inv}";:POP :GOTO 5340
5320 ? DAY$(Q*3+1,Q*3+3);" ";M$(M*3-2,M*3);" ";LOOP+INC*7;
5325 Q=Q+1
5327 IF Q=7 THEN Q=0
5330 NEXT LOOP
5340 POSITION 0,23:? "  {inv}START=NEXT{/inv}  {inv}SELECT=PRINT{/inv}  {inv}OPTION=MENU{/inv}";
5350 GOSUB 600:REM SCREEN EDITOR ROUTINE
5370 IF BUTTON=6 THEN GOSUB 6000:INC=INC+1:IF INC=5 THEN INC=0:Q=N:REM PUT SCREEN IN STRING
5380 IF BUTTON=6 THEN 5000
5410 IF BUTTON=3 THEN GOSUB 6000:GOTO 100:REM SAVE STRING, GOTO MENU
5420 GOSUB 3000:GOTO 5350:REM BUTTON IS 5, PRINT SCREEN
5999 REM PUT SCREEN DATA INTO STRING
6000 POKE 752,1:? "{RIGHT}{LEFT}":FOR LOOP=0 TO 3:INDEX1=880*INC+LOOP*220+1:INDEX2=SCREEN+LOOP*220
6010 DQ=USR(ADR(JJ$),ADR(SCR$(INDEX1)),INDEX2)
6020 NEXT LOOP
6030 POKE 752,0:RETURN
6999 REM PUT STRING DATA ONTO SCREEN
7000 FOR LOOP=0 TO 3:INDEX1=880*INC+LOOP*220+1:INDEX2=SCREEN+LOOP*220
7010 DQ=USR(ADR(JJ$),INDEX2,ADR(SCR$(INDEX1)))
7020 NEXT LOOP
7030 RETURN
29999 REM DISABLE BREAK KEY
30000 REM POKE 16,112:POKE 53774,112
30010 RETURN

Download

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

Credits