Subversion Repositories Kolibri OS

Rev

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

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