Subversion Repositories Kolibri OS

Rev

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

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