On Error Gotoo Close

erase everything from line 8 on down, and inform user that program is opening the requested file.

210 V = 8:A$ = CHR$(31) :GOSUB 20: A$ = "Opening " + NM$:GOSUB 20

open requested file as random access and field maximum length

220 OPEN"R",2,NM$ 225 FIELD 2,255 AS Fl$

make sure that the R$ array will always begin at subscript 1

check for end of file 240 IF EOF(1) THEN 360

check for: (colon) - If found, close file and go back and check if new file is requested by script

check for; (semi-colon) - if so, we have a patch description - display it - then go back and check for next line of the patch script

255 IF LEFT$(R$(CT),1) =CHR$(59) THEN V=V+2: A$ = MID$(R$(CT)s2):GOSUB 21:CT = CT + 1:GOTO 250

retrieve record number and convert it to the way Basic wants to see it (+1)

retrieve starting position of the patch within the record and convert it to the way Basic wants to see it (+1)

260 INPUT#1 ,R$(CT):P = VAL("&H" + R$(CT)) +1: CT = CT +1

retrive the 'D' line. That is, the new code to be patched to the file. Then store the bytes in the DP(X) array. We can accomodate up to 80 bytes.

270 INPUT#1 ,R$(CT):DP = LEN(R$(CT)):BY = 1: FOR X = 1 TO DP STEP 3:

DP (BY) = VAL("&H" + MI D$ (R$ (CT) ,X,2)): BY = BY +1: NEXT:CT = CT + 1

retrieve the F line. That is, the bytes that currently exists in the fiie to be patched. Then store the bytes in the FP(X) array. We can accomodate up to 80 bytes.

280 INPUT#1,R$(CT):FP = LEN(R$(CT)):BY = 1: FOR X = 1 TO FP STEP 3:

FP(BY) = VAL("&H" + MID$(R$(CT),X,2)):BY = BY +1: NEXT:CT = CT + 1

display error and abort current patch if the 'D' and 'F lines do not contain the same number of bytes.

A$ = "Error in " + NM$ +" script":GOSUB 21 :GOTO 350

no error, inform user that record will be retrieved

A$ = "Positioning to record" + STR$(R-1):GOSUB 21

retrieve the requested record and let the subroutine in line 80 find the the beginning of the FIELD buffer

290 GET 2,R

300 GOSUB 80:BY=BY-1

check if the bytes supplied in the 'F line match the bytes found in the buffer. If not, FL will be set to 1. An error message will be displayed and the current patch will abort. If FL=0, then the bytes matched and we prompt the user if this patch should be installed and we then get the user response

IF FL THEN A$ = "(F)ind bytes not found":GOSUB 21: GOTO 350 ELSE A$ = STR$(BY) +" patch-bytes found": GOSUB 21 :V=V+2:A$ = "Do you wish to install this patch (Y/N) ":GOSUB 21 :H = H + LEN(A$) 325 ML = 1 :GOSUB 30

check if < ESC > was pressed. If so, close all files and go back and prompt for new patch script. If the user answers T, we jump to line 330 where the patch will be processed. If the answer is TV', we will the attempt to process the next patch request.

327 IF FL THEN CLOSE: GOTO 100 ELSE IF l$ = "Y" OR l$ = "y" THEN 330 ELSE IF l$ = "N" OR l$ = "n" THEN V = 8: A$ = CHR$(31):GOSUB 20:GOTO 230 ELSE 325

write the new patch bytes to their appropriate positions in the FIELD buffer, and then write the record to disk.

330 FOR X = 1 TO BY:POKE F! + P-1 +X-1 ,DP(X):NEXT 340 PUT 2,R

inform user that patch was successful. Then attempt to process the next patch request.

345 V=V +1 :A$ = "Patch installed":GOSUB 21 350 GOSUB 90:V=9:A$ = CHR$(31) :GOSUB 20: GOTO 230

close all files and end with a courteous remark. 360 CLOSE

370 V=V + 2:A$ = "End of run":GOSUB 20: V = V +1 :A$ = 'Thank you for using PATCHER4": GOSUB 20 390 END

error trap routine

1000 A$ = "Unable to open" + NM$:GOSUB 21 :GOSUB 90

0 0

Post a comment