Subversion Repositories Kolibri OS

Rev

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

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