Subversion Repositories Kolibri OS

Rev

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

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