Subversion Repositories Kolibri OS

Rev

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

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