Subversion Repositories Kolibri OS

Rev

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

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