10 ! HP-85 to HP-9915 EPROM conversion 20 ! NEED TO USE CHECKSUM from PROG DEVELOPMENT ROM 30 ! Version 0.g 15/1/06 JAS 40 ! #### Outline Program Structure #### 50 ! Procedure - Read filename for EPROM file 60 ! If user wants to, create maximum size of 94 records. 70 ! Each record contains 1 integer and 1 string of 258 bytes. 80 ! Only first integer is used, contains last valid record number. 90 ! First string is the directory, remaining 93 are for program storage. 100 ! Initial version of program adds 1 Basic program to directory 110 ! and program storage 120 ! later versions may allow more programs to be added, plus Binary programs. 130 ! Procedure - Create empty directory string and store to EPROM file. 140 ! Procedure - Read Source Program name 150 ! (same as the Input filename ) 160 ! Procedure - Read in file & check length 170 ! Procedure - Read back directory from EPROM data file 180 ! Procedure - Update Directory String for new file 190 ! Procedure - Output Directory String and checksum 200 ! Procedure - Output Program Records and Checksum 210 ! Procedure - Close EPROM data file 220 ! ***** MAIN PROGRAM START ************ 230 ! Define variables 240 COM A$[258] ! contains directory 250 A$="" ! allocate now to use memory 260 ! P$ should be 24576 (24K) 270 ! reduced to 20K as memory 280 ! is limited. Need to remove comments to cope! 290 DIM P$[20480] ! contains HP-85 program minus MAI at start 300 DIM T$[258] ! contains current program record extracted from P$ 310 M=0 ! M - used for current size of EPROM data file in records 320 ! N - Used for previous number of entries in EPROM data file directory 330 DISP "HP-85 to HP-9915 EPROM Conversion" 340 DISP "---------------------------------" 350 DISP 360 DISP "Program uses an interim data" 370 DISP "file for the final EPROM" 380 DISP "contents." 390 ! Read name of EPROM data file into E$ 400 DISP "Enter filename for EPROM data" 410 DISP "file, (1 to 10 chars)" 420 INPUT E$ 430 IF LEN(E$)>10 THEN 400 440 DISP "Do you want to create a new file? (Y/N)" 450 INPUT Q$ 460 IF Q$="y" OR Q$="Y" THEN 610 ! Create new data file 470 IF Q$<>"n" AND Q$<>"N" THEN 440 ! Get a Y or N answer 480 ! Read back current record count and directory from EPROM data file 490 ASSIGN# 1 TO E$ 500 READ# 1,1 ; M,A$ 510 ASSIGN# 1 TO * 520 ! Display current EPROM file directory 530 DISP "Current EPROM data file contains";M;"records." 540 I=0 @ DISP "Current EPROM data file directory:" 550 IF A$[I*8+8,I*8+8]=CHR$(0) THEN N=I @ GOTO 750 ! Empty entry, 560 ! go and read in new program data 570 DISP A$[I*8+1,I*8+6];" "; 580 I=I+1 590 IF I=32 THEN DISP @ DISP "DIRECTORY FULL! (max 32)" @ STOP 600 GOTO 550 @ ! Go and look at next directory entry 610 ! Create new EPROM data file 620 ! File is formated as 94 records, each of 1 integer and 1 258 bytes string 630 ! Total space required = 94 * (8 + 3 + 258) = 25286 bytes 640 CREATE E$,94,269 @ ! Filename, number of records, record length 650 ! Create empty directory 660 FOR I=0 TO 31 ! 32 files in directory 670 A$[I*8+1,I*8+8]=" "&CHR$(0)&CHR$(0) 680 NEXT I 690 A$[257,258]=CHECKSUM$(A$[1,256]) ! Uses PROGRAM DEVELOPMENT ROM 700 ASSIGN# 1 TO E$ ! Open EPROM data file 710 PRINT# 1,1 ; 1,A$ ! Write 1 (file only 1 record long) plus emptry Directory 720 ASSIGN# 1 TO * ! Close again 730 N=0 ! 0 entries in new directory 740 DISP "Empty directory created in EPROM data file ";E$ 750 ! Read Program name into D$ 760 DISP 770 DISP "Enter filename for data file" 780 DISP "made from HP-85 program, which" 790 DISP "will be used as name for" 800 DISP "destination HP-9915 program" 810 DISP "filename (1 to 6 chars)" 820 INPUT D$ 830 IF LEN(D$)>6 THEN 770 840 ASSIGN# 2 TO D$ ! Open program data file 850 ! Read HP-85 Basic program into P$ 860 READ# 2 ; P$ 870 ASSIGN# 2 TO * ! Close program data file 880 DISP "Read in file of ";LEN(P$);" bytes." 890 L=(LEN(P$)+3)/256 ! Calculate number of records 900 IF FP(L)=0 THEN 920 ! Program file always exact multiple of 256 910 DISP "Error - program file length + 3 must be multiple of 256!" @ STOP 920 DISP "Program file is ";L;" records long." 930 ! Read back current record count and directory from EPROM data file 940 ASSIGN# 1 TO E$ ! Open EPROM data file 950 READ# 1,1 ; M,A$ 960 ! Check there is room for new file 970 DISP "Current EPROM file is ";M;" records long (max=94)." 980 IF M+L>94 THEN DISP "New program is too large to fit in EPROM !!" @ STOP 990 ! There are currently N items in the directory 1000 DISP @ DISP 1010 ! Update directory with new program file name and length 1020 DISP "Updating directory with entry #";N+1 1030 A$[N*8+1,N*8+LEN(D$)]=D$ 1040 A$[N*8+7,N*8+7]=CHR$(L) ! Need to use [7,7] rather than [7] 1050 ! else string truncated 1060 A$[N*8+8,N*8+8]=CHR$(32) ! type = Basic program 1070 A$[257,258]=CHECKSUM$(A$[1,256]) 1080 M=M+L ! EPROM data file will be L records longer 1090 PRINT# 1,1 ; M,A$ ! Write num of records and new directory to 1st record 1100 ASSIGN# 1 TO * 1110 N=N+1 ! Directory is 1 entry longer 1120 ! Output program records and checksum, from P$ via T$ 1130 DISP "Adding file ";D$;" to EPROM data file ";E$ 1140 ASSIGN# 1 TO E$ ! Open EPROM data file 1150 FOR I=1 TO L 1160 IF I>1 THEN 1200 ! 1st record is a special case 1170 T$[1,3]="MAI" ! 1st 3 bytes of program always MAI 1180 T$[4,256]=P$[1,253] 1190 GOTO 1210 1200 T$[1,256]=P$[(I-1)*256-2,I*256-3] 1210 T$[257,258]=CHECKSUM$(T$[1,256]) 1220 PRINT# 1,M-L+I ; 1,T$ ! Output record to file 1230 NEXT I 1240 ASSIGN# 1 TO * ! Close EPROM data file 1250 DISP "EPROM Data file updated " 1260 DISP "File now contains ";M;" program records" 1270 DISP "and contains ";N;" directory entries." 1280 DISP "END OF RUN" 1290 END