Subversion Repositories Kolibri OS

Rev

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

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