Subversion Repositories Kolibri OS

Rev

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

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