Subversion Repositories Kolibri OS

Rev

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

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