Subversion Repositories Kolibri OS

Rev

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

Rev 888 Rev 889
1
format MS COFF
1
format MS COFF
2
 
2
 
3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
;;
4
;;
5
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved.
5
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved.
6
;; PROGRAMMING:
6
;; PROGRAMMING:
7
;; Ivan Poddubny
7
;; Ivan Poddubny
8
;; Marat Zakiyanov (Mario79)
8
;; Marat Zakiyanov (Mario79)
9
;; VaStaNi
9
;; VaStaNi
10
;; Trans
10
;; Trans
11
;; Mihail Semenyako (mike.dld)
11
;; Mihail Semenyako (mike.dld)
12
;; Sergey Kuzmin (Wildwest)
12
;; Sergey Kuzmin (Wildwest)
13
;; Andrey Halyavin (halyavin)
13
;; Andrey Halyavin (halyavin)
14
;; Mihail Lisovin (Mihasik)
14
;; Mihail Lisovin (Mihasik)
15
;; Andrey Ignatiev (andrew_programmer)
15
;; Andrey Ignatiev (andrew_programmer)
16
;; NoName
16
;; NoName
17
;; Evgeny Grechnikov (Diamond)
17
;; Evgeny Grechnikov (Diamond)
18
;; Iliya Mihailov (Ghost)
18
;; Iliya Mihailov (Ghost)
19
;; Sergey Semyonov (Serge)
19
;; Sergey Semyonov (Serge)
20
;; Johnny_B
20
;; Johnny_B
21
;; SPraid (simba)
21
;; SPraid (simba)
22
;;
22
;;
23
;; Data in this file was originally part of MenuetOS project which is
23
;; Data in this file was originally part of MenuetOS project which is
24
;; distributed under the terms of GNU GPL. It is modified and redistributed as
24
;; distributed under the terms of GNU GPL. It is modified and redistributed as
25
;; part of KolibriOS project under the terms of GNU GPL.
25
;; part of KolibriOS project under the terms of GNU GPL.
26
;;
26
;;
27
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
27
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
28
;; PROGRAMMING:
28
;; PROGRAMMING:
29
;;
29
;;
30
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
30
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
31
;; - main os coding/design
31
;; - main os coding/design
32
;; Jan-Michael Brummer, BUZZ2@gmx.de
32
;; Jan-Michael Brummer, BUZZ2@gmx.de
33
;; Felix Kaiser, info@felix-kaiser.de
33
;; Felix Kaiser, info@felix-kaiser.de
34
;; Paolo Minazzi, paolo.minazzi@inwind.it
34
;; Paolo Minazzi, paolo.minazzi@inwind.it
35
;; quickcode@mail.ru
35
;; quickcode@mail.ru
36
;; Alexey, kgaz@crosswinds.net
36
;; Alexey, kgaz@crosswinds.net
37
;; Juan M. Caravaca, bitrider@wanadoo.es
37
;; Juan M. Caravaca, bitrider@wanadoo.es
38
;; kristol@nic.fi
38
;; kristol@nic.fi
39
;; Mike Hibbett, mikeh@oceanfree.net
39
;; Mike Hibbett, mikeh@oceanfree.net
40
;; Lasse Kuusijarvi, kuusijar@lut.fi
40
;; Lasse Kuusijarvi, kuusijar@lut.fi
41
;; Jarek Pelczar, jarekp3@wp.pl
41
;; Jarek Pelczar, jarekp3@wp.pl
42
;;
42
;;
43
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
43
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
44
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
44
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
45
;; consequences of using it or for whether it serves any particular purpose or
45
;; consequences of using it or for whether it serves any particular purpose or
46
;; works at all, unless he says so in writing. Refer to the GNU General Public
46
;; works at all, unless he says so in writing. Refer to the GNU General Public
47
;; License (the "GPL") for full details.
47
;; License (the "GPL") for full details.
48
;
48
;
49
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
49
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
50
;; but only under the conditions described in the GPL. A copy of this license
50
;; but only under the conditions described in the GPL. A copy of this license
51
;; is supposed to have been given to you along with KolibriOS so you can know
51
;; is supposed to have been given to you along with KolibriOS so you can know
52
;; your rights and responsibilities. It should be in a file named COPYING.
52
;; your rights and responsibilities. It should be in a file named COPYING.
53
;; Among other things, the copyright notice and this notice must be preserved
53
;; Among other things, the copyright notice and this notice must be preserved
54
;; on all copies.
54
;; on all copies.
55
;;
55
;;
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57
 
57
 
58
include 'macros.inc'
58
include 'macros.inc'
59
 
59
 
60
$Revision: 888 $
60
$Revision: 889 $
61
 
61
 
62
 
62
 
63
fastcall equ call
63
fastcall equ call
64
 
64
 
65
USE_COM_IRQ equ 1      ;make irq 3 and irq 4 available for PCI devices
65
USE_COM_IRQ equ 1      ;make irq 3 and irq 4 available for PCI devices
66
 
66
 
67
include "proc32.inc"
67
include "proc32.inc"
68
include "kglobals.inc"
68
include "kglobals.inc"
69
include "lang.inc"
69
include "lang.inc"
70
 
70
 
71
include "const.inc"
71
include "const.inc"
72
max_processes	 equ   255
72
max_processes	 equ   255
73
tss_step	 equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
73
tss_step	 equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
74
 
74
 
75
 
75
 
76
os_stack       equ  (os_data_l-_gdts)    ; GDTs
76
os_stack       equ  (os_data_l-_gdts)    ; GDTs
77
os_code        equ  (os_code_l-_gdts)
77
os_code        equ  (os_code_l-_gdts)
78
graph_data     equ  (3+graph_data_l-_gdts)
78
graph_data     equ  (3+graph_data_l-_gdts)
79
tss0           equ  (tss0_l-_gdts)
79
tss0           equ  (tss0_l-_gdts)
80
app_code       equ  (3+app_code_l-_gdts)
80
app_code       equ  (3+app_code_l-_gdts)
81
app_data       equ  (3+app_data_l-_gdts)
81
app_data       equ  (3+app_data_l-_gdts)
82
pci_code_sel   equ  (pci_code_32-_gdts)
82
pci_code_sel   equ  (pci_code_32-_gdts)
83
pci_data_sel   equ  (pci_data_32-_gdts)
83
pci_data_sel   equ  (pci_data_32-_gdts)
84
 
84
 
85
 
85
 
86
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87
;;
87
;;
88
;;   Included files:
88
;;   Included files:
89
;;
89
;;
90
;;   Kernel16.inc
90
;;   Kernel16.inc
91
;;    - Booteng.inc   English text for bootup
91
;;    - Booteng.inc   English text for bootup
92
;;    - Bootcode.inc  Hardware setup
92
;;    - Bootcode.inc  Hardware setup
93
;;    - Pci16.inc     PCI functions
93
;;    - Pci16.inc     PCI functions
94
;;
94
;;
95
;;   Kernel32.inc
95
;;   Kernel32.inc
96
;;    - Sys32.inc     Process management
96
;;    - Sys32.inc     Process management
97
;;    - Shutdown.inc  Shutdown and restart
97
;;    - Shutdown.inc  Shutdown and restart
98
;;    - Fat32.inc     Read / write hd
98
;;    - Fat32.inc     Read / write hd
99
;;    - Vesa12.inc    Vesa 1.2 driver
99
;;    - Vesa12.inc    Vesa 1.2 driver
100
;;    - Vesa20.inc    Vesa 2.0 driver
100
;;    - Vesa20.inc    Vesa 2.0 driver
101
;;    - Vga.inc       VGA driver
101
;;    - Vga.inc       VGA driver
102
;;    - Stack.inc     Network interface
102
;;    - Stack.inc     Network interface
103
;;    - Mouse.inc     Mouse pointer
103
;;    - Mouse.inc     Mouse pointer
104
;;    - Scincode.inc  Window skinning
104
;;    - Scincode.inc  Window skinning
105
;;    - Pci32.inc     PCI functions
105
;;    - Pci32.inc     PCI functions
106
;;
106
;;
107
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
108
 
108
 
109
 
109
 
110
public __os_stack
110
public __os_stack
111
public _boot_mbi
111
public _boot_mbi
112
public _sys_pdbr
112
public _sys_pdbr
113
public _gdts
113
public _gdts
114
public _high_code
114
public _high_code
115
 
115
 
116
public __hlt
116
public __hlt
117
public _panic_printf
117
public _panic_printf
118
public _printf
118
public _printf
119
public _pg_balloc
119
public _pg_balloc
120
public _mem_amount
120
public _mem_amount
121
public @balloc@4
121
public @balloc@4
122
 
122
 
123
public __setvars
123
public __setvars
124
 
124
 
125
public _rd_base
125
public _rd_base
126
public _rd_fat
126
public _rd_fat
127
public _rd_fat_end
127
public _rd_fat_end
128
public _rd_root
128
public _rd_root
129
public _rd_root_end
129
public _rd_root_end
130
 
130
 
-
 
131
public _load_file@4
-
 
132
 
-
 
133
public _kernel_exports
-
 
134
 
-
 
135
public _strncmp@12
131
 
136
 
132
extrn __edata
137
extrn __edata
133
 
138
 
134
extrn _16bit_start
139
extrn _16bit_start
135
extrn _16bit_end
140
extrn _16bit_end
136
 
141
 
137
extrn _enter_bootscreen
142
extrn _enter_bootscreen
138
extrn _poweroff
143
extrn _poweroff
139
 
144
 
140
extrn _init
145
extrn _init
141
extrn _init_mm
146
extrn _init_mm
142
 
147
 
143
extrn @core_alloc@4
148
extrn @core_alloc@4
144
extrn @core_free@4
149
extrn @core_free@4
145
 
150
 
146
extrn @init_heap@8
151
extrn @init_heap@8
147
extrn @find_large_md@4
152
extrn @find_large_md@4
148
extrn @phis_alloc@4
153
 
149
 
-
 
150
extrn @mem_alloc@8
154
extrn @mem_alloc@8
151
extrn @mem_free@4
155
extrn @mem_free@4
152
 
156
 
-
 
157
extrn @load_pe@4
-
 
158
extrn @load_pe_driver@4
-
 
159
 
153
extrn _slab_cache_init
160
extrn _slab_cache_init
154
extrn _alloc_page
161
extrn _alloc_page
155
 
162
 
156
extrn _get_free_mem
163
extrn _get_free_mem
157
 
164
 
158
extrn _bx_from_load
165
extrn _bx_from_load
159
 
166
 
160
 
167
 
161
section '.flat' code readable align 4096
168
section '.flat' code readable align 4096
162
 
169
 
163
use32
170
use32
164
 
171
 
165
align 4
172
align 4
166
 
173
 
167
use32
174
use32
168
 
175
 
169
        ;   call test_cpu
176
        ;   call test_cpu
170
        ;   bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
177
        ;   bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
171
 
178
 
172
        ;   call init_BIOS32
179
        ;   call init_BIOS32
173
 
180
 
174
;           jmp pword os_code:high_code
181
;           jmp pword os_code:high_code
175
 
182
 
176
align 4
183
align 4
177
;bios32_entry    dd ?
184
;bios32_entry    dd ?
178
;tmp_page_tabs   dd ?
185
;tmp_page_tabs   dd ?
179
 
186
 
180
 
187
 
181
__DEBUG__ fix 1
188
__DEBUG__ fix 1
182
__DEBUG_LEVEL__ fix 1
189
__DEBUG_LEVEL__ fix 1
183
 
190
 
184
 
191
 
185
MEM_WB     equ 6               ;write-back memory
192
MEM_WB     equ 6               ;write-back memory
186
MEM_WC     equ 1               ;write combined memory
193
MEM_WC     equ 1               ;write combined memory
187
MEM_UC     equ 0               ;uncached memory
194
MEM_UC     equ 0               ;uncached memory
188
 
195
 
189
 
196
 
190
__hlt:
197
__hlt:
191
           cli
198
           cli
192
@@:
199
@@:
193
           hlt
200
           hlt
194
           jmp @B
201
           jmp @B
195
 
202
 
196
align 4
203
align 4
197
_panic_printf:
204
_panic_printf:
198
 
205
 
199
           mov dword [esp], __hlt
206
           mov dword [esp], __hlt
200
           jmp _printf
207
           jmp _printf
201
 
208
 
202
align 4
209
align 4
203
include 'printf.inc'
210
include 'printf.inc'
204
 
211
 
205
align 4
212
align 4
206
proc test_cpu
213
proc test_cpu
207
           locals
214
           locals
208
              cpu_type   dd ?
215
              cpu_type   dd ?
209
              cpu_id     dd ?
216
              cpu_id     dd ?
210
              cpu_Intel  dd ?
217
              cpu_Intel  dd ?
211
              cpu_AMD    dd ?
218
              cpu_AMD    dd ?
212
           endl
219
           endl
213
 
220
 
214
           mov [cpu_type], 0
221
           mov [cpu_type], 0
215
           xor eax, eax
222
           xor eax, eax
216
           mov [cpu_caps], eax
223
           mov [cpu_caps], eax
217
           mov [cpu_caps+4], eax
224
           mov [cpu_caps+4], eax
218
 
225
 
219
           xor eax, eax
226
           xor eax, eax
220
           cpuid
227
           cpuid
221
 
228
 
222
           mov [cpu_vendor], ebx
229
           mov [cpu_vendor], ebx
223
           mov [cpu_vendor+4], edx
230
           mov [cpu_vendor+4], edx
224
           mov [cpu_vendor+8], ecx
231
           mov [cpu_vendor+8], ecx
225
           cmp ebx, dword [intel_str]
232
           cmp ebx, dword [intel_str]
226
           jne .check_AMD
233
           jne .check_AMD
227
           cmp edx, dword [intel_str+4]
234
           cmp edx, dword [intel_str+4]
228
           jne .check_AMD
235
           jne .check_AMD
229
           cmp ecx, dword [intel_str+8]
236
           cmp ecx, dword [intel_str+8]
230
           jne .check_AMD
237
           jne .check_AMD
231
           mov [cpu_Intel], 1
238
           mov [cpu_Intel], 1
232
           cmp eax, 1
239
           cmp eax, 1
233
           jl .end_cpuid
240
           jl .end_cpuid
234
           mov eax, 1
241
           mov eax, 1
235
           cpuid
242
           cpuid
236
           mov [cpu_sign], eax
243
           mov [cpu_sign], eax
237
           mov [cpu_info],  ebx
244
           mov [cpu_info],  ebx
238
           mov [cpu_caps],  edx
245
           mov [cpu_caps],  edx
239
           mov [cpu_caps+4],ecx
246
           mov [cpu_caps+4],ecx
240
 
247
 
241
           shr eax, 8
248
           shr eax, 8
242
           and eax, 0x0f
249
           and eax, 0x0f
243
           ret
250
           ret
244
.end_cpuid:
251
.end_cpuid:
245
           mov eax, [cpu_type]
252
           mov eax, [cpu_type]
246
           ret
253
           ret
247
 
254
 
248
.check_AMD:
255
.check_AMD:
249
           cmp ebx, dword [AMD_str]
256
           cmp ebx, dword [AMD_str]
250
           jne .unknown
257
           jne .unknown
251
           cmp edx, dword [AMD_str+4]
258
           cmp edx, dword [AMD_str+4]
252
           jne .unknown
259
           jne .unknown
253
           cmp ecx, dword [AMD_str+8]
260
           cmp ecx, dword [AMD_str+8]
254
           jne .unknown
261
           jne .unknown
255
           mov [cpu_AMD], 1
262
           mov [cpu_AMD], 1
256
           cmp eax, 1
263
           cmp eax, 1
257
           jl .unknown
264
           jl .unknown
258
           mov eax, 1
265
           mov eax, 1
259
           cpuid
266
           cpuid
260
           mov [cpu_sign], eax
267
           mov [cpu_sign], eax
261
           mov [cpu_info],  ebx
268
           mov [cpu_info],  ebx
262
           mov [cpu_caps],  edx
269
           mov [cpu_caps],  edx
263
           mov [cpu_caps+4],ecx
270
           mov [cpu_caps+4],ecx
264
           shr eax, 8
271
           shr eax, 8
265
           and eax, 0x0f
272
           and eax, 0x0f
266
           ret
273
           ret
267
.unknown:
274
.unknown:
268
           mov eax, 1
275
           mov eax, 1
269
           cpuid
276
           cpuid
270
           mov [cpu_sign], eax
277
           mov [cpu_sign], eax
271
           mov [cpu_info],  ebx
278
           mov [cpu_info],  ebx
272
           mov [cpu_caps],  edx
279
           mov [cpu_caps],  edx
273
           mov [cpu_caps+4],ecx
280
           mov [cpu_caps+4],ecx
274
           shr eax, 8
281
           shr eax, 8
275
           and eax, 0x0f
282
           and eax, 0x0f
276
           ret
283
           ret
277
endp
284
endp
278
 
285
 
279
align 4
286
align 4
280
_copy_pg_balloc  dd 0
287
_copy_pg_balloc  dd 0
281
 
288
 
282
 
289
 
283
_high_code:
290
_high_code:
284
 
291
 
285
	   mov ax,os_stack
292
	   mov ax,os_stack
286
           mov dx,app_data
293
           mov dx,app_data
287
	   mov ss,ax
294
	   mov ss,ax
288
           mov esp, __os_stack
295
           mov esp, __os_stack
289
 
296
 
290
           mov ds, dx
297
           mov ds, dx
291
           mov es, dx
298
           mov es, dx
292
           mov fs, dx
299
           mov fs, dx
293
           mov gs, dx
300
           mov gs, dx
294
 
301
 
295
 
302
 
296
         ;  bt [cpu_caps], CAPS_PGE
303
         ;  bt [cpu_caps], CAPS_PGE
297
         ;  jnc @F
304
         ;  jnc @F
298
 
305
 
299
         ;  or dword [sys_pgdir-OS_BASE+(OS_BASE shr 20)], PG_GLOBAL
306
         ;  or dword [sys_pgdir-OS_BASE+(OS_BASE shr 20)], PG_GLOBAL
300
 
307
 
301
         ;  mov ebx, cr4
308
         ;  mov ebx, cr4
302
         ;  or ebx, CR4_PGE
309
         ;  or ebx, CR4_PGE
303
         ;  mov cr4, ebx
310
         ;  mov cr4, ebx
304
@@:
311
@@:
305
         ;  mov eax, cr3
312
         ;  mov eax, cr3
306
         ;  mov cr3, eax           ; flush TLB
313
         ;  mov cr3, eax           ; flush TLB
307
 
314
 
308
           mov edx, 0x3fB
315
           mov edx, 0x3fB
309
           mov eax, 3
316
           mov eax, 3
310
           out dx, al
317
           out dx, al
311
 
318
 
312
           call test_cpu
319
           call test_cpu
313
           call _init
320
           call _init
314
 
321
 
315
           mov eax, [_pg_balloc]
322
           mov eax, [_pg_balloc]
316
           mov [_copy_pg_balloc], eax
323
           mov [_copy_pg_balloc], eax
317
 
324
 
318
	   mov [tss._ss0], os_stack
325
	   mov [tss._ss0], os_stack
319
           mov [tss._esp0], __os_stack
326
           mov [tss._esp0], __os_stack
320
           mov [tss._esp], __os_stack
327
           mov [tss._esp], __os_stack
321
	   mov [tss._cs],os_code
328
	   mov [tss._cs],os_code
322
	   mov [tss._ss],os_stack
329
	   mov [tss._ss],os_stack
323
	   mov [tss._ds],app_data
330
	   mov [tss._ds],app_data
324
	   mov [tss._es],app_data
331
	   mov [tss._es],app_data
325
	   mov [tss._fs],app_data
332
	   mov [tss._fs],app_data
326
	   mov [tss._gs],app_data
333
	   mov [tss._gs],app_data
327
	   mov [tss._io],128
334
	   mov [tss._io],128
328
;Add IO access table - bit array of permitted ports
335
;Add IO access table - bit array of permitted ports
329
	   mov edi, tss._io_map_0
336
	   mov edi, tss._io_map_0
330
	   xor eax, eax
337
	   xor eax, eax
331
	   not eax
338
	   not eax
332
	   mov ecx, 8192/4
339
	   mov ecx, 8192/4
333
	   rep stosd		     ; access to 4096*8=65536 ports
340
	   rep stosd		     ; access to 4096*8=65536 ports
334
 
341
 
335
	   mov	ax,tss0
342
	   mov	ax,tss0
336
	   ltr	ax
343
	   ltr	ax
337
 
344
 
338
__core_restart:
345
__core_restart:
339
 
346
 
340
           mov ecx, 1280*1024
347
           mov ecx, 1280*1024
341
           fastcall _balloc
348
           fastcall _balloc
342
           mov [_display_data], eax
349
           mov [_display_data], eax
343
 
350
 
344
           mov ecx, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
351
           mov ecx, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
345
                    (unpack.lc+unpack.lp)))*4
352
                    (unpack.lc+unpack.lp)))*4
346
           fastcall _balloc
353
           fastcall _balloc
347
           mov [unpack.p], eax
354
           mov [unpack.p], eax
348
 
355
 
349
; MEMORY MODEL
356
; MEMORY MODEL
350
 
357
 
351
           call _init_mm
358
           call _init_mm
352
           mov [pg_data.pg_mutex], 0
359
           mov [pg_data.pg_mutex], 0
353
 
360
 
354
           call _slab_cache_init
361
           call _slab_cache_init
355
 
362
 
356
           mov ecx, 0x80000000
363
           mov ecx, 0x80000000
357
           mov edx, 0x40000000
364
           mov edx, 0x40000000
358
           call @init_heap@8
365
           call @init_heap@8
359
 
366
 
360
           mov esi, _16bit_start
367
           mov esi, _16bit_start
361
           mov ecx, _16bit_end
368
           mov ecx, _16bit_end
362
           shr ecx, 2
369
           shr ecx, 2
363
           mov edi, _16BIT_BASE
370
           mov edi, _16BIT_BASE
364
           cld
371
           cld
365
           rep movsd
372
           rep movsd
366
 
373
 
367
           jmp far 0x60:_enter_bootscreen;
374
           jmp far 0x60:_enter_bootscreen;
368
 
375
 
369
align 4
376
align 4
370
__setvars:
377
__setvars:
371
           mov ax,os_stack
378
           mov ax,os_stack
372
           mov dx,app_data
379
           mov dx,app_data
373
	   mov ss,ax
380
	   mov ss,ax
374
           mov esp, __os_stack
381
           mov esp, __os_stack
375
 
382
 
376
           mov ds, dx
383
           mov ds, dx
377
           mov es, dx
384
           mov es, dx
378
           mov fs, dx
385
           mov fs, dx
379
           mov gs, dx
386
           mov gs, dx
380
 
387
 
381
; SAVE & CLEAR 0-0xffff
388
; SAVE & CLEAR 0-0xffff
382
 
389
 
383
           cld
390
           cld
384
           xor esi, esi
391
           xor esi, esi
385
           mov   edi,BOOT_VAR
392
           mov   edi,BOOT_VAR
386
           mov   ecx,0x10000 / 4
393
           mov   ecx,0x10000 / 4
387
           rep   movsd
394
           rep   movsd
388
 
395
 
389
           xor edi, edi
396
           xor edi, edi
390
           xor eax, eax
397
           xor eax, eax
391
           mov   ecx,0x10000 / 4
398
           mov   ecx,0x10000 / 4
392
           rep   stosd
399
           rep   stosd
393
 
400
 
394
           mov edi, 0x40000
401
           mov edi, 0x40000
395
           mov ecx, (0x90000-0x40000)/4
402
           mov ecx, (0x90000-0x40000)/4
396
           rep stosd
403
           rep stosd
397
 
404
 
398
           mov dword [_sys_pdbr], eax
405
           mov dword [_sys_pdbr], eax
399
           mov dword [_sys_pdbr+4], eax
406
           mov dword [_sys_pdbr+4], eax
400
           mov eax, cr3
407
           mov eax, cr3
401
           mov cr3, eax
408
           mov cr3, eax
402
 
409
 
403
; SAVE REAL MODE VARIABLES
410
; SAVE REAL MODE VARIABLES
404
	mov	ax, [BOOT_VAR + 0x9031]
411
	mov	ax, [BOOT_VAR + 0x9031]
405
	mov	[IDEContrRegsBaseAddr], ax
412
	mov	[IDEContrRegsBaseAddr], ax
406
; --------------- APM ---------------------
413
; --------------- APM ---------------------
407
 
414
 
408
; init selectors
415
; init selectors
409
    mov ebx,    [BOOT_VAR +0x9040]    ; offset of APM entry point
416
    mov ebx,    [BOOT_VAR +0x9040]    ; offset of APM entry point
410
    movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of
417
    movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of
411
				      ; protected-mode 32-bit code segment
418
				      ; protected-mode 32-bit code segment
412
    movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of
419
    movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of
413
				      ; protected-mode 16-bit code segment
420
				      ; protected-mode 16-bit code segment
414
    movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of
421
    movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of
415
				      ; protected-mode 16-bit data segment
422
				      ; protected-mode 16-bit data segment
416
 
423
 
417
    shl    eax, 4
424
    shl    eax, 4
418
    mov    [dword apm_code_32 + 2], ax
425
    mov    [dword apm_code_32 + 2], ax
419
    shr    eax, 16
426
    shr    eax, 16
420
    mov    [dword apm_code_32 + 4], al
427
    mov    [dword apm_code_32 + 4], al
421
 
428
 
422
    shl    ecx, 4
429
    shl    ecx, 4
423
    mov    [dword apm_code_16 + 2], cx
430
    mov    [dword apm_code_16 + 2], cx
424
    shr    ecx, 16
431
    shr    ecx, 16
425
    mov    [dword apm_code_16 + 4], cl
432
    mov    [dword apm_code_16 + 4], cl
426
 
433
 
427
    shl    edx, 4
434
    shl    edx, 4
428
    mov    [dword apm_data_16 + 2], dx
435
    mov    [dword apm_data_16 + 2], dx
429
    shr    edx, 16
436
    shr    edx, 16
430
    mov    [dword apm_data_16 + 4], dl
437
    mov    [dword apm_data_16 + 4], dl
431
 
438
 
432
    mov    dword[apm_entry], ebx
439
    mov    dword[apm_entry], ebx
433
    mov    word [apm_entry + 4], apm_code_32 - _gdts
440
    mov    word [apm_entry + 4], apm_code_32 - _gdts
434
 
441
 
435
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
442
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
436
    mov    [apm_vf], eax
443
    mov    [apm_vf], eax
437
; -----------------------------------------
444
; -----------------------------------------
438
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
445
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
439
;        mov   [0xF604],byte 1  ;al
446
;        mov   [0xF604],byte 1  ;al
440
	mov	al, [BOOT_VAR+0x901F]	; DMA access
447
	mov	al, [BOOT_VAR+0x901F]	; DMA access
441
	mov	[allow_dma_access], al
448
	mov	[allow_dma_access], al
442
	mov   al,[BOOT_VAR+0x9000]	  ; bpp
449
	mov   al,[BOOT_VAR+0x9000]	  ; bpp
443
	mov   [ScreenBPP],al
450
	mov   [ScreenBPP],al
444
 
451
 
445
	movzx eax,word [BOOT_VAR+0x900A]  ; X max
452
	movzx eax,word [BOOT_VAR+0x900A]  ; X max
446
	dec   eax
453
	dec   eax
447
	mov   [Screen_Max_X],eax
454
	mov   [Screen_Max_X],eax
448
	mov   [screen_workarea.right],eax
455
	mov   [screen_workarea.right],eax
449
	movzx eax,word [BOOT_VAR+0x900C]  ; Y max
456
	movzx eax,word [BOOT_VAR+0x900C]  ; Y max
450
	dec   eax
457
	dec   eax
451
	mov   [Screen_Max_Y],eax
458
	mov   [Screen_Max_Y],eax
452
	mov   [screen_workarea.bottom],eax
459
	mov   [screen_workarea.bottom],eax
453
	movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
460
	movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
454
	mov   [SCR_MODE],eax
461
	mov   [SCR_MODE],eax
455
	mov   eax,[BOOT_VAR+0x9014]	  ; Vesa 1.2 bnk sw add
462
	mov   eax,[BOOT_VAR+0x9014]	  ; Vesa 1.2 bnk sw add
456
	mov   [BANK_SWITCH],eax
463
	mov   [BANK_SWITCH],eax
457
	mov   [BytesPerScanLine],word 640*4	    ; Bytes PerScanLine
464
	mov   [BytesPerScanLine],word 640*4	    ; Bytes PerScanLine
458
	cmp   [SCR_MODE],word 0x13	    ; 320x200
465
	cmp   [SCR_MODE],word 0x13	    ; 320x200
459
	je    @f
466
	je    @f
460
	cmp   [SCR_MODE],word 0x12	    ; VGA 640x480
467
	cmp   [SCR_MODE],word 0x12	    ; VGA 640x480
461
	je    @f
468
	je    @f
462
 
469
 
463
	mov   ax,[BOOT_VAR+0x9001]	  ; for other modes
470
	mov   ax,[BOOT_VAR+0x9001]	  ; for other modes
464
	mov   [BytesPerScanLine],ax
471
	mov   [BytesPerScanLine],ax
465
@@:
472
@@:
466
	mov	esi, BOOT_VAR+0x9080
473
	mov	esi, BOOT_VAR+0x9080
467
	movzx	ecx, byte [esi-1]
474
	movzx	ecx, byte [esi-1]
468
	mov	[NumBiosDisks], ecx
475
	mov	[NumBiosDisks], ecx
469
	mov	edi, BiosDisksData
476
	mov	edi, BiosDisksData
470
	rep	movsd
477
	rep	movsd
471
 
478
 
472
; GRAPHICS ADDRESSES
479
; GRAPHICS ADDRESSES
473
 
480
 
474
	mov	byte [BOOT_VAR+0x901e],0x0
481
	mov	byte [BOOT_VAR+0x901e],0x0
475
	mov	eax,[BOOT_VAR+0x9018]
482
	mov	eax,[BOOT_VAR+0x9018]
476
	mov	[LFBAddress],eax
483
	mov	[LFBAddress],eax
477
 
484
 
478
	cmp	[SCR_MODE],word 0100000000000000b
485
	cmp	[SCR_MODE],word 0100000000000000b
479
	jge	setvesa20
486
	jge	setvesa20
480
	cmp	[SCR_MODE],word 0x13
487
	cmp	[SCR_MODE],word 0x13
481
	je	v20ga32
488
	je	v20ga32
482
	mov	[PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
489
	mov	[PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
483
	mov	[GETPIXEL],dword Vesa12_getpixel24
490
	mov	[GETPIXEL],dword Vesa12_getpixel24
484
	cmp	[ScreenBPP],byte 24
491
	cmp	[ScreenBPP],byte 24
485
	jz	ga24
492
	jz	ga24
486
	mov	[PUTPIXEL],dword Vesa12_putpixel32
493
	mov	[PUTPIXEL],dword Vesa12_putpixel32
487
	mov	[GETPIXEL],dword Vesa12_getpixel32
494
	mov	[GETPIXEL],dword Vesa12_getpixel32
488
      ga24:
495
      ga24:
489
	jmp	v20ga24
496
	jmp	v20ga24
490
      setvesa20:
497
      setvesa20:
491
	mov	[PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
498
	mov	[PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
492
	mov	[GETPIXEL],dword Vesa20_getpixel24
499
	mov	[GETPIXEL],dword Vesa20_getpixel24
493
	cmp	[ScreenBPP],byte 24
500
	cmp	[ScreenBPP],byte 24
494
	jz	v20ga24
501
	jz	v20ga24
495
      v20ga32:
502
      v20ga32:
496
	mov	[PUTPIXEL],dword Vesa20_putpixel32
503
	mov	[PUTPIXEL],dword Vesa20_putpixel32
497
	mov	[GETPIXEL],dword Vesa20_getpixel32
504
	mov	[GETPIXEL],dword Vesa20_getpixel32
498
      v20ga24:
505
      v20ga24:
499
	cmp	[SCR_MODE],word 0x12		    ; 16 C VGA 640x480
506
	cmp	[SCR_MODE],word 0x12		    ; 16 C VGA 640x480
500
	jne	no_mode_0x12
507
	jne	no_mode_0x12
501
	mov	[PUTPIXEL],dword VGA_putpixel
508
	mov	[PUTPIXEL],dword VGA_putpixel
502
	mov	[GETPIXEL],dword Vesa20_getpixel32
509
	mov	[GETPIXEL],dword Vesa20_getpixel32
503
      no_mode_0x12:
510
      no_mode_0x12:
504
 
511
 
505
; -------- Fast System Call init ----------
512
; -------- Fast System Call init ----------
506
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
513
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
507
	   bt [cpu_caps], CAPS_SEP
514
	   bt [cpu_caps], CAPS_SEP
508
	   jnc .SEnP   ; SysEnter not Present
515
	   jnc .SEnP   ; SysEnter not Present
509
	   xor edx, edx
516
	   xor edx, edx
510
	   mov ecx, MSR_SYSENTER_CS
517
	   mov ecx, MSR_SYSENTER_CS
511
	   mov eax, os_code
518
	   mov eax, os_code
512
	   wrmsr
519
	   wrmsr
513
	   mov ecx, MSR_SYSENTER_ESP
520
	   mov ecx, MSR_SYSENTER_ESP
514
;           mov eax, sysenter_stack ; Check it
521
;           mov eax, sysenter_stack ; Check it
515
	   xor	   eax, eax
522
	   xor	   eax, eax
516
	   wrmsr
523
	   wrmsr
517
	   mov ecx, MSR_SYSENTER_EIP
524
	   mov ecx, MSR_SYSENTER_EIP
518
	   mov eax, sysenter_entry
525
	   mov eax, sysenter_entry
519
	   wrmsr
526
	   wrmsr
520
.SEnP:
527
.SEnP:
521
; AMD SYSCALL/SYSRET
528
; AMD SYSCALL/SYSRET
522
	   cmp byte[cpu_vendor], 'A'
529
	   cmp byte[cpu_vendor], 'A'
523
	   jne .noSYSCALL
530
	   jne .noSYSCALL
524
	   mov eax, 0x80000001
531
	   mov eax, 0x80000001
525
	   cpuid
532
	   cpuid
526
	   test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
533
	   test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
527
	   jz .noSYSCALL
534
	   jz .noSYSCALL
528
	   mov ecx, MSR_AMD_EFER
535
	   mov ecx, MSR_AMD_EFER
529
	   rdmsr
536
	   rdmsr
530
	   or eax, 1   ; bit_0 - System Call Extension (SCE)
537
	   or eax, 1   ; bit_0 - System Call Extension (SCE)
531
	   wrmsr
538
	   wrmsr
532
 
539
 
533
	; !!!! It`s dirty hack, fix it !!!
540
	; !!!! It`s dirty hack, fix it !!!
534
	; Bits of EDX :
541
	; Bits of EDX :
535
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
542
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
536
	;  and the contents of this field, plus 8, are copied into the SS register.
543
	;  and the contents of this field, plus 8, are copied into the SS register.
537
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
544
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
538
	;  and the contents of this field, plus 8, are copied into the SS register.
545
	;  and the contents of this field, plus 8, are copied into the SS register.
539
 
546
 
540
	; mov   edx, (os_code + 16) * 65536 + os_code
547
	; mov   edx, (os_code + 16) * 65536 + os_code
541
	   mov edx, 0x1B0008
548
	   mov edx, 0x1B0008
542
 
549
 
543
	   mov eax, syscall_entry
550
	   mov eax, syscall_entry
544
	   mov ecx, MSR_AMD_STAR
551
	   mov ecx, MSR_AMD_STAR
545
	   wrmsr
552
	   wrmsr
546
.noSYSCALL:
553
.noSYSCALL:
547
; -----------------------------------------
554
; -----------------------------------------
548
; LOAD IDT
555
; LOAD IDT
549
 
556
 
550
           call _init_idt
557
           call _init_idt
551
 
558
 
552
           mov [LFBSize], 0x800000
559
           mov [LFBSize], 0x800000
553
	   call init_LFB
560
	   call init_LFB
554
           call init_fpu
561
           call init_fpu
555
           call init_malloc
562
           call init_malloc
556
 
563
 
557
           mov ecx, 0x51000
564
           mov ecx, 0x51000
558
           xor edx, edx
565
           xor edx, edx
559
           call @mem_alloc@8
566
           call @mem_alloc@8
560
	   mov [default_io_map], eax
567
	   mov [default_io_map], eax
561
 
568
 
562
	   add eax, 0x2000
569
	   add eax, 0x2000
563
	   mov [ipc_tmp], eax
570
	   mov [ipc_tmp], eax
564
	   mov ebx, 0x1000
571
	   mov ebx, 0x1000
565
 
572
 
566
	   add eax, 0x40000
573
	   add eax, 0x40000
567
	   mov [proc_mem_map], eax
574
	   mov [proc_mem_map], eax
568
 
575
 
569
	   add eax, 0x8000
576
	   add eax, 0x8000
570
	   mov [proc_mem_pdir], eax
577
	   mov [proc_mem_pdir], eax
571
 
578
 
572
	   add eax, ebx
579
	   add eax, ebx
573
	   mov [proc_mem_tab], eax
580
	   mov [proc_mem_tab], eax
574
 
581
 
575
	   add eax, ebx
582
	   add eax, ebx
576
	   mov [tmp_task_pdir], eax
583
	   mov [tmp_task_pdir], eax
577
 
584
 
578
	   add eax, ebx
585
	   add eax, ebx
579
	   mov [tmp_task_ptab], eax
586
	   mov [tmp_task_ptab], eax
580
 
587
 
581
	   add eax, ebx
588
	   add eax, ebx
582
	   mov [ipc_pdir], eax
589
	   mov [ipc_pdir], eax
583
 
590
 
584
	   add eax, ebx
591
	   add eax, ebx
585
	   mov [ipc_ptab], eax
592
	   mov [ipc_ptab], eax
586
 
593
 
587
	   call init_events
594
	   call init_events
588
	   mov eax, srv.fd-SRV_FD_OFFSET
595
	   mov eax, srv.fd-SRV_FD_OFFSET
589
	   mov [srv.fd], eax
596
	   mov [srv.fd], eax
590
	   mov [srv.bk], eax
597
	   mov [srv.bk], eax
591
 
598
 
592
	   mov edi, irq_tab
599
	   mov edi, irq_tab
593
	   xor eax, eax
600
	   xor eax, eax
594
	   mov ecx, 16
601
	   mov ecx, 16
595
	   rep stosd
602
	   rep stosd
596
 
603
 
597
;Set base of graphic segment to linear address of LFB
604
;Set base of graphic segment to linear address of LFB
598
	mov	eax,[LFBAddress]	  ; set for gs
605
	mov	eax,[LFBAddress]	  ; set for gs
599
	mov	[graph_data_l+2],ax
606
	mov	[graph_data_l+2],ax
600
	shr	eax,16
607
	shr	eax,16
601
	mov	[graph_data_l+4],al
608
	mov	[graph_data_l+4],al
602
	mov	[graph_data_l+7],ah
609
	mov	[graph_data_l+7],ah
603
 
610
 
604
	mov [CURRENT_TASK],dword 1
611
	mov [CURRENT_TASK],dword 1
605
	mov [TASK_COUNT],dword 1
612
	mov [TASK_COUNT],dword 1
606
	mov [TASK_BASE],dword TASK_DATA
613
	mov [TASK_BASE],dword TASK_DATA
607
	mov [current_slot], SLOT_BASE+256
614
	mov [current_slot], SLOT_BASE+256
608
 
615
 
609
; set background
616
; set background
610
	xor  eax,eax
617
	xor  eax,eax
611
	inc  eax
618
	inc  eax
612
	mov   [BgrDrawMode],eax
619
	mov   [BgrDrawMode],eax
613
	mov   [BgrDataWidth],eax
620
	mov   [BgrDataWidth],eax
614
	mov   [BgrDataHeight],eax
621
	mov   [BgrDataHeight],eax
615
        mov ecx, 4095
622
        mov ecx, 4095
616
        mov edx, PG_SW
623
        mov edx, PG_SW
617
	mov    [mem_BACKGROUND],4095
624
	mov    [mem_BACKGROUND],4095
618
        call @mem_alloc@8
625
        call @mem_alloc@8
619
	mov [img_background], eax
626
	mov [img_background], eax
620
 
627
 
621
        mov     [SLOT_BASE + 256 + APPDATA.dir_table], _sys_pdbr + (0x100000000-OS_BASE)
628
        mov     [SLOT_BASE + 256 + APPDATA.dir_table], _sys_pdbr + (0x100000000-OS_BASE)
622
 
629
 
623
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
630
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
624
 
631
 
625
	call  rerouteirqs
632
	call  rerouteirqs
626
 
633
 
627
; Initialize system V86 machine
634
; Initialize system V86 machine
628
        call    init_sys_v86
635
        call    init_sys_v86
629
 
636
 
630
; TIMER SET TO 1/100 S
637
; TIMER SET TO 1/100 S
631
 
638
 
632
	mov   al,0x34		   ; set to 100Hz
639
	mov   al,0x34		   ; set to 100Hz
633
	out   0x43,al
640
	out   0x43,al
634
	mov   al,0x9b		   ; lsb    1193180 / 1193
641
	mov   al,0x9b		   ; lsb    1193180 / 1193
635
	out   0x40,al
642
	out   0x40,al
636
	mov   al,0x2e		   ; msb
643
	mov   al,0x2e		   ; msb
637
	out   0x40,al
644
	out   0x40,al
638
 
645
 
639
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
646
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
640
; they are used: when partitions are scanned, hd_read relies on timer
647
; they are used: when partitions are scanned, hd_read relies on timer
641
	mov	al, 0xFE
648
	mov	al, 0xFE
642
	out	0x21, al
649
	out	0x21, al
643
	mov	al, 0x3F
650
	mov	al, 0x3F
644
	out	0xA1, al
651
	out	0xA1, al
645
 
652
 
646
;!!!!!!!!!!!!!!!!!!!!!!!!!!
653
;!!!!!!!!!!!!!!!!!!!!!!!!!!
647
include 'detect/disks.inc'
654
include 'detect/disks.inc'
648
;!!!!!!!!!!!!!!!!!!!!!!!!!!
655
;!!!!!!!!!!!!!!!!!!!!!!!!!!
649
 
656
 
650
  call Parser_params
657
  call Parser_params
651
 
658
 
652
; READ RAMDISK IMAGE FROM HD
659
; READ RAMDISK IMAGE FROM HD
653
 
660
 
654
;!!!!!!!!!!!!!!!!!!!!!!!
661
;!!!!!!!!!!!!!!!!!!!!!!!
655
;include 'boot/rdload.inc'
662
;include 'boot/rdload.inc'
656
;!!!!!!!!!!!!!!!!!!!!!!!
663
;!!!!!!!!!!!!!!!!!!!!!!!
657
;    mov    [dma_hdd],1
664
;    mov    [dma_hdd],1
658
; CALCULATE FAT CHAIN FOR RAMDISK
665
; CALCULATE FAT CHAIN FOR RAMDISK
659
 
666
 
660
	call  calculatefatchain
667
	call  calculatefatchain
661
 
668
 
662
 
669
 
663
 ; mov ax,[OS_BASE+0x10000+bx_from_load]
670
 ; mov ax,[OS_BASE+0x10000+bx_from_load]
664
 ; cmp ax,'r1'           ; if using not ram disk, then load librares and parameters {SPraid.simba}
671
 ; cmp ax,'r1'           ; if using not ram disk, then load librares and parameters {SPraid.simba}
665
 ; je  no_lib_load
672
 ; je  no_lib_load
666
; LOADING LIBRARES
673
; LOADING LIBRARES
667
;   stdcall dll.Load,@IMPORT                 ; loading librares for kernel (.obj files)
674
;   stdcall dll.Load,@IMPORT                 ; loading librares for kernel (.obj files)
668
;   call load_file_parse_table               ; prepare file parse table
675
;   call load_file_parse_table               ; prepare file parse table
669
;   call set_kernel_conf                     ; configure devices and gui
676
;   call set_kernel_conf                     ; configure devices and gui
670
;no_lib_load:
677
;no_lib_load:
671
 
678
 
672
; LOAD FONTS I and II
679
; LOAD FONTS I and II
673
 
680
 
674
	stdcall read_file, char, FONT_I, 0, 2304
681
	stdcall read_file, char, FONT_I, 0, 2304
675
        stdcall read_file, char2, FONT_II, 0, 2560
682
        stdcall read_file, char2, FONT_II, 0, 2560
676
 
683
 
677
	mov   esi,boot_fonts
684
	mov   esi,boot_fonts
678
	call  boot_log
685
	call  boot_log
679
 
686
 
680
; PRINT AMOUNT OF MEMORY
687
; PRINT AMOUNT OF MEMORY
681
	mov	esi, boot_memdetect
688
	mov	esi, boot_memdetect
682
	call	boot_log
689
	call	boot_log
683
 
690
 
684
	movzx	ecx, word [boot_y]
691
	movzx	ecx, word [boot_y]
685
	or	ecx, (10+29*6) shl 16 ; "Determining amount of memory"
692
	or	ecx, (10+29*6) shl 16 ; "Determining amount of memory"
686
	sub	ecx, 10
693
	sub	ecx, 10
687
	mov	edx, 0xFFFFFF
694
	mov	edx, 0xFFFFFF
688
        mov     ebx, [_mem_amount]
695
        mov     ebx, [_mem_amount]
689
	shr	ebx, 20
696
	shr	ebx, 20
690
	mov	edi, 1
697
	mov	edi, 1
691
	mov	eax, 0x00040000
698
	mov	eax, 0x00040000
692
	call	display_number_force
699
	call	display_number_force
693
 
700
 
694
; BUILD SCHEDULER
701
; BUILD SCHEDULER
695
 
702
 
696
	call   build_scheduler ; sys32.inc
703
	call   build_scheduler ; sys32.inc
697
 
704
 
698
	mov    esi,boot_devices
705
	mov    esi,boot_devices
699
	call   boot_log
706
	call   boot_log
700
 
707
 
701
	mov  [pci_access_enabled],1
708
	mov  [pci_access_enabled],1
702
 
709
 
703
 
710
 
704
; SET PRELIMINARY WINDOW STACK AND POSITIONS
711
; SET PRELIMINARY WINDOW STACK AND POSITIONS
705
 
712
 
706
	mov   esi,boot_windefs
713
	mov   esi,boot_windefs
707
	call  boot_log
714
	call  boot_log
708
	call  setwindowdefaults
715
	call  setwindowdefaults
709
 
716
 
710
; SET BACKGROUND DEFAULTS
717
; SET BACKGROUND DEFAULTS
711
 
718
 
712
	mov   esi,boot_bgr
719
	mov   esi,boot_bgr
713
	call  boot_log
720
	call  boot_log
714
	call  init_background
721
	call  init_background
715
	call  calculatebackground
722
	call  calculatebackground
716
 
723
 
717
; RESERVE SYSTEM IRQ'S JA PORT'S
724
; RESERVE SYSTEM IRQ'S JA PORT'S
718
 
725
 
719
	mov   esi,boot_resirqports
726
	mov   esi,boot_resirqports
720
	call  boot_log
727
	call  boot_log
721
	call  reserve_irqs_ports
728
	call  reserve_irqs_ports
722
 
729
 
723
; SET PORTS FOR IRQ HANDLERS
730
; SET PORTS FOR IRQ HANDLERS
724
 
731
 
725
	mov  esi,boot_setrports
732
	mov  esi,boot_setrports
726
	call boot_log
733
	call boot_log
727
	;call setirqreadports
734
	;call setirqreadports
728
 
735
 
729
; SET UP OS TASK
736
; SET UP OS TASK
730
 
737
 
731
	mov  esi,boot_setostask
738
	mov  esi,boot_setostask
732
	call boot_log
739
	call boot_log
733
 
740
 
734
	xor  eax, eax
741
	xor  eax, eax
735
	mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
742
	mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
736
	mov  dword [SLOT_BASE+APPDATA.fpu_handler], eax
743
	mov  dword [SLOT_BASE+APPDATA.fpu_handler], eax
737
	mov  dword [SLOT_BASE+APPDATA.sse_handler], eax
744
	mov  dword [SLOT_BASE+APPDATA.sse_handler], eax
738
 
745
 
739
	; name for OS/IDLE process
746
	; name for OS/IDLE process
740
 
747
 
741
	mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
748
	mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
742
	mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
749
	mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
743
        mov edi,  __os_stack-8192+512
750
        mov edi,  __os_stack-8192+512
744
	mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
751
	mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
745
	add edi, 0x2000-512
752
	add edi, 0x2000-512
746
	mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
753
	mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
747
	mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
754
	mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
748
	mov dword [SLOT_BASE+256+APPDATA.io_map],\
755
	mov dword [SLOT_BASE+256+APPDATA.io_map],\
749
		  (tss._io_map_0-OS_BASE+PG_MAP)
756
		  (tss._io_map_0-OS_BASE+PG_MAP)
750
	mov dword [SLOT_BASE+256+APPDATA.io_map+4],\
757
	mov dword [SLOT_BASE+256+APPDATA.io_map+4],\
751
		  (tss._io_map_1-OS_BASE+PG_MAP)
758
		  (tss._io_map_1-OS_BASE+PG_MAP)
752
 
759
 
753
	mov esi, fpu_data
760
	mov esi, fpu_data
754
	mov ecx, 512/4
761
	mov ecx, 512/4
755
	cld
762
	cld
756
	rep movsd
763
	rep movsd
757
 
764
 
758
        mov dword [SLOT_BASE+256+APPDATA.fpu_handler], eax
765
        mov dword [SLOT_BASE+256+APPDATA.fpu_handler], eax
759
	mov dword [SLOT_BASE+256+APPDATA.sse_handler], eax
766
	mov dword [SLOT_BASE+256+APPDATA.sse_handler], eax
760
 
767
 
761
	mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
768
	mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
762
	mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
769
	mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
763
	mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
770
	mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
764
 
771
 
765
	mov  dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
772
	mov  dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
766
 
773
 
767
	; task list
774
	; task list
768
	mov  [CURRENT_TASK],dword 1
775
	mov  [CURRENT_TASK],dword 1
769
	mov  [TASK_COUNT],dword 1
776
	mov  [TASK_COUNT],dword 1
770
	mov  [current_slot], SLOT_BASE+256
777
	mov  [current_slot], SLOT_BASE+256
771
	mov  [TASK_BASE],dword TASK_DATA
778
	mov  [TASK_BASE],dword TASK_DATA
772
	mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
779
	mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
773
	mov  [TASK_DATA+TASKDATA.pid], 1	; process id number
780
	mov  [TASK_DATA+TASKDATA.pid], 1	; process id number
774
	mov  [TASK_DATA+TASKDATA.mem_start], 0	; process base address
781
	mov  [TASK_DATA+TASKDATA.mem_start], 0	; process base address
775
 
782
 
776
        call init_cursors
783
        call init_cursors
777
        mov eax, [def_cursor]
784
        mov eax, [def_cursor]
778
	mov [SLOT_BASE+APPDATA.cursor],eax
785
	mov [SLOT_BASE+APPDATA.cursor],eax
779
	mov [SLOT_BASE+APPDATA.cursor+256],eax
786
	mov [SLOT_BASE+APPDATA.cursor+256],eax
780
 
787
 
-
 
788
        ;mov ecx, szAtiHW
781
       ; stdcall load_pe_driver, szAtiHW
789
        ;call @load_pe_driver@4
782
 
790
 
783
  ; READ TSC / SECOND
791
  ; READ TSC / SECOND
784
 
792
 
785
	mov   esi,boot_tsc
793
	mov   esi,boot_tsc
786
	call  boot_log
794
	call  boot_log
787
 
795
 
788
	call  _rdtsc
796
	call  _rdtsc
789
	mov   ecx,eax
797
	mov   ecx,eax
790
	mov   esi,250		    ; wait 1/4 a second
798
	mov   esi,250		    ; wait 1/4 a second
791
	call  delay_ms
799
	call  delay_ms
792
	call  _rdtsc
800
	call  _rdtsc
793
 
801
 
794
	sub   eax,ecx
802
	sub   eax,ecx
795
	shl   eax,2
803
	shl   eax,2
796
	mov   [CPU_FREQ],eax	      ; save tsc / sec
804
	mov   [CPU_FREQ],eax	      ; save tsc / sec
797
	mov ebx, 1000000
805
	mov ebx, 1000000
798
	div ebx
806
	div ebx
799
	mov [stall_mcs], eax
807
	mov [stall_mcs], eax
800
 
808
 
801
; SET VARIABLES
809
; SET VARIABLES
802
 
810
 
803
	call  set_variables
811
	call  set_variables
804
 
812
 
805
; SET MOUSE
813
; SET MOUSE
806
 
814
 
807
	stdcall load_driver, szPS2MDriver
815
	stdcall load_driver, szPS2MDriver
808
       ; stdcall load_driver, szCOM_MDriver
816
       ; stdcall load_driver, szCOM_MDriver
809
 
817
 
810
	mov   esi,boot_setmouse
818
	mov   esi,boot_setmouse
811
	call  boot_log
819
	call  boot_log
812
	call  setmouse
820
	call  setmouse
813
 
821
 
814
 
822
 
815
; STACK AND FDC
823
; STACK AND FDC
816
 
824
 
817
        call  stack_init
825
        call  stack_init
818
	call  fdc_init
826
	call  fdc_init
819
 
827
 
820
; PALETTE FOR 320x200 and 640x480 16 col
828
; PALETTE FOR 320x200 and 640x480 16 col
821
 
829
 
822
	cmp   [SCR_MODE],word 0x12
830
	cmp   [SCR_MODE],word 0x12
823
	jne   no_pal_vga
831
	jne   no_pal_vga
824
	mov   esi,boot_pal_vga
832
	mov   esi,boot_pal_vga
825
	call  boot_log
833
	call  boot_log
826
	call  paletteVGA
834
	call  paletteVGA
827
      no_pal_vga:
835
      no_pal_vga:
828
 
836
 
829
	cmp   [SCR_MODE],word 0x13
837
	cmp   [SCR_MODE],word 0x13
830
	jne   no_pal_ega
838
	jne   no_pal_ega
831
	mov   esi,boot_pal_ega
839
	mov   esi,boot_pal_ega
832
	call  boot_log
840
	call  boot_log
833
	call  palette320x200
841
	call  palette320x200
834
      no_pal_ega:
842
      no_pal_ega:
835
 
843
 
836
; LOAD DEFAULT SKIN
844
; LOAD DEFAULT SKIN
837
 
845
 
838
	call	load_default_skin
846
	call	load_default_skin
839
 
847
 
840
;protect io permission map
848
;protect io permission map
841
 
849
 
842
	   mov esi, [default_io_map]
850
	   mov esi, [default_io_map]
843
         ;  stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
851
         ;  stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
844
         ;  add esi, 0x1000
852
         ;  add esi, 0x1000
845
         ;  stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
853
         ;  stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
846
 
854
 
847
         ;  stdcall map_page,tss._io_map_0,\
855
         ;  stdcall map_page,tss._io_map_0,\
848
         ;          (tss._io_map_0-OS_BASE), PG_MAP
856
         ;          (tss._io_map_0-OS_BASE), PG_MAP
849
         ;  stdcall map_page,tss._io_map_1,\
857
         ;  stdcall map_page,tss._io_map_1,\
850
         ;          (tss._io_map_1-OS_BASE), PG_MAP
858
         ;          (tss._io_map_1-OS_BASE), PG_MAP
851
 
859
 
852
;  mov ax,[OS_BASE+0x10000+bx_from_load]
860
;  mov ax,[OS_BASE+0x10000+bx_from_load]
853
;  cmp ax,'r1'           ; if not rused ram disk - load network configuration from files {SPraid.simba}
861
;  cmp ax,'r1'           ; if not rused ram disk - load network configuration from files {SPraid.simba}
854
;  je  no_st_network
862
;  je  no_st_network
855
;        call set_network_conf
863
;        call set_network_conf
856
;  no_st_network:
864
;  no_st_network:
857
 
865
 
858
; LOAD FIRST APPLICATION
866
; LOAD FIRST APPLICATION
859
 
867
 
860
 
868
 
861
	mov	ebp, firstapp
869
	mov	ebp, firstapp
862
	call	fs_execute_from_sysdir
870
	call	fs_execute_from_sysdir
863
 
871
 
864
	cmp   eax,2		     ; continue if a process has been loaded
872
	cmp   eax,2		     ; continue if a process has been loaded
865
	je    first_app_found
873
	je    first_app_found
866
 
874
 
867
	mov	esi, boot_failed
875
	mov	esi, boot_failed
868
	call	boot_log
876
	call	boot_log
869
 
877
 
870
	mov   eax, 0xDEADBEEF	     ; otherwise halt
878
	mov   eax, 0xDEADBEEF	     ; otherwise halt
871
	hlt
879
	hlt
872
 
880
 
873
first_app_found:
881
first_app_found:
874
 
882
 
875
	cli
883
	cli
876
 
884
 
877
	;mov   [TASK_COUNT],dword 2
885
	;mov   [TASK_COUNT],dword 2
878
	mov   [CURRENT_TASK],dword 1	   ; set OS task fisrt
886
	mov   [CURRENT_TASK],dword 1	   ; set OS task fisrt
879
 
887
 
880
; SET KEYBOARD PARAMETERS
888
; SET KEYBOARD PARAMETERS
881
	mov   al, 0xf6	       ; reset keyboard, scan enabled
889
	mov   al, 0xf6	       ; reset keyboard, scan enabled
882
	call  kb_write
890
	call  kb_write
883
 
891
 
884
	; wait until 8042 is ready
892
	; wait until 8042 is ready
885
	xor ecx,ecx
893
	xor ecx,ecx
886
@@:
894
@@:
887
	in     al,64h
895
	in     al,64h
888
	and    al,00000010b
896
	and    al,00000010b
889
	loopnz @b
897
	loopnz @b
890
 
898
 
891
	mov   al, 0xF3	     ; set repeat rate & delay
899
	mov   al, 0xF3	     ; set repeat rate & delay
892
	call  kb_write
900
	call  kb_write
893
;        call  kb_read
901
;        call  kb_read
894
	mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
902
	mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
895
	call  kb_write
903
	call  kb_write
896
;        call  kb_read
904
;        call  kb_read
897
     ;// mike.dld [
905
     ;// mike.dld [
898
	call  set_lights
906
	call  set_lights
899
     ;// mike.dld ]
907
     ;// mike.dld ]
900
 
908
 
901
; START MULTITASKING
909
; START MULTITASKING
902
 
910
 
903
;if preboot_blogesc
911
;if preboot_blogesc
904
;        mov     esi, boot_tasking
912
;        mov     esi, boot_tasking
905
;        call    boot_log
913
;        call    boot_log
906
;.bll1:  in      al, 0x60        ; wait for ESC key press
914
;.bll1:  in      al, 0x60        ; wait for ESC key press
907
;        cmp     al, 129
915
;        cmp     al, 129
908
;        jne     .bll1
916
;        jne     .bll1
909
;end if
917
;end if
910
 
918
 
911
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
919
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
912
 
920
 
913
; UNMASK ALL IRQ'S
921
; UNMASK ALL IRQ'S
914
 
922
 
915
	mov   esi,boot_allirqs
923
	mov   esi,boot_allirqs
916
	call  boot_log
924
	call  boot_log
917
 
925
 
918
        mov   al,0                   ; unmask all irq's
926
        mov   al,0                   ; unmask all irq's
919
	out   0xA1,al
927
	out   0xA1,al
920
	out   0x21,al
928
	out   0x21,al
921
 
929
 
922
	mov   ecx,32
930
	mov   ecx,32
923
 
931
 
924
     ready_for_irqs:
932
     ready_for_irqs:
925
 
933
 
926
	mov   al,0x20		     ; ready for irqs
934
	mov   al,0x20		     ; ready for irqs
927
	out   0x20,al
935
	out   0x20,al
928
	out   0xa0,al
936
	out   0xa0,al
929
 
937
 
930
	loop  ready_for_irqs	     ; flush the queue
938
	loop  ready_for_irqs	     ; flush the queue
931
 
939
 
932
	stdcall attach_int_handler, dword 1, irq1, dword 0
940
	stdcall attach_int_handler, dword 1, irq1, dword 0
933
 
941
 
934
;        mov    [dma_hdd],1
942
;        mov    [dma_hdd],1
935
	cmp	[IDEContrRegsBaseAddr], 0
943
	cmp	[IDEContrRegsBaseAddr], 0
936
	setnz	[dma_hdd]
944
	setnz	[dma_hdd]
937
	mov [timer_ticks_enable],1		; for cd driver
945
	mov [timer_ticks_enable],1		; for cd driver
938
 
946
 
939
	sti
947
	sti
940
	call change_task
948
	call change_task
941
 
949
 
942
	jmp osloop
950
	jmp osloop
943
 
951
 
944
;        jmp   $                      ; wait here for timer to take control
952
;        jmp   $                      ; wait here for timer to take control
945
 
953
 
946
	; Fly :)
954
	; Fly :)
947
 
955
 
948
include 'unpacker.inc'
956
include 'unpacker.inc'
949
include 'fdo.inc'
957
include 'fdo.inc'
950
 
958
 
951
align 4
959
align 4
952
boot_log:
960
boot_log:
953
	 pushad
961
	 pushad
954
 
962
 
955
	 mov   ebx,10*65536
963
	 mov   ebx,10*65536
956
	 mov   bx,word [boot_y]
964
	 mov   bx,word [boot_y]
957
	 add   [boot_y],dword 10
965
	 add   [boot_y],dword 10
958
	 mov   ecx,0x80ffffff	; ASCIIZ string with white color
966
	 mov   ecx,0x80ffffff	; ASCIIZ string with white color
959
	 mov   edx,esi
967
	 mov   edx,esi
960
	 mov   edi,1
968
	 mov   edi,1
961
 
969
 
962
         call  dtext
970
         call  dtext
963
 
971
 
964
	 mov   [novesachecksum],1000
972
	 mov   [novesachecksum],1000
965
	 call  checkVga_N13
973
	 call  checkVga_N13
966
 
974
 
967
	 popad
975
	 popad
968
 
976
 
969
	 ret
977
	 ret
970
 
978
 
971
 
979
 
972
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
980
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
973
;                                                                    ;
981
;                                                                    ;
974
;                    MAIN OS LOOP START                              ;
982
;                    MAIN OS LOOP START                              ;
975
;                                                                    ;
983
;                                                                    ;
976
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
984
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
977
align 32
985
align 32
978
osloop:
986
osloop:
979
	call   [draw_pointer]
987
	call   [draw_pointer]
980
	call   checkbuttons
988
	call   checkbuttons
981
	call   checkwindows
989
	call   checkwindows
982
;       call   check_window_move_request
990
;       call   check_window_move_request
983
	call   checkmisc
991
	call   checkmisc
984
	call   checkVga_N13
992
	call   checkVga_N13
985
        call   stack_handler
993
        call   stack_handler
986
	call   checkidle
994
	call   checkidle
987
	call   check_fdd_motor_status
995
	call   check_fdd_motor_status
988
	call   check_ATAPI_device_event
996
	call   check_ATAPI_device_event
989
	jmp    osloop
997
	jmp    osloop
990
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
998
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
991
;                                                                    ;
999
;                                                                    ;
992
;                      MAIN OS LOOP END                              ;
1000
;                      MAIN OS LOOP END                              ;
993
;                                                                    ;
1001
;                                                                    ;
994
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1002
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
995
 
1003
 
996
checkidle:
1004
checkidle:
997
	pushad
1005
	pushad
998
 
1006
 
999
	cmp  [check_idle_semaphore],0
1007
	cmp  [check_idle_semaphore],0
1000
	jne  no_idle_state
1008
	jne  no_idle_state
1001
 
1009
 
1002
	call change_task
1010
	call change_task
1003
	mov  eax,[idlemem]
1011
	mov  eax,[idlemem]
1004
	mov  ebx,[timer_ticks] ;[0xfdf0]
1012
	mov  ebx,[timer_ticks] ;[0xfdf0]
1005
	cmp  eax,ebx
1013
	cmp  eax,ebx
1006
	jnz  idle_exit
1014
	jnz  idle_exit
1007
	call _rdtsc
1015
	call _rdtsc
1008
	mov  ecx,eax
1016
	mov  ecx,eax
1009
      idle_loop:
1017
      idle_loop:
1010
	hlt
1018
	hlt
1011
	cmp  [check_idle_semaphore],0
1019
	cmp  [check_idle_semaphore],0
1012
	jne  idle_loop_exit
1020
	jne  idle_loop_exit
1013
	mov  eax,[timer_ticks] ;[0xfdf0]
1021
	mov  eax,[timer_ticks] ;[0xfdf0]
1014
	cmp  ebx,eax
1022
	cmp  ebx,eax
1015
	jz   idle_loop
1023
	jz   idle_loop
1016
      idle_loop_exit:
1024
      idle_loop_exit:
1017
	mov  [idlemem],eax
1025
	mov  [idlemem],eax
1018
	call _rdtsc
1026
	call _rdtsc
1019
	sub  eax,ecx
1027
	sub  eax,ecx
1020
	mov  ebx,[idleuse]
1028
	mov  ebx,[idleuse]
1021
	add  ebx,eax
1029
	add  ebx,eax
1022
	mov  [idleuse],ebx
1030
	mov  [idleuse],ebx
1023
 
1031
 
1024
	popad
1032
	popad
1025
	ret
1033
	ret
1026
 
1034
 
1027
      idle_exit:
1035
      idle_exit:
1028
 
1036
 
1029
	mov  ebx,[timer_ticks] ;[0xfdf0]
1037
	mov  ebx,[timer_ticks] ;[0xfdf0]
1030
	mov  [idlemem],ebx
1038
	mov  [idlemem],ebx
1031
	call change_task
1039
	call change_task
1032
 
1040
 
1033
	popad
1041
	popad
1034
	ret
1042
	ret
1035
 
1043
 
1036
      no_idle_state:
1044
      no_idle_state:
1037
 
1045
 
1038
	dec  [check_idle_semaphore]
1046
	dec  [check_idle_semaphore]
1039
 
1047
 
1040
	mov  ebx,[timer_ticks] ;[0xfdf0]
1048
	mov  ebx,[timer_ticks] ;[0xfdf0]
1041
	mov  [idlemem],ebx
1049
	mov  [idlemem],ebx
1042
	call change_task
1050
	call change_task
1043
 
1051
 
1044
	popad
1052
	popad
1045
	ret
1053
	ret
1046
 
1054
 
1047
uglobal
1055
uglobal
1048
  idlemem		dd   0x0
1056
  idlemem		dd   0x0
1049
  idleuse		dd   0x0
1057
  idleuse		dd   0x0
1050
  idleusesec		dd   0x0
1058
  idleusesec		dd   0x0
1051
  check_idle_semaphore	dd   0x0
1059
  check_idle_semaphore	dd   0x0
1052
endg
1060
endg
1053
 
1061
 
1054
 
1062
 
1055
 
1063
 
1056
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1064
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1057
;                                                                      ;
1065
;                                                                      ;
1058
;                   INCLUDED SYSTEM FILES                              ;
1066
;                   INCLUDED SYSTEM FILES                              ;
1059
;                                                                      ;
1067
;                                                                      ;
1060
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1068
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1061
 
1069
 
1062
 
1070
 
1063
include "kernel32.inc"
1071
include "kernel32.inc"
1064
 
1072
 
1065
 
1073
 
1066
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1074
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1067
;                                                                      ;
1075
;                                                                      ;
1068
;                       KERNEL FUNCTIONS                               ;
1076
;                       KERNEL FUNCTIONS                               ;
1069
;                                                                      ;
1077
;                                                                      ;
1070
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1078
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1071
 
1079
 
1072
reserve_irqs_ports:
1080
reserve_irqs_ports:
1073
 
1081
 
1074
	pushad
1082
	pushad
1075
 
1083
 
1076
	mov  [irq_owner+4*0], 1    ; timer
1084
	mov  [irq_owner+4*0], 1    ; timer
1077
	;mov  [irq_owner+4*1], 1    ; keyboard
1085
	;mov  [irq_owner+4*1], 1    ; keyboard
1078
	mov  [irq_owner+4*6], 1    ; floppy diskette
1086
	mov  [irq_owner+4*6], 1    ; floppy diskette
1079
	mov  [irq_owner+4*13], 1   ; math co-pros
1087
	mov  [irq_owner+4*13], 1   ; math co-pros
1080
	mov  [irq_owner+4*14], 1   ; ide I
1088
	mov  [irq_owner+4*14], 1   ; ide I
1081
	mov  [irq_owner+4*15], 1   ; ide II
1089
	mov  [irq_owner+4*15], 1   ; ide II
1082
 
1090
 
1083
	; RESERVE PORTS
1091
	; RESERVE PORTS
1084
	mov   edi,1		       ; 0x00-0x2d
1092
	mov   edi,1		       ; 0x00-0x2d
1085
	mov   [RESERVED_PORTS],edi
1093
	mov   [RESERVED_PORTS],edi
1086
	shl   edi,4
1094
	shl   edi,4
1087
	mov   [RESERVED_PORTS+edi+0],dword 1
1095
	mov   [RESERVED_PORTS+edi+0],dword 1
1088
	mov   [RESERVED_PORTS+edi+4],dword 0x0
1096
	mov   [RESERVED_PORTS+edi+4],dword 0x0
1089
	mov   [RESERVED_PORTS+edi+8],dword 0x2d
1097
	mov   [RESERVED_PORTS+edi+8],dword 0x2d
1090
 
1098
 
1091
	inc   dword [RESERVED_PORTS]	      ; 0x30-0x4d
1099
	inc   dword [RESERVED_PORTS]	      ; 0x30-0x4d
1092
	mov   edi,[RESERVED_PORTS]
1100
	mov   edi,[RESERVED_PORTS]
1093
	shl   edi,4
1101
	shl   edi,4
1094
	mov   [RESERVED_PORTS+edi+0],dword 1
1102
	mov   [RESERVED_PORTS+edi+0],dword 1
1095
	mov   [RESERVED_PORTS+edi+4],dword 0x30
1103
	mov   [RESERVED_PORTS+edi+4],dword 0x30
1096
	mov   [RESERVED_PORTS+edi+8],dword 0x4d
1104
	mov   [RESERVED_PORTS+edi+8],dword 0x4d
1097
 
1105
 
1098
	inc   dword [RESERVED_PORTS]	      ; 0x50-0xdf
1106
	inc   dword [RESERVED_PORTS]	      ; 0x50-0xdf
1099
	mov   edi,[RESERVED_PORTS]
1107
	mov   edi,[RESERVED_PORTS]
1100
	shl   edi,4
1108
	shl   edi,4
1101
	mov   [RESERVED_PORTS+edi+0],dword 1
1109
	mov   [RESERVED_PORTS+edi+0],dword 1
1102
	mov   [RESERVED_PORTS+edi+4],dword 0x50
1110
	mov   [RESERVED_PORTS+edi+4],dword 0x50
1103
	mov   [RESERVED_PORTS+edi+8],dword 0xdf
1111
	mov   [RESERVED_PORTS+edi+8],dword 0xdf
1104
 
1112
 
1105
	inc   dword [RESERVED_PORTS]	      ; 0xe5-0xff
1113
	inc   dword [RESERVED_PORTS]	      ; 0xe5-0xff
1106
	mov   edi,[RESERVED_PORTS]
1114
	mov   edi,[RESERVED_PORTS]
1107
	shl   edi,4
1115
	shl   edi,4
1108
	mov   [RESERVED_PORTS+edi+0],dword 1
1116
	mov   [RESERVED_PORTS+edi+0],dword 1
1109
	mov   [RESERVED_PORTS+edi+4],dword 0xe5
1117
	mov   [RESERVED_PORTS+edi+4],dword 0xe5
1110
	mov   [RESERVED_PORTS+edi+8],dword 0xff
1118
	mov   [RESERVED_PORTS+edi+8],dword 0xff
1111
 
1119
 
1112
	popad
1120
	popad
1113
	ret
1121
	ret
1114
 
1122
 
1115
setirqreadports:
1123
setirqreadports:
1116
 
1124
 
1117
	mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1125
	mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1118
	mov   [irq12read+4],dword 0		     ; end of port list
1126
	mov   [irq12read+4],dword 0		     ; end of port list
1119
	;mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1127
	;mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1120
	;mov   [irq04read+4],dword 0                  ; end of port list
1128
	;mov   [irq04read+4],dword 0                  ; end of port list
1121
	;mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1129
	;mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1122
	;mov   [irq03read+4],dword 0                  ; end of port list
1130
	;mov   [irq03read+4],dword 0                  ; end of port list
1123
 
1131
 
1124
	ret
1132
	ret
1125
 
1133
 
1126
iglobal
1134
iglobal
1127
  process_number dd 0x1
1135
  process_number dd 0x1
1128
endg
1136
endg
1129
 
1137
 
1130
set_variables:
1138
set_variables:
1131
 
1139
 
1132
        mov   ecx,0x100                          ; flush port 0x60
1140
        mov   ecx,0x100                          ; flush port 0x60
1133
.fl60:	in    al,0x60
1141
.fl60:	in    al,0x60
1134
	loop  .fl60
1142
	loop  .fl60
1135
        mov   [MOUSE_BUFF_COUNT],byte 0          ; mouse buffer
1143
        mov   [MOUSE_BUFF_COUNT],byte 0          ; mouse buffer
1136
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
1144
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
1137
        mov   [BTN_COUNT],byte 0                 ; button buffer
1145
        mov   [BTN_COUNT],byte 0                 ; button buffer
1138
;        mov   [MOUSE_X],dword 100*65536+100     ; mouse x/y
1146
;        mov   [MOUSE_X],dword 100*65536+100     ; mouse x/y
1139
 
1147
 
1140
	push  eax
1148
	push  eax
1141
	mov   ax,[BOOT_VAR+0x900c]
1149
	mov   ax,[BOOT_VAR+0x900c]
1142
	shr   ax,1
1150
	shr   ax,1
1143
	shl   eax,16
1151
	shl   eax,16
1144
	mov   ax,[BOOT_VAR+0x900A]
1152
	mov   ax,[BOOT_VAR+0x900A]
1145
	shr   ax,1
1153
	shr   ax,1
1146
	mov   [MOUSE_X],eax
1154
	mov   [MOUSE_X],eax
1147
	pop   eax
1155
	pop   eax
1148
 
1156
 
1149
        mov   [BTN_ADDR],dword BUTTON_INFO       ; address of button list
1157
        mov   [BTN_ADDR],dword BUTTON_INFO       ; address of button list
1150
 
1158
 
1151
     ;!! IP 04.02.2005:
1159
     ;!! IP 04.02.2005:
1152
	mov   [next_usage_update], 100
1160
	mov   [next_usage_update], 100
1153
        mov   byte [DONT_SWITCH], 0              ; change task if possible
1161
        mov   byte [DONT_SWITCH], 0              ; change task if possible
1154
 
1162
 
1155
	ret
1163
	ret
1156
 
1164
 
1157
;* mouse centered - start code- Mario79
1165
;* mouse centered - start code- Mario79
1158
mouse_centered:
1166
mouse_centered:
1159
	push  eax
1167
	push  eax
1160
	mov   eax,[Screen_Max_X]
1168
	mov   eax,[Screen_Max_X]
1161
	shr   eax,1
1169
	shr   eax,1
1162
	mov   [MOUSE_X],ax
1170
	mov   [MOUSE_X],ax
1163
	mov   eax,[Screen_Max_Y]
1171
	mov   eax,[Screen_Max_Y]
1164
	shr   eax,1
1172
	shr   eax,1
1165
	mov   [MOUSE_Y],ax
1173
	mov   [MOUSE_Y],ax
1166
	pop   eax
1174
	pop   eax
1167
	ret
1175
	ret
1168
;* mouse centered - end code- Mario79
1176
;* mouse centered - end code- Mario79
1169
 
1177
 
1170
align 4
1178
align 4
1171
 
1179
 
1172
sys_outport:
1180
sys_outport:
1173
 
1181
 
1174
    mov   edi,ebx	   ; separate flag for read / write
1182
    mov   edi,ebx	   ; separate flag for read / write
1175
    and   ebx,65535
1183
    and   ebx,65535
1176
 
1184
 
1177
    mov   ecx,[RESERVED_PORTS]
1185
    mov   ecx,[RESERVED_PORTS]
1178
    test  ecx,ecx
1186
    test  ecx,ecx
1179
    jne   sopl8
1187
    jne   sopl8
1180
    mov   [esp+36],dword 1
1188
    mov   [esp+36],dword 1
1181
    ret
1189
    ret
1182
 
1190
 
1183
  sopl8:
1191
  sopl8:
1184
    mov   edx,[TASK_BASE]
1192
    mov   edx,[TASK_BASE]
1185
    mov   edx,[edx+0x4]
1193
    mov   edx,[edx+0x4]
1186
    and   ebx,65535
1194
    and   ebx,65535
1187
    cld
1195
    cld
1188
  sopl1:
1196
  sopl1:
1189
 
1197
 
1190
    mov   esi,ecx
1198
    mov   esi,ecx
1191
    shl   esi,4
1199
    shl   esi,4
1192
    add   esi,RESERVED_PORTS
1200
    add   esi,RESERVED_PORTS
1193
    cmp   edx,[esi+0]
1201
    cmp   edx,[esi+0]
1194
    jne   sopl2
1202
    jne   sopl2
1195
    cmp   ebx,[esi+4]
1203
    cmp   ebx,[esi+4]
1196
    jb	  sopl2
1204
    jb	  sopl2
1197
    cmp   ebx,[esi+8]
1205
    cmp   ebx,[esi+8]
1198
    jg	  sopl2
1206
    jg	  sopl2
1199
    jmp   sopl3
1207
    jmp   sopl3
1200
 
1208
 
1201
  sopl2:
1209
  sopl2:
1202
 
1210
 
1203
    dec   ecx
1211
    dec   ecx
1204
    jnz   sopl1
1212
    jnz   sopl1
1205
    mov   [esp+36],dword 1
1213
    mov   [esp+36],dword 1
1206
    ret
1214
    ret
1207
 
1215
 
1208
  sopl3:
1216
  sopl3:
1209
 
1217
 
1210
    test  edi,0x80000000 ; read ?
1218
    test  edi,0x80000000 ; read ?
1211
    jnz   sopl4
1219
    jnz   sopl4
1212
 
1220
 
1213
    mov   dx,bx 	 ; write
1221
    mov   dx,bx 	 ; write
1214
    out   dx,al
1222
    out   dx,al
1215
    mov   [esp+36],dword 0
1223
    mov   [esp+36],dword 0
1216
    ret
1224
    ret
1217
 
1225
 
1218
  sopl4:
1226
  sopl4:
1219
 
1227
 
1220
    mov   dx,bx 	 ; read
1228
    mov   dx,bx 	 ; read
1221
    in	  al,dx
1229
    in	  al,dx
1222
    and   eax,0xff
1230
    and   eax,0xff
1223
    mov   [esp+36],dword 0
1231
    mov   [esp+36],dword 0
1224
    mov   [esp+24],eax
1232
    mov   [esp+24],eax
1225
    ret
1233
    ret
1226
 
1234
 
1227
display_number:
1235
display_number:
1228
 
1236
 
1229
; eax = print type, al=0 -> ebx is number
1237
; eax = print type, al=0 -> ebx is number
1230
;                   al=1 -> ebx is pointer
1238
;                   al=1 -> ebx is pointer
1231
;                   ah=0 -> display decimal
1239
;                   ah=0 -> display decimal
1232
;                   ah=1 -> display hexadecimal
1240
;                   ah=1 -> display hexadecimal
1233
;                   ah=2 -> display binary
1241
;                   ah=2 -> display binary
1234
;                   eax bits 16-21 = number of digits to display (0-32)
1242
;                   eax bits 16-21 = number of digits to display (0-32)
1235
;                   eax bits 22-31 = reserved
1243
;                   eax bits 22-31 = reserved
1236
;
1244
;
1237
; ebx = number or pointer
1245
; ebx = number or pointer
1238
; ecx = x shl 16 + y
1246
; ecx = x shl 16 + y
1239
; edx = color
1247
; edx = color
1240
	xor	edi, edi
1248
	xor	edi, edi
1241
display_number_force:
1249
display_number_force:
1242
     push  eax
1250
     push  eax
1243
     and   eax,0x3fffffff
1251
     and   eax,0x3fffffff
1244
     cmp   eax,0xffff		 ; length > 0 ?
1252
     cmp   eax,0xffff		 ; length > 0 ?
1245
     pop   eax
1253
     pop   eax
1246
     jge   cont_displ
1254
     jge   cont_displ
1247
     ret
1255
     ret
1248
   cont_displ:
1256
   cont_displ:
1249
     push  eax
1257
     push  eax
1250
     and   eax,0x3fffffff
1258
     and   eax,0x3fffffff
1251
     cmp   eax,61*0x10000	 ; length <= 60 ?
1259
     cmp   eax,61*0x10000	 ; length <= 60 ?
1252
     pop   eax
1260
     pop   eax
1253
     jb    cont_displ2
1261
     jb    cont_displ2
1254
     ret
1262
     ret
1255
   cont_displ2:
1263
   cont_displ2:
1256
 
1264
 
1257
     pushad
1265
     pushad
1258
 
1266
 
1259
     cmp   al,1 		 ; ecx is a pointer ?
1267
     cmp   al,1 		 ; ecx is a pointer ?
1260
     jne   displnl1
1268
     jne   displnl1
1261
     mov   ebp,ebx
1269
     mov   ebp,ebx
1262
     add   ebp,4
1270
     add   ebp,4
1263
     mov   ebp,[ebp]
1271
     mov   ebp,[ebp]
1264
     mov   ebx,[ebx]
1272
     mov   ebx,[ebx]
1265
   displnl1:
1273
   displnl1:
1266
     sub   esp,64
1274
     sub   esp,64
1267
 
1275
 
1268
     cmp   ah,0 		 ; DECIMAL
1276
     cmp   ah,0 		 ; DECIMAL
1269
     jne   no_display_desnum
1277
     jne   no_display_desnum
1270
     shr   eax,16
1278
     shr   eax,16
1271
     and   eax,0xC03f
1279
     and   eax,0xC03f
1272
;     and   eax,0x3f
1280
;     and   eax,0x3f
1273
     push  eax
1281
     push  eax
1274
     and   eax,0x3f
1282
     and   eax,0x3f
1275
     mov   edi,esp
1283
     mov   edi,esp
1276
     add   edi,4+64-1
1284
     add   edi,4+64-1
1277
     mov   ecx,eax
1285
     mov   ecx,eax
1278
     mov   eax,ebx
1286
     mov   eax,ebx
1279
     mov   ebx,10
1287
     mov   ebx,10
1280
   d_desnum:
1288
   d_desnum:
1281
     xor   edx,edx
1289
     xor   edx,edx
1282
     call  division_64_bits
1290
     call  division_64_bits
1283
     div   ebx
1291
     div   ebx
1284
     add   dl,48
1292
     add   dl,48
1285
     mov   [edi],dl
1293
     mov   [edi],dl
1286
     dec   edi
1294
     dec   edi
1287
     loop  d_desnum
1295
     loop  d_desnum
1288
     pop   eax
1296
     pop   eax
1289
     call  normalize_number
1297
     call  normalize_number
1290
     call  draw_num_text
1298
     call  draw_num_text
1291
     add   esp,64
1299
     add   esp,64
1292
     popad
1300
     popad
1293
     ret
1301
     ret
1294
   no_display_desnum:
1302
   no_display_desnum:
1295
 
1303
 
1296
     cmp   ah,0x01		 ; HEXADECIMAL
1304
     cmp   ah,0x01		 ; HEXADECIMAL
1297
     jne   no_display_hexnum
1305
     jne   no_display_hexnum
1298
     shr   eax,16
1306
     shr   eax,16
1299
     and   eax,0xC03f
1307
     and   eax,0xC03f
1300
;     and   eax,0x3f
1308
;     and   eax,0x3f
1301
     push  eax
1309
     push  eax
1302
     and   eax,0x3f
1310
     and   eax,0x3f
1303
     mov   edi,esp
1311
     mov   edi,esp
1304
     add   edi,4+64-1
1312
     add   edi,4+64-1
1305
     mov   ecx,eax
1313
     mov   ecx,eax
1306
     mov   eax,ebx
1314
     mov   eax,ebx
1307
     mov   ebx,16
1315
     mov   ebx,16
1308
   d_hexnum:
1316
   d_hexnum:
1309
     xor   edx,edx
1317
     xor   edx,edx
1310
     call  division_64_bits
1318
     call  division_64_bits
1311
     div   ebx
1319
     div   ebx
1312
     add   edx,hexletters
1320
     add   edx,hexletters
1313
     mov   dl,[edx]
1321
     mov   dl,[edx]
1314
     mov   [edi],dl
1322
     mov   [edi],dl
1315
     dec   edi
1323
     dec   edi
1316
     loop  d_hexnum
1324
     loop  d_hexnum
1317
     pop   eax
1325
     pop   eax
1318
     call  normalize_number
1326
     call  normalize_number
1319
     call  draw_num_text
1327
     call  draw_num_text
1320
     add   esp,64
1328
     add   esp,64
1321
     popad
1329
     popad
1322
     ret
1330
     ret
1323
   no_display_hexnum:
1331
   no_display_hexnum:
1324
 
1332
 
1325
     cmp   ah,0x02		 ; BINARY
1333
     cmp   ah,0x02		 ; BINARY
1326
     jne   no_display_binnum
1334
     jne   no_display_binnum
1327
     shr   eax,16
1335
     shr   eax,16
1328
     and   eax,0xC03f
1336
     and   eax,0xC03f
1329
;     and   eax,0x3f
1337
;     and   eax,0x3f
1330
     push  eax
1338
     push  eax
1331
     and   eax,0x3f
1339
     and   eax,0x3f
1332
     mov   edi,esp
1340
     mov   edi,esp
1333
     add   edi,4+64-1
1341
     add   edi,4+64-1
1334
     mov   ecx,eax
1342
     mov   ecx,eax
1335
     mov   eax,ebx
1343
     mov   eax,ebx
1336
     mov   ebx,2
1344
     mov   ebx,2
1337
   d_binnum:
1345
   d_binnum:
1338
     xor   edx,edx
1346
     xor   edx,edx
1339
     call  division_64_bits
1347
     call  division_64_bits
1340
     div   ebx
1348
     div   ebx
1341
     add   dl,48
1349
     add   dl,48
1342
     mov   [edi],dl
1350
     mov   [edi],dl
1343
     dec   edi
1351
     dec   edi
1344
     loop  d_binnum
1352
     loop  d_binnum
1345
     pop   eax
1353
     pop   eax
1346
     call  normalize_number
1354
     call  normalize_number
1347
     call  draw_num_text
1355
     call  draw_num_text
1348
     add   esp,64
1356
     add   esp,64
1349
     popad
1357
     popad
1350
     ret
1358
     ret
1351
   no_display_binnum:
1359
   no_display_binnum:
1352
 
1360
 
1353
     add   esp,64
1361
     add   esp,64
1354
     popad
1362
     popad
1355
     ret
1363
     ret
1356
 
1364
 
1357
normalize_number:
1365
normalize_number:
1358
     test  ah,0x80
1366
     test  ah,0x80
1359
     jz   .continue
1367
     jz   .continue
1360
     mov  ecx,48
1368
     mov  ecx,48
1361
     and   eax,0x3f
1369
     and   eax,0x3f
1362
@@:
1370
@@:
1363
     inc   edi
1371
     inc   edi
1364
     cmp   [edi],cl
1372
     cmp   [edi],cl
1365
     jne   .continue
1373
     jne   .continue
1366
     dec   eax
1374
     dec   eax
1367
     cmp   eax,1
1375
     cmp   eax,1
1368
     ja    @r
1376
     ja    @r
1369
     mov   al,1
1377
     mov   al,1
1370
.continue:
1378
.continue:
1371
     and   eax,0x3f
1379
     and   eax,0x3f
1372
     ret
1380
     ret
1373
 
1381
 
1374
division_64_bits:
1382
division_64_bits:
1375
     test  [esp+1+4],byte 0x40
1383
     test  [esp+1+4],byte 0x40
1376
     jz   .continue
1384
     jz   .continue
1377
     push  eax
1385
     push  eax
1378
     mov   eax,ebp
1386
     mov   eax,ebp
1379
     div   ebx
1387
     div   ebx
1380
     mov   ebp,eax
1388
     mov   ebp,eax
1381
     pop   eax
1389
     pop   eax
1382
.continue:
1390
.continue:
1383
     ret
1391
     ret
1384
 
1392
 
1385
draw_num_text:
1393
draw_num_text:
1386
     mov   esi,eax
1394
     mov   esi,eax
1387
     mov   edx,64+4
1395
     mov   edx,64+4
1388
     sub   edx,eax
1396
     sub   edx,eax
1389
     add   edx,esp
1397
     add   edx,esp
1390
     mov   ebx,[esp+64+32-8+4]
1398
     mov   ebx,[esp+64+32-8+4]
1391
; add window start x & y
1399
; add window start x & y
1392
     mov   ecx,[TASK_BASE]
1400
     mov   ecx,[TASK_BASE]
1393
 
1401
 
1394
     mov   edi,[CURRENT_TASK]
1402
     mov   edi,[CURRENT_TASK]
1395
     shl   edi,8
1403
     shl   edi,8
1396
 
1404
 
1397
     mov   eax,[ecx-twdw+WDATA.box.left]
1405
     mov   eax,[ecx-twdw+WDATA.box.left]
1398
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1406
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1399
     shl   eax,16
1407
     shl   eax,16
1400
     add   eax,[ecx-twdw+WDATA.box.top]
1408
     add   eax,[ecx-twdw+WDATA.box.top]
1401
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1409
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1402
     add   ebx,eax
1410
     add   ebx,eax
1403
     mov   ecx,[esp+64+32-12+4]
1411
     mov   ecx,[esp+64+32-12+4]
1404
	and	ecx, not 0x80000000	; force counted string
1412
	and	ecx, not 0x80000000	; force counted string
1405
	mov	eax, [esp+64+8] 	; background color (if given)
1413
	mov	eax, [esp+64+8] 	; background color (if given)
1406
	mov	edi, [esp+64+4]
1414
	mov	edi, [esp+64+4]
1407
     jmp   dtext
1415
     jmp   dtext
1408
 
1416
 
1409
align 4
1417
align 4
1410
 
1418
 
1411
sys_setup:
1419
sys_setup:
1412
 
1420
 
1413
; 1=roland mpu midi base , base io address
1421
; 1=roland mpu midi base , base io address
1414
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1422
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1415
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1423
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1416
; 5=system language, 1eng 2fi 3ger 4rus
1424
; 5=system language, 1eng 2fi 3ger 4rus
1417
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1425
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1418
; 8=fat32 partition in hd
1426
; 8=fat32 partition in hd
1419
; 9
1427
; 9
1420
; 10 = sound dma channel
1428
; 10 = sound dma channel
1421
; 11 = enable lba read
1429
; 11 = enable lba read
1422
; 12 = enable pci access
1430
; 12 = enable pci access
1423
 
1431
 
1424
 
1432
 
1425
     mov  [esp+36],dword 0
1433
     mov  [esp+36],dword 0
1426
     cmp  eax,1 		     ; MIDI
1434
     cmp  eax,1 		     ; MIDI
1427
     jnz  nsyse1
1435
     jnz  nsyse1
1428
     cmp  ebx,0x100
1436
     cmp  ebx,0x100
1429
     jb   nsyse1
1437
     jb   nsyse1
1430
     mov  edx,65535
1438
     mov  edx,65535
1431
     cmp  edx,ebx
1439
     cmp  edx,ebx
1432
     jb   nsyse1
1440
     jb   nsyse1
1433
     mov  [midi_base],bx
1441
     mov  [midi_base],bx
1434
     mov  word [mididp],bx
1442
     mov  word [mididp],bx
1435
     inc  bx
1443
     inc  bx
1436
     mov  word [midisp],bx
1444
     mov  word [midisp],bx
1437
     ret
1445
     ret
1438
 
1446
 
1439
iglobal
1447
iglobal
1440
midi_base dw 0
1448
midi_base dw 0
1441
endg
1449
endg
1442
 
1450
 
1443
   nsyse1:
1451
   nsyse1:
1444
 
1452
 
1445
     cmp  eax,2 		     ; KEYBOARD
1453
     cmp  eax,2 		     ; KEYBOARD
1446
     jnz  nsyse2
1454
     jnz  nsyse2
1447
     cmp  ebx,1
1455
     cmp  ebx,1
1448
     jnz  kbnobase
1456
     jnz  kbnobase
1449
     mov  edi,[TASK_BASE]
1457
     mov  edi,[TASK_BASE]
1450
     add  ecx,[edi+TASKDATA.mem_start]
1458
     add  ecx,[edi+TASKDATA.mem_start]
1451
     mov  eax,ecx
1459
     mov  eax,ecx
1452
     mov  ebx,keymap
1460
     mov  ebx,keymap
1453
     mov  ecx,128
1461
     mov  ecx,128
1454
     call memmove
1462
     call memmove
1455
     ret
1463
     ret
1456
   kbnobase:
1464
   kbnobase:
1457
     cmp  ebx,2
1465
     cmp  ebx,2
1458
     jnz  kbnoshift
1466
     jnz  kbnoshift
1459
     mov  edi,[TASK_BASE]
1467
     mov  edi,[TASK_BASE]
1460
     add  ecx,[edi+TASKDATA.mem_start]
1468
     add  ecx,[edi+TASKDATA.mem_start]
1461
     mov  eax,ecx
1469
     mov  eax,ecx
1462
     mov  ebx,keymap_shift
1470
     mov  ebx,keymap_shift
1463
     mov  ecx,128
1471
     mov  ecx,128
1464
     call memmove
1472
     call memmove
1465
     ret
1473
     ret
1466
   kbnoshift:
1474
   kbnoshift:
1467
     cmp  ebx,3
1475
     cmp  ebx,3
1468
     jne  kbnoalt
1476
     jne  kbnoalt
1469
     mov  edi,[TASK_BASE]
1477
     mov  edi,[TASK_BASE]
1470
     add  ecx,[edi+TASKDATA.mem_start]
1478
     add  ecx,[edi+TASKDATA.mem_start]
1471
     mov  eax,ecx
1479
     mov  eax,ecx
1472
     mov  ebx,keymap_alt
1480
     mov  ebx,keymap_alt
1473
     mov  ecx,128
1481
     mov  ecx,128
1474
     call memmove
1482
     call memmove
1475
     ret
1483
     ret
1476
   kbnoalt:
1484
   kbnoalt:
1477
     cmp  ebx,9
1485
     cmp  ebx,9
1478
     jnz  kbnocountry
1486
     jnz  kbnocountry
1479
     mov  word [keyboard],cx
1487
     mov  word [keyboard],cx
1480
     ret
1488
     ret
1481
   kbnocountry:
1489
   kbnocountry:
1482
     mov  [esp+36],dword 1
1490
     mov  [esp+36],dword 1
1483
     ret
1491
     ret
1484
   nsyse2:
1492
   nsyse2:
1485
     cmp  eax,3 		     ; CD
1493
     cmp  eax,3 		     ; CD
1486
     jnz  nsyse4
1494
     jnz  nsyse4
1487
     test ebx,ebx
1495
     test ebx,ebx
1488
     jz   nosesl
1496
     jz   nosesl
1489
     cmp  ebx, 4
1497
     cmp  ebx, 4
1490
     ja   nosesl
1498
     ja   nosesl
1491
     mov  [cd_base],bl
1499
     mov  [cd_base],bl
1492
     cmp  ebx,1
1500
     cmp  ebx,1
1493
     jnz  noprma
1501
     jnz  noprma
1494
     mov  [cdbase],0x1f0
1502
     mov  [cdbase],0x1f0
1495
     mov  [cdid],0xa0
1503
     mov  [cdid],0xa0
1496
   noprma:
1504
   noprma:
1497
     cmp  ebx,2
1505
     cmp  ebx,2
1498
     jnz  noprsl
1506
     jnz  noprsl
1499
     mov  [cdbase],0x1f0
1507
     mov  [cdbase],0x1f0
1500
     mov  [cdid],0xb0
1508
     mov  [cdid],0xb0
1501
   noprsl:
1509
   noprsl:
1502
     cmp  ebx,3
1510
     cmp  ebx,3
1503
     jnz  nosema
1511
     jnz  nosema
1504
     mov  [cdbase],0x170
1512
     mov  [cdbase],0x170
1505
     mov  [cdid],0xa0
1513
     mov  [cdid],0xa0
1506
   nosema:
1514
   nosema:
1507
     cmp  ebx,4
1515
     cmp  ebx,4
1508
     jnz  nosesl
1516
     jnz  nosesl
1509
     mov  [cdbase],0x170
1517
     mov  [cdbase],0x170
1510
     mov  [cdid],0xb0
1518
     mov  [cdid],0xb0
1511
   nosesl:
1519
   nosesl:
1512
     ret
1520
     ret
1513
 
1521
 
1514
cd_base db 0
1522
cd_base db 0
1515
 
1523
 
1516
   nsyse4:
1524
   nsyse4:
1517
 
1525
 
1518
     cmp  eax,5 		     ; SYSTEM LANGUAGE
1526
     cmp  eax,5 		     ; SYSTEM LANGUAGE
1519
     jnz  nsyse5
1527
     jnz  nsyse5
1520
     mov  [syslang],ebx
1528
     mov  [syslang],ebx
1521
     ret
1529
     ret
1522
   nsyse5:
1530
   nsyse5:
1523
 
1531
 
1524
     cmp  eax,7 		     ; HD BASE
1532
     cmp  eax,7 		     ; HD BASE
1525
     jne  nsyse7
1533
     jne  nsyse7
1526
     test ebx,ebx
1534
     test ebx,ebx
1527
     jz   nosethd
1535
     jz   nosethd
1528
     cmp  ebx,4
1536
     cmp  ebx,4
1529
     ja   nosethd
1537
     ja   nosethd
1530
     mov  [hd_base],bl
1538
     mov  [hd_base],bl
1531
     cmp  ebx,1
1539
     cmp  ebx,1
1532
     jnz  noprmahd
1540
     jnz  noprmahd
1533
     mov  [hdbase],0x1f0
1541
     mov  [hdbase],0x1f0
1534
     mov  [hdid],0x0
1542
     mov  [hdid],0x0
1535
     mov  [hdpos],1
1543
     mov  [hdpos],1
1536
;     call set_FAT32_variables
1544
;     call set_FAT32_variables
1537
   noprmahd:
1545
   noprmahd:
1538
     cmp  ebx,2
1546
     cmp  ebx,2
1539
     jnz  noprslhd
1547
     jnz  noprslhd
1540
     mov  [hdbase],0x1f0
1548
     mov  [hdbase],0x1f0
1541
     mov  [hdid],0x10
1549
     mov  [hdid],0x10
1542
     mov  [hdpos],2
1550
     mov  [hdpos],2
1543
;     call set_FAT32_variables
1551
;     call set_FAT32_variables
1544
   noprslhd:
1552
   noprslhd:
1545
     cmp  ebx,3
1553
     cmp  ebx,3
1546
     jnz  nosemahd
1554
     jnz  nosemahd
1547
     mov  [hdbase],0x170
1555
     mov  [hdbase],0x170
1548
     mov  [hdid],0x0
1556
     mov  [hdid],0x0
1549
     mov  [hdpos],3
1557
     mov  [hdpos],3
1550
;     call set_FAT32_variables
1558
;     call set_FAT32_variables
1551
   nosemahd:
1559
   nosemahd:
1552
     cmp  ebx,4
1560
     cmp  ebx,4
1553
     jnz  noseslhd
1561
     jnz  noseslhd
1554
     mov  [hdbase],0x170
1562
     mov  [hdbase],0x170
1555
     mov  [hdid],0x10
1563
     mov  [hdid],0x10
1556
     mov  [hdpos],4
1564
     mov  [hdpos],4
1557
;     call set_FAT32_variables
1565
;     call set_FAT32_variables
1558
   noseslhd:
1566
   noseslhd:
1559
    call  reserve_hd1
1567
    call  reserve_hd1
1560
    call  reserve_hd_channel
1568
    call  reserve_hd_channel
1561
    call  free_hd_channel
1569
    call  free_hd_channel
1562
    mov   [hd1_status],0	; free
1570
    mov   [hd1_status],0	; free
1563
   nosethd:
1571
   nosethd:
1564
     ret
1572
     ret
1565
 
1573
 
1566
iglobal
1574
iglobal
1567
hd_base db 0
1575
hd_base db 0
1568
endg
1576
endg
1569
 
1577
 
1570
nsyse7:
1578
nsyse7:
1571
 
1579
 
1572
     cmp  eax,8 		     ; HD PARTITION
1580
     cmp  eax,8 		     ; HD PARTITION
1573
     jne  nsyse8
1581
     jne  nsyse8
1574
     mov  [fat32part],ebx
1582
     mov  [fat32part],ebx
1575
;     call set_FAT32_variables
1583
;     call set_FAT32_variables
1576
    call  reserve_hd1
1584
    call  reserve_hd1
1577
    call  reserve_hd_channel
1585
    call  reserve_hd_channel
1578
    call  free_hd_channel
1586
    call  free_hd_channel
1579
     pusha
1587
     pusha
1580
     call  choice_necessity_partition_1
1588
     call  choice_necessity_partition_1
1581
     popa
1589
     popa
1582
    mov   [hd1_status],0	; free
1590
    mov   [hd1_status],0	; free
1583
     ret
1591
     ret
1584
 
1592
 
1585
nsyse8:
1593
nsyse8:
1586
     cmp  eax,11		     ; ENABLE LBA READ
1594
     cmp  eax,11		     ; ENABLE LBA READ
1587
     jne  no_set_lba_read
1595
     jne  no_set_lba_read
1588
     and  ebx,1
1596
     and  ebx,1
1589
     mov  [lba_read_enabled],ebx
1597
     mov  [lba_read_enabled],ebx
1590
     ret
1598
     ret
1591
 
1599
 
1592
no_set_lba_read:
1600
no_set_lba_read:
1593
     cmp  eax,12                     ; ENABLE PCI ACCESS
1601
     cmp  eax,12                     ; ENABLE PCI ACCESS
1594
     jne  no_set_pci_access
1602
     jne  no_set_pci_access
1595
     and  ebx,1
1603
     and  ebx,1
1596
     mov  [pci_access_enabled],ebx
1604
     mov  [pci_access_enabled],ebx
1597
     ret
1605
     ret
1598
   no_set_pci_access:
1606
   no_set_pci_access:
1599
 
1607
 
1600
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1608
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1601
include 'vmodeint.inc'
1609
include 'vmodeint.inc'
1602
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1610
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1603
 
1611
 
1604
sys_setup_err:
1612
sys_setup_err:
1605
     mov  [esp+36],dword -1
1613
     mov  [esp+36],dword -1
1606
     ret
1614
     ret
1607
 
1615
 
1608
align 4
1616
align 4
1609
 
1617
 
1610
sys_getsetup:
1618
sys_getsetup:
1611
 
1619
 
1612
; 1=roland mpu midi base , base io address
1620
; 1=roland mpu midi base , base io address
1613
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1621
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1614
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1622
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1615
; 5=system language, 1eng 2fi 3ger 4rus
1623
; 5=system language, 1eng 2fi 3ger 4rus
1616
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1624
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1617
; 8=fat32 partition in hd
1625
; 8=fat32 partition in hd
1618
; 9=get hs timer tic
1626
; 9=get hs timer tic
1619
 
1627
 
1620
     cmp  eax,1
1628
     cmp  eax,1
1621
     jne  ngsyse1
1629
     jne  ngsyse1
1622
     movzx eax,[midi_base]
1630
     movzx eax,[midi_base]
1623
     mov  [esp+36],eax
1631
     mov  [esp+36],eax
1624
     ret
1632
     ret
1625
ngsyse1:
1633
ngsyse1:
1626
 
1634
 
1627
     cmp  eax,2
1635
     cmp  eax,2
1628
     jne  ngsyse2
1636
     jne  ngsyse2
1629
     cmp  ebx,1
1637
     cmp  ebx,1
1630
     jnz  kbnobaseret
1638
     jnz  kbnobaseret
1631
     mov  edi,[TASK_BASE]
1639
     mov  edi,[TASK_BASE]
1632
     add  ecx,[edi+TASKDATA.mem_start]
1640
     add  ecx,[edi+TASKDATA.mem_start]
1633
     mov  ebx,ecx
1641
     mov  ebx,ecx
1634
     mov  eax,keymap
1642
     mov  eax,keymap
1635
     mov  ecx,128
1643
     mov  ecx,128
1636
     call memmove
1644
     call memmove
1637
     ret
1645
     ret
1638
kbnobaseret:
1646
kbnobaseret:
1639
     cmp  ebx,2
1647
     cmp  ebx,2
1640
     jnz  kbnoshiftret
1648
     jnz  kbnoshiftret
1641
     mov  edi,[TASK_BASE]
1649
     mov  edi,[TASK_BASE]
1642
     add  ecx,[edi+TASKDATA.mem_start]
1650
     add  ecx,[edi+TASKDATA.mem_start]
1643
     mov  ebx,ecx
1651
     mov  ebx,ecx
1644
     mov  eax,keymap_shift
1652
     mov  eax,keymap_shift
1645
     mov  ecx,128
1653
     mov  ecx,128
1646
     call memmove
1654
     call memmove
1647
     ret
1655
     ret
1648
kbnoshiftret:
1656
kbnoshiftret:
1649
     cmp  ebx,3
1657
     cmp  ebx,3
1650
     jne  kbnoaltret
1658
     jne  kbnoaltret
1651
     mov  edi,[TASK_BASE]
1659
     mov  edi,[TASK_BASE]
1652
     add  ecx,[edi+TASKDATA.mem_start]
1660
     add  ecx,[edi+TASKDATA.mem_start]
1653
     mov  ebx,ecx
1661
     mov  ebx,ecx
1654
     mov  eax,keymap_alt
1662
     mov  eax,keymap_alt
1655
     mov  ecx,128
1663
     mov  ecx,128
1656
     call memmove
1664
     call memmove
1657
     ret
1665
     ret
1658
kbnoaltret:
1666
kbnoaltret:
1659
     cmp  ebx,9
1667
     cmp  ebx,9
1660
     jnz  ngsyse2
1668
     jnz  ngsyse2
1661
     movzx eax,word [keyboard]
1669
     movzx eax,word [keyboard]
1662
     mov  [esp+36],eax
1670
     mov  [esp+36],eax
1663
     ret
1671
     ret
1664
ngsyse2:
1672
ngsyse2:
1665
 
1673
 
1666
         cmp  eax,3
1674
         cmp  eax,3
1667
         jnz  ngsyse3
1675
         jnz  ngsyse3
1668
         movzx eax,[cd_base]
1676
         movzx eax,[cd_base]
1669
         mov  [esp+36],eax
1677
         mov  [esp+36],eax
1670
         ret
1678
         ret
1671
ngsyse3:
1679
ngsyse3:
1672
         cmp  eax,5
1680
         cmp  eax,5
1673
         jnz  ngsyse5
1681
         jnz  ngsyse5
1674
         mov  eax,[syslang]
1682
         mov  eax,[syslang]
1675
         mov  [esp+36],eax
1683
         mov  [esp+36],eax
1676
         ret
1684
         ret
1677
ngsyse5:
1685
ngsyse5:
1678
     cmp  eax,7
1686
     cmp  eax,7
1679
     jnz  ngsyse7
1687
     jnz  ngsyse7
1680
     movzx eax,[hd_base]
1688
     movzx eax,[hd_base]
1681
     mov  [esp+36],eax
1689
     mov  [esp+36],eax
1682
     ret
1690
     ret
1683
ngsyse7:
1691
ngsyse7:
1684
     cmp  eax,8
1692
     cmp  eax,8
1685
     jnz  ngsyse8
1693
     jnz  ngsyse8
1686
     mov eax,[fat32part]
1694
     mov eax,[fat32part]
1687
     mov  [esp+36],eax
1695
     mov  [esp+36],eax
1688
     ret
1696
     ret
1689
ngsyse8:
1697
ngsyse8:
1690
     cmp  eax,9
1698
     cmp  eax,9
1691
     jne  ngsyse9
1699
     jne  ngsyse9
1692
     mov  eax,[timer_ticks] ;[0xfdf0]
1700
     mov  eax,[timer_ticks] ;[0xfdf0]
1693
     mov  [esp+36],eax
1701
     mov  [esp+36],eax
1694
     ret
1702
     ret
1695
ngsyse9:
1703
ngsyse9:
1696
     cmp  eax,11
1704
     cmp  eax,11
1697
     jnz  ngsyse11
1705
     jnz  ngsyse11
1698
     mov eax,[lba_read_enabled]
1706
     mov eax,[lba_read_enabled]
1699
     mov  [esp+36],eax
1707
     mov  [esp+36],eax
1700
     ret
1708
     ret
1701
ngsyse11:
1709
ngsyse11:
1702
     cmp  eax,12
1710
     cmp  eax,12
1703
     jnz  ngsyse12
1711
     jnz  ngsyse12
1704
     mov eax,[pci_access_enabled]
1712
     mov eax,[pci_access_enabled]
1705
     mov  [esp+36],eax
1713
     mov  [esp+36],eax
1706
     ret
1714
     ret
1707
ngsyse12:
1715
ngsyse12:
1708
     mov  [esp+36],dword 1
1716
     mov  [esp+36],dword 1
1709
     ret
1717
     ret
1710
 
1718
 
1711
get_timer_ticks:
1719
get_timer_ticks:
1712
    mov eax,[timer_ticks]
1720
    mov eax,[timer_ticks]
1713
    ret
1721
    ret
1714
 
1722
 
1715
iglobal
1723
iglobal
1716
align 4
1724
align 4
1717
mousefn dd msscreen, mswin, msbutton, msset
1725
mousefn dd msscreen, mswin, msbutton, msset
1718
	dd app_load_cursor
1726
	dd app_load_cursor
1719
	dd app_set_cursor
1727
	dd app_set_cursor
1720
	dd app_delete_cursor
1728
	dd app_delete_cursor
1721
	dd msz
1729
	dd msz
1722
endg
1730
endg
1723
 
1731
 
1724
readmousepos:
1732
readmousepos:
1725
 
1733
 
1726
; eax=0 screen relative
1734
; eax=0 screen relative
1727
; eax=1 window relative
1735
; eax=1 window relative
1728
; eax=2 buttons pressed
1736
; eax=2 buttons pressed
1729
; eax=3 set mouse pos   ; reserved
1737
; eax=3 set mouse pos   ; reserved
1730
; eax=4 load cursor
1738
; eax=4 load cursor
1731
; eax=5 set cursor
1739
; eax=5 set cursor
1732
; eax=6 delete cursor   ; reserved
1740
; eax=6 delete cursor   ; reserved
1733
; eax=7 get mouse_z
1741
; eax=7 get mouse_z
1734
 
1742
 
1735
	   cmp eax, 7
1743
	   cmp eax, 7
1736
	   ja msset
1744
	   ja msset
1737
	   jmp [mousefn+eax*4]
1745
	   jmp [mousefn+eax*4]
1738
msscreen:
1746
msscreen:
1739
	   mov	eax,[MOUSE_X]
1747
	   mov	eax,[MOUSE_X]
1740
	   shl	eax,16
1748
	   shl	eax,16
1741
	   mov	ax,[MOUSE_Y]
1749
	   mov	ax,[MOUSE_Y]
1742
	   mov	[esp+36],eax
1750
	   mov	[esp+36],eax
1743
	   ret
1751
	   ret
1744
mswin:
1752
mswin:
1745
	   mov	eax,[MOUSE_X]
1753
	   mov	eax,[MOUSE_X]
1746
	   shl	eax,16
1754
	   shl	eax,16
1747
	   mov	ax,[MOUSE_Y]
1755
	   mov	ax,[MOUSE_Y]
1748
	   mov	esi,[TASK_BASE]
1756
	   mov	esi,[TASK_BASE]
1749
	   mov	bx, word [esi-twdw+WDATA.box.left]
1757
	   mov	bx, word [esi-twdw+WDATA.box.left]
1750
	   shl	ebx,16
1758
	   shl	ebx,16
1751
	   mov	bx, word [esi-twdw+WDATA.box.top]
1759
	   mov	bx, word [esi-twdw+WDATA.box.top]
1752
	   sub	eax,ebx
1760
	   sub	eax,ebx
1753
 
1761
 
1754
	   mov	edi,[CURRENT_TASK]
1762
	   mov	edi,[CURRENT_TASK]
1755
	   shl	edi,8
1763
	   shl	edi,8
1756
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1764
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1757
	   rol	eax,16
1765
	   rol	eax,16
1758
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1766
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1759
	   rol	eax,16
1767
	   rol	eax,16
1760
	   mov	[esp+36],eax
1768
	   mov	[esp+36],eax
1761
	   ret
1769
	   ret
1762
msbutton:
1770
msbutton:
1763
	   movzx eax,byte [BTN_DOWN]
1771
	   movzx eax,byte [BTN_DOWN]
1764
	   mov	[esp+36],eax
1772
	   mov	[esp+36],eax
1765
	   ret
1773
	   ret
1766
msz:
1774
msz:
1767
	   mov	 edi, [TASK_COUNT]
1775
	   mov	 edi, [TASK_COUNT]
1768
	   movzx edi, word [WIN_POS + edi*2]
1776
	   movzx edi, word [WIN_POS + edi*2]
1769
	   cmp	 edi, [CURRENT_TASK]
1777
	   cmp	 edi, [CURRENT_TASK]
1770
	   jne	 @f
1778
	   jne	 @f
1771
	   mov	 ax,[MOUSE_SCROLL_H]
1779
	   mov	 ax,[MOUSE_SCROLL_H]
1772
	   shl	 eax,16
1780
	   shl	 eax,16
1773
	   mov	 ax,[MOUSE_SCROLL_V]
1781
	   mov	 ax,[MOUSE_SCROLL_V]
1774
	   mov	 [esp+36],eax
1782
	   mov	 [esp+36],eax
1775
	   mov	 [MOUSE_SCROLL_H],word 0
1783
	   mov	 [MOUSE_SCROLL_H],word 0
1776
	   mov	 [MOUSE_SCROLL_V],word 0
1784
	   mov	 [MOUSE_SCROLL_V],word 0
1777
	   ret
1785
	   ret
1778
       @@:
1786
       @@:
1779
	   mov	[esp+36],dword 0
1787
	   mov	[esp+36],dword 0
1780
	   ret
1788
	   ret
1781
msset:
1789
msset:
1782
	   ret
1790
	   ret
1783
 
1791
 
1784
app_load_cursor:
1792
app_load_cursor:
1785
      ;     add ebx, new_app_base
1793
      ;     add ebx, new_app_base
1786
	   cmp ebx, OS_BASE
1794
	   cmp ebx, OS_BASE
1787
	   jae msset
1795
	   jae msset
1788
	   stdcall load_cursor, ebx, ecx
1796
	   stdcall load_cursor, ebx, ecx
1789
	   mov [esp+36], eax
1797
	   mov [esp+36], eax
1790
	   ret
1798
	   ret
1791
 
1799
 
1792
app_set_cursor:
1800
app_set_cursor:
1793
	   stdcall set_cursor, ebx
1801
	   stdcall set_cursor, ebx
1794
	   mov [esp+36], eax
1802
	   mov [esp+36], eax
1795
	   ret
1803
	   ret
1796
 
1804
 
1797
app_delete_cursor:
1805
app_delete_cursor:
1798
	   stdcall delete_cursor, ebx
1806
	   stdcall delete_cursor, ebx
1799
	   mov [esp+36], eax
1807
	   mov [esp+36], eax
1800
	   ret
1808
	   ret
1801
 
1809
 
1802
is_input:
1810
is_input:
1803
 
1811
 
1804
   push edx
1812
   push edx
1805
   mov	dx,word [midisp]
1813
   mov	dx,word [midisp]
1806
   in	al,dx
1814
   in	al,dx
1807
   and	al,0x80
1815
   and	al,0x80
1808
   pop	edx
1816
   pop	edx
1809
   ret
1817
   ret
1810
 
1818
 
1811
is_output:
1819
is_output:
1812
 
1820
 
1813
   push edx
1821
   push edx
1814
   mov	dx,word [midisp]
1822
   mov	dx,word [midisp]
1815
   in	al,dx
1823
   in	al,dx
1816
   and	al,0x40
1824
   and	al,0x40
1817
   pop	edx
1825
   pop	edx
1818
   ret
1826
   ret
1819
 
1827
 
1820
 
1828
 
1821
get_mpu_in:
1829
get_mpu_in:
1822
 
1830
 
1823
   push edx
1831
   push edx
1824
   mov	dx,word [mididp]
1832
   mov	dx,word [mididp]
1825
   in	al,dx
1833
   in	al,dx
1826
   pop	edx
1834
   pop	edx
1827
   ret
1835
   ret
1828
 
1836
 
1829
 
1837
 
1830
put_mpu_out:
1838
put_mpu_out:
1831
 
1839
 
1832
   push edx
1840
   push edx
1833
   mov	dx,word [mididp]
1841
   mov	dx,word [mididp]
1834
   out	dx,al
1842
   out	dx,al
1835
   pop	edx
1843
   pop	edx
1836
   ret
1844
   ret
1837
 
1845
 
1838
 
1846
 
1839
setuart:
1847
setuart:
1840
 
1848
 
1841
 su1:
1849
 su1:
1842
   call is_output
1850
   call is_output
1843
   cmp	al,0
1851
   cmp	al,0
1844
   jnz	su1
1852
   jnz	su1
1845
   mov	dx,word [midisp]
1853
   mov	dx,word [midisp]
1846
   mov	al,0xff
1854
   mov	al,0xff
1847
   out	dx,al
1855
   out	dx,al
1848
 su2:
1856
 su2:
1849
   mov	dx,word [midisp]
1857
   mov	dx,word [midisp]
1850
   mov	al,0xff
1858
   mov	al,0xff
1851
   out	dx,al
1859
   out	dx,al
1852
   call is_input
1860
   call is_input
1853
   cmp	al,0
1861
   cmp	al,0
1854
   jnz	su2
1862
   jnz	su2
1855
   call get_mpu_in
1863
   call get_mpu_in
1856
   cmp	al,0xfe
1864
   cmp	al,0xfe
1857
   jnz	su2
1865
   jnz	su2
1858
 su3:
1866
 su3:
1859
   call is_output
1867
   call is_output
1860
   cmp	al,0
1868
   cmp	al,0
1861
   jnz	su3
1869
   jnz	su3
1862
   mov	dx,word [midisp]
1870
   mov	dx,word [midisp]
1863
   mov	al,0x3f
1871
   mov	al,0x3f
1864
   out	dx,al
1872
   out	dx,al
1865
 
1873
 
1866
   ret
1874
   ret
1867
 
1875
 
1868
 
1876
 
1869
align 4
1877
align 4
1870
 
1878
 
1871
sys_midi:
1879
sys_midi:
1872
 
1880
 
1873
     cmp  [mididp],0
1881
     cmp  [mididp],0
1874
     jnz  sm0
1882
     jnz  sm0
1875
     mov  [esp+36],dword 1
1883
     mov  [esp+36],dword 1
1876
     ret
1884
     ret
1877
   sm0:
1885
   sm0:
1878
 
1886
 
1879
     cmp  eax,1
1887
     cmp  eax,1
1880
     mov  [esp+36],dword 0
1888
     mov  [esp+36],dword 0
1881
     jnz  smn1
1889
     jnz  smn1
1882
     call setuart
1890
     call setuart
1883
     ret
1891
     ret
1884
   smn1:
1892
   smn1:
1885
 
1893
 
1886
     cmp  eax,2
1894
     cmp  eax,2
1887
     jnz  smn2
1895
     jnz  smn2
1888
   sm10:
1896
   sm10:
1889
     call get_mpu_in
1897
     call get_mpu_in
1890
     call is_output
1898
     call is_output
1891
     test al,al
1899
     test al,al
1892
     jnz  sm10
1900
     jnz  sm10
1893
     mov  al,bl
1901
     mov  al,bl
1894
     call put_mpu_out
1902
     call put_mpu_out
1895
     ret
1903
     ret
1896
   smn2:
1904
   smn2:
1897
 
1905
 
1898
     ret
1906
     ret
1899
 
1907
 
1900
sys_end:
1908
sys_end:
1901
 
1909
 
1902
     mov   eax,[TASK_BASE]
1910
     mov   eax,[TASK_BASE]
1903
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1911
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1904
 
1912
 
1905
    waitterm:		 ; wait here for termination
1913
    waitterm:		 ; wait here for termination
1906
     mov   ebx,100
1914
     mov   ebx,100
1907
     call  delay_hs
1915
     call  delay_hs
1908
     jmp   waitterm
1916
     jmp   waitterm
1909
 
1917
 
1910
iglobal
1918
iglobal
1911
align 4
1919
align 4
1912
sys_system_table:
1920
sys_system_table:
1913
	dd	exit_for_anyone 	; 1 = obsolete
1921
	dd	exit_for_anyone 	; 1 = obsolete
1914
	dd	sysfn_terminate 	; 2 = terminate thread
1922
	dd	sysfn_terminate 	; 2 = terminate thread
1915
	dd	sysfn_activate		; 3 = activate window
1923
	dd	sysfn_activate		; 3 = activate window
1916
	dd	sysfn_getidletime	; 4 = get idle time
1924
	dd	sysfn_getidletime	; 4 = get idle time
1917
	dd	sysfn_getcpuclock	; 5 = get cpu clock
1925
	dd	sysfn_getcpuclock	; 5 = get cpu clock
1918
	dd	sysfn_saveramdisk	; 6 = save ramdisk
1926
	dd	sysfn_saveramdisk	; 6 = save ramdisk
1919
	dd	sysfn_getactive 	; 7 = get active window
1927
	dd	sysfn_getactive 	; 7 = get active window
1920
	dd	sysfn_sound_flag	; 8 = get/set sound_flag
1928
	dd	sysfn_sound_flag	; 8 = get/set sound_flag
1921
	dd	sysfn_shutdown		; 9 = shutdown with parameter
1929
	dd	sysfn_shutdown		; 9 = shutdown with parameter
1922
	dd	sysfn_minimize		; 10 = minimize window
1930
	dd	sysfn_minimize		; 10 = minimize window
1923
	dd	sysfn_getdiskinfo	; 11 = get disk subsystem info
1931
	dd	sysfn_getdiskinfo	; 11 = get disk subsystem info
1924
	dd	sysfn_lastkey		; 12 = get last pressed key
1932
	dd	sysfn_lastkey		; 12 = get last pressed key
1925
	dd	sysfn_getversion	; 13 = get kernel version
1933
	dd	sysfn_getversion	; 13 = get kernel version
1926
	dd	sysfn_waitretrace	; 14 = wait retrace
1934
	dd	sysfn_waitretrace	; 14 = wait retrace
1927
	dd	sysfn_centermouse	; 15 = center mouse cursor
1935
	dd	sysfn_centermouse	; 15 = center mouse cursor
1928
	dd	sysfn_getfreemem	; 16 = get free memory size
1936
	dd	sysfn_getfreemem	; 16 = get free memory size
1929
	dd	sysfn_getallmem 	; 17 = get total memory size
1937
	dd	sysfn_getallmem 	; 17 = get total memory size
1930
	dd	sysfn_terminate2	; 18 = terminate thread using PID
1938
	dd	sysfn_terminate2	; 18 = terminate thread using PID
1931
					;                 instead of slot
1939
					;                 instead of slot
1932
	dd	sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1940
	dd	sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1933
	dd	sysfn_meminfo		; 20 = get extended memory info
1941
	dd	sysfn_meminfo		; 20 = get extended memory info
1934
	dd	sysfn_pid_to_slot	; 21 = get slot number for pid
1942
	dd	sysfn_pid_to_slot	; 21 = get slot number for pid
1935
	dd	sysfn_min_rest_window	; 22 = minimize and restore any window
1943
	dd	sysfn_min_rest_window	; 22 = minimize and restore any window
1936
sysfn_num = ($ - sys_system_table)/4
1944
sysfn_num = ($ - sys_system_table)/4
1937
endg
1945
endg
1938
 
1946
 
1939
sys_system:
1947
sys_system:
1940
	dec	ebx
1948
	dec	ebx
1941
	cmp	ebx, sysfn_num
1949
	cmp	ebx, sysfn_num
1942
	jae	@f
1950
	jae	@f
1943
	jmp	dword [sys_system_table + ebx*4]
1951
	jmp	dword [sys_system_table + ebx*4]
1944
@@:
1952
@@:
1945
	ret
1953
	ret
1946
 
1954
 
1947
 
1955
 
1948
sysfn_shutdown: 	 ; 18.9 = system shutdown
1956
sysfn_shutdown: 	 ; 18.9 = system shutdown
1949
     cmp  ecx,1
1957
     cmp  ecx,1
1950
     jl   exit_for_anyone
1958
     jl   exit_for_anyone
1951
     cmp  ecx,4
1959
     cmp  ecx,4
1952
     jg   exit_for_anyone
1960
     jg   exit_for_anyone
1953
     mov  [BOOT_VAR+0x9030],cl
1961
     mov  [BOOT_VAR+0x9030],cl
1954
 
1962
 
1955
     mov  eax,[TASK_COUNT]
1963
     mov  eax,[TASK_COUNT]
1956
     mov  [SYS_SHUTDOWN],al
1964
     mov  [SYS_SHUTDOWN],al
1957
     mov  [shutdown_processes],eax
1965
     mov  [shutdown_processes],eax
1958
     and  dword [esp+32], 0
1966
     and  dword [esp+32], 0
1959
 exit_for_anyone:
1967
 exit_for_anyone:
1960
     ret
1968
     ret
1961
  uglobal
1969
  uglobal
1962
   shutdown_processes: dd 0x0
1970
   shutdown_processes: dd 0x0
1963
  endg
1971
  endg
1964
 
1972
 
1965
sysfn_terminate:	; 18.2 = TERMINATE
1973
sysfn_terminate:	; 18.2 = TERMINATE
1966
     cmp  ecx,2
1974
     cmp  ecx,2
1967
     jb   noprocessterminate
1975
     jb   noprocessterminate
1968
     mov  edx,[TASK_COUNT]
1976
     mov  edx,[TASK_COUNT]
1969
     cmp  ecx,edx
1977
     cmp  ecx,edx
1970
     ja   noprocessterminate
1978
     ja   noprocessterminate
1971
     mov  eax,[TASK_COUNT]
1979
     mov  eax,[TASK_COUNT]
1972
     shl  ecx,5
1980
     shl  ecx,5
1973
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
1981
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
1974
     add  ecx,CURRENT_TASK+TASKDATA.state
1982
     add  ecx,CURRENT_TASK+TASKDATA.state
1975
     cmp  byte [ecx], 9
1983
     cmp  byte [ecx], 9
1976
     jz   noprocessterminate
1984
     jz   noprocessterminate
1977
 
1985
 
1978
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1986
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1979
     mov  [ecx],byte 3	     ; clear possible i40's
1987
     mov  [ecx],byte 3	     ; clear possible i40's
1980
     ;call MEM_Heap_UnLock
1988
     ;call MEM_Heap_UnLock
1981
 
1989
 
1982
     cmp  edx,[application_table_status]    ; clear app table stat
1990
     cmp  edx,[application_table_status]    ; clear app table stat
1983
     jne  noatsc
1991
     jne  noatsc
1984
     mov  [application_table_status],0
1992
     mov  [application_table_status],0
1985
   noatsc:
1993
   noatsc:
1986
   noprocessterminate:
1994
   noprocessterminate:
1987
     ret
1995
     ret
1988
 
1996
 
1989
sysfn_terminate2:
1997
sysfn_terminate2:
1990
;lock application_table_status mutex
1998
;lock application_table_status mutex
1991
.table_status:
1999
.table_status:
1992
    cli
2000
    cli
1993
    cmp    [application_table_status],0
2001
    cmp    [application_table_status],0
1994
    je	   .stf
2002
    je	   .stf
1995
    sti
2003
    sti
1996
    call   change_task
2004
    call   change_task
1997
    jmp    .table_status
2005
    jmp    .table_status
1998
.stf:
2006
.stf:
1999
    call   set_application_table_status
2007
    call   set_application_table_status
2000
    mov    eax,ecx
2008
    mov    eax,ecx
2001
    call   pid_to_slot
2009
    call   pid_to_slot
2002
    test   eax,eax
2010
    test   eax,eax
2003
    jz	   .not_found
2011
    jz	   .not_found
2004
    mov    ecx,eax
2012
    mov    ecx,eax
2005
    pushfd
2013
    pushfd
2006
    cli
2014
    cli
2007
    call   sysfn_terminate
2015
    call   sysfn_terminate
2008
    mov    [application_table_status],0
2016
    mov    [application_table_status],0
2009
    popfd
2017
    popfd
2010
    and    dword [esp+32],0
2018
    and    dword [esp+32],0
2011
    ret
2019
    ret
2012
.not_found:
2020
.not_found:
2013
    mov    [application_table_status],0
2021
    mov    [application_table_status],0
2014
    or	   dword [esp+32],-1
2022
    or	   dword [esp+32],-1
2015
    ret
2023
    ret
2016
 
2024
 
2017
sysfn_activate: 	; 18.3 = ACTIVATE WINDOW
2025
sysfn_activate: 	; 18.3 = ACTIVATE WINDOW
2018
     cmp  ecx,2
2026
     cmp  ecx,2
2019
     jb   .nowindowactivate
2027
     jb   .nowindowactivate
2020
     cmp  ecx,[TASK_COUNT]
2028
     cmp  ecx,[TASK_COUNT]
2021
     ja   .nowindowactivate
2029
     ja   .nowindowactivate
2022
 
2030
 
2023
     mov   [window_minimize], 2   ; restore window if minimized
2031
     mov   [window_minimize], 2   ; restore window if minimized
2024
 
2032
 
2025
     movzx esi, word [WIN_STACK + ecx*2]
2033
     movzx esi, word [WIN_STACK + ecx*2]
2026
     cmp   esi, [TASK_COUNT]
2034
     cmp   esi, [TASK_COUNT]
2027
     je    .nowindowactivate ; already active
2035
     je    .nowindowactivate ; already active
2028
 
2036
 
2029
     mov   edi, ecx
2037
     mov   edi, ecx
2030
     shl   edi, 5
2038
     shl   edi, 5
2031
     add   edi, window_data
2039
     add   edi, window_data
2032
     movzx esi, word [WIN_STACK + ecx * 2]
2040
     movzx esi, word [WIN_STACK + ecx * 2]
2033
     lea   esi, [WIN_POS + esi * 2]
2041
     lea   esi, [WIN_POS + esi * 2]
2034
     call  waredraw
2042
     call  waredraw
2035
.nowindowactivate:
2043
.nowindowactivate:
2036
     ret
2044
     ret
2037
 
2045
 
2038
sysfn_getidletime:		; 18.4 = GET IDLETIME
2046
sysfn_getidletime:		; 18.4 = GET IDLETIME
2039
     mov  eax,[idleusesec]
2047
     mov  eax,[idleusesec]
2040
     mov  [esp+32], eax
2048
     mov  [esp+32], eax
2041
     ret
2049
     ret
2042
 
2050
 
2043
sysfn_getcpuclock:		; 18.5 = GET TSC/SEC
2051
sysfn_getcpuclock:		; 18.5 = GET TSC/SEC
2044
     mov  eax,[CPU_FREQ]
2052
     mov  eax,[CPU_FREQ]
2045
     mov  [esp+32], eax
2053
     mov  [esp+32], eax
2046
     ret
2054
     ret
2047
 
2055
 
2048
;  SAVE ramdisk to /hd/1/menuet.img
2056
;  SAVE ramdisk to /hd/1/menuet.img
2049
;!!!!!!!!!!!!!!!!!!!!!!!!
2057
;!!!!!!!!!!!!!!!!!!!!!!!!
2050
   include 'blkdev/rdsave.inc'
2058
   include 'blkdev/rdsave.inc'
2051
;!!!!!!!!!!!!!!!!!!!!!!!!
2059
;!!!!!!!!!!!!!!!!!!!!!!!!
2052
 
2060
 
2053
sysfn_getactive:	; 18.7 = get active window
2061
sysfn_getactive:	; 18.7 = get active window
2054
     mov  eax, [TASK_COUNT]
2062
     mov  eax, [TASK_COUNT]
2055
   movzx  eax, word [WIN_POS + eax*2]
2063
   movzx  eax, word [WIN_POS + eax*2]
2056
     mov  [esp+32],eax
2064
     mov  [esp+32],eax
2057
     ret
2065
     ret
2058
 
2066
 
2059
sysfn_sound_flag:	; 18.8 = get/set sound_flag
2067
sysfn_sound_flag:	; 18.8 = get/set sound_flag
2060
     cmp  ecx,1
2068
     cmp  ecx,1
2061
     jne  nogetsoundflag
2069
     jne  nogetsoundflag
2062
     movzx  eax,byte [sound_flag] ; get sound_flag
2070
     movzx  eax,byte [sound_flag] ; get sound_flag
2063
     mov  [esp+32],eax
2071
     mov  [esp+32],eax
2064
     ret
2072
     ret
2065
 nogetsoundflag:
2073
 nogetsoundflag:
2066
     cmp  ecx,2
2074
     cmp  ecx,2
2067
     jnz  nosoundflag
2075
     jnz  nosoundflag
2068
     xor  byte [sound_flag], 1
2076
     xor  byte [sound_flag], 1
2069
 nosoundflag:
2077
 nosoundflag:
2070
     ret
2078
     ret
2071
 
2079
 
2072
sysfn_minimize: 	; 18.10 = minimize window
2080
sysfn_minimize: 	; 18.10 = minimize window
2073
     mov   [window_minimize],1
2081
     mov   [window_minimize],1
2074
     ret
2082
     ret
2075
 
2083
 
2076
sysfn_getdiskinfo:	; 18.11 = get disk info table
2084
sysfn_getdiskinfo:	; 18.11 = get disk info table
2077
     cmp  ecx,1
2085
     cmp  ecx,1
2078
     jnz  full_table
2086
     jnz  full_table
2079
  small_table:
2087
  small_table:
2080
     call for_all_tables
2088
     call for_all_tables
2081
     mov ecx,10
2089
     mov ecx,10
2082
     cld
2090
     cld
2083
     rep movsb
2091
     rep movsb
2084
     ret
2092
     ret
2085
   for_all_tables:
2093
   for_all_tables:
2086
     mov edi,edx
2094
     mov edi,edx
2087
     mov esi,DRIVE_DATA
2095
     mov esi,DRIVE_DATA
2088
     ret
2096
     ret
2089
  full_table:
2097
  full_table:
2090
     cmp  ecx,2
2098
     cmp  ecx,2
2091
     jnz  exit_for_anyone
2099
     jnz  exit_for_anyone
2092
     call for_all_tables
2100
     call for_all_tables
2093
     mov ecx,16384
2101
     mov ecx,16384
2094
     cld
2102
     cld
2095
     rep movsd
2103
     rep movsd
2096
     ret
2104
     ret
2097
 
2105
 
2098
sysfn_lastkey:		; 18.12 = return 0 (backward compatibility)
2106
sysfn_lastkey:		; 18.12 = return 0 (backward compatibility)
2099
	and	dword [esp+32], 0
2107
	and	dword [esp+32], 0
2100
	ret
2108
	ret
2101
 
2109
 
2102
sysfn_getversion:	; 18.13 = get kernel ID and version
2110
sysfn_getversion:	; 18.13 = get kernel ID and version
2103
     mov edi,ebx
2111
     mov edi,ebx
2104
     mov esi,version_inf
2112
     mov esi,version_inf
2105
     mov ecx,version_end-version_inf
2113
     mov ecx,version_end-version_inf
2106
     rep movsb
2114
     rep movsb
2107
     ret
2115
     ret
2108
 
2116
 
2109
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2117
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2110
     ;wait retrace functions
2118
     ;wait retrace functions
2111
 sys_wait_retrace:
2119
 sys_wait_retrace:
2112
     mov edx,0x3da
2120
     mov edx,0x3da
2113
 WaitRetrace_loop:
2121
 WaitRetrace_loop:
2114
     in al,dx
2122
     in al,dx
2115
     test al,1000b
2123
     test al,1000b
2116
     jz WaitRetrace_loop
2124
     jz WaitRetrace_loop
2117
     and [esp+32],dword 0
2125
     and [esp+32],dword 0
2118
     ret
2126
     ret
2119
 
2127
 
2120
sysfn_centermouse:	; 18.15 = mouse centered
2128
sysfn_centermouse:	; 18.15 = mouse centered
2121
     call  mouse_centered
2129
     call  mouse_centered
2122
     and [esp+32],dword 0
2130
     and [esp+32],dword 0
2123
     ret
2131
     ret
2124
 
2132
 
2125
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2133
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2126
     cmp  ecx,0  ; get mouse speed factor
2134
     cmp  ecx,0  ; get mouse speed factor
2127
     jnz  .set_mouse_acceleration
2135
     jnz  .set_mouse_acceleration
2128
     xor  eax,eax
2136
     xor  eax,eax
2129
     mov  ax,[mouse_speed_factor]
2137
     mov  ax,[mouse_speed_factor]
2130
     mov  [esp+32],eax
2138
     mov  [esp+32],eax
2131
     ret
2139
     ret
2132
 .set_mouse_acceleration:
2140
 .set_mouse_acceleration:
2133
     cmp  ecx,1  ; set mouse speed factor
2141
     cmp  ecx,1  ; set mouse speed factor
2134
     jnz  .get_mouse_delay
2142
     jnz  .get_mouse_delay
2135
     mov  [mouse_speed_factor],dx
2143
     mov  [mouse_speed_factor],dx
2136
     ret
2144
     ret
2137
 .get_mouse_delay:
2145
 .get_mouse_delay:
2138
     cmp  ecx,2  ; get mouse delay
2146
     cmp  ecx,2  ; get mouse delay
2139
     jnz  .set_mouse_delay
2147
     jnz  .set_mouse_delay
2140
     mov  eax,[mouse_delay]
2148
     mov  eax,[mouse_delay]
2141
     mov  [esp+32],eax
2149
     mov  [esp+32],eax
2142
     ret
2150
     ret
2143
 .set_mouse_delay:
2151
 .set_mouse_delay:
2144
     cmp  ecx,3  ; set mouse delay
2152
     cmp  ecx,3  ; set mouse delay
2145
     jnz  .set_pointer_position
2153
     jnz  .set_pointer_position
2146
     mov  [mouse_delay],edx
2154
     mov  [mouse_delay],edx
2147
     ret
2155
     ret
2148
 .set_pointer_position:
2156
 .set_pointer_position:
2149
     cmp  ecx,4  ; set mouse pointer position
2157
     cmp  ecx,4  ; set mouse pointer position
2150
     jnz  .set_mouse_button
2158
     jnz  .set_mouse_button
2151
     mov   [MOUSE_Y],dx    ;y
2159
     mov   [MOUSE_Y],dx    ;y
2152
     ror   edx,16
2160
     ror   edx,16
2153
     mov   [MOUSE_X],dx    ;x
2161
     mov   [MOUSE_X],dx    ;x
2154
     rol   edx,16
2162
     rol   edx,16
2155
     ret
2163
     ret
2156
 .set_mouse_button:
2164
 .set_mouse_button:
2157
     cmp   ecx,5  ; set mouse button features
2165
     cmp   ecx,5  ; set mouse button features
2158
     jnz  .end
2166
     jnz  .end
2159
     mov   [BTN_DOWN],dl
2167
     mov   [BTN_DOWN],dl
2160
     mov   [mouse_active],1
2168
     mov   [mouse_active],1
2161
 .end:
2169
 .end:
2162
     ret
2170
     ret
2163
 
2171
 
2164
sysfn_getfreemem:
2172
sysfn_getfreemem:
2165
     call _get_free_mem
2173
     call _get_free_mem
2166
     shl eax, 2
2174
     shl eax, 2
2167
     mov [esp+32],eax
2175
     mov [esp+32],eax
2168
     ret
2176
     ret
2169
 
2177
 
2170
sysfn_getallmem:
2178
sysfn_getallmem:
2171
     mov  eax,[_mem_amount]
2179
     mov  eax,[_mem_amount]
2172
     shr eax, 10
2180
     shr eax, 10
2173
     mov  [esp+32],eax
2181
     mov  [esp+32],eax
2174
     ret
2182
     ret
2175
 
2183
 
2176
; // Alver, 2007-22-08 // {
2184
; // Alver, 2007-22-08 // {
2177
sysfn_pid_to_slot:
2185
sysfn_pid_to_slot:
2178
     mov   eax, ecx
2186
     mov   eax, ecx
2179
     call  pid_to_slot
2187
     call  pid_to_slot
2180
     mov   [esp+32], eax
2188
     mov   [esp+32], eax
2181
     ret
2189
     ret
2182
 
2190
 
2183
sysfn_min_rest_window:
2191
sysfn_min_rest_window:
2184
     pushad
2192
     pushad
2185
     mov   eax, edx	 ; ebx - operating
2193
     mov   eax, edx	 ; ebx - operating
2186
     shr   ecx, 1
2194
     shr   ecx, 1
2187
     jnc    @f
2195
     jnc    @f
2188
     call  pid_to_slot
2196
     call  pid_to_slot
2189
@@:
2197
@@:
2190
     or    eax, eax	 ; eax - number of slot
2198
     or    eax, eax	 ; eax - number of slot
2191
     jz    .error
2199
     jz    .error
2192
     cmp   eax, 255	    ; varify maximal slot number
2200
     cmp   eax, 255	    ; varify maximal slot number
2193
     ja    .error
2201
     ja    .error
2194
     movzx eax, word [WIN_STACK + eax*2]
2202
     movzx eax, word [WIN_STACK + eax*2]
2195
     shr   ecx, 1
2203
     shr   ecx, 1
2196
     jc    .restore
2204
     jc    .restore
2197
 ; .minimize:
2205
 ; .minimize:
2198
     call  minimize_window
2206
     call  minimize_window
2199
     jmp   .exit
2207
     jmp   .exit
2200
.restore:
2208
.restore:
2201
     call  restore_minimized_window
2209
     call  restore_minimized_window
2202
.exit:
2210
.exit:
2203
     popad
2211
     popad
2204
     xor   eax, eax
2212
     xor   eax, eax
2205
     mov   [esp+32], eax
2213
     mov   [esp+32], eax
2206
     ret
2214
     ret
2207
.error:
2215
.error:
2208
     popad
2216
     popad
2209
     xor   eax, eax
2217
     xor   eax, eax
2210
     dec   eax
2218
     dec   eax
2211
     mov   [esp+32], eax
2219
     mov   [esp+32], eax
2212
     ret
2220
     ret
2213
; } \\ Alver, 2007-22-08 \\
2221
; } \\ Alver, 2007-22-08 \\
2214
 
2222
 
2215
uglobal
2223
uglobal
2216
;// mike.dld, 2006-29-01 [
2224
;// mike.dld, 2006-29-01 [
2217
screen_workarea RECT
2225
screen_workarea RECT
2218
;// mike.dld, 2006-29-01 ]
2226
;// mike.dld, 2006-29-01 ]
2219
window_minimize db 0
2227
window_minimize db 0
2220
sound_flag	db 0
2228
sound_flag	db 0
2221
endg
2229
endg
2222
 
2230
 
2223
iglobal
2231
iglobal
2224
version_inf:
2232
version_inf:
2225
  db 0,7,1,0  ; version 0.7.1.0
2233
  db 0,7,1,0  ; version 0.7.1.0
2226
  db UID_KOLIBRI
2234
  db UID_KOLIBRI
2227
  dd __REV__
2235
  dd __REV__
2228
version_end:
2236
version_end:
2229
endg
2237
endg
2230
 
2238
 
2231
UID_NONE=0
2239
UID_NONE=0
2232
UID_MENUETOS=1	 ;official
2240
UID_MENUETOS=1	 ;official
2233
UID_KOLIBRI=2	 ;russian
2241
UID_KOLIBRI=2	 ;russian
2234
 
2242
 
2235
sys_cachetodiskette:
2243
sys_cachetodiskette:
2236
	cmp	ebx, 1
2244
	cmp	ebx, 1
2237
	jne	.no_floppy_a_save
2245
	jne	.no_floppy_a_save
2238
	mov	[flp_number], 1
2246
	mov	[flp_number], 1
2239
	jmp	.save_image_on_floppy
2247
	jmp	.save_image_on_floppy
2240
.no_floppy_a_save:
2248
.no_floppy_a_save:
2241
	cmp	ebx, 2
2249
	cmp	ebx, 2
2242
	jne	.no_floppy_b_save
2250
	jne	.no_floppy_b_save
2243
	mov	[flp_number], 2
2251
	mov	[flp_number], 2
2244
.save_image_on_floppy:
2252
.save_image_on_floppy:
2245
	call	save_image
2253
	call	save_image
2246
	mov	[esp + 32], dword 0
2254
	mov	[esp + 32], dword 0
2247
	cmp	[FDC_Status], 0
2255
	cmp	[FDC_Status], 0
2248
	je	.yes_floppy_save
2256
	je	.yes_floppy_save
2249
.no_floppy_b_save:
2257
.no_floppy_b_save:
2250
	mov	[esp + 32], dword 1
2258
	mov	[esp + 32], dword 1
2251
.yes_floppy_save:
2259
.yes_floppy_save:
2252
	ret
2260
	ret
2253
 
2261
 
2254
uglobal
2262
uglobal
2255
;  bgrchanged  dd  0x0
2263
;  bgrchanged  dd  0x0
2256
bgrlock db 0
2264
bgrlock db 0
2257
bgrlockpid dd 0
2265
bgrlockpid dd 0
2258
endg
2266
endg
2259
 
2267
 
2260
sys_background:
2268
sys_background:
2261
 
2269
 
2262
    cmp   ebx,1 			   ; BACKGROUND SIZE
2270
    cmp   ebx,1 			   ; BACKGROUND SIZE
2263
    jnz   nosb1
2271
    jnz   nosb1
2264
    cmp   ecx,0
2272
    cmp   ecx,0
2265
    je	  sbgrr
2273
    je	  sbgrr
2266
    cmp   edx,0
2274
    cmp   edx,0
2267
    je	  sbgrr
2275
    je	  sbgrr
2268
@@:
2276
@@:
2269
	mov	al, 1
2277
	mov	al, 1
2270
	xchg	[bgrlock], al
2278
	xchg	[bgrlock], al
2271
	test	al, al
2279
	test	al, al
2272
	jz	@f
2280
	jz	@f
2273
	call	change_task
2281
	call	change_task
2274
	jmp	@b
2282
	jmp	@b
2275
@@:
2283
@@:
2276
    mov   [BgrDataWidth],ecx
2284
    mov   [BgrDataWidth],ecx
2277
    mov   [BgrDataHeight],edx
2285
    mov   [BgrDataHeight],edx
2278
;    mov   [bgrchanged],1
2286
;    mov   [bgrchanged],1
2279
 
2287
 
2280
    pushad
2288
    pushad
2281
; return memory for old background
2289
; return memory for old background
2282
 
2290
 
2283
    mov ecx, [img_background]
2291
    mov ecx, [img_background]
2284
    call @mem_free@4
2292
    call @mem_free@4
2285
 
2293
 
2286
; calculate RAW size
2294
; calculate RAW size
2287
    xor  eax,eax
2295
    xor  eax,eax
2288
    inc  eax
2296
    inc  eax
2289
    cmp  [BgrDataWidth],eax
2297
    cmp  [BgrDataWidth],eax
2290
    jae   @f
2298
    jae   @f
2291
    mov [BgrDataWidth],eax
2299
    mov [BgrDataWidth],eax
2292
@@:
2300
@@:
2293
    cmp  [BgrDataHeight],eax
2301
    cmp  [BgrDataHeight],eax
2294
    jae   @f
2302
    jae   @f
2295
    mov [BgrDataHeight],eax
2303
    mov [BgrDataHeight],eax
2296
@@:
2304
@@:
2297
    mov  eax,[BgrDataWidth]
2305
    mov  eax,[BgrDataWidth]
2298
    imul eax,[BgrDataHeight]
2306
    imul eax,[BgrDataHeight]
2299
    lea  ecx,[eax*3]
2307
    lea  ecx,[eax*3]
2300
    mov  [mem_BACKGROUND],ecx
2308
    mov  [mem_BACKGROUND],ecx
2301
; get memory for new background
2309
; get memory for new background
2302
    mov edx, PG_SW
2310
    mov edx, PG_SW
2303
    stdcall @mem_alloc@8
2311
    stdcall @mem_alloc@8
2304
    test eax, eax
2312
    test eax, eax
2305
    jz .exit_mem
2313
    jz .exit_mem
2306
    mov [img_background], eax
2314
    mov [img_background], eax
2307
.exit_mem:
2315
.exit_mem:
2308
    popad
2316
    popad
2309
	mov	[bgrlock], 0
2317
	mov	[bgrlock], 0
2310
 
2318
 
2311
  sbgrr:
2319
  sbgrr:
2312
    ret
2320
    ret
2313
 
2321
 
2314
nosb1:
2322
nosb1:
2315
 
2323
 
2316
    cmp   ebx,2 			   ; SET PIXEL
2324
    cmp   ebx,2 			   ; SET PIXEL
2317
    jnz   nosb2
2325
    jnz   nosb2
2318
 
2326
 
2319
    mov ebx, [mem_BACKGROUND]
2327
    mov ebx, [mem_BACKGROUND]
2320
    add ebx, 4095
2328
    add ebx, 4095
2321
    and ebx, -4096
2329
    and ebx, -4096
2322
    sub ebx, 4
2330
    sub ebx, 4
2323
    cmp   ecx, ebx
2331
    cmp   ecx, ebx
2324
    ja   @F
2332
    ja   @F
2325
 
2333
 
2326
    mov   eax,[img_background]
2334
    mov   eax,[img_background]
2327
    mov   ebx,[eax+ecx]
2335
    mov   ebx,[eax+ecx]
2328
    and   ebx,0xFF000000 ;255*256*256*256
2336
    and   ebx,0xFF000000 ;255*256*256*256
2329
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2337
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2330
    add   edx,ebx
2338
    add   edx,ebx
2331
    mov   [eax+ecx],edx
2339
    mov   [eax+ecx],edx
2332
@@:
2340
@@:
2333
    ret
2341
    ret
2334
 
2342
 
2335
nosb2:
2343
nosb2:
2336
 
2344
 
2337
    cmp   ebx,3 			   ; DRAW BACKGROUND
2345
    cmp   ebx,3 			   ; DRAW BACKGROUND
2338
    jnz   nosb3
2346
    jnz   nosb3
2339
draw_background_temp:
2347
draw_background_temp:
2340
;    cmp   [bgrchanged],1 ;0
2348
;    cmp   [bgrchanged],1 ;0
2341
;    je    nosb31
2349
;    je    nosb31
2342
;draw_background_temp:
2350
;draw_background_temp:
2343
;    mov   [bgrchanged],1 ;0
2351
;    mov   [bgrchanged],1 ;0
2344
    mov    [background_defined], 1
2352
    mov    [background_defined], 1
2345
    call  force_redraw_background
2353
    call  force_redraw_background
2346
    mov    [REDRAW_BACKGROUND], byte 2
2354
    mov    [REDRAW_BACKGROUND], byte 2
2347
   nosb31:
2355
   nosb31:
2348
    ret
2356
    ret
2349
  nosb3:
2357
  nosb3:
2350
 
2358
 
2351
    cmp   ebx,4 			   ; TILED / STRETCHED
2359
    cmp   ebx,4 			   ; TILED / STRETCHED
2352
    jnz   nosb4
2360
    jnz   nosb4
2353
    cmp   ecx,[BgrDrawMode]
2361
    cmp   ecx,[BgrDrawMode]
2354
    je	  nosb41
2362
    je	  nosb41
2355
    mov   [BgrDrawMode],ecx
2363
    mov   [BgrDrawMode],ecx
2356
;    mov   [bgrchanged],1
2364
;    mov   [bgrchanged],1
2357
   nosb41:
2365
   nosb41:
2358
    ret
2366
    ret
2359
  nosb4:
2367
  nosb4:
2360
 
2368
 
2361
    cmp   ebx,5 			   ; BLOCK MOVE TO BGR
2369
    cmp   ebx,5 			   ; BLOCK MOVE TO BGR
2362
    jnz   nosb5
2370
    jnz   nosb5
2363
  ; bughere
2371
  ; bughere
2364
    mov   eax, ecx
2372
    mov   eax, ecx
2365
    mov   ebx, edx
2373
    mov   ebx, edx
2366
    add   ebx, [img_background]   ;IMG_BACKGROUND
2374
    add   ebx, [img_background]   ;IMG_BACKGROUND
2367
    mov   ecx, esi
2375
    mov   ecx, esi
2368
    call  memmove
2376
    call  memmove
2369
  .fin:
2377
  .fin:
2370
    ret
2378
    ret
2371
  nosb5:
2379
  nosb5:
2372
 
2380
 
2373
	cmp	ebx, 6
2381
	cmp	ebx, 6
2374
	jnz	nosb6
2382
	jnz	nosb6
2375
@@:
2383
@@:
2376
	mov	al, 1
2384
	mov	al, 1
2377
	xchg	[bgrlock], al
2385
	xchg	[bgrlock], al
2378
	test	al, al
2386
	test	al, al
2379
	jz	@f
2387
	jz	@f
2380
	call	change_task
2388
	call	change_task
2381
	jmp	@b
2389
	jmp	@b
2382
@@:
2390
@@:
2383
	mov	eax, [CURRENT_TASK]
2391
	mov	eax, [CURRENT_TASK]
2384
	mov	[bgrlockpid], eax
2392
	mov	[bgrlockpid], eax
2385
	stdcall user_alloc, [mem_BACKGROUND]
2393
	stdcall user_alloc, [mem_BACKGROUND]
2386
	mov	[esp+32], eax
2394
	mov	[esp+32], eax
2387
	test	eax, eax
2395
	test	eax, eax
2388
	jz	.nomem
2396
	jz	.nomem
2389
	mov	ebx, eax
2397
	mov	ebx, eax
2390
	shr	ebx, 12
2398
	shr	ebx, 12
2391
	or	dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2399
	or	dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2392
	mov	esi, [img_background]
2400
	mov	esi, [img_background]
2393
	shr	esi, 12
2401
	shr	esi, 12
2394
	mov	ecx, [mem_BACKGROUND]
2402
	mov	ecx, [mem_BACKGROUND]
2395
	add	ecx, 0xFFF
2403
	add	ecx, 0xFFF
2396
	shr	ecx, 12
2404
	shr	ecx, 12
2397
.z:
2405
.z:
2398
	mov	eax, [page_tabs+esi*4]
2406
	mov	eax, [page_tabs+esi*4]
2399
	or	al, PG_UW
2407
	or	al, PG_UW
2400
	mov	[page_tabs+ebx*4], eax
2408
	mov	[page_tabs+ebx*4], eax
2401
	mov	eax, ebx
2409
	mov	eax, ebx
2402
	shl	eax, 12
2410
	shl	eax, 12
2403
	invlpg	[eax]
2411
	invlpg	[eax]
2404
	inc	ebx
2412
	inc	ebx
2405
	inc	esi
2413
	inc	esi
2406
	loop	.z
2414
	loop	.z
2407
	ret
2415
	ret
2408
.nomem:
2416
.nomem:
2409
	and	[bgrlockpid], 0
2417
	and	[bgrlockpid], 0
2410
	mov	[bgrlock], 0
2418
	mov	[bgrlock], 0
2411
nosb6:
2419
nosb6:
2412
	cmp	ebx, 7
2420
	cmp	ebx, 7
2413
	jnz	nosb7
2421
	jnz	nosb7
2414
	cmp	[bgrlock], 0
2422
	cmp	[bgrlock], 0
2415
	jz	.err
2423
	jz	.err
2416
	mov	eax, [CURRENT_TASK]
2424
	mov	eax, [CURRENT_TASK]
2417
	cmp	[bgrlockpid], eax
2425
	cmp	[bgrlockpid], eax
2418
	jnz	.err
2426
	jnz	.err
2419
	mov	eax, ecx
2427
	mov	eax, ecx
2420
	mov	ebx, ecx
2428
	mov	ebx, ecx
2421
	shr	eax, 12
2429
	shr	eax, 12
2422
	mov	ecx, [page_tabs+(eax-1)*4]
2430
	mov	ecx, [page_tabs+(eax-1)*4]
2423
	test	cl, USED_BLOCK+DONT_FREE_BLOCK
2431
	test	cl, USED_BLOCK+DONT_FREE_BLOCK
2424
	jz	.err
2432
	jz	.err
2425
	jnp	.err
2433
	jnp	.err
2426
	push	eax
2434
	push	eax
2427
	shr	ecx, 12
2435
	shr	ecx, 12
2428
@@:
2436
@@:
2429
	and	dword [page_tabs+eax*4], 0
2437
	and	dword [page_tabs+eax*4], 0
2430
	mov	edx, eax
2438
	mov	edx, eax
2431
	shl	edx, 12
2439
	shl	edx, 12
2432
        push eax
2440
        push eax
2433
	invlpg	[edx]
2441
	invlpg	[edx]
2434
        pop eax
2442
        pop eax
2435
	inc	eax
2443
	inc	eax
2436
	loop	@b
2444
	loop	@b
2437
	pop	eax
2445
	pop	eax
2438
	and	dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2446
	and	dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2439
	stdcall user_free, ebx
2447
	stdcall user_free, ebx
2440
	mov	[esp+32], eax
2448
	mov	[esp+32], eax
2441
	and	[bgrlockpid], 0
2449
	and	[bgrlockpid], 0
2442
	mov	[bgrlock], 0
2450
	mov	[bgrlock], 0
2443
	ret
2451
	ret
2444
.err:
2452
.err:
2445
	and	dword [esp+32], 0
2453
	and	dword [esp+32], 0
2446
	ret
2454
	ret
2447
 
2455
 
2448
nosb7:
2456
nosb7:
2449
    ret
2457
    ret
2450
 
2458
 
2451
force_redraw_background:
2459
force_redraw_background:
2452
    mov   [draw_data+32 + RECT.left],dword 0
2460
    mov   [draw_data+32 + RECT.left],dword 0
2453
    mov   [draw_data+32 + RECT.top],dword 0
2461
    mov   [draw_data+32 + RECT.top],dword 0
2454
    push  eax ebx
2462
    push  eax ebx
2455
    mov   eax,[Screen_Max_X]
2463
    mov   eax,[Screen_Max_X]
2456
    mov   ebx,[Screen_Max_Y]
2464
    mov   ebx,[Screen_Max_Y]
2457
    mov   [draw_data+32 + RECT.right],eax
2465
    mov   [draw_data+32 + RECT.right],eax
2458
    mov   [draw_data+32 + RECT.bottom],ebx
2466
    mov   [draw_data+32 + RECT.bottom],ebx
2459
    pop   ebx eax
2467
    pop   ebx eax
2460
    mov   byte [REDRAW_BACKGROUND], 1
2468
    mov   byte [REDRAW_BACKGROUND], 1
2461
    ret
2469
    ret
2462
 
2470
 
2463
align 4
2471
align 4
2464
 
2472
 
2465
sys_getbackground:
2473
sys_getbackground:
2466
 
2474
 
2467
    cmp   eax,1 				 ; SIZE
2475
    cmp   eax,1 				 ; SIZE
2468
    jnz   nogb1
2476
    jnz   nogb1
2469
    mov   eax,[BgrDataWidth]
2477
    mov   eax,[BgrDataWidth]
2470
    shl   eax,16
2478
    shl   eax,16
2471
    mov   ax,[BgrDataHeight]
2479
    mov   ax,[BgrDataHeight]
2472
    mov   [esp+36],eax
2480
    mov   [esp+36],eax
2473
    ret
2481
    ret
2474
 
2482
 
2475
nogb1:
2483
nogb1:
2476
 
2484
 
2477
    cmp   eax,2 				 ; PIXEL
2485
    cmp   eax,2 				 ; PIXEL
2478
    jnz   nogb2
2486
    jnz   nogb2
2479
 
2487
 
2480
    mov ecx, [mem_BACKGROUND]
2488
    mov ecx, [mem_BACKGROUND]
2481
    add ecx, 4095
2489
    add ecx, 4095
2482
    and ecx, -4096
2490
    and ecx, -4096
2483
    sub ecx, 4
2491
    sub ecx, 4
2484
    cmp ebx, ecx
2492
    cmp ebx, ecx
2485
    ja  @F
2493
    ja  @F
2486
 
2494
 
2487
    mov   eax,[img_background]
2495
    mov   eax,[img_background]
2488
    mov   eax,[ebx+eax]
2496
    mov   eax,[ebx+eax]
2489
 
2497
 
2490
    and   eax, 0xFFFFFF
2498
    and   eax, 0xFFFFFF
2491
    mov   [esp+36],eax
2499
    mov   [esp+36],eax
2492
@@:
2500
@@:
2493
    ret
2501
    ret
2494
 
2502
 
2495
  nogb2:
2503
  nogb2:
2496
 
2504
 
2497
    cmp   eax,4 				 ; TILED / STRETCHED
2505
    cmp   eax,4 				 ; TILED / STRETCHED
2498
    jnz   nogb4
2506
    jnz   nogb4
2499
    mov   eax,[BgrDrawMode]
2507
    mov   eax,[BgrDrawMode]
2500
  nogb4:
2508
  nogb4:
2501
    mov   [esp+36],eax
2509
    mov   [esp+36],eax
2502
    ret
2510
    ret
2503
 
2511
 
2504
 
2512
 
2505
align 4
2513
align 4
2506
 
2514
 
2507
sys_getkey:
2515
sys_getkey:
2508
	mov	[esp + 32],dword 1
2516
	mov	[esp + 32],dword 1
2509
	; test main buffer
2517
	; test main buffer
2510
	mov	ebx, [CURRENT_TASK]			     ; TOP OF WINDOW STACK
2518
	mov	ebx, [CURRENT_TASK]			     ; TOP OF WINDOW STACK
2511
	movzx	ecx, word [WIN_STACK + ebx * 2]
2519
	movzx	ecx, word [WIN_STACK + ebx * 2]
2512
	mov	edx, [TASK_COUNT]
2520
	mov	edx, [TASK_COUNT]
2513
	cmp	ecx, edx
2521
	cmp	ecx, edx
2514
	jne	.finish
2522
	jne	.finish
2515
	cmp	[KEY_COUNT], byte 0
2523
	cmp	[KEY_COUNT], byte 0
2516
	je	.finish
2524
	je	.finish
2517
	movzx	eax, byte [KEY_BUFF]
2525
	movzx	eax, byte [KEY_BUFF]
2518
	shl	eax, 8
2526
	shl	eax, 8
2519
	push	eax
2527
	push	eax
2520
	dec	byte [KEY_COUNT]
2528
	dec	byte [KEY_COUNT]
2521
	and	byte [KEY_COUNT], 127
2529
	and	byte [KEY_COUNT], 127
2522
	movzx	ecx, byte [KEY_COUNT]
2530
	movzx	ecx, byte [KEY_COUNT]
2523
	add	ecx, 2
2531
	add	ecx, 2
2524
	mov	eax, KEY_BUFF + 1
2532
	mov	eax, KEY_BUFF + 1
2525
	mov	ebx, KEY_BUFF
2533
	mov	ebx, KEY_BUFF
2526
	call	memmove
2534
	call	memmove
2527
	pop	eax
2535
	pop	eax
2528
.ret_eax:
2536
.ret_eax:
2529
	mov	[esp + 32], eax
2537
	mov	[esp + 32], eax
2530
	ret
2538
	ret
2531
.finish:
2539
.finish:
2532
; test hotkeys buffer
2540
; test hotkeys buffer
2533
	mov	ecx, hotkey_buffer
2541
	mov	ecx, hotkey_buffer
2534
@@:
2542
@@:
2535
	cmp	[ecx], ebx
2543
	cmp	[ecx], ebx
2536
	jz	.found
2544
	jz	.found
2537
	add	ecx, 8
2545
	add	ecx, 8
2538
	cmp	ecx, hotkey_buffer + 120 * 8
2546
	cmp	ecx, hotkey_buffer + 120 * 8
2539
	jb	@b
2547
	jb	@b
2540
	ret
2548
	ret
2541
.found:
2549
.found:
2542
	mov	ax, [ecx + 6]
2550
	mov	ax, [ecx + 6]
2543
	shl	eax, 16
2551
	shl	eax, 16
2544
	mov	ah, [ecx + 4]
2552
	mov	ah, [ecx + 4]
2545
	mov	al, 2
2553
	mov	al, 2
2546
	and	dword [ecx + 4], 0
2554
	and	dword [ecx + 4], 0
2547
	and	dword [ecx], 0
2555
	and	dword [ecx], 0
2548
	jmp	.ret_eax
2556
	jmp	.ret_eax
2549
 
2557
 
2550
align 4
2558
align 4
2551
 
2559
 
2552
sys_getbutton:
2560
sys_getbutton:
2553
 
2561
 
2554
	mov	ebx, [CURRENT_TASK]			    ; TOP OF WINDOW STACK
2562
	mov	ebx, [CURRENT_TASK]			    ; TOP OF WINDOW STACK
2555
	mov	[esp + 32], dword 1
2563
	mov	[esp + 32], dword 1
2556
	movzx	ecx, word [WIN_STACK + ebx * 2]
2564
	movzx	ecx, word [WIN_STACK + ebx * 2]
2557
	mov	edx, [TASK_COUNT] ; less than 256 processes
2565
	mov	edx, [TASK_COUNT] ; less than 256 processes
2558
	cmp	ecx, edx
2566
	cmp	ecx, edx
2559
	jne	.exit
2567
	jne	.exit
2560
	movzx	eax, byte [BTN_COUNT]
2568
	movzx	eax, byte [BTN_COUNT]
2561
	test	eax, eax
2569
	test	eax, eax
2562
	jz	.exit
2570
	jz	.exit
2563
	mov	eax, [BTN_BUFF]
2571
	mov	eax, [BTN_BUFF]
2564
	shl	eax, 8
2572
	shl	eax, 8
2565
; // Alver 22.06.2008 // {
2573
; // Alver 22.06.2008 // {
2566
        mov       al, byte [btn_down_determ]
2574
        mov       al, byte [btn_down_determ]
2567
        and       al,0xFE                                       ; delete left button bit
2575
        and       al,0xFE                                       ; delete left button bit
2568
; } \\ Alver \\
2576
; } \\ Alver \\
2569
	mov	[BTN_COUNT], byte 0
2577
	mov	[BTN_COUNT], byte 0
2570
	mov	[esp + 32], eax
2578
	mov	[esp + 32], eax
2571
.exit:
2579
.exit:
2572
	ret
2580
	ret
2573
 
2581
 
2574
 
2582
 
2575
align 4
2583
align 4
2576
 
2584
 
2577
sys_cpuusage:
2585
sys_cpuusage:
2578
 
2586
 
2579
;  RETURN:
2587
;  RETURN:
2580
;
2588
;
2581
;  +00 dword     process cpu usage
2589
;  +00 dword     process cpu usage
2582
;  +04  word     position in windowing stack
2590
;  +04  word     position in windowing stack
2583
;  +06  word     windowing stack value at current position (cpu nro)
2591
;  +06  word     windowing stack value at current position (cpu nro)
2584
;  +10 12 bytes  name
2592
;  +10 12 bytes  name
2585
;  +22 dword     start in mem
2593
;  +22 dword     start in mem
2586
;  +26 dword     used mem
2594
;  +26 dword     used mem
2587
;  +30 dword     PID , process idenfification number
2595
;  +30 dword     PID , process idenfification number
2588
;
2596
;
2589
 
2597
 
2590
    cmp  ecx,-1 	; who am I ?
2598
    cmp  ecx,-1 	; who am I ?
2591
    jne  .no_who_am_i
2599
    jne  .no_who_am_i
2592
    mov  ecx,[CURRENT_TASK]
2600
    mov  ecx,[CURRENT_TASK]
2593
  .no_who_am_i:
2601
  .no_who_am_i:
2594
	cmp	ecx, max_processes
2602
	cmp	ecx, max_processes
2595
	ja	.nofillbuf
2603
	ja	.nofillbuf
2596
 
2604
 
2597
; +4: word: position of the window of thread in the window stack
2605
; +4: word: position of the window of thread in the window stack
2598
	mov	ax, [WIN_STACK + ecx * 2]
2606
	mov	ax, [WIN_STACK + ecx * 2]
2599
	mov	[ebx+4], ax
2607
	mov	[ebx+4], ax
2600
; +6: word: number of the thread slot, which window has in the window stack
2608
; +6: word: number of the thread slot, which window has in the window stack
2601
;           position ecx (has no relation to the specific thread)
2609
;           position ecx (has no relation to the specific thread)
2602
	mov	ax, [WIN_POS + ecx * 2]
2610
	mov	ax, [WIN_POS + ecx * 2]
2603
	mov	[ebx+6], ax
2611
	mov	[ebx+6], ax
2604
 
2612
 
2605
	shl	ecx, 5
2613
	shl	ecx, 5
2606
 
2614
 
2607
; +0: dword: memory usage
2615
; +0: dword: memory usage
2608
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2616
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2609
	mov	[ebx], eax
2617
	mov	[ebx], eax
2610
; +10: 11 bytes: name of the process
2618
; +10: 11 bytes: name of the process
2611
	push	ecx
2619
	push	ecx
2612
	lea	eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2620
	lea	eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2613
	add	ebx, 10
2621
	add	ebx, 10
2614
	mov	ecx, 11
2622
	mov	ecx, 11
2615
	call	memmove
2623
	call	memmove
2616
	pop	ecx
2624
	pop	ecx
2617
 
2625
 
2618
; +22: address of the process in memory
2626
; +22: address of the process in memory
2619
; +26: size of used memory - 1
2627
; +26: size of used memory - 1
2620
	push	edi
2628
	push	edi
2621
	lea	edi, [ebx+12]
2629
	lea	edi, [ebx+12]
2622
	xor	eax, eax
2630
	xor	eax, eax
2623
	mov	edx, 0x100000*16
2631
	mov	edx, 0x100000*16
2624
	cmp	ecx, 1 shl 5
2632
	cmp	ecx, 1 shl 5
2625
	je	.os_mem
2633
	je	.os_mem
2626
	mov	edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2634
	mov	edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2627
        xor eax, eax
2635
        xor eax, eax
2628
.os_mem:
2636
.os_mem:
2629
	stosd
2637
	stosd
2630
	lea	eax, [edx-1]
2638
	lea	eax, [edx-1]
2631
	stosd
2639
	stosd
2632
 
2640
 
2633
; +30: PID/TID
2641
; +30: PID/TID
2634
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2642
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2635
	stosd
2643
	stosd
2636
 
2644
 
2637
    ; window position and size
2645
    ; window position and size
2638
	push	esi
2646
	push	esi
2639
	lea	esi, [ecx + window_data + WDATA.box]
2647
	lea	esi, [ecx + window_data + WDATA.box]
2640
	movsd
2648
	movsd
2641
	movsd
2649
	movsd
2642
	movsd
2650
	movsd
2643
	movsd
2651
	movsd
2644
 
2652
 
2645
    ; Process state (+50)
2653
    ; Process state (+50)
2646
	mov	eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2654
	mov	eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2647
	stosd
2655
	stosd
2648
 
2656
 
2649
    ; Window client area box
2657
    ; Window client area box
2650
	lea	esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2658
	lea	esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2651
	movsd
2659
	movsd
2652
	movsd
2660
	movsd
2653
	movsd
2661
	movsd
2654
	movsd
2662
	movsd
2655
 
2663
 
2656
    ; Window state
2664
    ; Window state
2657
	mov	al, [ecx+window_data+WDATA.fl_wstate]
2665
	mov	al, [ecx+window_data+WDATA.fl_wstate]
2658
	stosb
2666
	stosb
2659
 
2667
 
2660
	pop	esi
2668
	pop	esi
2661
	pop	edi
2669
	pop	edi
2662
 
2670
 
2663
.nofillbuf:
2671
.nofillbuf:
2664
    ; return number of processes
2672
    ; return number of processes
2665
 
2673
 
2666
    mov    eax,[TASK_COUNT]
2674
    mov    eax,[TASK_COUNT]
2667
    mov    [esp+32],eax
2675
    mov    [esp+32],eax
2668
    ret
2676
    ret
2669
 
2677
 
2670
align 4
2678
align 4
2671
sys_clock:
2679
sys_clock:
2672
	cli
2680
	cli
2673
  ; Mikhail Lisovin  xx Jan 2005
2681
  ; Mikhail Lisovin  xx Jan 2005
2674
  @@:	mov   al, 10
2682
  @@:	mov   al, 10
2675
	out   0x70, al
2683
	out   0x70, al
2676
	in    al, 0x71
2684
	in    al, 0x71
2677
	test  al, al
2685
	test  al, al
2678
	jns   @f
2686
	jns   @f
2679
	mov   esi, 1
2687
	mov   esi, 1
2680
	call  delay_ms
2688
	call  delay_ms
2681
	jmp   @b
2689
	jmp   @b
2682
  @@:
2690
  @@:
2683
  ; end Lisovin's fix
2691
  ; end Lisovin's fix
2684
 
2692
 
2685
	xor   al,al	      ; seconds
2693
	xor   al,al	      ; seconds
2686
	out   0x70,al
2694
	out   0x70,al
2687
	in    al,0x71
2695
	in    al,0x71
2688
	movzx ecx,al
2696
	movzx ecx,al
2689
	mov   al,02	      ; minutes
2697
	mov   al,02	      ; minutes
2690
	shl   ecx,16
2698
	shl   ecx,16
2691
	out   0x70,al
2699
	out   0x70,al
2692
	in    al,0x71
2700
	in    al,0x71
2693
	movzx edx,al
2701
	movzx edx,al
2694
	mov   al,04	      ; hours
2702
	mov   al,04	      ; hours
2695
	shl   edx,8
2703
	shl   edx,8
2696
	out   0x70,al
2704
	out   0x70,al
2697
	in    al,0x71
2705
	in    al,0x71
2698
	add   ecx,edx
2706
	add   ecx,edx
2699
	movzx edx,al
2707
	movzx edx,al
2700
	add   ecx,edx
2708
	add   ecx,edx
2701
	sti
2709
	sti
2702
	mov	[esp + 32], ecx
2710
	mov	[esp + 32], ecx
2703
	ret
2711
	ret
2704
 
2712
 
2705
 
2713
 
2706
align 4
2714
align 4
2707
 
2715
 
2708
sys_date:
2716
sys_date:
2709
 
2717
 
2710
	cli
2718
	cli
2711
  @@:	mov   al, 10
2719
  @@:	mov   al, 10
2712
	out   0x70, al
2720
	out   0x70, al
2713
	in    al, 0x71
2721
	in    al, 0x71
2714
	test  al, al
2722
	test  al, al
2715
	jns   @f
2723
	jns   @f
2716
	mov   esi, 1
2724
	mov   esi, 1
2717
	call  delay_ms
2725
	call  delay_ms
2718
	jmp   @b
2726
	jmp   @b
2719
  @@:
2727
  @@:
2720
 
2728
 
2721
	mov	ch,0
2729
	mov	ch,0
2722
	mov	al,7		; date
2730
	mov	al,7		; date
2723
	out	0x70,al
2731
	out	0x70,al
2724
	in	al,0x71
2732
	in	al,0x71
2725
	mov	cl,al
2733
	mov	cl,al
2726
	mov	al,8		; month
2734
	mov	al,8		; month
2727
	shl	ecx,16
2735
	shl	ecx,16
2728
	out	0x70,al
2736
	out	0x70,al
2729
	in	al,0x71
2737
	in	al,0x71
2730
	mov	ch,al
2738
	mov	ch,al
2731
	mov	al,9		; year
2739
	mov	al,9		; year
2732
	out	0x70,al
2740
	out	0x70,al
2733
	in	al,0x71
2741
	in	al,0x71
2734
	mov	cl,al
2742
	mov	cl,al
2735
	sti
2743
	sti
2736
	mov	[esp+32], ecx
2744
	mov	[esp+32], ecx
2737
	ret
2745
	ret
2738
 
2746
 
2739
 
2747
 
2740
; redraw status
2748
; redraw status
2741
 
2749
 
2742
sys_redrawstat:
2750
sys_redrawstat:
2743
	cmp	ebx, 1
2751
	cmp	ebx, 1
2744
	jne	no_widgets_away
2752
	jne	no_widgets_away
2745
	; buttons away
2753
	; buttons away
2746
	mov	ecx,[CURRENT_TASK]
2754
	mov	ecx,[CURRENT_TASK]
2747
  sys_newba2:
2755
  sys_newba2:
2748
	mov	edi,[BTN_ADDR]
2756
	mov	edi,[BTN_ADDR]
2749
	cmp	[edi], dword 0	; empty button list ?
2757
	cmp	[edi], dword 0	; empty button list ?
2750
	je	end_of_buttons_away
2758
	je	end_of_buttons_away
2751
	movzx	ebx, word [edi]
2759
	movzx	ebx, word [edi]
2752
	inc	ebx
2760
	inc	ebx
2753
	mov	eax,edi
2761
	mov	eax,edi
2754
  sys_newba:
2762
  sys_newba:
2755
	dec	ebx
2763
	dec	ebx
2756
	jz	end_of_buttons_away
2764
	jz	end_of_buttons_away
2757
 
2765
 
2758
	add	eax, 0x10
2766
	add	eax, 0x10
2759
	cmp	cx, [eax]
2767
	cmp	cx, [eax]
2760
	jnz	sys_newba
2768
	jnz	sys_newba
2761
 
2769
 
2762
	push	eax ebx ecx
2770
	push	eax ebx ecx
2763
	mov	ecx,ebx
2771
	mov	ecx,ebx
2764
	inc	ecx
2772
	inc	ecx
2765
	shl	ecx, 4
2773
	shl	ecx, 4
2766
	mov	ebx, eax
2774
	mov	ebx, eax
2767
	add	eax, 0x10
2775
	add	eax, 0x10
2768
	call	memmove
2776
	call	memmove
2769
	dec	dword [edi]
2777
	dec	dword [edi]
2770
	pop	ecx ebx eax
2778
	pop	ecx ebx eax
2771
 
2779
 
2772
	jmp	sys_newba2
2780
	jmp	sys_newba2
2773
 
2781
 
2774
  end_of_buttons_away:
2782
  end_of_buttons_away:
2775
 
2783
 
2776
	ret
2784
	ret
2777
 
2785
 
2778
  no_widgets_away:
2786
  no_widgets_away:
2779
 
2787
 
2780
	cmp	ebx, 2
2788
	cmp	ebx, 2
2781
	jnz	srl1
2789
	jnz	srl1
2782
 
2790
 
2783
	mov	edx, [TASK_BASE]      ; return whole screen draw area for this app
2791
	mov	edx, [TASK_BASE]      ; return whole screen draw area for this app
2784
	add	edx, draw_data - CURRENT_TASK
2792
	add	edx, draw_data - CURRENT_TASK
2785
	mov	[edx + RECT.left], 0
2793
	mov	[edx + RECT.left], 0
2786
	mov	[edx + RECT.top], 0
2794
	mov	[edx + RECT.top], 0
2787
	mov	eax, [Screen_Max_X]
2795
	mov	eax, [Screen_Max_X]
2788
	mov	[edx + RECT.right], eax
2796
	mov	[edx + RECT.right], eax
2789
	mov	eax, [Screen_Max_Y]
2797
	mov	eax, [Screen_Max_Y]
2790
	mov	[edx + RECT.bottom], eax
2798
	mov	[edx + RECT.bottom], eax
2791
 
2799
 
2792
	mov	edi, [TASK_BASE]
2800
	mov	edi, [TASK_BASE]
2793
	or	[edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2801
	or	[edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2794
	call	sys_window_mouse
2802
	call	sys_window_mouse
2795
	ret
2803
	ret
2796
 
2804
 
2797
  srl1:
2805
  srl1:
2798
	ret
2806
	ret
2799
 
2807
 
2800
 
2808
 
2801
sys_drawwindow:
2809
sys_drawwindow:
2802
 
2810
 
2803
    mov   eax,edx
2811
    mov   eax,edx
2804
    shr   eax,16+8
2812
    shr   eax,16+8
2805
    and   eax,15
2813
    and   eax,15
2806
 
2814
 
2807
;    cmp   eax,0   ; type I    - original style
2815
;    cmp   eax,0   ; type I    - original style
2808
    jne   nosyswI
2816
    jne   nosyswI
2809
    inc   [mouse_pause]
2817
    inc   [mouse_pause]
2810
    call  [disable_mouse]
2818
    call  [disable_mouse]
2811
    call  sys_set_window
2819
    call  sys_set_window
2812
    call  [disable_mouse]
2820
    call  [disable_mouse]
2813
    call  drawwindow_I
2821
    call  drawwindow_I
2814
    ;dec   [mouse_pause]
2822
    ;dec   [mouse_pause]
2815
    ;call   [draw_pointer]
2823
    ;call   [draw_pointer]
2816
    ;ret
2824
    ;ret
2817
    jmp   draw_window_caption.2
2825
    jmp   draw_window_caption.2
2818
  nosyswI:
2826
  nosyswI:
2819
 
2827
 
2820
    cmp   al,1	  ; type II   - only reserve area, no draw
2828
    cmp   al,1	  ; type II   - only reserve area, no draw
2821
    jne   nosyswII
2829
    jne   nosyswII
2822
    inc   [mouse_pause]
2830
    inc   [mouse_pause]
2823
    call  [disable_mouse]
2831
    call  [disable_mouse]
2824
    call  sys_set_window
2832
    call  sys_set_window
2825
    call  [disable_mouse]
2833
    call  [disable_mouse]
2826
    call  sys_window_mouse
2834
    call  sys_window_mouse
2827
    dec   [mouse_pause]
2835
    dec   [mouse_pause]
2828
    call   [draw_pointer]
2836
    call   [draw_pointer]
2829
    ret
2837
    ret
2830
  nosyswII:
2838
  nosyswII:
2831
 
2839
 
2832
    cmp   al,2	  ; type III  - new style
2840
    cmp   al,2	  ; type III  - new style
2833
    jne   nosyswIII
2841
    jne   nosyswIII
2834
    inc   [mouse_pause]
2842
    inc   [mouse_pause]
2835
    call  [disable_mouse]
2843
    call  [disable_mouse]
2836
    call  sys_set_window
2844
    call  sys_set_window
2837
    call  [disable_mouse]
2845
    call  [disable_mouse]
2838
    call  drawwindow_III
2846
    call  drawwindow_III
2839
    ;dec   [mouse_pause]
2847
    ;dec   [mouse_pause]
2840
    ;call   [draw_pointer]
2848
    ;call   [draw_pointer]
2841
    ;ret
2849
    ;ret
2842
    jmp   draw_window_caption.2
2850
    jmp   draw_window_caption.2
2843
  nosyswIII:
2851
  nosyswIII:
2844
 
2852
 
2845
    cmp   al,3	  ; type IV - skinned window
2853
    cmp   al,3	  ; type IV - skinned window
2846
    je	  draw_skin_window
2854
    je	  draw_skin_window
2847
    cmp   al,4	  ; type V - skinned window not sized! {not_sized_skin_window}
2855
    cmp   al,4	  ; type V - skinned window not sized! {not_sized_skin_window}
2848
    jne   nosyswV
2856
    jne   nosyswV
2849
  draw_skin_window:
2857
  draw_skin_window:
2850
 
2858
 
2851
    inc   [mouse_pause]
2859
    inc   [mouse_pause]
2852
    call  [disable_mouse]
2860
    call  [disable_mouse]
2853
    call  sys_set_window
2861
    call  sys_set_window
2854
    call  [disable_mouse]
2862
    call  [disable_mouse]
2855
    mov   eax, [TASK_COUNT]
2863
    mov   eax, [TASK_COUNT]
2856
    movzx eax, word [WIN_POS + eax*2]
2864
    movzx eax, word [WIN_POS + eax*2]
2857
    cmp   eax, [CURRENT_TASK]
2865
    cmp   eax, [CURRENT_TASK]
2858
    setz  al
2866
    setz  al
2859
    movzx eax, al
2867
    movzx eax, al
2860
    push  eax
2868
    push  eax
2861
    call  drawwindow_IV
2869
    call  drawwindow_IV
2862
    ;dec   [mouse_pause]
2870
    ;dec   [mouse_pause]
2863
    ;call   [draw_pointer]
2871
    ;call   [draw_pointer]
2864
    ;ret
2872
    ;ret
2865
    jmp   draw_window_caption.2
2873
    jmp   draw_window_caption.2
2866
  nosyswV:
2874
  nosyswV:
2867
 
2875
 
2868
    ret
2876
    ret
2869
 
2877
 
2870
 
2878
 
2871
draw_window_caption:
2879
draw_window_caption:
2872
	inc	[mouse_pause]
2880
	inc	[mouse_pause]
2873
	call	[disable_mouse]
2881
	call	[disable_mouse]
2874
 
2882
 
2875
	xor	eax,eax
2883
	xor	eax,eax
2876
	mov	edx,[TASK_COUNT]
2884
	mov	edx,[TASK_COUNT]
2877
	movzx	edx,word[WIN_POS+edx*2]
2885
	movzx	edx,word[WIN_POS+edx*2]
2878
	cmp	edx,[CURRENT_TASK]
2886
	cmp	edx,[CURRENT_TASK]
2879
	jne	@f
2887
	jne	@f
2880
	inc	eax
2888
	inc	eax
2881
    @@: mov	edx,[CURRENT_TASK]
2889
    @@: mov	edx,[CURRENT_TASK]
2882
	shl	edx,5
2890
	shl	edx,5
2883
	add	edx,window_data
2891
	add	edx,window_data
2884
	movzx	ebx,[edx+WDATA.fl_wstyle]
2892
	movzx	ebx,[edx+WDATA.fl_wstyle]
2885
	and	bl,0x0F
2893
	and	bl,0x0F
2886
	cmp	bl,3
2894
	cmp	bl,3
2887
	je	.draw_caption_style_3		;{for 3 and 4 style write caption}
2895
	je	.draw_caption_style_3		;{for 3 and 4 style write caption}
2888
	cmp	bl,4
2896
	cmp	bl,4
2889
	je	.draw_caption_style_3
2897
	je	.draw_caption_style_3
2890
 
2898
 
2891
	jmp	.not_style_3
2899
	jmp	.not_style_3
2892
  .draw_caption_style_3:
2900
  .draw_caption_style_3:
2893
 
2901
 
2894
	push	edx
2902
	push	edx
2895
	call	drawwindow_IV_caption
2903
	call	drawwindow_IV_caption
2896
	add	esp,4
2904
	add	esp,4
2897
	jmp	.2
2905
	jmp	.2
2898
 
2906
 
2899
  .not_style_3:
2907
  .not_style_3:
2900
	cmp	bl,2
2908
	cmp	bl,2
2901
	jne	.not_style_2
2909
	jne	.not_style_2
2902
 
2910
 
2903
	call	drawwindow_III_caption
2911
	call	drawwindow_III_caption
2904
	jmp	.2
2912
	jmp	.2
2905
 
2913
 
2906
  .not_style_2:
2914
  .not_style_2:
2907
	cmp	bl,0
2915
	cmp	bl,0
2908
	jne	.2
2916
	jne	.2
2909
 
2917
 
2910
	call	drawwindow_I_caption
2918
	call	drawwindow_I_caption
2911
 
2919
 
2912
;--------------------------------------------------------------
2920
;--------------------------------------------------------------
2913
  .2:	;jmp     @f
2921
  .2:	;jmp     @f
2914
	mov	edi,[CURRENT_TASK]
2922
	mov	edi,[CURRENT_TASK]
2915
	shl	edi,5
2923
	shl	edi,5
2916
	test	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2924
	test	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2917
	jz	@f
2925
	jz	@f
2918
	mov	edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2926
	mov	edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2919
	or	edx,edx
2927
	or	edx,edx
2920
	jz	@f
2928
	jz	@f
2921
 
2929
 
2922
	movzx	eax,[edi+window_data+WDATA.fl_wstyle]
2930
	movzx	eax,[edi+window_data+WDATA.fl_wstyle]
2923
	and	al,0x0F
2931
	and	al,0x0F
2924
	cmp	al,3
2932
	cmp	al,3
2925
	je	.skinned
2933
	je	.skinned
2926
	cmp	al,4
2934
	cmp	al,4
2927
	je	.skinned
2935
	je	.skinned
2928
 
2936
 
2929
	jmp	.not_skinned
2937
	jmp	.not_skinned
2930
  .skinned:
2938
  .skinned:
2931
	mov	ebp,[edi+window_data+WDATA.box.left-2]
2939
	mov	ebp,[edi+window_data+WDATA.box.left-2]
2932
	mov	bp,word[edi+window_data+WDATA.box.top]
2940
	mov	bp,word[edi+window_data+WDATA.box.top]
2933
	movzx	eax,word[edi+window_data+WDATA.box.width]
2941
	movzx	eax,word[edi+window_data+WDATA.box.width]
2934
	sub	ax,[_skinmargins.left]
2942
	sub	ax,[_skinmargins.left]
2935
	sub	ax,[_skinmargins.right]
2943
	sub	ax,[_skinmargins.right]
2936
	push	edx
2944
	push	edx
2937
	cwde
2945
	cwde
2938
	cdq
2946
	cdq
2939
	mov	ebx,6
2947
	mov	ebx,6
2940
	idiv	ebx
2948
	idiv	ebx
2941
	pop	edx
2949
	pop	edx
2942
	or	eax,eax
2950
	or	eax,eax
2943
	js	@f
2951
	js	@f
2944
	mov	esi,eax
2952
	mov	esi,eax
2945
	mov	ebx,dword[_skinmargins.left-2]
2953
	mov	ebx,dword[_skinmargins.left-2]
2946
	mov	bx,word[_skinh]
2954
	mov	bx,word[_skinh]
2947
	sub	bx,[_skinmargins.bottom]
2955
	sub	bx,[_skinmargins.bottom]
2948
	sub	bx,[_skinmargins.top]
2956
	sub	bx,[_skinmargins.top]
2949
	sar	bx,1
2957
	sar	bx,1
2950
	adc	bx,0
2958
	adc	bx,0
2951
	add	bx,[_skinmargins.top]
2959
	add	bx,[_skinmargins.top]
2952
	add	bx,-3
2960
	add	bx,-3
2953
	add	ebx,ebp
2961
	add	ebx,ebp
2954
	jmp	.dodraw
2962
	jmp	.dodraw
2955
 
2963
 
2956
  .not_skinned:
2964
  .not_skinned:
2957
	cmp	al,1
2965
	cmp	al,1
2958
	je	@f
2966
	je	@f
2959
 
2967
 
2960
	mov	ebp,[edi+window_data+WDATA.box.left-2]
2968
	mov	ebp,[edi+window_data+WDATA.box.left-2]
2961
	mov	bp,word[edi+window_data+WDATA.box.top]
2969
	mov	bp,word[edi+window_data+WDATA.box.top]
2962
	movzx	eax,word[edi+window_data+WDATA.box.width]
2970
	movzx	eax,word[edi+window_data+WDATA.box.width]
2963
	sub	eax,16
2971
	sub	eax,16
2964
	push	edx
2972
	push	edx
2965
	cwde
2973
	cwde
2966
	cdq
2974
	cdq
2967
	mov	ebx,6
2975
	mov	ebx,6
2968
	idiv	ebx
2976
	idiv	ebx
2969
	pop	edx
2977
	pop	edx
2970
	or	eax,eax
2978
	or	eax,eax
2971
	js	@f
2979
	js	@f
2972
	mov	esi,eax
2980
	mov	esi,eax
2973
	mov	ebx,0x00080007
2981
	mov	ebx,0x00080007
2974
	add	ebx,ebp
2982
	add	ebx,ebp
2975
.dodraw:
2983
.dodraw:
2976
	mov	ecx,[common_colours+16];0x00FFFFFF
2984
	mov	ecx,[common_colours+16];0x00FFFFFF
2977
	or	ecx, 0x80000000
2985
	or	ecx, 0x80000000
2978
	xor	edi,edi
2986
	xor	edi,edi
2979
; // Alver 22.06.2008 // {
2987
; // Alver 22.06.2008 // {
2980
;	call	dtext
2988
;	call	dtext
2981
        call dtext_asciiz_esi
2989
        call dtext_asciiz_esi
2982
; } \\ Alver \\
2990
; } \\ Alver \\
2983
 
2991
 
2984
    @@:
2992
    @@:
2985
;--------------------------------------------------------------
2993
;--------------------------------------------------------------
2986
	dec	[mouse_pause]
2994
	dec	[mouse_pause]
2987
	call	[draw_pointer]
2995
	call	[draw_pointer]
2988
	ret
2996
	ret
2989
 
2997
 
2990
iglobal
2998
iglobal
2991
align 4
2999
align 4
2992
window_topleft dd \
3000
window_topleft dd \
2993
  1, 21,\		;type 0
3001
  1, 21,\		;type 0
2994
  0,  0,\	;type 1
3002
  0,  0,\	;type 1
2995
  5, 20,\	;type 2
3003
  5, 20,\	;type 2
2996
  5,  ?,\	;type 3 {set by skin}
3004
  5,  ?,\	;type 3 {set by skin}
2997
  5,  ? 	;type 4 {set by skin}
3005
  5,  ? 	;type 4 {set by skin}
2998
endg
3006
endg
2999
 
3007
 
3000
set_window_clientbox:
3008
set_window_clientbox:
3001
	push	eax ecx edi
3009
	push	eax ecx edi
3002
 
3010
 
3003
	mov	eax,[_skinh]
3011
	mov	eax,[_skinh]
3004
	mov	[window_topleft+4*7],eax
3012
	mov	[window_topleft+4*7],eax
3005
	mov	[window_topleft+4*9],eax
3013
	mov	[window_topleft+4*9],eax
3006
 
3014
 
3007
	mov	ecx,edi
3015
	mov	ecx,edi
3008
	sub	edi,window_data
3016
	sub	edi,window_data
3009
	shl	edi,3
3017
	shl	edi,3
3010
	test	[ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3018
	test	[ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3011
	jz	@f
3019
	jz	@f
3012
 
3020
 
3013
	movzx	eax,[ecx+WDATA.fl_wstyle]
3021
	movzx	eax,[ecx+WDATA.fl_wstyle]
3014
	and	eax,0x0F
3022
	and	eax,0x0F
3015
	mov	eax,[eax*8+window_topleft+0]
3023
	mov	eax,[eax*8+window_topleft+0]
3016
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3024
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3017
	shl	eax,1
3025
	shl	eax,1
3018
	neg	eax
3026
	neg	eax
3019
	add	eax,[ecx+WDATA.box.width]
3027
	add	eax,[ecx+WDATA.box.width]
3020
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3028
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3021
 
3029
 
3022
	movzx	eax,[ecx+WDATA.fl_wstyle]
3030
	movzx	eax,[ecx+WDATA.fl_wstyle]
3023
	and	eax,0x0F
3031
	and	eax,0x0F
3024
	push	[eax*8+window_topleft+0]
3032
	push	[eax*8+window_topleft+0]
3025
	mov	eax,[eax*8+window_topleft+4]
3033
	mov	eax,[eax*8+window_topleft+4]
3026
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3034
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3027
	neg	eax
3035
	neg	eax
3028
	sub	eax,[esp]
3036
	sub	eax,[esp]
3029
	add	eax,[ecx+WDATA.box.height]
3037
	add	eax,[ecx+WDATA.box.height]
3030
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3038
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3031
	add	esp,4
3039
	add	esp,4
3032
 
3040
 
3033
	pop	edi ecx eax
3041
	pop	edi ecx eax
3034
	ret
3042
	ret
3035
    @@:
3043
    @@:
3036
	xor	eax,eax
3044
	xor	eax,eax
3037
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3045
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3038
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3046
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3039
	mov	eax,[ecx+WDATA.box.width]
3047
	mov	eax,[ecx+WDATA.box.width]
3040
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3048
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3041
	mov	eax,[ecx+WDATA.box.height]
3049
	mov	eax,[ecx+WDATA.box.height]
3042
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3050
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3043
 
3051
 
3044
	pop	edi ecx eax
3052
	pop	edi ecx eax
3045
	ret
3053
	ret
3046
 
3054
 
3047
sys_set_window:
3055
sys_set_window:
3048
 
3056
 
3049
    mov   eax,[CURRENT_TASK]
3057
    mov   eax,[CURRENT_TASK]
3050
    shl   eax,5
3058
    shl   eax,5
3051
    add   eax,window_data
3059
    add   eax,window_data
3052
 
3060
 
3053
    ; colors
3061
    ; colors
3054
    mov   [eax+WDATA.cl_workarea],edx
3062
    mov   [eax+WDATA.cl_workarea],edx
3055
    mov   [eax+WDATA.cl_titlebar],esi
3063
    mov   [eax+WDATA.cl_titlebar],esi
3056
    mov   [eax+WDATA.cl_frames],edi
3064
    mov   [eax+WDATA.cl_frames],edi
3057
 
3065
 
3058
    mov   edi, eax
3066
    mov   edi, eax
3059
 
3067
 
3060
    ; check flag (?)
3068
    ; check flag (?)
3061
    test  [edi+WDATA.fl_wdrawn],1
3069
    test  [edi+WDATA.fl_wdrawn],1
3062
    jnz   newd
3070
    jnz   newd
3063
 
3071
 
3064
    mov   eax,[timer_ticks] ;[0xfdf0]
3072
    mov   eax,[timer_ticks] ;[0xfdf0]
3065
    add   eax,100
3073
    add   eax,100
3066
    mov   [new_window_starting],eax
3074
    mov   [new_window_starting],eax
3067
 
3075
 
3068
    movsx eax,bx
3076
    movsx eax,bx
3069
    mov   [edi+WDATA.box.width],eax
3077
    mov   [edi+WDATA.box.width],eax
3070
    movsx eax,cx
3078
    movsx eax,cx
3071
    mov   [edi+WDATA.box.height],eax
3079
    mov   [edi+WDATA.box.height],eax
3072
    sar   ebx,16
3080
    sar   ebx,16
3073
    sar   ecx,16
3081
    sar   ecx,16
3074
    mov   [edi+WDATA.box.left],ebx
3082
    mov   [edi+WDATA.box.left],ebx
3075
    mov   [edi+WDATA.box.top],ecx
3083
    mov   [edi+WDATA.box.top],ecx
3076
 
3084
 
3077
    call  check_window_position
3085
    call  check_window_position
3078
 
3086
 
3079
    call  set_window_clientbox
3087
    call  set_window_clientbox
3080
 
3088
 
3081
    push  ecx esi edi		    ; save for window fullscreen/resize
3089
    push  ecx esi edi		    ; save for window fullscreen/resize
3082
    ;mov   esi,edi
3090
    ;mov   esi,edi
3083
 
3091
 
3084
	mov	cl, [edi+WDATA.fl_wstyle]
3092
	mov	cl, [edi+WDATA.fl_wstyle]
3085
	mov	eax, [edi+WDATA.cl_frames]
3093
	mov	eax, [edi+WDATA.cl_frames]
3086
 
3094
 
3087
    sub   edi,window_data
3095
    sub   edi,window_data
3088
    shl   edi,3
3096
    shl   edi,3
3089
    add   edi,SLOT_BASE
3097
    add   edi,SLOT_BASE
3090
 
3098
 
3091
	and	cl,0x0F
3099
	and	cl,0x0F
3092
	mov	[edi+APPDATA.wnd_caption],0
3100
	mov	[edi+APPDATA.wnd_caption],0
3093
	cmp	cl,3
3101
	cmp	cl,3
3094
	je	set_APPDATA_wnd_caption
3102
	je	set_APPDATA_wnd_caption
3095
	cmp	cl,4								; {SPraid.simba}
3103
	cmp	cl,4								; {SPraid.simba}
3096
	je	set_APPDATA_wnd_caption
3104
	je	set_APPDATA_wnd_caption
3097
 
3105
 
3098
	jmp	@f
3106
	jmp	@f
3099
    set_APPDATA_wnd_caption:
3107
    set_APPDATA_wnd_caption:
3100
	mov	[edi+APPDATA.wnd_caption],eax
3108
	mov	[edi+APPDATA.wnd_caption],eax
3101
    @@: mov	esi,[esp+0]
3109
    @@: mov	esi,[esp+0]
3102
 
3110
 
3103
    add   edi, APPDATA.saved_box
3111
    add   edi, APPDATA.saved_box
3104
	movsd
3112
	movsd
3105
	movsd
3113
	movsd
3106
	movsd
3114
	movsd
3107
	movsd
3115
	movsd
3108
    pop   edi esi ecx
3116
    pop   edi esi ecx
3109
 
3117
 
3110
	mov	esi, [CURRENT_TASK]
3118
	mov	esi, [CURRENT_TASK]
3111
	movzx	esi, word [WIN_STACK+esi*2]
3119
	movzx	esi, word [WIN_STACK+esi*2]
3112
	lea	esi, [WIN_POS+esi*2]
3120
	lea	esi, [WIN_POS+esi*2]
3113
	call	waredraw
3121
	call	waredraw
3114
 
3122
 
3115
;;;    mov   ebx, 1
3123
;;;    mov   ebx, 1
3116
;;;    call  delay_hs
3124
;;;    call  delay_hs
3117
    mov   eax, [edi+WDATA.box.left]
3125
    mov   eax, [edi+WDATA.box.left]
3118
    mov   ebx, [edi+WDATA.box.top]
3126
    mov   ebx, [edi+WDATA.box.top]
3119
    mov   ecx, [edi+WDATA.box.width]
3127
    mov   ecx, [edi+WDATA.box.width]
3120
    mov   edx, [edi+WDATA.box.height]
3128
    mov   edx, [edi+WDATA.box.height]
3121
    add   ecx, eax
3129
    add   ecx, eax
3122
    add   edx, ebx
3130
    add   edx, ebx
3123
    call  calculatescreen
3131
    call  calculatescreen
3124
 
3132
 
3125
    mov   [KEY_COUNT],byte 0	       ; empty keyboard buffer
3133
    mov   [KEY_COUNT],byte 0	       ; empty keyboard buffer
3126
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
3134
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
3127
 
3135
 
3128
  newd:
3136
  newd:
3129
    mov   [edi+WDATA.fl_redraw],byte 0	 ; no redraw
3137
    mov   [edi+WDATA.fl_redraw],byte 0	 ; no redraw
3130
    mov   edx,edi
3138
    mov   edx,edi
3131
 
3139
 
3132
    ret
3140
    ret
3133
 
3141
 
3134
syscall_windowsettings:
3142
syscall_windowsettings:
3135
 
3143
 
3136
  .set_window_caption:
3144
  .set_window_caption:
3137
	dec	eax	; subfunction #1 - set window caption
3145
	dec	eax	; subfunction #1 - set window caption
3138
	jnz	.get_window_caption
3146
	jnz	.get_window_caption
3139
 
3147
 
3140
	; NOTE: only window owner thread can set its caption,
3148
	; NOTE: only window owner thread can set its caption,
3141
	;       so there's no parameter for PID/TID
3149
	;       so there's no parameter for PID/TID
3142
 
3150
 
3143
	mov	edi,[CURRENT_TASK]
3151
	mov	edi,[CURRENT_TASK]
3144
	shl	edi,5
3152
	shl	edi,5
3145
 
3153
 
3146
	; have to check if caption is within application memory limit
3154
	; have to check if caption is within application memory limit
3147
	; check is trivial, and if application resizes its memory,
3155
	; check is trivial, and if application resizes its memory,
3148
	;   caption still can become over bounds
3156
	;   caption still can become over bounds
3149
; diamond, 31.10.2006: check removed because with new memory manager
3157
; diamond, 31.10.2006: check removed because with new memory manager
3150
; there can be valid data after APPDATA.mem_size bound
3158
; there can be valid data after APPDATA.mem_size bound
3151
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3159
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3152
;        add     ecx,255 ; max caption length
3160
;        add     ecx,255 ; max caption length
3153
;        cmp     ebx,ecx
3161
;        cmp     ebx,ecx
3154
;        ja      .exit_fail
3162
;        ja      .exit_fail
3155
 
3163
 
3156
	mov	[edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3164
	mov	[edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3157
	or	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3165
	or	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3158
 
3166
 
3159
	call	draw_window_caption
3167
	call	draw_window_caption
3160
 
3168
 
3161
	xor	eax,eax ; eax = 0 (success)
3169
	xor	eax,eax ; eax = 0 (success)
3162
	ret
3170
	ret
3163
 
3171
 
3164
  .get_window_caption:
3172
  .get_window_caption:
3165
	dec	eax	; subfunction #2 - get window caption
3173
	dec	eax	; subfunction #2 - get window caption
3166
	jnz	.exit_fail
3174
	jnz	.exit_fail
3167
 
3175
 
3168
	; not implemented yet
3176
	; not implemented yet
3169
 
3177
 
3170
  .exit_fail:
3178
  .exit_fail:
3171
	xor	eax,eax
3179
	xor	eax,eax
3172
	inc	eax	; eax = 1 (fail)
3180
	inc	eax	; eax = 1 (fail)
3173
	ret
3181
	ret
3174
 
3182
 
3175
 
3183
 
3176
sys_window_move:
3184
sys_window_move:
3177
 
3185
 
3178
	mov	edi,[CURRENT_TASK]
3186
	mov	edi,[CURRENT_TASK]
3179
	shl	edi,5
3187
	shl	edi,5
3180
	add	edi,window_data
3188
	add	edi,window_data
3181
 
3189
 
3182
	test	[edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3190
	test	[edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3183
	jnz	.window_move_return
3191
	jnz	.window_move_return
3184
 
3192
 
3185
	push	dword [edi + WDATA.box.left]  ; save old coordinates
3193
	push	dword [edi + WDATA.box.left]  ; save old coordinates
3186
	push	dword [edi + WDATA.box.top]
3194
	push	dword [edi + WDATA.box.top]
3187
	push	dword [edi + WDATA.box.width]
3195
	push	dword [edi + WDATA.box.width]
3188
	push	dword [edi + WDATA.box.height]
3196
	push	dword [edi + WDATA.box.height]
3189
 
3197
 
3190
	cmp   eax,-1		      ; set new position and size
3198
	cmp   eax,-1		      ; set new position and size
3191
	je    .no_x_reposition
3199
	je    .no_x_reposition
3192
	mov	[edi + WDATA.box.left], eax
3200
	mov	[edi + WDATA.box.left], eax
3193
      .no_x_reposition:
3201
      .no_x_reposition:
3194
	cmp   ebx,-1
3202
	cmp   ebx,-1
3195
	je    .no_y_reposition
3203
	je    .no_y_reposition
3196
	mov	[edi + WDATA.box.top], ebx
3204
	mov	[edi + WDATA.box.top], ebx
3197
      .no_y_reposition:
3205
      .no_y_reposition:
3198
 
3206
 
3199
	test	[edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3207
	test	[edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3200
	jnz	.no_y_resizing
3208
	jnz	.no_y_resizing
3201
 
3209
 
3202
	cmp   ecx,-1
3210
	cmp   ecx,-1
3203
	je    .no_x_resizing
3211
	je    .no_x_resizing
3204
	mov	[edi + WDATA.box.width], ecx
3212
	mov	[edi + WDATA.box.width], ecx
3205
      .no_x_resizing:
3213
      .no_x_resizing:
3206
	cmp   edx,-1
3214
	cmp   edx,-1
3207
	je    .no_y_resizing
3215
	je    .no_y_resizing
3208
	mov	[edi + WDATA.box.height], edx
3216
	mov	[edi + WDATA.box.height], edx
3209
      .no_y_resizing:
3217
      .no_y_resizing:
3210
 
3218
 
3211
	call  check_window_position
3219
	call  check_window_position
3212
	call  set_window_clientbox
3220
	call  set_window_clientbox
3213
 
3221
 
3214
	pushad			     ; save for window fullscreen/resize
3222
	pushad			     ; save for window fullscreen/resize
3215
	mov   esi,edi
3223
	mov   esi,edi
3216
	sub   edi,window_data
3224
	sub   edi,window_data
3217
	shr   edi,5
3225
	shr   edi,5
3218
	shl   edi,8
3226
	shl   edi,8
3219
	add   edi, SLOT_BASE + APPDATA.saved_box
3227
	add   edi, SLOT_BASE + APPDATA.saved_box
3220
	mov   ecx,4
3228
	mov   ecx,4
3221
	cld
3229
	cld
3222
	rep   movsd
3230
	rep   movsd
3223
	popad
3231
	popad
3224
 
3232
 
3225
	pushad			     ; calculcate screen at new position
3233
	pushad			     ; calculcate screen at new position
3226
	mov   eax, [edi + WDATA.box.left]
3234
	mov   eax, [edi + WDATA.box.left]
3227
	mov   ebx, [edi + WDATA.box.top]
3235
	mov   ebx, [edi + WDATA.box.top]
3228
	mov   ecx, [edi + WDATA.box.width]
3236
	mov   ecx, [edi + WDATA.box.width]
3229
	mov   edx, [edi + WDATA.box.height]
3237
	mov   edx, [edi + WDATA.box.height]
3230
	add   ecx,eax
3238
	add   ecx,eax
3231
	add   edx,ebx
3239
	add   edx,ebx
3232
 
3240
 
3233
	call  calculatescreen
3241
	call  calculatescreen
3234
	popad
3242
	popad
3235
 
3243
 
3236
	pop   edx		    ; calculcate screen at old position
3244
	pop   edx		    ; calculcate screen at old position
3237
	pop   ecx
3245
	pop   ecx
3238
	pop   ebx
3246
	pop   ebx
3239
	pop   eax
3247
	pop   eax
3240
	add   ecx,eax
3248
	add   ecx,eax
3241
	add   edx,ebx
3249
	add   edx,ebx
3242
	mov   [dlx],eax 	    ; save for drawlimits
3250
	mov   [dlx],eax 	    ; save for drawlimits
3243
	mov   [dly],ebx
3251
	mov   [dly],ebx
3244
	mov   [dlxe],ecx
3252
	mov   [dlxe],ecx
3245
	mov   [dlye],edx
3253
	mov   [dlye],edx
3246
	call  calculatescreen
3254
	call  calculatescreen
3247
 
3255
 
3248
	mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3256
	mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3249
 
3257
 
3250
	mov   eax,edi		    ; redraw screen at old position
3258
	mov   eax,edi		    ; redraw screen at old position
3251
	xor   esi,esi
3259
	xor   esi,esi
3252
	call  redrawscreen
3260
	call  redrawscreen
3253
 
3261
 
3254
	mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3262
	mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3255
	mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3263
	mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3256
	mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3264
	mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3257
 
3265
 
3258
	call  [draw_pointer]
3266
	call  [draw_pointer]
3259
 
3267
 
3260
	mov   [window_move_pr],0
3268
	mov   [window_move_pr],0
3261
 
3269
 
3262
      .window_move_return:
3270
      .window_move_return:
3263
 
3271
 
3264
	ret
3272
	ret
3265
 
3273
 
3266
uglobal
3274
uglobal
3267
  window_move_pr   dd  0x0
3275
  window_move_pr   dd  0x0
3268
  window_move_eax  dd  0x0
3276
  window_move_eax  dd  0x0
3269
  window_move_ebx  dd  0x0
3277
  window_move_ebx  dd  0x0
3270
  window_move_ecx  dd  0x0
3278
  window_move_ecx  dd  0x0
3271
  window_move_edx  dd  0x0
3279
  window_move_edx  dd  0x0
3272
endg
3280
endg
3273
 
3281
 
3274
;ok - 100% work
3282
;ok - 100% work
3275
;nt - not tested
3283
;nt - not tested
3276
;---------------------------------------------------------------------------------------------
3284
;---------------------------------------------------------------------------------------------
3277
;eax
3285
;eax
3278
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3286
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3279
;1 - change task. Ret nothing. Block. ok.
3287
;1 - change task. Ret nothing. Block. ok.
3280
;2 - performance control
3288
;2 - performance control
3281
; ebx
3289
; ebx
3282
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3290
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3283
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3291
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3284
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3292
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3285
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3293
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3286
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3294
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3287
;eax
3295
;eax
3288
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3296
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3289
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3297
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3290
;---------------------------------------------------------------------------------------------
3298
;---------------------------------------------------------------------------------------------
3291
sys_sheduler: ;noname & halyavin
3299
sys_sheduler: ;noname & halyavin
3292
    cmp eax,0
3300
    cmp eax,0
3293
    je shed_counter
3301
    je shed_counter
3294
    cmp eax,2
3302
    cmp eax,2
3295
    je perf_control
3303
    je perf_control
3296
    cmp eax,3
3304
    cmp eax,3
3297
    je rdmsr_instr
3305
    je rdmsr_instr
3298
    cmp eax,4
3306
    cmp eax,4
3299
    je wrmsr_instr
3307
    je wrmsr_instr
3300
    cmp eax,1
3308
    cmp eax,1
3301
    jne not_supported
3309
    jne not_supported
3302
    call change_task ;delay,0
3310
    call change_task ;delay,0
3303
ret
3311
ret
3304
shed_counter:
3312
shed_counter:
3305
    mov eax,[context_counter]
3313
    mov eax,[context_counter]
3306
    mov [esp+36],eax
3314
    mov [esp+36],eax
3307
not_supported:
3315
not_supported:
3308
ret
3316
ret
3309
perf_control:
3317
perf_control:
3310
    inc eax ;now eax=3
3318
    inc eax ;now eax=3
3311
    cmp ebx,eax
3319
    cmp ebx,eax
3312
    je cache_disable
3320
    je cache_disable
3313
    dec eax
3321
    dec eax
3314
    cmp ebx,eax
3322
    cmp ebx,eax
3315
    je cache_enable
3323
    je cache_enable
3316
    dec eax
3324
    dec eax
3317
    cmp ebx,eax
3325
    cmp ebx,eax
3318
    je is_cache_enabled
3326
    je is_cache_enabled
3319
    dec eax
3327
    dec eax
3320
    cmp ebx,eax
3328
    cmp ebx,eax
3321
    je modify_pce
3329
    je modify_pce
3322
ret
3330
ret
3323
 
3331
 
3324
rdmsr_instr:
3332
rdmsr_instr:
3325
;now counter in ecx
3333
;now counter in ecx
3326
;(edx:eax) esi:edi => edx:esi
3334
;(edx:eax) esi:edi => edx:esi
3327
mov eax,esi
3335
mov eax,esi
3328
rdmsr
3336
rdmsr
3329
mov [esp+36],eax
3337
mov [esp+36],eax
3330
mov [esp+24],edx ;ret in ebx?
3338
mov [esp+24],edx ;ret in ebx?
3331
ret
3339
ret
3332
 
3340
 
3333
wrmsr_instr:
3341
wrmsr_instr:
3334
;now counter in ecx
3342
;now counter in ecx
3335
;(edx:eax) esi:edi => edx:esi
3343
;(edx:eax) esi:edi => edx:esi
3336
	; Fast Call MSR can't be destroy
3344
	; Fast Call MSR can't be destroy
3337
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3345
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3338
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3346
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3339
	cmp	ecx, MSR_SYSENTER_CS
3347
	cmp	ecx, MSR_SYSENTER_CS
3340
	je	@f
3348
	je	@f
3341
	cmp	ecx, MSR_SYSENTER_ESP
3349
	cmp	ecx, MSR_SYSENTER_ESP
3342
	je	@f
3350
	je	@f
3343
	cmp	ecx, MSR_SYSENTER_EIP
3351
	cmp	ecx, MSR_SYSENTER_EIP
3344
	je	@f
3352
	je	@f
3345
	cmp	ecx, MSR_AMD_STAR
3353
	cmp	ecx, MSR_AMD_STAR
3346
	je	@f
3354
	je	@f
3347
 
3355
 
3348
	mov	eax, esi
3356
	mov	eax, esi
3349
	wrmsr
3357
	wrmsr
3350
	; mov   [esp + 36], eax
3358
	; mov   [esp + 36], eax
3351
	; mov   [esp + 24], edx ;ret in ebx?
3359
	; mov   [esp + 24], edx ;ret in ebx?
3352
@@:
3360
@@:
3353
ret
3361
ret
3354
 
3362
 
3355
cache_disable:
3363
cache_disable:
3356
       mov eax,cr0
3364
       mov eax,cr0
3357
       or  eax,01100000000000000000000000000000b
3365
       or  eax,01100000000000000000000000000000b
3358
       mov cr0,eax
3366
       mov cr0,eax
3359
       wbinvd ;set MESI
3367
       wbinvd ;set MESI
3360
ret
3368
ret
3361
 
3369
 
3362
cache_enable:
3370
cache_enable:
3363
       mov eax,cr0
3371
       mov eax,cr0
3364
       and eax,10011111111111111111111111111111b
3372
       and eax,10011111111111111111111111111111b
3365
       mov cr0,eax
3373
       mov cr0,eax
3366
ret
3374
ret
3367
 
3375
 
3368
is_cache_enabled:
3376
is_cache_enabled:
3369
       mov eax,cr0
3377
       mov eax,cr0
3370
       mov ebx,eax
3378
       mov ebx,eax
3371
       and eax,01100000000000000000000000000000b
3379
       and eax,01100000000000000000000000000000b
3372
       jz cache_disabled
3380
       jz cache_disabled
3373
       mov [esp+36],ebx
3381
       mov [esp+36],ebx
3374
cache_disabled:
3382
cache_disabled:
3375
       mov dword [esp+36],eax ;0
3383
       mov dword [esp+36],eax ;0
3376
ret
3384
ret
3377
 
3385
 
3378
modify_pce:
3386
modify_pce:
3379
       mov eax,cr4
3387
       mov eax,cr4
3380
;       mov ebx,0
3388
;       mov ebx,0
3381
;       or  bx,100000000b ;pce
3389
;       or  bx,100000000b ;pce
3382
;       xor eax,ebx ;invert pce
3390
;       xor eax,ebx ;invert pce
3383
       bts eax,8 ;pce=cr4[8]
3391
       bts eax,8 ;pce=cr4[8]
3384
       mov cr4,eax
3392
       mov cr4,eax
3385
       mov [esp+36],eax
3393
       mov [esp+36],eax
3386
ret
3394
ret
3387
;---------------------------------------------------------------------------------------------
3395
;---------------------------------------------------------------------------------------------
3388
 
3396
 
3389
 
3397
 
3390
; check if pixel is allowed to be drawn
3398
; check if pixel is allowed to be drawn
3391
 
3399
 
3392
checkpixel:
3400
checkpixel:
3393
	push eax edx
3401
	push eax edx
3394
 
3402
 
3395
	mov  edx,[Screen_Max_X]     ; screen x size
3403
	mov  edx,[Screen_Max_X]     ; screen x size
3396
        mov  ecx, [_display_data]
3404
        mov  ecx, [_display_data]
3397
 
3405
 
3398
        inc  edx
3406
        inc  edx
3399
	imul edx, ebx
3407
	imul edx, ebx
3400
 
3408
 
3401
        add edx, ecx
3409
        add edx, ecx
3402
        mov  dl, [eax+edx] ; lea eax, [...]
3410
        mov  dl, [eax+edx] ; lea eax, [...]
3403
 
3411
 
3404
	xor  ecx, ecx
3412
	xor  ecx, ecx
3405
	mov  eax, [CURRENT_TASK]
3413
	mov  eax, [CURRENT_TASK]
3406
	cmp  al, dl
3414
	cmp  al, dl
3407
	setne cl
3415
	setne cl
3408
 
3416
 
3409
	pop  edx eax
3417
	pop  edx eax
3410
	ret
3418
	ret
3411
 
3419
 
3412
iglobal
3420
iglobal
3413
  cpustring db 'CPU',0
3421
  cpustring db 'CPU',0
3414
endg
3422
endg
3415
 
3423
 
3416
uglobal
3424
uglobal
3417
background_defined    db    0	 ; diamond, 11.04.2006
3425
background_defined    db    0	 ; diamond, 11.04.2006
3418
endg
3426
endg
3419
 
3427
 
3420
align 4
3428
align 4
3421
; check misc
3429
; check misc
3422
 
3430
 
3423
checkmisc:
3431
checkmisc:
3424
 
3432
 
3425
    cmp   [ctrl_alt_del], 1
3433
    cmp   [ctrl_alt_del], 1
3426
    jne   nocpustart
3434
    jne   nocpustart
3427
 
3435
 
3428
	mov	ebp, cpustring
3436
	mov	ebp, cpustring
3429
	call	fs_execute_from_sysdir
3437
	call	fs_execute_from_sysdir
3430
 
3438
 
3431
    mov   [ctrl_alt_del], 0
3439
    mov   [ctrl_alt_del], 0
3432
 
3440
 
3433
nocpustart:
3441
nocpustart:
3434
    cmp   [mouse_active], 1
3442
    cmp   [mouse_active], 1
3435
    jne   mouse_not_active
3443
    jne   mouse_not_active
3436
    mov   [mouse_active], 0
3444
    mov   [mouse_active], 0
3437
    xor   edi, edi
3445
    xor   edi, edi
3438
    mov   ecx,	[TASK_COUNT]
3446
    mov   ecx,	[TASK_COUNT]
3439
set_mouse_event:
3447
set_mouse_event:
3440
    add   edi, 256
3448
    add   edi, 256
3441
    or	  [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3449
    or	  [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3442
    loop  set_mouse_event
3450
    loop  set_mouse_event
3443
 
3451
 
3444
mouse_not_active:
3452
mouse_not_active:
3445
    cmp   [REDRAW_BACKGROUND],byte 0		   ; background update ?
3453
    cmp   [REDRAW_BACKGROUND],byte 0		   ; background update ?
3446
    jz	  nobackgr
3454
    jz	  nobackgr
3447
    cmp    [background_defined], 0
3455
    cmp    [background_defined], 0
3448
    jz	  nobackgr
3456
    jz	  nobackgr
3449
    cmp   [REDRAW_BACKGROUND], byte 2
3457
    cmp   [REDRAW_BACKGROUND], byte 2
3450
    jnz   no_set_bgr_event
3458
    jnz   no_set_bgr_event
3451
    xor   edi, edi
3459
    xor   edi, edi
3452
    mov   ecx,	[TASK_COUNT]
3460
    mov   ecx,	[TASK_COUNT]
3453
set_bgr_event:
3461
set_bgr_event:
3454
    add   edi, 256
3462
    add   edi, 256
3455
    or	  [edi+SLOT_BASE+APPDATA.event_mask], 16
3463
    or	  [edi+SLOT_BASE+APPDATA.event_mask], 16
3456
    loop  set_bgr_event
3464
    loop  set_bgr_event
3457
no_set_bgr_event:
3465
no_set_bgr_event:
3458
;    mov   [draw_data+32 + RECT.left],dword 0
3466
;    mov   [draw_data+32 + RECT.left],dword 0
3459
;    mov   [draw_data+32 + RECT.top],dword 0
3467
;    mov   [draw_data+32 + RECT.top],dword 0
3460
;    mov   eax,[Screen_Max_X]
3468
;    mov   eax,[Screen_Max_X]
3461
;    mov   ebx,[Screen_Max_Y]
3469
;    mov   ebx,[Screen_Max_Y]
3462
;    mov   [draw_data+32 + RECT.right],eax
3470
;    mov   [draw_data+32 + RECT.right],eax
3463
;    mov   [draw_data+32 + RECT.bottom],ebx
3471
;    mov   [draw_data+32 + RECT.bottom],ebx
3464
    call  drawbackground
3472
    call  drawbackground
3465
    mov   [REDRAW_BACKGROUND],byte 0
3473
    mov   [REDRAW_BACKGROUND],byte 0
3466
    mov   [MOUSE_BACKGROUND],byte 0
3474
    mov   [MOUSE_BACKGROUND],byte 0
3467
 
3475
 
3468
nobackgr:
3476
nobackgr:
3469
 
3477
 
3470
    ; system shutdown request
3478
    ; system shutdown request
3471
 
3479
 
3472
    cmp  [SYS_SHUTDOWN],byte 0
3480
    cmp  [SYS_SHUTDOWN],byte 0
3473
    je	 noshutdown
3481
    je	 noshutdown
3474
 
3482
 
3475
    mov  edx,[shutdown_processes]
3483
    mov  edx,[shutdown_processes]
3476
 
3484
 
3477
    cmp  [SYS_SHUTDOWN],dl
3485
    cmp  [SYS_SHUTDOWN],dl
3478
    jne  no_mark_system_shutdown
3486
    jne  no_mark_system_shutdown
3479
 
3487
 
3480
    lea   ecx,[edx-1]
3488
    lea   ecx,[edx-1]
3481
    mov   edx,OS_BASE+0x3040
3489
    mov   edx,OS_BASE+0x3040
3482
    jecxz @f
3490
    jecxz @f
3483
markz:
3491
markz:
3484
    mov   [edx+TASKDATA.state],byte 3
3492
    mov   [edx+TASKDATA.state],byte 3
3485
    add   edx,0x20
3493
    add   edx,0x20
3486
    loop  markz
3494
    loop  markz
3487
@@:
3495
@@:
3488
 
3496
 
3489
  no_mark_system_shutdown:
3497
  no_mark_system_shutdown:
3490
 
3498
 
3491
    call [disable_mouse]
3499
    call [disable_mouse]
3492
 
3500
 
3493
    dec  byte [SYS_SHUTDOWN]
3501
    dec  byte [SYS_SHUTDOWN]
3494
    je	 system_shutdown
3502
    je	 system_shutdown
3495
 
3503
 
3496
noshutdown:
3504
noshutdown:
3497
 
3505
 
3498
 
3506
 
3499
    mov   eax,[TASK_COUNT]		    ; termination
3507
    mov   eax,[TASK_COUNT]		    ; termination
3500
    mov   ebx,TASK_DATA+TASKDATA.state
3508
    mov   ebx,TASK_DATA+TASKDATA.state
3501
    mov   esi,1
3509
    mov   esi,1
3502
 
3510
 
3503
newct:
3511
newct:
3504
    mov   cl,[ebx]
3512
    mov   cl,[ebx]
3505
    cmp   cl,byte 3
3513
    cmp   cl,byte 3
3506
    jz	  terminate
3514
    jz	  terminate
3507
    cmp   cl,byte 4
3515
    cmp   cl,byte 4
3508
    jz	  terminate
3516
    jz	  terminate
3509
 
3517
 
3510
    add   ebx,0x20
3518
    add   ebx,0x20
3511
    inc   esi
3519
    inc   esi
3512
    dec   eax
3520
    dec   eax
3513
    jnz   newct
3521
    jnz   newct
3514
    ret
3522
    ret
3515
 
3523
 
3516
; redraw screen
3524
; redraw screen
3517
 
3525
 
3518
redrawscreen:
3526
redrawscreen:
3519
 
3527
 
3520
; eax , if process window_data base is eax, do not set flag/limits
3528
; eax , if process window_data base is eax, do not set flag/limits
3521
 
3529
 
3522
	 pushad
3530
	 pushad
3523
	 push  eax
3531
	 push  eax
3524
 
3532
 
3525
;;;         mov   ebx,2
3533
;;;         mov   ebx,2
3526
;;;         call  delay_hs
3534
;;;         call  delay_hs
3527
 
3535
 
3528
	 ;mov   ecx,0               ; redraw flags for apps
3536
	 ;mov   ecx,0               ; redraw flags for apps
3529
	 xor   ecx,ecx
3537
	 xor   ecx,ecx
3530
       newdw2:
3538
       newdw2:
3531
 
3539
 
3532
	 inc   ecx
3540
	 inc   ecx
3533
	 push  ecx
3541
	 push  ecx
3534
 
3542
 
3535
	 mov   eax,ecx
3543
	 mov   eax,ecx
3536
	 shl   eax,5
3544
	 shl   eax,5
3537
	 add   eax,window_data
3545
	 add   eax,window_data
3538
 
3546
 
3539
	 cmp   eax,[esp+4]
3547
	 cmp   eax,[esp+4]
3540
	 je    not_this_task
3548
	 je    not_this_task
3541
				   ; check if window in redraw area
3549
				   ; check if window in redraw area
3542
	 mov   edi,eax
3550
	 mov   edi,eax
3543
 
3551
 
3544
	 cmp   ecx,1		   ; limit for background
3552
	 cmp   ecx,1		   ; limit for background
3545
	 jz    bgli
3553
	 jz    bgli
3546
 
3554
 
3547
	 mov   eax, [edi + WDATA.box.left]
3555
	 mov   eax, [edi + WDATA.box.left]
3548
	 mov   ebx, [edi + WDATA.box.top]
3556
	 mov   ebx, [edi + WDATA.box.top]
3549
	 mov   ecx, [edi + WDATA.box.width]
3557
	 mov   ecx, [edi + WDATA.box.width]
3550
	 mov   edx, [edi + WDATA.box.height]
3558
	 mov   edx, [edi + WDATA.box.height]
3551
	 add   ecx,eax
3559
	 add   ecx,eax
3552
	 add   edx,ebx
3560
	 add   edx,ebx
3553
 
3561
 
3554
	 mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3562
	 mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3555
	 cmp   ecx,ebx
3563
	 cmp   ecx,ebx
3556
	 jb    ricino
3564
	 jb    ricino
3557
 
3565
 
3558
	 mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3566
	 mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3559
	 cmp   ecx,eax
3567
	 cmp   ecx,eax
3560
	 jb    ricino
3568
	 jb    ricino
3561
 
3569
 
3562
	 mov   eax, [edi + WDATA.box.left]
3570
	 mov   eax, [edi + WDATA.box.left]
3563
	 mov   ebx, [edi + WDATA.box.top]
3571
	 mov   ebx, [edi + WDATA.box.top]
3564
	 mov   ecx, [edi + WDATA.box.width]
3572
	 mov   ecx, [edi + WDATA.box.width]
3565
	 mov   edx, [edi + WDATA.box.height]
3573
	 mov   edx, [edi + WDATA.box.height]
3566
	 add   ecx, eax
3574
	 add   ecx, eax
3567
	 add   edx, ebx
3575
	 add   edx, ebx
3568
 
3576
 
3569
	 mov   eax,[dly]    ; eax = area y start     edx = window y end
3577
	 mov   eax,[dly]    ; eax = area y start     edx = window y end
3570
	 cmp   edx,eax
3578
	 cmp   edx,eax
3571
	 jb    ricino
3579
	 jb    ricino
3572
 
3580
 
3573
	 mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3581
	 mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3574
	 cmp   ecx,eax
3582
	 cmp   ecx,eax
3575
	 jb    ricino
3583
	 jb    ricino
3576
 
3584
 
3577
	bgli:
3585
	bgli:
3578
 
3586
 
3579
	 cmp   ecx,1
3587
	 cmp   ecx,1
3580
	 jnz   .az
3588
	 jnz   .az
3581
	 mov   al,[REDRAW_BACKGROUND]
3589
	 mov   al,[REDRAW_BACKGROUND]
3582
	 cmp   al,2
3590
	 cmp   al,2
3583
	 jz    newdw8
3591
	 jz    newdw8
3584
	 test  al,al
3592
	 test  al,al
3585
	 jz    .az
3593
	 jz    .az
3586
	 lea   eax,[edi+draw_data-window_data]
3594
	 lea   eax,[edi+draw_data-window_data]
3587
	 mov   ebx,[dlx]
3595
	 mov   ebx,[dlx]
3588
	 cmp   ebx,[eax+RECT.left]
3596
	 cmp   ebx,[eax+RECT.left]
3589
	 jae   @f
3597
	 jae   @f
3590
	 mov   [eax+RECT.left],ebx
3598
	 mov   [eax+RECT.left],ebx
3591
	@@:
3599
	@@:
3592
	 mov   ebx,[dly]
3600
	 mov   ebx,[dly]
3593
	 cmp   ebx,[eax+RECT.top]
3601
	 cmp   ebx,[eax+RECT.top]
3594
	 jae   @f
3602
	 jae   @f
3595
	 mov   [eax+RECT.top],ebx
3603
	 mov   [eax+RECT.top],ebx
3596
	@@:
3604
	@@:
3597
	 mov   ebx,[dlxe]
3605
	 mov   ebx,[dlxe]
3598
	 cmp   ebx,[eax+RECT.right]
3606
	 cmp   ebx,[eax+RECT.right]
3599
	 jbe   @f
3607
	 jbe   @f
3600
	 mov   [eax+RECT.right],ebx
3608
	 mov   [eax+RECT.right],ebx
3601
	@@:
3609
	@@:
3602
	 mov   ebx,[dlye]
3610
	 mov   ebx,[dlye]
3603
	 cmp   ebx,[eax+RECT.bottom]
3611
	 cmp   ebx,[eax+RECT.bottom]
3604
	 jbe   @f
3612
	 jbe   @f
3605
	 mov   [eax+RECT.bottom],ebx
3613
	 mov   [eax+RECT.bottom],ebx
3606
	@@:
3614
	@@:
3607
	 jmp   newdw8
3615
	 jmp   newdw8
3608
	.az:
3616
	.az:
3609
 
3617
 
3610
	 mov   eax,edi
3618
	 mov   eax,edi
3611
	 add   eax,draw_data-window_data
3619
	 add   eax,draw_data-window_data
3612
 
3620
 
3613
	 mov   ebx,[dlx]	  ; set limits
3621
	 mov   ebx,[dlx]	  ; set limits
3614
	 mov   [eax + RECT.left], ebx
3622
	 mov   [eax + RECT.left], ebx
3615
	 mov   ebx,[dly]
3623
	 mov   ebx,[dly]
3616
	 mov   [eax + RECT.top], ebx
3624
	 mov   [eax + RECT.top], ebx
3617
	 mov   ebx,[dlxe]
3625
	 mov   ebx,[dlxe]
3618
	 mov   [eax + RECT.right], ebx
3626
	 mov   [eax + RECT.right], ebx
3619
	 mov   ebx,[dlye]
3627
	 mov   ebx,[dlye]
3620
	 mov   [eax + RECT.bottom], ebx
3628
	 mov   [eax + RECT.bottom], ebx
3621
 
3629
 
3622
	 sub   eax,draw_data-window_data
3630
	 sub   eax,draw_data-window_data
3623
 
3631
 
3624
	 cmp   dword [esp],1
3632
	 cmp   dword [esp],1
3625
	 jne   nobgrd
3633
	 jne   nobgrd
3626
	 mov   byte [REDRAW_BACKGROUND], 1
3634
	 mov   byte [REDRAW_BACKGROUND], 1
3627
 
3635
 
3628
       newdw8:
3636
       newdw8:
3629
       nobgrd:
3637
       nobgrd:
3630
 
3638
 
3631
	 mov   [eax + WDATA.fl_redraw],byte 1	 ; mark as redraw
3639
	 mov   [eax + WDATA.fl_redraw],byte 1	 ; mark as redraw
3632
 
3640
 
3633
       ricino:
3641
       ricino:
3634
 
3642
 
3635
       not_this_task:
3643
       not_this_task:
3636
 
3644
 
3637
	 pop   ecx
3645
	 pop   ecx
3638
 
3646
 
3639
	 cmp   ecx,[TASK_COUNT]
3647
	 cmp   ecx,[TASK_COUNT]
3640
	 jle   newdw2
3648
	 jle   newdw2
3641
 
3649
 
3642
	 pop  eax
3650
	 pop  eax
3643
	 popad
3651
	 popad
3644
 
3652
 
3645
	 ret
3653
	 ret
3646
 
3654
 
3647
calculatebackground:   ; background
3655
calculatebackground:   ; background
3648
 
3656
 
3649
	; all black
3657
	; all black
3650
 
3658
 
3651
	mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3659
	mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3652
	xor   eax, eax
3660
	xor   eax, eax
3653
	mov   ecx, 1023    ;0x0fff00 / 4
3661
	mov   ecx, 1023    ;0x0fff00 / 4
3654
	cld
3662
	cld
3655
	rep   stosd
3663
	rep   stosd
3656
 
3664
 
3657
        mov   edi, [_display_data]              ; set os to use all pixels
3665
        mov   edi, [_display_data]              ; set os to use all pixels
3658
	mov   eax,0x01010101
3666
	mov   eax,0x01010101
3659
	mov   ecx,1280*1024 / 4
3667
	mov   ecx,1280*1024 / 4
3660
	rep   stosd
3668
	rep   stosd
3661
 
3669
 
3662
	mov   byte [REDRAW_BACKGROUND], 0	       ; do not draw background!
3670
	mov   byte [REDRAW_BACKGROUND], 0	       ; do not draw background!
3663
 
3671
 
3664
	ret
3672
	ret
3665
 
3673
 
3666
uglobal
3674
uglobal
3667
  imax	  dd 0x0
3675
  imax	  dd 0x0
3668
endg
3676
endg
3669
 
3677
 
3670
 
3678
 
3671
 
3679
 
3672
delay_ms:     ; delay in 1/1000 sec
3680
delay_ms:     ; delay in 1/1000 sec
3673
 
3681
 
3674
 
3682
 
3675
	push  eax
3683
	push  eax
3676
	push  ecx
3684
	push  ecx
3677
 
3685
 
3678
	mov   ecx,esi
3686
	mov   ecx,esi
3679
	; 
3687
	; 
3680
	imul  ecx, 33941
3688
	imul  ecx, 33941
3681
	shr   ecx, 9
3689
	shr   ecx, 9
3682
	; 
3690
	; 
3683
 
3691
 
3684
	in    al,0x61
3692
	in    al,0x61
3685
	and   al,0x10
3693
	and   al,0x10
3686
	mov   ah,al
3694
	mov   ah,al
3687
	cld
3695
	cld
3688
 
3696
 
3689
 cnt1:	in    al,0x61
3697
 cnt1:	in    al,0x61
3690
	and   al,0x10
3698
	and   al,0x10
3691
	cmp   al,ah
3699
	cmp   al,ah
3692
	jz    cnt1
3700
	jz    cnt1
3693
 
3701
 
3694
	mov   ah,al
3702
	mov   ah,al
3695
	loop  cnt1
3703
	loop  cnt1
3696
 
3704
 
3697
	pop   ecx
3705
	pop   ecx
3698
	pop   eax
3706
	pop   eax
3699
 
3707
 
3700
	ret
3708
	ret
3701
 
3709
 
3702
 
3710
 
3703
set_app_param:
3711
set_app_param:
3704
	mov	edi, [TASK_BASE]
3712
	mov	edi, [TASK_BASE]
3705
	mov	[edi + TASKDATA.event_mask], ebx
3713
	mov	[edi + TASKDATA.event_mask], ebx
3706
	ret
3714
	ret
3707
 
3715
 
3708
 
3716
 
3709
 
3717
 
3710
delay_hs:     ; delay in 1/100 secs
3718
delay_hs:     ; delay in 1/100 secs
3711
; ebx = delay time
3719
; ebx = delay time
3712
	push  ecx
3720
	push  ecx
3713
	push  edx
3721
	push  edx
3714
 
3722
 
3715
	mov   edx,[timer_ticks]
3723
	mov   edx,[timer_ticks]
3716
 
3724
 
3717
      newtic:
3725
      newtic:
3718
	mov   ecx,[timer_ticks]
3726
	mov   ecx,[timer_ticks]
3719
	sub   ecx,edx
3727
	sub   ecx,edx
3720
	cmp   ecx,ebx
3728
	cmp   ecx,ebx
3721
	jae   zerodelay
3729
	jae   zerodelay
3722
 
3730
 
3723
	call  change_task
3731
	call  change_task
3724
 
3732
 
3725
	jmp   newtic
3733
	jmp   newtic
3726
 
3734
 
3727
      zerodelay:
3735
      zerodelay:
3728
	pop   edx
3736
	pop   edx
3729
	pop   ecx
3737
	pop   ecx
3730
 
3738
 
3731
	ret
3739
	ret
3732
 
3740
 
3733
 
3741
 
3734
memmove:       ; memory move in bytes
3742
memmove:       ; memory move in bytes
3735
 
3743
 
3736
; eax = from
3744
; eax = from
3737
; ebx = to
3745
; ebx = to
3738
; ecx = no of bytes
3746
; ecx = no of bytes
3739
    test ecx, ecx
3747
    test ecx, ecx
3740
    jle  .ret
3748
    jle  .ret
3741
 
3749
 
3742
 
3750
 
3743
    push esi edi ecx
3751
    push esi edi ecx
3744
 
3752
 
3745
    mov  edi, ebx
3753
    mov  edi, ebx
3746
    mov  esi, eax
3754
    mov  esi, eax
3747
 
3755
 
3748
    test ecx, not 11b
3756
    test ecx, not 11b
3749
    jz	 @f
3757
    jz	 @f
3750
 
3758
 
3751
    push ecx
3759
    push ecx
3752
    shr  ecx, 2
3760
    shr  ecx, 2
3753
    rep  movsd
3761
    rep  movsd
3754
    pop  ecx
3762
    pop  ecx
3755
    and  ecx, 11b
3763
    and  ecx, 11b
3756
    jz	 .finish
3764
    jz	 .finish
3757
  @@:
3765
  @@:
3758
    rep  movsb
3766
    rep  movsb
3759
 
3767
 
3760
  .finish:
3768
  .finish:
3761
    pop  ecx edi esi
3769
    pop  ecx edi esi
3762
  .ret:
3770
  .ret:
3763
    ret
3771
    ret
3764
 
3772
 
3765
 
3773
 
3766
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3774
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3767
;align 4
3775
;align 4
3768
;
3776
;
3769
;read_floppy_file:
3777
;read_floppy_file:
3770
;
3778
;
3771
;; as input
3779
;; as input
3772
;;
3780
;;
3773
;; eax pointer to file
3781
;; eax pointer to file
3774
;; ebx file lenght
3782
;; ebx file lenght
3775
;; ecx start 512 byte block number
3783
;; ecx start 512 byte block number
3776
;; edx number of blocks to read
3784
;; edx number of blocks to read
3777
;; esi pointer to return/work area (atleast 20 000 bytes)
3785
;; esi pointer to return/work area (atleast 20 000 bytes)
3778
;;
3786
;;
3779
;;
3787
;;
3780
;; on return
3788
;; on return
3781
;;
3789
;;
3782
;; eax = 0 command succesful
3790
;; eax = 0 command succesful
3783
;;       1 no fd base and/or partition defined
3791
;;       1 no fd base and/or partition defined
3784
;;       2 yet unsupported FS
3792
;;       2 yet unsupported FS
3785
;;       3 unknown FS
3793
;;       3 unknown FS
3786
;;       4 partition not defined at hd
3794
;;       4 partition not defined at hd
3787
;;       5 file not found
3795
;;       5 file not found
3788
;; ebx = size of file
3796
;; ebx = size of file
3789
;
3797
;
3790
;     mov   edi,[TASK_BASE]
3798
;     mov   edi,[TASK_BASE]
3791
;     add   edi,0x10
3799
;     add   edi,0x10
3792
;     add   esi,[edi]
3800
;     add   esi,[edi]
3793
;     add   eax,[edi]
3801
;     add   eax,[edi]
3794
;
3802
;
3795
;     pushad
3803
;     pushad
3796
;     mov  edi,esi
3804
;     mov  edi,esi
3797
;     add  edi,1024
3805
;     add  edi,1024
3798
;     mov  esi,0x100000+19*512
3806
;     mov  esi,0x100000+19*512
3799
;     sub  ecx,1
3807
;     sub  ecx,1
3800
;     shl  ecx,9
3808
;     shl  ecx,9
3801
;     add  esi,ecx
3809
;     add  esi,ecx
3802
;     shl  edx,9
3810
;     shl  edx,9
3803
;     mov  ecx,edx
3811
;     mov  ecx,edx
3804
;     cld
3812
;     cld
3805
;     rep  movsb
3813
;     rep  movsb
3806
;     popad
3814
;     popad
3807
;
3815
;
3808
;     mov   [esp+36],eax
3816
;     mov   [esp+36],eax
3809
;     mov   [esp+24],ebx
3817
;     mov   [esp+24],ebx
3810
;     ret
3818
;     ret
3811
 
3819
 
3812
 
3820
 
3813
 
3821
 
3814
align 4
3822
align 4
3815
 
3823
 
3816
sys_programirq:
3824
sys_programirq:
3817
 
3825
 
3818
    mov   eax, [TASK_BASE]
3826
    mov   eax, [TASK_BASE]
3819
    add   ebx, [eax + TASKDATA.mem_start]
3827
    add   ebx, [eax + TASKDATA.mem_start]
3820
 
3828
 
3821
    cmp   ecx, 16
3829
    cmp   ecx, 16
3822
    jae   .not_owner
3830
    jae   .not_owner
3823
    mov   edi, [eax + TASKDATA.pid]
3831
    mov   edi, [eax + TASKDATA.pid]
3824
    cmp   edi, [irq_owner + 4 * ecx]
3832
    cmp   edi, [irq_owner + 4 * ecx]
3825
    je	  .spril1
3833
    je	  .spril1
3826
.not_owner:
3834
.not_owner:
3827
    xor   ecx, ecx
3835
    xor   ecx, ecx
3828
    jmp   .end
3836
    jmp   .end
3829
  .spril1:
3837
  .spril1:
3830
 
3838
 
3831
    shl   ecx, 6
3839
    shl   ecx, 6
3832
    mov   esi, ebx
3840
    mov   esi, ebx
3833
    lea   edi, [irq00read + ecx]
3841
    lea   edi, [irq00read + ecx]
3834
    push  16
3842
    push  16
3835
    pop   ecx
3843
    pop   ecx
3836
 
3844
 
3837
    cld
3845
    cld
3838
    rep   movsd
3846
    rep   movsd
3839
  .end:
3847
  .end:
3840
    mov   [esp+32], ecx
3848
    mov   [esp+32], ecx
3841
    ret
3849
    ret
3842
 
3850
 
3843
 
3851
 
3844
align 4
3852
align 4
3845
 
3853
 
3846
get_irq_data:
3854
get_irq_data:
3847
     movzx esi, bh			 ; save number of subfunction, if bh = 1, return data size, otherwise, read data
3855
     movzx esi, bh			 ; save number of subfunction, if bh = 1, return data size, otherwise, read data
3848
     xor   bh, bh
3856
     xor   bh, bh
3849
     cmp   ebx, 16
3857
     cmp   ebx, 16
3850
     jae   .not_owner
3858
     jae   .not_owner
3851
     mov   edx, [4 * ebx + irq_owner]	 ; check for irq owner
3859
     mov   edx, [4 * ebx + irq_owner]	 ; check for irq owner
3852
 
3860
 
3853
     mov   eax,[TASK_BASE]
3861
     mov   eax,[TASK_BASE]
3854
 
3862
 
3855
     cmp   edx,[eax+TASKDATA.pid]
3863
     cmp   edx,[eax+TASKDATA.pid]
3856
     je    gidril1
3864
     je    gidril1
3857
.not_owner:
3865
.not_owner:
3858
     xor   edx, edx
3866
     xor   edx, edx
3859
     dec   edx
3867
     dec   edx
3860
     jmp   gid1
3868
     jmp   gid1
3861
 
3869
 
3862
  gidril1:
3870
  gidril1:
3863
 
3871
 
3864
     shl   ebx, 12
3872
     shl   ebx, 12
3865
     lea   eax, [ebx + IRQ_SAVE]	 ; calculate address of the beginning of buffer + 0x0 - data size
3873
     lea   eax, [ebx + IRQ_SAVE]	 ; calculate address of the beginning of buffer + 0x0 - data size
3866
     mov   edx, [eax]			 ;                                              + 0x4 - data offset
3874
     mov   edx, [eax]			 ;                                              + 0x4 - data offset
3867
     dec   esi
3875
     dec   esi
3868
     jz    gid1
3876
     jz    gid1
3869
     test  edx, edx			 ; check if buffer is empty
3877
     test  edx, edx			 ; check if buffer is empty
3870
     jz    gid1
3878
     jz    gid1
3871
 
3879
 
3872
     mov   ebx, [eax + 0x4]
3880
     mov   ebx, [eax + 0x4]
3873
     mov   edi, ecx
3881
     mov   edi, ecx
3874
 
3882
 
3875
     mov   ecx, 4000			 ; buffer size, used frequently
3883
     mov   ecx, 4000			 ; buffer size, used frequently
3876
 
3884
 
3877
     cmp   ebx, ecx			 ; check for the end of buffer, if end of buffer, begin cycle again
3885
     cmp   ebx, ecx			 ; check for the end of buffer, if end of buffer, begin cycle again
3878
     jb    @f
3886
     jb    @f
3879
 
3887
 
3880
     xor   ebx, ebx
3888
     xor   ebx, ebx
3881
 
3889
 
3882
   @@:
3890
   @@:
3883
 
3891
 
3884
     lea   esi, [ebx + edx]		 ; calculate data size and offset
3892
     lea   esi, [ebx + edx]		 ; calculate data size and offset
3885
     cld
3893
     cld
3886
     cmp   esi, ecx			 ; if greater than the buffer size, begin cycle again
3894
     cmp   esi, ecx			 ; if greater than the buffer size, begin cycle again
3887
     jbe   @f
3895
     jbe   @f
3888
 
3896
 
3889
     sub   ecx, ebx
3897
     sub   ecx, ebx
3890
     sub   edx, ecx
3898
     sub   edx, ecx
3891
 
3899
 
3892
     lea   esi, [eax + ebx + 0x10]
3900
     lea   esi, [eax + ebx + 0x10]
3893
     rep   movsb
3901
     rep   movsb
3894
 
3902
 
3895
     xor   ebx, ebx
3903
     xor   ebx, ebx
3896
   @@:
3904
   @@:
3897
     lea   esi, [eax + ebx + 0x10]
3905
     lea   esi, [eax + ebx + 0x10]
3898
     mov   ecx, edx
3906
     mov   ecx, edx
3899
     add   ebx, edx
3907
     add   ebx, edx
3900
 
3908
 
3901
     rep   movsb
3909
     rep   movsb
3902
     mov   edx, [eax]
3910
     mov   edx, [eax]
3903
     mov   [eax], ecx			 ; set data size to zero
3911
     mov   [eax], ecx			 ; set data size to zero
3904
     mov   [eax + 0x4], ebx		 ; set data offset
3912
     mov   [eax + 0x4], ebx		 ; set data offset
3905
 
3913
 
3906
   gid1:
3914
   gid1:
3907
     mov   [esp+32], edx		 ; eax
3915
     mov   [esp+32], edx		 ; eax
3908
     ret
3916
     ret
3909
 
3917
 
3910
 
3918
 
3911
set_io_access_rights:
3919
set_io_access_rights:
3912
 
3920
 
3913
     pushad
3921
     pushad
3914
 
3922
 
3915
     mov edi, tss._io_map_0
3923
     mov edi, tss._io_map_0
3916
 
3924
 
3917
;     mov   ecx,eax
3925
;     mov   ecx,eax
3918
;     and   ecx,7    ; offset in byte
3926
;     and   ecx,7    ; offset in byte
3919
 
3927
 
3920
;     shr   eax,3    ; number of byte
3928
;     shr   eax,3    ; number of byte
3921
;     add   edi,eax
3929
;     add   edi,eax
3922
 
3930
 
3923
;     mov   ebx,1
3931
;     mov   ebx,1
3924
;     shl   ebx,cl
3932
;     shl   ebx,cl
3925
 
3933
 
3926
     cmp   ebp,0		; enable access - ebp = 0
3934
     cmp   ebp,0		; enable access - ebp = 0
3927
     jne   siar1
3935
     jne   siar1
3928
 
3936
 
3929
;     not   ebx
3937
;     not   ebx
3930
;     and   [edi],byte bl
3938
;     and   [edi],byte bl
3931
     btr [edi], eax
3939
     btr [edi], eax
3932
 
3940
 
3933
     popad
3941
     popad
3934
 
3942
 
3935
     ret
3943
     ret
3936
 
3944
 
3937
siar1:
3945
siar1:
3938
 
3946
 
3939
     bts [edi], eax
3947
     bts [edi], eax
3940
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3948
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3941
 
3949
 
3942
     popad
3950
     popad
3943
 
3951
 
3944
     ret
3952
     ret
3945
 
3953
 
3946
r_f_port_area:
3954
r_f_port_area:
3947
 
3955
 
3948
     test  eax, eax
3956
     test  eax, eax
3949
     jnz   free_port_area
3957
     jnz   free_port_area
3950
;     je    r_port_area
3958
;     je    r_port_area
3951
;     jmp   free_port_area
3959
;     jmp   free_port_area
3952
 
3960
 
3953
;   r_port_area:
3961
;   r_port_area:
3954
 
3962
 
3955
     pushad
3963
     pushad
3956
 
3964
 
3957
     cmp   ebx,ecx	      ; beginning > end ?
3965
     cmp   ebx,ecx	      ; beginning > end ?
3958
     ja    rpal1
3966
     ja    rpal1
3959
     cmp   ecx,65536
3967
     cmp   ecx,65536
3960
     jae   rpal1
3968
     jae   rpal1
3961
     mov   esi,[RESERVED_PORTS]
3969
     mov   esi,[RESERVED_PORTS]
3962
     test  esi,esi	      ; no reserved areas ?
3970
     test  esi,esi	      ; no reserved areas ?
3963
     je    rpal2
3971
     je    rpal2
3964
     cmp   esi,255	      ; max reserved
3972
     cmp   esi,255	      ; max reserved
3965
     jae   rpal1
3973
     jae   rpal1
3966
 rpal3:
3974
 rpal3:
3967
     mov   edi,esi
3975
     mov   edi,esi
3968
     shl   edi,4
3976
     shl   edi,4
3969
     add   edi,RESERVED_PORTS
3977
     add   edi,RESERVED_PORTS
3970
     cmp   ebx,[edi+8]
3978
     cmp   ebx,[edi+8]
3971
     ja    rpal4
3979
     ja    rpal4
3972
     cmp   ecx,[edi+4]
3980
     cmp   ecx,[edi+4]
3973
     jae   rpal1
3981
     jae   rpal1
3974
;     jb    rpal4
3982
;     jb    rpal4
3975
;     jmp   rpal1
3983
;     jmp   rpal1
3976
 rpal4:
3984
 rpal4:
3977
 
3985
 
3978
     dec   esi
3986
     dec   esi
3979
     jnz   rpal3
3987
     jnz   rpal3
3980
     jmp   rpal2
3988
     jmp   rpal2
3981
   rpal1:
3989
   rpal1:
3982
     popad
3990
     popad
3983
     mov   eax,1
3991
     mov   eax,1
3984
     ret
3992
     ret
3985
 
3993
 
3986
   rpal2:
3994
   rpal2:
3987
     popad
3995
     popad
3988
 
3996
 
3989
 
3997
 
3990
     ; enable port access at port IO map
3998
     ; enable port access at port IO map
3991
     cli
3999
     cli
3992
     pushad			   ; start enable io map
4000
     pushad			   ; start enable io map
3993
 
4001
 
3994
     cmp   ecx,65536 ;16384
4002
     cmp   ecx,65536 ;16384
3995
     jae   no_unmask_io ; jge
4003
     jae   no_unmask_io ; jge
3996
 
4004
 
3997
     mov   eax,ebx
4005
     mov   eax,ebx
3998
 
4006
 
3999
   new_port_access:
4007
   new_port_access:
4000
 
4008
 
4001
     pushad
4009
     pushad
4002
 
4010
 
4003
     xor   ebp,ebp		  ; enable - eax = port
4011
     xor   ebp,ebp		  ; enable - eax = port
4004
     call  set_io_access_rights
4012
     call  set_io_access_rights
4005
 
4013
 
4006
     popad
4014
     popad
4007
 
4015
 
4008
     inc   eax
4016
     inc   eax
4009
     cmp   eax,ecx
4017
     cmp   eax,ecx
4010
     jbe   new_port_access
4018
     jbe   new_port_access
4011
 
4019
 
4012
   no_unmask_io:
4020
   no_unmask_io:
4013
 
4021
 
4014
     popad			   ; end enable io map
4022
     popad			   ; end enable io map
4015
     sti
4023
     sti
4016
 
4024
 
4017
     mov   edi,[RESERVED_PORTS]
4025
     mov   edi,[RESERVED_PORTS]
4018
     add   edi,1
4026
     add   edi,1
4019
     mov   [RESERVED_PORTS],edi
4027
     mov   [RESERVED_PORTS],edi
4020
     shl   edi,4
4028
     shl   edi,4
4021
     add   edi,RESERVED_PORTS
4029
     add   edi,RESERVED_PORTS
4022
     mov   esi,[TASK_BASE]
4030
     mov   esi,[TASK_BASE]
4023
     mov   esi,[esi+TASKDATA.pid]
4031
     mov   esi,[esi+TASKDATA.pid]
4024
     mov   [edi],esi
4032
     mov   [edi],esi
4025
     mov   [edi+4],ebx
4033
     mov   [edi+4],ebx
4026
     mov   [edi+8],ecx
4034
     mov   [edi+8],ecx
4027
 
4035
 
4028
     xor   eax, eax
4036
     xor   eax, eax
4029
     ret
4037
     ret
4030
 
4038
 
4031
free_port_area:
4039
free_port_area:
4032
 
4040
 
4033
     pushad
4041
     pushad
4034
 
4042
 
4035
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
4043
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
4036
     test  esi,esi
4044
     test  esi,esi
4037
     je    frpal2
4045
     je    frpal2
4038
     mov   edx,[TASK_BASE]
4046
     mov   edx,[TASK_BASE]
4039
     mov   edx,[edx+TASKDATA.pid]
4047
     mov   edx,[edx+TASKDATA.pid]
4040
   frpal3:
4048
   frpal3:
4041
     mov   edi,esi
4049
     mov   edi,esi
4042
     shl   edi,4
4050
     shl   edi,4
4043
     add   edi,RESERVED_PORTS
4051
     add   edi,RESERVED_PORTS
4044
     cmp   edx,[edi]
4052
     cmp   edx,[edi]
4045
     jne   frpal4
4053
     jne   frpal4
4046
     cmp   ebx,[edi+4]
4054
     cmp   ebx,[edi+4]
4047
     jne   frpal4
4055
     jne   frpal4
4048
     cmp   ecx,[edi+8]
4056
     cmp   ecx,[edi+8]
4049
     jne   frpal4
4057
     jne   frpal4
4050
     jmp   frpal1
4058
     jmp   frpal1
4051
   frpal4:
4059
   frpal4:
4052
     dec   esi
4060
     dec   esi
4053
     jnz   frpal3
4061
     jnz   frpal3
4054
   frpal2:
4062
   frpal2:
4055
     popad
4063
     popad
4056
     mov   eax,1
4064
     mov   eax,1
4057
     ret
4065
     ret
4058
   frpal1:
4066
   frpal1:
4059
     mov   ecx,256
4067
     mov   ecx,256
4060
     sub   ecx,esi
4068
     sub   ecx,esi
4061
     shl   ecx,4
4069
     shl   ecx,4
4062
     mov   esi,edi
4070
     mov   esi,edi
4063
     add   esi,16
4071
     add   esi,16
4064
     cld
4072
     cld
4065
     rep   movsb
4073
     rep   movsb
4066
 
4074
 
4067
     dec   dword [RESERVED_PORTS]
4075
     dec   dword [RESERVED_PORTS]
4068
 
4076
 
4069
     popad
4077
     popad
4070
 
4078
 
4071
 
4079
 
4072
     ; disable port access at port IO map
4080
     ; disable port access at port IO map
4073
 
4081
 
4074
     pushad			   ; start disable io map
4082
     pushad			   ; start disable io map
4075
 
4083
 
4076
     cmp   ecx,65536 ;16384
4084
     cmp   ecx,65536 ;16384
4077
     jge   no_mask_io
4085
     jge   no_mask_io
4078
 
4086
 
4079
     mov   eax,ebx
4087
     mov   eax,ebx
4080
 
4088
 
4081
   new_port_access_disable:
4089
   new_port_access_disable:
4082
 
4090
 
4083
     pushad
4091
     pushad
4084
 
4092
 
4085
     mov   ebp,1		  ; disable - eax = port
4093
     mov   ebp,1		  ; disable - eax = port
4086
     call  set_io_access_rights
4094
     call  set_io_access_rights
4087
 
4095
 
4088
     popad
4096
     popad
4089
 
4097
 
4090
     inc   eax
4098
     inc   eax
4091
     cmp   eax,ecx
4099
     cmp   eax,ecx
4092
     jbe   new_port_access_disable
4100
     jbe   new_port_access_disable
4093
 
4101
 
4094
   no_mask_io:
4102
   no_mask_io:
4095
 
4103
 
4096
     popad			   ; end disable io map
4104
     popad			   ; end disable io map
4097
 
4105
 
4098
     xor   eax, eax
4106
     xor   eax, eax
4099
     ret
4107
     ret
4100
 
4108
 
4101
 
4109
 
4102
reserve_free_irq:
4110
reserve_free_irq:
4103
 
4111
 
4104
     xor   esi, esi
4112
     xor   esi, esi
4105
     inc   esi
4113
     inc   esi
4106
     cmp   ecx, 16
4114
     cmp   ecx, 16
4107
     jae   ril1
4115
     jae   ril1
4108
 
4116
 
4109
     push  ecx
4117
     push  ecx
4110
     lea   ecx, [irq_owner + 4 * ecx]
4118
     lea   ecx, [irq_owner + 4 * ecx]
4111
     mov   edx, [ecx]
4119
     mov   edx, [ecx]
4112
     mov   eax, [TASK_BASE]
4120
     mov   eax, [TASK_BASE]
4113
     mov   edi, [eax + TASKDATA.pid]
4121
     mov   edi, [eax + TASKDATA.pid]
4114
     pop   eax
4122
     pop   eax
4115
     dec   ebx
4123
     dec   ebx
4116
     jnz   reserve_irq
4124
     jnz   reserve_irq
4117
 
4125
 
4118
     cmp   edx, edi
4126
     cmp   edx, edi
4119
     jne   ril1
4127
     jne   ril1
4120
     dec   esi
4128
     dec   esi
4121
     mov   [ecx], esi
4129
     mov   [ecx], esi
4122
 
4130
 
4123
     jmp   ril1
4131
     jmp   ril1
4124
 
4132
 
4125
  reserve_irq:
4133
  reserve_irq:
4126
 
4134
 
4127
     cmp   dword [ecx], 0
4135
     cmp   dword [ecx], 0
4128
     jne   ril1
4136
     jne   ril1
4129
 
4137
 
4130
     mov   ebx, [f_irqs + 4 * eax]
4138
     mov   ebx, [f_irqs + 4 * eax]
4131
 
4139
 
4132
     stdcall attach_int_handler, eax, ebx, dword 0
4140
     stdcall attach_int_handler, eax, ebx, dword 0
4133
 
4141
 
4134
     mov   [ecx], edi
4142
     mov   [ecx], edi
4135
 
4143
 
4136
     dec   esi
4144
     dec   esi
4137
   ril1:
4145
   ril1:
4138
     mov   [esp+32], esi ; return in eax
4146
     mov   [esp+32], esi ; return in eax
4139
     ret
4147
     ret
4140
 
4148
 
4141
iglobal
4149
iglobal
4142
f_irqs:
4150
f_irqs:
4143
     dd 0x0
4151
     dd 0x0
4144
     dd 0x0
4152
     dd 0x0
4145
     dd p_irq2
4153
     dd p_irq2
4146
     dd p_irq3
4154
     dd p_irq3
4147
     dd p_irq4
4155
     dd p_irq4
4148
     dd p_irq5
4156
     dd p_irq5
4149
     dd p_irq6
4157
     dd p_irq6
4150
     dd p_irq7
4158
     dd p_irq7
4151
     dd p_irq8
4159
     dd p_irq8
4152
     dd p_irq9
4160
     dd p_irq9
4153
     dd p_irq10
4161
     dd p_irq10
4154
     dd p_irq11
4162
     dd p_irq11
4155
     dd 0x0
4163
     dd 0x0
4156
     dd 0x0
4164
     dd 0x0
4157
     dd p_irq14
4165
     dd p_irq14
4158
     dd p_irq15
4166
     dd p_irq15
4159
 
4167
 
4160
endg
4168
endg
4161
 
4169
 
4162
drawbackground:
4170
drawbackground:
4163
       inc   [mouse_pause]
4171
       inc   [mouse_pause]
4164
       cmp   [SCR_MODE],word 0x12
4172
       cmp   [SCR_MODE],word 0x12
4165
       je   dbrv20
4173
       je   dbrv20
4166
     dbrv12:
4174
     dbrv12:
4167
       cmp  [SCR_MODE],word 0100000000000000b
4175
       cmp  [SCR_MODE],word 0100000000000000b
4168
       jge  dbrv20
4176
       jge  dbrv20
4169
       cmp  [SCR_MODE],word 0x13
4177
       cmp  [SCR_MODE],word 0x13
4170
       je   dbrv20
4178
       je   dbrv20
4171
       call  vesa12_drawbackground
4179
       call  vesa12_drawbackground
4172
       dec   [mouse_pause]
4180
       dec   [mouse_pause]
4173
       call   [draw_pointer]
4181
       call   [draw_pointer]
4174
       ret
4182
       ret
4175
     dbrv20:
4183
     dbrv20:
4176
       cmp   [BgrDrawMode],dword 1
4184
       cmp   [BgrDrawMode],dword 1
4177
       jne   bgrstr
4185
       jne   bgrstr
4178
       call  vesa20_drawbackground_tiled
4186
       call  vesa20_drawbackground_tiled
4179
       dec   [mouse_pause]
4187
       dec   [mouse_pause]
4180
       call   [draw_pointer]
4188
       call   [draw_pointer]
4181
       ret
4189
       ret
4182
     bgrstr:
4190
     bgrstr:
4183
       call  vesa20_drawbackground_stretch
4191
       call  vesa20_drawbackground_stretch
4184
       dec   [mouse_pause]
4192
       dec   [mouse_pause]
4185
       call   [draw_pointer]
4193
       call   [draw_pointer]
4186
       ret
4194
       ret
4187
 
4195
 
4188
align 4
4196
align 4
4189
 
4197
 
4190
syscall_putimage:			; PutImage
4198
syscall_putimage:			; PutImage
4191
sys_putimage:
4199
sys_putimage:
4192
     test  ecx,0x80008000
4200
     test  ecx,0x80008000
4193
     jnz   .exit
4201
     jnz   .exit
4194
     test  ecx,0x0000FFFF
4202
     test  ecx,0x0000FFFF
4195
     jz    .exit
4203
     jz    .exit
4196
     test  ecx,0xFFFF0000
4204
     test  ecx,0xFFFF0000
4197
     jnz   @f
4205
     jnz   @f
4198
  .exit:
4206
  .exit:
4199
     ret
4207
     ret
4200
 @@:
4208
 @@:
4201
	mov	edi,[current_slot]
4209
	mov	edi,[current_slot]
4202
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
4210
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
4203
	rol	edx,16
4211
	rol	edx,16
4204
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
4212
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
4205
	rol	edx,16
4213
	rol	edx,16
4206
  .forced:
4214
  .forced:
4207
	push	ebp esi 0
4215
	push	ebp esi 0
4208
	mov	ebp, putimage_get24bpp
4216
	mov	ebp, putimage_get24bpp
4209
	mov	esi, putimage_init24bpp
4217
	mov	esi, putimage_init24bpp
4210
sys_putimage_bpp:
4218
sys_putimage_bpp:
4211
;        call    [disable_mouse] ; this will be done in xxx_putimage
4219
;        call    [disable_mouse] ; this will be done in xxx_putimage
4212
;        mov     eax, vga_putimage
4220
;        mov     eax, vga_putimage
4213
	cmp	[SCR_MODE], word 0x12
4221
	cmp	[SCR_MODE], word 0x12
4214
	jz	@f   ;.doit
4222
	jz	@f   ;.doit
4215
	mov	eax, vesa12_putimage
4223
	mov	eax, vesa12_putimage
4216
	cmp	[SCR_MODE], word 0100000000000000b
4224
	cmp	[SCR_MODE], word 0100000000000000b
4217
	jae	@f
4225
	jae	@f
4218
	cmp	[SCR_MODE], word 0x13
4226
	cmp	[SCR_MODE], word 0x13
4219
	jnz	.doit
4227
	jnz	.doit
4220
@@:
4228
@@:
4221
	mov	eax, vesa20_putimage
4229
	mov	eax, vesa20_putimage
4222
.doit:
4230
.doit:
4223
	inc	[mouse_pause]
4231
	inc	[mouse_pause]
4224
	call	eax
4232
	call	eax
4225
	dec	[mouse_pause]
4233
	dec	[mouse_pause]
4226
	pop	ebp esi ebp
4234
	pop	ebp esi ebp
4227
	jmp	[draw_pointer]
4235
	jmp	[draw_pointer]
4228
 
4236
 
4229
syscall_putimage_palette:
4237
syscall_putimage_palette:
4230
	mov	edi, esi
4238
	mov	edi, esi
4231
	mov	esi, edx
4239
	mov	esi, edx
4232
	mov	edx, ecx
4240
	mov	edx, ecx
4233
	mov	ecx, ebx
4241
	mov	ecx, ebx
4234
	mov	ebx, eax
4242
	mov	ebx, eax
4235
sys_putimage_palette:
4243
sys_putimage_palette:
4236
; ebx = pointer to image
4244
; ebx = pointer to image
4237
; ecx = [xsize]*65536 + [ysize]
4245
; ecx = [xsize]*65536 + [ysize]
4238
; edx = [xstart]*65536 + [ystart]
4246
; edx = [xstart]*65536 + [ystart]
4239
; esi = number of bits per pixel, must be 8, 24 or 32
4247
; esi = number of bits per pixel, must be 8, 24 or 32
4240
; edi = pointer to palette
4248
; edi = pointer to palette
4241
; ebp = row delta
4249
; ebp = row delta
4242
	mov	eax, [CURRENT_TASK]
4250
	mov	eax, [CURRENT_TASK]
4243
	shl	eax, 8
4251
	shl	eax, 8
4244
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4252
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4245
	rol	edx, 16
4253
	rol	edx, 16
4246
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4254
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4247
	rol	edx, 16
4255
	rol	edx, 16
4248
.forced:
4256
.forced:
4249
	push	ebp esi ebp
4257
	push	ebp esi ebp
4250
	cmp	esi, 8
4258
	cmp	esi, 8
4251
	jnz	@f
4259
	jnz	@f
4252
	mov	ebp, putimage_get8bpp
4260
	mov	ebp, putimage_get8bpp
4253
	mov	esi, putimage_init8bpp
4261
	mov	esi, putimage_init8bpp
4254
	jmp	sys_putimage_bpp
4262
	jmp	sys_putimage_bpp
4255
@@:
4263
@@:
4256
        cmp     esi, 16
4264
        cmp     esi, 16
4257
        jnz     @f
4265
        jnz     @f
4258
        mov     ebp, putimage_get16bpp
4266
        mov     ebp, putimage_get16bpp
4259
        mov     esi, putimage_init16bpp
4267
        mov     esi, putimage_init16bpp
4260
        jmp     sys_putimage_bpp
4268
        jmp     sys_putimage_bpp
4261
@@:
4269
@@:
4262
	cmp	esi, 24
4270
	cmp	esi, 24
4263
	jnz	@f
4271
	jnz	@f
4264
	mov	ebp, putimage_get24bpp
4272
	mov	ebp, putimage_get24bpp
4265
	mov	esi, putimage_init24bpp
4273
	mov	esi, putimage_init24bpp
4266
	jmp	sys_putimage_bpp
4274
	jmp	sys_putimage_bpp
4267
@@:
4275
@@:
4268
	cmp	esi, 32
4276
	cmp	esi, 32
4269
	jnz	@f
4277
	jnz	@f
4270
	mov	ebp, putimage_get32bpp
4278
	mov	ebp, putimage_get32bpp
4271
	mov	esi, putimage_init32bpp
4279
	mov	esi, putimage_init32bpp
4272
	jmp	sys_putimage_bpp
4280
	jmp	sys_putimage_bpp
4273
@@:
4281
@@:
4274
	pop	ebp esi ebp
4282
	pop	ebp esi ebp
4275
	ret
4283
	ret
4276
 
4284
 
4277
putimage_init24bpp:
4285
putimage_init24bpp:
4278
	lea	eax, [eax*3]
4286
	lea	eax, [eax*3]
4279
putimage_init8bpp:
4287
putimage_init8bpp:
4280
	ret
4288
	ret
4281
 
4289
 
4282
putimage_get24bpp:
4290
putimage_get24bpp:
4283
	mov	eax, [esi]
4291
	mov	eax, [esi]
4284
	add	esi, 3
4292
	add	esi, 3
4285
	ret	4
4293
	ret	4
4286
putimage_get8bpp:
4294
putimage_get8bpp:
4287
	movzx	eax, byte [esi]
4295
	movzx	eax, byte [esi]
4288
	push	edx
4296
	push	edx
4289
	mov	edx, [esp+8]
4297
	mov	edx, [esp+8]
4290
	mov	eax, [edx+eax*4]
4298
	mov	eax, [edx+eax*4]
4291
	pop	edx
4299
	pop	edx
4292
	inc	esi
4300
	inc	esi
4293
	ret	4
4301
	ret	4
4294
 
4302
 
4295
putimage_init32bpp:
4303
putimage_init32bpp:
4296
	shl	eax, 2
4304
	shl	eax, 2
4297
	ret
4305
	ret
4298
putimage_get32bpp:
4306
putimage_get32bpp:
4299
	lodsd
4307
	lodsd
4300
	ret	4
4308
	ret	4
4301
 
4309
 
4302
putimage_init16bpp:
4310
putimage_init16bpp:
4303
        add     eax, eax
4311
        add     eax, eax
4304
        ret
4312
        ret
4305
putimage_get16bpp:
4313
putimage_get16bpp:
4306
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4314
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4307
        push    ecx edx
4315
        push    ecx edx
4308
        movzx   eax, word [esi]
4316
        movzx   eax, word [esi]
4309
        add     esi, 2
4317
        add     esi, 2
4310
        mov     ecx, eax
4318
        mov     ecx, eax
4311
        mov     edx, eax
4319
        mov     edx, eax
4312
        and     eax, 0x1F
4320
        and     eax, 0x1F
4313
        and     ecx, 0x1F shl 5
4321
        and     ecx, 0x1F shl 5
4314
        and     edx, 0x1F shl 10
4322
        and     edx, 0x1F shl 10
4315
        shl     eax, 3
4323
        shl     eax, 3
4316
        shl     ecx, 6
4324
        shl     ecx, 6
4317
        shl     edx, 9
4325
        shl     edx, 9
4318
        or      eax, ecx
4326
        or      eax, ecx
4319
        or      eax, edx
4327
        or      eax, edx
4320
        pop     edx ecx
4328
        pop     edx ecx
4321
        ret
4329
        ret
4322
 
4330
 
4323
; eax x beginning
4331
; eax x beginning
4324
; ebx y beginning
4332
; ebx y beginning
4325
; ecx x end
4333
; ecx x end
4326
	; edx y end
4334
	; edx y end
4327
; edi color
4335
; edi color
4328
 
4336
 
4329
__sys_drawbar:
4337
__sys_drawbar:
4330
	mov	esi,[current_slot]
4338
	mov	esi,[current_slot]
4331
	add	eax,[esi+APPDATA.wnd_clientbox.left]
4339
	add	eax,[esi+APPDATA.wnd_clientbox.left]
4332
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
4340
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
4333
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
4341
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
4334
	add	edx,[esi+APPDATA.wnd_clientbox.top]
4342
	add	edx,[esi+APPDATA.wnd_clientbox.top]
4335
  .forced:
4343
  .forced:
4336
    inc   [mouse_pause]
4344
    inc   [mouse_pause]
4337
;        call    [disable_mouse]
4345
;        call    [disable_mouse]
4338
    cmp   [SCR_MODE],word 0x12
4346
    cmp   [SCR_MODE],word 0x12
4339
    je	 dbv20
4347
    je	 dbv20
4340
   sdbv20:
4348
   sdbv20:
4341
    cmp  [SCR_MODE],word 0100000000000000b
4349
    cmp  [SCR_MODE],word 0100000000000000b
4342
    jge  dbv20
4350
    jge  dbv20
4343
    cmp  [SCR_MODE],word 0x13
4351
    cmp  [SCR_MODE],word 0x13
4344
    je	 dbv20
4352
    je	 dbv20
4345
    call vesa12_drawbar
4353
    call vesa12_drawbar
4346
    dec   [mouse_pause]
4354
    dec   [mouse_pause]
4347
    call   [draw_pointer]
4355
    call   [draw_pointer]
4348
    ret
4356
    ret
4349
  dbv20:
4357
  dbv20:
4350
    call vesa20_drawbar
4358
    call vesa20_drawbar
4351
    dec   [mouse_pause]
4359
    dec   [mouse_pause]
4352
    call   [draw_pointer]
4360
    call   [draw_pointer]
4353
    ret
4361
    ret
4354
 
4362
 
4355
 
4363
 
4356
 
4364
 
4357
kb_read:
4365
kb_read:
4358
 
4366
 
4359
	push	ecx edx
4367
	push	ecx edx
4360
 
4368
 
4361
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4369
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4362
      kr_loop:
4370
      kr_loop:
4363
	in	al,0x64
4371
	in	al,0x64
4364
	test	al,1
4372
	test	al,1
4365
	jnz	kr_ready
4373
	jnz	kr_ready
4366
	loop	kr_loop
4374
	loop	kr_loop
4367
	mov	ah,1
4375
	mov	ah,1
4368
	jmp	kr_exit
4376
	jmp	kr_exit
4369
      kr_ready:
4377
      kr_ready:
4370
	push	ecx
4378
	push	ecx
4371
	mov	ecx,32
4379
	mov	ecx,32
4372
      kr_delay:
4380
      kr_delay:
4373
	loop	kr_delay
4381
	loop	kr_delay
4374
	pop	ecx
4382
	pop	ecx
4375
	in	al,0x60
4383
	in	al,0x60
4376
	xor	ah,ah
4384
	xor	ah,ah
4377
      kr_exit:
4385
      kr_exit:
4378
 
4386
 
4379
	pop	edx ecx
4387
	pop	edx ecx
4380
 
4388
 
4381
	ret
4389
	ret
4382
 
4390
 
4383
 
4391
 
4384
kb_write:
4392
kb_write:
4385
 
4393
 
4386
	push	ecx edx
4394
	push	ecx edx
4387
 
4395
 
4388
	mov	dl,al
4396
	mov	dl,al
4389
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4397
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4390
;      kw_loop1:
4398
;      kw_loop1:
4391
;        in      al,0x64
4399
;        in      al,0x64
4392
;        test    al,0x20
4400
;        test    al,0x20
4393
;        jz      kw_ok1
4401
;        jz      kw_ok1
4394
;        loop    kw_loop1
4402
;        loop    kw_loop1
4395
;        mov     ah,1
4403
;        mov     ah,1
4396
;        jmp     kw_exit
4404
;        jmp     kw_exit
4397
;      kw_ok1:
4405
;      kw_ok1:
4398
	in	al,0x60
4406
	in	al,0x60
4399
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4407
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4400
      kw_loop:
4408
      kw_loop:
4401
	in	al,0x64
4409
	in	al,0x64
4402
	test	al,2
4410
	test	al,2
4403
	jz	kw_ok
4411
	jz	kw_ok
4404
	loop	kw_loop
4412
	loop	kw_loop
4405
	mov	ah,1
4413
	mov	ah,1
4406
	jmp	kw_exit
4414
	jmp	kw_exit
4407
      kw_ok:
4415
      kw_ok:
4408
	mov	al,dl
4416
	mov	al,dl
4409
	out	0x60,al
4417
	out	0x60,al
4410
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4418
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4411
      kw_loop3:
4419
      kw_loop3:
4412
	in	al,0x64
4420
	in	al,0x64
4413
	test	al,2
4421
	test	al,2
4414
	jz	kw_ok3
4422
	jz	kw_ok3
4415
	loop	kw_loop3
4423
	loop	kw_loop3
4416
	mov	ah,1
4424
	mov	ah,1
4417
	jmp	kw_exit
4425
	jmp	kw_exit
4418
      kw_ok3:
4426
      kw_ok3:
4419
	mov	ah,8
4427
	mov	ah,8
4420
      kw_loop4:
4428
      kw_loop4:
4421
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4429
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4422
      kw_loop5:
4430
      kw_loop5:
4423
	in	al,0x64
4431
	in	al,0x64
4424
	test	al,1
4432
	test	al,1
4425
	jnz	kw_ok4
4433
	jnz	kw_ok4
4426
	loop	kw_loop5
4434
	loop	kw_loop5
4427
	dec	ah
4435
	dec	ah
4428
	jnz	kw_loop4
4436
	jnz	kw_loop4
4429
      kw_ok4:
4437
      kw_ok4:
4430
	xor	ah,ah
4438
	xor	ah,ah
4431
      kw_exit:
4439
      kw_exit:
4432
 
4440
 
4433
	pop	edx ecx
4441
	pop	edx ecx
4434
 
4442
 
4435
	ret
4443
	ret
4436
 
4444
 
4437
 
4445
 
4438
kb_cmd:
4446
kb_cmd:
4439
 
4447
 
4440
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4448
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4441
      c_wait:
4449
      c_wait:
4442
	in	al,0x64
4450
	in	al,0x64
4443
	test	al,2
4451
	test	al,2
4444
	jz	c_send
4452
	jz	c_send
4445
	loop	c_wait
4453
	loop	c_wait
4446
	jmp	c_error
4454
	jmp	c_error
4447
      c_send:
4455
      c_send:
4448
	mov	al,bl
4456
	mov	al,bl
4449
	out	0x64,al
4457
	out	0x64,al
4450
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4458
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4451
      c_accept:
4459
      c_accept:
4452
	in	al,0x64
4460
	in	al,0x64
4453
	test	al,2
4461
	test	al,2
4454
	jz	c_ok
4462
	jz	c_ok
4455
	loop	c_accept
4463
	loop	c_accept
4456
      c_error:
4464
      c_error:
4457
	mov	ah,1
4465
	mov	ah,1
4458
	jmp	c_exit
4466
	jmp	c_exit
4459
      c_ok:
4467
      c_ok:
4460
	xor	ah,ah
4468
	xor	ah,ah
4461
      c_exit:
4469
      c_exit:
4462
	ret
4470
	ret
4463
 
4471
 
4464
 
4472
 
4465
setmouse:  ; set mousepicture -pointer
4473
setmouse:  ; set mousepicture -pointer
4466
	   ; ps2 mouse enable
4474
	   ; ps2 mouse enable
4467
 
4475
 
4468
     mov     [MOUSE_PICTURE],dword mousepointer
4476
     mov     [MOUSE_PICTURE],dword mousepointer
4469
 
4477
 
4470
     cli
4478
     cli
4471
 
4479
 
4472
     ret
4480
     ret
4473
 
4481
 
4474
 
4482
 
4475
_rdtsc:
4483
_rdtsc:
4476
     bt [cpu_caps], CAPS_TSC
4484
     bt [cpu_caps], CAPS_TSC
4477
     jnc ret_rdtsc
4485
     jnc ret_rdtsc
4478
     rdtsc
4486
     rdtsc
4479
     ret
4487
     ret
4480
   ret_rdtsc:
4488
   ret_rdtsc:
4481
     mov   edx,0xffffffff
4489
     mov   edx,0xffffffff
4482
     mov   eax,0xffffffff
4490
     mov   eax,0xffffffff
4483
     ret
4491
     ret
4484
 
4492
 
4485
rerouteirqs:
4493
rerouteirqs:
4486
 
4494
 
4487
	mov	al,0x11 	;  icw4, edge triggered
4495
	mov	al,0x11 	;  icw4, edge triggered
4488
	out	0x20,al
4496
	out	0x20,al
4489
	call	pic_delay
4497
	call	pic_delay
4490
	out	0xA0,al
4498
	out	0xA0,al
4491
	call	pic_delay
4499
	call	pic_delay
4492
 
4500
 
4493
	mov	al,0x20 	;  generate 0x20 +
4501
	mov	al,0x20 	;  generate 0x20 +
4494
	out	0x21,al
4502
	out	0x21,al
4495
	call	pic_delay
4503
	call	pic_delay
4496
	mov	al,0x28 	;  generate 0x28 +
4504
	mov	al,0x28 	;  generate 0x28 +
4497
	out	0xA1,al
4505
	out	0xA1,al
4498
	call	pic_delay
4506
	call	pic_delay
4499
 
4507
 
4500
	mov	al,0x04 	;  slave at irq2
4508
	mov	al,0x04 	;  slave at irq2
4501
	out	0x21,al
4509
	out	0x21,al
4502
	call	pic_delay
4510
	call	pic_delay
4503
	mov	al,0x02 	;  at irq9
4511
	mov	al,0x02 	;  at irq9
4504
	out	0xA1,al
4512
	out	0xA1,al
4505
	call	pic_delay
4513
	call	pic_delay
4506
 
4514
 
4507
	mov	al,0x01 	;  8086 mode
4515
	mov	al,0x01 	;  8086 mode
4508
	out	0x21,al
4516
	out	0x21,al
4509
	call	pic_delay
4517
	call	pic_delay
4510
	out	0xA1,al
4518
	out	0xA1,al
4511
	call	pic_delay
4519
	call	pic_delay
4512
 
4520
 
4513
	mov	al,255		; mask all irq's
4521
	mov	al,255		; mask all irq's
4514
	out	0xA1,al
4522
	out	0xA1,al
4515
	call	pic_delay
4523
	call	pic_delay
4516
	out	0x21,al
4524
	out	0x21,al
4517
	call	pic_delay
4525
	call	pic_delay
4518
 
4526
 
4519
	mov	ecx,0x1000
4527
	mov	ecx,0x1000
4520
	cld
4528
	cld
4521
picl1:	call	pic_delay
4529
picl1:	call	pic_delay
4522
	loop	picl1
4530
	loop	picl1
4523
 
4531
 
4524
	mov	al,255		; mask all irq's
4532
	mov	al,255		; mask all irq's
4525
	out	0xA1,al
4533
	out	0xA1,al
4526
	call	pic_delay
4534
	call	pic_delay
4527
	out	0x21,al
4535
	out	0x21,al
4528
	call	pic_delay
4536
	call	pic_delay
4529
 
4537
 
4530
	ret
4538
	ret
4531
 
4539
 
4532
 
4540
 
4533
pic_delay:
4541
pic_delay:
4534
 
4542
 
4535
	jmp	pdl1
4543
	jmp	pdl1
4536
pdl1:	ret
4544
pdl1:	ret
4537
 
4545
 
4538
 
4546
 
4539
sys_msg_board_str:
4547
sys_msg_board_str:
4540
 
4548
 
4541
     pushad
4549
     pushad
4542
   @@:
4550
   @@:
4543
     cmp    [esi],byte 0
4551
     cmp    [esi],byte 0
4544
     je     @f
4552
     je     @f
4545
     mov    eax,1
4553
     mov    eax,1
4546
     movzx  ebx,byte [esi]
4554
     movzx  ebx,byte [esi]
4547
     call   sys_msg_board
4555
     call   sys_msg_board
4548
     inc    esi
4556
     inc    esi
4549
     jmp    @b
4557
     jmp    @b
4550
   @@:
4558
   @@:
4551
     popad
4559
     popad
4552
     ret
4560
     ret
4553
 
4561
 
4554
sys_msg_board_byte:
4562
sys_msg_board_byte:
4555
; in: al = byte to display
4563
; in: al = byte to display
4556
; out: nothing
4564
; out: nothing
4557
; destroys: nothing
4565
; destroys: nothing
4558
	pushad
4566
	pushad
4559
	mov	ecx, 2
4567
	mov	ecx, 2
4560
	shl	eax, 24
4568
	shl	eax, 24
4561
	jmp	@f
4569
	jmp	@f
4562
 
4570
 
4563
sys_msg_board_word:
4571
sys_msg_board_word:
4564
; in: ax = word to display
4572
; in: ax = word to display
4565
; out: nothing
4573
; out: nothing
4566
; destroys: nothing
4574
; destroys: nothing
4567
	pushad
4575
	pushad
4568
	mov	ecx, 4
4576
	mov	ecx, 4
4569
	shl	eax, 16
4577
	shl	eax, 16
4570
	jmp	@f
4578
	jmp	@f
4571
 
4579
 
4572
sys_msg_board_dword:
4580
sys_msg_board_dword:
4573
; in: eax = dword to display
4581
; in: eax = dword to display
4574
; out: nothing
4582
; out: nothing
4575
; destroys: nothing
4583
; destroys: nothing
4576
	pushad
4584
	pushad
4577
	mov	ecx, 8
4585
	mov	ecx, 8
4578
@@:
4586
@@:
4579
	push	ecx
4587
	push	ecx
4580
	rol	eax, 4
4588
	rol	eax, 4
4581
	push	eax
4589
	push	eax
4582
	and	al, 0xF
4590
	and	al, 0xF
4583
	cmp	al, 10
4591
	cmp	al, 10
4584
	sbb	al, 69h
4592
	sbb	al, 69h
4585
	das
4593
	das
4586
	mov	bl, al
4594
	mov	bl, al
4587
	xor	eax, eax
4595
	xor	eax, eax
4588
	inc	eax
4596
	inc	eax
4589
	call	sys_msg_board
4597
	call	sys_msg_board
4590
	pop	eax
4598
	pop	eax
4591
	pop	ecx
4599
	pop	ecx
4592
	loop	@b
4600
	loop	@b
4593
	popad
4601
	popad
4594
	ret
4602
	ret
4595
 
4603
 
4596
uglobal
4604
uglobal
4597
  msg_board_data: times 4096 db 0
4605
  msg_board_data: times 4096 db 0
4598
  msg_board_count dd 0x0
4606
  msg_board_count dd 0x0
4599
endg
4607
endg
4600
 
4608
 
4601
sys_msg_board:
4609
sys_msg_board:
4602
 
4610
 
4603
; eax=1 : write :  bl byte to write
4611
; eax=1 : write :  bl byte to write
4604
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4612
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4605
 
4613
 
4606
	mov	ecx, [msg_board_count]
4614
	mov	ecx, [msg_board_count]
4607
	cmp	eax, 1
4615
	cmp	eax, 1
4608
	jne	.smbl1
4616
	jne	.smbl1
4609
 
4617
 
4610
 
4618
 
4611
	mov	[msg_board_data+ecx],bl
4619
	mov	[msg_board_data+ecx],bl
4612
	inc	ecx
4620
	inc	ecx
4613
	and	ecx, 4095
4621
	and	ecx, 4095
4614
	mov	[msg_board_count], ecx
4622
	mov	[msg_board_count], ecx
4615
	mov	[check_idle_semaphore], 5
4623
	mov	[check_idle_semaphore], 5
4616
	ret
4624
	ret
4617
.smbl1:
4625
.smbl1:
4618
	cmp	eax, 2
4626
	cmp	eax, 2
4619
	jne	.smbl2
4627
	jne	.smbl2
4620
	test	ecx, ecx
4628
	test	ecx, ecx
4621
	jz	.smbl21
4629
	jz	.smbl21
4622
	mov	eax, msg_board_data+1
4630
	mov	eax, msg_board_data+1
4623
	mov	ebx, msg_board_data
4631
	mov	ebx, msg_board_data
4624
	movzx	edx, byte [ebx]
4632
	movzx	edx, byte [ebx]
4625
	call	memmove
4633
	call	memmove
4626
	dec	[msg_board_count]
4634
	dec	[msg_board_count]
4627
	mov	[esp + 36], edx ;eax
4635
	mov	[esp + 36], edx ;eax
4628
	mov	[esp + 24], dword 1
4636
	mov	[esp + 24], dword 1
4629
	ret
4637
	ret
4630
.smbl21:
4638
.smbl21:
4631
	mov	[esp+36], ecx
4639
	mov	[esp+36], ecx
4632
	mov	[esp+24], ecx
4640
	mov	[esp+24], ecx
4633
.smbl2:
4641
.smbl2:
4634
	ret
4642
	ret
4635
 
4643
 
4636
 
4644
 
4637
 
4645
 
4638
sys_process_def:
4646
sys_process_def:
4639
	mov	edi, [CURRENT_TASK]
4647
	mov	edi, [CURRENT_TASK]
4640
 
4648
 
4641
	dec	eax		; 1 = set keyboard mode
4649
	dec	eax		; 1 = set keyboard mode
4642
     jne   no_set_keyboard_setup
4650
     jne   no_set_keyboard_setup
4643
 
4651
 
4644
     shl   edi,8
4652
     shl   edi,8
4645
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4653
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4646
 
4654
 
4647
     ret
4655
     ret
4648
 
4656
 
4649
   no_set_keyboard_setup:
4657
   no_set_keyboard_setup:
4650
 
4658
 
4651
	dec	eax		; 2 = get keyboard mode
4659
	dec	eax		; 2 = get keyboard mode
4652
     jne   no_get_keyboard_setup
4660
     jne   no_get_keyboard_setup
4653
 
4661
 
4654
     shl   edi,8
4662
     shl   edi,8
4655
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4663
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4656
 
4664
 
4657
     mov   [esp+36],eax
4665
     mov   [esp+36],eax
4658
 
4666
 
4659
     ret
4667
     ret
4660
 
4668
 
4661
   no_get_keyboard_setup:
4669
   no_get_keyboard_setup:
4662
 
4670
 
4663
	dec	eax		; 3 = get keyboard ctrl, alt, shift
4671
	dec	eax		; 3 = get keyboard ctrl, alt, shift
4664
     jne   no_get_keyboard_cas
4672
     jne   no_get_keyboard_cas
4665
 
4673
 
4666
;     xor   eax,eax
4674
;     xor   eax,eax
4667
;     movzx eax,byte [shift]
4675
;     movzx eax,byte [shift]
4668
;     movzx ebx,byte [ctrl]
4676
;     movzx ebx,byte [ctrl]
4669
;     shl   ebx,2
4677
;     shl   ebx,2
4670
;     add   eax,ebx
4678
;     add   eax,ebx
4671
;     movzx ebx,byte [alt]
4679
;     movzx ebx,byte [alt]
4672
;     shl   ebx,3
4680
;     shl   ebx,3
4673
;     add   eax,ebx
4681
;     add   eax,ebx
4674
 
4682
 
4675
 ;// mike.dld [
4683
 ;// mike.dld [
4676
     mov   eax, [kb_state]
4684
     mov   eax, [kb_state]
4677
 ;// mike.dld ]
4685
 ;// mike.dld ]
4678
 
4686
 
4679
     mov   [esp+36],eax
4687
     mov   [esp+36],eax
4680
 
4688
 
4681
     ret
4689
     ret
4682
 
4690
 
4683
   no_get_keyboard_cas:
4691
   no_get_keyboard_cas:
4684
 
4692
 
4685
	dec	eax
4693
	dec	eax
4686
	jnz	no_add_keyboard_hotkey
4694
	jnz	no_add_keyboard_hotkey
4687
 
4695
 
4688
	mov	eax, hotkey_list
4696
	mov	eax, hotkey_list
4689
@@:
4697
@@:
4690
	cmp	dword [eax+8], 0
4698
	cmp	dword [eax+8], 0
4691
	jz	.found_free
4699
	jz	.found_free
4692
	add	eax, 16
4700
	add	eax, 16
4693
	cmp	eax, hotkey_list+16*256
4701
	cmp	eax, hotkey_list+16*256
4694
	jb	@b
4702
	jb	@b
4695
	mov	dword [esp+36], 1
4703
	mov	dword [esp+36], 1
4696
	ret
4704
	ret
4697
.found_free:
4705
.found_free:
4698
	mov	[eax+8], edi
4706
	mov	[eax+8], edi
4699
	mov	[eax+4], ecx
4707
	mov	[eax+4], ecx
4700
	movzx	ebx, bl
4708
	movzx	ebx, bl
4701
	lea	ebx, [hotkey_scancodes+ebx*4]
4709
	lea	ebx, [hotkey_scancodes+ebx*4]
4702
	mov	ecx, [ebx]
4710
	mov	ecx, [ebx]
4703
	mov	[eax], ecx
4711
	mov	[eax], ecx
4704
	mov	[ebx], eax
4712
	mov	[ebx], eax
4705
	mov	[eax+12], ebx
4713
	mov	[eax+12], ebx
4706
	jecxz	@f
4714
	jecxz	@f
4707
	mov	[ecx+12], eax
4715
	mov	[ecx+12], eax
4708
@@:
4716
@@:
4709
	and	dword [esp+36], 0
4717
	and	dword [esp+36], 0
4710
	ret
4718
	ret
4711
 
4719
 
4712
no_add_keyboard_hotkey:
4720
no_add_keyboard_hotkey:
4713
 
4721
 
4714
	dec	eax
4722
	dec	eax
4715
	jnz	no_del_keyboard_hotkey
4723
	jnz	no_del_keyboard_hotkey
4716
 
4724
 
4717
	movzx	ebx, bl
4725
	movzx	ebx, bl
4718
	lea	ebx, [hotkey_scancodes+ebx*4]
4726
	lea	ebx, [hotkey_scancodes+ebx*4]
4719
	mov	eax, [ebx]
4727
	mov	eax, [ebx]
4720
.scan:
4728
.scan:
4721
	test	eax, eax
4729
	test	eax, eax
4722
	jz	.notfound
4730
	jz	.notfound
4723
	cmp	[eax+8], edi
4731
	cmp	[eax+8], edi
4724
	jnz	.next
4732
	jnz	.next
4725
	cmp	[eax+4], ecx
4733
	cmp	[eax+4], ecx
4726
	jz	.found
4734
	jz	.found
4727
.next:
4735
.next:
4728
	mov	eax, [eax]
4736
	mov	eax, [eax]
4729
	jmp	.scan
4737
	jmp	.scan
4730
.notfound:
4738
.notfound:
4731
	mov	dword [esp+36], 1
4739
	mov	dword [esp+36], 1
4732
	ret
4740
	ret
4733
.found:
4741
.found:
4734
	mov	ecx, [eax]
4742
	mov	ecx, [eax]
4735
	jecxz	@f
4743
	jecxz	@f
4736
	mov	edx, [eax+12]
4744
	mov	edx, [eax+12]
4737
	mov	[ecx+12], edx
4745
	mov	[ecx+12], edx
4738
@@:
4746
@@:
4739
	mov	ecx, [eax+12]
4747
	mov	ecx, [eax+12]
4740
	mov	edx, [eax]
4748
	mov	edx, [eax]
4741
	mov	[ecx], edx
4749
	mov	[ecx], edx
4742
	xor	edx, edx
4750
	xor	edx, edx
4743
	mov	[eax+4], edx
4751
	mov	[eax+4], edx
4744
	mov	[eax+8], edx
4752
	mov	[eax+8], edx
4745
	mov	[eax+12], edx
4753
	mov	[eax+12], edx
4746
	mov	[eax], edx
4754
	mov	[eax], edx
4747
	mov	[esp+36], edx
4755
	mov	[esp+36], edx
4748
	ret
4756
	ret
4749
 
4757
 
4750
no_del_keyboard_hotkey:
4758
no_del_keyboard_hotkey:
4751
     ret
4759
     ret
4752
 
4760
 
4753
 
4761
 
4754
align 4
4762
align 4
4755
 
4763
 
4756
sys_gs: 			; direct screen access
4764
sys_gs: 			; direct screen access
4757
 
4765
 
4758
     cmp  eax,1 		; resolution
4766
     cmp  eax,1 		; resolution
4759
     jne  no_gs1
4767
     jne  no_gs1
4760
     mov  eax,[Screen_Max_X]
4768
     mov  eax,[Screen_Max_X]
4761
     shl  eax,16
4769
     shl  eax,16
4762
     mov  ax,[Screen_Max_Y]
4770
     mov  ax,[Screen_Max_Y]
4763
     add  eax,0x00010001
4771
     add  eax,0x00010001
4764
     mov  [esp+36],eax
4772
     mov  [esp+36],eax
4765
     ret
4773
     ret
4766
   no_gs1:
4774
   no_gs1:
4767
 
4775
 
4768
     cmp   eax,2		; bits per pixel
4776
     cmp   eax,2		; bits per pixel
4769
     jne   no_gs2
4777
     jne   no_gs2
4770
     movzx eax,byte [ScreenBPP]
4778
     movzx eax,byte [ScreenBPP]
4771
     mov   [esp+36],eax
4779
     mov   [esp+36],eax
4772
     ret
4780
     ret
4773
   no_gs2:
4781
   no_gs2:
4774
 
4782
 
4775
     cmp   eax,3		; bytes per scanline
4783
     cmp   eax,3		; bytes per scanline
4776
     jne   no_gs3
4784
     jne   no_gs3
4777
     mov   eax,[BytesPerScanLine]
4785
     mov   eax,[BytesPerScanLine]
4778
     mov   [esp+36],eax
4786
     mov   [esp+36],eax
4779
     ret
4787
     ret
4780
   no_gs3:
4788
   no_gs3:
4781
 
4789
 
4782
     mov  [esp+36],dword -1
4790
     mov  [esp+36],dword -1
4783
     ret
4791
     ret
4784
 
4792
 
4785
 
4793
 
4786
align 4 ; PCI functions
4794
align 4 ; PCI functions
4787
 
4795
 
4788
sys_pci:
4796
sys_pci:
4789
 
4797
 
4790
     call  pci_api
4798
     call  pci_api
4791
     mov   [esp+36],eax
4799
     mov   [esp+36],eax
4792
     ret
4800
     ret
4793
 
4801
 
4794
 
4802
 
4795
align 4  ;  system functions
4803
align 4  ;  system functions
4796
 
4804
 
4797
syscall_setpixel:			; SetPixel
4805
syscall_setpixel:			; SetPixel
4798
 
4806
 
4799
	mov	eax, ebx
4807
	mov	eax, ebx
4800
	mov	ebx, ecx
4808
	mov	ebx, ecx
4801
	mov	ecx, edx
4809
	mov	ecx, edx
4802
	mov	edx, [TASK_BASE]
4810
	mov	edx, [TASK_BASE]
4803
	add	eax, [edx-twdw+WDATA.box.left]
4811
	add	eax, [edx-twdw+WDATA.box.left]
4804
	add	ebx, [edx-twdw+WDATA.box.top]
4812
	add	ebx, [edx-twdw+WDATA.box.top]
4805
	mov	edi, [current_slot]
4813
	mov	edi, [current_slot]
4806
	add	eax, [edi+APPDATA.wnd_clientbox.left]
4814
	add	eax, [edi+APPDATA.wnd_clientbox.left]
4807
	add	ebx, [edi+APPDATA.wnd_clientbox.top]
4815
	add	ebx, [edi+APPDATA.wnd_clientbox.top]
4808
	xor	edi, edi ; no force
4816
	xor	edi, edi ; no force
4809
;       mov     edi, 1
4817
;       mov     edi, 1
4810
	call	[disable_mouse]
4818
	call	[disable_mouse]
4811
	jmp	[putpixel]
4819
	jmp	[putpixel]
4812
 
4820
 
4813
align 4
4821
align 4
4814
 
4822
 
4815
syscall_writetext:			; WriteText
4823
syscall_writetext:			; WriteText
4816
 
4824
 
4817
	mov   eax,[TASK_BASE]
4825
	mov   eax,[TASK_BASE]
4818
	mov   ebp,[eax-twdw+WDATA.box.left]
4826
	mov   ebp,[eax-twdw+WDATA.box.left]
4819
	push  esi
4827
	push  esi
4820
	mov   esi,[current_slot]
4828
	mov   esi,[current_slot]
4821
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4829
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4822
	shl   ebp,16
4830
	shl   ebp,16
4823
	add   ebp,[eax-twdw+WDATA.box.top]
4831
	add   ebp,[eax-twdw+WDATA.box.top]
4824
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4832
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4825
	pop   esi
4833
	pop   esi
4826
	add   ebx,ebp
4834
	add   ebx,ebp
4827
	mov   eax,edi
4835
	mov   eax,edi
4828
	xor   edi,edi
4836
	xor   edi,edi
4829
	jmp   dtext
4837
	jmp   dtext
4830
 
4838
 
4831
align 4
4839
align 4
4832
 
4840
 
4833
syscall_openramdiskfile:		; OpenRamdiskFile
4841
syscall_openramdiskfile:		; OpenRamdiskFile
4834
 
4842
 
4835
	mov	eax, ebx
4843
	mov	eax, ebx
4836
	mov	ebx, ecx
4844
	mov	ebx, ecx
4837
	mov	ecx, edx
4845
	mov	ecx, edx
4838
	mov	edx, esi
4846
	mov	edx, esi
4839
	mov	esi, 12
4847
	mov	esi, 12
4840
	call	fileread
4848
	call	fileread
4841
	mov	[esp+32], eax
4849
	mov	[esp+32], eax
4842
	ret
4850
	ret
4843
 
4851
 
4844
align 4
4852
align 4
4845
 
4853
 
4846
syscall_drawrect:			; DrawRect
4854
syscall_drawrect:			; DrawRect
4847
 
4855
 
4848
	mov	edi, edx ; color + gradient
4856
	mov	edi, edx ; color + gradient
4849
	and	edi, 0x80FFFFFF
4857
	and	edi, 0x80FFFFFF
4850
	test	bx, bx	; x.size
4858
	test	bx, bx	; x.size
4851
	je	.drectr
4859
	je	.drectr
4852
	test	cx, cx ; y.size
4860
	test	cx, cx ; y.size
4853
	je	.drectr
4861
	je	.drectr
4854
 
4862
 
4855
	mov	eax, ebx ; bad idea
4863
	mov	eax, ebx ; bad idea
4856
	mov	ebx, ecx
4864
	mov	ebx, ecx
4857
 
4865
 
4858
	movzx	ecx, ax ; ecx - x.size
4866
	movzx	ecx, ax ; ecx - x.size
4859
	shr	eax, 16 ; eax - x.coord
4867
	shr	eax, 16 ; eax - x.coord
4860
	movzx	edx, bx ; edx - y.size
4868
	movzx	edx, bx ; edx - y.size
4861
	shr	ebx, 16 ; ebx - y.coord
4869
	shr	ebx, 16 ; ebx - y.coord
4862
	mov	esi, [current_slot]
4870
	mov	esi, [current_slot]
4863
 
4871
 
4864
	add	eax, [esi + APPDATA.wnd_clientbox.left]
4872
	add	eax, [esi + APPDATA.wnd_clientbox.left]
4865
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4873
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4866
	add	ecx, eax
4874
	add	ecx, eax
4867
	add	edx, ebx
4875
	add	edx, ebx
4868
	jmp	[drawbar]
4876
	jmp	[drawbar]
4869
.drectr:
4877
.drectr:
4870
	ret
4878
	ret
4871
 
4879
 
4872
align 4
4880
align 4
4873
syscall_getscreensize:			; GetScreenSize
4881
syscall_getscreensize:			; GetScreenSize
4874
	mov	ax, [Screen_Max_X]
4882
	mov	ax, [Screen_Max_X]
4875
	shl	eax, 16
4883
	shl	eax, 16
4876
	mov	ax, [Screen_Max_Y]
4884
	mov	ax, [Screen_Max_Y]
4877
	mov	[esp + 32], eax
4885
	mov	[esp + 32], eax
4878
	ret
4886
	ret
4879
 
4887
 
4880
align 4
4888
align 4
4881
 
4889
 
4882
syscall_cdaudio:			; CD
4890
syscall_cdaudio:			; CD
4883
 
4891
 
4884
	cmp	eax, 4
4892
	cmp	eax, 4
4885
	jb	.audio
4893
	jb	.audio
4886
	jz	.eject
4894
	jz	.eject
4887
	cmp	eax, 5
4895
	cmp	eax, 5
4888
	jnz	.ret
4896
	jnz	.ret
4889
.load:
4897
.load:
4890
	call	.reserve
4898
	call	.reserve
4891
	call	LoadMedium
4899
	call	LoadMedium
4892
	call	.free
4900
	call	.free
4893
	ret
4901
	ret
4894
.eject:
4902
.eject:
4895
	call	.reserve
4903
	call	.reserve
4896
	call	clear_CD_cache
4904
	call	clear_CD_cache
4897
	call	allow_medium_removal
4905
	call	allow_medium_removal
4898
	call	EjectMedium
4906
	call	EjectMedium
4899
	call	.free
4907
	call	.free
4900
	ret
4908
	ret
4901
.audio:
4909
.audio:
4902
     call  sys_cd_audio
4910
     call  sys_cd_audio
4903
     mov   [esp+36],eax
4911
     mov   [esp+36],eax
4904
.ret:
4912
.ret:
4905
     ret
4913
     ret
4906
 
4914
 
4907
.reserve:
4915
.reserve:
4908
	call	reserve_cd
4916
	call	reserve_cd
4909
	mov	eax, ebx
4917
	mov	eax, ebx
4910
	shr	eax, 1
4918
	shr	eax, 1
4911
	and	eax, 1
4919
	and	eax, 1
4912
	inc	eax
4920
	inc	eax
4913
	mov	[ChannelNumber], ax
4921
	mov	[ChannelNumber], ax
4914
	mov	eax, ebx
4922
	mov	eax, ebx
4915
	and	eax, 1
4923
	and	eax, 1
4916
	mov	[DiskNumber], al
4924
	mov	[DiskNumber], al
4917
	call	reserve_cd_channel
4925
	call	reserve_cd_channel
4918
	and	ebx, 3
4926
	and	ebx, 3
4919
	inc	ebx
4927
	inc	ebx
4920
	mov	[cdpos], ebx
4928
	mov	[cdpos], ebx
4921
	add	ebx, ebx
4929
	add	ebx, ebx
4922
	mov	cl, 8
4930
	mov	cl, 8
4923
	sub	cl, bl
4931
	sub	cl, bl
4924
	mov	al, [DRIVE_DATA+1]
4932
	mov	al, [DRIVE_DATA+1]
4925
	shr	al, cl
4933
	shr	al, cl
4926
	test	al, 2
4934
	test	al, 2
4927
	jz	.err
4935
	jz	.err
4928
	ret
4936
	ret
4929
.free:
4937
.free:
4930
	call	free_cd_channel
4938
	call	free_cd_channel
4931
	and	[cd_status], 0
4939
	and	[cd_status], 0
4932
	ret
4940
	ret
4933
.err:
4941
.err:
4934
	call	.free
4942
	call	.free
4935
	pop	eax
4943
	pop	eax
4936
	ret
4944
	ret
4937
 
4945
 
4938
align 4
4946
align 4
4939
 
4947
 
4940
syscall_getpixel:			; GetPixel
4948
syscall_getpixel:			; GetPixel
4941
     mov   ecx, [Screen_Max_X]
4949
     mov   ecx, [Screen_Max_X]
4942
     inc   ecx
4950
     inc   ecx
4943
     xor   edx, edx
4951
     xor   edx, edx
4944
     mov   eax, ebx
4952
     mov   eax, ebx
4945
     div   ecx
4953
     div   ecx
4946
     mov   ebx, edx
4954
     mov   ebx, edx
4947
     xchg  eax, ebx
4955
     xchg  eax, ebx
4948
     call  dword [GETPIXEL] ; eax - x, ebx - y
4956
     call  dword [GETPIXEL] ; eax - x, ebx - y
4949
     mov   [esp + 32], ecx
4957
     mov   [esp + 32], ecx
4950
     ret
4958
     ret
4951
 
4959
 
4952
 
4960
 
4953
align 4
4961
align 4
4954
 
4962
 
4955
syscall_drawline:			; DrawLine
4963
syscall_drawline:			; DrawLine
4956
 
4964
 
4957
	mov	edi, [TASK_BASE]
4965
	mov	edi, [TASK_BASE]
4958
	movzx	eax, word[edi-twdw+WDATA.box.left]
4966
	movzx	eax, word[edi-twdw+WDATA.box.left]
4959
	mov	ebp, eax
4967
	mov	ebp, eax
4960
	mov	esi, [current_slot]
4968
	mov	esi, [current_slot]
4961
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
4969
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
4962
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
4970
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
4963
	add	ebp,ebx
4971
	add	ebp,ebx
4964
	shl	eax, 16
4972
	shl	eax, 16
4965
	movzx	ebx, word[edi-twdw+WDATA.box.top]
4973
	movzx	ebx, word[edi-twdw+WDATA.box.top]
4966
	add	eax, ebp
4974
	add	eax, ebp
4967
	mov	ebp, ebx
4975
	mov	ebp, ebx
4968
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
4976
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
4969
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
4977
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
4970
	add	ebp, ecx
4978
	add	ebp, ecx
4971
	shl	ebx, 16
4979
	shl	ebx, 16
4972
	xor	edi, edi
4980
	xor	edi, edi
4973
	add	ebx, ebp
4981
	add	ebx, ebp
4974
	mov	ecx, edx
4982
	mov	ecx, edx
4975
	jmp	[draw_line]
4983
	jmp	[draw_line]
4976
 
4984
 
4977
align 4
4985
align 4
4978
 
4986
 
4979
syscall_getirqowner:			; GetIrqOwner
4987
syscall_getirqowner:			; GetIrqOwner
4980
 
4988
 
4981
     cmp   ebx,16
4989
     cmp   ebx,16
4982
     jae   .err
4990
     jae   .err
4983
 
4991
 
4984
     cmp   [irq_rights + 4 * ebx], dword 2
4992
     cmp   [irq_rights + 4 * ebx], dword 2
4985
     je    .err
4993
     je    .err
4986
 
4994
 
4987
     mov   eax,[4 * ebx + irq_owner]
4995
     mov   eax,[4 * ebx + irq_owner]
4988
     mov   [esp+32],eax
4996
     mov   [esp+32],eax
4989
 
4997
 
4990
     ret
4998
     ret
4991
.err:
4999
.err:
4992
     or    dword [esp+32], -1
5000
     or    dword [esp+32], -1
4993
     ret
5001
     ret
4994
 
5002
 
4995
align 4
5003
align 4
4996
 
5004
 
4997
syscall_reserveportarea:		; ReservePortArea and FreePortArea
5005
syscall_reserveportarea:		; ReservePortArea and FreePortArea
4998
 
5006
 
4999
     call  r_f_port_area
5007
     call  r_f_port_area
5000
     mov   [esp+36],eax
5008
     mov   [esp+36],eax
5001
     ret
5009
     ret
5002
 
5010
 
5003
align 4
5011
align 4
5004
 
5012
 
5005
syscall_threads:			; CreateThreads
5013
syscall_threads:			; CreateThreads
5006
 
5014
 
5007
     call  sys_threads
5015
     call  sys_threads
5008
     mov   [esp+36],eax
5016
     mov   [esp+36],eax
5009
     ret
5017
     ret
5010
 
5018
 
5011
align 4
5019
align 4
5012
 
5020
 
5013
stack_driver_stat:
5021
stack_driver_stat:
5014
 
5022
 
5015
     call  app_stack_handler		; Stack status
5023
     call  app_stack_handler		; Stack status
5016
 
5024
 
5017
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5025
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5018
;     call  change_task                 ; between sent packet
5026
;     call  change_task                 ; between sent packet
5019
 
5027
 
5020
     mov   [esp+36],eax
5028
     mov   [esp+36],eax
5021
     ret
5029
     ret
5022
 
5030
 
5023
align 4
5031
align 4
5024
 
5032
 
5025
socket: 				; Socket interface
5033
socket: 				; Socket interface
5026
     call  app_socket_handler
5034
     call  app_socket_handler
5027
 
5035
 
5028
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5036
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5029
;     call  change_task                 ; between sent packet
5037
;     call  change_task                 ; between sent packet
5030
 
5038
 
5031
     mov   [esp+36],eax
5039
     mov   [esp+36],eax
5032
     mov   [esp+24],ebx
5040
     mov   [esp+24],ebx
5033
     ret
5041
     ret
5034
 
5042
 
5035
align 4
5043
align 4
5036
 
5044
 
5037
read_from_hd:				; Read from hd - fn not in use
5045
read_from_hd:				; Read from hd - fn not in use
5038
 
5046
 
5039
     mov   edi,[TASK_BASE]
5047
     mov   edi,[TASK_BASE]
5040
     add   edi,TASKDATA.mem_start
5048
     add   edi,TASKDATA.mem_start
5041
     add   eax,[edi]
5049
     add   eax,[edi]
5042
     add   ecx,[edi]
5050
     add   ecx,[edi]
5043
     add   edx,[edi]
5051
     add   edx,[edi]
5044
     call  file_read
5052
     call  file_read
5045
 
5053
 
5046
     mov   [esp+36],eax
5054
     mov   [esp+36],eax
5047
     mov   [esp+24],ebx
5055
     mov   [esp+24],ebx
5048
 
5056
 
5049
     ret
5057
     ret
5050
 
5058
 
5051
paleholder:
5059
paleholder:
5052
	ret
5060
	ret
5053
 
5061
 
5054
align 4
5062
align 4
5055
set_screen:
5063
set_screen:
5056
	cmp eax, [Screen_Max_X]
5064
	cmp eax, [Screen_Max_X]
5057
	jne .set
5065
	jne .set
5058
 
5066
 
5059
	cmp edx, [Screen_Max_Y]
5067
	cmp edx, [Screen_Max_Y]
5060
	jne .set
5068
	jne .set
5061
	ret
5069
	ret
5062
.set:
5070
.set:
5063
	pushfd
5071
	pushfd
5064
	cli
5072
	cli
5065
 
5073
 
5066
	mov [Screen_Max_X], eax
5074
	mov [Screen_Max_X], eax
5067
	mov [Screen_Max_Y], edx
5075
	mov [Screen_Max_Y], edx
5068
 
5076
 
5069
	mov [screen_workarea.right],eax
5077
	mov [screen_workarea.right],eax
5070
	mov [screen_workarea.bottom], edx
5078
	mov [screen_workarea.bottom], edx
5071
	inc eax
5079
	inc eax
5072
	shl eax, 2			;32 bpp
5080
	shl eax, 2			;32 bpp
5073
	mov [BytesPerScanLine], eax
5081
	mov [BytesPerScanLine], eax
5074
	push ebx
5082
	push ebx
5075
	push esi
5083
	push esi
5076
	push edi
5084
	push edi
5077
	call	repos_windows
5085
	call	repos_windows
5078
	mov	eax, 0
5086
	mov	eax, 0
5079
	mov	ebx, 0
5087
	mov	ebx, 0
5080
	mov	ecx, [Screen_Max_X]
5088
	mov	ecx, [Screen_Max_X]
5081
	mov	edx, [Screen_Max_Y]
5089
	mov	edx, [Screen_Max_Y]
5082
	call	calculatescreen
5090
	call	calculatescreen
5083
	pop edi
5091
	pop edi
5084
	pop esi
5092
	pop esi
5085
	pop ebx
5093
	pop ebx
5086
 
5094
 
5087
	popfd
5095
	popfd
5088
	ret
5096
	ret
5089
 
5097
 
5090
; --------------- APM ---------------------
5098
; --------------- APM ---------------------
5091
apm_entry    dp    0
5099
apm_entry    dp    0
5092
apm_vf	      dd    0
5100
apm_vf	      dd    0
5093
align 4
5101
align 4
5094
sys_apm:
5102
sys_apm:
5095
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5103
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5096
    jne    @f
5104
    jne    @f
5097
    or	  [esp + 56], byte 1	; error
5105
    or	  [esp + 56], byte 1	; error
5098
    mov    [esp + 36], dword 8	  ; 32-bit protected-mode interface not supported
5106
    mov    [esp + 36], dword 8	  ; 32-bit protected-mode interface not supported
5099
    ret
5107
    ret
5100
 
5108
 
5101
@@:
5109
@@:
5102
    xchg    eax, ecx
5110
    xchg    eax, ecx
5103
    xchg    ebx, ecx
5111
    xchg    ebx, ecx
5104
 
5112
 
5105
    cmp    al, 3
5113
    cmp    al, 3
5106
    ja	  @f
5114
    ja	  @f
5107
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
5115
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
5108
    mov    eax, [apm_vf]
5116
    mov    eax, [apm_vf]
5109
    mov    [esp + 36], eax
5117
    mov    [esp + 36], eax
5110
    shr    eax, 16
5118
    shr    eax, 16
5111
    mov    [esp + 32], eax
5119
    mov    [esp + 32], eax
5112
    ret
5120
    ret
5113
 
5121
 
5114
@@:
5122
@@:
5115
 
5123
 
5116
    mov esi, [master_tab+(OS_BASE shr 20)]
5124
    mov esi, [master_tab+(OS_BASE shr 20)]
5117
    xchg [master_tab], esi
5125
    xchg [master_tab], esi
5118
    push esi
5126
    push esi
5119
    mov edi, cr3
5127
    mov edi, cr3
5120
    mov cr3, edi		 ;flush TLB
5128
    mov cr3, edi		 ;flush TLB
5121
 
5129
 
5122
    call    pword [apm_entry]	 ; call APM BIOS
5130
    call    pword [apm_entry]	 ; call APM BIOS
5123
 
5131
 
5124
    xchg eax, [esp]
5132
    xchg eax, [esp]
5125
    mov [master_tab], eax
5133
    mov [master_tab], eax
5126
    mov eax, cr3
5134
    mov eax, cr3
5127
    mov cr3, eax
5135
    mov cr3, eax
5128
    pop eax
5136
    pop eax
5129
 
5137
 
5130
    mov    [esp + 8 ], edi
5138
    mov    [esp + 8 ], edi
5131
    mov    [esp + 12], esi
5139
    mov    [esp + 12], esi
5132
    mov    [esp + 24], ebx
5140
    mov    [esp + 24], ebx
5133
    mov    [esp + 28], edx
5141
    mov    [esp + 28], edx
5134
    mov    [esp + 32], ecx
5142
    mov    [esp + 32], ecx
5135
    mov    [esp + 36], eax
5143
    mov    [esp + 36], eax
5136
    setc    al
5144
    setc    al
5137
    and    [esp + 56], byte 0xfe
5145
    and    [esp + 56], byte 0xfe
5138
    or	  [esp + 56], al
5146
    or	  [esp + 56], al
5139
 
5147
 
5140
 
5148
 
5141
    ret
5149
    ret
5142
; -----------------------------------------
5150
; -----------------------------------------
5143
 
5151
 
5144
align 4
5152
align 4
5145
 
5153
 
5146
undefined_syscall:			; Undefined system call
5154
undefined_syscall:			; Undefined system call
5147
     mov   [esp + 32], dword -1
5155
     mov   [esp + 32], dword -1
5148
     ret
5156
     ret
5149
 
5157
 
5150
align 4
5158
align 4
5151
system_shutdown:	  ; shut down the system
5159
system_shutdown:	  ; shut down the system
5152
 
5160
 
5153
	   cmp byte [BOOT_VAR+0x9030], 1
5161
	   cmp byte [BOOT_VAR+0x9030], 1
5154
	   jne @F
5162
	   jne @F
5155
	   ret
5163
	   ret
5156
@@:
5164
@@:
5157
	   call stop_all_services
5165
	   call stop_all_services
5158
	   push 3		 ; stop playing cd
5166
	   push 3		 ; stop playing cd
5159
	   pop	eax
5167
	   pop	eax
5160
	   call sys_cd_audio
5168
	   call sys_cd_audio
5161
 
5169
 
5162
yes_shutdown_param:
5170
yes_shutdown_param:
5163
 
5171
 
5164
	   cli
5172
	   cli
5165
 
5173
 
5166
           cmp byte [BOOT_VAR+0x9030], 3
5174
           cmp byte [BOOT_VAR+0x9030], 3
5167
           je _sys_reboot
5175
           je _sys_reboot
5168
 
5176
 
5169
           cmp byte [BOOT_VAR+0x9030], 4
5177
           cmp byte [BOOT_VAR+0x9030], 4
5170
           je _sys_restart
5178
           je _sys_restart
5171
 
5179
 
5172
           cld
5180
           cld
5173
           mov  esi, BOOT_VAR    ; restore 0x0 - 0xffff
5181
           mov  esi, BOOT_VAR    ; restore 0x0 - 0xffff
5174
           mov  edi, OS_BASE
5182
           mov  edi, OS_BASE
5175
           mov  ecx,0x10000/4
5183
           mov  ecx,0x10000/4
5176
           rep movsd
5184
           rep movsd
5177
 
5185
 
5178
           mov esi, _16bit_start + OS_BASE
5186
           mov esi, _16bit_start + OS_BASE
5179
           mov ecx, _16bit_end
5187
           mov ecx, _16bit_end
5180
           shr ecx, 2
5188
           shr ecx, 2
5181
           mov edi, _16BIT_BASE + OS_BASE
5189
           mov edi, _16BIT_BASE + OS_BASE
5182
           rep movsd
5190
           rep movsd
5183
 
5191
 
5184
           mov dword [_sys_pdbr],   PG_LARGE+PG_SW
5192
           mov dword [_sys_pdbr],   PG_LARGE+PG_SW
5185
           mov eax, _sys_pdbr + (0x100000000-OS_BASE)
5193
           mov eax, _sys_pdbr + (0x100000000-OS_BASE)
5186
           mov cr3, eax
5194
           mov cr3, eax
5187
 
5195
 
5188
           jmp far 0x60:_poweroff;
5196
           jmp far 0x60:_poweroff;
5189
 
5197
 
5190
 
5198
 
5191
_sys_restart:
5199
_sys_restart:
5192
 
5200
 
5193
           mov ax,os_stack
5201
           mov ax,os_stack
5194
           mov dx,app_data
5202
           mov dx,app_data
5195
	   mov ss,ax
5203
	   mov ss,ax
5196
           mov esp, __os_stack
5204
           mov esp, __os_stack
5197
 
5205
 
5198
           mov ds, dx
5206
           mov ds, dx
5199
           mov es, dx
5207
           mov es, dx
5200
           mov fs, dx
5208
           mov fs, dx
5201
           mov gs, dx
5209
           mov gs, dx
5202
 
5210
 
5203
           call restorefatchain
5211
           call restorefatchain
5204
 
5212
 
5205
           cld
5213
           cld
5206
           mov  esi, BOOT_VAR    ; restore 0x0 - 0xffff
5214
           mov  esi, BOOT_VAR    ; restore 0x0 - 0xffff
5207
           mov  edi, OS_BASE
5215
           mov  edi, OS_BASE
5208
           mov  ecx,0x10000/4
5216
           mov  ecx,0x10000/4
5209
           rep movsd
5217
           rep movsd
5210
 
5218
 
5211
           mov eax, [_copy_pg_balloc]
5219
           mov eax, [_copy_pg_balloc]
5212
           mov [_pg_balloc], eax
5220
           mov [_pg_balloc], eax
5213
 
5221
 
5214
           mov dword [_sys_pdbr],   PG_LARGE+PG_SW
5222
           mov dword [_sys_pdbr],   PG_LARGE+PG_SW
5215
           mov eax, _sys_pdbr + (0x100000000-OS_BASE)
5223
           mov eax, _sys_pdbr + (0x100000000-OS_BASE)
5216
           mov cr3, eax
5224
           mov cr3, eax
5217
 
5225
 
5218
           mov ecx, LAST_PAGE
5226
           mov ecx, LAST_PAGE
5219
           mov edi, cur_saved_data
5227
           mov edi, cur_saved_data
5220
           sub edi, OS_BASE
5228
           sub edi, OS_BASE
5221
           sub ecx, edi
5229
           sub ecx, edi
5222
           shr ecx, 2
5230
           shr ecx, 2
5223
           xor eax, eax
5231
           xor eax, eax
5224
           rep stosd
5232
           rep stosd
5225
 
5233
 
5226
           call test_cpu
5234
           call test_cpu
5227
 
5235
 
5228
   ;        jmp __core_restart
5236
   ;        jmp __core_restart
5229
 
5237
 
5230
_sys_reboot:
5238
_sys_reboot:
5231
           mov  word [OS_BASE+0x467+0],0xFFF0
5239
           mov  word [OS_BASE+0x467+0],0xFFF0
5232
           mov  word [OS_BASE+0x467+2],0xF000
5240
           mov  word [OS_BASE+0x467+2],0xF000
5233
 
5241
 
5234
	   mov	al,0x0F
5242
	   mov	al,0x0F
5235
	   out	0x70,al
5243
	   out	0x70,al
5236
	   mov	al,0x05
5244
	   mov	al,0x05
5237
	   out	0x71,al
5245
	   out	0x71,al
5238
 
5246
 
5239
	   mov	al,0xFE
5247
	   mov	al,0xFE
5240
	   out	0x64,al
5248
	   out	0x64,al
5241
 
5249
 
5242
	   hlt
5250
	   hlt
5243
 
5251
 
5244
include "data32.inc"
5252
include "data32.inc"
5245
 
5253
 
5246
__REV__ = __REV
5254
__REV__ = __REV
5247
 
5255
 
5248
;uglobals_size = $ - endofcode
5256
;uglobals_size = $ - endofcode
5249
;diff16 "end of kernel code",0,$
5257
;diff16 "end of kernel code",0,$