Subversion Repositories Kolibri OS

Rev

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

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