Subversion Repositories Kolibri OS

Rev

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

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