100 REM Test NadaNet File Server 110 REM MJM - 03/17/07 120 : 130 GOSUB 50000: REM Initialize File Server Definitions 140 : 200 PRINT : PRINT "TEST.FSERVER running on Page " PEEK (104) 210 P$ = "testdir" 220 : 230 REM Do "Phase 2" if starting on page 32 240 IF PEEK (104) = 32 GOTO 940: REM (Page 8 on first execution) 250 : 260 REM Phase 1: Start monitoring 270 RQ$ = "mon 4": GOSUB 51000: REM MONitor all requests 280 : 290 REM Create directory 300 EH = 1: REM Handle error in-line 310 RQ$ = "create" + P$: GOSUB 51000 320 EH = 0: REM STOP on future errors 330 IF RC = 128 OR RC = 19 GOTO 360: REM DUPLICATE FILENAME error permitted 340 PRINT "*** Error: CREATE error "RC: STOP 350 : 360 REM Generate a page of data 370 BUF = 4 * 4096: REM $4000 380 POKE BUF,ID 390 FOR I = 1 TO 255: POKE BUF + I,I: NEXT 400 : 410 REM Save the data 420 F$ = P$ + "/testfile" + IS$: REM Unique file pathname 430 RQ$ = "bsave" + F$ + ",a" + STR$ (BUF) + ",l$100": GOSUB 51000 440 : 450 FOR I = 0 TO 255: POKE BUF + I,0: NEXT : REM Clear the buffer 460 POKE BUF + 256,55: REM Place mark just past end 470 : 480 REM Read it back 490 RQ$ = "bload" + F$: GOSUB 51000 500 : 510 REM Verify the file data 520 I = 0:ERR = PEEK (BUF) < > ID 530 FOR I = 1 TO 255 540 ERR = ERR OR ( PEEK (BUF + I) < > I) 550 NEXT 560 ERR = ERR OR ( PEEK (BUF + 256) < > 55): REM Verify transfer length 570 IF ERR THEN PRINT "*** Error: File length > 256.": STOP 580 PRINT "File data OK" 590 : 600 REM DELETE the file 610 RQ$ = "delete" + F$: GOSUB 51000 620 : 630 REM POKE a program to set 6 bytes at BUF+32 ($4020) to 165 640 LC = 3 * 256: REM $300 650 BP = LC 660 READ V: IF V > - 1 THEN POKE LC,V:LC = LC + 1: GOTO 660 670 DATA 169,165,162,5,157,32,64,202,16,250,96,3,96,-1 680 : 690 REM BSAVE the program 700 F$ = P$ + "/bruntst" + IS$: REM Unique file pathname 710 RQ$ = "bsave" + F$ + ",a$300,l" + STR$ (LC - BP): GOSUB 51000 720 : 730 REM BRUN the program at BUF+16 ($4010) 740 RQ$ = "brun" + F$ + ",a$4010": GOSUB 51000 750 AD = PEEK (RA + 1) + 256 * PEEK (RA + 2): REM BRUN address 760 IF AD < > BUF + 16 THEN PRINT "*** Error: BRUN addr="AD", not "BUF + 16 770 ERR = 0: REM Check that the program ran... 780 FOR I = 0 TO 5 790 ERR = ERR OR ( PEEK (BUF + 32 + I) < > 165) 800 NEXT 810 IF ERR THEN PRINT "*** Error: BRUN "F$" didn't run." 820 : 830 REM DELETE the file 840 RQ$ = "delete" + F$: GOSUB 51000 850 : 860 REM Test SAVE and RUN commands 870 F$ = P$ + "/test.fserverx" + IS$: REM Unique name for this program 880 RQ$ = "save" + F$: GOSUB 51000: REM SAVE a copy of this program 890 POKE 2 * 4096,0: POKE 104,32: REM Prepare to re-RUN it on Page 32 900 RQ$ = "run" + F$: GOSUB 51000: REM RUN! 910 PRINT "*** Error: RUN returned!!",A$ 920 STOP 930 REM =============== Second RUN =================== 940 REM Phase 2: Check more commands 950 F$ = P$ + "/test.fserverx" + IS$: REM Re-form unique name for porgram copy 960 RQ$ = "verify" + F$: GOSUB 51000: REM VERIFY copy 970 RQ$ = "delete" + F$: GOSUB 51000: REM DELETE copy 980 EH = 1: REM This time VERIFY should fail 990 RQ$ = "verify" + F$: GOSUB 51000: REM VERIFY copy 1000 EH = 0 1010 IF RC < > 6 THEN PRINT "*** Error: DELETE failed, RC="RC 1020 : 1030 REM RUN TEST.FSERVER2 1040 POKE 8 * 256,0: POKE 104,8: REM RUN it on page 8 1050 RQ$ = "run" + "test.fserver2": GOSUB 51000 1060 PRINT "*** Error: RUN returned!!",A$ 1070 STOP 1080 : 50000 REM ====== File Server definitions ====== 50010 ID = PEEK (3 * 256 + 12 * 16 + 12): REM My NadaNet ID ($3CC) 50020 ID$ = CHR$ (ID): REM My ID as CHR$ 50030 IS$ = STR$ (ID): REM My ID as STR$ 50040 FSRV = 16: REM Msg Class of File Server Requests 50050 RA = 2 * 256 + 6 * 16: REM Result Code address = $260 50060 : 50070 REM Install USR function to return address of param 50080 I = 3 * 256 + 11 * 16: REM USR code at $3B0 50090 POKE 12, INT (I / 256): POKE 11,I - PEEK (12) * 256: REM USR JMP 50100 READ A$: IF A$ < > "USR" GOTO 50100: REM Position to USR DATA 50110 READ V: IF V > - 1 THEN POKE I,V:I = I + 1: GOTO 50110 50120 DATA USR,160,2,177,131,72,136,177,131,168,104,76,242,226,-1 50130 RESTORE 50140 RETURN 50150 : 51000 REM ====== Invoke File Server ====== 51010 MS$ = ID$ + RQ$: REM Prefix ID 51020 POKE RA,127: REM Mark incomplete 51030 & PUTMSG(2,FSRV, LEN (MS$), USR (MS$)): REM Enqueue request 51040 FOR UNTIL = 0 TO 1 51050 & SERVE#():RC = PEEK (RA) 51060 UNTIL = (RC < > 127): NEXT : REM Await result 51070 REM RC = 129 means BRUN loaded code without error, now call it. 51080 IF RC = 129 THEN RC = 128: CALL PEEK (RA + 1) + 256 * PEEK (RA + 2) 51090 IF RC = 128 OR EH THEN RETURN : REM If OK or inline error handling 51100 PRINT "File server error "RC" for request:": PRINT "<"RQ$">" 51110 STOP