]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/elksutil.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / elksutil.c
1 /*
2  * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
3  *
4  * ELKS utility routines for Micro-Windows drivers
5  */
6 #include "device.h"
7 #include "vgaplan4.h"
8
9 /*
10  * Return the byte at far address
11  */
12 unsigned char
13 GETBYTE_FP(FARADDR addr)
14 {
15 #asm
16         push    bp
17         mov     bp,sp
18         push    ds
19
20         mov     bx,[bp+4]       ! bx = lo addr
21         mov     ax,[bp+6]       ! ds = hi addr
22         mov     ds,ax
23         mov     al,[bx]         ! get byte at ds:bx
24         xor     ah,ah
25
26         pop     ds
27         pop     bp
28 #endasm
29 }
30
31 /*
32  * Put the byte at far address
33  */
34 void
35 PUTBYTE_FP(FARADDR addr,unsigned char val)
36 {
37 #asm
38         push    bp
39         mov     bp,sp
40         push    ds
41
42         mov     bx,[bp+4]       ! bx = lo addr
43         mov     ax,[bp+6]       ! ds = hi addr
44         mov     ds,ax
45         mov     al,[bp+8]       ! al = val
46         mov     [bx],al         ! put byte at ds:bx
47
48         pop     ds
49         pop     bp
50 #endasm
51 }
52
53 /*
54  * Read-modify-write the byte at far address
55  */
56 void
57 RMW_FP(FARADDR addr)
58 {
59 #asm
60         push    bp
61         mov     bp,sp
62         push    ds
63
64         mov     bx,[bp+4]       ! bx = lo addr
65         mov     ax,[bp+6]       ! ds = hi addr
66         mov     ds,ax
67         or      [bx],al         ! rmw byte at ds:bx, al value doesnt matter
68
69         pop     ds
70         pop     bp
71 #endasm
72 }
73
74 /*
75  * Or the byte at far address
76  */
77 void
78 ORBYTE_FP(FARADDR addr,unsigned char val)
79 {
80 #asm
81         push    bp
82         mov     bp,sp
83         push    ds
84
85         mov     bx,[bp+4]       ! bx = lo addr
86         mov     ax,[bp+6]       ! ds = hi addr
87         mov     ds,ax
88         mov     al,[bp+8]       ! al = val
89         or      [bx],al         ! or byte at ds:bx
90
91         pop     ds
92         pop     bp
93 #endasm
94 }
95
96 /*
97  * And the byte at far address
98  */
99 void
100 ANDBYTE_FP(FARADDR addr,unsigned char val)
101 {
102 #asm
103         push    bp
104         mov     bp,sp
105         push    ds
106
107         mov     bx,[bp+4]       ! bx = lo addr
108         mov     ax,[bp+6]       ! ds = hi addr
109         mov     ds,ax
110         mov     al,[bp+8]       ! al = val
111         and     [bx],al         ! and byte at ds:bx
112
113         pop     ds
114         pop     bp
115 #endasm
116 }
117
118 /*
119  * Input byte from i/o port
120  */
121 int
122 inportb(int port)
123 {
124 #asm
125         push    bp
126         mov     bp,sp
127
128         mov     dx,[bp+4]       ! dx = port
129         in      al,dx           ! input byte
130         xor     ah,ah
131
132         pop     bp
133 #endasm
134 }
135
136 /*
137  * Output byte to i/o port
138  */
139 void
140 outportb(int port,unsigned char data)
141 {
142 #asm
143         push    bp
144         mov     bp,sp
145
146         mov     dx,[bp+4]       ! dx = port
147         mov     al,[bp+6]       ! al = data
148         out     dx,al
149
150         pop     bp
151 #endasm
152 }
153
154 /*
155  * Output word i/o port
156  */
157 void
158 outport(int port,int data)
159 {
160 #asm
161         push    bp
162         mov     bp,sp
163
164         mov     dx,[bp+4]       ! dx = port
165         mov     ax,[bp+6]       ! ax = data
166         out     dx,ax
167
168         pop     bp
169 #endasm
170 }
171
172 /*
173  * es:bp = int10(int ax,int bx)
174  *  Call video bios using interrupt 10h
175  */
176 FARADDR
177 int10(int ax,int bx)
178 {
179 #asm
180         push    bp
181         mov     bp,sp
182         push    es
183         push    ds
184         push    si
185         push    di
186
187         mov     ax,[bp+4]       ! get first arg
188         mov     bx,[bp+6]       ! get second arg
189         int     $10
190         mov     dx,es           ! return es:bp
191         mov     ax,bp
192
193         pop     di
194         pop     si
195         pop     ds
196         pop     es
197         pop     bp
198 #endasm
199 }
200
201 /* poll the keyboard*/
202 int
203 kbpoll(void)
204 {
205 #asm
206         mov     ah,1                    ! read, no remove
207         int     $16
208         jz      nordy                   ! no chars ready
209         mov     ax,1                    ! chars ready
210         ret
211 nordy:  xor     ax,ax                   ! no chars ready
212 #endasm
213 }
214
215 /* wait and read a kbd char when ready*/
216 int
217 kbread(void)
218 {
219 #asm
220         xor     ah,ah                   ! read and remove
221         int     $16                     ! return ax
222 #endasm
223 }
224
225 /* return kbd shift status*/
226 int
227 kbflags(void)
228 {
229 #asm
230         mov     ah,2                    ! get shift status
231         int     $16
232         mov     ah,0                    ! low bits only for now...
233 #endasm
234 }