1 | ; Project name : Assembly Library
|
---|
2 | ; Description : Serial Server Support, Scan for Server
|
---|
3 | ;
|
---|
4 | ; This functionality is broken out from SerialServer as it may only be needed during
|
---|
5 | ; initialization to find a server, and then could be discarded, (for example the case
|
---|
6 | ; of a TSR).
|
---|
7 |
|
---|
8 | %include "SerialServer.inc"
|
---|
9 |
|
---|
10 | ; Section containing code
|
---|
11 | SECTION .text
|
---|
12 |
|
---|
13 | ;--------------------------------------------------------------------
|
---|
14 | ; SerialServerScan_ScanForServer:
|
---|
15 | ; Parameters:
|
---|
16 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
17 | ; 0xAx: Scan for drive, low nibble indicates drive
|
---|
18 | ; 0x0: Scan for Server, independent of drives
|
---|
19 | ; DX: Port and Baud to Scan for
|
---|
20 | ; 0: Scan a known set of ports and bauds
|
---|
21 | ; ES:SI: Ptr to buffer for return
|
---|
22 | ; Returns:
|
---|
23 | ; CF: Cleared if success, Set if error
|
---|
24 | ; Corrupts registers:
|
---|
25 | ; AL, BX, CX, DX, DI
|
---|
26 | ;--------------------------------------------------------------------
|
---|
27 | SerialServerScan_ScanForServer:
|
---|
28 | mov cx, 1 ; one sector, not scanning (default)
|
---|
29 |
|
---|
30 | test dx, dx
|
---|
31 | jnz short SerialServerScan_CheckForServer_PortAndBaudInDX
|
---|
32 |
|
---|
33 | mov di,.scanPortAddresses-1
|
---|
34 | mov ch,1 ; tell server that we are scanning
|
---|
35 |
|
---|
36 | .nextPort:
|
---|
37 | inc di ; load next port address
|
---|
38 | xor dh, dh
|
---|
39 | mov dl,[cs:di]
|
---|
40 | eSHL_IM dx, 2 ; shift from one byte to two
|
---|
41 | stc ; setup error code for exit
|
---|
42 | jz .error
|
---|
43 |
|
---|
44 | ;
|
---|
45 | ; Test for COM port presence, write to and read from registers
|
---|
46 | ;
|
---|
47 | push dx
|
---|
48 | add dl,Serial_UART_lineControl
|
---|
49 | mov al, 09ah
|
---|
50 | out dx, al
|
---|
51 | in al, dx
|
---|
52 | pop dx
|
---|
53 | cmp al, 09ah
|
---|
54 | jnz .nextPort
|
---|
55 |
|
---|
56 | mov al, 0ch
|
---|
57 | out dx, al
|
---|
58 | in al, dx
|
---|
59 | cmp al, 0ch
|
---|
60 | jnz .nextPort
|
---|
61 |
|
---|
62 | ;
|
---|
63 | ; Begin baud rate scan on this port...
|
---|
64 | ;
|
---|
65 | ; On a scan, we support 6 baud rates, starting here and going higher by a factor of two each step, with a
|
---|
66 | ; small jump between 9600 and 38800. These 6 were selected since we wanted to support 9600 baud and 115200,
|
---|
67 | ; *on the server side* if the client side had a 4x clock multiplier, a 2x clock multiplier, or no clock multiplier.
|
---|
68 | ;
|
---|
69 | ; Starting with 30h, that means 30h (2400 baud), 18h (4800 baud), 0ch (9600 baud), and
|
---|
70 | ; 04h (28800 baud), 02h (57600 baud), 01h (115200 baud)
|
---|
71 | ;
|
---|
72 | ; Note: hardware baud multipliers (2x, 4x) will impact the final baud rate and are not known at this level
|
---|
73 | ;
|
---|
74 | mov dh,030h * 2 ; multiply by 2 since we are about to divide by 2
|
---|
75 | mov dl,[cs:di] ; restore single byte port address for scan
|
---|
76 |
|
---|
77 | .nextBaud:
|
---|
78 | shr dh,1
|
---|
79 | jz .nextPort
|
---|
80 | cmp dh,6 ; skip from 6 to 4, to move from the top of the 9600 baud range
|
---|
81 | jnz .testBaud ; to the bottom of the 115200 baud range
|
---|
82 | mov dh,4
|
---|
83 |
|
---|
84 | .testBaud:
|
---|
85 | call SerialServerScan_CheckForServer_PortAndBaudInDX
|
---|
86 | jc .nextBaud
|
---|
87 |
|
---|
88 | .error:
|
---|
89 | ret
|
---|
90 |
|
---|
91 | .scanPortAddresses: db SERIAL_COM7_IOADDRESS >> 2
|
---|
92 | db SERIAL_COM6_IOADDRESS >> 2
|
---|
93 | db SERIAL_COM5_IOADDRESS >> 2
|
---|
94 | db SERIAL_COM4_IOADDRESS >> 2
|
---|
95 | db SERIAL_COM3_IOADDRESS >> 2
|
---|
96 | db SERIAL_COM2_IOADDRESS >> 2
|
---|
97 | db SERIAL_COM1_IOADDRESS >> 2
|
---|
98 | db 0
|
---|
99 |
|
---|
100 |
|
---|
101 | ;--------------------------------------------------------------------
|
---|
102 | ; SerialServer_CheckForServer_PortAndBaudInDX:
|
---|
103 | ; Parameters:
|
---|
104 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
105 | ; 0xAx: Scan for drive, low nibble indicates drive
|
---|
106 | ; 0x0: Scan for Server, independent of drives
|
---|
107 | ; DX: Baud and Port
|
---|
108 | ; CH: 1: We are doing a scan for the serial server
|
---|
109 | ; 0: We are working off a specific port given by the user
|
---|
110 | ; CL: 1, for one sector to read
|
---|
111 | ; ES:SI: Ptr to buffer for return
|
---|
112 | ; Returns:
|
---|
113 | ; AH: INT 13h Error Code
|
---|
114 | ; CF: Cleared if success, Set if error
|
---|
115 | ; Corrupts registers:
|
---|
116 | ; AL, BX
|
---|
117 | ;--------------------------------------------------------------------
|
---|
118 | SerialServerScan_CheckForServer_PortAndBaudInDX:
|
---|
119 | push bp ; setup fake SerialServer_Command
|
---|
120 |
|
---|
121 | push dx ; send port baud and rate, returned in inquire packet
|
---|
122 | ; (and possibly returned in the drive identification string)
|
---|
123 |
|
---|
124 | push cx ; send number of sectors, and if it is on a scan or not
|
---|
125 |
|
---|
126 | mov bl,SerialServer_Command_Inquire ; protocol command onto stack with bh
|
---|
127 | push bx
|
---|
128 |
|
---|
129 | mov bp,sp
|
---|
130 |
|
---|
131 | call SerialServer_SendReceive
|
---|
132 |
|
---|
133 | pop bx
|
---|
134 | pop cx
|
---|
135 | pop dx
|
---|
136 | pop bp
|
---|
137 |
|
---|
138 | ret
|
---|
139 |
|
---|