'=========================================================================== ' Subject: DETERMINE PORTS IN USE Date: 04-27-99 (16:50) ' Author: Donald R. Darden Code: PB ' Origin: oldefoxx@earthlink.net Packet: PB.ABC '=========================================================================== defint a-z color 15,1 cls if instr(command$,"?") then ?"PORT USE, by Donald R. Darden, 1999, offered as FREEWARE" ? ?"This program scans the port addresses from 000 to 3FF and tries to determine" ?"which ones are attached to a hardware adapter of some sort, and which ones ?"are still available to be assigned to new hardware. It works by using the ?"fact that PCs are designed to return a high or all-ones condition (&hFF or ?"255 decimal) when not attached to an external device. Because individual ?"registers in an adapter can also return an all-ones condition, it is very ?"important to consider the adjacent addresses when testing ports in this ?"fashion. For instance, 8 consecutive ports are unlikely to all be set to ?"255 when attached to an adapter, but it could happen, whereas any one NOT ?"being set to 255 would surely indicate that an adapter is present. ? ?"As submitted, this program makes four assumptions: (1) The range of ?"possible port addresses is from 0 to 4095. (It could concievably be from ?"0 to 65535). (2) That the interest is primarily in 8-port groups (which ?"correspond to the number of ports needed for additional serial ports). ?"(3) That the particular multiport card to be added has eight serial ports, ?"and these all need to be adjacent to each other (a block of 64 consecutive ?"ports is needed). And (4) that for addressing purposes, the first serial ?"port must start on an exact multiple of 64 boundary (000, 040, 080, 0C0, ?"100, etc.). If all these conditions are satisfied, the corresponding line ?"in the output file (default name: A:\portuse.txt) will end with ***. (All ?"lines having :: should be :FF:, but are compressed for readability.) ?,"Press any key to continue... "; locate ,,1 sleep cls ?"This information can be of particular value when checked against the list of ?"I/O ports maintained by Ralf Brown (as a part of his comprehensive list of ?"PC Interrupts and other related information, available from the Internet, ?"without charge. Check out sites that cover PC Assembly Language Programming ?"(by using a search engine such as www.hotbot.com, www.lycos.com, www.snap. ?"com, www.altavista.digital.com, among others). By matching your used ports ?"against with what the PORTS list indicates, and consulting your PC Setup ?"screen or documentation, you should be able to get a pretty good handle on ?"what you have installed and where it resides in your PC. ? ?"Note that many adapters can be reconfigured to work from different port ?"locations and/or with different Interrupts (IRQs). This can be very ?"important if you have two adapters whose settings put them at the same or ?"overlapping ports. You can't allow this, because this can lock up your PC, ?"or cause other problems. If you don't have the documentation for your ?"adapters, you can still see what different PORT settings are allowed for ?"them (if listed in the PORTS list, or by checking out the venders' sites ?"on the internet to see if they offer that information on line)." ? ?"One precaution about working with unknown hardware/ports. It is generally ?"safe to use the INP(port_addr) command as demonstrated by this program, but ?"the same cannot be said for the OUT command. That is because the PC and ?"attached hardware are vulnerable to changes that you can make in timing, ?"interrupt states, what is enabled and disabled, and so on. So be careful." ?,"Press any key now to run the program... "; locate ,,1 sleep cls end if open "a:\portuse.txt" for output as #1 d=0 for a=0 to 4095-64 step 8 do e=0 for b=a to a+63 bad=0 on error goto override if inp(b)<&hff then incr e on error goto 0 next if a>=d then if e then ?"Ports "right$("00"+hex$(a),3)" - "right$("00"+hex$(a+7),3)": "; ?#1,"Ports "right$("00"+hex$(a),3)" - "right$("00"+hex$(a+7),3)": "; for b=a to a+7 ?":"; ?#1,":"; if inp(b)<&hff then ?hex$(inp(b)); ?#1,hex$(inp(b)); end if next ? ?#1,"" else if (a mod &H40)=0 then ?"Ports "right$("00"+hex$(a),3)" - "right$("00"+hex$(a+63),3) _ ": appears to be available. ***" ?#1,"Ports "right$("00"+hex$(a),3)" - "right$("00"+hex$(a+63),3) _ ": appears to be available. ***" incr a,56 else ?"Ports "right$("00"+hex$(a),3)" - "right$("00"+hex$(a+7),3) _ ": appears to be available." ?#1,"Ports "right$("00"+hex$(a),3)" - "right$("00"+hex$(a+7),3) _ ": appears to be available." end if end if end if loop until 1 next close ?"Done!" end override: bad=0 if bad=0 then bad=-1 resume next