RESPON.BAS - A demo response fielder program

100 ! RESPON.BAS - pick up CDROM server data, put it in file for use
110 ! by requesting job, and wake that job up from its XCALL SLEEP.
120 ! This BASIC program requires that AUTLOG.LIT and AUTLOG.SBR
130 ! be LOADED in user or system memory. AUTLOG.IMP must also be
140 ! loaded in memory, which is done by executing AUTLOG, then an
150 ! AMOS command to drop to the dot. Then you can fire this program up.
160 ! Note that this prgram, and REQ.BAS assume to all be running in the same
170 ! account. Also, both programs have hard coded "PCSERV" as the serial
180 ! port of the PC server. Make sure its baud rate matches the rate of the
190 ! server software.
200 map1 MODE,b,2               ! mode 0=CHAR I/O, 1=COMMANDS, 2=TALK, 3=SCREEN
210 map1 ERRCOD         ! contains status of last command
220     map2 AUTERR,b,1
230     map2 REMERR,b,1
240 MAP1 OVERLAYS
250     MAP2 STRING,s,10002,@OVERLAYS
260     MAP2 UNFORMAT,@OVERLAYS
270     map3 CHAR'COUNT,b,2
280     map3 TEXT'AREA,x,10000
290     map3 AS'ARRAY(10000),b,1,@TEXT'AREA
300     map3 AS'A'STRING,s,10000,@TEXT'AREA
310
320 MAP1 MISC
330     MAP2 ACTION,f,6
340     MAP2 DONE,f,6
350
360 MAP1 TICKS,b,4
370 MAP1 MATCH'AREA
380     MAP2 MATCH'COUNT,b,2
390     MAP2 MATCH'STRING,x,100
400 MAP1 STX,s,1,CHR(2)
410 MAP1 ETX,S,1,CHR(3)
420 MAP1 FUNCTION,s,3
430 MAP1 ID,s,3
440 MAP1 LENGTH,f
450 MAP1 CHECKSUM
460 MAP1 COMPUTED,F
470 MAP1 OUTFILE,s,40
480
490 AS'A'STRING = "LINK PCSERV"
500 MODE = 1
510 XCALL AUTLOG, MODE, AS'A'STRING, ERRCOD
520 IF AUTERR THEN PRINT "LINK: AUTERR=";AUTERR : STOP
530 ! Main routine. LINK up to CDROM port, set BAUD rate, and wait for
540 ! responses. Write them to disk when we get them.
550 RESET'BUFFER:
560 CHAR'COUNT = 0
570 LOOP:
580 MATCH'STRING = ETX
590 MATCH'COUNT = 1
600 TICKS = 60 * 10000
610 MODE = 7
620 XCALL AUTLOG, MODE, UNFORMAT, ERRCOD, TICKS , MATCH'AREA
630 IF (REMERR AND 2)=2 goto LOOP  ! timed out
640 IF (REMERR AND 4)=4 goto LOOP  ! no match
650 IF (REMERR AND 8)=8 goto LOOP  ! buffer full
660 ! we have a packet - lets check it
670 ! set POS to index position of STX in buffer
680 POS = INSTR(1,AS'A'STRING,STX)
690 if POS = 0 GOTO RESET'BUFFER  ! no STX in packet - toss it
700 FUNCTION = AS'A'STRING[POS+1;3]
710 ID = AS'A'STRING[POS+4;3]
720 LENGTH = AS'A'STRING[POS+7;8]
730 CSUM = AS'A'STRING[CHAR'COUNT-3;3]
740 ? "ID=";ID;" FUNCTION=";FUNCTION;" LENGTH=";LENGTH;" CHAR'COUNT=";CHAR'COUNT
750 IF LENGTH > CHAR'COUNT+1-POS PRINT "LENGTH is BAD" : GOTO RESET'BUFFER
760 COMPUTED = 0
770 FOR I= POS to POS+LENGTH-5  ! less checksum & ETX
780 COMPUTED = COMPUTED + AS'ARRAY(I)
790 NEXT I
800 ?
810 COMPUTED = (COMPUTED AND 255)
820 IF COMPUTED # CSUM PRINT "CSUM = ";CSUM;" COMPUTED=";COMPUTED
830 OUTFILE = "CAT" +  ID + ".DAT"
840 ? "WRITING ";OUTFILE
850 OPEN #2,OUTFILE, OUTPUT
860 ? #2 AS'A'STRING[POS+13;LENGTH-17]
870 CLOSE #2
880 XCALL WAKNO,ID
890 ?
900 GOTO RESET'BUFFER