Subversion Repositories Kolibri OS

Rev

Rev 4286 | Rev 4297 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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