Subversion Repositories Kolibri OS

Rev

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

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