Subversion Repositories Kolibri OS

Rev

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

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