Subversion Repositories Kolibri OS

Rev

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

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