Subversion Repositories Kolibri OS

Rev

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

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