source: xtideuniversalbios/trunk/Assembly_Library/Src/Serial/SerialServerScan.asm@ 323

Last change on this file since 323 was 277, checked in by gregli@…, 13 years ago

Moved the bulk of the serial code to the assembly library, for inclusion in other utilities. Fixed a bug in int13h.asm when floppy support was not enabled that was preventing foreign drives from working properly.

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