Subversion Repositories Kolibri OS

Rev

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

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