Subversion Repositories Kolibri OS

Rev

Rev 6319 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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