Subversion Repositories Kolibri OS

Rev

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

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