Subversion Repositories Kolibri OS

Rev

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

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