DECLARE FUNCTION AskForBaseAddress! (OldOne AS INTEGER) '*-------------------------------------------------------------------- '* Sample program demonstrating register level access '* of input data '*-------------------------------------------------------------------- ' 'Declare table of offsets into data registers ' DIM OFS%(6) OFS%(0) = 0 OFS%(1) = 1 OFS%(2) = 2 OFS%(3) = 4 OFS%(4) = 5 OFS%(5) = 6 ' ' Display program header information ' CLS PRINT " SAMPLE 1.BAS" PRINT PRINT "Demonstration program for accessing input data." PRINT "Program reads each of the input ports"; " 16 input" PRINT "channels and displays on/off status of those channels." PRINT : PRINT Address% = AskForBaseAddress!(&H350) CLS PRINT : PRINT : PRINT PRINT "Board Configuration:" PRINT PRINT " -- Base Address is "; HEX$(Address%); " hex" PRINT " -- If you are using the option C card, all mode switches" PRINT " should be OFF." PRINT " -- All remaining jumper settings are irrelevant" PRINT : PRINT : PRINT PRINT "Press any key to continue " A$ = INPUT$(1) ' ' Main program loop ' CLS LOCATE 4, 1 INPUT "Enter port nunmber to read (0,1,2): "; PORT% READLOOP: CLS LOCATE 2, 28 PRINT "Reading Port "; PRINT PORT% LOCATE 4, 27 PRINT "Input Status" LOCATE 5, 27 PRINT "------------------" ' ' Read the first 8 input channels of the current port ' BYTE% = INP(Address% + OFS%(2 * PORT%)) FOR i% = 0 TO 7 LOCATE 6 + i%, 28 PRINT USING "##"; i% BIT% = BYTE% MOD 2 BYTE% = INT(BYTE% / 2) LOCATE 6 + i%, 43 IF BIT% = 1 THEN PRINT "ON " ELSE PRINT "OFF" END IF NEXT i% ' ' Read second 8 input channels of the current port ' BYTE% = INP(Address% + OFS%(2 * PORT% + 1)) FOR i% = 8 TO 15 LOCATE 6 + i%, 28 PRINT USING "##"; i% BIT% = BYTE% MOD 2 BYTE% = INT(BYTE% / 2) LOCATE 6 + i%, 43 IF BIT% = 1 THEN PRINT "ON " ELSE PRINT "OFF" END IF NEXT i% LOCATE 24, 10 PRINT "Press 'Q' to quit; press any other key to re-read the port" A$ = INPUT$(1) IF A$ = "Q" THEN GOTO QUIT IF A$ = "q" THEN GOTO QUIT GOTO READLOOP QUIT: CLS END FUNCTION AskForBaseAddress (OldOne AS INTEGER) Msg$ = "" NewOne% = 0: Success = 0: Dummy% = 0 AddrInputPosX = 0: AddrInputPosY = 0 PRINT "Please enter the Base Address (0000-FFFF) for your card (in hex)" PRINT "or press ENTER for "; HEX$(OldOne%); "." PRINT ">"; AddrInputPosX = POS(0): AddrInputPosY = CSRLIN WHILE Success = 0 LOCATE AddrInputPosY, AddrInputPosX PRINT " " LOCATE AddrInputPosY, AddrInputPosX LINE INPUT Msg$ NewOne% = VAL("&H0" + LEFT$(Msg$, 4)) Success = 1 Dummy% = NewOne% IF (Msg$ = "") THEN LOCATE AddrInputPosY, AddrInputPosX PRINT HEX$(OldOne%) Success = 1 Dummy% = OldOne% END IF WEND AskForBaseAddress = Dummy% END FUNCTION