Subversion Repositories Kolibri OS

Rev

Rev 1310 | Rev 1314 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1310 Rev 1312
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
2
;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.
4
;; PROGRAMMING:
4
;; PROGRAMMING:
5
;; Ivan Poddubny
5
;; Ivan Poddubny
6
;; Marat Zakiyanov (Mario79)
6
;; Marat Zakiyanov (Mario79)
7
;; VaStaNi
7
;; VaStaNi
8
;; Trans
8
;; Trans
9
;; Mihail Semenyako (mike.dld)
9
;; Mihail Semenyako (mike.dld)
10
;; Sergey Kuzmin (Wildwest)
10
;; Sergey Kuzmin (Wildwest)
11
;; Andrey Halyavin (halyavin)
11
;; Andrey Halyavin (halyavin)
12
;; Mihail Lisovin (Mihasik)
12
;; Mihail Lisovin (Mihasik)
13
;; Andrey Ignatiev (andrew_programmer)
13
;; Andrey Ignatiev (andrew_programmer)
14
;; NoName
14
;; NoName
15
;; Evgeny Grechnikov (Diamond)
15
;; Evgeny Grechnikov (Diamond)
16
;; Iliya Mihailov (Ghost)
16
;; Iliya Mihailov (Ghost)
17
;; Sergey Semyonov (Serge)
17
;; Sergey Semyonov (Serge)
18
;; Johnny_B
18
;; Johnny_B
19
;; SPraid (simba)
19
;; SPraid (simba)
20
;; Hidnplayr
20
;; Hidnplayr
21
;; Alexey Teplov ()
21
;; Alexey Teplov ()
22
;;
22
;;
23
;; Data in this file was originally part of MenuetOS project which is
23
;; Data in this file was originally part of MenuetOS project which is
24
;; distributed under the terms of GNU GPL. It is modified and redistributed as
24
;; distributed under the terms of GNU GPL. It is modified and redistributed as
25
;; part of KolibriOS project under the terms of GNU GPL.
25
;; part of KolibriOS project under the terms of GNU GPL.
26
;;
26
;;
27
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
27
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
28
;; PROGRAMMING:
28
;; PROGRAMMING:
29
;;
29
;;
30
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
30
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
31
;; - main os coding/design
31
;; - main os coding/design
32
;; Jan-Michael Brummer, BUZZ2@gmx.de
32
;; Jan-Michael Brummer, BUZZ2@gmx.de
33
;; Felix Kaiser, info@felix-kaiser.de
33
;; Felix Kaiser, info@felix-kaiser.de
34
;; Paolo Minazzi, paolo.minazzi@inwind.it
34
;; Paolo Minazzi, paolo.minazzi@inwind.it
35
;; quickcode@mail.ru
35
;; quickcode@mail.ru
36
;; Alexey, kgaz@crosswinds.net
36
;; Alexey, kgaz@crosswinds.net
37
;; Juan M. Caravaca, bitrider@wanadoo.es
37
;; Juan M. Caravaca, bitrider@wanadoo.es
38
;; kristol@nic.fi
38
;; kristol@nic.fi
39
;; Mike Hibbett, mikeh@oceanfree.net
39
;; Mike Hibbett, mikeh@oceanfree.net
40
;; Lasse Kuusijarvi, kuusijar@lut.fi
40
;; Lasse Kuusijarvi, kuusijar@lut.fi
41
;; Jarek Pelczar, jarekp3@wp.pl
41
;; Jarek Pelczar, jarekp3@wp.pl
42
;;
42
;;
43
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
43
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
44
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
44
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
45
;; consequences of using it or for whether it serves any particular purpose or
45
;; consequences of using it or for whether it serves any particular purpose or
46
;; works at all, unless he says so in writing. Refer to the GNU General Public
46
;; works at all, unless he says so in writing. Refer to the GNU General Public
47
;; License (the "GPL") for full details.
47
;; License (the "GPL") for full details.
48
;
48
;
49
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
49
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
50
;; but only under the conditions described in the GPL. A copy of this license
50
;; but only under the conditions described in the GPL. A copy of this license
51
;; is supposed to have been given to you along with KolibriOS so you can know
51
;; is supposed to have been given to you along with KolibriOS so you can know
52
;; your rights and responsibilities. It should be in a file named COPYING.
52
;; your rights and responsibilities. It should be in a file named COPYING.
53
;; Among other things, the copyright notice and this notice must be preserved
53
;; Among other things, the copyright notice and this notice must be preserved
54
;; on all copies.
54
;; on all copies.
55
;;
55
;;
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57
 
57
 
58
include 'macros.inc'
58
include 'macros.inc'
59
 
59
 
60
$Revision: 1310 $
60
$Revision: 1312 $
61
 
61
 
62
 
62
 
63
USE_COM_IRQ     equ 1      ; make irq 3 and irq 4 available for PCI devices
63
USE_COM_IRQ     equ 1      ; make irq 3 and irq 4 available for PCI devices
64
 
64
 
65
; Enabling the next line will enable serial output console
65
; Enabling the next line will enable serial output console
66
;debug_com_base  equ 0x3f8  ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
66
;debug_com_base  equ 0x3f8  ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
67
 
67
 
68
include "proc32.inc"
68
include "proc32.inc"
69
include "kglobals.inc"
69
include "kglobals.inc"
70
include "lang.inc"
70
include "lang.inc"
71
 
71
 
72
include "const.inc"
72
include "const.inc"
73
max_processes    equ   255
73
max_processes    equ   255
74
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
74
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
75
 
75
 
76
 
76
 
77
os_stack       equ  (os_data_l-gdts)    ; GDTs
77
os_stack       equ  (os_data_l-gdts)    ; GDTs
78
os_code        equ  (os_code_l-gdts)
78
os_code        equ  (os_code_l-gdts)
79
graph_data     equ  (3+graph_data_l-gdts)
79
graph_data     equ  (3+graph_data_l-gdts)
80
tss0           equ  (tss0_l-gdts)
80
tss0           equ  (tss0_l-gdts)
81
app_code       equ  (3+app_code_l-gdts)
81
app_code       equ  (3+app_code_l-gdts)
82
app_data       equ  (3+app_data_l-gdts)
82
app_data       equ  (3+app_data_l-gdts)
83
app_tls        equ  (3+tls_data_l-gdts)
83
app_tls        equ  (3+tls_data_l-gdts)
84
pci_code_sel   equ  (pci_code_32-gdts)
84
pci_code_sel   equ  (pci_code_32-gdts)
85
pci_data_sel   equ  (pci_data_32-gdts)
85
pci_data_sel   equ  (pci_data_32-gdts)
86
 
86
 
87
 
87
 
88
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
88
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89
;;
89
;;
90
;;   Included files:
90
;;   Included files:
91
;;
91
;;
92
;;   Kernel16.inc
92
;;   Kernel16.inc
93
;;    - Booteng.inc   English text for bootup
93
;;    - Booteng.inc   English text for bootup
94
;;    - Bootcode.inc  Hardware setup
94
;;    - Bootcode.inc  Hardware setup
95
;;    - Pci16.inc     PCI functions
95
;;    - Pci16.inc     PCI functions
96
;;
96
;;
97
;;   Kernel32.inc
97
;;   Kernel32.inc
98
;;    - Sys32.inc     Process management
98
;;    - Sys32.inc     Process management
99
;;    - Shutdown.inc  Shutdown and restart
99
;;    - Shutdown.inc  Shutdown and restart
100
;;    - Fat32.inc     Read / write hd
100
;;    - Fat32.inc     Read / write hd
101
;;    - Vesa12.inc    Vesa 1.2 driver
101
;;    - Vesa12.inc    Vesa 1.2 driver
102
;;    - Vesa20.inc    Vesa 2.0 driver
102
;;    - Vesa20.inc    Vesa 2.0 driver
103
;;    - Vga.inc       VGA driver
103
;;    - Vga.inc       VGA driver
104
;;    - Stack.inc     Network interface
104
;;    - Stack.inc     Network interface
105
;;    - Mouse.inc     Mouse pointer
105
;;    - Mouse.inc     Mouse pointer
106
;;    - Scincode.inc  Window skinning
106
;;    - Scincode.inc  Window skinning
107
;;    - Pci32.inc     PCI functions
107
;;    - Pci32.inc     PCI functions
108
;;
108
;;
109
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110
 
110
 
111
 
111
 
112
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
113
;;                                                                      ;;
113
;;                                                                      ;;
114
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
114
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
115
;;                                                                      ;;
115
;;                                                                      ;;
116
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
116
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117
 
117
 
118
use16
118
use16
119
                  org   0x0
119
                  org   0x0
120
                  jmp   start_of_code
120
                  jmp   start_of_code
121
 
121
 
122
version db    'Kolibri OS  version 0.7.5.0      ',13,10,13,10,0
122
version db    'Kolibri OS  version 0.7.5.0      ',13,10,13,10,0
123
 
123
 
124
include "boot/bootstr.inc"     ; language-independent boot messages
124
include "boot/bootstr.inc"     ; language-independent boot messages
125
include "boot/preboot.inc"
125
include "boot/preboot.inc"
126
 
126
 
127
if lang eq en
127
if lang eq en
128
include "boot/booteng.inc"     ; english system boot messages
128
include "boot/booteng.inc"     ; english system boot messages
129
else if lang eq ru
129
else if lang eq ru
130
include "boot/bootru.inc"      ; russian system boot messages
130
include "boot/bootru.inc"      ; russian system boot messages
131
include "boot/ru.inc"          ; Russian font
131
include "boot/ru.inc"          ; Russian font
132
else if lang eq et
132
else if lang eq et
133
include "boot/bootet.inc"      ; estonian system boot messages
133
include "boot/bootet.inc"      ; estonian system boot messages
134
include "boot/et.inc"          ; Estonian font
134
include "boot/et.inc"          ; Estonian font
135
else
135
else
136
include "boot/bootge.inc"      ; german system boot messages
136
include "boot/bootge.inc"      ; german system boot messages
137
end if
137
end if
138
 
138
 
139
include "boot/bootcode.inc"    ; 16 bit system boot code
139
include "boot/bootcode.inc"    ; 16 bit system boot code
140
include "bus/pci/pci16.inc"
140
include "bus/pci/pci16.inc"
141
include "detect/biosdisk.inc"
141
include "detect/biosdisk.inc"
142
 
142
 
143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144
;;                                                                      ;;
144
;;                                                                      ;;
145
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
145
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
146
;;                                                                      ;;
146
;;                                                                      ;;
147
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
148
 
148
 
149
 
149
 
150
; CR0 Flags - Protected mode and Paging
150
; CR0 Flags - Protected mode and Paging
151
 
151
 
152
        mov ecx, CR0_PE
152
        mov ecx, CR0_PE
153
 
153
 
154
; Enabling 32 bit protected mode
154
; Enabling 32 bit protected mode
155
 
155
 
156
        sidt    [cs:old_ints_h]
156
        sidt    [cs:old_ints_h]
157
 
157
 
158
        cli                             ; disable all irqs
158
        cli                             ; disable all irqs
159
        cld
159
        cld
160
        mov     al,255                  ; mask all irqs
160
        mov     al,255                  ; mask all irqs
161
        out     0xa1,al
161
        out     0xa1,al
162
        out     0x21,al
162
        out     0x21,al
163
   l.5: in      al, 0x64                ; Enable A20
163
   l.5: in      al, 0x64                ; Enable A20
164
        test    al, 2
164
        test    al, 2
165
        jnz     l.5
165
        jnz     l.5
166
        mov     al, 0xD1
166
        mov     al, 0xD1
167
        out     0x64, al
167
        out     0x64, al
168
   l.6: in      al, 0x64
168
   l.6: in      al, 0x64
169
        test    al, 2
169
        test    al, 2
170
        jnz     l.6
170
        jnz     l.6
171
        mov     al, 0xDF
171
        mov     al, 0xDF
172
        out     0x60, al
172
        out     0x60, al
173
   l.7: in      al, 0x64
173
   l.7: in      al, 0x64
174
        test    al, 2
174
        test    al, 2
175
        jnz     l.7
175
        jnz     l.7
176
        mov     al, 0xFF
176
        mov     al, 0xFF
177
        out     0x64, al
177
        out     0x64, al
178
 
178
 
179
        lgdt    [cs:tmp_gdt]            ; Load GDT
179
        lgdt    [cs:tmp_gdt]            ; Load GDT
180
        mov     eax, cr0                ; protected mode
180
        mov     eax, cr0                ; protected mode
181
        or      eax, ecx
181
        or      eax, ecx
182
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
182
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
183
        mov     cr0, eax
183
        mov     cr0, eax
184
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
184
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
185
 
185
 
186
align 8
186
align 8
187
tmp_gdt:
187
tmp_gdt:
188
 
188
 
189
        dw     23
189
        dw     23
190
        dd     tmp_gdt+0x10000
190
        dd     tmp_gdt+0x10000
191
        dw     0
191
        dw     0
192
 
192
 
193
        dw     0xffff
193
        dw     0xffff
194
        dw     0x0000
194
        dw     0x0000
195
        db     0x00
195
        db     0x00
196
        dw     11011111b *256 +10011010b
196
        dw     11011111b *256 +10011010b
197
        db     0x00
197
        db     0x00
198
 
198
 
199
        dw     0xffff
199
        dw     0xffff
200
        dw     0x0000
200
        dw     0x0000
201
        db     0x00
201
        db     0x00
202
        dw     11011111b *256 +10010010b
202
        dw     11011111b *256 +10010010b
203
        db     0x00
203
        db     0x00
204
 
204
 
205
include "data16.inc"
205
include "data16.inc"
206
 
206
 
207
use32
207
use32
208
org $+0x10000
208
org $+0x10000
209
 
209
 
210
align 4
210
align 4
211
B32:
211
B32:
212
           mov   ax,os_stack       ; Selector for os
212
           mov   ax,os_stack       ; Selector for os
213
           mov   ds,ax
213
           mov   ds,ax
214
           mov   es,ax
214
           mov   es,ax
215
           mov   fs,ax
215
           mov   fs,ax
216
           mov   gs,ax
216
           mov   gs,ax
217
           mov   ss,ax
217
           mov   ss,ax
218
           mov   esp,0x3ec00       ; Set stack
218
           mov   esp,0x3ec00       ; Set stack
219
 
219
 
220
; CLEAR 0x280000 - HEAP_BASE
220
; CLEAR 0x280000 - HEAP_BASE
221
 
221
 
222
           xor   eax,eax
222
           xor   eax,eax
223
           mov   edi,0x280000
223
           mov   edi,0x280000
224
           mov   ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
224
           mov   ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
225
           cld
225
           cld
226
           rep   stosd
226
           rep   stosd
227
 
227
 
228
           mov   edi,0x40000
228
           mov   edi,0x40000
229
           mov   ecx,(0x90000-0x40000)/4
229
           mov   ecx,(0x90000-0x40000)/4
230
           rep   stosd
230
           rep   stosd
231
 
231
 
232
; CLEAR KERNEL UNDEFINED GLOBALS
232
; CLEAR KERNEL UNDEFINED GLOBALS
233
           mov   edi, endofcode-OS_BASE
233
           mov   edi, endofcode-OS_BASE
234
           mov   ecx, (uglobals_size/4)+4
234
           mov   ecx, (uglobals_size/4)+4
235
           rep   stosd
235
           rep   stosd
236
 
236
 
237
; SAVE & CLEAR 0-0xffff
237
; SAVE & CLEAR 0-0xffff
238
 
238
 
239
           xor   esi, esi
239
           xor   esi, esi
240
           mov   edi,0x2F0000
240
           mov   edi,0x2F0000
241
           mov   ecx,0x10000 / 4
241
           mov   ecx,0x10000 / 4
242
           rep   movsd
242
           rep   movsd
243
           mov   edi,0x1000
243
           mov   edi,0x1000
244
           mov   ecx,0xf000 / 4
244
           mov   ecx,0xf000 / 4
245
           rep   stosd
245
           rep   stosd
246
 
246
 
247
           call test_cpu
247
           call test_cpu
248
           bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
248
           bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
249
 
249
 
250
           call init_BIOS32
250
           call init_BIOS32
251
; MEMORY MODEL
251
; MEMORY MODEL
252
           call mem_test
252
           call mem_test
253
           call init_mem
253
           call init_mem
254
           call init_page_map
254
           call init_page_map
255
 
255
 
256
; ENABLE PAGING
256
; ENABLE PAGING
257
 
257
 
258
           mov eax, sys_pgdir-OS_BASE
258
           mov eax, sys_pgdir-OS_BASE
259
           mov cr3, eax
259
           mov cr3, eax
260
 
260
 
261
           mov eax,cr0
261
           mov eax,cr0
262
           or eax,CR0_PG+CR0_WP
262
           or eax,CR0_PG+CR0_WP
263
           mov cr0,eax
263
           mov cr0,eax
264
 
264
 
265
           lgdt [gdts]
265
           lgdt [gdts]
266
           jmp pword os_code:high_code
266
           jmp pword os_code:high_code
267
 
267
 
268
align 4
268
align 4
269
bios32_entry    dd ?
269
bios32_entry    dd ?
270
tmp_page_tabs   dd ?
270
tmp_page_tabs   dd ?
271
 
271
 
272
use16
272
use16
273
org $-0x10000
273
org $-0x10000
274
include "boot/shutdown.inc" ; shutdown or restart
274
include "boot/shutdown.inc" ; shutdown or restart
275
org $+0x10000
275
org $+0x10000
276
use32
276
use32
277
 
277
 
278
__DEBUG__ fix 1
278
__DEBUG__ fix 1
279
__DEBUG_LEVEL__ fix 1
279
__DEBUG_LEVEL__ fix 1
280
include 'init.inc'
280
include 'init.inc'
281
 
281
 
282
org OS_BASE+$
282
org OS_BASE+$
283
 
283
 
284
align 4
284
align 4
285
high_code:
285
high_code:
286
           mov ax, os_stack
286
           mov ax, os_stack
287
           mov bx, app_data
287
           mov bx, app_data
288
           mov cx, app_tls
288
           mov cx, app_tls
289
           mov ss, ax
289
           mov ss, ax
290
           add esp, OS_BASE
290
           add esp, OS_BASE
291
 
291
 
292
           mov ds, bx
292
           mov ds, bx
293
           mov es, bx
293
           mov es, bx
294
           mov fs, cx
294
           mov fs, cx
295
           mov gs, bx
295
           mov gs, bx
296
 
296
 
297
           bt [cpu_caps], CAPS_PGE
297
           bt [cpu_caps], CAPS_PGE
298
           jnc @F
298
           jnc @F
299
 
299
 
300
           or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
300
           or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
301
 
301
 
302
           mov ebx, cr4
302
           mov ebx, cr4
303
           or ebx, CR4_PGE
303
           or ebx, CR4_PGE
304
           mov cr4, ebx
304
           mov cr4, ebx
305
@@:
305
@@:
306
           xor eax, eax
306
           xor eax, eax
307
           mov dword [sys_pgdir], eax
307
           mov dword [sys_pgdir], eax
308
           mov dword [sys_pgdir+4], eax
308
           mov dword [sys_pgdir+4], eax
309
 
309
 
310
           mov eax, cr3
310
           mov eax, cr3
311
           mov cr3, eax           ; flush TLB
311
           mov cr3, eax           ; flush TLB
312
 
312
 
313
; SAVE REAL MODE VARIABLES
313
; SAVE REAL MODE VARIABLES
314
        mov     ax, [BOOT_VAR + 0x9031]
314
        mov     ax, [BOOT_VAR + 0x9031]
315
        mov     [IDEContrRegsBaseAddr], ax
315
        mov     [IDEContrRegsBaseAddr], ax
316
; --------------- APM ---------------------
316
; --------------- APM ---------------------
317
 
317
 
318
; init selectors
318
; init selectors
319
    mov ebx,[BOOT_VAR+0x9040]			; offset of APM entry point
319
    mov ebx,[BOOT_VAR+0x9040]			; offset of APM entry point
320
    movzx eax,word [BOOT_VAR+0x9050] 	; real-mode segment base address of
320
    movzx eax,word [BOOT_VAR+0x9050] 	; real-mode segment base address of
321
										; protected-mode 32-bit code segment
321
										; protected-mode 32-bit code segment
322
    movzx ecx,word [BOOT_VAR+0x9052] 	; real-mode segment base address of
322
    movzx ecx,word [BOOT_VAR+0x9052] 	; real-mode segment base address of
323
										; protected-mode 16-bit code segment
323
										; protected-mode 16-bit code segment
324
    movzx edx,word [BOOT_VAR+0x9054] 	; real-mode segment base address of
324
    movzx edx,word [BOOT_VAR+0x9054] 	; real-mode segment base address of
325
										; protected-mode 16-bit data segment
325
										; protected-mode 16-bit data segment
326
 
326
 
327
    shl    eax, 4
327
    shl    eax, 4
328
    mov    [dword apm_code_32 + 2], ax
328
    mov    [dword apm_code_32 + 2], ax
329
    shr    eax, 16
329
    shr    eax, 16
330
    mov    [dword apm_code_32 + 4], al
330
    mov    [dword apm_code_32 + 4], al
331
 
331
 
332
    shl    ecx, 4
332
    shl    ecx, 4
333
    mov    [dword apm_code_16 + 2], cx
333
    mov    [dword apm_code_16 + 2], cx
334
    shr    ecx, 16
334
    shr    ecx, 16
335
    mov    [dword apm_code_16 + 4], cl
335
    mov    [dword apm_code_16 + 4], cl
336
 
336
 
337
    shl    edx, 4
337
    shl    edx, 4
338
    mov    [dword apm_data_16 + 2], dx
338
    mov    [dword apm_data_16 + 2], dx
339
    shr    edx, 16
339
    shr    edx, 16
340
    mov    [dword apm_data_16 + 4], dl
340
    mov    [dword apm_data_16 + 4], dl
341
 
341
 
342
    mov    dword[apm_entry], ebx
342
    mov    dword[apm_entry], ebx
343
    mov    word [apm_entry + 4], apm_code_32 - gdts
343
    mov    word [apm_entry + 4], apm_code_32 - gdts
344
 
344
 
345
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
345
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
346
    mov    [apm_vf], eax
346
    mov    [apm_vf], eax
347
; -----------------------------------------
347
; -----------------------------------------
348
;        movzx eax,byte [BOOT_VAR+0x9010]	; mouse port
348
;        movzx eax,byte [BOOT_VAR+0x9010]	; mouse port
349
;        mov   [0xF604],byte 1  ;al
349
;        mov   [0xF604],byte 1  ;al
350
		mov	al, [BOOT_VAR+0x901F]   	; DMA access
350
		mov	al, [BOOT_VAR+0x901F]   	; DMA access
351
        mov	[allow_dma_access], al
351
        mov	[allow_dma_access], al
352
        movzx eax, byte [BOOT_VAR+0x9000]        ; bpp
352
        movzx eax, byte [BOOT_VAR+0x9000]        ; bpp
353
        mov [ScreenBPP],al
353
        mov [ScreenBPP],al
354
 
354
 
355
        mov [_display.bpp], eax
355
        mov [_display.bpp], eax
356
        mov [_display.vrefresh], 60
356
        mov [_display.vrefresh], 60
357
        mov [_display.disable_mouse],  __sys_disable_mouse
357
        mov [_display.disable_mouse],  __sys_disable_mouse
358
 
358
 
359
        movzx eax,word [BOOT_VAR+0x900A]  ; X max
359
        movzx eax,word [BOOT_VAR+0x900A]  ; X max
360
        mov [_display.width], eax
360
        mov [_display.width], eax
361
        dec   eax
361
        dec   eax
362
        mov   [Screen_Max_X],eax
362
        mov   [Screen_Max_X],eax
363
        mov   [screen_workarea.right],eax
363
        mov   [screen_workarea.right],eax
364
        movzx eax,word [BOOT_VAR+0x900C]  ; Y max
364
        movzx eax,word [BOOT_VAR+0x900C]  ; Y max
365
        mov [_display.height], eax
365
        mov [_display.height], eax
366
        dec   eax
366
        dec   eax
367
        mov   [Screen_Max_Y],eax
367
        mov   [Screen_Max_Y],eax
368
        mov   [screen_workarea.bottom],eax
368
        mov   [screen_workarea.bottom],eax
369
        movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
369
        movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
370
        mov   [SCR_MODE],eax
370
        mov   [SCR_MODE],eax
371
        mov   eax,[BOOT_VAR+0x9014]       ; Vesa 1.2 bnk sw add
371
        mov   eax,[BOOT_VAR+0x9014]       ; Vesa 1.2 bnk sw add
372
        mov   [BANK_SWITCH],eax
372
        mov   [BANK_SWITCH],eax
373
        mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
373
        mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
374
        cmp   [SCR_MODE],word 0x13          ; 320x200
374
        cmp   [SCR_MODE],word 0x13          ; 320x200
375
        je    @f
375
        je    @f
376
        cmp   [SCR_MODE],word 0x12          ; VGA 640x480
376
        cmp   [SCR_MODE],word 0x12          ; VGA 640x480
377
        je    @f
377
        je    @f
378
        movzx eax, word[BOOT_VAR+0x9001]        ; for other modes
378
        movzx eax, word[BOOT_VAR+0x9001]        ; for other modes
379
        mov   [BytesPerScanLine],ax
379
        mov   [BytesPerScanLine],ax
380
        mov [_display.pitch], eax
380
        mov [_display.pitch], eax
381
@@:
381
@@:
382
        mov eax, [_display.width]
382
        mov eax, [_display.width]
383
        mul [_display.height]
383
        mul [_display.height]
384
        mov [_WinMapSize], eax
384
        mov [_WinMapSize], eax
385
 
385
 
386
        mov     esi, BOOT_VAR+0x9080
386
        mov     esi, BOOT_VAR+0x9080
387
        movzx   ecx, byte [esi-1]
387
        movzx   ecx, byte [esi-1]
388
        mov     [NumBiosDisks], ecx
388
        mov     [NumBiosDisks], ecx
389
        mov     edi, BiosDisksData
389
        mov     edi, BiosDisksData
390
        rep     movsd
390
        rep     movsd
391
 
391
 
392
; GRAPHICS ADDRESSES
392
; GRAPHICS ADDRESSES
393
 
393
 
394
        and     byte [BOOT_VAR+0x901e],0x0
394
        and     byte [BOOT_VAR+0x901e],0x0
395
        mov     eax,[BOOT_VAR+0x9018]
395
        mov     eax,[BOOT_VAR+0x9018]
396
        mov     [LFBAddress],eax
396
        mov     [LFBAddress],eax
397
 
397
 
398
        cmp     [SCR_MODE],word 0100000000000000b
398
        cmp     [SCR_MODE],word 0100000000000000b
399
        jge     setvesa20
399
        jge     setvesa20
400
        cmp     [SCR_MODE],word 0x13
400
        cmp     [SCR_MODE],word 0x13
401
        je      v20ga32
401
        je      v20ga32
402
        mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
402
        mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
403
        mov     [GETPIXEL],dword Vesa12_getpixel24
403
        mov     [GETPIXEL],dword Vesa12_getpixel24
404
        cmp     [ScreenBPP],byte 24
404
        cmp     [ScreenBPP],byte 24
405
        jz      ga24
405
        jz      ga24
406
        mov     [PUTPIXEL],dword Vesa12_putpixel32
406
        mov     [PUTPIXEL],dword Vesa12_putpixel32
407
        mov     [GETPIXEL],dword Vesa12_getpixel32
407
        mov     [GETPIXEL],dword Vesa12_getpixel32
408
      ga24:
408
      ga24:
409
        jmp     v20ga24
409
        jmp     v20ga24
410
      setvesa20:
410
      setvesa20:
411
        mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
411
        mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
412
        mov     [GETPIXEL],dword Vesa20_getpixel24
412
        mov     [GETPIXEL],dword Vesa20_getpixel24
413
        cmp     [ScreenBPP],byte 24
413
        cmp     [ScreenBPP],byte 24
414
        jz      v20ga24
414
        jz      v20ga24
415
      v20ga32:
415
      v20ga32:
416
        mov     [PUTPIXEL],dword Vesa20_putpixel32
416
        mov     [PUTPIXEL],dword Vesa20_putpixel32
417
        mov     [GETPIXEL],dword Vesa20_getpixel32
417
        mov     [GETPIXEL],dword Vesa20_getpixel32
418
      v20ga24:
418
      v20ga24:
419
        cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
419
        cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
420
        jne     no_mode_0x12
420
        jne     no_mode_0x12
421
        mov     [PUTPIXEL],dword VGA_putpixel
421
        mov     [PUTPIXEL],dword VGA_putpixel
422
        mov     [GETPIXEL],dword Vesa20_getpixel32
422
        mov     [GETPIXEL],dword Vesa20_getpixel32
423
      no_mode_0x12:
423
      no_mode_0x12:
424
 
424
 
425
; -------- Fast System Call init ----------
425
; -------- Fast System Call init ----------
426
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
426
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
427
           bt [cpu_caps], CAPS_SEP
427
           bt [cpu_caps], CAPS_SEP
428
           jnc .SEnP   ; SysEnter not Present
428
           jnc .SEnP   ; SysEnter not Present
429
           xor edx, edx
429
           xor edx, edx
430
           mov ecx, MSR_SYSENTER_CS
430
           mov ecx, MSR_SYSENTER_CS
431
           mov eax, os_code
431
           mov eax, os_code
432
           wrmsr
432
           wrmsr
433
           mov ecx, MSR_SYSENTER_ESP
433
           mov ecx, MSR_SYSENTER_ESP
434
;           mov eax, sysenter_stack ; Check it
434
;           mov eax, sysenter_stack ; Check it
435
           xor     eax, eax
435
           xor     eax, eax
436
           wrmsr
436
           wrmsr
437
           mov ecx, MSR_SYSENTER_EIP
437
           mov ecx, MSR_SYSENTER_EIP
438
           mov eax, sysenter_entry
438
           mov eax, sysenter_entry
439
           wrmsr
439
           wrmsr
440
.SEnP:
440
.SEnP:
441
; AMD SYSCALL/SYSRET
441
; AMD SYSCALL/SYSRET
442
           cmp byte[cpu_vendor], 'A'
442
           cmp byte[cpu_vendor], 'A'
443
           jne .noSYSCALL
443
           jne .noSYSCALL
444
           mov eax, 0x80000001
444
           mov eax, 0x80000001
445
           cpuid
445
           cpuid
446
           test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
446
           test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
447
           jz .noSYSCALL
447
           jz .noSYSCALL
448
           mov ecx, MSR_AMD_EFER
448
           mov ecx, MSR_AMD_EFER
449
           rdmsr
449
           rdmsr
450
           or eax, 1   ; bit_0 - System Call Extension (SCE)
450
           or eax, 1   ; bit_0 - System Call Extension (SCE)
451
           wrmsr
451
           wrmsr
452
 
452
 
453
        ; !!!! It`s dirty hack, fix it !!!
453
        ; !!!! It`s dirty hack, fix it !!!
454
        ; Bits of EDX :
454
        ; Bits of EDX :
455
        ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
455
        ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
456
        ;  and the contents of this field, plus 8, are copied into the SS register.
456
        ;  and the contents of this field, plus 8, are copied into the SS register.
457
        ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
457
        ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
458
        ;  and the contents of this field, plus 8, are copied into the SS register.
458
        ;  and the contents of this field, plus 8, are copied into the SS register.
459
 
459
 
460
        ; mov   edx, (os_code + 16) * 65536 + os_code
460
        ; mov   edx, (os_code + 16) * 65536 + os_code
461
           mov edx, 0x1B0008
461
           mov edx, 0x1B0008
462
 
462
 
463
           mov eax, syscall_entry
463
           mov eax, syscall_entry
464
           mov ecx, MSR_AMD_STAR
464
           mov ecx, MSR_AMD_STAR
465
           wrmsr
465
           wrmsr
466
.noSYSCALL:
466
.noSYSCALL:
467
; -----------------------------------------
467
; -----------------------------------------
468
        stdcall alloc_page
468
        stdcall alloc_page
469
        stdcall map_page, tss-0xF80, eax, PG_SW
469
        stdcall map_page, tss-0xF80, eax, PG_SW
470
        stdcall alloc_page
470
        stdcall alloc_page
471
        inc     eax
471
        inc     eax
472
        mov     [SLOT_BASE+256+APPDATA.io_map], eax
472
        mov     [SLOT_BASE+256+APPDATA.io_map], eax
473
        stdcall map_page, tss+0x80, eax, PG_SW
473
        stdcall map_page, tss+0x80, eax, PG_SW
474
        stdcall alloc_page
474
        stdcall alloc_page
475
        inc     eax
475
        inc     eax
476
        mov     dword [SLOT_BASE+256+APPDATA.io_map+4], eax
476
        mov     dword [SLOT_BASE+256+APPDATA.io_map+4], eax
477
        stdcall map_page, tss+0x1080, eax, PG_SW
477
        stdcall map_page, tss+0x1080, eax, PG_SW
478
 
478
 
479
; LOAD IDT
479
; LOAD IDT
480
 
480
 
481
           call build_interrupt_table ;lidt is executed
481
           call build_interrupt_table ;lidt is executed
482
          ;lidt [idtreg]
482
          ;lidt [idtreg]
483
 
483
 
484
           call init_kernel_heap
484
           call init_kernel_heap
485
           stdcall kernel_alloc, RING0_STACK_SIZE+512
485
           stdcall kernel_alloc, RING0_STACK_SIZE+512
486
           mov [os_stack_seg], eax
486
           mov [os_stack_seg], eax
487
 
487
 
488
           lea esp, [eax+RING0_STACK_SIZE]
488
           lea esp, [eax+RING0_STACK_SIZE]
489
 
489
 
490
           mov [tss._ss0], os_stack
490
           mov [tss._ss0], os_stack
491
           mov [tss._esp0], esp
491
           mov [tss._esp0], esp
492
           mov [tss._esp], esp
492
           mov [tss._esp], esp
493
           mov [tss._cs],os_code
493
           mov [tss._cs],os_code
494
           mov [tss._ss],os_stack
494
           mov [tss._ss],os_stack
495
           mov [tss._ds],app_data
495
           mov [tss._ds],app_data
496
           mov [tss._es],app_data
496
           mov [tss._es],app_data
497
           mov [tss._fs],app_data
497
           mov [tss._fs],app_data
498
           mov [tss._gs],app_data
498
           mov [tss._gs],app_data
499
           mov [tss._io],128
499
           mov [tss._io],128
500
;Add IO access table - bit array of permitted ports
500
;Add IO access table - bit array of permitted ports
501
           mov edi, tss._io_map_0
501
           mov edi, tss._io_map_0
502
           xor eax, eax
502
           xor eax, eax
503
           not eax
503
           not eax
504
           mov ecx, 8192/4
504
           mov ecx, 8192/4
505
           rep stosd                 ; access to 4096*8=65536 ports
505
           rep stosd                 ; access to 4096*8=65536 ports
506
 
506
 
507
           mov  ax,tss0
507
           mov  ax,tss0
508
           ltr  ax
508
           ltr  ax
509
 
509
 
510
           mov [LFBSize], 0x800000
510
           mov [LFBSize], 0x800000
511
           call init_LFB
511
           call init_LFB
512
           call init_fpu
512
           call init_fpu
513
           call init_malloc
513
           call init_malloc
514
 
514
 
515
           stdcall alloc_kernel_space, 0x51000
515
           stdcall alloc_kernel_space, 0x51000
516
           mov [default_io_map], eax
516
           mov [default_io_map], eax
517
 
517
 
518
           add eax, 0x2000
518
           add eax, 0x2000
519
           mov [ipc_tmp], eax
519
           mov [ipc_tmp], eax
520
           mov ebx, 0x1000
520
           mov ebx, 0x1000
521
 
521
 
522
           add eax, 0x40000
522
           add eax, 0x40000
523
           mov [proc_mem_map], eax
523
           mov [proc_mem_map], eax
524
 
524
 
525
           add eax, 0x8000
525
           add eax, 0x8000
526
           mov [proc_mem_pdir], eax
526
           mov [proc_mem_pdir], eax
527
 
527
 
528
           add eax, ebx
528
           add eax, ebx
529
           mov [proc_mem_tab], eax
529
           mov [proc_mem_tab], eax
530
 
530
 
531
           add eax, ebx
531
           add eax, ebx
532
           mov [tmp_task_pdir], eax
532
           mov [tmp_task_pdir], eax
533
 
533
 
534
           add eax, ebx
534
           add eax, ebx
535
           mov [tmp_task_ptab], eax
535
           mov [tmp_task_ptab], eax
536
 
536
 
537
           add eax, ebx
537
           add eax, ebx
538
           mov [ipc_pdir], eax
538
           mov [ipc_pdir], eax
539
 
539
 
540
           add eax, ebx
540
           add eax, ebx
541
           mov [ipc_ptab], eax
541
           mov [ipc_ptab], eax
542
 
542
 
543
           stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
543
           stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
544
                                 (unpack.lc+unpack.lp)))*4
544
                                 (unpack.lc+unpack.lp)))*4
545
 
545
 
546
           mov [unpack.p], eax
546
           mov [unpack.p], eax
547
 
547
 
548
           call init_events
548
           call init_events
549
           mov eax, srv.fd-SRV_FD_OFFSET
549
           mov eax, srv.fd-SRV_FD_OFFSET
550
           mov [srv.fd], eax
550
           mov [srv.fd], eax
551
           mov [srv.bk], eax
551
           mov [srv.bk], eax
552
 
552
 
553
           mov edi, irq_tab
553
           mov edi, irq_tab
554
           xor eax, eax
554
           xor eax, eax
555
           mov ecx, 16
555
           mov ecx, 16
556
           rep stosd
556
           rep stosd
557
 
557
 
558
;Set base of graphic segment to linear address of LFB
558
;Set base of graphic segment to linear address of LFB
559
        mov     eax,[LFBAddress]          ; set for gs
559
        mov     eax,[LFBAddress]          ; set for gs
560
        mov     [graph_data_l+2],ax
560
        mov     [graph_data_l+2],ax
561
        shr     eax,16
561
        shr     eax,16
562
        mov     [graph_data_l+4],al
562
        mov     [graph_data_l+4],al
563
        mov     [graph_data_l+7],ah
563
        mov     [graph_data_l+7],ah
564
 
564
 
565
        stdcall kernel_alloc, [_WinMapSize]
565
        stdcall kernel_alloc, [_WinMapSize]
566
        mov [_WinMapAddress], eax
566
        mov [_WinMapAddress], eax
567
 
567
 
568
        xor  eax,eax
568
        xor  eax,eax
569
        inc  eax
569
        inc  eax
570
        mov [CURRENT_TASK],eax		;dword 1
570
        mov [CURRENT_TASK],eax		;dword 1
571
        mov [TASK_COUNT],eax		;dword 1
571
        mov [TASK_COUNT],eax		;dword 1
572
        mov [TASK_BASE],dword TASK_DATA
572
        mov [TASK_BASE],dword TASK_DATA
573
        mov [current_slot], SLOT_BASE+256
573
        mov [current_slot], SLOT_BASE+256
574
 
574
 
575
; set background
575
; set background
576
 
576
 
577
        mov   [BgrDrawMode],eax
577
        mov   [BgrDrawMode],eax
578
        mov   [BgrDataWidth],eax
578
        mov   [BgrDataWidth],eax
579
        mov   [BgrDataHeight],eax
579
        mov   [BgrDataHeight],eax
580
        mov    [mem_BACKGROUND], 4
580
        mov    [mem_BACKGROUND], 4
581
        mov [img_background], static_background_data
581
        mov [img_background], static_background_data
582
 
582
 
583
        mov     [SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE
583
        mov     [SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE
584
 
584
 
585
        stdcall kernel_alloc, 0x10000/8
585
        stdcall kernel_alloc, 0x10000/8
586
        mov     edi, eax
586
        mov     edi, eax
587
        mov     [network_free_ports], eax
587
        mov     [network_free_ports], eax
588
        or      eax, -1
588
        or      eax, -1
589
        mov     ecx, 0x10000/32
589
        mov     ecx, 0x10000/32
590
        rep     stosd
590
        rep     stosd
591
 
591
 
592
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
592
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
593
 
593
 
594
        call  rerouteirqs
594
        call  rerouteirqs
595
 
595
 
596
; Initialize system V86 machine
596
; Initialize system V86 machine
597
        call    init_sys_v86
597
        call    init_sys_v86
598
 
598
 
599
; TIMER SET TO 1/100 S
599
; TIMER SET TO 1/100 S
600
 
600
 
601
        mov   al,0x34              ; set to 100Hz
601
        mov   al,0x34              ; set to 100Hz
602
        out   0x43,al
602
        out   0x43,al
603
        mov   al,0x9b              ; lsb    1193180 / 1193
603
        mov   al,0x9b              ; lsb    1193180 / 1193
604
        out   0x40,al
604
        out   0x40,al
605
        mov   al,0x2e              ; msb
605
        mov   al,0x2e              ; msb
606
        out   0x40,al
606
        out   0x40,al
607
 
607
 
608
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
608
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
609
; they are used: when partitions are scanned, hd_read relies on timer
609
; they are used: when partitions are scanned, hd_read relies on timer
610
; Also enable IRQ2, because in some configurations
610
; Also enable IRQ2, because in some configurations
611
; IRQs from slave controller are not delivered until IRQ2 on master is enabled
611
; IRQs from slave controller are not delivered until IRQ2 on master is enabled
612
        mov     al, 0xFA
612
        mov     al, 0xFA
613
        out     0x21, al
613
        out     0x21, al
614
        mov     al, 0x3F
614
        mov     al, 0x3F
615
        out     0xA1, al
615
        out     0xA1, al
616
 
616
 
617
;!!!!!!!!!!!!!!!!!!!!!!!!!!
617
;!!!!!!!!!!!!!!!!!!!!!!!!!!
618
include 'detect/disks.inc'
618
include 'detect/disks.inc'
619
;!!!!!!!!!!!!!!!!!!!!!!!!!!
619
;!!!!!!!!!!!!!!!!!!!!!!!!!!
620
 
620
 
621
  call Parser_params
621
  call Parser_params
622
 
622
 
623
; READ RAMDISK IMAGE FROM HD
623
; READ RAMDISK IMAGE FROM HD
624
 
624
 
625
;!!!!!!!!!!!!!!!!!!!!!!!
625
;!!!!!!!!!!!!!!!!!!!!!!!
626
include 'boot/rdload.inc'
626
include 'boot/rdload.inc'
627
;!!!!!!!!!!!!!!!!!!!!!!!
627
;!!!!!!!!!!!!!!!!!!!!!!!
628
;    mov    [dma_hdd],1
628
;    mov    [dma_hdd],1
629
; CALCULATE FAT CHAIN FOR RAMDISK
629
; CALCULATE FAT CHAIN FOR RAMDISK
630
 
630
 
631
        call  calculatefatchain
631
        call  calculatefatchain
632
 
632
 
633
; LOAD VMODE DRIVER
633
; LOAD VMODE DRIVER
634
 
634
 
635
;!!!!!!!!!!!!!!!!!!!!!!!
635
;!!!!!!!!!!!!!!!!!!!!!!!
636
include 'vmodeld.inc'
636
include 'vmodeld.inc'
637
;!!!!!!!!!!!!!!!!!!!!!!!
637
;!!!!!!!!!!!!!!!!!!!!!!!
638
 
638
 
639
if 0
639
if 0
640
  mov ax,[OS_BASE+0x10000+bx_from_load]
640
  mov ax,[OS_BASE+0x10000+bx_from_load]
641
  cmp ax,'r1'           ; if using not ram disk, then load librares and parameters {SPraid.simba}
641
  cmp ax,'r1'           ; if using not ram disk, then load librares and parameters {SPraid.simba}
642
  je  no_lib_load
642
  je  no_lib_load
643
; LOADING LIBRARES
643
; LOADING LIBRARES
644
   stdcall dll.Load,@IMPORT                 ; loading librares for kernel (.obj files)
644
   stdcall dll.Load,@IMPORT                 ; loading librares for kernel (.obj files)
645
   call load_file_parse_table               ; prepare file parse table
645
   call load_file_parse_table               ; prepare file parse table
646
   call set_kernel_conf                     ; configure devices and gui
646
   call set_kernel_conf                     ; configure devices and gui
647
no_lib_load:
647
no_lib_load:
648
end if
648
end if
649
 
649
 
650
; LOAD FONTS I and II
650
; LOAD FONTS I and II
651
 
651
 
652
        stdcall read_file, char, FONT_I, 0, 2304
652
        stdcall read_file, char, FONT_I, 0, 2304
653
        stdcall read_file, char2, FONT_II, 0, 2560
653
        stdcall read_file, char2, FONT_II, 0, 2560
654
 
654
 
655
        mov   esi,boot_fonts
655
        mov   esi,boot_fonts
656
        call  boot_log
656
        call  boot_log
657
 
657
 
658
; PRINT AMOUNT OF MEMORY
658
; PRINT AMOUNT OF MEMORY
659
        mov     esi, boot_memdetect
659
        mov     esi, boot_memdetect
660
        call    boot_log
660
        call    boot_log
661
 
661
 
662
        movzx   ecx, word [boot_y]
662
        movzx   ecx, word [boot_y]
663
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
663
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
664
        sub     ecx, 10
664
        sub     ecx, 10
665
        mov     edx, 0xFFFFFF
665
        mov     edx, 0xFFFFFF
666
        mov     ebx, [MEM_AMOUNT]
666
        mov     ebx, [MEM_AMOUNT]
667
        shr     ebx, 20
667
        shr     ebx, 20
668
        xor     edi,edi
668
        xor     edi,edi
669
        mov     eax, 0x00040000
669
        mov     eax, 0x00040000
670
		inc		edi
670
		inc		edi
671
        call    display_number_force
671
        call    display_number_force
672
 
672
 
673
; BUILD SCHEDULER
673
; BUILD SCHEDULER
674
 
674
 
675
        call   build_scheduler ; sys32.inc
675
        call   build_scheduler ; sys32.inc
676
 
676
 
677
        mov    esi,boot_devices
677
        mov    esi,boot_devices
678
        call   boot_log
678
        call   boot_log
679
 
679
 
680
        mov  [pci_access_enabled],1
680
        mov  [pci_access_enabled],1
681
 
681
 
682
 
682
 
683
; SET PRELIMINARY WINDOW STACK AND POSITIONS
683
; SET PRELIMINARY WINDOW STACK AND POSITIONS
684
 
684
 
685
        mov   esi,boot_windefs
685
        mov   esi,boot_windefs
686
        call  boot_log
686
        call  boot_log
687
        call  setwindowdefaults
687
        call  setwindowdefaults
688
 
688
 
689
; SET BACKGROUND DEFAULTS
689
; SET BACKGROUND DEFAULTS
690
 
690
 
691
        mov   esi,boot_bgr
691
        mov   esi,boot_bgr
692
        call  boot_log
692
        call  boot_log
693
        call  init_background
693
        call  init_background
694
        call  calculatebackground
694
        call  calculatebackground
695
 
695
 
696
; RESERVE SYSTEM IRQ'S JA PORT'S
696
; RESERVE SYSTEM IRQ'S JA PORT'S
697
 
697
 
698
        mov   esi,boot_resirqports
698
        mov   esi,boot_resirqports
699
        call  boot_log
699
        call  boot_log
700
        call  reserve_irqs_ports
700
        call  reserve_irqs_ports
701
 
701
 
702
; SET PORTS FOR IRQ HANDLERS
702
; SET PORTS FOR IRQ HANDLERS
703
 
703
 
704
        mov  esi,boot_setrports
704
        mov  esi,boot_setrports
705
        call boot_log
705
        call boot_log
706
        ;call setirqreadports
706
        ;call setirqreadports
707
 
707
 
708
; SET UP OS TASK
708
; SET UP OS TASK
709
 
709
 
710
        mov  esi,boot_setostask
710
        mov  esi,boot_setostask
711
        call boot_log
711
        call boot_log
712
 
712
 
713
        xor  eax, eax
713
        xor  eax, eax
714
        mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
714
        mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
715
        mov  dword [SLOT_BASE+APPDATA.exc_handler], eax
715
        mov  dword [SLOT_BASE+APPDATA.exc_handler], eax
716
        mov  dword [SLOT_BASE+APPDATA.except_mask], eax
716
        mov  dword [SLOT_BASE+APPDATA.except_mask], eax
717
 
717
 
718
        ; name for OS/IDLE process
718
        ; name for OS/IDLE process
719
 
719
 
720
        mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
720
        mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
721
        mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
721
        mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
722
        mov edi, [os_stack_seg]
722
        mov edi, [os_stack_seg]
723
        mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
723
        mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
724
        add edi, 0x2000-512
724
        add edi, 0x2000-512
725
        mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
725
        mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
726
        mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
726
        mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
727
	; [SLOT_BASE+256+APPDATA.io_map] was set earlier
727
	; [SLOT_BASE+256+APPDATA.io_map] was set earlier
728
 
728
 
729
        mov esi, fpu_data
729
        mov esi, fpu_data
730
        mov ecx, 512/4
730
        mov ecx, 512/4
731
        cld
731
        cld
732
        rep movsd
732
        rep movsd
733
 
733
 
734
        mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax
734
        mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax
735
        mov dword [SLOT_BASE+256+APPDATA.except_mask], eax
735
        mov dword [SLOT_BASE+256+APPDATA.except_mask], eax
736
 
736
 
737
        mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
737
        mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
738
        mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
738
        mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
739
        mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
739
        mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
740
 
740
 
741
        mov  dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
741
        mov  dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
742
        mov dword [SLOT_BASE+256+APPDATA.tls_base], eax
742
        mov dword [SLOT_BASE+256+APPDATA.tls_base], eax
743
 
743
 
744
        ; task list
744
        ; task list
745
        mov  dword [TASK_DATA+TASKDATA.mem_start],eax	; process base address
745
        mov  dword [TASK_DATA+TASKDATA.mem_start],eax	; process base address
746
	inc  eax
746
	inc  eax
747
        mov  dword [CURRENT_TASK],eax
747
        mov  dword [CURRENT_TASK],eax
748
        mov  dword [TASK_COUNT],eax
748
        mov  dword [TASK_COUNT],eax
749
        mov  [current_slot], SLOT_BASE+256
749
        mov  [current_slot], SLOT_BASE+256
750
        mov  [TASK_BASE],dword TASK_DATA
750
        mov  [TASK_BASE],dword TASK_DATA
751
        mov  byte[TASK_DATA+TASKDATA.wnd_number],al	; on screen number
751
        mov  byte[TASK_DATA+TASKDATA.wnd_number],al	; on screen number
752
        mov  dword [TASK_DATA+TASKDATA.pid], eax        ; process id number
752
        mov  dword [TASK_DATA+TASKDATA.pid], eax        ; process id number
753
 
753
 
754
 
754
 
755
        call init_cursors
755
        call init_cursors
756
        mov eax, [def_cursor]
756
        mov eax, [def_cursor]
757
        mov [SLOT_BASE+APPDATA.cursor],eax
757
        mov [SLOT_BASE+APPDATA.cursor],eax
758
        mov [SLOT_BASE+APPDATA.cursor+256],eax
758
        mov [SLOT_BASE+APPDATA.cursor+256],eax
759
 
759
 
760
  ; READ TSC / SECOND
760
  ; READ TSC / SECOND
761
 
761
 
762
        mov   esi,boot_tsc
762
        mov   esi,boot_tsc
763
        call  boot_log
763
        call  boot_log
764
        cli
764
        cli
765
        rdtsc ;call  _rdtsc
765
        rdtsc ;call  _rdtsc
766
        mov   ecx,eax
766
        mov   ecx,eax
767
        mov   esi,250               ; wait 1/4 a second
767
        mov   esi,250               ; wait 1/4 a second
768
        call  delay_ms
768
        call  delay_ms
769
        rdtsc ;call  _rdtsc
769
        rdtsc ;call  _rdtsc
770
        sti
770
        sti
771
        sub   eax,ecx
771
        sub   eax,ecx
772
        shl   eax,2
772
        shl   eax,2
773
        mov   [CPU_FREQ],eax          ; save tsc / sec
773
        mov   [CPU_FREQ],eax          ; save tsc / sec
774
;       mov ebx, 1000000
774
;       mov ebx, 1000000
775
;       div ebx
775
;       div ebx
776
; ¢®®¡é¥-â® ¯à®¨§¢®¤¨â¥«ì­®áâì ¢ ¤ ­­®¬ ª®­ªà¥â­®¬ ¬¥áâ¥
776
; ¢®®¡é¥-â® ¯à®¨§¢®¤¨â¥«ì­®áâì ¢ ¤ ­­®¬ ª®­ªà¥â­®¬ ¬¥áâ¥
777
; ᮢ¥à襭­® ­¥ªà¨â¨ç­ , ­® çâ®¡ë § âª­ãâì «î¡¨â¥«¥©
777
; ᮢ¥à襭­® ­¥ªà¨â¨ç­ , ­® çâ®¡ë § âª­ãâì «î¡¨â¥«¥©
778
; ®¯â¨¬¨§¨àãîé¨å ª®¬¯¨«ïâ®à®¢ Ÿ‚“...
778
; ®¯â¨¬¨§¨àãîé¨å ª®¬¯¨«ïâ®à®¢ Ÿ‚“...
779
        mov     edx, 2251799814
779
        mov     edx, 2251799814
780
        mul     edx
780
        mul     edx
781
        shr     edx, 19
781
        shr     edx, 19
782
        mov [stall_mcs], edx
782
        mov [stall_mcs], edx
783
; PRINT CPU FREQUENCY
783
; PRINT CPU FREQUENCY
784
        mov     esi, boot_cpufreq
784
        mov     esi, boot_cpufreq
785
        call    boot_log
785
        call    boot_log
786
 
786
 
787
        mov     ebx, edx
787
        mov     ebx, edx
788
        movzx   ecx, word [boot_y]
788
        movzx   ecx, word [boot_y]
789
        add     ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is '
789
        add     ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is '
790
        mov     edx, 0xFFFFFF
790
        mov     edx, 0xFFFFFF
791
        xor     edi,edi
791
        xor     edi,edi
792
        mov     eax, 0x00040000
792
        mov     eax, 0x00040000
793
		inc		edi
793
		inc		edi
794
        call    display_number_force
794
        call    display_number_force
795
 
795
 
796
; SET VARIABLES
796
; SET VARIABLES
797
 
797
 
798
        call  set_variables
798
        call  set_variables
799
 
799
 
800
; SET MOUSE
800
; SET MOUSE
801
 
801
 
802
        ;call   detect_devices
802
        ;call   detect_devices
803
        stdcall load_driver, szPS2MDriver
803
        stdcall load_driver, szPS2MDriver
804
;        stdcall load_driver, szCOM_MDriver
804
;        stdcall load_driver, szCOM_MDriver
805
 
805
 
806
        mov   esi,boot_setmouse
806
        mov   esi,boot_setmouse
807
        call  boot_log
807
        call  boot_log
808
        call  setmouse
808
        call  setmouse
809
 
809
 
810
 
810
 
811
; STACK AND FDC
811
; STACK AND FDC
812
 
812
 
813
        call  stack_init
813
        call  stack_init
814
        call  fdc_init
814
        call  fdc_init
815
 
815
 
816
; PALETTE FOR 320x200 and 640x480 16 col
816
; PALETTE FOR 320x200 and 640x480 16 col
817
 
817
 
818
        cmp   [SCR_MODE],word 0x12
818
        cmp   [SCR_MODE],word 0x12
819
        jne   no_pal_vga
819
        jne   no_pal_vga
820
        mov   esi,boot_pal_vga
820
        mov   esi,boot_pal_vga
821
        call  boot_log
821
        call  boot_log
822
        call  paletteVGA
822
        call  paletteVGA
823
      no_pal_vga:
823
      no_pal_vga:
824
 
824
 
825
        cmp   [SCR_MODE],word 0x13
825
        cmp   [SCR_MODE],word 0x13
826
        jne   no_pal_ega
826
        jne   no_pal_ega
827
        mov   esi,boot_pal_ega
827
        mov   esi,boot_pal_ega
828
        call  boot_log
828
        call  boot_log
829
        call  palette320x200
829
        call  palette320x200
830
      no_pal_ega:
830
      no_pal_ega:
831
 
831
 
832
; LOAD DEFAULT SKIN
832
; LOAD DEFAULT SKIN
833
 
833
 
834
        call    load_default_skin
834
        call    load_default_skin
835
 
835
 
836
;protect io permission map
836
;protect io permission map
837
 
837
 
838
           mov esi, [default_io_map]
838
           mov esi, [default_io_map]
839
           stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map], PG_MAP
839
           stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map], PG_MAP
840
           add esi, 0x1000
840
           add esi, 0x1000
841
           stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
841
           stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
842
 
842
 
843
           stdcall map_page,tss._io_map_0,\
843
           stdcall map_page,tss._io_map_0,\
844
                   [SLOT_BASE+256+APPDATA.io_map], PG_MAP
844
                   [SLOT_BASE+256+APPDATA.io_map], PG_MAP
845
           stdcall map_page,tss._io_map_1,\
845
           stdcall map_page,tss._io_map_1,\
846
                   [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
846
                   [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
847
 
847
 
848
  mov ax,[OS_BASE+0x10000+bx_from_load]
848
  mov ax,[OS_BASE+0x10000+bx_from_load]
849
  cmp ax,'r1'           ; if not rused ram disk - load network configuration from files {SPraid.simba}
849
  cmp ax,'r1'           ; if not rused ram disk - load network configuration from files {SPraid.simba}
850
  je  no_st_network
850
  je  no_st_network
851
        call set_network_conf
851
        call set_network_conf
852
  no_st_network:
852
  no_st_network:
853
 
853
 
854
; LOAD FIRST APPLICATION
854
; LOAD FIRST APPLICATION
855
        cli
855
        cli
856
 
856
 
857
        cmp   byte [BOOT_VAR+0x9030],1
857
        cmp   byte [BOOT_VAR+0x9030],1
858
        jne   no_load_vrr_m
858
        jne   no_load_vrr_m
859
 
859
 
860
        mov     ebp, vrr_m
860
        mov     ebp, vrr_m
861
        call    fs_execute_from_sysdir
861
        call    fs_execute_from_sysdir
862
 
862
 
863
;        cmp   eax,2                  ; if vrr_m app found (PID=2)
863
;        cmp   eax,2                  ; if vrr_m app found (PID=2)
864
	sub   eax,2
864
	sub   eax,2
865
        jz    first_app_found
865
        jz    first_app_found
866
 
866
 
867
no_load_vrr_m:
867
no_load_vrr_m:
868
 
868
 
869
        mov     ebp, firstapp
869
        mov     ebp, firstapp
870
        call    fs_execute_from_sysdir
870
        call    fs_execute_from_sysdir
871
 
871
 
872
;        cmp   eax,2                  ; continue if a process has been loaded
872
;        cmp   eax,2                  ; continue if a process has been loaded
873
	sub   eax,2
873
	sub   eax,2
874
        jz    first_app_found
874
        jz    first_app_found
875
 
875
 
876
        mov     esi, boot_failed
876
        mov     esi, boot_failed
877
        call    boot_log
877
        call    boot_log
878
 
878
 
879
        mov   eax, 0xDEADBEEF        ; otherwise halt
879
        mov   eax, 0xDEADBEEF        ; otherwise halt
880
        hlt
880
        hlt
881
 
881
 
882
first_app_found:
882
first_app_found:
883
 
883
 
884
        cli
884
        cli
885
 
885
 
886
        ;mov   [TASK_COUNT],dword 2
886
        ;mov   [TASK_COUNT],dword 2
887
	push  1
887
	push  1
888
        pop   dword [CURRENT_TASK]      ; set OS task fisrt
888
        pop   dword [CURRENT_TASK]      ; set OS task fisrt
889
 
889
 
890
; SET KEYBOARD PARAMETERS
890
; SET KEYBOARD PARAMETERS
891
        mov   al, 0xf6         ; reset keyboard, scan enabled
891
        mov   al, 0xf6         ; reset keyboard, scan enabled
892
        call  kb_write
892
        call  kb_write
893
 
893
 
894
        ; wait until 8042 is ready
894
        ; wait until 8042 is ready
895
        xor ecx,ecx
895
        xor ecx,ecx
896
      @@:
896
      @@:
897
        in     al,64h
897
        in     al,64h
898
        and    al,00000010b
898
        and    al,00000010b
899
        loopnz @b
899
        loopnz @b
900
 
900
 
901
       ; mov   al, 0xED       ; svetodiody - only for testing!
901
       ; mov   al, 0xED       ; svetodiody - only for testing!
902
       ; call  kb_write
902
       ; call  kb_write
903
       ; call  kb_read
903
       ; call  kb_read
904
       ; mov   al, 111b
904
       ; mov   al, 111b
905
       ; call  kb_write
905
       ; call  kb_write
906
       ; call  kb_read
906
       ; call  kb_read
907
 
907
 
908
        mov   al, 0xF3       ; set repeat rate & delay
908
        mov   al, 0xF3       ; set repeat rate & delay
909
        call  kb_write
909
        call  kb_write
910
;        call  kb_read
910
;        call  kb_read
911
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
911
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
912
        call  kb_write
912
        call  kb_write
913
;        call  kb_read
913
;        call  kb_read
914
     ;// mike.dld [
914
     ;// mike.dld [
915
        call  set_lights
915
        call  set_lights
916
     ;// mike.dld ]
916
     ;// mike.dld ]
917
 
917
 
918
 
918
 
919
; Setup serial output console (if enabled)
919
; Setup serial output console (if enabled)
920
 
920
 
921
if defined debug_com_base
921
if defined debug_com_base
922
 
922
 
923
        ; enable Divisor latch
923
        ; enable Divisor latch
924
 
924
 
925
        mov     dx, debug_com_base+3
925
        mov     dx, debug_com_base+3
926
        mov     al, 1 shl 7
926
        mov     al, 1 shl 7
927
        out     dx, al
927
        out     dx, al
928
 
928
 
929
        ; Set speed to 115200 baud (max speed)
929
        ; Set speed to 115200 baud (max speed)
930
 
930
 
931
        mov     dx, debug_com_base
931
        mov     dx, debug_com_base
932
        mov     al, 0x01
932
        mov     al, 0x01
933
        out     dx, al
933
        out     dx, al
934
 
934
 
935
        mov     dx, debug_com_base+1
935
        mov     dx, debug_com_base+1
936
        mov     al, 0x00
936
        mov     al, 0x00
937
        out     dx, al
937
        out     dx, al
938
 
938
 
939
        ; No parity, 8bits words, one stop bit, dlab bit back to 0
939
        ; No parity, 8bits words, one stop bit, dlab bit back to 0
940
 
940
 
941
        mov     dx, debug_com_base+3
941
        mov     dx, debug_com_base+3
942
        mov     al, 3
942
        mov     al, 3
943
        out     dx, al
943
        out     dx, al
944
 
944
 
945
        ; disable interrupts
945
        ; disable interrupts
946
 
946
 
947
        mov     dx, debug_com_base+1
947
        mov     dx, debug_com_base+1
948
        mov     al, 0
948
        mov     al, 0
949
        out     dx, al
949
        out     dx, al
950
 
950
 
951
        ; clear +  enable fifo (64 bits)
951
        ; clear +  enable fifo (64 bits)
952
 
952
 
953
        mov     dx, debug_com_base+2
953
        mov     dx, debug_com_base+2
954
        mov     al, 0x7 + 1 shl 5
954
        mov     al, 0x7 + 1 shl 5
955
        out     dx, al
955
        out     dx, al
956
 
956
 
957
 
957
 
958
end if
958
end if
959
 
959
 
960
; START MULTITASKING
960
; START MULTITASKING
961
 
961
 
962
if preboot_blogesc
962
if preboot_blogesc
963
        mov     esi, boot_tasking
963
        mov     esi, boot_tasking
964
        call    boot_log
964
        call    boot_log
965
.bll1:  in      al, 0x60        ; wait for ESC key press
965
.bll1:  in      al, 0x60        ; wait for ESC key press
966
        cmp     al, 129
966
        cmp     al, 129
967
        jne     .bll1
967
        jne     .bll1
968
end if
968
end if
969
 
969
 
970
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
970
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
971
 
971
 
972
; UNMASK ALL IRQ'S
972
; UNMASK ALL IRQ'S
973
 
973
 
974
        mov   esi,boot_allirqs
974
        mov   esi,boot_allirqs
975
        call  boot_log
975
        call  boot_log
976
 
976
 
977
        cli                          ;guarantee forbidance of interrupts.
977
        cli                          ;guarantee forbidance of interrupts.
978
        mov   al,0                   ; unmask all irq's
978
        mov   al,0                   ; unmask all irq's
979
        out   0xA1,al
979
        out   0xA1,al
980
        out   0x21,al
980
        out   0x21,al
981
 
981
 
982
        mov   ecx,32
982
        mov   ecx,32
983
 
983
 
984
     ready_for_irqs:
984
     ready_for_irqs:
985
 
985
 
986
        mov   al,0x20                ; ready for irqs
986
        mov   al,0x20                ; ready for irqs
987
        out   0x20,al
987
        out   0x20,al
988
        out   0xa0,al
988
        out   0xa0,al
989
 
989
 
990
        loop  ready_for_irqs         ; flush the queue
990
        loop  ready_for_irqs         ; flush the queue
991
 
991
 
992
        stdcall attach_int_handler, dword 1, irq1, dword 0
992
        stdcall attach_int_handler, dword 1, irq1, dword 0
993
 
993
 
994
;        mov    [dma_hdd],1
994
;        mov    [dma_hdd],1
995
        cmp     [IDEContrRegsBaseAddr], 0
995
        cmp     [IDEContrRegsBaseAddr], 0
996
        setnz   [dma_hdd]
996
        setnz   [dma_hdd]
997
        mov [timer_ticks_enable],1              ; for cd driver
997
        mov [timer_ticks_enable],1              ; for cd driver
998
 
998
 
999
        sti
999
        sti
1000
        call change_task
1000
        call change_task
1001
 
1001
 
1002
        jmp osloop
1002
        jmp osloop
1003
 
1003
 
1004
;        jmp   $                      ; wait here for timer to take control
1004
;        jmp   $                      ; wait here for timer to take control
1005
 
1005
 
1006
        ; Fly :)
1006
        ; Fly :)
1007
 
1007
 
1008
include 'unpacker.inc'
1008
include 'unpacker.inc'
1009
include 'fdo.inc'
1009
include 'fdo.inc'
1010
 
1010
 
1011
align 4
1011
align 4
1012
boot_log:
1012
boot_log:
1013
         pushad
1013
         pushad
1014
 
1014
 
1015
        mov   ebx,10*65536
1015
        mov   ebx,10*65536
1016
        mov   bx,word [boot_y]
1016
        mov   bx,word [boot_y]
1017
        add   [boot_y],dword 10
1017
        add   [boot_y],dword 10
1018
        mov   ecx,0x80ffffff   ; ASCIIZ string with white color
1018
        mov   ecx,0x80ffffff   ; ASCIIZ string with white color
1019
		xor	  edi,edi
1019
		xor	  edi,edi
1020
        mov   edx,esi
1020
        mov   edx,esi
1021
		inc	  edi
1021
		inc	  edi
1022
        call  dtext
1022
        call  dtext
1023
 
1023
 
1024
        mov   [novesachecksum],1000
1024
        mov   [novesachecksum],1000
1025
        call  checkVga_N13
1025
        call  checkVga_N13
1026
 
1026
 
1027
        popad
1027
        popad
1028
 
1028
 
1029
        ret
1029
        ret
1030
 
1030
 
1031
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1031
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1032
;                                                                    ;
1032
;                                                                    ;
1033
;                    MAIN OS LOOP START                              ;
1033
;                    MAIN OS LOOP START                              ;
1034
;                                                                    ;
1034
;                                                                    ;
1035
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1035
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1036
align 32
1036
align 32
1037
osloop:
1037
osloop:
1038
        call   [draw_pointer]
1038
        call   [draw_pointer]
1039
        call   checkbuttons
1039
        call   checkbuttons
1040
        call   checkwindows
1040
        call   checkwindows
1041
;       call   check_window_move_request
1041
;       call   check_window_move_request
1042
        call   checkmisc
1042
        call   checkmisc
1043
        call   checkVga_N13
1043
        call   checkVga_N13
1044
        call   stack_handler
1044
        call   stack_handler
1045
        call   checkidle
1045
        call   checkidle
1046
        call   check_fdd_motor_status
1046
        call   check_fdd_motor_status
1047
        call   check_ATAPI_device_event
1047
        call   check_ATAPI_device_event
1048
        jmp    osloop
1048
        jmp    osloop
1049
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1049
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1050
;                                                                    ;
1050
;                                                                    ;
1051
;                      MAIN OS LOOP END                              ;
1051
;                      MAIN OS LOOP END                              ;
1052
;                                                                    ;
1052
;                                                                    ;
1053
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1053
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1054
align 4
1054
align 4
1055
checkidle:
1055
checkidle:
1056
        pushad
1056
        pushad
1057
        call    change_task
1057
        call    change_task
1058
        jmp     idle_loop_entry
1058
        jmp     idle_loop_entry
1059
  idle_loop:
1059
  idle_loop:
1060
        cmp     eax,[idlemem]     ; eax == [timer_ticks]
1060
        cmp     eax,[idlemem]     ; eax == [timer_ticks]
1061
        jne     idle_exit
1061
        jne     idle_exit
1062
        rdtsc   ;call _rdtsc
1062
        rdtsc   ;call _rdtsc
1063
        mov     ecx,eax
1063
        mov     ecx,eax
1064
        hlt
1064
        hlt
1065
        rdtsc   ;call _rdtsc
1065
        rdtsc   ;call _rdtsc
1066
        sub     eax,ecx
1066
        sub     eax,ecx
1067
        add     [idleuse],eax
1067
        add     [idleuse],eax
1068
  idle_loop_entry:
1068
  idle_loop_entry:
1069
        mov     eax,[timer_ticks] ; eax =  [timer_ticks]
1069
        mov     eax,[timer_ticks] ; eax =  [timer_ticks]
1070
        cmp     [check_idle_semaphore],0
1070
        cmp     [check_idle_semaphore],0
1071
        je      idle_loop
1071
        je      idle_loop
1072
        dec     [check_idle_semaphore]
1072
        dec     [check_idle_semaphore]
1073
  idle_exit:
1073
  idle_exit:
1074
        mov     [idlemem],eax     ; eax == [timer_ticks]
1074
        mov     [idlemem],eax     ; eax == [timer_ticks]
1075
        popad
1075
        popad
1076
        ret
1076
        ret
1077
 
1077
 
1078
uglobal
1078
uglobal
1079
  idlemem               dd   0x0
1079
  idlemem               dd   0x0
1080
  idleuse               dd   0x0
1080
  idleuse               dd   0x0
1081
  idleusesec            dd   0x0
1081
  idleusesec            dd   0x0
1082
  check_idle_semaphore  dd   0x0
1082
  check_idle_semaphore  dd   0x0
1083
endg
1083
endg
1084
 
1084
 
1085
 
1085
 
1086
 
1086
 
1087
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1087
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1088
;                                                                      ;
1088
;                                                                      ;
1089
;                   INCLUDED SYSTEM FILES                              ;
1089
;                   INCLUDED SYSTEM FILES                              ;
1090
;                                                                      ;
1090
;                                                                      ;
1091
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1091
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1092
 
1092
 
1093
 
1093
 
1094
include "kernel32.inc"
1094
include "kernel32.inc"
1095
 
1095
 
1096
 
1096
 
1097
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1097
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1098
;                                                                      ;
1098
;                                                                      ;
1099
;                       KERNEL FUNCTIONS                               ;
1099
;                       KERNEL FUNCTIONS                               ;
1100
;                                                                      ;
1100
;                                                                      ;
1101
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1101
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1102
 
1102
 
1103
reserve_irqs_ports:
1103
reserve_irqs_ports:
1104
 
1104
 
1105
        push eax
1105
        push eax
1106
        xor	eax,eax
1106
        xor	eax,eax
1107
		inc	eax
1107
		inc	eax
1108
        mov  byte [irq_owner+4*0],al		;1    ; timer
1108
        mov  byte [irq_owner+4*0],al		;1    ; timer
1109
        ;mov  [irq_owner+4*1], 1    ; keyboard
1109
        ;mov  [irq_owner+4*1], 1    ; keyboard
1110
        mov  byte [irq_owner+4*6],al		;1    ; floppy diskette
1110
        mov  byte [irq_owner+4*6],al		;1    ; floppy diskette
1111
        mov  byte [irq_owner+4*13],al	;1   ; math co-pros
1111
        mov  byte [irq_owner+4*13],al	;1   ; math co-pros
1112
        mov  byte [irq_owner+4*14],al	;1   ; ide I
1112
        mov  byte [irq_owner+4*14],al	;1   ; ide I
1113
        mov  byte [irq_owner+4*15],al	;1   ; ide II
1113
        mov  byte [irq_owner+4*15],al	;1   ; ide II
1114
        pop  eax
1114
        pop  eax
1115
 
1115
 
1116
; RESERVE PORTS
1116
; RESERVE PORTS
1117
	push  4
1117
	push  4
1118
        pop   dword [RESERVED_PORTS]	;,edi
1118
        pop   dword [RESERVED_PORTS]	;,edi
1119
 
1119
 
1120
	push  1
1120
	push  1
1121
        pop   dword [RESERVED_PORTS+16+0]	;,dword 1
1121
        pop   dword [RESERVED_PORTS+16+0]	;,dword 1
1122
        and   dword [RESERVED_PORTS+16+4],0	;,dword 0x0
1122
        and   dword [RESERVED_PORTS+16+4],0	;,dword 0x0
1123
        mov   dword [RESERVED_PORTS+16+8],0x2d	;,dword 0x2d
1123
        mov   dword [RESERVED_PORTS+16+8],0x2d	;,dword 0x2d
1124
 
1124
 
1125
	push  1
1125
	push  1
1126
        pop   dword [RESERVED_PORTS+32+0]	;,dword 1
1126
        pop   dword [RESERVED_PORTS+32+0]	;,dword 1
1127
        push  0x30
1127
        push  0x30
1128
        pop   dword [RESERVED_PORTS+32+4]	;,dword 0x30
1128
        pop   dword [RESERVED_PORTS+32+4]	;,dword 0x30
1129
	push  0x4d
1129
	push  0x4d
1130
        pop   dword [RESERVED_PORTS+32+8]	;,dword 0x4d
1130
        pop   dword [RESERVED_PORTS+32+8]	;,dword 0x4d
1131
 
1131
 
1132
	push  1
1132
	push  1
1133
        pop   dword [RESERVED_PORTS+48+0]	;,dword 1
1133
        pop   dword [RESERVED_PORTS+48+0]	;,dword 1
1134
	push  0x50
1134
	push  0x50
1135
        pop   dword [RESERVED_PORTS+48+4]	;,dword 0x50
1135
        pop   dword [RESERVED_PORTS+48+4]	;,dword 0x50
1136
        mov   dword [RESERVED_PORTS+48+8],0xdf	;,dword 0xdf
1136
        mov   dword [RESERVED_PORTS+48+8],0xdf	;,dword 0xdf
1137
 
1137
 
1138
	push  1
1138
	push  1
1139
        pop   dword [RESERVED_PORTS+64+0]	;,dword 1
1139
        pop   dword [RESERVED_PORTS+64+0]	;,dword 1
1140
 
1140
 
1141
        mov   dword [RESERVED_PORTS+64+4],0xe5	;,dword 0xe5
1141
        mov   dword [RESERVED_PORTS+64+4],0xe5	;,dword 0xe5
1142
        mov   dword [RESERVED_PORTS+64+8],0xff	;,dword 0xff
1142
        mov   dword [RESERVED_PORTS+64+8],0xff	;,dword 0xff
1143
 
1143
 
1144
        ret
1144
        ret
1145
 
1145
 
1146
setirqreadports:
1146
setirqreadports:
1147
 
1147
 
1148
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1148
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1149
	    and   dword [irq12read+4],0                   ; end of port list
1149
	    and   dword [irq12read+4],0                   ; end of port list
1150
;        mov   [irq12read+4],dword 0                  ; end of port list
1150
;        mov   [irq12read+4],dword 0                  ; end of port list
1151
        ;mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1151
        ;mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1152
        ;mov   [irq04read+4],dword 0                  ; end of port list
1152
        ;mov   [irq04read+4],dword 0                  ; end of port list
1153
        ;mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1153
        ;mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1154
        ;mov   [irq03read+4],dword 0                  ; end of port list
1154
        ;mov   [irq03read+4],dword 0                  ; end of port list
1155
 
1155
 
1156
        ret
1156
        ret
1157
 
1157
 
1158
iglobal
1158
iglobal
1159
  process_number dd 0x1
1159
  process_number dd 0x1
1160
endg
1160
endg
1161
 
1161
 
1162
set_variables:
1162
set_variables:
1163
 
1163
 
1164
        mov   ecx,0x100                       ; flush port 0x60
1164
        mov   ecx,0x100                       ; flush port 0x60
1165
.fl60:  in    al,0x60
1165
.fl60:  in    al,0x60
1166
        loop  .fl60
1166
        loop  .fl60
1167
        push  eax
1167
        push  eax
1168
 
1168
 
1169
        mov   ax,[BOOT_VAR+0x900c]
1169
        mov   ax,[BOOT_VAR+0x900c]
1170
        shr   ax,1
1170
        shr   ax,1
1171
        shl   eax,16
1171
        shl   eax,16
1172
        mov   ax,[BOOT_VAR+0x900A]
1172
        mov   ax,[BOOT_VAR+0x900A]
1173
        shr   ax,1
1173
        shr   ax,1
1174
        mov   [MOUSE_X],eax
1174
        mov   [MOUSE_X],eax
1175
 
1175
 
1176
        xor   eax,eax
1176
        xor   eax,eax
1177
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1177
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1178
 
1178
 
1179
        mov   byte [MOUSE_BUFF_COUNT],al                 ; mouse buffer
1179
        mov   byte [MOUSE_BUFF_COUNT],al                 ; mouse buffer
1180
        mov   byte [KEY_COUNT],al                 ; keyboard buffer
1180
        mov   byte [KEY_COUNT],al                 ; keyboard buffer
1181
        mov   byte [BTN_COUNT],al                 ; button buffer
1181
        mov   byte [BTN_COUNT],al                 ; button buffer
1182
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1182
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1183
 
1183
 
1184
     ;!! IP 04.02.2005:
1184
     ;!! IP 04.02.2005:
1185
        mov   byte [DONT_SWITCH],al ; change task if possible
1185
        mov   byte [DONT_SWITCH],al ; change task if possible
1186
        pop   eax
1186
        pop   eax
1187
        ret
1187
        ret
1188
 
1188
 
1189
align 4
1189
align 4
1190
;input  eax=43,bl-byte of output, ecx - number of port
1190
;input  eax=43,bl-byte of output, ecx - number of port
1191
sys_outport:
1191
sys_outport:
1192
 
1192
 
1193
    mov   edi,ecx          ; separate flag for read / write
1193
    mov   edi,ecx          ; separate flag for read / write
1194
    and   ecx,65535
1194
    and   ecx,65535
1195
 
1195
 
1196
    mov   eax,[RESERVED_PORTS]
1196
    mov   eax,[RESERVED_PORTS]
1197
    test  eax,eax
1197
    test  eax,eax
1198
    jnz   .sopl8
1198
    jnz   .sopl8
1199
    inc	  eax
1199
    inc	  eax
1200
	mov   [esp+32],eax
1200
	mov   [esp+32],eax
1201
    ret
1201
    ret
1202
 
1202
 
1203
  .sopl8:
1203
  .sopl8:
1204
    mov   edx,[TASK_BASE]
1204
    mov   edx,[TASK_BASE]
1205
    mov   edx,[edx+0x4]
1205
    mov   edx,[edx+0x4]
1206
    ;and   ecx,65535
1206
    ;and   ecx,65535
1207
    ;cld - set on interrupt 0x40
1207
    ;cld - set on interrupt 0x40
1208
  .sopl1:
1208
  .sopl1:
1209
 
1209
 
1210
    mov   esi,eax
1210
    mov   esi,eax
1211
    shl   esi,4
1211
    shl   esi,4
1212
    add   esi,RESERVED_PORTS
1212
    add   esi,RESERVED_PORTS
1213
    cmp   edx,[esi+0]
1213
    cmp   edx,[esi+0]
1214
    jne   .sopl2
1214
    jne   .sopl2
1215
    cmp   ecx,[esi+4]
1215
    cmp   ecx,[esi+4]
1216
    jb    .sopl2
1216
    jb    .sopl2
1217
    cmp   ecx,[esi+8]
1217
    cmp   ecx,[esi+8]
1218
    jg    .sopl2
1218
    jg    .sopl2
1219
.sopl3:
1219
.sopl3:
1220
 
1220
 
1221
    test  edi,0x80000000 ; read ?
1221
    test  edi,0x80000000 ; read ?
1222
    jnz   .sopl4
1222
    jnz   .sopl4
1223
 
1223
 
1224
	mov	  eax,ebx
1224
	mov	  eax,ebx
1225
    mov   dx,cx          ; write
1225
    mov   dx,cx          ; write
1226
    out   dx,al
1226
    out   dx,al
1227
    and   [esp+32],dword 0
1227
    and   [esp+32],dword 0
1228
    ret
1228
    ret
1229
 
1229
 
1230
	.sopl2:
1230
	.sopl2:
1231
 
1231
 
1232
    dec   eax
1232
    dec   eax
1233
    jnz   .sopl1
1233
    jnz   .sopl1
1234
	inc	  eax
1234
	inc	  eax
1235
    mov   [esp+32],eax
1235
    mov   [esp+32],eax
1236
    ret
1236
    ret
1237
 
1237
 
1238
  
1238
  
1239
  .sopl4:
1239
  .sopl4:
1240
 
1240
 
1241
    mov   dx,cx          ; read
1241
    mov   dx,cx          ; read
1242
    in    al,dx
1242
    in    al,dx
1243
    and   eax,0xff
1243
    and   eax,0xff
1244
    and   [esp+32],dword 0
1244
    and   [esp+32],dword 0
1245
    mov   [esp+20],eax
1245
    mov   [esp+20],eax
1246
    ret
1246
    ret
1247
 
1247
 
1248
display_number:
1248
display_number:
1249
 
1249
 
1250
; eax = print type, al=0 -> ebx is number
1250
; eax = print type, al=0 -> ebx is number
1251
;                   al=1 -> ebx is pointer
1251
;                   al=1 -> ebx is pointer
1252
;                   ah=0 -> display decimal
1252
;                   ah=0 -> display decimal
1253
;                   ah=1 -> display hexadecimal
1253
;                   ah=1 -> display hexadecimal
1254
;                   ah=2 -> display binary
1254
;                   ah=2 -> display binary
1255
;                   eax bits 16-21 = number of digits to display (0-32)
1255
;                   eax bits 16-21 = number of digits to display (0-32)
1256
;                   eax bits 22-31 = reserved
1256
;                   eax bits 22-31 = reserved
1257
;
1257
;
1258
; ebx = number or pointer
1258
; ebx = number or pointer
1259
; ecx = x shl 16 + y
1259
; ecx = x shl 16 + y
1260
; edx = color
1260
; edx = color
1261
    xor     edi, edi
1261
    xor     edi, edi
1262
display_number_force:
1262
display_number_force:
1263
    push  eax
1263
    push  eax
1264
    and   eax,0x3fffffff
1264
    and   eax,0x3fffffff
1265
    cmp   eax,0xffff            ; length > 0 ?
1265
    cmp   eax,0xffff            ; length > 0 ?
1266
    pop   eax
1266
    pop   eax
1267
    jge   cont_displ
1267
    jge   cont_displ
1268
    ret
1268
    ret
1269
   cont_displ:
1269
   cont_displ:
1270
     push  eax
1270
     push  eax
1271
     and   eax,0x3fffffff
1271
     and   eax,0x3fffffff
1272
     cmp   eax,61*0x10000        ; length <= 60 ?
1272
     cmp   eax,61*0x10000        ; length <= 60 ?
1273
     pop   eax
1273
     pop   eax
1274
     jb    cont_displ2
1274
     jb    cont_displ2
1275
     ret
1275
     ret
1276
   cont_displ2:
1276
   cont_displ2:
1277
 
1277
 
1278
     pushad
1278
     pushad
1279
 
1279
 
1280
     cmp   al,1                  ; ecx is a pointer ?
1280
     cmp   al,1                  ; ecx is a pointer ?
1281
     jne   displnl1
1281
     jne   displnl1
1282
     mov   ebp,ebx
1282
     mov   ebp,ebx
1283
     add   ebp,4
1283
     add   ebp,4
1284
     mov   ebp,[ebp+std_application_base_address]
1284
     mov   ebp,[ebp+std_application_base_address]
1285
     mov   ebx,[ebx+std_application_base_address]
1285
     mov   ebx,[ebx+std_application_base_address]
1286
 displnl1:
1286
 displnl1:
1287
     sub   esp,64
1287
     sub   esp,64
1288
 
1288
 
1289
    test   ah,ah                  ; DECIMAL
1289
    test   ah,ah                  ; DECIMAL
1290
    jnz   no_display_desnum
1290
    jnz   no_display_desnum
1291
    shr   eax,16
1291
    shr   eax,16
1292
    and   eax,0xC03f
1292
    and   eax,0xC03f
1293
;     and   eax,0x3f
1293
;     and   eax,0x3f
1294
    push  eax
1294
    push  eax
1295
    and   eax,0x3f
1295
    and   eax,0x3f
1296
    mov   edi,esp
1296
    mov   edi,esp
1297
    add   edi,4+64-1
1297
    add   edi,4+64-1
1298
    mov   ecx,eax
1298
    mov   ecx,eax
1299
    mov   eax,ebx
1299
    mov   eax,ebx
1300
    mov   ebx,10
1300
    mov   ebx,10
1301
 d_desnum:
1301
 d_desnum:
1302
     xor   edx,edx
1302
     xor   edx,edx
1303
     call  division_64_bits
1303
     call  division_64_bits
1304
     div   ebx
1304
     div   ebx
1305
     add   dl,48
1305
     add   dl,48
1306
     mov   [edi],dl
1306
     mov   [edi],dl
1307
     dec   edi
1307
     dec   edi
1308
     loop  d_desnum
1308
     loop  d_desnum
1309
     pop   eax
1309
     pop   eax
1310
     call  normalize_number
1310
     call  normalize_number
1311
     call  draw_num_text
1311
     call  draw_num_text
1312
     add   esp,64
1312
     add   esp,64
1313
     popad
1313
     popad
1314
     ret
1314
     ret
1315
   no_display_desnum:
1315
   no_display_desnum:
1316
 
1316
 
1317
     cmp   ah,0x01               ; HEXADECIMAL
1317
     cmp   ah,0x01               ; HEXADECIMAL
1318
     jne   no_display_hexnum
1318
     jne   no_display_hexnum
1319
     shr   eax,16
1319
     shr   eax,16
1320
     and   eax,0xC03f
1320
     and   eax,0xC03f
1321
;     and   eax,0x3f
1321
;     and   eax,0x3f
1322
     push  eax
1322
     push  eax
1323
     and   eax,0x3f
1323
     and   eax,0x3f
1324
     mov   edi,esp
1324
     mov   edi,esp
1325
     add   edi,4+64-1
1325
     add   edi,4+64-1
1326
     mov   ecx,eax
1326
     mov   ecx,eax
1327
     mov   eax,ebx
1327
     mov   eax,ebx
1328
     mov   ebx,16
1328
     mov   ebx,16
1329
   d_hexnum:
1329
   d_hexnum:
1330
     xor   edx,edx
1330
     xor   edx,edx
1331
     call  division_64_bits
1331
     call  division_64_bits
1332
     div   ebx
1332
     div   ebx
1333
   hexletters = __fdo_hexdigits
1333
   hexletters = __fdo_hexdigits
1334
     add   edx,hexletters
1334
     add   edx,hexletters
1335
     mov   dl,[edx]
1335
     mov   dl,[edx]
1336
     mov   [edi],dl
1336
     mov   [edi],dl
1337
     dec   edi
1337
     dec   edi
1338
     loop  d_hexnum
1338
     loop  d_hexnum
1339
     pop   eax
1339
     pop   eax
1340
     call  normalize_number
1340
     call  normalize_number
1341
     call  draw_num_text
1341
     call  draw_num_text
1342
     add   esp,64
1342
     add   esp,64
1343
     popad
1343
     popad
1344
     ret
1344
     ret
1345
   no_display_hexnum:
1345
   no_display_hexnum:
1346
 
1346
 
1347
     cmp   ah,0x02               ; BINARY
1347
     cmp   ah,0x02               ; BINARY
1348
     jne   no_display_binnum
1348
     jne   no_display_binnum
1349
     shr   eax,16
1349
     shr   eax,16
1350
     and   eax,0xC03f
1350
     and   eax,0xC03f
1351
;     and   eax,0x3f
1351
;     and   eax,0x3f
1352
     push  eax
1352
     push  eax
1353
     and   eax,0x3f
1353
     and   eax,0x3f
1354
     mov   edi,esp
1354
     mov   edi,esp
1355
     add   edi,4+64-1
1355
     add   edi,4+64-1
1356
     mov   ecx,eax
1356
     mov   ecx,eax
1357
     mov   eax,ebx
1357
     mov   eax,ebx
1358
     mov   ebx,2
1358
     mov   ebx,2
1359
   d_binnum:
1359
   d_binnum:
1360
     xor   edx,edx
1360
     xor   edx,edx
1361
     call  division_64_bits
1361
     call  division_64_bits
1362
     div   ebx
1362
     div   ebx
1363
     add   dl,48
1363
     add   dl,48
1364
     mov   [edi],dl
1364
     mov   [edi],dl
1365
     dec   edi
1365
     dec   edi
1366
     loop  d_binnum
1366
     loop  d_binnum
1367
     pop   eax
1367
     pop   eax
1368
     call  normalize_number
1368
     call  normalize_number
1369
     call  draw_num_text
1369
     call  draw_num_text
1370
     add   esp,64
1370
     add   esp,64
1371
     popad
1371
     popad
1372
     ret
1372
     ret
1373
   no_display_binnum:
1373
   no_display_binnum:
1374
 
1374
 
1375
     add   esp,64
1375
     add   esp,64
1376
     popad
1376
     popad
1377
     ret
1377
     ret
1378
 
1378
 
1379
normalize_number:
1379
normalize_number:
1380
     test  ah,0x80
1380
     test  ah,0x80
1381
     jz   .continue
1381
     jz   .continue
1382
     mov  ecx,48
1382
     mov  ecx,48
1383
     and   eax,0x3f
1383
     and   eax,0x3f
1384
@@:
1384
@@:
1385
     inc   edi
1385
     inc   edi
1386
     cmp   [edi],cl
1386
     cmp   [edi],cl
1387
     jne   .continue
1387
     jne   .continue
1388
     dec   eax
1388
     dec   eax
1389
     cmp   eax,1
1389
     cmp   eax,1
1390
     ja    @r
1390
     ja    @r
1391
     mov   al,1
1391
     mov   al,1
1392
.continue:
1392
.continue:
1393
     and   eax,0x3f
1393
     and   eax,0x3f
1394
     ret
1394
     ret
1395
 
1395
 
1396
division_64_bits:
1396
division_64_bits:
1397
     test  [esp+1+4],byte 0x40
1397
     test  [esp+1+4],byte 0x40
1398
     jz   .continue
1398
     jz   .continue
1399
     push  eax
1399
     push  eax
1400
     mov   eax,ebp
1400
     mov   eax,ebp
1401
     div   ebx
1401
     div   ebx
1402
     mov   ebp,eax
1402
     mov   ebp,eax
1403
     pop   eax
1403
     pop   eax
1404
.continue:
1404
.continue:
1405
     ret
1405
     ret
1406
 
1406
 
1407
draw_num_text:
1407
draw_num_text:
1408
     mov   esi,eax
1408
     mov   esi,eax
1409
     mov   edx,64+4
1409
     mov   edx,64+4
1410
     sub   edx,eax
1410
     sub   edx,eax
1411
     add   edx,esp
1411
     add   edx,esp
1412
     mov   ebx,[esp+64+32-8+4]
1412
     mov   ebx,[esp+64+32-8+4]
1413
; add window start x & y
1413
; add window start x & y
1414
     mov   ecx,[TASK_BASE]
1414
     mov   ecx,[TASK_BASE]
1415
 
1415
 
1416
     mov   edi,[CURRENT_TASK]
1416
     mov   edi,[CURRENT_TASK]
1417
     shl   edi,8
1417
     shl   edi,8
1418
 
1418
 
1419
     mov   eax,[ecx-twdw+WDATA.box.left]
1419
     mov   eax,[ecx-twdw+WDATA.box.left]
1420
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1420
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1421
     shl   eax,16
1421
     shl   eax,16
1422
     add   eax,[ecx-twdw+WDATA.box.top]
1422
     add   eax,[ecx-twdw+WDATA.box.top]
1423
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1423
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1424
     add   ebx,eax
1424
     add   ebx,eax
1425
     mov   ecx,[esp+64+32-12+4]
1425
     mov   ecx,[esp+64+32-12+4]
1426
        and     ecx, not 0x80000000     ; force counted string
1426
        and     ecx, not 0x80000000     ; force counted string
1427
        mov     eax, [esp+64+8]         ; background color (if given)
1427
        mov     eax, [esp+64+8]         ; background color (if given)
1428
        mov     edi, [esp+64+4]
1428
        mov     edi, [esp+64+4]
1429
     jmp   dtext
1429
     jmp   dtext
1430
 
1430
 
1431
align 4
1431
align 4
1432
 
1432
 
1433
sys_setup:
1433
sys_setup:
1434
 
1434
 
1435
; 1=roland mpu midi base , base io address
1435
; 1=roland mpu midi base , base io address
1436
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1436
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1437
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1437
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1438
; 5=system language, 1eng 2fi 3ger 4rus
1438
; 5=system language, 1eng 2fi 3ger 4rus
1439
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1439
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1440
; 8=fat32 partition in hd
1440
; 8=fat32 partition in hd
1441
; 9
1441
; 9
1442
; 10 = sound dma channel
1442
; 10 = sound dma channel
1443
; 11 = enable lba read
1443
; 11 = enable lba read
1444
; 12 = enable pci access
1444
; 12 = enable pci access
1445
 
1445
 
1446
 
1446
 
1447
     	and  [esp+32],dword 0
1447
     	and  [esp+32],dword 0
1448
	dec	ebx				; MIDI
1448
	dec	ebx				; MIDI
1449
	jnz  nsyse1
1449
	jnz  nsyse1
1450
	cmp  ecx,0x100
1450
	cmp  ecx,0x100
1451
 
1451
 
1452
	jb   nsyse1
1452
	jb   nsyse1
1453
	mov	esi,65535
1453
	mov	esi,65535
1454
	cmp	esi,ecx
1454
	cmp	esi,ecx
1455
 
1455
 
1456
	jb   nsyse1
1456
	jb   nsyse1
1457
	mov  [midi_base],cx	;bx
1457
	mov  [midi_base],cx	;bx
1458
	mov  word [mididp],cx	;bx
1458
	mov  word [mididp],cx	;bx
1459
	inc  cx		    	;bx
1459
	inc  cx		    	;bx
1460
	mov  word [midisp],cx	;bx
1460
	mov  word [midisp],cx	;bx
1461
	ret
1461
	ret
1462
 
1462
 
1463
iglobal
1463
iglobal
1464
midi_base dw 0
1464
midi_base dw 0
1465
endg
1465
endg
1466
 
1466
 
1467
   nsyse1:
1467
   nsyse1:
1468
	dec	ebx				 ; KEYBOARD
1468
	dec	ebx				 ; KEYBOARD
1469
	jnz  nsyse2
1469
	jnz  nsyse2
1470
	mov  edi,[TASK_BASE]
1470
	mov  edi,[TASK_BASE]
1471
	mov  eax,[edi+TASKDATA.mem_start]
1471
	mov  eax,[edi+TASKDATA.mem_start]
1472
	add  eax,edx
1472
	add  eax,edx
1473
 
1473
 
1474
	dec	ecx
1474
	dec	ecx
1475
	jnz  kbnobase
1475
	jnz  kbnobase
1476
	mov  ebx,keymap
1476
	mov  ebx,keymap
1477
	mov  ecx,128
1477
	mov  ecx,128
1478
	call memmove
1478
	call memmove
1479
	ret
1479
	ret
1480
   kbnobase:
1480
   kbnobase:
1481
	dec  ecx
1481
	dec  ecx
1482
	jnz  kbnoshift
1482
	jnz  kbnoshift
1483
 
1483
 
1484
	mov  ebx,keymap_shift
1484
	mov  ebx,keymap_shift
1485
	mov  ecx,128
1485
	mov  ecx,128
1486
	call memmove
1486
	call memmove
1487
	ret
1487
	ret
1488
   kbnoshift:
1488
   kbnoshift:
1489
	dec  ecx
1489
	dec  ecx
1490
	jnz  kbnoalt
1490
	jnz  kbnoalt
1491
	mov  ebx,keymap_alt
1491
	mov  ebx,keymap_alt
1492
	mov  ecx,128
1492
	mov  ecx,128
1493
	call memmove
1493
	call memmove
1494
	ret
1494
	ret
1495
   kbnoalt:
1495
   kbnoalt:
1496
	sub  ecx,6
1496
	sub  ecx,6
1497
	jnz  kbnocountry
1497
	jnz  kbnocountry
1498
	mov  word [keyboard],dx
1498
	mov  word [keyboard],dx
1499
	ret
1499
	ret
1500
   kbnocountry:
1500
   kbnocountry:
1501
	mov  [esp+32],dword 1
1501
	mov  [esp+32],dword 1
1502
	ret
1502
	ret
1503
   nsyse2:
1503
   nsyse2:
1504
	dec  ebx			    ; CD
1504
	dec  ebx			    ; CD
1505
	jnz  nsyse4
1505
	jnz  nsyse4
1506
 
1506
 
1507
	test ecx,ecx
1507
	test ecx,ecx
1508
	jz   nosesl
1508
	jz   nosesl
1509
 
1509
 
1510
	cmp  ecx, 4
1510
	cmp  ecx, 4
1511
	ja   nosesl
1511
	ja   nosesl
1512
	mov  [cd_base],cl
1512
	mov  [cd_base],cl
1513
 
1513
 
1514
	dec	ecx
1514
	dec	ecx
1515
	jnz  noprma
1515
	jnz  noprma
1516
	mov  [cdbase],0x1f0
1516
	mov  [cdbase],0x1f0
1517
	mov  [cdid],0xa0
1517
	mov  [cdid],0xa0
1518
   noprma:
1518
   noprma:
1519
 
1519
 
1520
	dec	ecx
1520
	dec	ecx
1521
	jnz  noprsl
1521
	jnz  noprsl
1522
	mov  [cdbase],0x1f0
1522
	mov  [cdbase],0x1f0
1523
	mov  [cdid],0xb0
1523
	mov  [cdid],0xb0
1524
   noprsl:
1524
   noprsl:
1525
	dec	ecx
1525
	dec	ecx
1526
     	jnz  nosema
1526
     	jnz  nosema
1527
     	mov  [cdbase],0x170
1527
     	mov  [cdbase],0x170
1528
     	mov  [cdid],0xa0
1528
     	mov  [cdid],0xa0
1529
   nosema:
1529
   nosema:
1530
	dec	ecx
1530
	dec	ecx
1531
     	jnz  nosesl
1531
     	jnz  nosesl
1532
     	mov  [cdbase],0x170
1532
     	mov  [cdbase],0x170
1533
     	mov  [cdid],0xb0
1533
     	mov  [cdid],0xb0
1534
   nosesl:
1534
   nosesl:
1535
     	ret
1535
     	ret
1536
 
1536
 
1537
iglobal
1537
iglobal
1538
cd_base db 0
1538
cd_base db 0
1539
 
1539
 
1540
endg
1540
endg
1541
   nsyse4:
1541
   nsyse4:
1542
                 
1542
                 
1543
     	sub  ebx,2		 ; SYSTEM LANGUAGE
1543
     	sub  ebx,2		 ; SYSTEM LANGUAGE
1544
     	jnz  nsyse5
1544
     	jnz  nsyse5
1545
     	mov  [syslang],ecx
1545
     	mov  [syslang],ecx
1546
     	ret
1546
     	ret
1547
   nsyse5:
1547
   nsyse5:
1548
         
1548
         
1549
     	sub  ebx,2		; HD BASE
1549
     	sub  ebx,2		; HD BASE
1550
     	jnz  nsyse7
1550
     	jnz  nsyse7
1551
 
1551
 
1552
     	test ecx,ecx
1552
     	test ecx,ecx
1553
     	jz   nosethd
1553
     	jz   nosethd
1554
 
1554
 
1555
     	cmp  ecx,4
1555
     	cmp  ecx,4
1556
     	ja   nosethd
1556
     	ja   nosethd
1557
     	mov  [hd_base],cl
1557
     	mov  [hd_base],cl
1558
 
1558
 
1559
     	cmp  ecx,1
1559
     	cmp  ecx,1
1560
     	jnz  noprmahd
1560
     	jnz  noprmahd
1561
     	mov  [hdbase],0x1f0
1561
     	mov  [hdbase],0x1f0
1562
     	and  dword [hdid],0x0
1562
     	and  dword [hdid],0x0
1563
     	mov  dword [hdpos],ecx
1563
     	mov  dword [hdpos],ecx
1564
;     call set_FAT32_variables
1564
;     call set_FAT32_variables
1565
   noprmahd:
1565
   noprmahd:
1566
 
1566
 
1567
     	cmp  ecx,2
1567
     	cmp  ecx,2
1568
     	jnz  noprslhd
1568
     	jnz  noprslhd
1569
     	mov  [hdbase],0x1f0
1569
     	mov  [hdbase],0x1f0
1570
     	mov  [hdid],0x10
1570
     	mov  [hdid],0x10
1571
     	mov  dword [hdpos],ecx
1571
     	mov  dword [hdpos],ecx
1572
;     call set_FAT32_variables
1572
;     call set_FAT32_variables
1573
   noprslhd:
1573
   noprslhd:
1574
 
1574
 
1575
     	cmp  ecx,3
1575
     	cmp  ecx,3
1576
     	jnz  nosemahd
1576
     	jnz  nosemahd
1577
     	mov  [hdbase],0x170
1577
     	mov  [hdbase],0x170
1578
     	and  dword [hdid],0x0
1578
     	and  dword [hdid],0x0
1579
     	mov  dword [hdpos],ecx
1579
     	mov  dword [hdpos],ecx
1580
;     call set_FAT32_variables
1580
;     call set_FAT32_variables
1581
   nosemahd:
1581
   nosemahd:
1582
 
1582
 
1583
     	cmp  ecx,4
1583
     	cmp  ecx,4
1584
     	jnz  noseslhd
1584
     	jnz  noseslhd
1585
     	mov  [hdbase],0x170
1585
     	mov  [hdbase],0x170
1586
     	mov  [hdid],0x10
1586
     	mov  [hdid],0x10
1587
     	mov  dword [hdpos],ecx
1587
     	mov  dword [hdpos],ecx
1588
;     call set_FAT32_variables
1588
;     call set_FAT32_variables
1589
   noseslhd:
1589
   noseslhd:
1590
    	call  reserve_hd1
1590
    	call  reserve_hd1
1591
    	call  reserve_hd_channel
1591
    	call  reserve_hd_channel
1592
    	call  free_hd_channel
1592
    	call  free_hd_channel
1593
    	and   dword [hd1_status],0        ; free
1593
    	and   dword [hd1_status],0        ; free
1594
   nosethd:
1594
   nosethd:
1595
     	ret
1595
     	ret
1596
 
1596
 
1597
iglobal
1597
iglobal
1598
hd_base db 0
1598
hd_base db 0
1599
endg
1599
endg
1600
 
1600
 
1601
nsyse7:
1601
nsyse7:
1602
 
1602
 
1603
;     cmp  eax,8                      ; HD PARTITION
1603
;     cmp  eax,8                      ; HD PARTITION
1604
     	dec  ebx
1604
     	dec  ebx
1605
     	jnz  nsyse8
1605
     	jnz  nsyse8
1606
     	mov  [fat32part],ecx
1606
     	mov  [fat32part],ecx
1607
;     call set_FAT32_variables
1607
;     call set_FAT32_variables
1608
    	call  reserve_hd1
1608
    	call  reserve_hd1
1609
    	call  reserve_hd_channel
1609
    	call  reserve_hd_channel
1610
    	call  free_hd_channel
1610
    	call  free_hd_channel
1611
;     	pusha
1611
;     	pusha
1612
     	call  choice_necessity_partition_1
1612
     	call  choice_necessity_partition_1
1613
;     	popa
1613
;     	popa
1614
    	and dword [hd1_status],0        ; free
1614
    	and dword [hd1_status],0        ; free
1615
     	ret
1615
     	ret
1616
 
1616
 
1617
nsyse8:
1617
nsyse8:
1618
;     cmp  eax,11                     ; ENABLE LBA READ
1618
;     cmp  eax,11                     ; ENABLE LBA READ
1619
    	and  ecx,1
1619
    	and  ecx,1
1620
	sub  ebx,3
1620
	sub  ebx,3
1621
    	jnz  no_set_lba_read
1621
    	jnz  no_set_lba_read
1622
    	mov  [lba_read_enabled],ecx
1622
    	mov  [lba_read_enabled],ecx
1623
    	ret
1623
    	ret
1624
 
1624
 
1625
no_set_lba_read:
1625
no_set_lba_read:
1626
;     cmp  eax,12                     ; ENABLE PCI ACCESS
1626
;     cmp  eax,12                     ; ENABLE PCI ACCESS
1627
    	dec  ebx
1627
    	dec  ebx
1628
    	jnz  no_set_pci_access
1628
    	jnz  no_set_pci_access
1629
    	mov  [pci_access_enabled],ecx
1629
    	mov  [pci_access_enabled],ecx
1630
    	ret
1630
    	ret
1631
no_set_pci_access:
1631
no_set_pci_access:
1632
 
1632
 
1633
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1633
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1634
include 'vmodeint.inc'
1634
include 'vmodeint.inc'
1635
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1635
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1636
 
1636
 
1637
sys_setup_err:
1637
sys_setup_err:
1638
     	or  [esp+32],dword -1
1638
     	or  [esp+32],dword -1
1639
     	ret
1639
     	ret
1640
 
1640
 
1641
align 4
1641
align 4
1642
 
1642
 
1643
sys_getsetup:
1643
sys_getsetup:
1644
 
1644
 
1645
; 1=roland mpu midi base , base io address
1645
; 1=roland mpu midi base , base io address
1646
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1646
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1647
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1647
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1648
; 5=system language, 1eng 2fi 3ger 4rus
1648
; 5=system language, 1eng 2fi 3ger 4rus
1649
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1649
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1650
; 8=fat32 partition in hd
1650
; 8=fat32 partition in hd
1651
; 9=get hs timer tic
1651
; 9=get hs timer tic
1652
 
1652
 
1653
;     cmp  eax,1
1653
;     cmp  eax,1
1654
	dec	ebx
1654
	dec	ebx
1655
     	jnz  ngsyse1
1655
     	jnz  ngsyse1
1656
     	movzx eax,[midi_base]
1656
     	movzx eax,[midi_base]
1657
     	mov  [esp+32],eax
1657
     	mov  [esp+32],eax
1658
     	ret
1658
     	ret
1659
ngsyse1:
1659
ngsyse1:
1660
;     cmp  eax,2
1660
;     cmp  eax,2
1661
	dec	ebx
1661
	dec	ebx
1662
     	jnz  ngsyse2
1662
     	jnz  ngsyse2
1663
 
1663
 
1664
     	mov  edi,[TASK_BASE]
1664
     	mov  edi,[TASK_BASE]
1665
     	mov  ebx,[edi+TASKDATA.mem_start]
1665
     	mov  ebx,[edi+TASKDATA.mem_start]
1666
     	add  ebx,edx
1666
     	add  ebx,edx
1667
 
1667
 
1668
;     cmp  ebx,1
1668
;     cmp  ebx,1
1669
	dec	ecx
1669
	dec	ecx
1670
     	jnz  kbnobaseret
1670
     	jnz  kbnobaseret
1671
     	mov  eax,keymap
1671
     	mov  eax,keymap
1672
     	mov  ecx,128
1672
     	mov  ecx,128
1673
     	call memmove
1673
     	call memmove
1674
     	ret
1674
     	ret
1675
kbnobaseret:
1675
kbnobaseret:
1676
;     cmp  ebx,2
1676
;     cmp  ebx,2
1677
	dec	ecx
1677
	dec	ecx
1678
     	jnz  kbnoshiftret
1678
     	jnz  kbnoshiftret
1679
 
1679
 
1680
     	mov  eax,keymap_shift
1680
     	mov  eax,keymap_shift
1681
     	mov  ecx,128
1681
     	mov  ecx,128
1682
     	call memmove
1682
     	call memmove
1683
     	ret
1683
     	ret
1684
kbnoshiftret:
1684
kbnoshiftret:
1685
;     cmp  ebx,3
1685
;     cmp  ebx,3
1686
	dec	ecx
1686
	dec	ecx
1687
     	jne  kbnoaltret
1687
     	jne  kbnoaltret
1688
 
1688
 
1689
     	mov  eax,keymap_alt
1689
     	mov  eax,keymap_alt
1690
     	mov  ecx,128
1690
     	mov  ecx,128
1691
     	call memmove
1691
     	call memmove
1692
     	ret
1692
     	ret
1693
kbnoaltret:
1693
kbnoaltret:
1694
;     cmp  ebx,9
1694
;     cmp  ebx,9
1695
	sub	ecx,6
1695
	sub	ecx,6
1696
     	jnz  ngsyse2
1696
     	jnz  ngsyse2
1697
     	movzx eax,word [keyboard]
1697
     	movzx eax,word [keyboard]
1698
     	mov  [esp+32],eax
1698
     	mov  [esp+32],eax
1699
     	ret
1699
     	ret
1700
 
1700
 
1701
 
1701
 
1702
ngsyse2:
1702
ngsyse2:
1703
;         cmp  eax,3
1703
;         cmp  eax,3
1704
	dec	ebx
1704
	dec	ebx
1705
        jnz  ngsyse3
1705
        jnz  ngsyse3
1706
        movzx eax,[cd_base]
1706
        movzx eax,[cd_base]
1707
        mov  [esp+32],eax
1707
        mov  [esp+32],eax
1708
        ret
1708
        ret
1709
ngsyse3:
1709
ngsyse3:
1710
;         cmp  eax,5
1710
;         cmp  eax,5
1711
	sub	ebx,2
1711
	sub	ebx,2
1712
        jnz  ngsyse5
1712
        jnz  ngsyse5
1713
        mov  eax,[syslang]
1713
        mov  eax,[syslang]
1714
        mov  [esp+32],eax
1714
        mov  [esp+32],eax
1715
        ret
1715
        ret
1716
ngsyse5:
1716
ngsyse5:
1717
;     cmp  eax,7
1717
;     cmp  eax,7
1718
	sub	ebx,2
1718
	sub	ebx,2
1719
     	jnz  ngsyse7
1719
     	jnz  ngsyse7
1720
     	movzx eax,[hd_base]
1720
     	movzx eax,[hd_base]
1721
     	mov  [esp+32],eax
1721
     	mov  [esp+32],eax
1722
     	ret
1722
     	ret
1723
ngsyse7:
1723
ngsyse7:
1724
;     cmp  eax,8
1724
;     cmp  eax,8
1725
	dec	ebx
1725
	dec	ebx
1726
     	jnz  ngsyse8
1726
     	jnz  ngsyse8
1727
     	mov eax,[fat32part]
1727
     	mov eax,[fat32part]
1728
     	mov  [esp+32],eax
1728
     	mov  [esp+32],eax
1729
     	ret
1729
     	ret
1730
ngsyse8:
1730
ngsyse8:
1731
;     cmp  eax,9
1731
;     cmp  eax,9
1732
	dec	ebx
1732
	dec	ebx
1733
     	jnz  ngsyse9
1733
     	jnz  ngsyse9
1734
     	mov  eax,[timer_ticks] ;[0xfdf0]
1734
     	mov  eax,[timer_ticks] ;[0xfdf0]
1735
     	mov  [esp+32],eax
1735
     	mov  [esp+32],eax
1736
     	ret
1736
     	ret
1737
ngsyse9:
1737
ngsyse9:
1738
;     cmp  eax,11
1738
;     cmp  eax,11
1739
	sub	ebx,2
1739
	sub	ebx,2
1740
     	jnz  ngsyse11
1740
     	jnz  ngsyse11
1741
     	mov eax,[lba_read_enabled]
1741
     	mov eax,[lba_read_enabled]
1742
     	mov  [esp+32],eax
1742
     	mov  [esp+32],eax
1743
     	ret
1743
     	ret
1744
ngsyse11:
1744
ngsyse11:
1745
;     cmp  eax,12
1745
;     cmp  eax,12
1746
	dec	ebx
1746
	dec	ebx
1747
     	jnz  ngsyse12
1747
     	jnz  ngsyse12
1748
     	mov eax,[pci_access_enabled]
1748
     	mov eax,[pci_access_enabled]
1749
     	mov  [esp+32],eax
1749
     	mov  [esp+32],eax
1750
     	ret
1750
     	ret
1751
ngsyse12:
1751
ngsyse12:
1752
     	mov  [esp+32],dword 1
1752
     	mov  [esp+32],dword 1
1753
     	ret
1753
     	ret
1754
 
1754
 
1755
	
1755
	
1756
get_timer_ticks:
1756
get_timer_ticks:
1757
    	mov eax,[timer_ticks]
1757
    	mov eax,[timer_ticks]
1758
    	ret
1758
    	ret
1759
 
1759
 
1760
iglobal
1760
iglobal
1761
align 4
1761
align 4
1762
mousefn dd msscreen, mswin, msbutton, msset
1762
mousefn dd msscreen, mswin, msbutton, msset
1763
        dd app_load_cursor
1763
        dd app_load_cursor
1764
        dd app_set_cursor
1764
        dd app_set_cursor
1765
        dd app_delete_cursor
1765
        dd app_delete_cursor
1766
        dd msz
1766
        dd msz
1767
endg
1767
endg
1768
 
1768
 
1769
readmousepos:
1769
readmousepos:
1770
 
1770
 
1771
; eax=0 screen relative
1771
; eax=0 screen relative
1772
; eax=1 window relative
1772
; eax=1 window relative
1773
; eax=2 buttons pressed
1773
; eax=2 buttons pressed
1774
; eax=3 set mouse pos   ; reserved
1774
; eax=3 set mouse pos   ; reserved
1775
; eax=4 load cursor
1775
; eax=4 load cursor
1776
; eax=5 set cursor
1776
; eax=5 set cursor
1777
; eax=6 delete cursor   ; reserved
1777
; eax=6 delete cursor   ; reserved
1778
; eax=7 get mouse_z
1778
; eax=7 get mouse_z
1779
 
1779
 
1780
           cmp ebx, 7
1780
           cmp ebx, 7
1781
           ja msset
1781
           ja msset
1782
           jmp [mousefn+ebx*4]
1782
           jmp [mousefn+ebx*4]
1783
msscreen:
1783
msscreen:
1784
           mov  eax,[MOUSE_X]
1784
           mov  eax,[MOUSE_X]
1785
           shl  eax,16
1785
           shl  eax,16
1786
           mov  ax,[MOUSE_Y]
1786
           mov  ax,[MOUSE_Y]
1787
           mov  [esp+36-4],eax
1787
           mov  [esp+36-4],eax
1788
           ret
1788
           ret
1789
mswin:
1789
mswin:
1790
           mov  eax,[MOUSE_X]
1790
           mov  eax,[MOUSE_X]
1791
           shl  eax,16
1791
           shl  eax,16
1792
           mov  ax,[MOUSE_Y]
1792
           mov  ax,[MOUSE_Y]
1793
           mov  esi,[TASK_BASE]
1793
           mov  esi,[TASK_BASE]
1794
           mov  bx, word [esi-twdw+WDATA.box.left]
1794
           mov  bx, word [esi-twdw+WDATA.box.left]
1795
           shl  ebx,16
1795
           shl  ebx,16
1796
           mov  bx, word [esi-twdw+WDATA.box.top]
1796
           mov  bx, word [esi-twdw+WDATA.box.top]
1797
           sub  eax,ebx
1797
           sub  eax,ebx
1798
 
1798
 
1799
           mov  edi,[CURRENT_TASK]
1799
           mov  edi,[CURRENT_TASK]
1800
           shl  edi,8
1800
           shl  edi,8
1801
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1801
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1802
           rol  eax,16
1802
           rol  eax,16
1803
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1803
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1804
           rol  eax,16
1804
           rol  eax,16
1805
           mov  [esp+36-4],eax
1805
           mov  [esp+36-4],eax
1806
           ret
1806
           ret
1807
msbutton:
1807
msbutton:
1808
           movzx eax,byte [BTN_DOWN]
1808
           movzx eax,byte [BTN_DOWN]
1809
           mov  [esp+36-4],eax
1809
           mov  [esp+36-4],eax
1810
           ret
1810
           ret
1811
msz:
1811
msz:
1812
           mov   edi, [TASK_COUNT]
1812
           mov   edi, [TASK_COUNT]
1813
           movzx edi, word [WIN_POS + edi*2]
1813
           movzx edi, word [WIN_POS + edi*2]
1814
           cmp   edi, [CURRENT_TASK]
1814
           cmp   edi, [CURRENT_TASK]
1815
           jne   @f
1815
           jne   @f
1816
           mov   ax,[MOUSE_SCROLL_H]
1816
           mov   ax,[MOUSE_SCROLL_H]
1817
           shl   eax,16
1817
           shl   eax,16
1818
           mov   ax,[MOUSE_SCROLL_V]
1818
           mov   ax,[MOUSE_SCROLL_V]
1819
           mov   [esp+36-4],eax
1819
           mov   [esp+36-4],eax
1820
           and   [MOUSE_SCROLL_H],word 0
1820
           and   [MOUSE_SCROLL_H],word 0
1821
           and   [MOUSE_SCROLL_V],word 0
1821
           and   [MOUSE_SCROLL_V],word 0
1822
           ret
1822
           ret
1823
       @@:
1823
       @@:
1824
           and  [esp+36-4],dword 0
1824
           and  [esp+36-4],dword 0
1825
;           ret
1825
;           ret
1826
msset:
1826
msset:
1827
           ret
1827
           ret
1828
 
1828
 
1829
app_load_cursor:
1829
app_load_cursor:
1830
           cmp ecx, OS_BASE
1830
           cmp ecx, OS_BASE
1831
           jae msset
1831
           jae msset
1832
           stdcall load_cursor, ecx, edx
1832
           stdcall load_cursor, ecx, edx
1833
           mov [esp+36-4], eax
1833
           mov [esp+36-4], eax
1834
           ret
1834
           ret
1835
 
1835
 
1836
app_set_cursor:
1836
app_set_cursor:
1837
           stdcall set_cursor, ecx
1837
           stdcall set_cursor, ecx
1838
           mov [esp+36-4], eax
1838
           mov [esp+36-4], eax
1839
           ret
1839
           ret
1840
 
1840
 
1841
app_delete_cursor:
1841
app_delete_cursor:
1842
           stdcall delete_cursor, ecx
1842
           stdcall delete_cursor, ecx
1843
           mov [esp+36-4], eax
1843
           mov [esp+36-4], eax
1844
           ret
1844
           ret
1845
 
1845
 
1846
is_input:
1846
is_input:
1847
 
1847
 
1848
   push edx
1848
   push edx
1849
   mov  dx,word [midisp]
1849
   mov  dx,word [midisp]
1850
   in   al,dx
1850
   in   al,dx
1851
   and  al,0x80
1851
   and  al,0x80
1852
   pop  edx
1852
   pop  edx
1853
   ret
1853
   ret
1854
 
1854
 
1855
is_output:
1855
is_output:
1856
 
1856
 
1857
   push edx
1857
   push edx
1858
   mov  dx,word [midisp]
1858
   mov  dx,word [midisp]
1859
   in   al,dx
1859
   in   al,dx
1860
   and  al,0x40
1860
   and  al,0x40
1861
   pop  edx
1861
   pop  edx
1862
   ret
1862
   ret
1863
 
1863
 
1864
 
1864
 
1865
get_mpu_in:
1865
get_mpu_in:
1866
 
1866
 
1867
   push edx
1867
   push edx
1868
   mov  dx,word [mididp]
1868
   mov  dx,word [mididp]
1869
   in   al,dx
1869
   in   al,dx
1870
   pop  edx
1870
   pop  edx
1871
   ret
1871
   ret
1872
 
1872
 
1873
 
1873
 
1874
put_mpu_out:
1874
put_mpu_out:
1875
 
1875
 
1876
   push edx
1876
   push edx
1877
   mov  dx,word [mididp]
1877
   mov  dx,word [mididp]
1878
   out  dx,al
1878
   out  dx,al
1879
   pop  edx
1879
   pop  edx
1880
   ret
1880
   ret
1881
 
1881
 
1882
 
1882
 
1883
 
1883
 
1884
align 4
1884
align 4
1885
 
1885
 
1886
sys_midi:
1886
sys_midi:
1887
	cmp  [mididp],0
1887
	cmp  [mididp],0
1888
	jnz  sm0
1888
	jnz  sm0
1889
	mov  [esp+36],dword 1
1889
	mov  [esp+36],dword 1
1890
	ret
1890
	ret
1891
sm0:
1891
sm0:
1892
	and  [esp+36],dword 0
1892
	and  [esp+36],dword 0
1893
	dec  ebx
1893
	dec  ebx
1894
	jnz  smn1
1894
	jnz  smn1
1895
 ;    call setuart
1895
 ;    call setuart
1896
su1:
1896
su1:
1897
	call is_output
1897
	call is_output
1898
	test al,al
1898
	test al,al
1899
	jnz  su1
1899
	jnz  su1
1900
	mov  dx,word [midisp]
1900
	mov  dx,word [midisp]
1901
	mov  al,0xff
1901
	mov  al,0xff
1902
	out  dx,al
1902
	out  dx,al
1903
su2:
1903
su2:
1904
	mov  dx,word [midisp]
1904
	mov  dx,word [midisp]
1905
	mov  al,0xff
1905
	mov  al,0xff
1906
	out  dx,al
1906
	out  dx,al
1907
	call is_input
1907
	call is_input
1908
	test al,al
1908
	test al,al
1909
	jnz  su2
1909
	jnz  su2
1910
	call get_mpu_in
1910
	call get_mpu_in
1911
	cmp  al,0xfe
1911
	cmp  al,0xfe
1912
	jnz  su2
1912
	jnz  su2
1913
su3:
1913
su3:
1914
	call is_output
1914
	call is_output
1915
	test  al,al
1915
	test  al,al
1916
	jnz  su3
1916
	jnz  su3
1917
	mov  dx,word [midisp]
1917
	mov  dx,word [midisp]
1918
	mov  al,0x3f
1918
	mov  al,0x3f
1919
	out  dx,al
1919
	out  dx,al
1920
	ret
1920
	ret
1921
smn1:
1921
smn1:
1922
	dec  ebx
1922
	dec  ebx
1923
	jnz  smn2
1923
	jnz  smn2
1924
sm10:
1924
sm10:
1925
	call get_mpu_in
1925
	call get_mpu_in
1926
	call is_output
1926
	call is_output
1927
	test al,al
1927
	test al,al
1928
	jnz  sm10
1928
	jnz  sm10
1929
	mov  al,bl
1929
	mov  al,bl
1930
	call put_mpu_out
1930
	call put_mpu_out
1931
	smn2:
1931
	smn2:
1932
	ret
1932
	ret
1933
 
1933
 
1934
detect_devices:
1934
detect_devices:
1935
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1935
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1936
;include 'detect/commouse.inc'
1936
;include 'detect/commouse.inc'
1937
;include 'detect/ps2mouse.inc'
1937
;include 'detect/ps2mouse.inc'
1938
;include 'detect/dev_fd.inc'
1938
;include 'detect/dev_fd.inc'
1939
;include 'detect/dev_hdcd.inc'
1939
;include 'detect/dev_hdcd.inc'
1940
;include 'detect/sear_par.inc'
1940
;include 'detect/sear_par.inc'
1941
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1941
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1942
    ret
1942
    ret
1943
 
1943
 
1944
sys_end:
1944
sys_end:
1945
 
1945
 
1946
     mov ecx, [current_slot]
1946
     mov ecx, [current_slot]
1947
     mov eax, [ecx+APPDATA.tls_base]
1947
     mov eax, [ecx+APPDATA.tls_base]
1948
     test eax, eax
1948
     test eax, eax
1949
     jz @F
1949
     jz @F
1950
 
1950
 
1951
     stdcall user_free, eax
1951
     stdcall user_free, eax
1952
@@:
1952
@@:
1953
 
1953
 
1954
     mov   eax,[TASK_BASE]
1954
     mov   eax,[TASK_BASE]
1955
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1955
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1956
 
1956
 
1957
    waitterm:            ; wait here for termination
1957
    waitterm:            ; wait here for termination
1958
     mov   ebx,100
1958
     mov   ebx,100
1959
     call  delay_hs
1959
     call  delay_hs
1960
     jmp   waitterm
1960
     jmp   waitterm
1961
 
1961
 
1962
iglobal
1962
iglobal
1963
align 4
1963
align 4
1964
sys_system_table:
1964
sys_system_table:
1965
        dd      exit_for_anyone         ; 1 = obsolete
1965
        dd      exit_for_anyone         ; 1 = obsolete
1966
        dd      sysfn_terminate         ; 2 = terminate thread
1966
        dd      sysfn_terminate         ; 2 = terminate thread
1967
        dd      sysfn_activate          ; 3 = activate window
1967
        dd      sysfn_activate          ; 3 = activate window
1968
        dd      sysfn_getidletime       ; 4 = get idle time
1968
        dd      sysfn_getidletime       ; 4 = get idle time
1969
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1969
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1970
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1970
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1971
        dd      sysfn_getactive         ; 7 = get active window
1971
        dd      sysfn_getactive         ; 7 = get active window
1972
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1972
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1973
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
1973
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
1974
        dd      sysfn_minimize          ; 10 = minimize window
1974
        dd      sysfn_minimize          ; 10 = minimize window
1975
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
1975
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
1976
        dd      sysfn_lastkey           ; 12 = get last pressed key
1976
        dd      sysfn_lastkey           ; 12 = get last pressed key
1977
        dd      sysfn_getversion        ; 13 = get kernel version
1977
        dd      sysfn_getversion        ; 13 = get kernel version
1978
        dd      sysfn_waitretrace       ; 14 = wait retrace
1978
        dd      sysfn_waitretrace       ; 14 = wait retrace
1979
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1979
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1980
        dd      sysfn_getfreemem        ; 16 = get free memory size
1980
        dd      sysfn_getfreemem        ; 16 = get free memory size
1981
        dd      sysfn_getallmem         ; 17 = get total memory size
1981
        dd      sysfn_getallmem         ; 17 = get total memory size
1982
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1982
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1983
                                        ;                 instead of slot
1983
                                        ;                 instead of slot
1984
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1984
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1985
        dd      sysfn_meminfo           ; 20 = get extended memory info
1985
        dd      sysfn_meminfo           ; 20 = get extended memory info
1986
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
1986
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
1987
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
1987
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
1988
sysfn_num = ($ - sys_system_table)/4
1988
sysfn_num = ($ - sys_system_table)/4
1989
endg
1989
endg
1990
 
1990
 
1991
sys_system:
1991
sys_system:
1992
        dec     ebx
1992
        dec     ebx
1993
        cmp     ebx, sysfn_num
1993
        cmp     ebx, sysfn_num
1994
        jae     @f
1994
        jae     @f
1995
        jmp     dword [sys_system_table + ebx*4]
1995
        jmp     dword [sys_system_table + ebx*4]
1996
@@:
1996
@@:
1997
        ret
1997
        ret
1998
 
1998
 
1999
 
1999
 
2000
sysfn_shutdown:          ; 18.9 = system shutdown
2000
sysfn_shutdown:          ; 18.9 = system shutdown
2001
     cmp  ecx,1
2001
     cmp  ecx,1
2002
     jl   exit_for_anyone
2002
     jl   exit_for_anyone
2003
     cmp  ecx,4
2003
     cmp  ecx,4
2004
     jg   exit_for_anyone
2004
     jg   exit_for_anyone
2005
     mov  [BOOT_VAR+0x9030],cl
2005
     mov  [BOOT_VAR+0x9030],cl
2006
 
2006
 
2007
     mov  eax,[TASK_COUNT]
2007
     mov  eax,[TASK_COUNT]
2008
     mov  [SYS_SHUTDOWN],al
2008
     mov  [SYS_SHUTDOWN],al
2009
     mov  [shutdown_processes],eax
2009
     mov  [shutdown_processes],eax
2010
     and  dword [esp+32], 0
2010
     and  dword [esp+32], 0
2011
 exit_for_anyone:
2011
 exit_for_anyone:
2012
     ret
2012
     ret
2013
  uglobal
2013
  uglobal
2014
   shutdown_processes: dd 0x0
2014
   shutdown_processes: dd 0x0
2015
  endg
2015
  endg
2016
 
2016
 
2017
sysfn_terminate:        ; 18.2 = TERMINATE
2017
sysfn_terminate:        ; 18.2 = TERMINATE
2018
     cmp  ecx,2
2018
     cmp  ecx,2
2019
     jb   noprocessterminate
2019
     jb   noprocessterminate
2020
     mov  edx,[TASK_COUNT]
2020
     mov  edx,[TASK_COUNT]
2021
     cmp  ecx,edx
2021
     cmp  ecx,edx
2022
     ja   noprocessterminate
2022
     ja   noprocessterminate
2023
     mov  eax,[TASK_COUNT]
2023
     mov  eax,[TASK_COUNT]
2024
     shl  ecx,5
2024
     shl  ecx,5
2025
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
2025
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
2026
     add  ecx,CURRENT_TASK+TASKDATA.state
2026
     add  ecx,CURRENT_TASK+TASKDATA.state
2027
     cmp  byte [ecx], 9
2027
     cmp  byte [ecx], 9
2028
     jz   noprocessterminate
2028
     jz   noprocessterminate
2029
 
2029
 
2030
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2030
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2031
     mov  [ecx],byte 3       ; clear possible i40's
2031
     mov  [ecx],byte 3       ; clear possible i40's
2032
     ;call MEM_Heap_UnLock
2032
     ;call MEM_Heap_UnLock
2033
 
2033
 
2034
     cmp  edx,[application_table_status]    ; clear app table stat
2034
     cmp  edx,[application_table_status]    ; clear app table stat
2035
     jne  noatsc
2035
     jne  noatsc
2036
     mov  [application_table_status],0
2036
     mov  [application_table_status],0
2037
   noatsc:
2037
   noatsc:
2038
   noprocessterminate:
2038
   noprocessterminate:
2039
     ret
2039
     ret
2040
 
2040
 
2041
sysfn_terminate2:
2041
sysfn_terminate2:
2042
;lock application_table_status mutex
2042
;lock application_table_status mutex
2043
.table_status:
2043
.table_status:
2044
    cli
2044
    cli
2045
    cmp    [application_table_status],0
2045
    cmp    [application_table_status],0
2046
    je     .stf
2046
    je     .stf
2047
    sti
2047
    sti
2048
    call   change_task
2048
    call   change_task
2049
    jmp    .table_status
2049
    jmp    .table_status
2050
.stf:
2050
.stf:
2051
    call   set_application_table_status
2051
    call   set_application_table_status
2052
    mov    eax,ecx
2052
    mov    eax,ecx
2053
    call   pid_to_slot
2053
    call   pid_to_slot
2054
    test   eax,eax
2054
    test   eax,eax
2055
    jz     .not_found
2055
    jz     .not_found
2056
    mov    ecx,eax
2056
    mov    ecx,eax
2057
    cli
2057
    cli
2058
    call   sysfn_terminate
2058
    call   sysfn_terminate
2059
    mov    [application_table_status],0
2059
    mov    [application_table_status],0
2060
    sti
2060
    sti
2061
    and    dword [esp+32],0
2061
    and    dword [esp+32],0
2062
    ret
2062
    ret
2063
.not_found:
2063
.not_found:
2064
    mov    [application_table_status],0
2064
    mov    [application_table_status],0
2065
    or     dword [esp+32],-1
2065
    or     dword [esp+32],-1
2066
    ret
2066
    ret
2067
 
2067
 
2068
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2068
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2069
     cmp  ecx,2
2069
     cmp  ecx,2
2070
     jb   .nowindowactivate
2070
     jb   .nowindowactivate
2071
     cmp  ecx,[TASK_COUNT]
2071
     cmp  ecx,[TASK_COUNT]
2072
     ja   .nowindowactivate
2072
     ja   .nowindowactivate
2073
 
2073
 
2074
     mov   [window_minimize], 2   ; restore window if minimized
2074
     mov   [window_minimize], 2   ; restore window if minimized
2075
 
2075
 
2076
     movzx esi, word [WIN_STACK + ecx*2]
2076
     movzx esi, word [WIN_STACK + ecx*2]
2077
     cmp   esi, [TASK_COUNT]
2077
     cmp   esi, [TASK_COUNT]
2078
     je    .nowindowactivate ; already active
2078
     je    .nowindowactivate ; already active
2079
 
2079
 
2080
     mov   edi, ecx
2080
     mov   edi, ecx
2081
     shl   edi, 5
2081
     shl   edi, 5
2082
     add   edi, window_data
2082
     add   edi, window_data
2083
     movzx esi, word [WIN_STACK + ecx * 2]
2083
     movzx esi, word [WIN_STACK + ecx * 2]
2084
     lea   esi, [WIN_POS + esi * 2]
2084
     lea   esi, [WIN_POS + esi * 2]
2085
     call  waredraw
2085
     call  waredraw
2086
.nowindowactivate:
2086
.nowindowactivate:
2087
     ret
2087
     ret
2088
 
2088
 
2089
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2089
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2090
     mov  eax,[idleusesec]
2090
     mov  eax,[idleusesec]
2091
     mov  [esp+32], eax
2091
     mov  [esp+32], eax
2092
     ret
2092
     ret
2093
 
2093
 
2094
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2094
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2095
     mov  eax,[CPU_FREQ]
2095
     mov  eax,[CPU_FREQ]
2096
     mov  [esp+32], eax
2096
     mov  [esp+32], eax
2097
     ret
2097
     ret
2098
 
2098
 
2099
;  SAVE ramdisk to /hd/1/menuet.img
2099
;  SAVE ramdisk to /hd/1/menuet.img
2100
;!!!!!!!!!!!!!!!!!!!!!!!!
2100
;!!!!!!!!!!!!!!!!!!!!!!!!
2101
   include 'blkdev/rdsave.inc'
2101
   include 'blkdev/rdsave.inc'
2102
;!!!!!!!!!!!!!!!!!!!!!!!!
2102
;!!!!!!!!!!!!!!!!!!!!!!!!
2103
align 4
2103
align 4
2104
sysfn_getactive:        ; 18.7 = get active window
2104
sysfn_getactive:        ; 18.7 = get active window
2105
     mov  eax, [TASK_COUNT]
2105
     mov  eax, [TASK_COUNT]
2106
   movzx  eax, word [WIN_POS + eax*2]
2106
   movzx  eax, word [WIN_POS + eax*2]
2107
     mov  [esp+32],eax
2107
     mov  [esp+32],eax
2108
     ret
2108
     ret
2109
 
2109
 
2110
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2110
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2111
;     cmp  ecx,1
2111
;     cmp  ecx,1
2112
     dec  ecx
2112
     dec  ecx
2113
     jnz  nogetsoundflag
2113
     jnz  nogetsoundflag
2114
     movzx  eax,byte [sound_flag] ; get sound_flag
2114
     movzx  eax,byte [sound_flag] ; get sound_flag
2115
     mov  [esp+32],eax
2115
     mov  [esp+32],eax
2116
     ret
2116
     ret
2117
 nogetsoundflag:
2117
 nogetsoundflag:
2118
;     cmp  ecx,2
2118
;     cmp  ecx,2
2119
     dec  ecx
2119
     dec  ecx
2120
     jnz  nosoundflag
2120
     jnz  nosoundflag
2121
     xor  byte [sound_flag], 1
2121
     xor  byte [sound_flag], 1
2122
 nosoundflag:
2122
 nosoundflag:
2123
     ret
2123
     ret
2124
 
2124
 
2125
sysfn_minimize:         ; 18.10 = minimize window
2125
sysfn_minimize:         ; 18.10 = minimize window
2126
     mov   [window_minimize],1
2126
     mov   [window_minimize],1
2127
     ret
2127
     ret
2128
align 4
2128
align 4
2129
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2129
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2130
;     cmp  ecx,1
2130
;     cmp  ecx,1
2131
     dec  ecx
2131
     dec  ecx
2132
     jnz  full_table
2132
     jnz  full_table
2133
  small_table:
2133
  small_table:
2134
     call for_all_tables
2134
     call for_all_tables
2135
     mov ecx,10
2135
     mov ecx,10
2136
     cld
2136
     cld
2137
     rep movsb
2137
     rep movsb
2138
     ret
2138
     ret
2139
   for_all_tables:
2139
   for_all_tables:
2140
     mov edi,edx
2140
     mov edi,edx
2141
     mov esi,DRIVE_DATA
2141
     mov esi,DRIVE_DATA
2142
     ret
2142
     ret
2143
  full_table:
2143
  full_table:
2144
;     cmp  ecx,2
2144
;     cmp  ecx,2
2145
     dec  ecx
2145
     dec  ecx
2146
     jnz  exit_for_anyone
2146
     jnz  exit_for_anyone
2147
     call for_all_tables
2147
     call for_all_tables
2148
     mov ecx,16384
2148
     mov ecx,16384
2149
     cld
2149
     cld
2150
     rep movsd
2150
     rep movsd
2151
     ret
2151
     ret
2152
 
2152
 
2153
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2153
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2154
        and     dword [esp+32], 0
2154
        and     dword [esp+32], 0
2155
        ret
2155
        ret
2156
 
2156
 
2157
sysfn_getversion:       ; 18.13 = get kernel ID and version
2157
sysfn_getversion:       ; 18.13 = get kernel ID and version
2158
     mov edi,ebx
2158
     mov edi,ebx
2159
     mov esi,version_inf
2159
     mov esi,version_inf
2160
     mov ecx,version_end-version_inf
2160
     mov ecx,version_end-version_inf
2161
     rep movsb
2161
     rep movsb
2162
     ret
2162
     ret
2163
 
2163
 
2164
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2164
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2165
     ;wait retrace functions
2165
     ;wait retrace functions
2166
 sys_wait_retrace:
2166
 sys_wait_retrace:
2167
     mov edx,0x3da
2167
     mov edx,0x3da
2168
 WaitRetrace_loop:
2168
 WaitRetrace_loop:
2169
     in al,dx
2169
     in al,dx
2170
     test al,1000b
2170
     test al,1000b
2171
     jz WaitRetrace_loop
2171
     jz WaitRetrace_loop
2172
     and [esp+32],dword 0
2172
     and [esp+32],dword 0
2173
     ret
2173
     ret
2174
 
2174
 
2175
align 4
2175
align 4
2176
sysfn_centermouse:      ; 18.15 = mouse centered
2176
sysfn_centermouse:      ; 18.15 = mouse centered
2177
; removed here by 
2177
; removed here by 
2178
;     call  mouse_centered
2178
;     call  mouse_centered
2179
;* mouse centered - start code- Mario79
2179
;* mouse centered - start code- Mario79
2180
;mouse_centered:
2180
;mouse_centered:
2181
;        push  eax
2181
;        push  eax
2182
        mov   eax,[Screen_Max_X]
2182
        mov   eax,[Screen_Max_X]
2183
        shr   eax,1
2183
        shr   eax,1
2184
        mov   [MOUSE_X],ax
2184
        mov   [MOUSE_X],ax
2185
        mov   eax,[Screen_Max_Y]
2185
        mov   eax,[Screen_Max_Y]
2186
        shr   eax,1
2186
        shr   eax,1
2187
        mov   [MOUSE_Y],ax
2187
        mov   [MOUSE_Y],ax
2188
;        ret
2188
;        ret
2189
;* mouse centered - end code- Mario79
2189
;* mouse centered - end code- Mario79
2190
	xor   eax,eax
2190
	xor   eax,eax
2191
        and   [esp+32],eax
2191
        and   [esp+32],eax
2192
;        pop   eax
2192
;        pop   eax
2193
 
2193
 
2194
     ret
2194
     ret
2195
align 4
2195
align 4
2196
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2196
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2197
     test ecx,ecx  ; get mouse speed factor
2197
     test ecx,ecx  ; get mouse speed factor
2198
     jnz  .set_mouse_acceleration
2198
     jnz  .set_mouse_acceleration
2199
     xor  eax,eax
2199
     xor  eax,eax
2200
     mov  ax,[mouse_speed_factor]
2200
     mov  ax,[mouse_speed_factor]
2201
     mov  [esp+32],eax
2201
     mov  [esp+32],eax
2202
     ret
2202
     ret
2203
 .set_mouse_acceleration:
2203
 .set_mouse_acceleration:
2204
;     cmp  ecx,1  ; set mouse speed factor
2204
;     cmp  ecx,1  ; set mouse speed factor
2205
     dec  ecx
2205
     dec  ecx
2206
     jnz  .get_mouse_delay
2206
     jnz  .get_mouse_delay
2207
     mov  [mouse_speed_factor],dx
2207
     mov  [mouse_speed_factor],dx
2208
     ret
2208
     ret
2209
 .get_mouse_delay:
2209
 .get_mouse_delay:
2210
;     cmp  ecx,2  ; get mouse delay
2210
;     cmp  ecx,2  ; get mouse delay
2211
     dec  ecx
2211
     dec  ecx
2212
     jnz  .set_mouse_delay
2212
     jnz  .set_mouse_delay
2213
     mov  eax,[mouse_delay]
2213
     mov  eax,[mouse_delay]
2214
     mov  [esp+32],eax
2214
     mov  [esp+32],eax
2215
     ret
2215
     ret
2216
 .set_mouse_delay:
2216
 .set_mouse_delay:
2217
;     cmp  ecx,3  ; set mouse delay
2217
;     cmp  ecx,3  ; set mouse delay
2218
     dec  ecx
2218
     dec  ecx
2219
     jnz  .set_pointer_position
2219
     jnz  .set_pointer_position
2220
     mov  [mouse_delay],edx
2220
     mov  [mouse_delay],edx
2221
     ret
2221
     ret
2222
 .set_pointer_position:
2222
 .set_pointer_position:
2223
;     cmp  ecx,4  ; set mouse pointer position
2223
;     cmp  ecx,4  ; set mouse pointer position
2224
     dec   ecx
2224
     dec   ecx
2225
     jnz  .set_mouse_button
2225
     jnz  .set_mouse_button
2226
     mov   [MOUSE_Y],dx    ;y
2226
     mov   [MOUSE_Y],dx    ;y
2227
     ror   edx,16
2227
     ror   edx,16
2228
     mov   [MOUSE_X],dx    ;x
2228
     mov   [MOUSE_X],dx    ;x
2229
     rol   edx,16
2229
     rol   edx,16
2230
     ret
2230
     ret
2231
 .set_mouse_button:
2231
 .set_mouse_button:
2232
;     cmp   ecx,5  ; set mouse button features
2232
;     cmp   ecx,5  ; set mouse button features
2233
     dec   ecx
2233
     dec   ecx
2234
     jnz  .end
2234
     jnz  .end
2235
     mov   [BTN_DOWN],dl
2235
     mov   [BTN_DOWN],dl
2236
     mov   [mouse_active],1
2236
     mov   [mouse_active],1
2237
 .end:
2237
 .end:
2238
     ret
2238
     ret
2239
 
2239
 
2240
sysfn_getfreemem:
2240
sysfn_getfreemem:
2241
     mov eax, [pg_data.pages_free]
2241
     mov eax, [pg_data.pages_free]
2242
     shl eax, 2
2242
     shl eax, 2
2243
     mov [esp+32],eax
2243
     mov [esp+32],eax
2244
     ret
2244
     ret
2245
 
2245
 
2246
sysfn_getallmem:
2246
sysfn_getallmem:
2247
     mov  eax,[MEM_AMOUNT]
2247
     mov  eax,[MEM_AMOUNT]
2248
     shr eax, 10
2248
     shr eax, 10
2249
     mov  [esp+32],eax
2249
     mov  [esp+32],eax
2250
     ret
2250
     ret
2251
 
2251
 
2252
; // Alver, 2007-22-08 // {
2252
; // Alver, 2007-22-08 // {
2253
sysfn_pid_to_slot:
2253
sysfn_pid_to_slot:
2254
     mov   eax, ecx
2254
     mov   eax, ecx
2255
     call  pid_to_slot
2255
     call  pid_to_slot
2256
     mov   [esp+32], eax
2256
     mov   [esp+32], eax
2257
     ret
2257
     ret
2258
 
2258
 
2259
sysfn_min_rest_window:
2259
sysfn_min_rest_window:
2260
     pushad
2260
     pushad
2261
     mov   eax, edx      ; ebx - operating
2261
     mov   eax, edx      ; ebx - operating
2262
     shr   ecx, 1
2262
     shr   ecx, 1
2263
     jnc    @f
2263
     jnc    @f
2264
     call  pid_to_slot
2264
     call  pid_to_slot
2265
@@:
2265
@@:
2266
     or    eax, eax      ; eax - number of slot
2266
     or    eax, eax      ; eax - number of slot
2267
     jz    .error
2267
     jz    .error
2268
     cmp   eax, 255         ; varify maximal slot number
2268
     cmp   eax, 255         ; varify maximal slot number
2269
     ja    .error
2269
     ja    .error
2270
     movzx eax, word [WIN_STACK + eax*2]
2270
     movzx eax, word [WIN_STACK + eax*2]
2271
     shr   ecx, 1
2271
     shr   ecx, 1
2272
     jc    .restore
2272
     jc    .restore
2273
 ; .minimize:
2273
 ; .minimize:
2274
     call  minimize_window
2274
     call  minimize_window
2275
     jmp   .exit
2275
     jmp   .exit
2276
.restore:
2276
.restore:
2277
     call  restore_minimized_window
2277
     call  restore_minimized_window
2278
.exit:
2278
.exit:
2279
     popad
2279
     popad
2280
     xor   eax, eax
2280
     xor   eax, eax
2281
     mov   [esp+32], eax
2281
     mov   [esp+32], eax
2282
     ret
2282
     ret
2283
.error:
2283
.error:
2284
     popad
2284
     popad
2285
     xor   eax, eax
2285
     xor   eax, eax
2286
     dec   eax
2286
     dec   eax
2287
     mov   [esp+32], eax
2287
     mov   [esp+32], eax
2288
     ret
2288
     ret
2289
; } \\ Alver, 2007-22-08 \\
2289
; } \\ Alver, 2007-22-08 \\
2290
 
2290
 
2291
uglobal
2291
uglobal
2292
;// mike.dld, 2006-29-01 [
2292
;// mike.dld, 2006-29-01 [
2293
screen_workarea RECT
2293
screen_workarea RECT
2294
;// mike.dld, 2006-29-01 ]
2294
;// mike.dld, 2006-29-01 ]
2295
window_minimize db 0
2295
window_minimize db 0
2296
sound_flag      db 0
2296
sound_flag      db 0
2297
endg
2297
endg
2298
 
2298
 
2299
iglobal
2299
iglobal
2300
version_inf:
2300
version_inf:
2301
  db 0,7,5,0  ; version 0.7.5.0
2301
  db 0,7,5,0  ; version 0.7.5.0
2302
  db UID_KOLIBRI
2302
  db UID_KOLIBRI
2303
  dd __REV__
2303
  dd __REV__
2304
version_end:
2304
version_end:
2305
endg
2305
endg
2306
 
2306
 
2307
UID_NONE=0
2307
UID_NONE=0
2308
UID_MENUETOS=1   ;official
2308
UID_MENUETOS=1   ;official
2309
UID_KOLIBRI=2    ;russian
2309
UID_KOLIBRI=2    ;russian
2310
 
2310
 
2311
sys_cachetodiskette:
2311
sys_cachetodiskette:
2312
        cmp     ebx, 1
2312
        cmp     ebx, 1
2313
        jne     .no_floppy_a_save
2313
        jne     .no_floppy_a_save
2314
        mov     [flp_number], 1
2314
        mov     [flp_number], 1
2315
        jmp     .save_image_on_floppy
2315
        jmp     .save_image_on_floppy
2316
.no_floppy_a_save:
2316
.no_floppy_a_save:
2317
        cmp     ebx, 2
2317
        cmp     ebx, 2
2318
        jne     .no_floppy_b_save
2318
        jne     .no_floppy_b_save
2319
        mov     [flp_number], 2
2319
        mov     [flp_number], 2
2320
.save_image_on_floppy:
2320
.save_image_on_floppy:
2321
        call    save_image
2321
        call    save_image
2322
        mov     [esp + 32], dword 0
2322
        mov     [esp + 32], dword 0
2323
        cmp     [FDC_Status], 0
2323
        cmp     [FDC_Status], 0
2324
        je      .yes_floppy_save
2324
        je      .yes_floppy_save
2325
.no_floppy_b_save:
2325
.no_floppy_b_save:
2326
        mov     [esp + 32], dword 1
2326
        mov     [esp + 32], dword 1
2327
.yes_floppy_save:
2327
.yes_floppy_save:
2328
        ret
2328
        ret
2329
 
2329
 
2330
uglobal
2330
uglobal
2331
;  bgrchanged  dd  0x0
2331
;  bgrchanged  dd  0x0
2332
align 4
2332
align 4
2333
bgrlockpid dd 0
2333
bgrlockpid dd 0
2334
bgrlock db 0
2334
bgrlock db 0
2335
endg
2335
endg
2336
 
2336
 
2337
sys_background:
2337
sys_background:
2338
 
2338
 
2339
    cmp   ebx,1                            ; BACKGROUND SIZE
2339
    cmp   ebx,1                            ; BACKGROUND SIZE
2340
    jnz   nosb1
2340
    jnz   nosb1
2341
    test  ecx,ecx
2341
    test  ecx,ecx
2342
;    cmp   ecx,0
2342
;    cmp   ecx,0
2343
    jz    sbgrr
2343
    jz    sbgrr
2344
    test  edx,edx
2344
    test  edx,edx
2345
;    cmp   edx,0
2345
;    cmp   edx,0
2346
    jz    sbgrr
2346
    jz    sbgrr
2347
@@:
2347
@@:
2348
;;Maxis use atomic bts for mutexes  4.4.2009
2348
;;Maxis use atomic bts for mutexes  4.4.2009
2349
        bts     dword [bgrlock], 0
2349
        bts     dword [bgrlock], 0
2350
        jnc     @f
2350
        jnc     @f
2351
        call    change_task
2351
        call    change_task
2352
        jmp     @b
2352
        jmp     @b
2353
@@:
2353
@@:
2354
    mov   [BgrDataWidth],ecx
2354
    mov   [BgrDataWidth],ecx
2355
    mov   [BgrDataHeight],edx
2355
    mov   [BgrDataHeight],edx
2356
;    mov   [bgrchanged],1
2356
;    mov   [bgrchanged],1
2357
 
2357
 
2358
    pushad
2358
    pushad
2359
; return memory for old background
2359
; return memory for old background
2360
        mov     eax, [img_background]
2360
        mov     eax, [img_background]
2361
        cmp     eax, static_background_data
2361
        cmp     eax, static_background_data
2362
        jz      @f
2362
        jz      @f
2363
        stdcall kernel_free, eax
2363
        stdcall kernel_free, eax
2364
@@:
2364
@@:
2365
; calculate RAW size
2365
; calculate RAW size
2366
    xor  eax,eax
2366
    xor  eax,eax
2367
    inc  eax
2367
    inc  eax
2368
    cmp  [BgrDataWidth],eax
2368
    cmp  [BgrDataWidth],eax
2369
    jae   @f
2369
    jae   @f
2370
    mov [BgrDataWidth],eax
2370
    mov [BgrDataWidth],eax
2371
@@:
2371
@@:
2372
    cmp  [BgrDataHeight],eax
2372
    cmp  [BgrDataHeight],eax
2373
    jae   @f
2373
    jae   @f
2374
    mov [BgrDataHeight],eax
2374
    mov [BgrDataHeight],eax
2375
@@:
2375
@@:
2376
    mov  eax,[BgrDataWidth]
2376
    mov  eax,[BgrDataWidth]
2377
    imul eax,[BgrDataHeight]
2377
    imul eax,[BgrDataHeight]
2378
    lea  eax,[eax*3]
2378
    lea  eax,[eax*3]
2379
    mov  [mem_BACKGROUND],eax
2379
    mov  [mem_BACKGROUND],eax
2380
; get memory for new background
2380
; get memory for new background
2381
    stdcall kernel_alloc, eax
2381
    stdcall kernel_alloc, eax
2382
    test eax, eax
2382
    test eax, eax
2383
    jz .memfailed
2383
    jz .memfailed
2384
    mov [img_background], eax
2384
    mov [img_background], eax
2385
    jmp .exit
2385
    jmp .exit
2386
.memfailed:
2386
.memfailed:
2387
; revert to static monotone data
2387
; revert to static monotone data
2388
        mov     [img_background], static_background_data
2388
        mov     [img_background], static_background_data
2389
        xor     eax, eax
2389
        xor     eax, eax
2390
        inc     eax
2390
        inc     eax
2391
        mov     [BgrDataWidth], eax
2391
        mov     [BgrDataWidth], eax
2392
        mov     [BgrDataHeight], eax
2392
        mov     [BgrDataHeight], eax
2393
        mov     [mem_BACKGROUND], 4
2393
        mov     [mem_BACKGROUND], 4
2394
.exit:
2394
.exit:
2395
    popad
2395
    popad
2396
        mov     [bgrlock], 0
2396
        mov     [bgrlock], 0
2397
 
2397
 
2398
  sbgrr:
2398
  sbgrr:
2399
    ret
2399
    ret
2400
 
2400
 
2401
nosb1:
2401
nosb1:
2402
 
2402
 
2403
    cmp   ebx,2                            ; SET PIXEL
2403
    cmp   ebx,2                            ; SET PIXEL
2404
    jnz   nosb2
2404
    jnz   nosb2
2405
 
2405
 
2406
    mov   eax, [img_background]
2406
    mov   eax, [img_background]
2407
    test  ecx, ecx
2407
    test  ecx, ecx
2408
    jz    @f
2408
    jz    @f
2409
    cmp   eax, static_background_data
2409
    cmp   eax, static_background_data
2410
    jz    .ret
2410
    jz    .ret
2411
@@:
2411
@@:
2412
    mov ebx, [mem_BACKGROUND]
2412
    mov ebx, [mem_BACKGROUND]
2413
    add ebx, 4095
2413
    add ebx, 4095
2414
    and ebx, -4096
2414
    and ebx, -4096
2415
    sub ebx, 4
2415
    sub ebx, 4
2416
    cmp   ecx, ebx
2416
    cmp   ecx, ebx
2417
    ja   .ret
2417
    ja   .ret
2418
 
2418
 
2419
    mov   ebx,[eax+ecx]
2419
    mov   ebx,[eax+ecx]
2420
    and   ebx,0xFF000000 ;255*256*256*256
2420
    and   ebx,0xFF000000 ;255*256*256*256
2421
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2421
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2422
    add   edx,ebx
2422
    add   edx,ebx
2423
    mov   [eax+ecx],edx
2423
    mov   [eax+ecx],edx
2424
.ret:
2424
.ret:
2425
    ret
2425
    ret
2426
nosb2:
2426
nosb2:
2427
 
2427
 
2428
    cmp   ebx,3                            ; DRAW BACKGROUND
2428
    cmp   ebx,3                            ; DRAW BACKGROUND
2429
    jnz   nosb3
2429
    jnz   nosb3
2430
draw_background_temp:
2430
draw_background_temp:
2431
;    cmp   [bgrchanged],1 ;0
2431
;    cmp   [bgrchanged],1 ;0
2432
;    je    nosb31
2432
;    je    nosb31
2433
;draw_background_temp:
2433
;draw_background_temp:
2434
;    mov   [bgrchanged],1 ;0
2434
;    mov   [bgrchanged],1 ;0
2435
    mov    [background_defined], 1
2435
    mov    [background_defined], 1
2436
    call  force_redraw_background
2436
    call  force_redraw_background
2437
    mov    [REDRAW_BACKGROUND], byte 2
2437
    mov    [REDRAW_BACKGROUND], byte 2
2438
   nosb31:
2438
   nosb31:
2439
    ret
2439
    ret
2440
  nosb3:
2440
  nosb3:
2441
 
2441
 
2442
    cmp   ebx,4                            ; TILED / STRETCHED
2442
    cmp   ebx,4                            ; TILED / STRETCHED
2443
    jnz   nosb4
2443
    jnz   nosb4
2444
    cmp   ecx,[BgrDrawMode]
2444
    cmp   ecx,[BgrDrawMode]
2445
    je    nosb41
2445
    je    nosb41
2446
    mov   [BgrDrawMode],ecx
2446
    mov   [BgrDrawMode],ecx
2447
;    mov   [bgrchanged],1
2447
;    mov   [bgrchanged],1
2448
   nosb41:
2448
   nosb41:
2449
    ret
2449
    ret
2450
  nosb4:
2450
  nosb4:
2451
 
2451
 
2452
    cmp   ebx,5                            ; BLOCK MOVE TO BGR
2452
    cmp   ebx,5                            ; BLOCK MOVE TO BGR
2453
    jnz   nosb5
2453
    jnz   nosb5
2454
    cmp   [img_background], static_background_data
2454
    cmp   [img_background], static_background_data
2455
    jnz   @f
2455
    jnz   @f
2456
    test  edx, edx
2456
    test  edx, edx
2457
    jnz   .fin
2457
    jnz   .fin
2458
    cmp   esi, 4
2458
    cmp   esi, 4
2459
    ja    .fin
2459
    ja    .fin
2460
  @@:
2460
  @@:
2461
  ; bughere
2461
  ; bughere
2462
    mov   eax, ecx
2462
    mov   eax, ecx
2463
    mov   ebx, edx
2463
    mov   ebx, edx
2464
    add   ebx, [img_background]   ;IMG_BACKGROUND
2464
    add   ebx, [img_background]   ;IMG_BACKGROUND
2465
    mov   ecx, esi
2465
    mov   ecx, esi
2466
    call  memmove
2466
    call  memmove
2467
  .fin:
2467
  .fin:
2468
    ret
2468
    ret
2469
  nosb5:
2469
  nosb5:
2470
 
2470
 
2471
        cmp     ebx, 6
2471
        cmp     ebx, 6
2472
        jnz     nosb6
2472
        jnz     nosb6
2473
;;Maxis use atomic bts for mutex 4.4.2009
2473
;;Maxis use atomic bts for mutex 4.4.2009
2474
@@:
2474
@@:
2475
        bts     dword [bgrlock], 0
2475
        bts     dword [bgrlock], 0
2476
        jnc     @f
2476
        jnc     @f
2477
        call    change_task
2477
        call    change_task
2478
        jmp     @b
2478
        jmp     @b
2479
@@:
2479
@@:
2480
        mov     eax, [CURRENT_TASK]
2480
        mov     eax, [CURRENT_TASK]
2481
        mov     [bgrlockpid], eax
2481
        mov     [bgrlockpid], eax
2482
        cmp     [img_background], static_background_data
2482
        cmp     [img_background], static_background_data
2483
        jz      .nomem
2483
        jz      .nomem
2484
        stdcall user_alloc, [mem_BACKGROUND]
2484
        stdcall user_alloc, [mem_BACKGROUND]
2485
        mov     [esp+32], eax
2485
        mov     [esp+32], eax
2486
        test    eax, eax
2486
        test    eax, eax
2487
        jz      .nomem
2487
        jz      .nomem
2488
        mov     ebx, eax
2488
        mov     ebx, eax
2489
        shr     ebx, 12
2489
        shr     ebx, 12
2490
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2490
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2491
        mov     esi, [img_background]
2491
        mov     esi, [img_background]
2492
        shr     esi, 12
2492
        shr     esi, 12
2493
        mov     ecx, [mem_BACKGROUND]
2493
        mov     ecx, [mem_BACKGROUND]
2494
        add     ecx, 0xFFF
2494
        add     ecx, 0xFFF
2495
        shr     ecx, 12
2495
        shr     ecx, 12
2496
.z:
2496
.z:
2497
        mov     eax, [page_tabs+ebx*4]
2497
        mov     eax, [page_tabs+ebx*4]
2498
        test    al, 1
2498
        test    al, 1
2499
        jz      @f
2499
        jz      @f
2500
        call    free_page
2500
        call    free_page
2501
@@:
2501
@@:
2502
        mov     eax, [page_tabs+esi*4]
2502
        mov     eax, [page_tabs+esi*4]
2503
        or      al, PG_UW
2503
        or      al, PG_UW
2504
        mov     [page_tabs+ebx*4], eax
2504
        mov     [page_tabs+ebx*4], eax
2505
        mov     eax, ebx
2505
        mov     eax, ebx
2506
        shl     eax, 12
2506
        shl     eax, 12
2507
        invlpg  [eax]
2507
        invlpg  [eax]
2508
        inc     ebx
2508
        inc     ebx
2509
        inc     esi
2509
        inc     esi
2510
        loop    .z
2510
        loop    .z
2511
        ret
2511
        ret
2512
.nomem:
2512
.nomem:
2513
        and     [bgrlockpid], 0
2513
        and     [bgrlockpid], 0
2514
        mov     [bgrlock], 0
2514
        mov     [bgrlock], 0
2515
nosb6:
2515
nosb6:
2516
        cmp     ebx, 7
2516
        cmp     ebx, 7
2517
        jnz     nosb7
2517
        jnz     nosb7
2518
        cmp     [bgrlock], 0
2518
        cmp     [bgrlock], 0
2519
        jz      .err
2519
        jz      .err
2520
        mov     eax, [CURRENT_TASK]
2520
        mov     eax, [CURRENT_TASK]
2521
        cmp     [bgrlockpid], eax
2521
        cmp     [bgrlockpid], eax
2522
        jnz     .err
2522
        jnz     .err
2523
        mov     eax, ecx
2523
        mov     eax, ecx
2524
        mov     ebx, ecx
2524
        mov     ebx, ecx
2525
        shr     eax, 12
2525
        shr     eax, 12
2526
        mov     ecx, [page_tabs+(eax-1)*4]
2526
        mov     ecx, [page_tabs+(eax-1)*4]
2527
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2527
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2528
        jz      .err
2528
        jz      .err
2529
        jnp     .err
2529
        jnp     .err
2530
        push    eax
2530
        push    eax
2531
        shr     ecx, 12
2531
        shr     ecx, 12
-
 
2532
        dec     ecx
2532
@@:
2533
@@:
2533
        and     dword [page_tabs+eax*4], 0
2534
        and     dword [page_tabs+eax*4], 0
2534
        mov     edx, eax
2535
        mov     edx, eax
2535
        shl     edx, 12
2536
        shl     edx, 12
2536
        push eax
2537
        push eax
2537
        invlpg  [edx]
2538
        invlpg  [edx]
2538
        pop eax
2539
        pop eax
2539
        inc     eax
2540
        inc     eax
2540
        loop    @b
2541
        loop    @b
2541
        pop     eax
2542
        pop     eax
2542
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2543
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2543
        stdcall user_free, ebx
2544
        stdcall user_free, ebx
2544
        mov     [esp+32], eax
2545
        mov     [esp+32], eax
2545
        and     [bgrlockpid], 0
2546
        and     [bgrlockpid], 0
2546
        mov     [bgrlock], 0
2547
        mov     [bgrlock], 0
2547
        ret
2548
        ret
2548
.err:
2549
.err:
2549
        and     dword [esp+32], 0
2550
        and     dword [esp+32], 0
2550
        ret
2551
        ret
2551
 
2552
 
2552
nosb7:
2553
nosb7:
2553
    ret
2554
    ret
2554
 
2555
 
2555
force_redraw_background:
2556
force_redraw_background:
2556
    and   [draw_data+32 + RECT.left],dword 0
2557
    and   [draw_data+32 + RECT.left],dword 0
2557
    and   [draw_data+32 + RECT.top],dword 0
2558
    and   [draw_data+32 + RECT.top],dword 0
2558
    push  eax ebx
2559
    push  eax ebx
2559
    mov   eax,[Screen_Max_X]
2560
    mov   eax,[Screen_Max_X]
2560
    mov   ebx,[Screen_Max_Y]
2561
    mov   ebx,[Screen_Max_Y]
2561
    mov   [draw_data+32 + RECT.right],eax
2562
    mov   [draw_data+32 + RECT.right],eax
2562
    mov   [draw_data+32 + RECT.bottom],ebx
2563
    mov   [draw_data+32 + RECT.bottom],ebx
2563
    pop   ebx eax
2564
    pop   ebx eax
2564
    mov   byte [REDRAW_BACKGROUND], 1
2565
    mov   byte [REDRAW_BACKGROUND], 1
2565
    ret
2566
    ret
2566
 
2567
 
2567
align 4
2568
align 4
2568
 
2569
 
2569
sys_getbackground:
2570
sys_getbackground:
2570
;    cmp   eax,1                                  ; SIZE
2571
;    cmp   eax,1                                  ; SIZE
2571
    dec	  ebx
2572
    dec	  ebx
2572
    jnz   nogb1
2573
    jnz   nogb1
2573
    mov   eax,[BgrDataWidth]
2574
    mov   eax,[BgrDataWidth]
2574
    shl   eax,16
2575
    shl   eax,16
2575
    mov   ax,[BgrDataHeight]
2576
    mov   ax,[BgrDataHeight]
2576
    mov   [esp+32],eax
2577
    mov   [esp+32],eax
2577
    ret
2578
    ret
2578
 
2579
 
2579
nogb1:
2580
nogb1:
2580
;    cmp   eax,2                                  ; PIXEL
2581
;    cmp   eax,2                                  ; PIXEL
2581
    dec	  ebx
2582
    dec	  ebx
2582
    jnz   nogb2
2583
    jnz   nogb2
2583
 
2584
 
2584
        mov     eax, [img_background]
2585
        mov     eax, [img_background]
2585
        test    ecx, ecx
2586
        test    ecx, ecx
2586
        jz      @f
2587
        jz      @f
2587
        cmp     eax, static_background_data
2588
        cmp     eax, static_background_data
2588
        jz      .ret
2589
        jz      .ret
2589
@@:
2590
@@:
2590
    mov ebx, [mem_BACKGROUND]
2591
    mov ebx, [mem_BACKGROUND]
2591
    add ebx, 4095
2592
    add ebx, 4095
2592
    and ebx, -4096
2593
    and ebx, -4096
2593
    sub ebx, 4
2594
    sub ebx, 4
2594
    cmp ecx, ebx
2595
    cmp ecx, ebx
2595
    ja  .ret
2596
    ja  .ret
2596
 
2597
 
2597
    mov   eax,[ecx+eax]
2598
    mov   eax,[ecx+eax]
2598
 
2599
 
2599
    and   eax, 0xFFFFFF
2600
    and   eax, 0xFFFFFF
2600
    mov   [esp+32],eax
2601
    mov   [esp+32],eax
2601
.ret:
2602
.ret:
2602
    ret
2603
    ret
2603
  nogb2:
2604
  nogb2:
2604
 
2605
 
2605
;    cmp   eax,4                                  ; TILED / STRETCHED
2606
;    cmp   eax,4                                  ; TILED / STRETCHED
2606
    dec   ebx
2607
    dec   ebx
2607
    jnz   nogb4
2608
    jnz   nogb4
2608
    mov   eax,[BgrDrawMode]
2609
    mov   eax,[BgrDrawMode]
2609
  nogb4:
2610
  nogb4:
2610
    mov   [esp+32],eax
2611
    mov   [esp+32],eax
2611
    ret
2612
    ret
2612
 
2613
 
2613
align 4
2614
align 4
2614
 
2615
 
2615
sys_getkey:
2616
sys_getkey:
2616
        mov     [esp + 32],dword 1
2617
        mov     [esp + 32],dword 1
2617
        ; test main buffer
2618
        ; test main buffer
2618
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2619
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2619
        movzx   ecx, word [WIN_STACK + ebx * 2]
2620
        movzx   ecx, word [WIN_STACK + ebx * 2]
2620
        mov     edx, [TASK_COUNT]
2621
        mov     edx, [TASK_COUNT]
2621
        cmp     ecx, edx
2622
        cmp     ecx, edx
2622
        jne     .finish
2623
        jne     .finish
2623
        cmp     [KEY_COUNT], byte 0
2624
        cmp     [KEY_COUNT], byte 0
2624
        je      .finish
2625
        je      .finish
2625
        movzx   eax, byte [KEY_BUFF]
2626
        movzx   eax, byte [KEY_BUFF]
2626
        shl     eax, 8
2627
        shl     eax, 8
2627
        push    eax
2628
        push    eax
2628
        dec     byte [KEY_COUNT]
2629
        dec     byte [KEY_COUNT]
2629
        and     byte [KEY_COUNT], 127
2630
        and     byte [KEY_COUNT], 127
2630
        movzx   ecx, byte [KEY_COUNT]
2631
        movzx   ecx, byte [KEY_COUNT]
2631
        add     ecx, 2
2632
        add     ecx, 2
2632
        mov     eax, KEY_BUFF + 1
2633
        mov     eax, KEY_BUFF + 1
2633
        mov     ebx, KEY_BUFF
2634
        mov     ebx, KEY_BUFF
2634
        call    memmove
2635
        call    memmove
2635
        pop     eax
2636
        pop     eax
2636
.ret_eax:
2637
.ret_eax:
2637
        mov     [esp + 32], eax
2638
        mov     [esp + 32], eax
2638
        ret
2639
        ret
2639
.finish:
2640
.finish:
2640
; test hotkeys buffer
2641
; test hotkeys buffer
2641
        mov     ecx, hotkey_buffer
2642
        mov     ecx, hotkey_buffer
2642
@@:
2643
@@:
2643
        cmp     [ecx], ebx
2644
        cmp     [ecx], ebx
2644
        jz      .found
2645
        jz      .found
2645
        add     ecx, 8
2646
        add     ecx, 8
2646
        cmp     ecx, hotkey_buffer + 120 * 8
2647
        cmp     ecx, hotkey_buffer + 120 * 8
2647
        jb      @b
2648
        jb      @b
2648
        ret
2649
        ret
2649
.found:
2650
.found:
2650
        mov     ax, [ecx + 6]
2651
        mov     ax, [ecx + 6]
2651
        shl     eax, 16
2652
        shl     eax, 16
2652
        mov     ah, [ecx + 4]
2653
        mov     ah, [ecx + 4]
2653
        mov     al, 2
2654
        mov     al, 2
2654
        and     dword [ecx + 4], 0
2655
        and     dword [ecx + 4], 0
2655
        and     dword [ecx], 0
2656
        and     dword [ecx], 0
2656
        jmp     .ret_eax
2657
        jmp     .ret_eax
2657
 
2658
 
2658
align 4
2659
align 4
2659
 
2660
 
2660
sys_getbutton:
2661
sys_getbutton:
2661
 
2662
 
2662
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2663
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2663
        mov     [esp + 32], dword 1
2664
        mov     [esp + 32], dword 1
2664
        movzx   ecx, word [WIN_STACK + ebx * 2]
2665
        movzx   ecx, word [WIN_STACK + ebx * 2]
2665
        mov     edx, [TASK_COUNT] ; less than 256 processes
2666
        mov     edx, [TASK_COUNT] ; less than 256 processes
2666
        cmp     ecx, edx
2667
        cmp     ecx, edx
2667
        jne     .exit
2668
        jne     .exit
2668
        movzx   eax, byte [BTN_COUNT]
2669
        movzx   eax, byte [BTN_COUNT]
2669
        test    eax, eax
2670
        test    eax, eax
2670
        jz      .exit
2671
        jz      .exit
2671
        mov     eax, [BTN_BUFF]
2672
        mov     eax, [BTN_BUFF]
2672
        shl     eax, 8
2673
        shl     eax, 8
2673
; // Alver 22.06.2008 // {
2674
; // Alver 22.06.2008 // {
2674
        mov       al, byte [btn_down_determ]
2675
        mov       al, byte [btn_down_determ]
2675
        and       al,0xFE                                       ; delete left button bit
2676
        and       al,0xFE                                       ; delete left button bit
2676
; } \\ Alver \\
2677
; } \\ Alver \\
2677
        mov     [BTN_COUNT], byte 0
2678
        mov     [BTN_COUNT], byte 0
2678
        mov     [esp + 32], eax
2679
        mov     [esp + 32], eax
2679
.exit:
2680
.exit:
2680
        ret
2681
        ret
2681
 
2682
 
2682
 
2683
 
2683
align 4
2684
align 4
2684
 
2685
 
2685
sys_cpuusage:
2686
sys_cpuusage:
2686
 
2687
 
2687
;  RETURN:
2688
;  RETURN:
2688
;
2689
;
2689
;  +00 dword     process cpu usage
2690
;  +00 dword     process cpu usage
2690
;  +04  word     position in windowing stack
2691
;  +04  word     position in windowing stack
2691
;  +06  word     windowing stack value at current position (cpu nro)
2692
;  +06  word     windowing stack value at current position (cpu nro)
2692
;  +10 12 bytes  name
2693
;  +10 12 bytes  name
2693
;  +22 dword     start in mem
2694
;  +22 dword     start in mem
2694
;  +26 dword     used mem
2695
;  +26 dword     used mem
2695
;  +30 dword     PID , process idenfification number
2696
;  +30 dword     PID , process idenfification number
2696
;
2697
;
2697
 
2698
 
2698
    cmp  ecx,-1         ; who am I ?
2699
    cmp  ecx,-1         ; who am I ?
2699
    jne  .no_who_am_i
2700
    jne  .no_who_am_i
2700
    mov  ecx,[CURRENT_TASK]
2701
    mov  ecx,[CURRENT_TASK]
2701
  .no_who_am_i:
2702
  .no_who_am_i:
2702
        cmp     ecx, max_processes
2703
        cmp     ecx, max_processes
2703
        ja      .nofillbuf
2704
        ja      .nofillbuf
2704
 
2705
 
2705
; +4: word: position of the window of thread in the window stack
2706
; +4: word: position of the window of thread in the window stack
2706
        mov     ax, [WIN_STACK + ecx * 2]
2707
        mov     ax, [WIN_STACK + ecx * 2]
2707
        mov     [ebx+4], ax
2708
        mov     [ebx+4], ax
2708
; +6: word: number of the thread slot, which window has in the window stack
2709
; +6: word: number of the thread slot, which window has in the window stack
2709
;           position ecx (has no relation to the specific thread)
2710
;           position ecx (has no relation to the specific thread)
2710
        mov     ax, [WIN_POS + ecx * 2]
2711
        mov     ax, [WIN_POS + ecx * 2]
2711
        mov     [ebx+6], ax
2712
        mov     [ebx+6], ax
2712
 
2713
 
2713
        shl     ecx, 5
2714
        shl     ecx, 5
2714
 
2715
 
2715
; +0: dword: memory usage
2716
; +0: dword: memory usage
2716
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2717
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2717
        mov     [ebx], eax
2718
        mov     [ebx], eax
2718
; +10: 11 bytes: name of the process
2719
; +10: 11 bytes: name of the process
2719
        push    ecx
2720
        push    ecx
2720
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2721
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2721
        add     ebx, 10
2722
        add     ebx, 10
2722
        mov     ecx, 11
2723
        mov     ecx, 11
2723
        call    memmove
2724
        call    memmove
2724
        pop     ecx
2725
        pop     ecx
2725
 
2726
 
2726
; +22: address of the process in memory
2727
; +22: address of the process in memory
2727
; +26: size of used memory - 1
2728
; +26: size of used memory - 1
2728
        push    edi
2729
        push    edi
2729
        lea     edi, [ebx+12]
2730
        lea     edi, [ebx+12]
2730
        xor     eax, eax
2731
        xor     eax, eax
2731
        mov     edx, 0x100000*16
2732
        mov     edx, 0x100000*16
2732
        cmp     ecx, 1 shl 5
2733
        cmp     ecx, 1 shl 5
2733
        je      .os_mem
2734
        je      .os_mem
2734
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2735
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2735
        mov     eax, std_application_base_address
2736
        mov     eax, std_application_base_address
2736
.os_mem:
2737
.os_mem:
2737
        stosd
2738
        stosd
2738
        lea     eax, [edx-1]
2739
        lea     eax, [edx-1]
2739
        stosd
2740
        stosd
2740
 
2741
 
2741
; +30: PID/TID
2742
; +30: PID/TID
2742
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2743
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2743
        stosd
2744
        stosd
2744
 
2745
 
2745
    ; window position and size
2746
    ; window position and size
2746
        push    esi
2747
        push    esi
2747
        lea     esi, [ecx + window_data + WDATA.box]
2748
        lea     esi, [ecx + window_data + WDATA.box]
2748
        movsd
2749
        movsd
2749
        movsd
2750
        movsd
2750
        movsd
2751
        movsd
2751
        movsd
2752
        movsd
2752
 
2753
 
2753
    ; Process state (+50)
2754
    ; Process state (+50)
2754
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2755
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2755
        stosd
2756
        stosd
2756
 
2757
 
2757
    ; Window client area box
2758
    ; Window client area box
2758
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2759
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2759
        movsd
2760
        movsd
2760
        movsd
2761
        movsd
2761
        movsd
2762
        movsd
2762
        movsd
2763
        movsd
2763
 
2764
 
2764
    ; Window state
2765
    ; Window state
2765
        mov     al, [ecx+window_data+WDATA.fl_wstate]
2766
        mov     al, [ecx+window_data+WDATA.fl_wstate]
2766
        stosb
2767
        stosb
2767
 
2768
 
2768
        pop     esi
2769
        pop     esi
2769
        pop     edi
2770
        pop     edi
2770
 
2771
 
2771
.nofillbuf:
2772
.nofillbuf:
2772
    ; return number of processes
2773
    ; return number of processes
2773
 
2774
 
2774
    mov    eax,[TASK_COUNT]
2775
    mov    eax,[TASK_COUNT]
2775
    mov    [esp+32],eax
2776
    mov    [esp+32],eax
2776
    ret
2777
    ret
2777
 
2778
 
2778
align 4
2779
align 4
2779
sys_clock:
2780
sys_clock:
2780
        cli
2781
        cli
2781
  ; Mikhail Lisovin  xx Jan 2005
2782
  ; Mikhail Lisovin  xx Jan 2005
2782
  @@:   mov   al, 10
2783
  @@:   mov   al, 10
2783
        out   0x70, al
2784
        out   0x70, al
2784
        in    al, 0x71
2785
        in    al, 0x71
2785
        test  al, al
2786
        test  al, al
2786
        jns   @f
2787
        jns   @f
2787
        mov   esi, 1
2788
        mov   esi, 1
2788
        call  delay_ms
2789
        call  delay_ms
2789
        jmp   @b
2790
        jmp   @b
2790
  @@:
2791
  @@:
2791
  ; end Lisovin's fix
2792
  ; end Lisovin's fix
2792
 
2793
 
2793
        xor   al,al           ; seconds
2794
        xor   al,al           ; seconds
2794
        out   0x70,al
2795
        out   0x70,al
2795
        in    al,0x71
2796
        in    al,0x71
2796
        movzx ecx,al
2797
        movzx ecx,al
2797
        mov   al,02           ; minutes
2798
        mov   al,02           ; minutes
2798
        shl   ecx,16
2799
        shl   ecx,16
2799
        out   0x70,al
2800
        out   0x70,al
2800
        in    al,0x71
2801
        in    al,0x71
2801
        movzx edx,al
2802
        movzx edx,al
2802
        mov   al,04           ; hours
2803
        mov   al,04           ; hours
2803
        shl   edx,8
2804
        shl   edx,8
2804
        out   0x70,al
2805
        out   0x70,al
2805
        in    al,0x71
2806
        in    al,0x71
2806
        add   ecx,edx
2807
        add   ecx,edx
2807
        movzx edx,al
2808
        movzx edx,al
2808
        add   ecx,edx
2809
        add   ecx,edx
2809
        sti
2810
        sti
2810
        mov     [esp + 32], ecx
2811
        mov     [esp + 32], ecx
2811
        ret
2812
        ret
2812
 
2813
 
2813
 
2814
 
2814
align 4
2815
align 4
2815
 
2816
 
2816
sys_date:
2817
sys_date:
2817
 
2818
 
2818
        cli
2819
        cli
2819
  @@:   mov   al, 10
2820
  @@:   mov   al, 10
2820
        out   0x70, al
2821
        out   0x70, al
2821
        in    al, 0x71
2822
        in    al, 0x71
2822
        test  al, al
2823
        test  al, al
2823
        jns   @f
2824
        jns   @f
2824
        mov   esi, 1
2825
        mov   esi, 1
2825
        call  delay_ms
2826
        call  delay_ms
2826
        jmp   @b
2827
        jmp   @b
2827
  @@:
2828
  @@:
2828
 
2829
 
2829
        mov     ch,0
2830
        mov     ch,0
2830
        mov     al,7            ; date
2831
        mov     al,7            ; date
2831
        out     0x70,al
2832
        out     0x70,al
2832
        in      al,0x71
2833
        in      al,0x71
2833
        mov     cl,al
2834
        mov     cl,al
2834
        mov     al,8            ; month
2835
        mov     al,8            ; month
2835
        shl     ecx,16
2836
        shl     ecx,16
2836
        out     0x70,al
2837
        out     0x70,al
2837
        in      al,0x71
2838
        in      al,0x71
2838
        mov     ch,al
2839
        mov     ch,al
2839
        mov     al,9            ; year
2840
        mov     al,9            ; year
2840
        out     0x70,al
2841
        out     0x70,al
2841
        in      al,0x71
2842
        in      al,0x71
2842
        mov     cl,al
2843
        mov     cl,al
2843
        sti
2844
        sti
2844
        mov     [esp+32], ecx
2845
        mov     [esp+32], ecx
2845
        ret
2846
        ret
2846
 
2847
 
2847
 
2848
 
2848
; redraw status
2849
; redraw status
2849
 
2850
 
2850
sys_redrawstat:
2851
sys_redrawstat:
2851
        cmp     ebx, 1
2852
        cmp     ebx, 1
2852
        jne     no_widgets_away
2853
        jne     no_widgets_away
2853
        ; buttons away
2854
        ; buttons away
2854
        mov     ecx,[CURRENT_TASK]
2855
        mov     ecx,[CURRENT_TASK]
2855
  sys_newba2:
2856
  sys_newba2:
2856
        mov     edi,[BTN_ADDR]
2857
        mov     edi,[BTN_ADDR]
2857
        cmp     [edi], dword 0  ; empty button list ?
2858
        cmp     [edi], dword 0  ; empty button list ?
2858
        je      end_of_buttons_away
2859
        je      end_of_buttons_away
2859
        movzx   ebx, word [edi]
2860
        movzx   ebx, word [edi]
2860
        inc     ebx
2861
        inc     ebx
2861
        mov     eax,edi
2862
        mov     eax,edi
2862
  sys_newba:
2863
  sys_newba:
2863
        dec     ebx
2864
        dec     ebx
2864
        jz      end_of_buttons_away
2865
        jz      end_of_buttons_away
2865
 
2866
 
2866
        add     eax, 0x10
2867
        add     eax, 0x10
2867
        cmp     cx, [eax]
2868
        cmp     cx, [eax]
2868
        jnz     sys_newba
2869
        jnz     sys_newba
2869
 
2870
 
2870
        push    eax ebx ecx
2871
        push    eax ebx ecx
2871
        mov     ecx,ebx
2872
        mov     ecx,ebx
2872
        inc     ecx
2873
        inc     ecx
2873
        shl     ecx, 4
2874
        shl     ecx, 4
2874
        mov     ebx, eax
2875
        mov     ebx, eax
2875
        add     eax, 0x10
2876
        add     eax, 0x10
2876
        call    memmove
2877
        call    memmove
2877
        dec     dword [edi]
2878
        dec     dword [edi]
2878
        pop     ecx ebx eax
2879
        pop     ecx ebx eax
2879
 
2880
 
2880
        jmp     sys_newba2
2881
        jmp     sys_newba2
2881
 
2882
 
2882
  end_of_buttons_away:
2883
  end_of_buttons_away:
2883
 
2884
 
2884
        ret
2885
        ret
2885
 
2886
 
2886
  no_widgets_away:
2887
  no_widgets_away:
2887
 
2888
 
2888
        cmp     ebx, 2
2889
        cmp     ebx, 2
2889
        jnz     srl1
2890
        jnz     srl1
2890
 
2891
 
2891
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
2892
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
2892
        add     edx, draw_data - CURRENT_TASK
2893
        add     edx, draw_data - CURRENT_TASK
2893
        mov     [edx + RECT.left], 0
2894
        mov     [edx + RECT.left], 0
2894
        mov     [edx + RECT.top], 0
2895
        mov     [edx + RECT.top], 0
2895
        mov     eax, [Screen_Max_X]
2896
        mov     eax, [Screen_Max_X]
2896
        mov     [edx + RECT.right], eax
2897
        mov     [edx + RECT.right], eax
2897
        mov     eax, [Screen_Max_Y]
2898
        mov     eax, [Screen_Max_Y]
2898
        mov     [edx + RECT.bottom], eax
2899
        mov     [edx + RECT.bottom], eax
2899
 
2900
 
2900
        mov     edi, [TASK_BASE]
2901
        mov     edi, [TASK_BASE]
2901
        or      [edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2902
        or      [edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2902
        call    sys_window_mouse
2903
        call    sys_window_mouse
2903
        ret
2904
        ret
2904
 
2905
 
2905
  srl1:
2906
  srl1:
2906
        ret
2907
        ret
2907
 
2908
 
2908
 
2909
 
2909
sys_drawwindow:
2910
sys_drawwindow:
2910
 
2911
 
2911
    mov   eax,edx
2912
    mov   eax,edx
2912
    shr   eax,16+8
2913
    shr   eax,16+8
2913
    and   eax,15
2914
    and   eax,15
2914
 
2915
 
2915
;    cmp   eax,0   ; type I    - original style
2916
;    cmp   eax,0   ; type I    - original style
2916
    jne   nosyswI
2917
    jne   nosyswI
2917
    inc   [mouse_pause]
2918
    inc   [mouse_pause]
2918
    call  [_display.disable_mouse]
2919
    call  [_display.disable_mouse]
2919
    call  sys_set_window
2920
    call  sys_set_window
2920
    call  [_display.disable_mouse]
2921
    call  [_display.disable_mouse]
2921
    call  drawwindow_I
2922
    call  drawwindow_I
2922
    ;dec   [mouse_pause]
2923
    ;dec   [mouse_pause]
2923
    ;call   [draw_pointer]
2924
    ;call   [draw_pointer]
2924
    ;ret
2925
    ;ret
2925
    jmp   draw_window_caption.2
2926
    jmp   draw_window_caption.2
2926
  nosyswI:
2927
  nosyswI:
2927
 
2928
 
2928
    cmp   al,1    ; type II   - only reserve area, no draw
2929
    cmp   al,1    ; type II   - only reserve area, no draw
2929
    jne   nosyswII
2930
    jne   nosyswII
2930
    inc   [mouse_pause]
2931
    inc   [mouse_pause]
2931
    call  [_display.disable_mouse]
2932
    call  [_display.disable_mouse]
2932
    call  sys_set_window
2933
    call  sys_set_window
2933
    call  [_display.disable_mouse]
2934
    call  [_display.disable_mouse]
2934
    call  sys_window_mouse
2935
    call  sys_window_mouse
2935
    dec   [mouse_pause]
2936
    dec   [mouse_pause]
2936
    call   [draw_pointer]
2937
    call   [draw_pointer]
2937
    ret
2938
    ret
2938
  nosyswII:
2939
  nosyswII:
2939
 
2940
 
2940
    cmp   al,2    ; type III  - new style
2941
    cmp   al,2    ; type III  - new style
2941
    jne   nosyswIII
2942
    jne   nosyswIII
2942
    inc   [mouse_pause]
2943
    inc   [mouse_pause]
2943
    call  [_display.disable_mouse]
2944
    call  [_display.disable_mouse]
2944
    call  sys_set_window
2945
    call  sys_set_window
2945
    call  [_display.disable_mouse]
2946
    call  [_display.disable_mouse]
2946
    call  drawwindow_III
2947
    call  drawwindow_III
2947
    ;dec   [mouse_pause]
2948
    ;dec   [mouse_pause]
2948
    ;call   [draw_pointer]
2949
    ;call   [draw_pointer]
2949
    ;ret
2950
    ;ret
2950
    jmp   draw_window_caption.2
2951
    jmp   draw_window_caption.2
2951
  nosyswIII:
2952
  nosyswIII:
2952
 
2953
 
2953
    cmp   al,3    ; type IV - skinned window
2954
    cmp   al,3    ; type IV - skinned window
2954
    je    draw_skin_window
2955
    je    draw_skin_window
2955
    cmp   al,4    ; type V - skinned window not sized! {not_sized_skin_window}
2956
    cmp   al,4    ; type V - skinned window not sized! {not_sized_skin_window}
2956
    jne   nosyswV
2957
    jne   nosyswV
2957
  draw_skin_window:
2958
  draw_skin_window:
2958
 
2959
 
2959
    inc   [mouse_pause]
2960
    inc   [mouse_pause]
2960
    call  [_display.disable_mouse]
2961
    call  [_display.disable_mouse]
2961
    call  sys_set_window
2962
    call  sys_set_window
2962
    call  [_display.disable_mouse]
2963
    call  [_display.disable_mouse]
2963
    mov   eax, [TASK_COUNT]
2964
    mov   eax, [TASK_COUNT]
2964
    movzx eax, word [WIN_POS + eax*2]
2965
    movzx eax, word [WIN_POS + eax*2]
2965
    cmp   eax, [CURRENT_TASK]
2966
    cmp   eax, [CURRENT_TASK]
2966
    setz  al
2967
    setz  al
2967
    movzx eax, al
2968
    movzx eax, al
2968
    push  eax
2969
    push  eax
2969
    call  drawwindow_IV
2970
    call  drawwindow_IV
2970
    ;dec   [mouse_pause]
2971
    ;dec   [mouse_pause]
2971
    ;call   [draw_pointer]
2972
    ;call   [draw_pointer]
2972
    ;ret
2973
    ;ret
2973
    jmp   draw_window_caption.2
2974
    jmp   draw_window_caption.2
2974
  nosyswV:
2975
  nosyswV:
2975
 
2976
 
2976
    ret
2977
    ret
2977
 
2978
 
2978
 
2979
 
2979
draw_window_caption:
2980
draw_window_caption:
2980
        inc     [mouse_pause]
2981
        inc     [mouse_pause]
2981
        call    [_display.disable_mouse]
2982
        call    [_display.disable_mouse]
2982
 
2983
 
2983
        xor     eax,eax
2984
        xor     eax,eax
2984
        mov     edx,[TASK_COUNT]
2985
        mov     edx,[TASK_COUNT]
2985
        movzx   edx,word[WIN_POS+edx*2]
2986
        movzx   edx,word[WIN_POS+edx*2]
2986
        cmp     edx,[CURRENT_TASK]
2987
        cmp     edx,[CURRENT_TASK]
2987
        jne     @f
2988
        jne     @f
2988
        inc     eax
2989
        inc     eax
2989
    @@: mov     edx,[CURRENT_TASK]
2990
    @@: mov     edx,[CURRENT_TASK]
2990
        shl     edx,5
2991
        shl     edx,5
2991
        add     edx,window_data
2992
        add     edx,window_data
2992
        movzx   ebx,[edx+WDATA.fl_wstyle]
2993
        movzx   ebx,[edx+WDATA.fl_wstyle]
2993
        and     bl,0x0F
2994
        and     bl,0x0F
2994
        cmp     bl,3
2995
        cmp     bl,3
2995
        je      .draw_caption_style_3           ;{for 3 and 4 style write caption}
2996
        je      .draw_caption_style_3           ;{for 3 and 4 style write caption}
2996
        cmp     bl,4
2997
        cmp     bl,4
2997
        je      .draw_caption_style_3
2998
        je      .draw_caption_style_3
2998
 
2999
 
2999
        jmp     .not_style_3
3000
        jmp     .not_style_3
3000
  .draw_caption_style_3:
3001
  .draw_caption_style_3:
3001
 
3002
 
3002
        push    edx
3003
        push    edx
3003
        call    drawwindow_IV_caption
3004
        call    drawwindow_IV_caption
3004
        add     esp,4
3005
        add     esp,4
3005
        jmp     .2
3006
        jmp     .2
3006
 
3007
 
3007
  .not_style_3:
3008
  .not_style_3:
3008
        cmp     bl,2
3009
        cmp     bl,2
3009
        jne     .not_style_2
3010
        jne     .not_style_2
3010
 
3011
 
3011
        call    drawwindow_III_caption
3012
        call    drawwindow_III_caption
3012
        jmp     .2
3013
        jmp     .2
3013
 
3014
 
3014
  .not_style_2:
3015
  .not_style_2:
3015
        cmp     bl,0
3016
        cmp     bl,0
3016
        jne     .2
3017
        jne     .2
3017
 
3018
 
3018
        call    drawwindow_I_caption
3019
        call    drawwindow_I_caption
3019
 
3020
 
3020
;--------------------------------------------------------------
3021
;--------------------------------------------------------------
3021
  .2:   ;jmp     @f
3022
  .2:   ;jmp     @f
3022
        mov     edi,[CURRENT_TASK]
3023
        mov     edi,[CURRENT_TASK]
3023
        shl     edi,5
3024
        shl     edi,5
3024
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3025
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3025
        jz      @f
3026
        jz      @f
3026
        mov     edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
3027
        mov     edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
3027
        or      edx,edx
3028
        or      edx,edx
3028
        jz      @f
3029
        jz      @f
3029
 
3030
 
3030
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
3031
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
3031
        and     al,0x0F
3032
        and     al,0x0F
3032
        cmp     al,3
3033
        cmp     al,3
3033
        je      .skinned
3034
        je      .skinned
3034
        cmp     al,4
3035
        cmp     al,4
3035
        je      .skinned
3036
        je      .skinned
3036
 
3037
 
3037
        jmp     .not_skinned
3038
        jmp     .not_skinned
3038
  .skinned:
3039
  .skinned:
3039
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3040
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3040
        mov     bp,word[edi+window_data+WDATA.box.top]
3041
        mov     bp,word[edi+window_data+WDATA.box.top]
3041
        movzx   eax,word[edi+window_data+WDATA.box.width]
3042
        movzx   eax,word[edi+window_data+WDATA.box.width]
3042
        sub     ax,[_skinmargins.left]
3043
        sub     ax,[_skinmargins.left]
3043
        sub     ax,[_skinmargins.right]
3044
        sub     ax,[_skinmargins.right]
3044
        push    edx
3045
        push    edx
3045
        cwde
3046
        cwde
3046
        cdq
3047
        cdq
3047
        mov     ebx,6
3048
        mov     ebx,6
3048
        idiv    ebx
3049
        idiv    ebx
3049
        pop     edx
3050
        pop     edx
3050
        or      eax,eax
3051
        or      eax,eax
3051
        js      @f
3052
        js      @f
3052
        mov     esi,eax
3053
        mov     esi,eax
3053
        mov     ebx,dword[_skinmargins.left-2]
3054
        mov     ebx,dword[_skinmargins.left-2]
3054
        mov     bx,word[_skinh]
3055
        mov     bx,word[_skinh]
3055
        sub     bx,[_skinmargins.bottom]
3056
        sub     bx,[_skinmargins.bottom]
3056
        sub     bx,[_skinmargins.top]
3057
        sub     bx,[_skinmargins.top]
3057
        sar     bx,1
3058
        sar     bx,1
3058
        adc     bx,0
3059
        adc     bx,0
3059
        add     bx,[_skinmargins.top]
3060
        add     bx,[_skinmargins.top]
3060
        add     bx,-3
3061
        add     bx,-3
3061
        add     ebx,ebp
3062
        add     ebx,ebp
3062
        jmp     .dodraw
3063
        jmp     .dodraw
3063
 
3064
 
3064
  .not_skinned:
3065
  .not_skinned:
3065
        cmp     al,1
3066
        cmp     al,1
3066
        je      @f
3067
        je      @f
3067
 
3068
 
3068
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3069
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3069
        mov     bp,word[edi+window_data+WDATA.box.top]
3070
        mov     bp,word[edi+window_data+WDATA.box.top]
3070
        movzx   eax,word[edi+window_data+WDATA.box.width]
3071
        movzx   eax,word[edi+window_data+WDATA.box.width]
3071
        sub     eax,16
3072
        sub     eax,16
3072
        push    edx
3073
        push    edx
3073
        cwde
3074
        cwde
3074
        cdq
3075
        cdq
3075
        mov     ebx,6
3076
        mov     ebx,6
3076
        idiv    ebx
3077
        idiv    ebx
3077
        pop     edx
3078
        pop     edx
3078
        or      eax,eax
3079
        or      eax,eax
3079
        js      @f
3080
        js      @f
3080
        mov     esi,eax
3081
        mov     esi,eax
3081
        mov     ebx,0x00080007
3082
        mov     ebx,0x00080007
3082
        add     ebx,ebp
3083
        add     ebx,ebp
3083
.dodraw:
3084
.dodraw:
3084
        mov     ecx,[common_colours+16];0x00FFFFFF
3085
        mov     ecx,[common_colours+16];0x00FFFFFF
3085
        or      ecx, 0x80000000
3086
        or      ecx, 0x80000000
3086
        xor     edi,edi
3087
        xor     edi,edi
3087
; // Alver 22.06.2008 // {
3088
; // Alver 22.06.2008 // {
3088
;       call    dtext
3089
;       call    dtext
3089
        call dtext_asciiz_esi
3090
        call dtext_asciiz_esi
3090
; } \\ Alver \\
3091
; } \\ Alver \\
3091
 
3092
 
3092
    @@:
3093
    @@:
3093
;--------------------------------------------------------------
3094
;--------------------------------------------------------------
3094
        dec     [mouse_pause]
3095
        dec     [mouse_pause]
3095
        call    [draw_pointer]
3096
        call    [draw_pointer]
3096
        ret
3097
        ret
3097
 
3098
 
3098
iglobal
3099
iglobal
3099
align 4
3100
align 4
3100
window_topleft dd \
3101
window_topleft dd \
3101
  1, 21,\               ;type 0
3102
  1, 21,\               ;type 0
3102
  0,  0,\       ;type 1
3103
  0,  0,\       ;type 1
3103
  5, 20,\       ;type 2
3104
  5, 20,\       ;type 2
3104
  5,  ?,\       ;type 3 {set by skin}
3105
  5,  ?,\       ;type 3 {set by skin}
3105
  5,  ?         ;type 4 {set by skin}
3106
  5,  ?         ;type 4 {set by skin}
3106
endg
3107
endg
3107
 
3108
 
3108
set_window_clientbox:
3109
set_window_clientbox:
3109
        push    eax ecx edi
3110
        push    eax ecx edi
3110
 
3111
 
3111
        mov     eax,[_skinh]
3112
        mov     eax,[_skinh]
3112
        mov     [window_topleft+4*7],eax
3113
        mov     [window_topleft+4*7],eax
3113
        mov     [window_topleft+4*9],eax
3114
        mov     [window_topleft+4*9],eax
3114
 
3115
 
3115
        mov     ecx,edi
3116
        mov     ecx,edi
3116
        sub     edi,window_data
3117
        sub     edi,window_data
3117
        shl     edi,3
3118
        shl     edi,3
3118
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3119
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3119
        jz      @f
3120
        jz      @f
3120
 
3121
 
3121
        movzx   eax,[ecx+WDATA.fl_wstyle]
3122
        movzx   eax,[ecx+WDATA.fl_wstyle]
3122
        and     eax,0x0F
3123
        and     eax,0x0F
3123
        mov     eax,[eax*8+window_topleft+0]
3124
        mov     eax,[eax*8+window_topleft+0]
3124
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3125
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3125
        shl     eax,1
3126
        shl     eax,1
3126
        neg     eax
3127
        neg     eax
3127
        add     eax,[ecx+WDATA.box.width]
3128
        add     eax,[ecx+WDATA.box.width]
3128
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3129
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3129
 
3130
 
3130
        movzx   eax,[ecx+WDATA.fl_wstyle]
3131
        movzx   eax,[ecx+WDATA.fl_wstyle]
3131
        and     eax,0x0F
3132
        and     eax,0x0F
3132
        push    [eax*8+window_topleft+0]
3133
        push    [eax*8+window_topleft+0]
3133
        mov     eax,[eax*8+window_topleft+4]
3134
        mov     eax,[eax*8+window_topleft+4]
3134
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3135
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3135
        neg     eax
3136
        neg     eax
3136
        sub     eax,[esp]
3137
        sub     eax,[esp]
3137
        add     eax,[ecx+WDATA.box.height]
3138
        add     eax,[ecx+WDATA.box.height]
3138
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3139
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3139
        add     esp,4
3140
        add     esp,4
3140
 
3141
 
3141
        pop     edi ecx eax
3142
        pop     edi ecx eax
3142
        ret
3143
        ret
3143
    @@:
3144
    @@:
3144
        xor     eax,eax
3145
        xor     eax,eax
3145
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3146
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3146
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3147
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3147
        mov     eax,[ecx+WDATA.box.width]
3148
        mov     eax,[ecx+WDATA.box.width]
3148
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3149
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3149
        mov     eax,[ecx+WDATA.box.height]
3150
        mov     eax,[ecx+WDATA.box.height]
3150
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3151
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3151
 
3152
 
3152
        pop     edi ecx eax
3153
        pop     edi ecx eax
3153
        ret
3154
        ret
3154
 
3155
 
3155
sys_set_window:
3156
sys_set_window:
3156
 
3157
 
3157
    mov   eax,[CURRENT_TASK]
3158
    mov   eax,[CURRENT_TASK]
3158
    shl   eax,5
3159
    shl   eax,5
3159
    add   eax,window_data
3160
    add   eax,window_data
3160
 
3161
 
3161
    ; colors
3162
    ; colors
3162
    mov   [eax+WDATA.cl_workarea],edx
3163
    mov   [eax+WDATA.cl_workarea],edx
3163
    mov   [eax+WDATA.cl_titlebar],esi
3164
    mov   [eax+WDATA.cl_titlebar],esi
3164
    mov   [eax+WDATA.cl_frames],edi
3165
    mov   [eax+WDATA.cl_frames],edi
3165
 
3166
 
3166
    mov   edi, eax
3167
    mov   edi, eax
3167
 
3168
 
3168
    ; check flag (?)
3169
    ; check flag (?)
3169
    test  [edi+WDATA.fl_wdrawn],1
3170
    test  [edi+WDATA.fl_wdrawn],1
3170
    jnz   newd
3171
    jnz   newd
3171
 
3172
 
3172
    mov   eax,[timer_ticks] ;[0xfdf0]
3173
    mov   eax,[timer_ticks] ;[0xfdf0]
3173
    add   eax,100
3174
    add   eax,100
3174
    mov   [new_window_starting],eax
3175
    mov   [new_window_starting],eax
3175
 
3176
 
3176
    movsx eax,bx
3177
    movsx eax,bx
3177
    mov   [edi+WDATA.box.width],eax
3178
    mov   [edi+WDATA.box.width],eax
3178
    movsx eax,cx
3179
    movsx eax,cx
3179
    mov   [edi+WDATA.box.height],eax
3180
    mov   [edi+WDATA.box.height],eax
3180
    sar   ebx,16
3181
    sar   ebx,16
3181
    sar   ecx,16
3182
    sar   ecx,16
3182
    mov   [edi+WDATA.box.left],ebx
3183
    mov   [edi+WDATA.box.left],ebx
3183
    mov   [edi+WDATA.box.top],ecx
3184
    mov   [edi+WDATA.box.top],ecx
3184
 
3185
 
3185
    call  check_window_position
3186
    call  check_window_position
3186
 
3187
 
3187
    push  ecx esi edi               ; save for window fullscreen/resize
3188
    push  ecx esi edi               ; save for window fullscreen/resize
3188
    ;mov   esi,edi
3189
    ;mov   esi,edi
3189
 
3190
 
3190
        mov     cl, [edi+WDATA.fl_wstyle]
3191
        mov     cl, [edi+WDATA.fl_wstyle]
3191
        mov     eax, [edi+WDATA.cl_frames]
3192
        mov     eax, [edi+WDATA.cl_frames]
3192
 
3193
 
3193
    sub   edi,window_data
3194
    sub   edi,window_data
3194
    shl   edi,3
3195
    shl   edi,3
3195
    add   edi,SLOT_BASE
3196
    add   edi,SLOT_BASE
3196
 
3197
 
3197
        and     cl,0x0F
3198
        and     cl,0x0F
3198
        mov     [edi+APPDATA.wnd_caption],0
3199
        mov     [edi+APPDATA.wnd_caption],0
3199
        cmp     cl,3
3200
        cmp     cl,3
3200
        je      set_APPDATA_wnd_caption
3201
        je      set_APPDATA_wnd_caption
3201
        cmp     cl,4                                                            ; {SPraid.simba}
3202
        cmp     cl,4                                                            ; {SPraid.simba}
3202
        je      set_APPDATA_wnd_caption
3203
        je      set_APPDATA_wnd_caption
3203
 
3204
 
3204
        jmp     @f
3205
        jmp     @f
3205
    set_APPDATA_wnd_caption:
3206
    set_APPDATA_wnd_caption:
3206
        mov     [edi+APPDATA.wnd_caption],eax
3207
        mov     [edi+APPDATA.wnd_caption],eax
3207
    @@: mov     esi,[esp+0]
3208
    @@: mov     esi,[esp+0]
3208
 
3209
 
3209
    add   edi, APPDATA.saved_box
3210
    add   edi, APPDATA.saved_box
3210
        movsd
3211
        movsd
3211
        movsd
3212
        movsd
3212
        movsd
3213
        movsd
3213
        movsd
3214
        movsd
3214
    pop   edi esi ecx
3215
    pop   edi esi ecx
3215
 
3216
 
3216
        mov     esi, [CURRENT_TASK]
3217
        mov     esi, [CURRENT_TASK]
3217
        movzx   esi, word [WIN_STACK+esi*2]
3218
        movzx   esi, word [WIN_STACK+esi*2]
3218
        lea     esi, [WIN_POS+esi*2]
3219
        lea     esi, [WIN_POS+esi*2]
3219
        call    waredraw
3220
        call    waredraw
3220
 
3221
 
3221
;;;    mov   ebx, 1
3222
;;;    mov   ebx, 1
3222
;;;    call  delay_hs
3223
;;;    call  delay_hs
3223
    mov   eax, [edi+WDATA.box.left]
3224
    mov   eax, [edi+WDATA.box.left]
3224
    mov   ebx, [edi+WDATA.box.top]
3225
    mov   ebx, [edi+WDATA.box.top]
3225
    mov   ecx, [edi+WDATA.box.width]
3226
    mov   ecx, [edi+WDATA.box.width]
3226
    mov   edx, [edi+WDATA.box.height]
3227
    mov   edx, [edi+WDATA.box.height]
3227
    add   ecx, eax
3228
    add   ecx, eax
3228
    add   edx, ebx
3229
    add   edx, ebx
3229
    call  calculatescreen
3230
    call  calculatescreen
3230
 
3231
 
3231
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3232
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3232
    mov   [BTN_COUNT],byte 0           ; empty button buffer
3233
    mov   [BTN_COUNT],byte 0           ; empty button buffer
3233
 
3234
 
3234
  newd:
3235
  newd:
3235
    call  set_window_clientbox
3236
    call  set_window_clientbox
3236
 
3237
 
3237
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
3238
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
3238
    mov   edx,edi
3239
    mov   edx,edi
3239
 
3240
 
3240
    ret
3241
    ret
3241
 
3242
 
3242
syscall_windowsettings:
3243
syscall_windowsettings:
3243
 
3244
 
3244
  .set_window_caption:
3245
  .set_window_caption:
3245
        dec     eax     ; subfunction #1 - set window caption
3246
        dec     eax     ; subfunction #1 - set window caption
3246
        jnz     .get_window_caption
3247
        jnz     .get_window_caption
3247
 
3248
 
3248
        ; NOTE: only window owner thread can set its caption,
3249
        ; NOTE: only window owner thread can set its caption,
3249
        ;       so there's no parameter for PID/TID
3250
        ;       so there's no parameter for PID/TID
3250
 
3251
 
3251
        mov     edi,[CURRENT_TASK]
3252
        mov     edi,[CURRENT_TASK]
3252
        shl     edi,5
3253
        shl     edi,5
3253
 
3254
 
3254
        ; have to check if caption is within application memory limit
3255
        ; have to check if caption is within application memory limit
3255
        ; check is trivial, and if application resizes its memory,
3256
        ; check is trivial, and if application resizes its memory,
3256
        ;   caption still can become over bounds
3257
        ;   caption still can become over bounds
3257
; diamond, 31.10.2006: check removed because with new memory manager
3258
; diamond, 31.10.2006: check removed because with new memory manager
3258
; there can be valid data after APPDATA.mem_size bound
3259
; there can be valid data after APPDATA.mem_size bound
3259
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3260
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3260
;        add     ecx,255 ; max caption length
3261
;        add     ecx,255 ; max caption length
3261
;        cmp     ebx,ecx
3262
;        cmp     ebx,ecx
3262
;        ja      .exit_fail
3263
;        ja      .exit_fail
3263
 
3264
 
3264
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3265
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3265
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3266
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3266
 
3267
 
3267
        call    draw_window_caption
3268
        call    draw_window_caption
3268
 
3269
 
3269
        xor     eax,eax ; eax = 0 (success)
3270
        xor     eax,eax ; eax = 0 (success)
3270
        ret
3271
        ret
3271
 
3272
 
3272
  .get_window_caption:
3273
  .get_window_caption:
3273
        dec     eax     ; subfunction #2 - get window caption
3274
        dec     eax     ; subfunction #2 - get window caption
3274
        jnz     .exit_fail
3275
        jnz     .exit_fail
3275
 
3276
 
3276
        ; not implemented yet
3277
        ; not implemented yet
3277
 
3278
 
3278
  .exit_fail:
3279
  .exit_fail:
3279
        xor     eax,eax
3280
        xor     eax,eax
3280
        inc     eax     ; eax = 1 (fail)
3281
        inc     eax     ; eax = 1 (fail)
3281
        ret
3282
        ret
3282
 
3283
 
3283
 
3284
 
3284
sys_window_move:
3285
sys_window_move:
3285
 
3286
 
3286
        mov     edi,[CURRENT_TASK]
3287
        mov     edi,[CURRENT_TASK]
3287
        shl     edi,5
3288
        shl     edi,5
3288
        add     edi,window_data
3289
        add     edi,window_data
3289
 
3290
 
3290
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3291
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3291
        jnz     .window_move_return
3292
        jnz     .window_move_return
3292
 
3293
 
3293
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3294
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3294
        push    dword [edi + WDATA.box.top]
3295
        push    dword [edi + WDATA.box.top]
3295
        push    dword [edi + WDATA.box.width]
3296
        push    dword [edi + WDATA.box.width]
3296
        push    dword [edi + WDATA.box.height]
3297
        push    dword [edi + WDATA.box.height]
3297
 
3298
 
3298
        cmp   eax,-1                  ; set new position and size
3299
        cmp   eax,-1                  ; set new position and size
3299
        je    .no_x_reposition
3300
        je    .no_x_reposition
3300
        mov     [edi + WDATA.box.left], eax
3301
        mov     [edi + WDATA.box.left], eax
3301
      .no_x_reposition:
3302
      .no_x_reposition:
3302
        cmp   ebx,-1
3303
        cmp   ebx,-1
3303
        je    .no_y_reposition
3304
        je    .no_y_reposition
3304
        mov     [edi + WDATA.box.top], ebx
3305
        mov     [edi + WDATA.box.top], ebx
3305
      .no_y_reposition:
3306
      .no_y_reposition:
3306
 
3307
 
3307
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3308
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3308
        jnz     .no_y_resizing
3309
        jnz     .no_y_resizing
3309
 
3310
 
3310
        cmp   ecx,-1
3311
        cmp   ecx,-1
3311
        je    .no_x_resizing
3312
        je    .no_x_resizing
3312
        mov     [edi + WDATA.box.width], ecx
3313
        mov     [edi + WDATA.box.width], ecx
3313
      .no_x_resizing:
3314
      .no_x_resizing:
3314
        cmp   edx,-1
3315
        cmp   edx,-1
3315
        je    .no_y_resizing
3316
        je    .no_y_resizing
3316
        mov     [edi + WDATA.box.height], edx
3317
        mov     [edi + WDATA.box.height], edx
3317
      .no_y_resizing:
3318
      .no_y_resizing:
3318
 
3319
 
3319
        call  check_window_position
3320
        call  check_window_position
3320
        call  set_window_clientbox
3321
        call  set_window_clientbox
3321
 
3322
 
3322
        pushad                       ; save for window fullscreen/resize
3323
        pushad                       ; save for window fullscreen/resize
3323
        mov   esi,edi
3324
        mov   esi,edi
3324
        sub   edi,window_data
3325
        sub   edi,window_data
3325
        shr   edi,5
3326
        shr   edi,5
3326
        shl   edi,8
3327
        shl   edi,8
3327
        add   edi, SLOT_BASE + APPDATA.saved_box
3328
        add   edi, SLOT_BASE + APPDATA.saved_box
3328
        mov   ecx,4
3329
        mov   ecx,4
3329
        cld
3330
        cld
3330
        rep   movsd
3331
        rep   movsd
3331
        popad
3332
        popad
3332
 
3333
 
3333
        pushad                       ; calculcate screen at new position
3334
        pushad                       ; calculcate screen at new position
3334
        mov   eax, [edi + WDATA.box.left]
3335
        mov   eax, [edi + WDATA.box.left]
3335
        mov   ebx, [edi + WDATA.box.top]
3336
        mov   ebx, [edi + WDATA.box.top]
3336
        mov   ecx, [edi + WDATA.box.width]
3337
        mov   ecx, [edi + WDATA.box.width]
3337
        mov   edx, [edi + WDATA.box.height]
3338
        mov   edx, [edi + WDATA.box.height]
3338
        add   ecx,eax
3339
        add   ecx,eax
3339
        add   edx,ebx
3340
        add   edx,ebx
3340
 
3341
 
3341
        call  calculatescreen
3342
        call  calculatescreen
3342
        popad
3343
        popad
3343
 
3344
 
3344
        pop   edx                   ; calculcate screen at old position
3345
        pop   edx                   ; calculcate screen at old position
3345
        pop   ecx
3346
        pop   ecx
3346
        pop   ebx
3347
        pop   ebx
3347
        pop   eax
3348
        pop   eax
3348
        add   ecx,eax
3349
        add   ecx,eax
3349
        add   edx,ebx
3350
        add   edx,ebx
3350
        mov   [dlx],eax             ; save for drawlimits
3351
        mov   [dlx],eax             ; save for drawlimits
3351
        mov   [dly],ebx
3352
        mov   [dly],ebx
3352
        mov   [dlxe],ecx
3353
        mov   [dlxe],ecx
3353
        mov   [dlye],edx
3354
        mov   [dlye],edx
3354
        call  calculatescreen
3355
        call  calculatescreen
3355
 
3356
 
3356
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3357
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3357
 
3358
 
3358
        mov   eax,edi               ; redraw screen at old position
3359
        mov   eax,edi               ; redraw screen at old position
3359
        xor   esi,esi
3360
        xor   esi,esi
3360
        call  redrawscreen
3361
        call  redrawscreen
3361
 
3362
 
3362
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3363
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3363
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3364
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3364
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3365
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3365
 
3366
 
3366
        call  [draw_pointer]
3367
        call  [draw_pointer]
3367
 
3368
 
3368
        mov   [window_move_pr],0
3369
        mov   [window_move_pr],0
3369
 
3370
 
3370
      .window_move_return:
3371
      .window_move_return:
3371
 
3372
 
3372
        ret
3373
        ret
3373
 
3374
 
3374
uglobal
3375
uglobal
3375
  window_move_pr   dd  0x0
3376
  window_move_pr   dd  0x0
3376
  window_move_eax  dd  0x0
3377
  window_move_eax  dd  0x0
3377
  window_move_ebx  dd  0x0
3378
  window_move_ebx  dd  0x0
3378
  window_move_ecx  dd  0x0
3379
  window_move_ecx  dd  0x0
3379
  window_move_edx  dd  0x0
3380
  window_move_edx  dd  0x0
3380
endg
3381
endg
3381
 
3382
 
3382
;ok - 100% work
3383
;ok - 100% work
3383
;nt - not tested
3384
;nt - not tested
3384
;---------------------------------------------------------------------------------------------
3385
;---------------------------------------------------------------------------------------------
3385
;eax
3386
;eax
3386
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3387
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3387
;1 - change task. Ret nothing. Block. ok.
3388
;1 - change task. Ret nothing. Block. ok.
3388
;2 - performance control
3389
;2 - performance control
3389
; ebx
3390
; ebx
3390
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3391
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3391
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3392
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3392
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3393
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3393
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3394
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3394
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3395
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3395
;eax
3396
;eax
3396
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3397
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3397
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3398
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3398
;---------------------------------------------------------------------------------------------
3399
;---------------------------------------------------------------------------------------------
3399
sys_sheduler:   
3400
sys_sheduler:   
3400
; old sys_sheduler ;noname & halyavin
3401
; old sys_sheduler ;noname & halyavin
3401
;    cmp eax,0
3402
;    cmp eax,0
3402
;    je shed_counter
3403
;    je shed_counter
3403
;    cmp eax,2
3404
;    cmp eax,2
3404
;    je perf_control
3405
;    je perf_control
3405
;    cmp eax,3
3406
;    cmp eax,3
3406
;    je rdmsr_instr
3407
;    je rdmsr_instr
3407
;    cmp eax,4
3408
;    cmp eax,4
3408
;    je wrmsr_instr
3409
;    je wrmsr_instr
3409
;    cmp eax,1
3410
;    cmp eax,1
3410
;    jne not_supported
3411
;    jne not_supported
3411
;    call change_task ;delay,0
3412
;    call change_task ;delay,0
3412
 
3413
 
3413
;rewritten by   15.11.2009
3414
;rewritten by   15.11.2009
3414
     test	eax,eax		
3415
     test	eax,eax		
3415
     jz         .shed_counter    ;eax=0
3416
     jz         .shed_counter    ;eax=0
3416
     dec	eax             
3417
     dec	eax             
3417
     jz         change_task	 ;eax=1
3418
     jz         change_task	 ;eax=1
3418
     dec	eax
3419
     dec	eax
3419
     jz         .perf_control    ;eax=2
3420
     jz         .perf_control    ;eax=2
3420
     dec	eax
3421
     dec	eax
3421
     jz		.rdmsr_instr     ;eax=3
3422
     jz		.rdmsr_instr     ;eax=3
3422
     dec	eax
3423
     dec	eax
3423
     jnz	@f
3424
     jnz	@f
3424
;wrmsr_instr     ;eax=4
3425
;wrmsr_instr     ;eax=4
3425
;.wrmsr_instr:
3426
;.wrmsr_instr:
3426
;now counter in ecx
3427
;now counter in ecx
3427
;(edx:eax) esi:edi => edx:esi
3428
;(edx:eax) esi:edi => edx:esi
3428
        ; Fast Call MSR can't be destroy
3429
        ; Fast Call MSR can't be destroy
3429
        ; ® MSR_AMD_EFER ¬®¦­® ¨§¬¥­ïâì, â.ª. ¢ í⮬ ॣ¨áâॠ«¨è
3430
        ; ® MSR_AMD_EFER ¬®¦­® ¨§¬¥­ïâì, â.ª. ¢ í⮬ ॣ¨áâॠ«¨è
3430
        ; ¢ª«îç îâáï/¢ëª«îç îâáï à áè¨à¥­­ë¥ ¢®§¬®¦­®áâ¨
3431
        ; ¢ª«îç îâáï/¢ëª«îç îâáï à áè¨à¥­­ë¥ ¢®§¬®¦­®áâ¨
3431
        cmp     ecx, MSR_SYSENTER_CS
3432
        cmp     ecx, MSR_SYSENTER_CS
3432
        je      @f
3433
        je      @f
3433
        cmp     ecx, MSR_SYSENTER_ESP
3434
        cmp     ecx, MSR_SYSENTER_ESP
3434
        je      @f
3435
        je      @f
3435
        cmp     ecx, MSR_SYSENTER_EIP
3436
        cmp     ecx, MSR_SYSENTER_EIP
3436
        je      @f
3437
        je      @f
3437
        cmp     ecx, MSR_AMD_STAR
3438
        cmp     ecx, MSR_AMD_STAR
3438
        je      @f
3439
        je      @f
3439
 
3440
 
3440
        mov     eax, esi
3441
        mov     eax, esi
3441
        wrmsr
3442
        wrmsr
3442
        ; mov   [esp + 36], eax
3443
        ; mov   [esp + 36], eax
3443
        ; mov   [esp + 24], edx ;ret in ebx?
3444
        ; mov   [esp + 24], edx ;ret in ebx?
3444
@@:
3445
@@:
3445
ret
3446
ret
3446
 
3447
 
3447
.shed_counter:
3448
.shed_counter:
3448
    mov eax,[context_counter]
3449
    mov eax,[context_counter]
3449
    mov [esp+36],eax
3450
    mov [esp+36],eax
3450
ret
3451
ret
3451
.perf_control:
3452
.perf_control:
3452
;    inc eax ;now eax=3
3453
;    inc eax ;now eax=3
3453
    add eax,3		;restore eax=3
3454
    add eax,3		;restore eax=3
3454
    cmp ebx,eax
3455
    cmp ebx,eax
3455
    je cache_disable
3456
    je cache_disable
3456
    dec eax
3457
    dec eax
3457
    cmp ebx,eax
3458
    cmp ebx,eax
3458
    je cache_enable
3459
    je cache_enable
3459
    dec eax
3460
    dec eax
3460
    cmp ebx,eax
3461
    cmp ebx,eax
3461
    je is_cache_enabled
3462
    je is_cache_enabled
3462
    dec eax
3463
    dec eax
3463
    cmp ebx,eax
3464
    cmp ebx,eax
3464
    je modify_pce
3465
    je modify_pce
3465
ret
3466
ret
3466
 
3467
 
3467
.rdmsr_instr:
3468
.rdmsr_instr:
3468
;now counter in ecx
3469
;now counter in ecx
3469
;(edx:eax) esi:edi => edx:esi
3470
;(edx:eax) esi:edi => edx:esi
3470
mov eax,esi
3471
mov eax,esi
3471
rdmsr
3472
rdmsr
3472
mov [esp+36],eax
3473
mov [esp+36],eax
3473
mov [esp+24],edx ;ret in ebx?
3474
mov [esp+24],edx ;ret in ebx?
3474
ret
3475
ret
3475
 
3476
 
3476
cache_disable:
3477
cache_disable:
3477
       mov eax,cr0
3478
       mov eax,cr0
3478
       or  eax,01100000000000000000000000000000b
3479
       or  eax,01100000000000000000000000000000b
3479
       mov cr0,eax
3480
       mov cr0,eax
3480
       wbinvd ;set MESI
3481
       wbinvd ;set MESI
3481
ret
3482
ret
3482
 
3483
 
3483
cache_enable:
3484
cache_enable:
3484
       mov eax,cr0
3485
       mov eax,cr0
3485
       and eax,10011111111111111111111111111111b
3486
       and eax,10011111111111111111111111111111b
3486
       mov cr0,eax
3487
       mov cr0,eax
3487
ret
3488
ret
3488
 
3489
 
3489
is_cache_enabled:
3490
is_cache_enabled:
3490
       mov eax,cr0
3491
       mov eax,cr0
3491
       mov ebx,eax
3492
       mov ebx,eax
3492
       and eax,01100000000000000000000000000000b
3493
       and eax,01100000000000000000000000000000b
3493
       jz cache_disabled
3494
       jz cache_disabled
3494
       mov [esp+36],ebx
3495
       mov [esp+36],ebx
3495
cache_disabled:
3496
cache_disabled:
3496
       mov dword [esp+36],eax ;0
3497
       mov dword [esp+36],eax ;0
3497
ret
3498
ret
3498
 
3499
 
3499
modify_pce:
3500
modify_pce:
3500
       mov eax,cr4
3501
       mov eax,cr4
3501
;       mov ebx,0
3502
;       mov ebx,0
3502
;       or  bx,100000000b ;pce
3503
;       or  bx,100000000b ;pce
3503
;       xor eax,ebx ;invert pce
3504
;       xor eax,ebx ;invert pce
3504
       bts eax,8 ;pce=cr4[8]
3505
       bts eax,8 ;pce=cr4[8]
3505
       mov cr4,eax
3506
       mov cr4,eax
3506
       mov [esp+36],eax
3507
       mov [esp+36],eax
3507
ret
3508
ret
3508
;---------------------------------------------------------------------------------------------
3509
;---------------------------------------------------------------------------------------------
3509
 
3510
 
3510
 
3511
 
3511
; check if pixel is allowed to be drawn
3512
; check if pixel is allowed to be drawn
3512
 
3513
 
3513
checkpixel:
3514
checkpixel:
3514
        push eax edx
3515
        push eax edx
3515
 
3516
 
3516
        mov  edx,[Screen_Max_X]     ; screen x size
3517
        mov  edx,[Screen_Max_X]     ; screen x size
3517
        inc  edx
3518
        inc  edx
3518
        imul edx, ebx
3519
        imul edx, ebx
3519
        add  eax, [_WinMapAddress]
3520
        add  eax, [_WinMapAddress]
3520
        mov  dl, [eax+edx] ; lea eax, [...]
3521
        mov  dl, [eax+edx] ; lea eax, [...]
3521
 
3522
 
3522
        xor  ecx, ecx
3523
        xor  ecx, ecx
3523
        mov  eax, [CURRENT_TASK]
3524
        mov  eax, [CURRENT_TASK]
3524
        cmp  al, dl
3525
        cmp  al, dl
3525
        setne cl
3526
        setne cl
3526
 
3527
 
3527
        pop  edx eax
3528
        pop  edx eax
3528
        ret
3529
        ret
3529
 
3530
 
3530
iglobal
3531
iglobal
3531
  cpustring db 'CPU',0
3532
  cpustring db 'CPU',0
3532
endg
3533
endg
3533
 
3534
 
3534
uglobal
3535
uglobal
3535
background_defined    db    0    ; diamond, 11.04.2006
3536
background_defined    db    0    ; diamond, 11.04.2006
3536
endg
3537
endg
3537
 
3538
 
3538
align 4
3539
align 4
3539
; check misc
3540
; check misc
3540
 
3541
 
3541
checkmisc:
3542
checkmisc:
3542
 
3543
 
3543
    cmp   [ctrl_alt_del], 1
3544
    cmp   [ctrl_alt_del], 1
3544
    jne   nocpustart
3545
    jne   nocpustart
3545
 
3546
 
3546
        mov     ebp, cpustring
3547
        mov     ebp, cpustring
3547
        call    fs_execute_from_sysdir
3548
        call    fs_execute_from_sysdir
3548
 
3549
 
3549
    mov   [ctrl_alt_del], 0
3550
    mov   [ctrl_alt_del], 0
3550
 
3551
 
3551
nocpustart:
3552
nocpustart:
3552
    cmp   [mouse_active], 1
3553
    cmp   [mouse_active], 1
3553
    jne   mouse_not_active
3554
    jne   mouse_not_active
3554
    mov   [mouse_active], 0
3555
    mov   [mouse_active], 0
3555
    xor   edi, edi
3556
    xor   edi, edi
3556
    mov   ecx,  [TASK_COUNT]
3557
    mov   ecx,  [TASK_COUNT]
3557
set_mouse_event:
3558
set_mouse_event:
3558
    add   edi, 256
3559
    add   edi, 256
3559
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3560
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3560
    loop  set_mouse_event
3561
    loop  set_mouse_event
3561
 
3562
 
3562
mouse_not_active:
3563
mouse_not_active:
3563
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3564
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3564
    jz    nobackgr
3565
    jz    nobackgr
3565
    cmp    [background_defined], 0
3566
    cmp    [background_defined], 0
3566
    jz    nobackgr
3567
    jz    nobackgr
3567
    cmp   [REDRAW_BACKGROUND], byte 2
3568
    cmp   [REDRAW_BACKGROUND], byte 2
3568
    jnz   no_set_bgr_event
3569
    jnz   no_set_bgr_event
3569
    xor   edi, edi
3570
    xor   edi, edi
3570
    mov   ecx,  [TASK_COUNT]
3571
    mov   ecx,  [TASK_COUNT]
3571
set_bgr_event:
3572
set_bgr_event:
3572
    add   edi, 256
3573
    add   edi, 256
3573
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3574
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3574
    loop  set_bgr_event
3575
    loop  set_bgr_event
3575
no_set_bgr_event:
3576
no_set_bgr_event:
3576
;    mov   [draw_data+32 + RECT.left],dword 0
3577
;    mov   [draw_data+32 + RECT.left],dword 0
3577
;    mov   [draw_data+32 + RECT.top],dword 0
3578
;    mov   [draw_data+32 + RECT.top],dword 0
3578
;    mov   eax,[Screen_Max_X]
3579
;    mov   eax,[Screen_Max_X]
3579
;    mov   ebx,[Screen_Max_Y]
3580
;    mov   ebx,[Screen_Max_Y]
3580
;    mov   [draw_data+32 + RECT.right],eax
3581
;    mov   [draw_data+32 + RECT.right],eax
3581
;    mov   [draw_data+32 + RECT.bottom],ebx
3582
;    mov   [draw_data+32 + RECT.bottom],ebx
3582
    call  drawbackground
3583
    call  drawbackground
3583
    mov   [REDRAW_BACKGROUND],byte 0
3584
    mov   [REDRAW_BACKGROUND],byte 0
3584
    mov   [MOUSE_BACKGROUND],byte 0
3585
    mov   [MOUSE_BACKGROUND],byte 0
3585
 
3586
 
3586
nobackgr:
3587
nobackgr:
3587
 
3588
 
3588
    ; system shutdown request
3589
    ; system shutdown request
3589
 
3590
 
3590
    cmp  [SYS_SHUTDOWN],byte 0
3591
    cmp  [SYS_SHUTDOWN],byte 0
3591
    je   noshutdown
3592
    je   noshutdown
3592
 
3593
 
3593
    mov  edx,[shutdown_processes]
3594
    mov  edx,[shutdown_processes]
3594
 
3595
 
3595
    cmp  [SYS_SHUTDOWN],dl
3596
    cmp  [SYS_SHUTDOWN],dl
3596
    jne  no_mark_system_shutdown
3597
    jne  no_mark_system_shutdown
3597
 
3598
 
3598
    lea   ecx,[edx-1]
3599
    lea   ecx,[edx-1]
3599
    mov   edx,OS_BASE+0x3040
3600
    mov   edx,OS_BASE+0x3040
3600
    jecxz @f
3601
    jecxz @f
3601
markz:
3602
markz:
3602
    mov   [edx+TASKDATA.state],byte 3
3603
    mov   [edx+TASKDATA.state],byte 3
3603
    add   edx,0x20
3604
    add   edx,0x20
3604
    loop  markz
3605
    loop  markz
3605
@@:
3606
@@:
3606
 
3607
 
3607
  no_mark_system_shutdown:
3608
  no_mark_system_shutdown:
3608
 
3609
 
3609
    call [_display.disable_mouse]
3610
    call [_display.disable_mouse]
3610
 
3611
 
3611
    dec  byte [SYS_SHUTDOWN]
3612
    dec  byte [SYS_SHUTDOWN]
3612
    je   system_shutdown
3613
    je   system_shutdown
3613
 
3614
 
3614
noshutdown:
3615
noshutdown:
3615
 
3616
 
3616
 
3617
 
3617
    mov   eax,[TASK_COUNT]                  ; termination
3618
    mov   eax,[TASK_COUNT]                  ; termination
3618
    mov   ebx,TASK_DATA+TASKDATA.state
3619
    mov   ebx,TASK_DATA+TASKDATA.state
3619
    mov   esi,1
3620
    mov   esi,1
3620
 
3621
 
3621
newct:
3622
newct:
3622
    mov   cl,[ebx]
3623
    mov   cl,[ebx]
3623
    cmp   cl,byte 3
3624
    cmp   cl,byte 3
3624
    jz    terminate
3625
    jz    terminate
3625
    cmp   cl,byte 4
3626
    cmp   cl,byte 4
3626
    jz    terminate
3627
    jz    terminate
3627
 
3628
 
3628
    add   ebx,0x20
3629
    add   ebx,0x20
3629
    inc   esi
3630
    inc   esi
3630
    dec   eax
3631
    dec   eax
3631
    jnz   newct
3632
    jnz   newct
3632
    ret
3633
    ret
3633
 
3634
 
3634
; redraw screen
3635
; redraw screen
3635
 
3636
 
3636
redrawscreen:
3637
redrawscreen:
3637
 
3638
 
3638
; eax , if process window_data base is eax, do not set flag/limits
3639
; eax , if process window_data base is eax, do not set flag/limits
3639
 
3640
 
3640
         pushad
3641
         pushad
3641
         push  eax
3642
         push  eax
3642
 
3643
 
3643
;;;         mov   ebx,2
3644
;;;         mov   ebx,2
3644
;;;         call  delay_hs
3645
;;;         call  delay_hs
3645
 
3646
 
3646
         ;mov   ecx,0               ; redraw flags for apps
3647
         ;mov   ecx,0               ; redraw flags for apps
3647
         xor   ecx,ecx
3648
         xor   ecx,ecx
3648
       newdw2:
3649
       newdw2:
3649
 
3650
 
3650
         inc   ecx
3651
         inc   ecx
3651
         push  ecx
3652
         push  ecx
3652
 
3653
 
3653
         mov   eax,ecx
3654
         mov   eax,ecx
3654
         shl   eax,5
3655
         shl   eax,5
3655
         add   eax,window_data
3656
         add   eax,window_data
3656
 
3657
 
3657
         cmp   eax,[esp+4]
3658
         cmp   eax,[esp+4]
3658
         je    not_this_task
3659
         je    not_this_task
3659
                                   ; check if window in redraw area
3660
                                   ; check if window in redraw area
3660
         mov   edi,eax
3661
         mov   edi,eax
3661
 
3662
 
3662
         cmp   ecx,1               ; limit for background
3663
         cmp   ecx,1               ; limit for background
3663
         jz    bgli
3664
         jz    bgli
3664
 
3665
 
3665
         mov   eax, [edi + WDATA.box.left]
3666
         mov   eax, [edi + WDATA.box.left]
3666
         mov   ebx, [edi + WDATA.box.top]
3667
         mov   ebx, [edi + WDATA.box.top]
3667
         mov   ecx, [edi + WDATA.box.width]
3668
         mov   ecx, [edi + WDATA.box.width]
3668
         mov   edx, [edi + WDATA.box.height]
3669
         mov   edx, [edi + WDATA.box.height]
3669
         add   ecx,eax
3670
         add   ecx,eax
3670
         add   edx,ebx
3671
         add   edx,ebx
3671
 
3672
 
3672
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3673
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3673
         cmp   ecx,ebx
3674
         cmp   ecx,ebx
3674
         jb    ricino
3675
         jb    ricino
3675
 
3676
 
3676
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3677
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3677
         cmp   ecx,eax
3678
         cmp   ecx,eax
3678
         jb    ricino
3679
         jb    ricino
3679
 
3680
 
3680
         mov   eax, [edi + WDATA.box.left]
3681
         mov   eax, [edi + WDATA.box.left]
3681
         mov   ebx, [edi + WDATA.box.top]
3682
         mov   ebx, [edi + WDATA.box.top]
3682
         mov   ecx, [edi + WDATA.box.width]
3683
         mov   ecx, [edi + WDATA.box.width]
3683
         mov   edx, [edi + WDATA.box.height]
3684
         mov   edx, [edi + WDATA.box.height]
3684
         add   ecx, eax
3685
         add   ecx, eax
3685
         add   edx, ebx
3686
         add   edx, ebx
3686
 
3687
 
3687
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3688
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3688
         cmp   edx,eax
3689
         cmp   edx,eax
3689
         jb    ricino
3690
         jb    ricino
3690
 
3691
 
3691
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3692
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3692
         cmp   ecx,eax
3693
         cmp   ecx,eax
3693
         jb    ricino
3694
         jb    ricino
3694
 
3695
 
3695
        bgli:
3696
        bgli:
3696
 
3697
 
3697
         cmp   ecx,1
3698
         cmp   ecx,1
3698
         jnz   .az
3699
         jnz   .az
3699
         mov   al,[REDRAW_BACKGROUND]
3700
         mov   al,[REDRAW_BACKGROUND]
3700
         cmp   al,2
3701
         cmp   al,2
3701
         jz    newdw8
3702
         jz    newdw8
3702
         test  al,al
3703
         test  al,al
3703
         jz    .az
3704
         jz    .az
3704
         lea   eax,[edi+draw_data-window_data]
3705
         lea   eax,[edi+draw_data-window_data]
3705
         mov   ebx,[dlx]
3706
         mov   ebx,[dlx]
3706
         cmp   ebx,[eax+RECT.left]
3707
         cmp   ebx,[eax+RECT.left]
3707
         jae   @f
3708
         jae   @f
3708
         mov   [eax+RECT.left],ebx
3709
         mov   [eax+RECT.left],ebx
3709
        @@:
3710
        @@:
3710
         mov   ebx,[dly]
3711
         mov   ebx,[dly]
3711
         cmp   ebx,[eax+RECT.top]
3712
         cmp   ebx,[eax+RECT.top]
3712
         jae   @f
3713
         jae   @f
3713
         mov   [eax+RECT.top],ebx
3714
         mov   [eax+RECT.top],ebx
3714
        @@:
3715
        @@:
3715
         mov   ebx,[dlxe]
3716
         mov   ebx,[dlxe]
3716
         cmp   ebx,[eax+RECT.right]
3717
         cmp   ebx,[eax+RECT.right]
3717
         jbe   @f
3718
         jbe   @f
3718
         mov   [eax+RECT.right],ebx
3719
         mov   [eax+RECT.right],ebx
3719
        @@:
3720
        @@:
3720
         mov   ebx,[dlye]
3721
         mov   ebx,[dlye]
3721
         cmp   ebx,[eax+RECT.bottom]
3722
         cmp   ebx,[eax+RECT.bottom]
3722
         jbe   @f
3723
         jbe   @f
3723
         mov   [eax+RECT.bottom],ebx
3724
         mov   [eax+RECT.bottom],ebx
3724
        @@:
3725
        @@:
3725
         jmp   newdw8
3726
         jmp   newdw8
3726
        .az:
3727
        .az:
3727
 
3728
 
3728
         mov   eax,edi
3729
         mov   eax,edi
3729
         add   eax,draw_data-window_data
3730
         add   eax,draw_data-window_data
3730
 
3731
 
3731
         mov   ebx,[dlx]          ; set limits
3732
         mov   ebx,[dlx]          ; set limits
3732
         mov   [eax + RECT.left], ebx
3733
         mov   [eax + RECT.left], ebx
3733
         mov   ebx,[dly]
3734
         mov   ebx,[dly]
3734
         mov   [eax + RECT.top], ebx
3735
         mov   [eax + RECT.top], ebx
3735
         mov   ebx,[dlxe]
3736
         mov   ebx,[dlxe]
3736
         mov   [eax + RECT.right], ebx
3737
         mov   [eax + RECT.right], ebx
3737
         mov   ebx,[dlye]
3738
         mov   ebx,[dlye]
3738
         mov   [eax + RECT.bottom], ebx
3739
         mov   [eax + RECT.bottom], ebx
3739
 
3740
 
3740
         sub   eax,draw_data-window_data
3741
         sub   eax,draw_data-window_data
3741
 
3742
 
3742
         cmp   dword [esp],1
3743
         cmp   dword [esp],1
3743
         jne   nobgrd
3744
         jne   nobgrd
3744
         mov   byte [REDRAW_BACKGROUND], 1
3745
         mov   byte [REDRAW_BACKGROUND], 1
3745
 
3746
 
3746
       newdw8:
3747
       newdw8:
3747
       nobgrd:
3748
       nobgrd:
3748
 
3749
 
3749
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3750
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3750
 
3751
 
3751
       ricino:
3752
       ricino:
3752
 
3753
 
3753
       not_this_task:
3754
       not_this_task:
3754
 
3755
 
3755
         pop   ecx
3756
         pop   ecx
3756
 
3757
 
3757
         cmp   ecx,[TASK_COUNT]
3758
         cmp   ecx,[TASK_COUNT]
3758
         jle   newdw2
3759
         jle   newdw2
3759
 
3760
 
3760
         pop  eax
3761
         pop  eax
3761
         popad
3762
         popad
3762
 
3763
 
3763
         ret
3764
         ret
3764
 
3765
 
3765
calculatebackground:   ; background
3766
calculatebackground:   ; background
3766
 
3767
 
3767
        mov   edi, [_WinMapAddress]                ; set os to use all pixels
3768
        mov   edi, [_WinMapAddress]                ; set os to use all pixels
3768
        mov   eax,0x01010101
3769
        mov   eax,0x01010101
3769
        mov   ecx, [_WinMapSize]
3770
        mov   ecx, [_WinMapSize]
3770
        shr   ecx, 2
3771
        shr   ecx, 2
3771
        rep   stosd
3772
        rep   stosd
3772
 
3773
 
3773
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3774
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3774
 
3775
 
3775
        ret
3776
        ret
3776
 
3777
 
3777
uglobal
3778
uglobal
3778
  imax    dd 0x0
3779
  imax    dd 0x0
3779
endg
3780
endg
3780
 
3781
 
3781
 
3782
 
3782
 
3783
 
3783
delay_ms:     ; delay in 1/1000 sec
3784
delay_ms:     ; delay in 1/1000 sec
3784
 
3785
 
3785
 
3786
 
3786
        push  eax
3787
        push  eax
3787
        push  ecx
3788
        push  ecx
3788
 
3789
 
3789
        mov   ecx,esi
3790
        mov   ecx,esi
3790
        ; 
3791
        ; 
3791
        imul  ecx, 33941
3792
        imul  ecx, 33941
3792
        shr   ecx, 9
3793
        shr   ecx, 9
3793
        ; 
3794
        ; 
3794
 
3795
 
3795
        in    al,0x61
3796
        in    al,0x61
3796
        and   al,0x10
3797
        and   al,0x10
3797
        mov   ah,al
3798
        mov   ah,al
3798
        cld
3799
        cld
3799
 
3800
 
3800
 cnt1:  in    al,0x61
3801
 cnt1:  in    al,0x61
3801
        and   al,0x10
3802
        and   al,0x10
3802
        cmp   al,ah
3803
        cmp   al,ah
3803
        jz    cnt1
3804
        jz    cnt1
3804
 
3805
 
3805
        mov   ah,al
3806
        mov   ah,al
3806
        loop  cnt1
3807
        loop  cnt1
3807
 
3808
 
3808
        pop   ecx
3809
        pop   ecx
3809
        pop   eax
3810
        pop   eax
3810
 
3811
 
3811
        ret
3812
        ret
3812
 
3813
 
3813
 
3814
 
3814
set_app_param:
3815
set_app_param:
3815
        mov     edi, [TASK_BASE]
3816
        mov     edi, [TASK_BASE]
3816
        mov     eax, [edi + TASKDATA.event_mask]
3817
        mov     eax, [edi + TASKDATA.event_mask]
3817
        mov     [edi + TASKDATA.event_mask], ebx
3818
        mov     [edi + TASKDATA.event_mask], ebx
3818
        mov     [esp+32], eax
3819
        mov     [esp+32], eax
3819
        ret
3820
        ret
3820
 
3821
 
3821
 
3822
 
3822
 
3823
 
3823
delay_hs:     ; delay in 1/100 secs
3824
delay_hs:     ; delay in 1/100 secs
3824
; ebx = delay time
3825
; ebx = delay time
3825
        push  ecx
3826
        push  ecx
3826
        push  edx
3827
        push  edx
3827
 
3828
 
3828
        mov   edx,[timer_ticks]
3829
        mov   edx,[timer_ticks]
3829
 
3830
 
3830
      newtic:
3831
      newtic:
3831
        mov   ecx,[timer_ticks]
3832
        mov   ecx,[timer_ticks]
3832
        sub   ecx,edx
3833
        sub   ecx,edx
3833
        cmp   ecx,ebx
3834
        cmp   ecx,ebx
3834
        jae   zerodelay
3835
        jae   zerodelay
3835
 
3836
 
3836
        call  change_task
3837
        call  change_task
3837
 
3838
 
3838
        jmp   newtic
3839
        jmp   newtic
3839
 
3840
 
3840
      zerodelay:
3841
      zerodelay:
3841
        pop   edx
3842
        pop   edx
3842
        pop   ecx
3843
        pop   ecx
3843
 
3844
 
3844
        ret
3845
        ret
3845
 
3846
 
3846
align 16	;very often call this subrutine
3847
align 16	;very often call this subrutine
3847
memmove:       ; memory move in bytes
3848
memmove:       ; memory move in bytes
3848
 
3849
 
3849
; eax = from
3850
; eax = from
3850
; ebx = to
3851
; ebx = to
3851
; ecx = no of bytes
3852
; ecx = no of bytes
3852
    test ecx, ecx
3853
    test ecx, ecx
3853
    jle  .ret
3854
    jle  .ret
3854
 
3855
 
3855
    push esi edi ecx
3856
    push esi edi ecx
3856
 
3857
 
3857
    mov  edi, ebx
3858
    mov  edi, ebx
3858
    mov  esi, eax
3859
    mov  esi, eax
3859
 
3860
 
3860
    test ecx, not 11b
3861
    test ecx, not 11b
3861
    jz   @f
3862
    jz   @f
3862
 
3863
 
3863
    push ecx
3864
    push ecx
3864
    shr  ecx, 2
3865
    shr  ecx, 2
3865
    rep  movsd
3866
    rep  movsd
3866
    pop  ecx
3867
    pop  ecx
3867
    and  ecx, 11b
3868
    and  ecx, 11b
3868
    jz   .finish
3869
    jz   .finish
3869
  @@:
3870
  @@:
3870
    rep  movsb
3871
    rep  movsb
3871
 
3872
 
3872
  .finish:
3873
  .finish:
3873
    pop  ecx edi esi
3874
    pop  ecx edi esi
3874
  .ret:
3875
  .ret:
3875
    ret
3876
    ret
3876
 
3877
 
3877
 
3878
 
3878
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3879
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3879
;align 4
3880
;align 4
3880
;
3881
;
3881
;read_floppy_file:
3882
;read_floppy_file:
3882
;
3883
;
3883
;; as input
3884
;; as input
3884
;;
3885
;;
3885
;; eax pointer to file
3886
;; eax pointer to file
3886
;; ebx file lenght
3887
;; ebx file lenght
3887
;; ecx start 512 byte block number
3888
;; ecx start 512 byte block number
3888
;; edx number of blocks to read
3889
;; edx number of blocks to read
3889
;; esi pointer to return/work area (atleast 20 000 bytes)
3890
;; esi pointer to return/work area (atleast 20 000 bytes)
3890
;;
3891
;;
3891
;;
3892
;;
3892
;; on return
3893
;; on return
3893
;;
3894
;;
3894
;; eax = 0 command succesful
3895
;; eax = 0 command succesful
3895
;;       1 no fd base and/or partition defined
3896
;;       1 no fd base and/or partition defined
3896
;;       2 yet unsupported FS
3897
;;       2 yet unsupported FS
3897
;;       3 unknown FS
3898
;;       3 unknown FS
3898
;;       4 partition not defined at hd
3899
;;       4 partition not defined at hd
3899
;;       5 file not found
3900
;;       5 file not found
3900
;; ebx = size of file
3901
;; ebx = size of file
3901
;
3902
;
3902
;     mov   edi,[TASK_BASE]
3903
;     mov   edi,[TASK_BASE]
3903
;     add   edi,0x10
3904
;     add   edi,0x10
3904
;     add   esi,[edi]
3905
;     add   esi,[edi]
3905
;     add   eax,[edi]
3906
;     add   eax,[edi]
3906
;
3907
;
3907
;     pushad
3908
;     pushad
3908
;     mov  edi,esi
3909
;     mov  edi,esi
3909
;     add  edi,1024
3910
;     add  edi,1024
3910
;     mov  esi,0x100000+19*512
3911
;     mov  esi,0x100000+19*512
3911
;     sub  ecx,1
3912
;     sub  ecx,1
3912
;     shl  ecx,9
3913
;     shl  ecx,9
3913
;     add  esi,ecx
3914
;     add  esi,ecx
3914
;     shl  edx,9
3915
;     shl  edx,9
3915
;     mov  ecx,edx
3916
;     mov  ecx,edx
3916
;     cld
3917
;     cld
3917
;     rep  movsb
3918
;     rep  movsb
3918
;     popad
3919
;     popad
3919
;
3920
;
3920
;     mov   [esp+36],eax
3921
;     mov   [esp+36],eax
3921
;     mov   [esp+24],ebx
3922
;     mov   [esp+24],ebx
3922
;     ret
3923
;     ret
3923
 
3924
 
3924
 
3925
 
3925
 
3926
 
3926
align 4
3927
align 4
3927
 
3928
 
3928
sys_programirq:
3929
sys_programirq:
3929
 
3930
 
3930
    mov   eax, [TASK_BASE]
3931
    mov   eax, [TASK_BASE]
3931
    add   ebx, [eax + TASKDATA.mem_start]
3932
    add   ebx, [eax + TASKDATA.mem_start]
3932
 
3933
 
3933
    cmp   ecx, 16
3934
    cmp   ecx, 16
3934
    jae   .not_owner
3935
    jae   .not_owner
3935
    mov   edi, [eax + TASKDATA.pid]
3936
    mov   edi, [eax + TASKDATA.pid]
3936
    cmp   edi, [irq_owner + 4 * ecx]
3937
    cmp   edi, [irq_owner + 4 * ecx]
3937
    je    .spril1
3938
    je    .spril1
3938
.not_owner:
3939
.not_owner:
3939
    xor   ecx, ecx
3940
    xor   ecx, ecx
3940
    inc   ecx
3941
    inc   ecx
3941
    jmp   .end
3942
    jmp   .end
3942
  .spril1:
3943
  .spril1:
3943
 
3944
 
3944
    shl   ecx, 6
3945
    shl   ecx, 6
3945
    mov   esi, ebx
3946
    mov   esi, ebx
3946
    lea   edi, [irq00read + ecx]
3947
    lea   edi, [irq00read + ecx]
3947
    push  16
3948
    push  16
3948
    pop   ecx
3949
    pop   ecx
3949
 
3950
 
3950
    cld
3951
    cld
3951
    rep   movsd
3952
    rep   movsd
3952
  .end:
3953
  .end:
3953
    mov   [esp+32], ecx
3954
    mov   [esp+32], ecx
3954
    ret
3955
    ret
3955
 
3956
 
3956
 
3957
 
3957
align 4
3958
align 4
3958
 
3959
 
3959
get_irq_data:
3960
get_irq_data:
3960
     movzx esi, bh                       ; save number of subfunction, if bh = 1, return data size, otherwise, read data
3961
     movzx esi, bh                       ; save number of subfunction, if bh = 1, return data size, otherwise, read data
3961
     xor   bh, bh
3962
     xor   bh, bh
3962
     cmp   ebx, 16
3963
     cmp   ebx, 16
3963
     jae   .not_owner
3964
     jae   .not_owner
3964
     mov   edx, [4 * ebx + irq_owner]    ; check for irq owner
3965
     mov   edx, [4 * ebx + irq_owner]    ; check for irq owner
3965
 
3966
 
3966
     mov   eax,[TASK_BASE]
3967
     mov   eax,[TASK_BASE]
3967
 
3968
 
3968
     cmp   edx,[eax+TASKDATA.pid]
3969
     cmp   edx,[eax+TASKDATA.pid]
3969
     je    gidril1
3970
     je    gidril1
3970
.not_owner:
3971
.not_owner:
3971
     xor   edx, edx
3972
     xor   edx, edx
3972
     dec   edx
3973
     dec   edx
3973
     jmp   gid1
3974
     jmp   gid1
3974
 
3975
 
3975
  gidril1:
3976
  gidril1:
3976
 
3977
 
3977
     shl   ebx, 12
3978
     shl   ebx, 12
3978
     lea   eax, [ebx + IRQ_SAVE]         ; calculate address of the beginning of buffer + 0x0 - data size
3979
     lea   eax, [ebx + IRQ_SAVE]         ; calculate address of the beginning of buffer + 0x0 - data size
3979
     mov   edx, [eax]                    ;                                              + 0x4 - data offset
3980
     mov   edx, [eax]                    ;                                              + 0x4 - data offset
3980
     dec   esi
3981
     dec   esi
3981
     jz    gid1
3982
     jz    gid1
3982
     test  edx, edx                      ; check if buffer is empty
3983
     test  edx, edx                      ; check if buffer is empty
3983
     jz    gid1
3984
     jz    gid1
3984
 
3985
 
3985
     mov   ebx, [eax + 0x4]
3986
     mov   ebx, [eax + 0x4]
3986
     mov   edi, ecx
3987
     mov   edi, ecx
3987
 
3988
 
3988
     mov   ecx, 4000                     ; buffer size, used frequently
3989
     mov   ecx, 4000                     ; buffer size, used frequently
3989
 
3990
 
3990
     cmp   ebx, ecx                      ; check for the end of buffer, if end of buffer, begin cycle again
3991
     cmp   ebx, ecx                      ; check for the end of buffer, if end of buffer, begin cycle again
3991
     jb    @f
3992
     jb    @f
3992
 
3993
 
3993
     xor   ebx, ebx
3994
     xor   ebx, ebx
3994
 
3995
 
3995
   @@:
3996
   @@:
3996
 
3997
 
3997
     lea   esi, [ebx + edx]              ; calculate data size and offset
3998
     lea   esi, [ebx + edx]              ; calculate data size and offset
3998
     cld
3999
     cld
3999
     cmp   esi, ecx                      ; if greater than the buffer size, begin cycle again
4000
     cmp   esi, ecx                      ; if greater than the buffer size, begin cycle again
4000
     jbe   @f
4001
     jbe   @f
4001
 
4002
 
4002
     sub   ecx, ebx
4003
     sub   ecx, ebx
4003
     sub   edx, ecx
4004
     sub   edx, ecx
4004
 
4005
 
4005
     lea   esi, [eax + ebx + 0x10]
4006
     lea   esi, [eax + ebx + 0x10]
4006
     rep   movsb
4007
     rep   movsb
4007
 
4008
 
4008
     xor   ebx, ebx
4009
     xor   ebx, ebx
4009
   @@:
4010
   @@:
4010
     lea   esi, [eax + ebx + 0x10]
4011
     lea   esi, [eax + ebx + 0x10]
4011
     mov   ecx, edx
4012
     mov   ecx, edx
4012
     add   ebx, edx
4013
     add   ebx, edx
4013
 
4014
 
4014
     rep   movsb
4015
     rep   movsb
4015
     mov   edx, [eax]
4016
     mov   edx, [eax]
4016
     mov   [eax], ecx                    ; set data size to zero
4017
     mov   [eax], ecx                    ; set data size to zero
4017
     mov   [eax + 0x4], ebx              ; set data offset
4018
     mov   [eax + 0x4], ebx              ; set data offset
4018
 
4019
 
4019
   gid1:
4020
   gid1:
4020
     mov   [esp+32], edx                 ; eax
4021
     mov   [esp+32], edx                 ; eax
4021
     ret
4022
     ret
4022
 
4023
 
4023
 
4024
 
4024
set_io_access_rights:
4025
set_io_access_rights:
4025
      push edi eax
4026
      push edi eax
4026
      mov edi, tss._io_map_0
4027
      mov edi, tss._io_map_0
4027
;     mov   ecx,eax
4028
;     mov   ecx,eax
4028
;     and   ecx,7    ; offset in byte
4029
;     and   ecx,7    ; offset in byte
4029
;     shr   eax,3    ; number of byte
4030
;     shr   eax,3    ; number of byte
4030
;     add   edi,eax
4031
;     add   edi,eax
4031
;     mov   ebx,1
4032
;     mov   ebx,1
4032
;     shl   ebx,cl
4033
;     shl   ebx,cl
4033
     test  ebp,ebp
4034
     test  ebp,ebp
4034
;     cmp   ebp,0                ; enable access - ebp = 0
4035
;     cmp   ebp,0                ; enable access - ebp = 0
4035
     jnz   siar1
4036
     jnz   siar1
4036
;     not   ebx
4037
;     not   ebx
4037
;     and   [edi],byte bl
4038
;     and   [edi],byte bl
4038
     btr [edi], eax
4039
     btr [edi], eax
4039
     pop eax edi
4040
     pop eax edi
4040
     ret
4041
     ret
4041
siar1:
4042
siar1:
4042
     bts [edi], eax
4043
     bts [edi], eax
4043
  ;  or    [edi],byte bl        ; disable access - ebp = 1
4044
  ;  or    [edi],byte bl        ; disable access - ebp = 1
4044
     pop eax edi
4045
     pop eax edi
4045
     ret
4046
     ret
4046
;reserve/free group of ports
4047
;reserve/free group of ports
4047
;  * eax = 46 - number function
4048
;  * eax = 46 - number function
4048
;  * ebx = 0 - reserve, 1 - free
4049
;  * ebx = 0 - reserve, 1 - free
4049
;  * ecx = number start arrea of ports
4050
;  * ecx = number start arrea of ports
4050
;  * edx = number end arrea of ports (include last number of port)
4051
;  * edx = number end arrea of ports (include last number of port)
4051
;Return value:
4052
;Return value:
4052
;  * eax = 0 - succesful 
4053
;  * eax = 0 - succesful 
4053
;  * eax = 1 - error
4054
;  * eax = 1 - error
4054
;  * The system has reserve this ports:
4055
;  * The system has reserve this ports:
4055
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
4056
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
4056
;destroys eax,ebx, ebp
4057
;destroys eax,ebx, ebp
4057
r_f_port_area:
4058
r_f_port_area:
4058
 
4059
 
4059
     test  ebx, ebx
4060
     test  ebx, ebx
4060
     jnz   free_port_area
4061
     jnz   free_port_area
4061
;     je    r_port_area
4062
;     je    r_port_area
4062
;     jmp   free_port_area
4063
;     jmp   free_port_area
4063
 
4064
 
4064
;   r_port_area:
4065
;   r_port_area:
4065
 
4066
 
4066
;     pushad
4067
;     pushad
4067
 
4068
 
4068
     cmp   ecx,edx            ; beginning > end ?
4069
     cmp   ecx,edx            ; beginning > end ?
4069
     ja    rpal1
4070
     ja    rpal1
4070
     cmp   edx,65536
4071
     cmp   edx,65536
4071
     jae   rpal1
4072
     jae   rpal1
4072
     mov   eax,[RESERVED_PORTS]
4073
     mov   eax,[RESERVED_PORTS]
4073
     test  eax,eax            ; no reserved areas ?
4074
     test  eax,eax            ; no reserved areas ?
4074
     je    rpal2
4075
     je    rpal2
4075
     cmp   eax,255            ; max reserved
4076
     cmp   eax,255            ; max reserved
4076
     jae   rpal1
4077
     jae   rpal1
4077
 rpal3:
4078
 rpal3:
4078
     mov   ebx,eax
4079
     mov   ebx,eax
4079
     shl   ebx,4
4080
     shl   ebx,4
4080
     add   ebx,RESERVED_PORTS
4081
     add   ebx,RESERVED_PORTS
4081
     cmp   ecx,[ebx+8]
4082
     cmp   ecx,[ebx+8]
4082
     ja    rpal4
4083
     ja    rpal4
4083
     cmp   edx,[ebx+4]
4084
     cmp   edx,[ebx+4]
4084
     jae   rpal1
4085
     jae   rpal1
4085
;     jb    rpal4
4086
;     jb    rpal4
4086
;     jmp   rpal1
4087
;     jmp   rpal1
4087
 rpal4:
4088
 rpal4:
4088
     dec   eax
4089
     dec   eax
4089
     jnz   rpal3
4090
     jnz   rpal3
4090
     jmp   rpal2
4091
     jmp   rpal2
4091
   rpal1:
4092
   rpal1:
4092
;     popad
4093
;     popad
4093
;     mov   eax,1
4094
;     mov   eax,1
4094
     xor    eax,eax
4095
     xor    eax,eax
4095
     inc    eax
4096
     inc    eax
4096
     ret
4097
     ret
4097
   rpal2:
4098
   rpal2:
4098
;     popad
4099
;     popad
4099
     ; enable port access at port IO map
4100
     ; enable port access at port IO map
4100
	cli
4101
	cli
4101
	pushad                        ; start enable io map
4102
	pushad                        ; start enable io map
4102
 
4103
 
4103
	cmp   edx,65536 ;16384
4104
	cmp   edx,65536 ;16384
4104
	jae   no_unmask_io ; jge
4105
	jae   no_unmask_io ; jge
4105
	mov   eax,ecx
4106
	mov   eax,ecx
4106
;	push	ebp
4107
;	push	ebp
4107
	xor	ebp,ebp                ; enable - eax = port
4108
	xor	ebp,ebp                ; enable - eax = port
4108
new_port_access:
4109
new_port_access:
4109
;     pushad
4110
;     pushad
4110
	call	set_io_access_rights
4111
	call	set_io_access_rights
4111
;     popad
4112
;     popad
4112
     inc   eax
4113
     inc   eax
4113
     cmp   eax,edx
4114
     cmp   eax,edx
4114
     jbe   new_port_access
4115
     jbe   new_port_access
4115
;	pop	ebp
4116
;	pop	ebp
4116
no_unmask_io:
4117
no_unmask_io:
4117
	popad                         ; end enable io map
4118
	popad                         ; end enable io map
4118
     sti
4119
     sti
4119
 
4120
 
4120
     mov   eax,[RESERVED_PORTS]
4121
     mov   eax,[RESERVED_PORTS]
4121
     add   eax,1
4122
     add   eax,1
4122
     mov   [RESERVED_PORTS],eax
4123
     mov   [RESERVED_PORTS],eax
4123
     shl   eax,4
4124
     shl   eax,4
4124
     add   eax,RESERVED_PORTS
4125
     add   eax,RESERVED_PORTS
4125
     mov   ebx,[TASK_BASE]
4126
     mov   ebx,[TASK_BASE]
4126
     mov   ebx,[ebx+TASKDATA.pid]
4127
     mov   ebx,[ebx+TASKDATA.pid]
4127
     mov   [eax],ebx
4128
     mov   [eax],ebx
4128
     mov   [eax+4],ecx
4129
     mov   [eax+4],ecx
4129
     mov   [eax+8],edx
4130
     mov   [eax+8],edx
4130
 
4131
 
4131
     xor   eax, eax
4132
     xor   eax, eax
4132
     ret
4133
     ret
4133
 
4134
 
4134
free_port_area:
4135
free_port_area:
4135
 
4136
 
4136
;     pushad
4137
;     pushad
4137
     mov   eax,[RESERVED_PORTS]     ; no reserved areas ?
4138
     mov   eax,[RESERVED_PORTS]     ; no reserved areas ?
4138
     test  eax,eax
4139
     test  eax,eax
4139
     jz    frpal2
4140
     jz    frpal2
4140
     mov   ebx,[TASK_BASE]
4141
     mov   ebx,[TASK_BASE]
4141
     mov   ebx,[ebx+TASKDATA.pid]
4142
     mov   ebx,[ebx+TASKDATA.pid]
4142
   frpal3:
4143
   frpal3:
4143
     mov   edi,eax
4144
     mov   edi,eax
4144
     shl   edi,4
4145
     shl   edi,4
4145
     add   edi,RESERVED_PORTS
4146
     add   edi,RESERVED_PORTS
4146
     cmp   ebx,[edi]
4147
     cmp   ebx,[edi]
4147
     jne   frpal4
4148
     jne   frpal4
4148
     cmp   ecx,[edi+4]
4149
     cmp   ecx,[edi+4]
4149
     jne   frpal4
4150
     jne   frpal4
4150
     cmp   edx,[edi+8]
4151
     cmp   edx,[edi+8]
4151
     jne   frpal4
4152
     jne   frpal4
4152
     jmp   frpal1
4153
     jmp   frpal1
4153
   frpal4:
4154
   frpal4:
4154
     dec   eax
4155
     dec   eax
4155
     jnz   frpal3
4156
     jnz   frpal3
4156
   frpal2:
4157
   frpal2:
4157
;     popad
4158
;     popad
4158
     inc   eax
4159
     inc   eax
4159
     ret
4160
     ret
4160
   frpal1:
4161
   frpal1:
4161
	push	ecx
4162
	push	ecx
4162
	mov   ecx,256
4163
	mov   ecx,256
4163
	sub   ecx,eax
4164
	sub   ecx,eax
4164
	shl   ecx,4
4165
	shl   ecx,4
4165
	mov   esi,edi
4166
	mov   esi,edi
4166
	add   esi,16
4167
	add   esi,16
4167
	cld
4168
	cld
4168
	rep   movsb
4169
	rep   movsb
4169
 
4170
 
4170
	dec   dword [RESERVED_PORTS]
4171
	dec   dword [RESERVED_PORTS]
4171
;popad
4172
;popad
4172
;disable port access at port IO map
4173
;disable port access at port IO map
4173
 
4174
 
4174
;     pushad                        ; start disable io map
4175
;     pushad                        ; start disable io map
4175
     pop	eax	;start port
4176
     pop	eax	;start port
4176
     cmp   edx,65536 ;16384
4177
     cmp   edx,65536 ;16384
4177
     jge   no_mask_io
4178
     jge   no_mask_io
4178
 
4179
 
4179
;     mov   eax,ecx
4180
;     mov   eax,ecx
4180
	xor	ebp,ebp
4181
	xor	ebp,ebp
4181
	inc	ebp
4182
	inc	ebp
4182
new_port_access_disable:
4183
new_port_access_disable:
4183
;     pushad
4184
;     pushad
4184
;     mov   ebp,1                  ; disable - eax = port
4185
;     mov   ebp,1                  ; disable - eax = port
4185
     call  set_io_access_rights
4186
     call  set_io_access_rights
4186
;     popad
4187
;     popad
4187
     inc   eax
4188
     inc   eax
4188
     cmp   eax,edx
4189
     cmp   eax,edx
4189
     jbe   new_port_access_disable
4190
     jbe   new_port_access_disable
4190
no_mask_io:
4191
no_mask_io:
4191
;     popad                         ; end disable io map
4192
;     popad                         ; end disable io map
4192
     xor   eax, eax
4193
     xor   eax, eax
4193
     ret
4194
     ret
4194
 
4195
 
4195
 
4196
 
4196
reserve_free_irq:
4197
reserve_free_irq:
4197
 
4198
 
4198
     xor   esi, esi
4199
     xor   esi, esi
4199
     inc   esi
4200
     inc   esi
4200
     cmp   ecx, 16
4201
     cmp   ecx, 16
4201
     jae   ril1
4202
     jae   ril1
4202
 
4203
 
4203
     push  ecx
4204
     push  ecx
4204
     lea   ecx, [irq_owner + 4 * ecx]
4205
     lea   ecx, [irq_owner + 4 * ecx]
4205
     mov   edx, [ecx]
4206
     mov   edx, [ecx]
4206
     mov   eax, [TASK_BASE]
4207
     mov   eax, [TASK_BASE]
4207
     mov   edi, [eax + TASKDATA.pid]
4208
     mov   edi, [eax + TASKDATA.pid]
4208
     pop   eax
4209
     pop   eax
4209
     dec   ebx
4210
     dec   ebx
4210
     jnz   reserve_irq
4211
     jnz   reserve_irq
4211
 
4212
 
4212
     cmp   edx, edi
4213
     cmp   edx, edi
4213
     jne   ril1
4214
     jne   ril1
4214
     dec   esi
4215
     dec   esi
4215
     mov   [ecx], esi
4216
     mov   [ecx], esi
4216
 
4217
 
4217
     jmp   ril1
4218
     jmp   ril1
4218
 
4219
 
4219
  reserve_irq:
4220
  reserve_irq:
4220
 
4221
 
4221
     cmp   dword [ecx], 0
4222
     cmp   dword [ecx], 0
4222
     jne   ril1
4223
     jne   ril1
4223
 
4224
 
4224
     mov   ebx, [f_irqs + 4 * eax]
4225
     mov   ebx, [f_irqs + 4 * eax]
4225
 
4226
 
4226
     stdcall attach_int_handler, eax, ebx, dword 0
4227
     stdcall attach_int_handler, eax, ebx, dword 0
4227
 
4228
 
4228
     mov   [ecx], edi
4229
     mov   [ecx], edi
4229
 
4230
 
4230
     dec   esi
4231
     dec   esi
4231
   ril1:
4232
   ril1:
4232
     mov   [esp+32], esi ; return in eax
4233
     mov   [esp+32], esi ; return in eax
4233
     ret
4234
     ret
4234
 
4235
 
4235
iglobal
4236
iglobal
4236
f_irqs:
4237
f_irqs:
4237
     dd 0x0
4238
     dd 0x0
4238
     dd 0x0
4239
     dd 0x0
4239
     dd p_irq2
4240
     dd p_irq2
4240
     dd p_irq3
4241
     dd p_irq3
4241
     dd p_irq4
4242
     dd p_irq4
4242
     dd p_irq5
4243
     dd p_irq5
4243
     dd p_irq6
4244
     dd p_irq6
4244
     dd p_irq7
4245
     dd p_irq7
4245
     dd p_irq8
4246
     dd p_irq8
4246
     dd p_irq9
4247
     dd p_irq9
4247
     dd p_irq10
4248
     dd p_irq10
4248
     dd p_irq11
4249
     dd p_irq11
4249
     dd 0x0
4250
     dd 0x0
4250
     dd 0x0
4251
     dd 0x0
4251
     dd p_irq14
4252
     dd p_irq14
4252
     dd p_irq15
4253
     dd p_irq15
4253
 
4254
 
4254
endg
4255
endg
4255
 
4256
 
4256
drawbackground:
4257
drawbackground:
4257
       inc   [mouse_pause]
4258
       inc   [mouse_pause]
4258
       cmp   [SCR_MODE],word 0x12
4259
       cmp   [SCR_MODE],word 0x12
4259
       je   dbrv20
4260
       je   dbrv20
4260
     dbrv12:
4261
     dbrv12:
4261
       cmp  [SCR_MODE],word 0100000000000000b
4262
       cmp  [SCR_MODE],word 0100000000000000b
4262
       jge  dbrv20
4263
       jge  dbrv20
4263
       cmp  [SCR_MODE],word 0x13
4264
       cmp  [SCR_MODE],word 0x13
4264
       je   dbrv20
4265
       je   dbrv20
4265
       call  vesa12_drawbackground
4266
       call  vesa12_drawbackground
4266
       dec   [mouse_pause]
4267
       dec   [mouse_pause]
4267
       call   [draw_pointer]
4268
       call   [draw_pointer]
4268
       ret
4269
       ret
4269
     dbrv20:
4270
     dbrv20:
4270
       cmp   [BgrDrawMode],dword 1
4271
       cmp   [BgrDrawMode],dword 1
4271
       jne   bgrstr
4272
       jne   bgrstr
4272
       call  vesa20_drawbackground_tiled
4273
       call  vesa20_drawbackground_tiled
4273
       dec   [mouse_pause]
4274
       dec   [mouse_pause]
4274
       call   [draw_pointer]
4275
       call   [draw_pointer]
4275
       ret
4276
       ret
4276
     bgrstr:
4277
     bgrstr:
4277
       call  vesa20_drawbackground_stretch
4278
       call  vesa20_drawbackground_stretch
4278
       dec   [mouse_pause]
4279
       dec   [mouse_pause]
4279
       call   [draw_pointer]
4280
       call   [draw_pointer]
4280
       ret
4281
       ret
4281
 
4282
 
4282
align 4
4283
align 4
4283
 
4284
 
4284
syscall_putimage:                       ; PutImage
4285
syscall_putimage:                       ; PutImage
4285
sys_putimage:
4286
sys_putimage:
4286
     test  ecx,0x80008000
4287
     test  ecx,0x80008000
4287
     jnz   .exit
4288
     jnz   .exit
4288
     test  ecx,0x0000FFFF
4289
     test  ecx,0x0000FFFF
4289
     jz    .exit
4290
     jz    .exit
4290
     test  ecx,0xFFFF0000
4291
     test  ecx,0xFFFF0000
4291
     jnz   @f
4292
     jnz   @f
4292
  .exit:
4293
  .exit:
4293
     ret
4294
     ret
4294
 @@:
4295
 @@:
4295
        mov     edi,[current_slot]
4296
        mov     edi,[current_slot]
4296
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4297
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4297
        rol     edx,16
4298
        rol     edx,16
4298
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4299
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4299
        rol     edx,16
4300
        rol     edx,16
4300
  .forced:
4301
  .forced:
4301
        push    ebp esi 0
4302
        push    ebp esi 0
4302
        mov     ebp, putimage_get24bpp
4303
        mov     ebp, putimage_get24bpp
4303
        mov     esi, putimage_init24bpp
4304
        mov     esi, putimage_init24bpp
4304
sys_putimage_bpp:
4305
sys_putimage_bpp:
4305
;        call    [disable_mouse] ; this will be done in xxx_putimage
4306
;        call    [disable_mouse] ; this will be done in xxx_putimage
4306
;        mov     eax, vga_putimage
4307
;        mov     eax, vga_putimage
4307
        cmp     [SCR_MODE], word 0x12
4308
        cmp     [SCR_MODE], word 0x12
4308
        jz      @f   ;.doit
4309
        jz      @f   ;.doit
4309
        mov     eax, vesa12_putimage
4310
        mov     eax, vesa12_putimage
4310
        cmp     [SCR_MODE], word 0100000000000000b
4311
        cmp     [SCR_MODE], word 0100000000000000b
4311
        jae     @f
4312
        jae     @f
4312
        cmp     [SCR_MODE], word 0x13
4313
        cmp     [SCR_MODE], word 0x13
4313
        jnz     .doit
4314
        jnz     .doit
4314
@@:
4315
@@:
4315
        mov     eax, vesa20_putimage
4316
        mov     eax, vesa20_putimage
4316
.doit:
4317
.doit:
4317
        inc     [mouse_pause]
4318
        inc     [mouse_pause]
4318
        call    eax
4319
        call    eax
4319
        dec     [mouse_pause]
4320
        dec     [mouse_pause]
4320
        pop     ebp esi ebp
4321
        pop     ebp esi ebp
4321
        jmp     [draw_pointer]
4322
        jmp     [draw_pointer]
4322
 
4323
 
4323
syscall_putimage_palette:
4324
syscall_putimage_palette:
4324
        mov     edi, esi
4325
        mov     edi, esi
4325
        mov     esi, edx
4326
        mov     esi, edx
4326
        mov     edx, ecx
4327
        mov     edx, ecx
4327
        mov     ecx, ebx
4328
        mov     ecx, ebx
4328
        mov     ebx, eax
4329
        mov     ebx, eax
4329
sys_putimage_palette:
4330
sys_putimage_palette:
4330
; ebx = pointer to image
4331
; ebx = pointer to image
4331
; ecx = [xsize]*65536 + [ysize]
4332
; ecx = [xsize]*65536 + [ysize]
4332
; edx = [xstart]*65536 + [ystart]
4333
; edx = [xstart]*65536 + [ystart]
4333
; esi = number of bits per pixel, must be 8, 24 or 32
4334
; esi = number of bits per pixel, must be 8, 24 or 32
4334
; edi = pointer to palette
4335
; edi = pointer to palette
4335
; ebp = row delta
4336
; ebp = row delta
4336
        mov     eax, [CURRENT_TASK]
4337
        mov     eax, [CURRENT_TASK]
4337
        shl     eax, 8
4338
        shl     eax, 8
4338
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4339
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4339
        rol     edx, 16
4340
        rol     edx, 16
4340
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4341
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4341
        rol     edx, 16
4342
        rol     edx, 16
4342
.forced:
4343
.forced:
4343
        cmp     esi, 1
4344
        cmp     esi, 1
4344
        jnz     @f
4345
        jnz     @f
4345
        push    edi
4346
        push    edi
4346
        mov     eax, [edi+4]
4347
        mov     eax, [edi+4]
4347
        sub     eax, [edi]
4348
        sub     eax, [edi]
4348
        push    eax
4349
        push    eax
4349
        push    dword [edi]
4350
        push    dword [edi]
4350
        push    0ffffff80h
4351
        push    0ffffff80h
4351
        mov     edi, esp
4352
        mov     edi, esp
4352
        call    put_mono_image
4353
        call    put_mono_image
4353
        add     esp, 12
4354
        add     esp, 12
4354
        pop     edi
4355
        pop     edi
4355
        ret
4356
        ret
4356
@@:
4357
@@:
4357
        cmp     esi, 2
4358
        cmp     esi, 2
4358
        jnz     @f
4359
        jnz     @f
4359
        push    edi
4360
        push    edi
4360
        push    0ffffff80h
4361
        push    0ffffff80h
4361
        mov     edi, esp
4362
        mov     edi, esp
4362
        call    put_2bit_image
4363
        call    put_2bit_image
4363
        pop     eax
4364
        pop     eax
4364
        pop     edi
4365
        pop     edi
4365
        ret
4366
        ret
4366
@@:
4367
@@:
4367
        cmp     esi, 4
4368
        cmp     esi, 4
4368
        jnz     @f
4369
        jnz     @f
4369
        push    edi
4370
        push    edi
4370
        push    0ffffff80h
4371
        push    0ffffff80h
4371
        mov     edi, esp
4372
        mov     edi, esp
4372
        call    put_4bit_image
4373
        call    put_4bit_image
4373
        pop     eax
4374
        pop     eax
4374
        pop     edi
4375
        pop     edi
4375
        ret
4376
        ret
4376
@@:
4377
@@:
4377
        push    ebp esi ebp
4378
        push    ebp esi ebp
4378
        cmp     esi, 8
4379
        cmp     esi, 8
4379
        jnz     @f
4380
        jnz     @f
4380
        mov     ebp, putimage_get8bpp
4381
        mov     ebp, putimage_get8bpp
4381
        mov     esi, putimage_init8bpp
4382
        mov     esi, putimage_init8bpp
4382
        jmp     sys_putimage_bpp
4383
        jmp     sys_putimage_bpp
4383
@@:
4384
@@:
4384
        cmp     esi, 15
4385
        cmp     esi, 15
4385
        jnz     @f
4386
        jnz     @f
4386
        mov     ebp, putimage_get15bpp
4387
        mov     ebp, putimage_get15bpp
4387
        mov     esi, putimage_init15bpp
4388
        mov     esi, putimage_init15bpp
4388
        jmp     sys_putimage_bpp
4389
        jmp     sys_putimage_bpp
4389
@@:
4390
@@:
4390
        cmp     esi, 16
4391
        cmp     esi, 16
4391
        jnz     @f
4392
        jnz     @f
4392
        mov     ebp, putimage_get16bpp
4393
        mov     ebp, putimage_get16bpp
4393
        mov     esi, putimage_init16bpp
4394
        mov     esi, putimage_init16bpp
4394
        jmp     sys_putimage_bpp
4395
        jmp     sys_putimage_bpp
4395
@@:
4396
@@:
4396
        cmp     esi, 24
4397
        cmp     esi, 24
4397
        jnz     @f
4398
        jnz     @f
4398
        mov     ebp, putimage_get24bpp
4399
        mov     ebp, putimage_get24bpp
4399
        mov     esi, putimage_init24bpp
4400
        mov     esi, putimage_init24bpp
4400
        jmp     sys_putimage_bpp
4401
        jmp     sys_putimage_bpp
4401
@@:
4402
@@:
4402
        cmp     esi, 32
4403
        cmp     esi, 32
4403
        jnz     @f
4404
        jnz     @f
4404
        mov     ebp, putimage_get32bpp
4405
        mov     ebp, putimage_get32bpp
4405
        mov     esi, putimage_init32bpp
4406
        mov     esi, putimage_init32bpp
4406
        jmp     sys_putimage_bpp
4407
        jmp     sys_putimage_bpp
4407
@@:
4408
@@:
4408
        pop     ebp esi ebp
4409
        pop     ebp esi ebp
4409
        ret
4410
        ret
4410
 
4411
 
4411
put_mono_image:
4412
put_mono_image:
4412
        push    ebp esi ebp
4413
        push    ebp esi ebp
4413
        mov     ebp, putimage_get1bpp
4414
        mov     ebp, putimage_get1bpp
4414
        mov     esi, putimage_init1bpp
4415
        mov     esi, putimage_init1bpp
4415
        jmp     sys_putimage_bpp
4416
        jmp     sys_putimage_bpp
4416
put_2bit_image:
4417
put_2bit_image:
4417
        push    ebp esi ebp
4418
        push    ebp esi ebp
4418
        mov     ebp, putimage_get2bpp
4419
        mov     ebp, putimage_get2bpp
4419
        mov     esi, putimage_init2bpp
4420
        mov     esi, putimage_init2bpp
4420
        jmp     sys_putimage_bpp
4421
        jmp     sys_putimage_bpp
4421
put_4bit_image:
4422
put_4bit_image:
4422
        push    ebp esi ebp
4423
        push    ebp esi ebp
4423
        mov     ebp, putimage_get4bpp
4424
        mov     ebp, putimage_get4bpp
4424
        mov     esi, putimage_init4bpp
4425
        mov     esi, putimage_init4bpp
4425
        jmp     sys_putimage_bpp
4426
        jmp     sys_putimage_bpp
4426
 
4427
 
4427
putimage_init24bpp:
4428
putimage_init24bpp:
4428
        lea     eax, [eax*3]
4429
        lea     eax, [eax*3]
4429
putimage_init8bpp:
4430
putimage_init8bpp:
4430
        ret
4431
        ret
4431
 
4432
 
4432
align 16
4433
align 16
4433
putimage_get24bpp:
4434
putimage_get24bpp:
4434
        movzx   eax, byte [esi+2]
4435
        movzx   eax, byte [esi+2]
4435
        shl     eax, 16
4436
        shl     eax, 16
4436
        mov     ax, [esi]
4437
        mov     ax, [esi]
4437
        add     esi, 3
4438
        add     esi, 3
4438
        ret     4
4439
        ret     4
4439
align 16
4440
align 16
4440
putimage_get8bpp:
4441
putimage_get8bpp:
4441
        movzx   eax, byte [esi]
4442
        movzx   eax, byte [esi]
4442
        push    edx
4443
        push    edx
4443
        mov     edx, [esp+8]
4444
        mov     edx, [esp+8]
4444
        mov     eax, [edx+eax*4]
4445
        mov     eax, [edx+eax*4]
4445
        pop     edx
4446
        pop     edx
4446
        inc     esi
4447
        inc     esi
4447
        ret     4
4448
        ret     4
4448
 
4449
 
4449
putimage_init1bpp:
4450
putimage_init1bpp:
4450
        add     eax, ecx
4451
        add     eax, ecx
4451
        push    ecx
4452
        push    ecx
4452
        add     eax, 7
4453
        add     eax, 7
4453
        add     ecx, 7
4454
        add     ecx, 7
4454
        shr     eax, 3
4455
        shr     eax, 3
4455
        shr     ecx, 3
4456
        shr     ecx, 3
4456
        sub     eax, ecx
4457
        sub     eax, ecx
4457
        pop     ecx
4458
        pop     ecx
4458
        ret
4459
        ret
4459
align 16
4460
align 16
4460
putimage_get1bpp:
4461
putimage_get1bpp:
4461
        push    edx
4462
        push    edx
4462
        mov     edx, [esp+8]
4463
        mov     edx, [esp+8]
4463
        mov     al, [edx]
4464
        mov     al, [edx]
4464
        add     al, al
4465
        add     al, al
4465
        jnz     @f
4466
        jnz     @f
4466
        lodsb
4467
        lodsb
4467
        adc     al, al
4468
        adc     al, al
4468
@@:
4469
@@:
4469
        mov     [edx], al
4470
        mov     [edx], al
4470
        sbb     eax, eax
4471
        sbb     eax, eax
4471
        and     eax, [edx+8]
4472
        and     eax, [edx+8]
4472
        add     eax, [edx+4]
4473
        add     eax, [edx+4]
4473
        pop     edx
4474
        pop     edx
4474
        ret     4
4475
        ret     4
4475
 
4476
 
4476
putimage_init2bpp:
4477
putimage_init2bpp:
4477
        add     eax, ecx
4478
        add     eax, ecx
4478
        push    ecx
4479
        push    ecx
4479
        add     ecx, 3
4480
        add     ecx, 3
4480
        add     eax, 3
4481
        add     eax, 3
4481
        shr     ecx, 2
4482
        shr     ecx, 2
4482
        shr     eax, 2
4483
        shr     eax, 2
4483
        sub     eax, ecx
4484
        sub     eax, ecx
4484
        pop     ecx
4485
        pop     ecx
4485
        ret
4486
        ret
4486
align 16
4487
align 16
4487
putimage_get2bpp:
4488
putimage_get2bpp:
4488
        push    edx
4489
        push    edx
4489
        mov     edx, [esp+8]
4490
        mov     edx, [esp+8]
4490
        mov     al, [edx]
4491
        mov     al, [edx]
4491
        mov     ah, al
4492
        mov     ah, al
4492
        shr     al, 6
4493
        shr     al, 6
4493
        shl     ah, 2
4494
        shl     ah, 2
4494
        jnz     .nonewbyte
4495
        jnz     .nonewbyte
4495
        lodsb
4496
        lodsb
4496
        mov     ah, al
4497
        mov     ah, al
4497
        shr     al, 6
4498
        shr     al, 6
4498
        shl     ah, 2
4499
        shl     ah, 2
4499
        add     ah, 1
4500
        add     ah, 1
4500
.nonewbyte:
4501
.nonewbyte:
4501
        mov     [edx], ah
4502
        mov     [edx], ah
4502
        mov     edx, [edx+4]
4503
        mov     edx, [edx+4]
4503
        movzx   eax, al
4504
        movzx   eax, al
4504
        mov     eax, [edx+eax*4]
4505
        mov     eax, [edx+eax*4]
4505
        pop     edx
4506
        pop     edx
4506
        ret     4
4507
        ret     4
4507
 
4508
 
4508
putimage_init4bpp:
4509
putimage_init4bpp:
4509
        add     eax, ecx
4510
        add     eax, ecx
4510
        push    ecx
4511
        push    ecx
4511
        add     ecx, 1
4512
        add     ecx, 1
4512
        add     eax, 1
4513
        add     eax, 1
4513
        shr     ecx, 1
4514
        shr     ecx, 1
4514
        shr     eax, 1
4515
        shr     eax, 1
4515
        sub     eax, ecx
4516
        sub     eax, ecx
4516
        pop     ecx
4517
        pop     ecx
4517
        ret
4518
        ret
4518
align 16
4519
align 16
4519
putimage_get4bpp:
4520
putimage_get4bpp:
4520
        push    edx
4521
        push    edx
4521
        mov     edx, [esp+8]
4522
        mov     edx, [esp+8]
4522
        add     byte [edx], 80h
4523
        add     byte [edx], 80h
4523
        jc      @f
4524
        jc      @f
4524
        movzx   eax, byte [edx+1]
4525
        movzx   eax, byte [edx+1]
4525
        mov     edx, [edx+4]
4526
        mov     edx, [edx+4]
4526
        and     eax, 0x0F
4527
        and     eax, 0x0F
4527
        mov     eax, [edx+eax*4]
4528
        mov     eax, [edx+eax*4]
4528
        pop     edx
4529
        pop     edx
4529
        ret     4
4530
        ret     4
4530
@@:
4531
@@:
4531
        movzx   eax, byte [esi]
4532
        movzx   eax, byte [esi]
4532
        add     esi, 1
4533
        add     esi, 1
4533
        mov     [edx+1], al
4534
        mov     [edx+1], al
4534
        shr     eax, 4
4535
        shr     eax, 4
4535
        mov     edx, [edx+4]
4536
        mov     edx, [edx+4]
4536
        mov     eax, [edx+eax*4]
4537
        mov     eax, [edx+eax*4]
4537
        pop     edx
4538
        pop     edx
4538
        ret     4
4539
        ret     4
4539
 
4540
 
4540
putimage_init32bpp:
4541
putimage_init32bpp:
4541
        shl     eax, 2
4542
        shl     eax, 2
4542
        ret
4543
        ret
4543
align 16
4544
align 16
4544
putimage_get32bpp:
4545
putimage_get32bpp:
4545
        lodsd
4546
        lodsd
4546
        ret     4
4547
        ret     4
4547
 
4548
 
4548
putimage_init15bpp:
4549
putimage_init15bpp:
4549
putimage_init16bpp:
4550
putimage_init16bpp:
4550
        add     eax, eax
4551
        add     eax, eax
4551
        ret
4552
        ret
4552
align 16
4553
align 16
4553
putimage_get15bpp:
4554
putimage_get15bpp:
4554
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4555
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4555
        push    ecx edx
4556
        push    ecx edx
4556
        movzx   eax, word [esi]
4557
        movzx   eax, word [esi]
4557
        add     esi, 2
4558
        add     esi, 2
4558
        mov     ecx, eax
4559
        mov     ecx, eax
4559
        mov     edx, eax
4560
        mov     edx, eax
4560
        and     eax, 0x1F
4561
        and     eax, 0x1F
4561
        and     ecx, 0x1F shl 5
4562
        and     ecx, 0x1F shl 5
4562
        and     edx, 0x1F shl 10
4563
        and     edx, 0x1F shl 10
4563
        shl     eax, 3
4564
        shl     eax, 3
4564
        shl     ecx, 6
4565
        shl     ecx, 6
4565
        shl     edx, 9
4566
        shl     edx, 9
4566
        or      eax, ecx
4567
        or      eax, ecx
4567
        or      eax, edx
4568
        or      eax, edx
4568
        pop     edx ecx
4569
        pop     edx ecx
4569
        ret     4
4570
        ret     4
4570
 
4571
 
4571
align 16
4572
align 16
4572
putimage_get16bpp:
4573
putimage_get16bpp:
4573
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
4574
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
4574
        push    ecx edx
4575
        push    ecx edx
4575
        movzx   eax, word [esi]
4576
        movzx   eax, word [esi]
4576
        add     esi, 2
4577
        add     esi, 2
4577
        mov     ecx, eax
4578
        mov     ecx, eax
4578
        mov     edx, eax
4579
        mov     edx, eax
4579
        and     eax, 0x1F
4580
        and     eax, 0x1F
4580
        and     ecx, 0x3F shl 5
4581
        and     ecx, 0x3F shl 5
4581
        and     edx, 0x1F shl 11
4582
        and     edx, 0x1F shl 11
4582
        shl     eax, 3
4583
        shl     eax, 3
4583
        shl     ecx, 5
4584
        shl     ecx, 5
4584
        shl     edx, 8
4585
        shl     edx, 8
4585
        or      eax, ecx
4586
        or      eax, ecx
4586
        or      eax, edx
4587
        or      eax, edx
4587
        pop     edx ecx
4588
        pop     edx ecx
4588
        ret     4
4589
        ret     4
4589
 
4590
 
4590
; eax x beginning
4591
; eax x beginning
4591
; ebx y beginning
4592
; ebx y beginning
4592
; ecx x end
4593
; ecx x end
4593
        ; edx y end
4594
        ; edx y end
4594
; edi color
4595
; edi color
4595
 
4596
 
4596
__sys_drawbar:
4597
__sys_drawbar:
4597
        mov     esi,[current_slot]
4598
        mov     esi,[current_slot]
4598
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4599
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4599
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4600
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4600
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4601
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4601
        add     edx,[esi+APPDATA.wnd_clientbox.top]
4602
        add     edx,[esi+APPDATA.wnd_clientbox.top]
4602
  .forced:
4603
  .forced:
4603
    inc   [mouse_pause]
4604
    inc   [mouse_pause]
4604
;        call    [disable_mouse]
4605
;        call    [disable_mouse]
4605
    cmp   [SCR_MODE],word 0x12
4606
    cmp   [SCR_MODE],word 0x12
4606
    je   dbv20
4607
    je   dbv20
4607
   sdbv20:
4608
   sdbv20:
4608
    cmp  [SCR_MODE],word 0100000000000000b
4609
    cmp  [SCR_MODE],word 0100000000000000b
4609
    jge  dbv20
4610
    jge  dbv20
4610
    cmp  [SCR_MODE],word 0x13
4611
    cmp  [SCR_MODE],word 0x13
4611
    je   dbv20
4612
    je   dbv20
4612
    call vesa12_drawbar
4613
    call vesa12_drawbar
4613
    dec   [mouse_pause]
4614
    dec   [mouse_pause]
4614
    call   [draw_pointer]
4615
    call   [draw_pointer]
4615
    ret
4616
    ret
4616
  dbv20:
4617
  dbv20:
4617
    call vesa20_drawbar
4618
    call vesa20_drawbar
4618
    dec   [mouse_pause]
4619
    dec   [mouse_pause]
4619
    call   [draw_pointer]
4620
    call   [draw_pointer]
4620
    ret
4621
    ret
4621
 
4622
 
4622
 
4623
 
4623
 
4624
 
4624
kb_read:
4625
kb_read:
4625
 
4626
 
4626
        push    ecx edx
4627
        push    ecx edx
4627
 
4628
 
4628
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4629
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4629
      kr_loop:
4630
      kr_loop:
4630
        in      al,0x64
4631
        in      al,0x64
4631
        test    al,1
4632
        test    al,1
4632
        jnz     kr_ready
4633
        jnz     kr_ready
4633
        loop    kr_loop
4634
        loop    kr_loop
4634
        mov     ah,1
4635
        mov     ah,1
4635
        jmp     kr_exit
4636
        jmp     kr_exit
4636
      kr_ready:
4637
      kr_ready:
4637
        push    ecx
4638
        push    ecx
4638
        mov     ecx,32
4639
        mov     ecx,32
4639
      kr_delay:
4640
      kr_delay:
4640
        loop    kr_delay
4641
        loop    kr_delay
4641
        pop     ecx
4642
        pop     ecx
4642
        in      al,0x60
4643
        in      al,0x60
4643
        xor     ah,ah
4644
        xor     ah,ah
4644
      kr_exit:
4645
      kr_exit:
4645
 
4646
 
4646
        pop     edx ecx
4647
        pop     edx ecx
4647
 
4648
 
4648
        ret
4649
        ret
4649
 
4650
 
4650
 
4651
 
4651
kb_write:
4652
kb_write:
4652
 
4653
 
4653
        push    ecx edx
4654
        push    ecx edx
4654
 
4655
 
4655
        mov     dl,al
4656
        mov     dl,al
4656
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4657
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4657
;      kw_loop1:
4658
;      kw_loop1:
4658
;        in      al,0x64
4659
;        in      al,0x64
4659
;        test    al,0x20
4660
;        test    al,0x20
4660
;        jz      kw_ok1
4661
;        jz      kw_ok1
4661
;        loop    kw_loop1
4662
;        loop    kw_loop1
4662
;        mov     ah,1
4663
;        mov     ah,1
4663
;        jmp     kw_exit
4664
;        jmp     kw_exit
4664
;      kw_ok1:
4665
;      kw_ok1:
4665
        in      al,0x60
4666
        in      al,0x60
4666
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4667
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4667
      kw_loop:
4668
      kw_loop:
4668
        in      al,0x64
4669
        in      al,0x64
4669
        test    al,2
4670
        test    al,2
4670
        jz      kw_ok
4671
        jz      kw_ok
4671
        loop    kw_loop
4672
        loop    kw_loop
4672
        mov     ah,1
4673
        mov     ah,1
4673
        jmp     kw_exit
4674
        jmp     kw_exit
4674
      kw_ok:
4675
      kw_ok:
4675
        mov     al,dl
4676
        mov     al,dl
4676
        out     0x60,al
4677
        out     0x60,al
4677
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4678
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4678
      kw_loop3:
4679
      kw_loop3:
4679
        in      al,0x64
4680
        in      al,0x64
4680
        test    al,2
4681
        test    al,2
4681
        jz      kw_ok3
4682
        jz      kw_ok3
4682
        loop    kw_loop3
4683
        loop    kw_loop3
4683
        mov     ah,1
4684
        mov     ah,1
4684
        jmp     kw_exit
4685
        jmp     kw_exit
4685
      kw_ok3:
4686
      kw_ok3:
4686
        mov     ah,8
4687
        mov     ah,8
4687
      kw_loop4:
4688
      kw_loop4:
4688
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4689
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4689
      kw_loop5:
4690
      kw_loop5:
4690
        in      al,0x64
4691
        in      al,0x64
4691
        test    al,1
4692
        test    al,1
4692
        jnz     kw_ok4
4693
        jnz     kw_ok4
4693
        loop    kw_loop5
4694
        loop    kw_loop5
4694
        dec     ah
4695
        dec     ah
4695
        jnz     kw_loop4
4696
        jnz     kw_loop4
4696
      kw_ok4:
4697
      kw_ok4:
4697
        xor     ah,ah
4698
        xor     ah,ah
4698
      kw_exit:
4699
      kw_exit:
4699
 
4700
 
4700
        pop     edx ecx
4701
        pop     edx ecx
4701
 
4702
 
4702
        ret
4703
        ret
4703
 
4704
 
4704
 
4705
 
4705
kb_cmd:
4706
kb_cmd:
4706
 
4707
 
4707
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4708
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4708
      c_wait:
4709
      c_wait:
4709
        in      al,0x64
4710
        in      al,0x64
4710
        test    al,2
4711
        test    al,2
4711
        jz      c_send
4712
        jz      c_send
4712
        loop    c_wait
4713
        loop    c_wait
4713
        jmp     c_error
4714
        jmp     c_error
4714
      c_send:
4715
      c_send:
4715
        mov     al,bl
4716
        mov     al,bl
4716
        out     0x64,al
4717
        out     0x64,al
4717
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4718
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4718
      c_accept:
4719
      c_accept:
4719
        in      al,0x64
4720
        in      al,0x64
4720
        test    al,2
4721
        test    al,2
4721
        jz      c_ok
4722
        jz      c_ok
4722
        loop    c_accept
4723
        loop    c_accept
4723
      c_error:
4724
      c_error:
4724
        mov     ah,1
4725
        mov     ah,1
4725
        jmp     c_exit
4726
        jmp     c_exit
4726
      c_ok:
4727
      c_ok:
4727
        xor     ah,ah
4728
        xor     ah,ah
4728
      c_exit:
4729
      c_exit:
4729
        ret
4730
        ret
4730
 
4731
 
4731
 
4732
 
4732
setmouse:  ; set mousepicture -pointer
4733
setmouse:  ; set mousepicture -pointer
4733
           ; ps2 mouse enable
4734
           ; ps2 mouse enable
4734
 
4735
 
4735
     mov     [MOUSE_PICTURE],dword mousepointer
4736
     mov     [MOUSE_PICTURE],dword mousepointer
4736
 
4737
 
4737
     cli
4738
     cli
4738
 
4739
 
4739
     ret
4740
     ret
4740
 
4741
 
4741
if used _rdtsc
4742
if used _rdtsc
4742
_rdtsc:
4743
_rdtsc:
4743
     bt [cpu_caps], CAPS_TSC
4744
     bt [cpu_caps], CAPS_TSC
4744
     jnc ret_rdtsc
4745
     jnc ret_rdtsc
4745
     rdtsc
4746
     rdtsc
4746
     ret
4747
     ret
4747
   ret_rdtsc:
4748
   ret_rdtsc:
4748
     mov   edx,0xffffffff
4749
     mov   edx,0xffffffff
4749
     mov   eax,0xffffffff
4750
     mov   eax,0xffffffff
4750
     ret
4751
     ret
4751
end if
4752
end if
4752
 
4753
 
4753
rerouteirqs:
4754
rerouteirqs:
4754
 
4755
 
4755
        cli
4756
        cli
4756
 
4757
 
4757
        mov     al,0x11         ;  icw4, edge triggered
4758
        mov     al,0x11         ;  icw4, edge triggered
4758
        out     0x20,al
4759
        out     0x20,al
4759
        call    pic_delay
4760
        call    pic_delay
4760
        out     0xA0,al
4761
        out     0xA0,al
4761
        call    pic_delay
4762
        call    pic_delay
4762
 
4763
 
4763
        mov     al,0x20         ;  generate 0x20 +
4764
        mov     al,0x20         ;  generate 0x20 +
4764
        out     0x21,al
4765
        out     0x21,al
4765
        call    pic_delay
4766
        call    pic_delay
4766
        mov     al,0x28         ;  generate 0x28 +
4767
        mov     al,0x28         ;  generate 0x28 +
4767
        out     0xA1,al
4768
        out     0xA1,al
4768
        call    pic_delay
4769
        call    pic_delay
4769
 
4770
 
4770
        mov     al,0x04         ;  slave at irq2
4771
        mov     al,0x04         ;  slave at irq2
4771
        out     0x21,al
4772
        out     0x21,al
4772
        call    pic_delay
4773
        call    pic_delay
4773
        mov     al,0x02         ;  at irq9
4774
        mov     al,0x02         ;  at irq9
4774
        out     0xA1,al
4775
        out     0xA1,al
4775
        call    pic_delay
4776
        call    pic_delay
4776
 
4777
 
4777
        mov     al,0x01         ;  8086 mode
4778
        mov     al,0x01         ;  8086 mode
4778
        out     0x21,al
4779
        out     0x21,al
4779
        call    pic_delay
4780
        call    pic_delay
4780
        out     0xA1,al
4781
        out     0xA1,al
4781
        call    pic_delay
4782
        call    pic_delay
4782
 
4783
 
4783
        mov     al,255          ; mask all irq's
4784
        mov     al,255          ; mask all irq's
4784
        out     0xA1,al
4785
        out     0xA1,al
4785
        call    pic_delay
4786
        call    pic_delay
4786
        out     0x21,al
4787
        out     0x21,al
4787
        call    pic_delay
4788
        call    pic_delay
4788
 
4789
 
4789
        mov     ecx,0x1000
4790
        mov     ecx,0x1000
4790
        cld
4791
        cld
4791
picl1:  call    pic_delay
4792
picl1:  call    pic_delay
4792
        loop    picl1
4793
        loop    picl1
4793
 
4794
 
4794
        mov     al,255          ; mask all irq's
4795
        mov     al,255          ; mask all irq's
4795
        out     0xA1,al
4796
        out     0xA1,al
4796
        call    pic_delay
4797
        call    pic_delay
4797
        out     0x21,al
4798
        out     0x21,al
4798
        call    pic_delay
4799
        call    pic_delay
4799
 
4800
 
4800
        cli
4801
        cli
4801
 
4802
 
4802
        ret
4803
        ret
4803
 
4804
 
4804
 
4805
 
4805
pic_delay:
4806
pic_delay:
4806
 
4807
 
4807
        jmp     pdl1
4808
        jmp     pdl1
4808
pdl1:   ret
4809
pdl1:   ret
4809
 
4810
 
4810
 
4811
 
4811
sys_msg_board_str:
4812
sys_msg_board_str:
4812
 
4813
 
4813
     pushad
4814
     pushad
4814
   @@:
4815
   @@:
4815
     cmp    [esi],byte 0
4816
     cmp    [esi],byte 0
4816
     je     @f
4817
     je     @f
4817
     mov    eax,1
4818
     mov    eax,1
4818
     movzx  ebx,byte [esi]
4819
     movzx  ebx,byte [esi]
4819
     call   sys_msg_board
4820
     call   sys_msg_board
4820
     inc    esi
4821
     inc    esi
4821
     jmp    @b
4822
     jmp    @b
4822
   @@:
4823
   @@:
4823
     popad
4824
     popad
4824
     ret
4825
     ret
4825
 
4826
 
4826
sys_msg_board_byte:
4827
sys_msg_board_byte:
4827
; in: al = byte to display
4828
; in: al = byte to display
4828
; out: nothing
4829
; out: nothing
4829
; destroys: nothing
4830
; destroys: nothing
4830
        pushad
4831
        pushad
4831
        mov     ecx, 2
4832
        mov     ecx, 2
4832
        shl     eax, 24
4833
        shl     eax, 24
4833
        jmp     @f
4834
        jmp     @f
4834
 
4835
 
4835
sys_msg_board_word:
4836
sys_msg_board_word:
4836
; in: ax = word to display
4837
; in: ax = word to display
4837
; out: nothing
4838
; out: nothing
4838
; destroys: nothing
4839
; destroys: nothing
4839
        pushad
4840
        pushad
4840
        mov     ecx, 4
4841
        mov     ecx, 4
4841
        shl     eax, 16
4842
        shl     eax, 16
4842
        jmp     @f
4843
        jmp     @f
4843
 
4844
 
4844
sys_msg_board_dword:
4845
sys_msg_board_dword:
4845
; in: eax = dword to display
4846
; in: eax = dword to display
4846
; out: nothing
4847
; out: nothing
4847
; destroys: nothing
4848
; destroys: nothing
4848
        pushad
4849
        pushad
4849
        mov     ecx, 8
4850
        mov     ecx, 8
4850
@@:
4851
@@:
4851
        push    ecx
4852
        push    ecx
4852
        rol     eax, 4
4853
        rol     eax, 4
4853
        push    eax
4854
        push    eax
4854
        and     al, 0xF
4855
        and     al, 0xF
4855
        cmp     al, 10
4856
        cmp     al, 10
4856
        sbb     al, 69h
4857
        sbb     al, 69h
4857
        das
4858
        das
4858
        mov     bl, al
4859
        mov     bl, al
4859
        xor     eax, eax
4860
        xor     eax, eax
4860
        inc     eax
4861
        inc     eax
4861
        call    sys_msg_board
4862
        call    sys_msg_board
4862
        pop     eax
4863
        pop     eax
4863
        pop     ecx
4864
        pop     ecx
4864
        loop    @b
4865
        loop    @b
4865
        popad
4866
        popad
4866
        ret
4867
        ret
4867
 
4868
 
4868
uglobal
4869
uglobal
4869
  msg_board_data: times 4096 db 0
4870
  msg_board_data: times 4096 db 0
4870
  msg_board_count dd 0x0
4871
  msg_board_count dd 0x0
4871
endg
4872
endg
4872
 
4873
 
4873
sys_msg_board:
4874
sys_msg_board:
4874
 
4875
 
4875
; eax=1 : write :  bl byte to write
4876
; eax=1 : write :  bl byte to write
4876
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4877
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4877
 
4878
 
4878
        mov     ecx, [msg_board_count]
4879
        mov     ecx, [msg_board_count]
4879
        cmp     eax, 1
4880
        cmp     eax, 1
4880
        jne     .smbl1
4881
        jne     .smbl1
4881
 
4882
 
4882
if defined debug_com_base
4883
if defined debug_com_base
4883
 
4884
 
4884
        push    dx ax
4885
        push    dx ax
4885
 
4886
 
4886
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4887
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4887
        mov     dx, debug_com_base+5
4888
        mov     dx, debug_com_base+5
4888
        in      al, dx
4889
        in      al, dx
4889
        test    al, 1 shl 5
4890
        test    al, 1 shl 5
4890
        jz      @r
4891
        jz      @r
4891
 
4892
 
4892
        mov     dx, debug_com_base      ; Output the byte
4893
        mov     dx, debug_com_base      ; Output the byte
4893
        mov     al, bl
4894
        mov     al, bl
4894
        out     dx, al
4895
        out     dx, al
4895
 
4896
 
4896
        pop     ax dx
4897
        pop     ax dx
4897
 
4898
 
4898
end if
4899
end if
4899
 
4900
 
4900
        mov     [msg_board_data+ecx],bl
4901
        mov     [msg_board_data+ecx],bl
4901
        inc     ecx
4902
        inc     ecx
4902
        and     ecx, 4095
4903
        and     ecx, 4095
4903
        mov     [msg_board_count], ecx
4904
        mov     [msg_board_count], ecx
4904
        mov     [check_idle_semaphore], 5
4905
        mov     [check_idle_semaphore], 5
4905
        ret
4906
        ret
4906
.smbl1:
4907
.smbl1:
4907
        cmp     eax, 2
4908
        cmp     eax, 2
4908
        jne     .smbl2
4909
        jne     .smbl2
4909
        test    ecx, ecx
4910
        test    ecx, ecx
4910
        jz      .smbl21
4911
        jz      .smbl21
4911
        mov     eax, msg_board_data+1
4912
        mov     eax, msg_board_data+1
4912
        mov     ebx, msg_board_data
4913
        mov     ebx, msg_board_data
4913
        movzx   edx, byte [ebx]
4914
        movzx   edx, byte [ebx]
4914
        call    memmove
4915
        call    memmove
4915
        dec     [msg_board_count]
4916
        dec     [msg_board_count]
4916
        mov     [esp + 36], edx ;eax
4917
        mov     [esp + 36], edx ;eax
4917
        mov     [esp + 24], dword 1
4918
        mov     [esp + 24], dword 1
4918
        ret
4919
        ret
4919
.smbl21:
4920
.smbl21:
4920
        mov     [esp+36], ecx
4921
        mov     [esp+36], ecx
4921
        mov     [esp+24], ecx
4922
        mov     [esp+24], ecx
4922
.smbl2:
4923
.smbl2:
4923
        ret
4924
        ret
4924
 
4925
 
4925
 
4926
 
4926
 
4927
 
4927
sys_process_def:
4928
sys_process_def:
4928
        mov     edi, [CURRENT_TASK]
4929
        mov     edi, [CURRENT_TASK]
4929
 
4930
 
4930
        dec     eax             ; 1 = set keyboard mode
4931
        dec     eax             ; 1 = set keyboard mode
4931
     jne   no_set_keyboard_setup
4932
     jne   no_set_keyboard_setup
4932
 
4933
 
4933
     shl   edi,8
4934
     shl   edi,8
4934
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4935
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4935
 
4936
 
4936
     ret
4937
     ret
4937
 
4938
 
4938
   no_set_keyboard_setup:
4939
   no_set_keyboard_setup:
4939
 
4940
 
4940
        dec     eax             ; 2 = get keyboard mode
4941
        dec     eax             ; 2 = get keyboard mode
4941
     jne   no_get_keyboard_setup
4942
     jne   no_get_keyboard_setup
4942
 
4943
 
4943
     shl   edi,8
4944
     shl   edi,8
4944
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4945
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4945
 
4946
 
4946
     mov   [esp+36],eax
4947
     mov   [esp+36],eax
4947
 
4948
 
4948
     ret
4949
     ret
4949
 
4950
 
4950
   no_get_keyboard_setup:
4951
   no_get_keyboard_setup:
4951
 
4952
 
4952
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4953
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4953
     jne   no_get_keyboard_cas
4954
     jne   no_get_keyboard_cas
4954
 
4955
 
4955
;     xor   eax,eax
4956
;     xor   eax,eax
4956
;     movzx eax,byte [shift]
4957
;     movzx eax,byte [shift]
4957
;     movzx ebx,byte [ctrl]
4958
;     movzx ebx,byte [ctrl]
4958
;     shl   ebx,2
4959
;     shl   ebx,2
4959
;     add   eax,ebx
4960
;     add   eax,ebx
4960
;     movzx ebx,byte [alt]
4961
;     movzx ebx,byte [alt]
4961
;     shl   ebx,3
4962
;     shl   ebx,3
4962
;     add   eax,ebx
4963
;     add   eax,ebx
4963
 
4964
 
4964
 ;// mike.dld [
4965
 ;// mike.dld [
4965
     mov   eax, [kb_state]
4966
     mov   eax, [kb_state]
4966
 ;// mike.dld ]
4967
 ;// mike.dld ]
4967
 
4968
 
4968
     mov   [esp+36],eax
4969
     mov   [esp+36],eax
4969
 
4970
 
4970
     ret
4971
     ret
4971
 
4972
 
4972
   no_get_keyboard_cas:
4973
   no_get_keyboard_cas:
4973
 
4974
 
4974
        dec     eax
4975
        dec     eax
4975
        jnz     no_add_keyboard_hotkey
4976
        jnz     no_add_keyboard_hotkey
4976
 
4977
 
4977
        mov     eax, hotkey_list
4978
        mov     eax, hotkey_list
4978
@@:
4979
@@:
4979
        cmp     dword [eax+8], 0
4980
        cmp     dword [eax+8], 0
4980
        jz      .found_free
4981
        jz      .found_free
4981
        add     eax, 16
4982
        add     eax, 16
4982
        cmp     eax, hotkey_list+16*256
4983
        cmp     eax, hotkey_list+16*256
4983
        jb      @b
4984
        jb      @b
4984
        mov     dword [esp+36], 1
4985
        mov     dword [esp+36], 1
4985
        ret
4986
        ret
4986
.found_free:
4987
.found_free:
4987
        mov     [eax+8], edi
4988
        mov     [eax+8], edi
4988
        mov     [eax+4], ecx
4989
        mov     [eax+4], ecx
4989
        movzx   ebx, bl
4990
        movzx   ebx, bl
4990
        lea     ebx, [hotkey_scancodes+ebx*4]
4991
        lea     ebx, [hotkey_scancodes+ebx*4]
4991
        mov     ecx, [ebx]
4992
        mov     ecx, [ebx]
4992
        mov     [eax], ecx
4993
        mov     [eax], ecx
4993
        mov     [ebx], eax
4994
        mov     [ebx], eax
4994
        mov     [eax+12], ebx
4995
        mov     [eax+12], ebx
4995
        jecxz   @f
4996
        jecxz   @f
4996
        mov     [ecx+12], eax
4997
        mov     [ecx+12], eax
4997
@@:
4998
@@:
4998
        and     dword [esp+36], 0
4999
        and     dword [esp+36], 0
4999
        ret
5000
        ret
5000
 
5001
 
5001
no_add_keyboard_hotkey:
5002
no_add_keyboard_hotkey:
5002
 
5003
 
5003
        dec     eax
5004
        dec     eax
5004
        jnz     no_del_keyboard_hotkey
5005
        jnz     no_del_keyboard_hotkey
5005
 
5006
 
5006
        movzx   ebx, bl
5007
        movzx   ebx, bl
5007
        lea     ebx, [hotkey_scancodes+ebx*4]
5008
        lea     ebx, [hotkey_scancodes+ebx*4]
5008
        mov     eax, [ebx]
5009
        mov     eax, [ebx]
5009
.scan:
5010
.scan:
5010
        test    eax, eax
5011
        test    eax, eax
5011
        jz      .notfound
5012
        jz      .notfound
5012
        cmp     [eax+8], edi
5013
        cmp     [eax+8], edi
5013
        jnz     .next
5014
        jnz     .next
5014
        cmp     [eax+4], ecx
5015
        cmp     [eax+4], ecx
5015
        jz      .found
5016
        jz      .found
5016
.next:
5017
.next:
5017
        mov     eax, [eax]
5018
        mov     eax, [eax]
5018
        jmp     .scan
5019
        jmp     .scan
5019
.notfound:
5020
.notfound:
5020
        mov     dword [esp+36], 1
5021
        mov     dword [esp+36], 1
5021
        ret
5022
        ret
5022
.found:
5023
.found:
5023
        mov     ecx, [eax]
5024
        mov     ecx, [eax]
5024
        jecxz   @f
5025
        jecxz   @f
5025
        mov     edx, [eax+12]
5026
        mov     edx, [eax+12]
5026
        mov     [ecx+12], edx
5027
        mov     [ecx+12], edx
5027
@@:
5028
@@:
5028
        mov     ecx, [eax+12]
5029
        mov     ecx, [eax+12]
5029
        mov     edx, [eax]
5030
        mov     edx, [eax]
5030
        mov     [ecx], edx
5031
        mov     [ecx], edx
5031
        xor     edx, edx
5032
        xor     edx, edx
5032
        mov     [eax+4], edx
5033
        mov     [eax+4], edx
5033
        mov     [eax+8], edx
5034
        mov     [eax+8], edx
5034
        mov     [eax+12], edx
5035
        mov     [eax+12], edx
5035
        mov     [eax], edx
5036
        mov     [eax], edx
5036
        mov     [esp+36], edx
5037
        mov     [esp+36], edx
5037
        ret
5038
        ret
5038
 
5039
 
5039
no_del_keyboard_hotkey:
5040
no_del_keyboard_hotkey:
5040
     ret
5041
     ret
5041
 
5042
 
5042
 
5043
 
5043
align 4
5044
align 4
5044
 
5045
 
5045
sys_gs:                         ; direct screen access
5046
sys_gs:                         ; direct screen access
5046
 
5047
 
5047
     cmp  eax,1                 ; resolution
5048
     cmp  eax,1                 ; resolution
5048
     jne  no_gs1
5049
     jne  no_gs1
5049
     mov  eax,[Screen_Max_X]
5050
     mov  eax,[Screen_Max_X]
5050
     shl  eax,16
5051
     shl  eax,16
5051
     mov  ax,[Screen_Max_Y]
5052
     mov  ax,[Screen_Max_Y]
5052
     add  eax,0x00010001
5053
     add  eax,0x00010001
5053
     mov  [esp+36],eax
5054
     mov  [esp+36],eax
5054
     ret
5055
     ret
5055
   no_gs1:
5056
   no_gs1:
5056
 
5057
 
5057
     cmp   eax,2                ; bits per pixel
5058
     cmp   eax,2                ; bits per pixel
5058
     jne   no_gs2
5059
     jne   no_gs2
5059
     movzx eax,byte [ScreenBPP]
5060
     movzx eax,byte [ScreenBPP]
5060
     mov   [esp+36],eax
5061
     mov   [esp+36],eax
5061
     ret
5062
     ret
5062
   no_gs2:
5063
   no_gs2:
5063
 
5064
 
5064
     cmp   eax,3                ; bytes per scanline
5065
     cmp   eax,3                ; bytes per scanline
5065
     jne   no_gs3
5066
     jne   no_gs3
5066
     mov   eax,[BytesPerScanLine]
5067
     mov   eax,[BytesPerScanLine]
5067
     mov   [esp+36],eax
5068
     mov   [esp+36],eax
5068
     ret
5069
     ret
5069
   no_gs3:
5070
   no_gs3:
5070
 
5071
 
5071
     or  [esp+36],dword -1
5072
     or  [esp+36],dword -1
5072
     ret
5073
     ret
5073
 
5074
 
5074
 
5075
 
5075
align 4 ; PCI functions
5076
align 4 ; PCI functions
5076
 
5077
 
5077
sys_pci:
5078
sys_pci:
5078
 
5079
 
5079
     call  pci_api
5080
     call  pci_api
5080
     mov   [esp+36],eax
5081
     mov   [esp+36],eax
5081
     ret
5082
     ret
5082
 
5083
 
5083
 
5084
 
5084
align 4  ;  system functions
5085
align 4  ;  system functions
5085
 
5086
 
5086
syscall_setpixel:                       ; SetPixel
5087
syscall_setpixel:                       ; SetPixel
5087
 
5088
 
5088
        mov     eax, ebx
5089
        mov     eax, ebx
5089
        mov     ebx, ecx
5090
        mov     ebx, ecx
5090
        mov     ecx, edx
5091
        mov     ecx, edx
5091
        mov     edx, [TASK_BASE]
5092
        mov     edx, [TASK_BASE]
5092
        add     eax, [edx-twdw+WDATA.box.left]
5093
        add     eax, [edx-twdw+WDATA.box.left]
5093
        add     ebx, [edx-twdw+WDATA.box.top]
5094
        add     ebx, [edx-twdw+WDATA.box.top]
5094
        mov     edi, [current_slot]
5095
        mov     edi, [current_slot]
5095
        add     eax, [edi+APPDATA.wnd_clientbox.left]
5096
        add     eax, [edi+APPDATA.wnd_clientbox.left]
5096
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
5097
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
5097
        xor     edi, edi ; no force
5098
        xor     edi, edi ; no force
5098
;       mov     edi, 1
5099
;       mov     edi, 1
5099
        call    [_display.disable_mouse]
5100
        call    [_display.disable_mouse]
5100
        jmp     [putpixel]
5101
        jmp     [putpixel]
5101
 
5102
 
5102
align 4
5103
align 4
5103
 
5104
 
5104
syscall_writetext:                      ; WriteText
5105
syscall_writetext:                      ; WriteText
5105
 
5106
 
5106
        mov   eax,[TASK_BASE]
5107
        mov   eax,[TASK_BASE]
5107
        mov   ebp,[eax-twdw+WDATA.box.left]
5108
        mov   ebp,[eax-twdw+WDATA.box.left]
5108
        push  esi
5109
        push  esi
5109
        mov   esi,[current_slot]
5110
        mov   esi,[current_slot]
5110
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
5111
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
5111
        shl   ebp,16
5112
        shl   ebp,16
5112
        add   ebp,[eax-twdw+WDATA.box.top]
5113
        add   ebp,[eax-twdw+WDATA.box.top]
5113
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
5114
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
5114
        pop   esi
5115
        pop   esi
5115
        add   ebx,ebp
5116
        add   ebx,ebp
5116
        mov   eax,edi
5117
        mov   eax,edi
5117
        xor   edi,edi
5118
        xor   edi,edi
5118
        jmp   dtext
5119
        jmp   dtext
5119
 
5120
 
5120
align 4
5121
align 4
5121
 
5122
 
5122
syscall_openramdiskfile:                ; OpenRamdiskFile
5123
syscall_openramdiskfile:                ; OpenRamdiskFile
5123
 
5124
 
5124
        mov     eax, ebx
5125
        mov     eax, ebx
5125
        mov     ebx, ecx
5126
        mov     ebx, ecx
5126
        mov     ecx, edx
5127
        mov     ecx, edx
5127
        mov     edx, esi
5128
        mov     edx, esi
5128
        mov     esi, 12
5129
        mov     esi, 12
5129
        call    fileread
5130
        call    fileread
5130
        mov     [esp+32], eax
5131
        mov     [esp+32], eax
5131
        ret
5132
        ret
5132
 
5133
 
5133
align 4
5134
align 4
5134
 
5135
 
5135
syscall_drawrect:                       ; DrawRect
5136
syscall_drawrect:                       ; DrawRect
5136
 
5137
 
5137
        mov     edi, edx ; color + gradient
5138
        mov     edi, edx ; color + gradient
5138
        and     edi, 0x80FFFFFF
5139
        and     edi, 0x80FFFFFF
5139
        test    bx, bx  ; x.size
5140
        test    bx, bx  ; x.size
5140
        je      .drectr
5141
        je      .drectr
5141
        test    cx, cx ; y.size
5142
        test    cx, cx ; y.size
5142
        je      .drectr
5143
        je      .drectr
5143
 
5144
 
5144
        mov     eax, ebx ; bad idea
5145
        mov     eax, ebx ; bad idea
5145
        mov     ebx, ecx
5146
        mov     ebx, ecx
5146
 
5147
 
5147
        movzx   ecx, ax ; ecx - x.size
5148
        movzx   ecx, ax ; ecx - x.size
5148
        shr     eax, 16 ; eax - x.coord
5149
        shr     eax, 16 ; eax - x.coord
5149
        movzx   edx, bx ; edx - y.size
5150
        movzx   edx, bx ; edx - y.size
5150
        shr     ebx, 16 ; ebx - y.coord
5151
        shr     ebx, 16 ; ebx - y.coord
5151
        mov     esi, [current_slot]
5152
        mov     esi, [current_slot]
5152
 
5153
 
5153
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5154
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5154
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5155
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5155
        add     ecx, eax
5156
        add     ecx, eax
5156
        add     edx, ebx
5157
        add     edx, ebx
5157
        jmp     [drawbar]
5158
        jmp     [drawbar]
5158
.drectr:
5159
.drectr:
5159
        ret
5160
        ret
5160
 
5161
 
5161
align 4
5162
align 4
5162
syscall_getscreensize:                  ; GetScreenSize
5163
syscall_getscreensize:                  ; GetScreenSize
5163
        mov     ax, [Screen_Max_X]
5164
        mov     ax, [Screen_Max_X]
5164
        shl     eax, 16
5165
        shl     eax, 16
5165
        mov     ax, [Screen_Max_Y]
5166
        mov     ax, [Screen_Max_Y]
5166
        mov     [esp + 32], eax
5167
        mov     [esp + 32], eax
5167
        ret
5168
        ret
5168
 
5169
 
5169
align 4
5170
align 4
5170
 
5171
 
5171
syscall_cdaudio:                        ; CD
5172
syscall_cdaudio:                        ; CD
5172
 
5173
 
5173
        cmp     ebx, 4
5174
        cmp     ebx, 4
5174
        jb      .audio
5175
        jb      .audio
5175
        jz      .eject
5176
        jz      .eject
5176
        cmp     ebx, 5
5177
        cmp     ebx, 5
5177
        jnz     .ret
5178
        jnz     .ret
5178
.load:
5179
.load:
5179
        call    .reserve
5180
        call    .reserve
5180
        call    LoadMedium
5181
        call    LoadMedium
5181
        ;call    .free
5182
        ;call    .free
5182
		jmp		.free
5183
		jmp		.free
5183
;        ret
5184
;        ret
5184
.eject:
5185
.eject:
5185
        call    .reserve
5186
        call    .reserve
5186
        call    clear_CD_cache
5187
        call    clear_CD_cache
5187
        call    allow_medium_removal
5188
        call    allow_medium_removal
5188
        call    EjectMedium
5189
        call    EjectMedium
5189
;        call    .free
5190
;        call    .free
5190
		jmp		.free
5191
		jmp		.free
5191
;        ret
5192
;        ret
5192
.audio:
5193
.audio:
5193
     call  sys_cd_audio
5194
     call  sys_cd_audio
5194
     mov   [esp+36-4],eax
5195
     mov   [esp+36-4],eax
5195
.ret:
5196
.ret:
5196
     ret
5197
     ret
5197
 
5198
 
5198
.reserve:
5199
.reserve:
5199
        call    reserve_cd
5200
        call    reserve_cd
5200
        mov     eax, ecx
5201
        mov     eax, ecx
5201
        shr     eax, 1
5202
        shr     eax, 1
5202
        and     eax, 1
5203
        and     eax, 1
5203
        inc     eax
5204
        inc     eax
5204
        mov     [ChannelNumber], ax
5205
        mov     [ChannelNumber], ax
5205
        mov     eax, ecx
5206
        mov     eax, ecx
5206
        and     eax, 1
5207
        and     eax, 1
5207
        mov     [DiskNumber], al
5208
        mov     [DiskNumber], al
5208
        call    reserve_cd_channel
5209
        call    reserve_cd_channel
5209
        and     ebx, 3
5210
        and     ebx, 3
5210
        inc     ebx
5211
        inc     ebx
5211
        mov     [cdpos], ebx
5212
        mov     [cdpos], ebx
5212
        add     ebx, ebx
5213
        add     ebx, ebx
5213
        mov     cl, 8
5214
        mov     cl, 8
5214
        sub     cl, bl
5215
        sub     cl, bl
5215
        mov     al, [DRIVE_DATA+1]
5216
        mov     al, [DRIVE_DATA+1]
5216
        shr     al, cl
5217
        shr     al, cl
5217
        test    al, 2
5218
        test    al, 2
5218
        jz      .free;.err
5219
        jz      .free;.err
5219
        ret
5220
        ret
5220
.free:
5221
.free:
5221
        call    free_cd_channel
5222
        call    free_cd_channel
5222
        and     [cd_status], 0
5223
        and     [cd_status], 0
5223
        ret
5224
        ret
5224
.err:
5225
.err:
5225
        call    .free
5226
        call    .free
5226
;        pop     eax
5227
;        pop     eax
5227
        ret
5228
        ret
5228
 
5229
 
5229
align 4
5230
align 4
5230
 
5231
 
5231
syscall_getpixel:                       ; GetPixel
5232
syscall_getpixel:                       ; GetPixel
5232
     mov   ecx, [Screen_Max_X]
5233
     mov   ecx, [Screen_Max_X]
5233
     inc   ecx
5234
     inc   ecx
5234
     xor   edx, edx
5235
     xor   edx, edx
5235
     mov   eax, ebx
5236
     mov   eax, ebx
5236
     div   ecx
5237
     div   ecx
5237
     mov   ebx, edx
5238
     mov   ebx, edx
5238
     xchg  eax, ebx
5239
     xchg  eax, ebx
5239
     call  dword [GETPIXEL] ; eax - x, ebx - y
5240
     call  dword [GETPIXEL] ; eax - x, ebx - y
5240
     mov   [esp + 32], ecx
5241
     mov   [esp + 32], ecx
5241
     ret
5242
     ret
5242
 
5243
 
5243
align 4
5244
align 4
5244
 
5245
 
5245
syscall_getarea:
5246
syscall_getarea:
5246
;eax = 36
5247
;eax = 36
5247
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5248
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5248
;ecx = [size x]*65536 + [size y]
5249
;ecx = [size x]*65536 + [size y]
5249
;edx = [start x]*65536 + [start y]
5250
;edx = [start x]*65536 + [start y]
5250
     pushad
5251
     pushad
5251
         inc   [mouse_pause]
5252
         inc   [mouse_pause]
5252
; Check of use of the hardware cursor.
5253
; Check of use of the hardware cursor.
5253
      cmp  [_display.disable_mouse],__sys_disable_mouse
5254
      cmp  [_display.disable_mouse],__sys_disable_mouse
5254
          jne  @f
5255
          jne  @f
5255
; Since the test for the coordinates of the mouse should not be used,
5256
; Since the test for the coordinates of the mouse should not be used,
5256
; then use the call [disable_mouse] is not possible!
5257
; then use the call [disable_mouse] is not possible!
5257
      cmp  dword [MOUSE_VISIBLE],dword 0
5258
      cmp  dword [MOUSE_VISIBLE],dword 0
5258
      jne  @f
5259
      jne  @f
5259
      pushf
5260
      pushf
5260
      cli
5261
      cli
5261
      call draw_mouse_under
5262
      call draw_mouse_under
5262
      popf
5263
      popf
5263
      mov  [MOUSE_VISIBLE],dword 1
5264
      mov  [MOUSE_VISIBLE],dword 1
5264
@@:
5265
@@:
5265
     mov   edi,ebx
5266
     mov   edi,ebx
5266
     mov   eax,edx
5267
     mov   eax,edx
5267
     shr   eax,16
5268
     shr   eax,16
5268
     mov   ebx,edx
5269
     mov   ebx,edx
5269
     and   ebx,0xffff
5270
     and   ebx,0xffff
5270
     dec   eax
5271
     dec   eax
5271
           dec   ebx
5272
           dec   ebx
5272
     ; eax - x, ebx - y
5273
     ; eax - x, ebx - y
5273
     mov   edx,ecx
5274
     mov   edx,ecx
5274
     
5275
     
5275
     shr   ecx,16
5276
     shr   ecx,16
5276
     and   edx,0xffff
5277
     and   edx,0xffff
5277
     mov   esi,ecx
5278
     mov   esi,ecx
5278
     ; ecx - size x, edx - size y
5279
     ; ecx - size x, edx - size y
5279
         
5280
         
5280
         mov   ebp,edx
5281
         mov   ebp,edx
5281
         dec   ebp
5282
         dec   ebp
5282
     lea   ebp,[ebp*3]
5283
     lea   ebp,[ebp*3]
5283
         
5284
         
5284
         imul  ebp,esi
5285
         imul  ebp,esi
5285
         
5286
         
5286
         mov   esi,ecx
5287
         mov   esi,ecx
5287
         dec   esi
5288
         dec   esi
5288
         lea   esi,[esi*3]
5289
         lea   esi,[esi*3]
5289
         
5290
         
5290
     add   ebp,esi
5291
     add   ebp,esi
5291
     add   ebp,edi
5292
     add   ebp,edi
5292
 
5293
 
5293
     add   ebx,edx
5294
     add   ebx,edx
5294
         
5295
         
5295
.start_y:
5296
.start_y:
5296
     push  ecx edx
5297
     push  ecx edx
5297
.start_x:
5298
.start_x:
5298
     push  eax ebx ecx
5299
     push  eax ebx ecx
5299
     add   eax,ecx
5300
     add   eax,ecx
5300
 
5301
 
5301
     call  dword [GETPIXEL] ; eax - x, ebx - y
5302
     call  dword [GETPIXEL] ; eax - x, ebx - y
5302
     
5303
     
5303
     mov   [ebp],cx
5304
     mov   [ebp],cx
5304
     shr   ecx,16
5305
     shr   ecx,16
5305
     mov   [ebp+2],cl
5306
     mov   [ebp+2],cl
5306
 
5307
 
5307
     pop   ecx ebx eax
5308
     pop   ecx ebx eax
5308
     sub   ebp,3
5309
     sub   ebp,3
5309
     dec   ecx
5310
     dec   ecx
5310
     jnz   .start_x
5311
     jnz   .start_x
5311
         pop   edx ecx
5312
         pop   edx ecx
5312
         dec   ebx
5313
         dec   ebx
5313
     dec   edx
5314
     dec   edx
5314
     jnz   .start_y
5315
     jnz   .start_y
5315
     dec        [mouse_pause]
5316
     dec        [mouse_pause]
5316
; Check of use of the hardware cursor.
5317
; Check of use of the hardware cursor.
5317
      cmp  [_display.disable_mouse],__sys_disable_mouse
5318
      cmp  [_display.disable_mouse],__sys_disable_mouse
5318
          jne  @f
5319
          jne  @f
5319
         call  [draw_pointer]
5320
         call  [draw_pointer]
5320
@@:
5321
@@:
5321
     popad
5322
     popad
5322
     ret
5323
     ret
5323
 
5324
 
5324
align 4
5325
align 4
5325
 
5326
 
5326
syscall_drawline:                       ; DrawLine
5327
syscall_drawline:                       ; DrawLine
5327
 
5328
 
5328
        mov     edi, [TASK_BASE]
5329
        mov     edi, [TASK_BASE]
5329
        movzx   eax, word[edi-twdw+WDATA.box.left]
5330
        movzx   eax, word[edi-twdw+WDATA.box.left]
5330
        mov     ebp, eax
5331
        mov     ebp, eax
5331
        mov     esi, [current_slot]
5332
        mov     esi, [current_slot]
5332
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5333
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5333
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
5334
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
5334
        add     ebp,ebx
5335
        add     ebp,ebx
5335
        shl     eax, 16
5336
        shl     eax, 16
5336
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5337
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5337
        add     eax, ebp
5338
        add     eax, ebp
5338
        mov     ebp, ebx
5339
        mov     ebp, ebx
5339
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5340
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5340
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5341
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5341
        add     ebp, ecx
5342
        add     ebp, ecx
5342
        shl     ebx, 16
5343
        shl     ebx, 16
5343
        xor     edi, edi
5344
        xor     edi, edi
5344
        add     ebx, ebp
5345
        add     ebx, ebp
5345
        mov     ecx, edx
5346
        mov     ecx, edx
5346
        jmp     [draw_line]
5347
        jmp     [draw_line]
5347
 
5348
 
5348
align 4
5349
align 4
5349
 
5350
 
5350
syscall_getirqowner:                    ; GetIrqOwner
5351
syscall_getirqowner:                    ; GetIrqOwner
5351
 
5352
 
5352
     cmp   ebx,16
5353
     cmp   ebx,16
5353
     jae   .err
5354
     jae   .err
5354
 
5355
 
5355
     cmp   [irq_rights + 4 * ebx], dword 2
5356
     cmp   [irq_rights + 4 * ebx], dword 2
5356
     je    .err
5357
     je    .err
5357
 
5358
 
5358
     mov   eax,[4 * ebx + irq_owner]
5359
     mov   eax,[4 * ebx + irq_owner]
5359
     mov   [esp+32],eax
5360
     mov   [esp+32],eax
5360
 
5361
 
5361
     ret
5362
     ret
5362
.err:
5363
.err:
5363
     or    dword [esp+32], -1
5364
     or    dword [esp+32], -1
5364
     ret
5365
     ret
5365
 
5366
 
5366
align 4
5367
align 4
5367
 
5368
 
5368
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5369
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
5369
 
5370
 
5370
     call  r_f_port_area
5371
     call  r_f_port_area
5371
     mov   [esp+32],eax
5372
     mov   [esp+32],eax
5372
     ret
5373
     ret
5373
 
5374
 
5374
align 4
5375
align 4
5375
 
5376
 
5376
syscall_threads:                        ; CreateThreads
5377
syscall_threads:                        ; CreateThreads
5377
 
5378
 
5378
     call  sys_threads
5379
     call  sys_threads
5379
     mov   [esp+36],eax
5380
     mov   [esp+36],eax
5380
     ret
5381
     ret
5381
 
5382
 
5382
align 4
5383
align 4
5383
 
5384
 
5384
stack_driver_stat:
5385
stack_driver_stat:
5385
 
5386
 
5386
     call  app_stack_handler            ; Stack status
5387
     call  app_stack_handler            ; Stack status
5387
 
5388
 
5388
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5389
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5389
;     call  change_task                 ; between sent packet
5390
;     call  change_task                 ; between sent packet
5390
 
5391
 
5391
     mov   [esp+36],eax
5392
     mov   [esp+36],eax
5392
     ret
5393
     ret
5393
 
5394
 
5394
align 4
5395
align 4
5395
 
5396
 
5396
socket:                                 ; Socket interface
5397
socket:                                 ; Socket interface
5397
     call  app_socket_handler
5398
     call  app_socket_handler
5398
 
5399
 
5399
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5400
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5400
;     call  change_task                 ; between sent packet
5401
;     call  change_task                 ; between sent packet
5401
 
5402
 
5402
     mov   [esp+36],eax
5403
     mov   [esp+36],eax
5403
     mov   [esp+24],ebx
5404
     mov   [esp+24],ebx
5404
     ret
5405
     ret
5405
 
5406
 
5406
align 4
5407
align 4
5407
 
5408
 
5408
read_from_hd:                           ; Read from hd - fn not in use
5409
read_from_hd:                           ; Read from hd - fn not in use
5409
 
5410
 
5410
     mov   edi,[TASK_BASE]
5411
     mov   edi,[TASK_BASE]
5411
     add   edi,TASKDATA.mem_start
5412
     add   edi,TASKDATA.mem_start
5412
     add   eax,[edi]
5413
     add   eax,[edi]
5413
     add   ecx,[edi]
5414
     add   ecx,[edi]
5414
     add   edx,[edi]
5415
     add   edx,[edi]
5415
     call  file_read
5416
     call  file_read
5416
 
5417
 
5417
     mov   [esp+36],eax
5418
     mov   [esp+36],eax
5418
     mov   [esp+24],ebx
5419
     mov   [esp+24],ebx
5419
 
5420
 
5420
     ret
5421
     ret
5421
 
5422
 
5422
paleholder:
5423
paleholder:
5423
        ret
5424
        ret
5424
 
5425
 
5425
align 4
5426
align 4
5426
set_screen:
5427
set_screen:
5427
        cmp eax, [Screen_Max_X]
5428
        cmp eax, [Screen_Max_X]
5428
        jne .set
5429
        jne .set
5429
 
5430
 
5430
        cmp edx, [Screen_Max_Y]
5431
        cmp edx, [Screen_Max_Y]
5431
        jne .set
5432
        jne .set
5432
        ret
5433
        ret
5433
.set:
5434
.set:
5434
        pushfd
5435
        pushfd
5435
        cli
5436
        cli
5436
 
5437
 
5437
        mov [Screen_Max_X], eax
5438
        mov [Screen_Max_X], eax
5438
        mov [Screen_Max_Y], edx
5439
        mov [Screen_Max_Y], edx
5439
        mov [BytesPerScanLine], ecx
5440
        mov [BytesPerScanLine], ecx
5440
 
5441
 
5441
        mov [screen_workarea.right],eax
5442
        mov [screen_workarea.right],eax
5442
        mov [screen_workarea.bottom], edx
5443
        mov [screen_workarea.bottom], edx
5443
 
5444
 
5444
        push ebx
5445
        push ebx
5445
        push esi
5446
        push esi
5446
        push edi
5447
        push edi
5447
 
5448
 
5448
        pushad
5449
        pushad
5449
 
5450
 
5450
        stdcall kernel_free, [_WinMapAddress]
5451
        stdcall kernel_free, [_WinMapAddress]
5451
 
5452
 
5452
        mov eax, [_display.width]
5453
        mov eax, [_display.width]
5453
        mul [_display.height]
5454
        mul [_display.height]
5454
        mov [_WinMapSize], eax
5455
        mov [_WinMapSize], eax
5455
 
5456
 
5456
        stdcall kernel_alloc, eax
5457
        stdcall kernel_alloc, eax
5457
        mov [_WinMapAddress], eax
5458
        mov [_WinMapAddress], eax
5458
        test eax, eax
5459
        test eax, eax
5459
        jz .epic_fail
5460
        jz .epic_fail
5460
 
5461
 
5461
        popad
5462
        popad
5462
 
5463
 
5463
        call    repos_windows
5464
        call    repos_windows
5464
        xor eax, eax
5465
        xor eax, eax
5465
        xor ebx, ebx
5466
        xor ebx, ebx
5466
        mov     ecx, [Screen_Max_X]
5467
        mov     ecx, [Screen_Max_X]
5467
        mov     edx, [Screen_Max_Y]
5468
        mov     edx, [Screen_Max_Y]
5468
        call    calculatescreen
5469
        call    calculatescreen
5469
        pop edi
5470
        pop edi
5470
        pop esi
5471
        pop esi
5471
        pop ebx
5472
        pop ebx
5472
 
5473
 
5473
        popfd
5474
        popfd
5474
        ret
5475
        ret
5475
 
5476
 
5476
.epic_fail:
5477
.epic_fail:
5477
        hlt                     ; Houston, we've had a problem
5478
        hlt                     ; Houston, we've had a problem
5478
 
5479
 
5479
; --------------- APM ---------------------
5480
; --------------- APM ---------------------
5480
apm_entry    dp    0
5481
apm_entry    dp    0
5481
apm_vf        dd    0
5482
apm_vf        dd    0
5482
align 4
5483
align 4
5483
sys_apm:
5484
sys_apm:
5484
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5485
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5485
    jne    @f
5486
    jne    @f
5486
    or     [esp + 48], byte 1    ; error
5487
    or     [esp + 48], byte 1    ; error
5487
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
5488
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
5488
    ret
5489
    ret
5489
 
5490
 
5490
@@:
5491
@@:
5491
    xchg    eax, ecx
5492
    xchg    eax, ecx
5492
    xchg    ebx, ecx
5493
    xchg    ebx, ecx
5493
 
5494
 
5494
    cmp    al, 3
5495
    cmp    al, 3
5495
    ja    @f
5496
    ja    @f
5496
    and    [esp + 48], byte 0xfe    ; emulate func 0..3 as func 0
5497
    and    [esp + 48], byte 0xfe    ; emulate func 0..3 as func 0
5497
    mov    eax, [apm_vf]
5498
    mov    eax, [apm_vf]
5498
    mov    [esp + 36], eax
5499
    mov    [esp + 36], eax
5499
    shr    eax, 16
5500
    shr    eax, 16
5500
    mov    [esp + 32], eax
5501
    mov    [esp + 32], eax
5501
    ret
5502
    ret
5502
 
5503
 
5503
@@:
5504
@@:
5504
 
5505
 
5505
    mov esi, [master_tab+(OS_BASE shr 20)]
5506
    mov esi, [master_tab+(OS_BASE shr 20)]
5506
    xchg [master_tab], esi
5507
    xchg [master_tab], esi
5507
    push esi
5508
    push esi
5508
    mov edi, cr3
5509
    mov edi, cr3
5509
    mov cr3, edi                 ;flush TLB
5510
    mov cr3, edi                 ;flush TLB
5510
 
5511
 
5511
    call    pword [apm_entry]    ; call APM BIOS
5512
    call    pword [apm_entry]    ; call APM BIOS
5512
 
5513
 
5513
    xchg eax, [esp]
5514
    xchg eax, [esp]
5514
    mov [master_tab], eax
5515
    mov [master_tab], eax
5515
    mov eax, cr3
5516
    mov eax, cr3
5516
    mov cr3, eax
5517
    mov cr3, eax
5517
    pop eax
5518
    pop eax
5518
 
5519
 
5519
    mov    [esp + 8 ], edi
5520
    mov    [esp + 8 ], edi
5520
    mov    [esp + 12], esi
5521
    mov    [esp + 12], esi
5521
    mov    [esp + 24], ebx
5522
    mov    [esp + 24], ebx
5522
    mov    [esp + 28], edx
5523
    mov    [esp + 28], edx
5523
    mov    [esp + 32], ecx
5524
    mov    [esp + 32], ecx
5524
    mov    [esp + 36], eax
5525
    mov    [esp + 36], eax
5525
    setc   al
5526
    setc   al
5526
    and    [esp + 48], byte 0xfe
5527
    and    [esp + 48], byte 0xfe
5527
    or     [esp + 48], al
5528
    or     [esp + 48], al
5528
 
5529
 
5529
 
5530
 
5530
    ret
5531
    ret
5531
; -----------------------------------------
5532
; -----------------------------------------
5532
 
5533
 
5533
align 4
5534
align 4
5534
 
5535
 
5535
undefined_syscall:                      ; Undefined system call
5536
undefined_syscall:                      ; Undefined system call
5536
     mov   [esp + 32], dword -1
5537
     mov   [esp + 32], dword -1
5537
     ret
5538
     ret
5538
 
5539
 
5539
align 4
5540
align 4
5540
system_shutdown:          ; shut down the system
5541
system_shutdown:          ; shut down the system
5541
 
5542
 
5542
           cmp byte [BOOT_VAR+0x9030], 1
5543
           cmp byte [BOOT_VAR+0x9030], 1
5543
           jne @F
5544
           jne @F
5544
           ret
5545
           ret
5545
@@:
5546
@@:
5546
           call stop_all_services
5547
           call stop_all_services
5547
           push 3                ; stop playing cd
5548
           push 3                ; stop playing cd
5548
           pop  eax
5549
           pop  eax
5549
           call sys_cd_audio
5550
           call sys_cd_audio
5550
 
5551
 
5551
yes_shutdown_param:
5552
yes_shutdown_param:
5552
           cli
5553
           cli
5553
 
5554
 
5554
           mov  eax, kernel_file ; load kernel.mnt to 0x7000:0
5555
           mov  eax, kernel_file ; load kernel.mnt to 0x7000:0
5555
           push 12
5556
           push 12
5556
           pop  esi
5557
           pop  esi
5557
           xor  ebx,ebx
5558
           xor  ebx,ebx
5558
           or   ecx,-1
5559
           or   ecx,-1
5559
           mov  edx, OS_BASE+0x70000
5560
           mov  edx, OS_BASE+0x70000
5560
           call fileread
5561
           call fileread
5561
 
5562
 
5562
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5563
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5563
           mov  edi,OS_BASE+0x40000
5564
           mov  edi,OS_BASE+0x40000
5564
           mov  ecx,1000
5565
           mov  ecx,1000
5565
           rep  movsb
5566
           rep  movsb
5566
 
5567
 
5567
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5568
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5568
           mov  edi, OS_BASE
5569
           mov  edi, OS_BASE
5569
           mov  ecx,0x10000/4
5570
           mov  ecx,0x10000/4
5570
           cld
5571
           cld
5571
           rep movsd
5572
           rep movsd
5572
 
5573
 
5573
           call restorefatchain
5574
           call restorefatchain
5574
 
5575
 
5575
           mov al, 0xFF
5576
           mov al, 0xFF
5576
           out 0x21, al
5577
           out 0x21, al
5577
           out 0xA1, al
5578
           out 0xA1, al
5578
 
5579
 
5579
if 0
5580
if 0
5580
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5581
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5581
           mov  word [OS_BASE+0x467+2],0x1000
5582
           mov  word [OS_BASE+0x467+2],0x1000
5582
 
5583
 
5583
           mov  al,0x0F
5584
           mov  al,0x0F
5584
           out  0x70,al
5585
           out  0x70,al
5585
           mov  al,0x05
5586
           mov  al,0x05
5586
           out  0x71,al
5587
           out  0x71,al
5587
 
5588
 
5588
           mov  al,0xFE
5589
           mov  al,0xFE
5589
           out  0x64,al
5590
           out  0x64,al
5590
 
5591
 
5591
           hlt
5592
           hlt
5592
           jmp $-1
5593
           jmp $-1
5593
 
5594
 
5594
else
5595
else
5595
        cmp     byte [OS_BASE + 0x9030], 2
5596
        cmp     byte [OS_BASE + 0x9030], 2
5596
        jnz     no_acpi_power_off
5597
        jnz     no_acpi_power_off
5597
 
5598
 
5598
; scan for RSDP
5599
; scan for RSDP
5599
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
5600
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
5600
        movzx   eax, word [OS_BASE + 0x40E]
5601
        movzx   eax, word [OS_BASE + 0x40E]
5601
        shl     eax, 4
5602
        shl     eax, 4
5602
        jz      @f
5603
        jz      @f
5603
        mov     ecx, 1024/16
5604
        mov     ecx, 1024/16
5604
        call    scan_rsdp
5605
        call    scan_rsdp
5605
        jnc     .rsdp_found
5606
        jnc     .rsdp_found
5606
@@:
5607
@@:
5607
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
5608
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
5608
        mov     eax, 0xE0000
5609
        mov     eax, 0xE0000
5609
        mov     ecx, 0x2000
5610
        mov     ecx, 0x2000
5610
        call    scan_rsdp
5611
        call    scan_rsdp
5611
        jc      no_acpi_power_off
5612
        jc      no_acpi_power_off
5612
.rsdp_found:
5613
.rsdp_found:
5613
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
5614
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
5614
        mov     ebp, [ipc_tmp]
5615
        mov     ebp, [ipc_tmp]
5615
        stdcall map_page, ebp, esi, PG_MAP
5616
        stdcall map_page, ebp, esi, PG_MAP
5616
        lea     eax, [esi+1000h]
5617
        lea     eax, [esi+1000h]
5617
        lea     edx, [ebp+1000h]
5618
        lea     edx, [ebp+1000h]
5618
        stdcall map_page, edx, eax, PG_MAP
5619
        stdcall map_page, edx, eax, PG_MAP
5619
        and     esi, 0xFFF
5620
        and     esi, 0xFFF
5620
        add     esi, ebp
5621
        add     esi, ebp
5621
        cmp     dword [esi], 'RSDT'
5622
        cmp     dword [esi], 'RSDT'
5622
        jnz     no_acpi_power_off
5623
        jnz     no_acpi_power_off
5623
        mov     ecx, [esi+4]
5624
        mov     ecx, [esi+4]
5624
        sub     ecx, 24h
5625
        sub     ecx, 24h
5625
        jbe     no_acpi_power_off
5626
        jbe     no_acpi_power_off
5626
        shr     ecx, 2
5627
        shr     ecx, 2
5627
        add     esi, 24h
5628
        add     esi, 24h
5628
.scan_fadt:
5629
.scan_fadt:
5629
        lodsd
5630
        lodsd
5630
        mov     ebx, eax
5631
        mov     ebx, eax
5631
        lea     eax, [ebp+2000h]
5632
        lea     eax, [ebp+2000h]
5632
        stdcall map_page, eax, ebx, PG_MAP
5633
        stdcall map_page, eax, ebx, PG_MAP
5633
        lea     eax, [ebp+3000h]
5634
        lea     eax, [ebp+3000h]
5634
        add     ebx, 0x1000
5635
        add     ebx, 0x1000
5635
        stdcall map_page, eax, ebx, PG_MAP
5636
        stdcall map_page, eax, ebx, PG_MAP
5636
        and     ebx, 0xFFF
5637
        and     ebx, 0xFFF
5637
        lea     ebx, [ebx+ebp+2000h]
5638
        lea     ebx, [ebx+ebp+2000h]
5638
        cmp     dword [ebx], 'FACP'
5639
        cmp     dword [ebx], 'FACP'
5639
        jz      .fadt_found
5640
        jz      .fadt_found
5640
        loop    .scan_fadt
5641
        loop    .scan_fadt
5641
        jmp     no_acpi_power_off
5642
        jmp     no_acpi_power_off
5642
.fadt_found:
5643
.fadt_found:
5643
; ebx is linear address of FADT
5644
; ebx is linear address of FADT
5644
        mov     edi, [ebx+40] ; physical address of the DSDT
5645
        mov     edi, [ebx+40] ; physical address of the DSDT
5645
        lea     eax, [ebp+4000h]
5646
        lea     eax, [ebp+4000h]
5646
        stdcall map_page, eax, edi, PG_MAP
5647
        stdcall map_page, eax, edi, PG_MAP
5647
        lea     eax, [ebp+5000h]
5648
        lea     eax, [ebp+5000h]
5648
        lea     esi, [edi+0x1000]
5649
        lea     esi, [edi+0x1000]
5649
        stdcall map_page, eax, esi, PG_MAP
5650
        stdcall map_page, eax, esi, PG_MAP
5650
        and     esi, 0xFFF
5651
        and     esi, 0xFFF
5651
        sub     edi, esi
5652
        sub     edi, esi
5652
        cmp     dword [esi+ebp+4000h], 'DSDT'
5653
        cmp     dword [esi+ebp+4000h], 'DSDT'
5653
        jnz     no_acpi_power_off
5654
        jnz     no_acpi_power_off
5654
        mov     eax, [esi+ebp+4004h] ; DSDT length
5655
        mov     eax, [esi+ebp+4004h] ; DSDT length
5655
        sub     eax, 36+4
5656
        sub     eax, 36+4
5656
        jbe     no_acpi_power_off
5657
        jbe     no_acpi_power_off
5657
        add     esi, 36
5658
        add     esi, 36
5658
.scan_dsdt:
5659
.scan_dsdt:
5659
        cmp     dword [esi+ebp+4000h], '_S5_'
5660
        cmp     dword [esi+ebp+4000h], '_S5_'
5660
        jnz     .scan_dsdt_cont
5661
        jnz     .scan_dsdt_cont
5661
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
5662
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
5662
        jnz     .scan_dsdt_cont
5663
        jnz     .scan_dsdt_cont
5663
        mov     dl, [esi+ebp+4000h+6]
5664
        mov     dl, [esi+ebp+4000h+6]
5664
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5665
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5665
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5666
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5666
        ja      .scan_dsdt_cont
5667
        ja      .scan_dsdt_cont
5667
        cmp     dl, 1
5668
        cmp     dl, 1
5668
        jb      .scan_dsdt_cont
5669
        jb      .scan_dsdt_cont
5669
        lea     esi, [esi+ebp+4000h+7]
5670
        lea     esi, [esi+ebp+4000h+7]
5670
        xor     ecx, ecx
5671
        xor     ecx, ecx
5671
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
5672
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
5672
        jz      @f
5673
        jz      @f
5673
        cmp     byte [esi], 0xA
5674
        cmp     byte [esi], 0xA
5674
        jnz     no_acpi_power_off
5675
        jnz     no_acpi_power_off
5675
        inc     esi
5676
        inc     esi
5676
        mov     cl, [esi]
5677
        mov     cl, [esi]
5677
@@:
5678
@@:
5678
        inc     esi
5679
        inc     esi
5679
        cmp     dl, 2
5680
        cmp     dl, 2
5680
        jb      @f
5681
        jb      @f
5681
        cmp     byte [esi], 0
5682
        cmp     byte [esi], 0
5682
        jz      @f
5683
        jz      @f
5683
        cmp     byte [esi], 0xA
5684
        cmp     byte [esi], 0xA
5684
        jnz     no_acpi_power_off
5685
        jnz     no_acpi_power_off
5685
        inc     esi
5686
        inc     esi
5686
        mov     ch, [esi]
5687
        mov     ch, [esi]
5687
@@:
5688
@@:
5688
        jmp     do_acpi_power_off
5689
        jmp     do_acpi_power_off
5689
.scan_dsdt_cont:
5690
.scan_dsdt_cont:
5690
        inc     esi
5691
        inc     esi
5691
        cmp     esi, 0x1000
5692
        cmp     esi, 0x1000
5692
        jb      @f
5693
        jb      @f
5693
        sub     esi, 0x1000
5694
        sub     esi, 0x1000
5694
        add     edi, 0x1000
5695
        add     edi, 0x1000
5695
        push    eax
5696
        push    eax
5696
        lea     eax, [ebp+4000h]
5697
        lea     eax, [ebp+4000h]
5697
        stdcall map_page, eax, edi, PG_MAP
5698
        stdcall map_page, eax, edi, PG_MAP
5698
        push    PG_MAP
5699
        push    PG_MAP
5699
        lea     eax, [edi+1000h]
5700
        lea     eax, [edi+1000h]
5700
        push    eax
5701
        push    eax
5701
        lea     eax, [ebp+5000h]
5702
        lea     eax, [ebp+5000h]
5702
        push    eax
5703
        push    eax
5703
        stdcall map_page
5704
        stdcall map_page
5704
        pop     eax
5705
        pop     eax
5705
@@:
5706
@@:
5706
        dec     eax
5707
        dec     eax
5707
        jnz     .scan_dsdt
5708
        jnz     .scan_dsdt
5708
        jmp     no_acpi_power_off
5709
        jmp     no_acpi_power_off
5709
do_acpi_power_off:
5710
do_acpi_power_off:
5710
        mov     edx, [ebx+48]
5711
        mov     edx, [ebx+48]
5711
        test    edx, edx
5712
        test    edx, edx
5712
        jz      .nosmi
5713
        jz      .nosmi
5713
        mov     al, [ebx+52]
5714
        mov     al, [ebx+52]
5714
        out     dx, al
5715
        out     dx, al
5715
        mov     edx, [ebx+64]
5716
        mov     edx, [ebx+64]
5716
@@:
5717
@@:
5717
        in      ax, dx
5718
        in      ax, dx
5718
        test    al, 1
5719
        test    al, 1
5719
        jz      @b
5720
        jz      @b
5720
.nosmi:
5721
.nosmi:
5721
        and     cx, 0x0707
5722
        and     cx, 0x0707
5722
        shl     cx, 2
5723
        shl     cx, 2
5723
        or      cx, 0x2020
5724
        or      cx, 0x2020
5724
        mov     edx, [ebx+64]
5725
        mov     edx, [ebx+64]
5725
        in      ax, dx
5726
        in      ax, dx
5726
        and     ax, 203h
5727
        and     ax, 203h
5727
        or      ah, cl
5728
        or      ah, cl
5728
        out     dx, ax
5729
        out     dx, ax
5729
        mov     edx, [ebx+68]
5730
        mov     edx, [ebx+68]
5730
        test    edx, edx
5731
        test    edx, edx
5731
        jz      @f
5732
        jz      @f
5732
        in      ax, dx
5733
        in      ax, dx
5733
        and     ax, 203h
5734
        and     ax, 203h
5734
        or      ah, ch
5735
        or      ah, ch
5735
        out     dx, ax
5736
        out     dx, ax
5736
@@:
5737
@@:
5737
        jmp     $
5738
        jmp     $
5738
 
5739
 
5739
 
5740
 
5740
no_acpi_power_off:
5741
no_acpi_power_off:
5741
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5742
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5742
           mov  word [OS_BASE+0x467+2],0x1000
5743
           mov  word [OS_BASE+0x467+2],0x1000
5743
 
5744
 
5744
           mov  al,0x0F
5745
           mov  al,0x0F
5745
           out  0x70,al
5746
           out  0x70,al
5746
           mov  al,0x05
5747
           mov  al,0x05
5747
           out  0x71,al
5748
           out  0x71,al
5748
 
5749
 
5749
           mov  al,0xFE
5750
           mov  al,0xFE
5750
           out  0x64,al
5751
           out  0x64,al
5751
 
5752
 
5752
           hlt
5753
           hlt
5753
           jmp $-1
5754
           jmp $-1
5754
 
5755
 
5755
scan_rsdp:
5756
scan_rsdp:
5756
        add     eax, OS_BASE
5757
        add     eax, OS_BASE
5757
.s:
5758
.s:
5758
        cmp     dword [eax], 'RSD '
5759
        cmp     dword [eax], 'RSD '
5759
        jnz     .n
5760
        jnz     .n
5760
        cmp     dword [eax+4], 'PTR '
5761
        cmp     dword [eax+4], 'PTR '
5761
        jnz     .n
5762
        jnz     .n
5762
        xor     edx, edx
5763
        xor     edx, edx
5763
        xor     esi, esi
5764
        xor     esi, esi
5764
@@:
5765
@@:
5765
        add     dl, [eax+esi]
5766
        add     dl, [eax+esi]
5766
        inc     esi
5767
        inc     esi
5767
        cmp     esi, 20
5768
        cmp     esi, 20
5768
        jnz     @b
5769
        jnz     @b
5769
        test    dl, dl
5770
        test    dl, dl
5770
        jz      .ok
5771
        jz      .ok
5771
.n:
5772
.n:
5772
        add     eax, 10h
5773
        add     eax, 10h
5773
        loop    .s
5774
        loop    .s
5774
        stc
5775
        stc
5775
.ok:
5776
.ok:
5776
        ret
5777
        ret
5777
end if
5778
end if
5778
 
5779
 
5779
include "data32.inc"
5780
include "data32.inc"
5780
 
5781
 
5781
__REV__ = __REV
5782
__REV__ = __REV
5782
 
5783
 
5783
uglobals_size = $ - endofcode
5784
uglobals_size = $ - endofcode
5784
diff16 "end of kernel code",0,$
5785
diff16 "end of kernel code",0,$