Subversion Repositories Kolibri OS

Rev

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

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