Path: ns-mx!uunet!usc!apple!mattd
From: mattd@Apple.COM (Matt Deatherage)
Newsgroups: comp.binaries.apple2
Subject: ProDOS 8 v1.9 slot-based clock driver patcher
Summary: Adds other years to P8 v1.9
Keywords: P8 ProDOS 1.9 clock patch slot-based
Message-ID: <61317@apple.Apple.COM>
Date: 1 Jan 92 07:08:53 GMT
Organization: Apple Computer Inc., Cupertino, CA
Lines: 310

================================================================

The attached Applesoft BASIC program is a preliminary version of a program
that will appear soon in a ProDOS 8 Technical Note.  This program patches
ProDOS 8 versions 1.9 and 2.0 so that the slot clock driver contains a six
year table beginning with the current year, for any six year period beginning
as early as 1940 or ending as late as 2039.  If you're not using version 1.9,
upgrade now.  Version 2.0 will be released later in 1992.

This is necessary because the slot-based clock driver in ProDOS 8 version 1.9
contains a year table that ends with 1991 (having last been changed for ProDOS
8 1.2 in 1986).  It is only necessary for people using slot-based clocks or
their equivalents on Apple II+, IIe or IIc computers.  Apple IIgs computers
never use this clock driver.

This is a preliminary release.  It has not been completely tested; use it at
your own risk but we think it works.  The instructions and human interface
aren't finalized.  If run on an Apple II without lower-case capabilities, the
screen will look strange.  Typing names of off-line disks when prompted will
cause the program to break.  There is no indication in the ProDOS 8 splash
screen that the file has been patched.  The program only patches files named
"PRODOS" at the root level of specified disks.  There may be other problems as
well; we hope to address most of them in the future ProDOS 8 Technical Note.

In the meantime, this program will succefully patch ProDOS 8 version 1.9 to
return years other than 1986 through 1991.  But always keep a backup of
unmodified ProDOS 8 v1.9 just in case something goes wrong.

The location of the clock driver in the ProDOS 8 v2.0 file as documented in
this program is not guaranteed and is still subject to change.

Developer Technical Support
Apple Computer, Inc.

-------------------------------------------------------------------------

1 REM ProDOS 8 ThunderClock Driver Patch Utility
2 REM Written by Greg Branche
3 REM Copyright (c) 1991, Apple Computer, Inc.
4 REM All Rights Reserved
5 :
10 REM This program allows a user to modify the
11 REM table of year values stored within the
12 REM ThunderClock driver, thereby allowing
13 REM the driver to calculate the correct
14 REM value based on month, day, and day-
15 REM of-week.  The table consists of seven
16 REM entrys, with each entry corresponding
17 REM to the year in which January 1st falls
18 REM on the day-of-the-week for that table
19 REM entry.
20 :
21 REM Instructions and background information
22 REM are contained within the program.  They
23 REM are displayed to the user at the beginning
24 REM of the program.
25 :
100 PRINT CHR$ (21): HOME : REM turn off 80-col card
110 REM cu() = cumulative # of days in year
120 DIM CU(12)
130 REM fill array with # of days in year
140 CU(1) = 0: REM January
150 FOR I = 2 TO 12
160 READ X
170 CU(I) = CU(I - 1) + X
180 NEXT I
190 :
200 REM DN$() = Names for days of week
210 DIM DN$(7)
220 REM fill array with names of days of week
230 FOR I = 1 TO 7
240 READ DN$(I)
250 NEXT I
260 :
270 REM yt() is the year table values
280 DIM YT(7)
290 :
300 REM Save original prefix
310 PRINT CHR$ (4)"Prefix"
320 INPUT PFX$
330 :
340 DEF FN MOD7(X) = INT (((X / 7) - INT (X / 7)) * 7 + .5)
350 :
360 REM Display some instructions
370 HOME 
380 READ A$
390 IF A$ = "" THEN GOSUB 900: GOTO 1000
400 PRINT A$
410 IF PEEK (37) > 21 THEN GOSUB 900: HOME 
420 GOTO 380
430 :
799 REM Finds position of / within date string
800 X = 0: REM On exit, contains position of /, or 0 if none found
810 FOR I = 1 TO 3
820 IF MID$ (DAY$,I,1) = "/" THEN X = I:I = 3
830 NEXT I
840 RETURN 
850 :
899 REM Pause between screenfuls of information
900 VTAB 24: HTAB 4: PRINT "<RET> to continue, <ESC> to exit";: GET 
      A$
910 IF A$ = CHR$ (27) THEN POP : GOTO 5000
920 IF A$ < > CHR$ (13) THEN PRINT CHR$ (7): GOTO 900
930 RETURN 
940 :
999 REM get the user's input and convert
1000 HOME 
1010 PRINT "Please enter today's date (mm/dd/yy)"
1020 INPUT "-> ";DAY$
1030 GOSUB 800: REM find slash separator
1040 IF X < > 0 THEN 1080
1050 PRINT "Invalid date entered.  Please try again."; CHR$ (7)
1060 GOTO 1010
1070 REM Convert month value to numeric variable
1080 MO = VAL ( MID$ (DAY$,1,X - 1))
1090 DAY$ = MID$ (DAY$,X + 1)
1100 IF MO < 1 OR MO > 12 THEN 1050: REM Range check the month value
1110 GOSUB 800: REM Parse out the current day
1120 IF X = 0 THEN 1050
1130 REM Convert day string into numeric value
1140 DA = VAL ( MID$ (DAY$,1,X - 1))
1150 DAY$ = MID$ (DAY$,X + 1)
1160 IF DA < 1 OR DA > 31 THEN 1050: REM Range check the day value
1170 REM Convert year string into numeric value
1180 YR = VAL (DAY$)
1190 IF YR < 0 OR YR > 99 THEN 1050: REM Only allow 0-99
1200 IF YR > 39 THEN YR = YR + 1900: REM 40-99 must be 1940-1999
1210 IF YR < 40 THEN YR = YR + 2000: REM 0-39 must be 2000-2039
1220 :
1230 PRINT "Please enter the day of the week"
1240 INPUT "(e.g. Wed) -> ";DOW$
1250 IF LEN (DOW$) > = 3 THEN 1270: REM Must be at least 3 characters
1260 PRINT "Invalid day of week.  Please try again."; CHR$ (7): GOTO 
      1230
1270 IF LEN (DOW$) > 3 THEN DOW$ = LEFT$ (DOW$,3)
1280 REM Shift any lower case letters to upper case
1290 B$ = ""
1300 FOR I = 1 TO 3
1310 A$ = MID$ (DOW$,I,1)
1320 IF ASC (A$) > = ASC ("a") AND ASC (A$) < = ASC ("z") THEN A$ = 
      CHR$ ( ASC (A$) - ( ASC ("a") - ASC ("A")))
1330 B$ = B$ + A$
1340 NEXT I
1350 DOW$ = B$
1360 REM Now convert day-of-week string to numeric value
1370 DOW = 0
1380 FOR I = 1 TO 7
1390 IF DOW$ = DN$(I) THEN DOW = I:I = 7
1400 NEXT I
1410 IF DOW = 0 THEN 1260
1420 :
1430 REM Calculate the number of days so far this year
1440 DYS = DA + CU(MO)
1450 REM Must account for extra day in leap year
1460 IF (YR / 4) = INT (YR / 4) AND MO > 2 THEN DYS = DYS + 1
1470 :
1480 REM Now calculate the index to use to fill in the table
1490 IDX = DOW - FN MOD7(DYS) + 1
1500 IDX = ABS (IDX - 10)
1510 IF IDX > 7 THEN IDX = IDX - 7
1520 :
1530 REM Now we can fill in the year table
1540 FOR I = 1 TO 7
1550 X = YR - 1900
1560 IF X > 100 THEN X = X - 100
1570 YT(IDX) = X: REM store the year into table
1580 IDX = IDX - 1
1590 IF IDX < 1 THEN IDX = 7
1600 IF (YR / 4) < > INT (YR / 4) THEN 1660: REM not a leap year
1610 I = I + 1: REM update index
1620 IF I > 7 THEN 1670: REM if entire array done, exit
1630 YT(IDX) = X: REM duplicate entry for leap year
1640 IDX = IDX - 1
1650 IF IDX < 1 THEN IDX = 7
1660 YR = YR + 1
1670 NEXT I
1680 :
1690 FOR I = 1 TO 7: REM Poke table into memory
1700 POKE 767 + I,YT(I)
1710 NEXT I
2000 REM Now that the table is set up,
2010 REM we can modify the file(s)
2020 VTAB 6: HTAB 1
2030 PRINT "You may now insert the disk containing": PRINT "the ProDOS 
      file to be modified, then": PRINT "enter the location of the disk. 
       You"
2040 PRINT "can enter the location either as the": PRINT "volume name 
      of the disk, or by its": PRINT "slot and drive location (ESC to 
      exit):"
2045 PRINT "-> ";
2050 VTAB 12: HTAB 4: CALL - 958
2060 GET A$
2070 IF A$ = "/" THEN 2100: REM input volume name
2080 IF A$ = "S" OR A$ = "s" THEN 2200: REM slot/drive input
2085 IF ASC (A$) = 27 THEN 5000: REM ESC pressed, exit
2090 PRINT CHR$ (7);: GOTO 2060: REM None of the above, try again
2098 :
2099 REM Read volume name from user
2100 PRINT A$;: INPUT "";PTH$
2110 PTH$ = "/" + PTH$: REM build full pathname
2120 FOR I = 2 TO LEN (PTH$)
2130 IF MID$ (PTH$,I,1) < > "/" THEN 2160: REM Ensure only volume name 
      is included
2140 PRINT "Please supply only the volume name."; CHR$ (7)
2150 VTAB 12: HTAB 4: CALL - 868: GOTO 2060
2160 NEXT I
2170 VTAB 13: HTAB 1: CALL - 958
2180 PRINT CHR$ (4)"Prefix "PTH$: REM Set ProDOS prefix
2190 GOTO 2300: REM then go modify the ProDOS file
2198 :
2199 REM Read volume name from disk in specified drive
2200 PRINT "S";
2210 GET A$
2220 SL = VAL (A$)
2230 IF SL < 1 OR SL > 7 THEN PRINT : PRINT "Slot number 1-7 only."; 
      CHR$ (7);: VTAB 12: HTAB 5: GOTO 2210
2240 PRINT SL;",D";: CALL - 958
2250 GET A$
2260 DR = VAL (A$)
2270 IF DR < > 1 AND DR < > 2 THEN PRINT : PRINT "Driver number 1 or 
      2 only."; CHR$ (7): VTAB 12: HTAB 8: GOTO 2250
2280 PRINT DR: CALL - 958
2290 PRINT CHR$ (4)"Prefix,S"SL",D"DR"
2300 REM Prefix is now set to the proper volume
2320 PRINT CHR$ (4)"Bload ProDOS,tsys,a$310,l$3,b$1b": REM Read P8 2.0 
      version
2330 A$ = ""
2340 FOR I = 1 TO 3
2342 X = PEEK (783 + I)
2344 IF X > 127 THEN X = X - 128
2350 A$ = A$ + CHR$ (X)
2360 NEXT I
2370 IF VAL (A$) < > 2 THEN 2400: REM it's not version 2.0
2380 ADRS = 3958: REM location of table within image
2390 GOTO 2600: REM go write the new table
2400 PRINT CHR$ (4)"Bload ProDOS,tsys,a$310,l$3,b$651"
2410 A$ = ""
2420 FOR I = 1 TO 3
2422 X = PEEK (783 + I)
2424 IF X > 127 THEN X = X - 128
2430 A$ = A$ + CHR$ (X)
2440 NEXT I
2450 IF VAL (A$) = 1.9 THEN 2500: REM it's version 1.9
2460 PRINT "Only ProDOS versions 1.9 and 2.0 may": PRINT "be patched 
      by this program."
2470 INPUT "Would you like to try again? ";A$
2480 IF LEFT$ (A$,1) = "Y" OR LEFT$ (A$,1) = "y" THEN 2050
2490 GOTO 5000
2500 ADRS = 12918: REM location of table within 1.9
2598 :
2599 REM Write the new table out to the file
2600 PRINT CHR$ (4),"BSave ProDOS,tsys,a$300,l7,b"ADRS
2610 GOTO 2050
5000 PRINT CHR$ (4)"Prefix"PFX$
5010 HOME 
5020 PRINT "Quit to (B)ASIC or (P)roDOS program"
5030 INPUT "launcher? ";A$
5040 IF LEFT$ (A$,1) = "P" OR LEFT$ (A$,1) = "p" THEN PRINT CHR$ (4)"Bye"
5050 IF LEFT$ (A$,1) = "B" OR LEFT$ (A$,1) = "b" THEN HOME : END 
5060 PRINT CHR$ (7);: GOTO 5020
59999 :
60000 REM # of days in each month
60010 DATA 31,28,31,30,31,30,31,31,30,31,30
60020 REM Names of days of week
60030 DATA SUN,MON,TUE,WED,THU,FRI,SAT
60040 REM Informational text and instructions
60050 DATA "This utility allows you to patch an"
60060 DATA "internal table used by the ProDOS"
60070 DATA "ThunderClock driver.  This table is"
60080 DATA "used to calculate the current year"
60090 DATA "for date-stamping files on ProDOS"
60100 DATA "disks, since the ThunderClock does"
60110 DATA "not return this information to ProDOS."
60120 DATA "The table only holds seven values, one"
60130 DATA "for each day of the week.  There must"
60140 DATA "be at least one year duplicated within"
60150 DATA "the table to account for the inter-"
60160 DATA "vening leap year.  Therefore, the"
60170 DATA "table must be updated at least every"
60180 DATA "six years to keep it current.  This"
60190 DATA "utility will ask you to enter the"
60200 DATA "current date and day of the week.  It"
60210 DATA "will use this information to calculate"
60220 DATA "the entries to place into the table."
60230 DATA "Next, it will ask you to insert a disk"
60240 DATA "containing the ProDOS file to be"
60250 DATA "modified, and ask you to specify the"
60260 DATA "location of the disk.  The ProDOS"
60270 DATA "file must be either version 1.9 or"
60280 DATA "version 2.0.  The location may be"
60290 DATA "specified as either the volume name"
60300 DATA "of the disk, or as its slot and drive"
60310 DATA "location.  The utility will then"
60320 DATA "proceed to write out the new table"
60330 DATA "entries to the file.  When the file"
60340 DATA "has been updated, the utility will"
60350 DATA "again ask you to insert a disk and"
60360 DATA "specify its location.  This can be"
60370 DATA "continued for every disk that you"
60380 DATA "wish to update.  When you have com-"
60390 DATA "pleted all of your disks, press the"
60400 DATA "ESC key to exit the utility."
60410 DATA ""
-- 
============================================================================
Matt Deatherage, Developer Technical  | The opinions expressed herein are
Support, Apple Computer, Inc.         | not those of Apple Computer, and
Personal mail only, please.  Thanks.  | shame on you for thinking otherwise.
^^^^^^^^ Technical questions are not personal. Please post them instead.
============================================================================

