Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / dos / _event.asm
1 ;****************************************************************************
2 ;*
3 ;*                  SciTech Multi-platform Graphics Library
4 ;*
5 ;*  ========================================================================
6 ;*
7 ;*    The contents of this file are subject to the SciTech MGL Public
8 ;*    License Version 1.0 (the "License"); you may not use this file
9 ;*    except in compliance with the License. You may obtain a copy of
10 ;*    the License at http://www.scitechsoft.com/mgl-license.txt
11 ;*
12 ;*    Software distributed under the License is distributed on an
13 ;*    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 ;*    implied. See the License for the specific language governing
15 ;*    rights and limitations under the License.
16 ;*
17 ;*    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 ;*
19 ;*    The Initial Developer of the Original Code is SciTech Software, Inc.
20 ;*    All Rights Reserved.
21 ;*
22 ;*  ========================================================================
23 ;*
24 ;* Language:    80386 Assembler
25 ;* Environment: IBM PC (MS DOS)
26 ;*
27 ;* Description: Assembly language support routines for the event module.
28 ;*
29 ;****************************************************************************
30
31         ideal
32
33 include "scitech.mac"           ; Memory model macros
34
35 ifdef flatmodel
36
37 header  _event                  ; Set up memory model
38
39 begdataseg  _event
40
41     cextern  _EVT_biosPtr,DPTR
42
43 ifdef   USE_NASM
44 %define KB_HEAD     WORD esi+01Ah   ; Keyboard buffer head in BIOS data area
45 %define KB_TAIL     WORD esi+01Ch   ; Keyboard buffer tail in BIOS data area
46 %define KB_START    WORD esi+080h   ; Start of keyboard buffer in BIOS data area
47 %define KB_END      WORD esi+082h   ; End of keyboard buffer in BIOS data area
48 else
49 KB_HEAD     EQU WORD esi+01Ah       ; Keyboard buffer head in BIOS data area
50 KB_TAIL     EQU WORD esi+01Ch       ; Keyboard buffer tail in BIOS data area
51 KB_START    EQU WORD esi+080h       ; Start of keyboard buffer in BIOS data area
52 KB_END      EQU WORD esi+082h       ; End of keyboard buffer in BIOS data area
53 endif
54
55 enddataseg  _event
56
57 begcodeseg  _event              ; Start of code segment
58
59     cpublic _EVT_codeStart
60
61 ;----------------------------------------------------------------------------
62 ; int _EVT_getKeyCode(void)
63 ;----------------------------------------------------------------------------
64 ; Returns the key code for the next available key by extracting it from
65 ; the BIOS keyboard buffer.
66 ;----------------------------------------------------------------------------
67 cprocstart  _EVT_getKeyCode
68
69         enter_c
70
71         mov     esi,[_EVT_biosPtr]
72         xor     ebx,ebx
73         xor     eax,eax
74         mov     bx,[KB_HEAD]
75         cmp     bx,[KB_TAIL]
76         jz      @@Done
77         xor     eax,eax
78         mov     ax,[esi+ebx]    ; EAX := character from keyboard buffer
79         inc     _bx
80         inc     _bx
81         cmp     bx,[KB_END]     ; Hit the end of the keyboard buffer?
82         jl      @@1
83         mov     bx,[KB_START]
84 @@1:    mov     [KB_HEAD],bx    ; Update keyboard buffer head pointer
85
86 @@Done: leave_c
87         ret
88
89 cprocend
90
91 ;----------------------------------------------------------------------------
92 ; void _EVT_pumpMessages(void)
93 ;----------------------------------------------------------------------------
94 ; This function would normally do nothing, however due to strange bugs
95 ; in the Windows 3.1 and OS/2 DOS boxes, we don't get any hardware keyboard
96 ; interrupts unless we periodically call the BIOS keyboard functions. Hence
97 ; this function gets called every time that we check for events, and works
98 ; around this problem (in essence it tells the DOS VDM to pump the
99 ; keyboard events to our program ;-).
100 ;
101 ; Note that this bug is not present under Win 9x DOS boxes.
102 ;----------------------------------------------------------------------------
103 cprocstart  _EVT_pumpMessages
104
105         mov     ah,11h          ; Function - Check keyboard status
106         int     16h             ; Call BIOS
107         
108         mov     ax, 0Bh         ; Reset Move Mouse
109         int     33h
110         ret
111
112 cprocend
113
114 ;----------------------------------------------------------------------------
115 ; int _EVT_disableInt(void);
116 ;----------------------------------------------------------------------------
117 ; Return processor interrupt status and disable interrupts.
118 ;----------------------------------------------------------------------------
119 cprocstart  _EVT_disableInt
120
121         pushf                   ; Put flag word on stack
122         cli                     ; Disable interrupts!
123         pop     eax             ; deposit flag word in return register
124         ret
125
126 cprocend
127
128 ;----------------------------------------------------------------------------
129 ; void _EVT_restoreInt(int ps);
130 ;----------------------------------------------------------------------------
131 ; Restore processor interrupt status.
132 ;----------------------------------------------------------------------------
133 cprocstart  _EVT_restoreInt
134
135         ARG     ps:UINT
136
137         push    ebp
138         mov     ebp,esp         ; Set up stack frame
139         push    [DWORD ps]
140         popf                    ; Restore processor status (and interrupts)
141         pop     ebp
142         ret
143
144 cprocend
145
146 ;----------------------------------------------------------------------------
147 ; int EVT_rdinx(int port,int index)
148 ;----------------------------------------------------------------------------
149 ; Reads an indexed register value from an I/O port.
150 ;----------------------------------------------------------------------------
151 cprocstart  EVT_rdinx
152
153         ARG     port:UINT, index:UINT
154
155         push    ebp
156         mov     ebp,esp
157         mov     edx,[port]
158         mov     al,[BYTE index]
159         out     dx,al
160         inc     dx
161         in      al,dx
162         movzx   eax,al
163         pop     ebp
164         ret
165
166 cprocend
167
168 ;----------------------------------------------------------------------------
169 ; void EVT_wrinx(int port,int index,int value)
170 ;----------------------------------------------------------------------------
171 ; Writes an indexed register value to an I/O port.
172 ;----------------------------------------------------------------------------
173 cprocstart  EVT_wrinx
174
175         ARG     port:UINT, index:UINT, value:UINT
176
177         push    ebp
178         mov     ebp,esp
179         mov     edx,[port]
180         mov     al,[BYTE index]
181         mov     ah,[BYTE value]
182         out     dx,ax
183         pop     ebp
184         ret
185
186 cprocend
187
188     cpublic _EVT_codeEnd
189
190 endcodeseg  _event
191
192 endif
193
194         END                         ; End of module