Subversion Repositories Kolibri OS

Rev

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

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