Subversion Repositories Kolibri OS

Rev

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

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