Subversion Repositories Kolibri OS

Rev

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

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