Subversion Repositories Kolibri OS

Rev

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

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