Subversion Repositories Kolibri OS

Rev

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

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