Subversion Repositories Kolibri OS

Rev

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

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