Subversion Repositories Kolibri OS

Rev

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

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