Subversion Repositories Kolibri OS

Rev

Rev 3531 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3531 Rev 3573
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
2
;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.
3
;; Copyright (C) KolibriOS team 2004-2013. 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
;; Hidnplayr
20
;; Hidnplayr
21
;; Alexey Teplov ()
21
;; Alexey Teplov ()
22
;; Artem Jerdev (art_zh)
22
;; Artem Jerdev (art_zh)
23
;;
23
;;
24
;; Data in this file was originally part of MenuetOS project which is
24
;; Data in this file was originally part of MenuetOS project which is
25
;; distributed under the terms of GNU GPL. It is modified and redistributed as
25
;; distributed under the terms of GNU GPL. It is modified and redistributed as
26
;; part of KolibriOS project under the terms of GNU GPL.
26
;; part of KolibriOS project under the terms of GNU GPL.
27
;;
27
;;
28
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
28
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
29
;; PROGRAMMING:
29
;; PROGRAMMING:
30
;;
30
;;
31
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
31
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
32
;; - main os coding/design
32
;; - main os coding/design
33
;; Jan-Michael Brummer, BUZZ2@gmx.de
33
;; Jan-Michael Brummer, BUZZ2@gmx.de
34
;; Felix Kaiser, info@felix-kaiser.de
34
;; Felix Kaiser, info@felix-kaiser.de
35
;; Paolo Minazzi, paolo.minazzi@inwind.it
35
;; Paolo Minazzi, paolo.minazzi@inwind.it
36
;; quickcode@mail.ru
36
;; quickcode@mail.ru
37
;; Alexey, kgaz@crosswinds.net
37
;; Alexey, kgaz@crosswinds.net
38
;; Juan M. Caravaca, bitrider@wanadoo.es
38
;; Juan M. Caravaca, bitrider@wanadoo.es
39
;; kristol@nic.fi
39
;; kristol@nic.fi
40
;; Mike Hibbett, mikeh@oceanfree.net
40
;; Mike Hibbett, mikeh@oceanfree.net
41
;; Lasse Kuusijarvi, kuusijar@lut.fi
41
;; Lasse Kuusijarvi, kuusijar@lut.fi
42
;; Jarek Pelczar, jarekp3@wp.pl
42
;; Jarek Pelczar, jarekp3@wp.pl
43
;;
43
;;
44
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
44
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
45
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
45
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
46
;; consequences of using it or for whether it serves any particular purpose or
46
;; consequences of using it or for whether it serves any particular purpose or
47
;; works at all, unless he says so in writing. Refer to the GNU General Public
47
;; works at all, unless he says so in writing. Refer to the GNU General Public
48
;; License (the "GPL") for full details.
48
;; License (the "GPL") for full details.
49
;
49
;
50
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
50
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
51
;; but only under the conditions described in the GPL. A copy of this license
51
;; but only under the conditions described in the GPL. A copy of this license
52
;; is supposed to have been given to you along with KolibriOS so you can know
52
;; is supposed to have been given to you along with KolibriOS so you can know
53
;; your rights and responsibilities. It should be in a file named COPYING.
53
;; your rights and responsibilities. It should be in a file named COPYING.
54
;; Among other things, the copyright notice and this notice must be preserved
54
;; Among other things, the copyright notice and this notice must be preserved
55
;; on all copies.
55
;; on all copies.
56
;;
56
;;
57
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58
 
58
 
59
include 'macros.inc'
59
include 'macros.inc'
60
 
60
 
61
$Revision: 3531 $
61
$Revision: 3573 $
62
 
62
 
63
 
63
 
64
USE_COM_IRQ	equ 1	   ; make irq 3 and irq 4 available for PCI devices
64
USE_COM_IRQ	equ 1	   ; make irq 3 and irq 4 available for PCI devices
65
 
65
 
66
include "proc32.inc"
66
include "proc32.inc"
67
include "kglobals.inc"
67
include "kglobals.inc"
68
 
68
 
69
include "const.inc"
69
include "const.inc"
70
max_processes	 equ   255
70
max_processes	 equ   255
71
tss_step	 equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
71
tss_step	 equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
72
 
72
 
73
 
73
 
74
os_stack       equ  (os_data_l-gdts)	; GDTs
74
os_stack       equ  (os_data_l-gdts)	; GDTs
75
os_code        equ  (os_code_l-gdts)
75
os_code        equ  (os_code_l-gdts)
76
graph_data     equ  (3+graph_data_l-gdts)
76
graph_data     equ  (3+graph_data_l-gdts)
77
tss0	       equ  (tss0_l-gdts)
77
tss0	       equ  (tss0_l-gdts)
78
app_code       equ  (3+app_code_l-gdts)
78
app_code       equ  (3+app_code_l-gdts)
79
app_data       equ  (3+app_data_l-gdts)
79
app_data       equ  (3+app_data_l-gdts)
80
app_tls        equ  (3+tls_data_l-gdts)
80
app_tls        equ  (3+tls_data_l-gdts)
81
pci_code_sel   equ  (pci_code_32-gdts)
81
pci_code_sel   equ  (pci_code_32-gdts)
82
pci_data_sel   equ  (pci_data_32-gdts)
82
pci_data_sel   equ  (pci_data_32-gdts)
83
 
83
 
84
 
84
 
85
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
86
;;
86
;;
87
;;   Included files:
87
;;   Included files:
88
;;
88
;;
89
;;   Kernel16.inc
89
;;   Kernel16.inc
90
;;    - Bootcode.inc  Hardware setup
90
;;    - Bootcode.inc  Hardware setup
91
;;
91
;;
92
;;   Kernel32.inc
92
;;   Kernel32.inc
93
;;    - Sys32.inc     Process management
93
;;    - Sys32.inc     Process management
94
;;    - Shutdown.inc  Shutdown and restart
94
;;    - Shutdown.inc  Shutdown and restart
95
;;    - Fat32.inc     Read / write hd
95
;;    - Fat32.inc     Read / write hd
96
;;    - Vesa12.inc    Vesa 1.2 driver
96
;;    - Vesa12.inc    Vesa 1.2 driver
97
;;    - Vesa20.inc    Vesa 2.0 driver
97
;;    - Vesa20.inc    Vesa 2.0 driver
98
;;    - Vga.inc       VGA driver
98
;;    - Vga.inc       VGA driver
99
;;    - Stack.inc     Network interface
99
;;    - Stack.inc     Network interface
100
;;    - Mouse.inc     Mouse pointer
100
;;    - Mouse.inc     Mouse pointer
101
;;    - Scincode.inc  Window skinning
101
;;    - Scincode.inc  Window skinning
102
;;    - Pci32.inc     PCI functions
102
;;    - Pci32.inc     PCI functions
103
;;
103
;;
104
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105
 
105
 
106
 
106
 
107
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
108
;;                                                                      ;;
108
;;                                                                      ;;
109
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
109
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
110
;;                                                                      ;;
110
;;                                                                      ;;
111
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112
 
112
 
113
use16
113
use16
114
		  org	0x0
114
		  org	0x0
115
		  jmp	start_of_code
115
		  jmp	start_of_code
116
 
116
 
117
version db    'Kolibri-A   version 0.1.0.0      ',13,10,13,10,0
117
version db    'Kolibri-A   version 0.1.0.0      ',13,10,13,10,0
118
 
118
 
119
diff16 "bootcode start: ",0,$
119
diff16 "bootcode start: ",0,$
120
include "boot/bootcode.inc"    ; 16 bit system boot code
120
include "boot/bootcode.inc"    ; 16 bit system boot code
121
 
121
 
122
diff16 "biosdisk start: ",0,$
122
diff16 "biosdisk start: ",0,$
123
include "detect/biosdisk.inc"
123
include "detect/biosdisk.inc"
124
 
124
 
125
diff16 "end of code16 : ",0,$
125
diff16 "end of code16 : ",0,$
126
 
126
 
127
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
128
;;                                                                      ;;
128
;;                                                                      ;;
129
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
129
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
130
;;                                                                      ;;
130
;;                                                                      ;;
131
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132
 
132
 
133
switch_32:
133
switch_32:
134
; CR0 Flags - Protected mode and Paging
134
; CR0 Flags - Protected mode and Paging
135
 
135
 
136
	mov ecx, CR0_PE
136
	mov ecx, CR0_PE
137
 
137
 
138
; Enabling 32 bit protected mode
138
; Enabling 32 bit protected mode
139
 
139
 
140
	sidt	[cs:old_ints_h]
140
	sidt	[cs:old_ints_h]
141
 
141
 
142
	cli				; disable all irqs
142
	cli				; disable all irqs
143
	cld
143
	cld
144
	mov	al,255			; mask all irqs
144
	mov	al,255			; mask all irqs
145
	out	0xa1,al
145
	out	0xa1,al
146
	out	0x21,al
146
	out	0x21,al
147
   l.5: in	al, 0x64		; Enable A20
147
   l.5: in	al, 0x64		; Enable A20
148
	test	al, 2
148
	test	al, 2
149
	jnz	l.5
149
	jnz	l.5
150
	mov	al, 0xD1
150
	mov	al, 0xD1
151
	out	0x64, al
151
	out	0x64, al
152
   l.6: in	al, 0x64
152
   l.6: in	al, 0x64
153
	test	al, 2
153
	test	al, 2
154
	jnz	l.6
154
	jnz	l.6
155
	mov	al, 0xDF
155
	mov	al, 0xDF
156
	out	0x60, al
156
	out	0x60, al
157
   l.7: in	al, 0x64
157
   l.7: in	al, 0x64
158
	test	al, 2
158
	test	al, 2
159
	jnz	l.7
159
	jnz	l.7
160
	mov	al, 0xFF
160
	mov	al, 0xFF
161
	out	0x64, al
161
	out	0x64, al
162
 
162
 
163
	lgdt	[cs:tmp_gdt]		; Load GDT
163
	lgdt	[cs:tmp_gdt]		; Load GDT
164
	mov	eax, cr0		; protected mode
164
	mov	eax, cr0		; protected mode
165
	or	eax, ecx
165
	or	eax, ecx
166
	and	eax, 10011111b *65536*256 + 0xffffff ; caching enabled
166
	and	eax, 10011111b *65536*256 + 0xffffff ; caching enabled
167
	mov	cr0, eax
167
	mov	cr0, eax
168
	jmp	pword os_code:B32	; jmp to enable 32 bit mode
168
	jmp	pword os_code:B32	; jmp to enable 32 bit mode
169
 
169
 
170
align 8
170
align 8
171
tmp_gdt:
171
tmp_gdt:
172
 
172
 
173
	dw     23
173
	dw     23
174
	dd     tmp_gdt+0x10000
174
	dd     tmp_gdt+0x10000
175
	dw     0
175
	dw     0
176
 
176
 
177
	dw     0xffff
177
	dw     0xffff
178
	dw     0x0000
178
	dw     0x0000
179
	db     0x00
179
	db     0x00
180
	dw     11011111b *256 +10011010b
180
	dw     11011111b *256 +10011010b
181
	db     0x00
181
	db     0x00
182
 
182
 
183
	dw     0xffff
183
	dw     0xffff
184
	dw     0x0000
184
	dw     0x0000
185
	db     0x00
185
	db     0x00
186
	dw     11011111b *256 +10010010b
186
	dw     11011111b *256 +10010010b
187
	db     0x00
187
	db     0x00
188
 
188
 
189
diff10 "32bit enter sz :",switch_32,$
189
diff10 "32bit enter sz :",switch_32,$
190
diff16 "data16   start :",0,$
190
diff16 "data16   start :",0,$
191
 
191
 
192
include "data16.inc"
192
include "data16.inc"
193
 
193
 
194
 
194
 
195
use32
195
use32
196
org $+0x10000
196
org $+0x10000
197
 
197
 
198
align 4
198
align 4
199
B32:
199
B32:
200
diff16 "32-bit code start ",0,$
200
diff16 "32-bit code start ",0,$
201
	   mov	 ax,os_stack	   ; Selector for os
201
	   mov	 ax,os_stack	   ; Selector for os
202
	   mov	 ds,ax
202
	   mov	 ds,ax
203
	   mov	 es,ax
203
	   mov	 es,ax
204
	   mov	 fs,ax
204
	   mov	 fs,ax
205
	   mov	 gs,ax
205
	   mov	 gs,ax
206
	   mov	 ss,ax
206
	   mov	 ss,ax
207
	   mov	 esp,0x4ec00	   ; Set stack
207
	   mov	 esp,0x4ec00	   ; Set stack
208
 
208
 
209
;-------------------------------------------------------------------------------
209
;-------------------------------------------------------------------------------
210
	   call preinit_mem	; (init.inc)
210
	   call preinit_mem	; (init.inc)
211
 
211
 
212
	   call test_cpu	; (init.inc - to be moved to bus/CPU.inc)
212
	   call test_cpu	; (init.inc - to be moved to bus/CPU.inc)
213
	   bts [cpu_caps-OS_BASE], CAPS_TSC	;force use rdtsc
213
	   bts [cpu_caps-OS_BASE], CAPS_TSC	;force use rdtsc
214
 
214
 
215
	   call init_BIOS32	; (init.inc - to be removed later)
215
	   call init_BIOS32	; (init.inc - to be removed later)
216
 
216
 
217
; PCIe extended config space access
217
; PCIe extended config space access
218
 
218
 
219
 
219
 
220
	call fusion_pcie_init	; (bus/HT.inc)
220
	call fusion_pcie_init	; (bus/HT.inc)
221
 
221
 
222
 
222
 
223
; MEMORY MODEL
223
; MEMORY MODEL
224
	   call init_mem	; (init.inc)
224
	   call init_mem	; (init.inc)
225
 
225
 
226
; ENABLE PAGING
226
; ENABLE PAGING
227
 
227
 
228
	   mov eax, sys_pgdir-OS_BASE
228
	   mov eax, sys_pgdir-OS_BASE
229
	   mov cr3, eax
229
	   mov cr3, eax
230
 
230
 
231
	   mov eax,cr0
231
	   mov eax,cr0
232
	   or eax,CR0_PG+CR0_WP
232
	   or eax,CR0_PG+CR0_WP
233
	   mov cr0,eax
233
	   mov cr0,eax
234
 
234
 
235
	   lgdt [gdts]
235
	   lgdt [gdts]
236
	   jmp pword os_code:high_code
236
	   jmp pword os_code:high_code
237
 
237
 
238
diff16 "32-bit init size ",B32,$
238
diff16 "32-bit init size ",B32,$
239
 
239
 
240
align 4
240
align 4
241
bios32_entry	dd ?
241
bios32_entry	dd ?
242
tmp_page_tabs	dd ?
242
tmp_page_tabs	dd ?
243
 
243
 
244
 
244
 
245
__DEBUG__ fix 1
245
__DEBUG__ fix 1
246
__DEBUG_LEVEL__ fix 1
246
__DEBUG_LEVEL__ fix 1
247
include 'init.inc'
247
include 'init.inc'
248
 
248
 
249
org OS_BASE+$
249
org OS_BASE+$
250
 
250
 
251
align 4
251
align 4
252
high_code:
252
high_code:
253
	   mov ax, os_stack
253
	   mov ax, os_stack
254
	   mov bx, app_data
254
	   mov bx, app_data
255
	   mov cx, app_tls
255
	   mov cx, app_tls
256
	   mov ss, ax
256
	   mov ss, ax
257
	   add esp, OS_BASE
257
	   add esp, OS_BASE
258
 
258
 
259
	   mov ds, bx
259
	   mov ds, bx
260
	   mov es, bx
260
	   mov es, bx
261
	   mov fs, cx
261
	   mov fs, cx
262
	   mov gs, bx
262
	   mov gs, bx
263
 
263
 
264
	   bt [cpu_caps], CAPS_PGE
264
	   bt [cpu_caps], CAPS_PGE
265
	   jnc @F
265
	   jnc @F
266
 
266
 
267
	   or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
267
	   or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
268
 
268
 
269
	   mov ebx, cr4
269
	   mov ebx, cr4
270
	   or ebx, CR4_PGE
270
	   or ebx, CR4_PGE
271
	   mov cr4, ebx
271
	   mov cr4, ebx
272
@@:
272
@@:
273
	   xor eax, eax
273
	   xor eax, eax
274
	   mov dword [sys_pgdir], eax
274
	   mov dword [sys_pgdir], eax
275
	   mov dword [sys_pgdir+4], eax
275
	   mov dword [sys_pgdir+4], eax
276
 
276
 
277
	   mov eax, cr3
277
	   mov eax, cr3
278
	   mov cr3, eax 	  ; flush TLB
278
	   mov cr3, eax 	  ; flush TLB
279
 
279
 
280
; SAVE REAL MODE VARIABLES
280
; SAVE REAL MODE VARIABLES
281
	xor	eax, eax
281
	xor	eax, eax
282
	mov	[IDEContrRegsBaseAddr], ax
282
	mov	[IDEContrRegsBaseAddr], ax
283
; -----------------------------------------
283
; -----------------------------------------
284
	inc	eax
284
	inc	eax
285
;        mov     al, [BOOT_VAR+0x901F]           ; DMA access
285
;        mov     al, [BOOT_VAR+0x901F]           ; DMA access
286
	mov	[allow_dma_access], al
286
	mov	[allow_dma_access], al
287
	mov	eax, 32 			; << bpp
287
	mov	eax, 32 			; << bpp
288
	mov	[ScreenBPP],al
288
	mov	[ScreenBPP],al
289
	mov	[_display.bpp], eax
289
	mov	[_display.bpp], eax
290
 
290
 
291
	mov	[_display.vrefresh], 60
291
	mov	[_display.vrefresh], 60
292
	mov	[_display.disable_mouse],  __sys_disable_mouse
292
	mov	[_display.disable_mouse],  __sys_disable_mouse
293
 
293
 
294
	mov	eax, 1024			; << X max
294
	mov	eax, 1024			; << X max
295
	mov	[_display.width], eax
295
	mov	[_display.width], eax
296
	dec	eax
296
	dec	eax
297
	mov	[Screen_Max_X],eax
297
	mov	[Screen_Max_X],eax
298
	mov	[screen_workarea.right],eax
298
	mov	[screen_workarea.right],eax
299
	mov	eax,768 			; << Y max
299
	mov	eax,768 			; << Y max
300
	mov	[_display.height], eax
300
	mov	[_display.height], eax
301
	dec	eax
301
	dec	eax
302
	mov	[Screen_Max_Y],eax
302
	mov	[Screen_Max_Y],eax
303
	mov	[screen_workarea.bottom],eax
303
	mov	[screen_workarea.bottom],eax
304
	mov	eax, 0x7055			; << screen mode
304
	mov	eax, 0x7055			; << screen mode
305
	mov	[SCR_MODE],eax
305
	mov	[SCR_MODE],eax
306
 
306
 
307
	mov	eax, 4096			; << may be different!
307
	mov	eax, 4096			; << may be different!
308
	mov	[BytesPerScanLine],ax
308
	mov	[BytesPerScanLine],ax
309
	mov	[_display.pitch], eax
309
	mov	[_display.pitch], eax
310
 
310
 
311
	mov	eax, [_display.width]
311
	mov	eax, [_display.width]
312
	mul	[_display.height]
312
	mul	[_display.height]
313
	mov	[_WinMapSize], eax
313
	mov	[_WinMapSize], eax
314
 
314
 
315
	mov	esi, BOOT_VAR+0x9080
315
	mov	esi, BOOT_VAR+0x9080
316
	movzx	ecx, byte [esi-1]
316
	movzx	ecx, byte [esi-1]
317
	mov	[NumBiosDisks], ecx
317
	mov	[NumBiosDisks], ecx
318
	mov	edi, BiosDisksData
318
	mov	edi, BiosDisksData
319
	rep	movsd
319
	rep	movsd
320
 
320
 
321
 
321
 
322
; GRAPHICS ADDRESSES
322
; GRAPHICS ADDRESSES
323
 
323
 
324
	and	byte [BOOT_VAR+0x901e],0x0
324
	and	byte [BOOT_VAR+0x901e],0x0
325
	mov	eax, [BOOT_VAR+0x9018]
325
	mov	eax, [BOOT_VAR+0x9018]
326
	mov	[LFBAddress],eax
326
	mov	[LFBAddress],eax
327
 
327
 
328
	mov	[PUTPIXEL],dword __sys_putpixel
328
	mov	[PUTPIXEL],dword __sys_putpixel
329
	mov	[GETPIXEL],dword get_pixel
329
	mov	[GETPIXEL],dword get_pixel
330
 
330
 
331
; -------- Fast System Call init ----------
331
; -------- Fast System Call init ----------
332
.SEnP:
332
.SEnP:
333
; AMD SYSCALL/SYSRET
333
; AMD SYSCALL/SYSRET
334
	   mov ecx, MSR_AMD_EFER
334
	   mov ecx, MSR_AMD_EFER
335
	   rdmsr
335
	   rdmsr
336
	   or eax, 1   ; bit_0 - System Call Extension (SCE)
336
	   or eax, 1   ; bit_0 - System Call Extension (SCE)
337
	   wrmsr
337
	   wrmsr
338
 
338
 
339
	; Bits of EDX :
339
	; Bits of EDX :
340
	; Bit 31..16 During the SYSRET instruction, this field is copied into the CS register
340
	; Bit 31..16 During the SYSRET instruction, this field is copied into the CS register
341
	;  and the contents of this field, plus 8, are copied into the SS register.
341
	;  and the contents of this field, plus 8, are copied into the SS register.
342
	; Bit 15..0 During the SYSCALL instruction, this field is copied into the CS register
342
	; Bit 15..0 During the SYSCALL instruction, this field is copied into the CS register
343
	;  and the contents of this field, plus 8, are copied into the SS register.
343
	;  and the contents of this field, plus 8, are copied into the SS register.
344
 
344
 
345
	   mov edx, 0x1B000B	; RING3 task stack will be used for fast syscalls!
345
	   mov edx, 0x1B000B	; RING3 task stack will be used for fast syscalls!
346
 
346
 
347
	   mov eax, syscall_entry
347
	   mov eax, syscall_entry
348
	   mov ecx, MSR_AMD_STAR
348
	   mov ecx, MSR_AMD_STAR
349
	   wrmsr
349
	   wrmsr
350
.noSYSCALL:
350
.noSYSCALL:
351
; -----------------------------------------
351
; -----------------------------------------
352
	stdcall alloc_page
352
	stdcall alloc_page
353
	stdcall map_page, tss-0xF80, eax, PG_SW 	; lower 0xF80 bytes might be used for something
353
	stdcall map_page, tss-0xF80, eax, PG_SW 	; lower 0xF80 bytes might be used for something
354
	stdcall alloc_page
354
	stdcall alloc_page
355
	inc	eax
355
	inc	eax
356
	mov	[SLOT_BASE+256+APPDATA.io_map], eax
356
	mov	[SLOT_BASE+256+APPDATA.io_map], eax
357
	stdcall map_page, tss+0x80, eax, PG_SW
357
	stdcall map_page, tss+0x80, eax, PG_SW
358
	stdcall alloc_page
358
	stdcall alloc_page
359
	inc	eax
359
	inc	eax
360
	mov	dword [SLOT_BASE+256+APPDATA.io_map+4], eax
360
	mov	dword [SLOT_BASE+256+APPDATA.io_map+4], eax
361
	stdcall map_page, tss+0x1080, eax, PG_SW
361
	stdcall map_page, tss+0x1080, eax, PG_SW
362
 
362
 
363
; LOAD IDT
363
; LOAD IDT
364
 
364
 
365
	   call 	build_interrupt_table ;lidt is executed
365
	   call 	build_interrupt_table ;lidt is executed
366
 
366
 
367
	   call 	init_kernel_heap
367
	   call 	init_kernel_heap
368
	   stdcall	kernel_alloc, RING0_STACK_SIZE+512
368
	   stdcall	kernel_alloc, RING0_STACK_SIZE+512
369
	   mov	[os_stack_seg], eax
369
	   mov	[os_stack_seg], eax
370
 
370
 
371
	   lea	esp, [eax+RING0_STACK_SIZE]
371
	   lea	esp, [eax+RING0_STACK_SIZE]
372
 
372
 
373
	   mov	[tss._ss0], os_stack
373
	   mov	[tss._ss0], os_stack
374
	   mov	[tss._esp0], esp
374
	   mov	[tss._esp0], esp
375
	   mov	[tss._esp], esp
375
	   mov	[tss._esp], esp
376
	   mov	[tss._cs],os_code
376
	   mov	[tss._cs],os_code
377
	   mov	[tss._ss],os_stack
377
	   mov	[tss._ss],os_stack
378
	   mov	[tss._ds],app_data
378
	   mov	[tss._ds],app_data
379
	   mov	[tss._es],app_data
379
	   mov	[tss._es],app_data
380
	   mov	[tss._fs],app_data
380
	   mov	[tss._fs],app_data
381
	   mov	[tss._gs],app_data
381
	   mov	[tss._gs],app_data
382
	   mov	[tss._io],128
382
	   mov	[tss._io],128
383
;Add IO access table - bit array of permitted ports
383
;Add IO access table - bit array of permitted ports
384
	   mov	edi, tss._io_map_0
384
	   mov	edi, tss._io_map_0
385
	   xor	eax, eax
385
	   xor	eax, eax
386
	   mov	ecx, 2047
386
	   mov	ecx, 2047
387
	   rep	stosd		     ; access to 65504 ports granted
387
	   rep	stosd		     ; access to 65504 ports granted
388
	   not	eax		     ; the last 32 ports blocked
388
	   not	eax		     ; the last 32 ports blocked
389
	   stosd
389
	   stosd
390
 
390
 
391
	   mov	ax,tss0
391
	   mov	ax,tss0
392
	   ltr	ax
392
	   ltr	ax
393
 
393
 
394
	   mov	[LFBSize], 0x800000
394
	   mov	[LFBSize], 0x800000
395
	   call init_LFB
395
	   call init_LFB
396
	   call init_fpu
396
	   call init_fpu
397
	   call init_malloc
397
	   call init_malloc
398
;-
398
;-
399
	   stdcall alloc_kernel_space, 0x51000
399
	   stdcall alloc_kernel_space, 0x51000
400
	   mov	[default_io_map], eax
400
	   mov	[default_io_map], eax
401
 
401
 
402
	   add	eax, 0x2000
402
	   add	eax, 0x2000
403
	   mov	[ipc_tmp], eax
403
	   mov	[ipc_tmp], eax
404
	   mov	ebx, 0x1000
404
	   mov	ebx, 0x1000
405
 
405
 
406
	   add	eax, 0x40000
406
	   add	eax, 0x40000
407
	   mov	[proc_mem_map], eax
407
	   mov	[proc_mem_map], eax
408
 
408
 
409
	   add	eax, 0x8000
409
	   add	eax, 0x8000
410
	   mov	[proc_mem_pdir], eax
410
	   mov	[proc_mem_pdir], eax
411
 
411
 
412
	   add	eax, ebx
412
	   add	eax, ebx
413
	   mov	[proc_mem_tab], eax
413
	   mov	[proc_mem_tab], eax
414
 
414
 
415
	   add	eax, ebx
415
	   add	eax, ebx
416
	   mov	[tmp_task_pdir], eax
416
	   mov	[tmp_task_pdir], eax
417
 
417
 
418
	   add	eax, ebx
418
	   add	eax, ebx
419
	   mov	[tmp_task_ptab], eax
419
	   mov	[tmp_task_ptab], eax
420
 
420
 
421
	   add	eax, ebx
421
	   add	eax, ebx
422
	   mov	[ipc_pdir], eax
422
	   mov	[ipc_pdir], eax
423
 
423
 
424
	   add	eax, ebx
424
	   add	eax, ebx
425
	   mov	[ipc_ptab], eax
425
	   mov	[ipc_ptab], eax
426
 
426
 
427
	   stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
427
	   stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
428
				 (unpack.lc+unpack.lp)))*4
428
				 (unpack.lc+unpack.lp)))*4
429
 
429
 
430
	   mov	[unpack.p], eax     ; unpacker.inc
430
	   mov	[unpack.p], eax     ; unpacker.inc
431
 
431
 
432
	   call init_events
432
	   call init_events
433
	   mov	eax, srv.fd-SRV_FD_OFFSET
433
	   mov	eax, srv.fd-SRV_FD_OFFSET
434
	   mov	[srv.fd], eax
434
	   mov	[srv.fd], eax
435
	   mov	[srv.bk], eax
435
	   mov	[srv.bk], eax
436
 
436
 
437
	   mov	edi, irq_tab
437
	   mov	edi, irq_tab
438
	   xor	eax, eax
438
	   xor	eax, eax
439
	   mov	ecx, 16
439
	   mov	ecx, 16
440
	   rep	stosd
440
	   rep	stosd
441
 
441
 
442
;Set base of graphic segment to linear address of LFB
442
;Set base of graphic segment to linear address of LFB
443
	mov	eax,[LFBAddress]	  ; set for gs
443
	mov	eax,[LFBAddress]	  ; set for gs
444
	mov	[graph_data_l+2],ax
444
	mov	[graph_data_l+2],ax
445
	shr	eax,16
445
	shr	eax,16
446
	mov	[graph_data_l+4],al
446
	mov	[graph_data_l+4],al
447
	mov	[graph_data_l+7],ah
447
	mov	[graph_data_l+7],ah
448
 
448
 
449
;       or      [KERNEL_ALLOC_FLAG], dword PG_NOCACHE   ;<<<<<<<<<<<<<<<<
449
;       or      [KERNEL_ALLOC_FLAG], dword PG_NOCACHE   ;<<<<<<<<<<<<<<<<
450
	stdcall kernel_alloc, [_WinMapSize]
450
	stdcall kernel_alloc, [_WinMapSize]
451
	mov	[_WinMapAddress], eax
451
	mov	[_WinMapAddress], eax
452
;       xor     [KERNEL_ALLOC_FLAG], dword PG_NOCACHE   ;<<<<<<<<<<<<<<<<
452
;       xor     [KERNEL_ALLOC_FLAG], dword PG_NOCACHE   ;<<<<<<<<<<<<<<<<
453
 
453
 
454
	xor  eax,eax
454
	xor  eax,eax
455
	inc  eax
455
	inc  eax
456
	mov [CURRENT_TASK],eax		;dword 1
456
	mov [CURRENT_TASK],eax		;dword 1
457
	mov [TASK_COUNT],eax		;dword 1
457
	mov [TASK_COUNT],eax		;dword 1
458
	mov [TASK_BASE],dword TASK_DATA
458
	mov [TASK_BASE],dword TASK_DATA
459
	mov [current_slot], SLOT_BASE+256
459
	mov [current_slot], SLOT_BASE+256
460
 
460
 
461
; set background
461
; set background
462
 
462
 
463
	mov   [BgrDrawMode],eax
463
	mov   [BgrDrawMode],eax
464
	mov   [BgrDataWidth],eax
464
	mov   [BgrDataWidth],eax
465
	mov   [BgrDataHeight],eax
465
	mov   [BgrDataHeight],eax
466
	mov   [mem_BACKGROUND], 4
466
	mov   [mem_BACKGROUND], 4
467
	mov   [img_background], static_background_data
467
	mov   [img_background], static_background_data
468
 
468
 
469
	mov	[SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE
469
	mov	[SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE
470
 
470
 
471
	stdcall kernel_alloc, 0x10000/8
471
	stdcall kernel_alloc, 0x10000/8
472
	mov	edi, eax
472
	mov	edi, eax
473
	mov	[network_free_ports], eax
473
	mov	[network_free_ports], eax
474
	or	eax, -1
474
	or	eax, -1
475
	mov	ecx, 0x10000/32
475
	mov	ecx, 0x10000/32
476
	rep	stosd
476
	rep	stosd
477
 
477
 
478
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
478
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
479
 
479
 
480
	call  rerouteirqs
480
	call  rerouteirqs
481
 
481
 
482
; Initialize system V86 machine
482
; Initialize system V86 machine
483
	call	init_sys_v86
483
	call	init_sys_v86
484
 
484
 
485
; TIMER SET TO 1/100 S
485
; TIMER SET TO 1/100 S
486
 
486
 
487
	mov   al,0x34		   ; set to 100Hz
487
	mov   al,0x34		   ; set to 100Hz
488
	out   0x43,al
488
	out   0x43,al
489
	mov   al,0x9b		   ; lsb    1193180 / 1193
489
	mov   al,0x9b		   ; lsb    1193180 / 1193
490
	out   0x40,al
490
	out   0x40,al
491
	mov   al,0x2e		   ; msb
491
	mov   al,0x2e		   ; msb
492
	out   0x40,al
492
	out   0x40,al
493
 
493
 
494
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
494
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
495
; they are used: when partitions are scanned, hd_read relies on timer
495
; they are used: when partitions are scanned, hd_read relies on timer
496
; Also enable IRQ2, because in some configurations
496
; Also enable IRQ2, because in some configurations
497
; IRQs from slave controller are not delivered until IRQ2 on master is enabled
497
; IRQs from slave controller are not delivered until IRQ2 on master is enabled
498
	mov	al, 0xFA
498
	mov	al, 0xFA
499
	out	0x21, al
499
	out	0x21, al
500
	mov	al, 0x3F
500
	mov	al, 0x3F
501
	out	0xA1, al
501
	out	0xA1, al
502
 
502
 
503
; Enable interrupts in IDE controller
503
; Enable interrupts in IDE controller
504
;       mov     al, 0
504
;       mov     al, 0
505
;       mov     dx, 0x3F6
505
;       mov     dx, 0x3F6
506
;       out     dx, al
506
;       out     dx, al
507
;       mov     dl, 0x76
507
;       mov     dl, 0x76
508
;       out     dx, al
508
;       out     dx, al
509
 
509
 
510
;!!!!!!!!!!!!!!!!!!!!!!!!!!
510
;!!!!!!!!!!!!!!!!!!!!!!!!!!
511
include 'detect/disks.inc'
511
include 'detect/disks.inc'
512
;!!!!!!!!!!!!!!!!!!!!!!!!!!
512
;!!!!!!!!!!!!!!!!!!!!!!!!!!
513
 
513
 
514
  call Parser_params
514
  call Parser_params
515
 
515
 
516
; READ RAMDISK IMAGE FROM HD
516
; READ RAMDISK IMAGE FROM HD
517
 
517
 
518
;!!!!!!!!!!!!!!!!!!!!!!!
518
;!!!!!!!!!!!!!!!!!!!!!!!
519
;include 'boot/rdload.inc'
519
;include 'boot/rdload.inc'
520
;!!!!!!!!!!!!!!!!!!!!!!!
520
;!!!!!!!!!!!!!!!!!!!!!!!
521
;    mov    [dma_hdd],1
521
;    mov    [dma_hdd],1
522
; CALCULATE FAT CHAIN FOR RAMDISK
522
; CALCULATE FAT CHAIN FOR RAMDISK
523
 
523
 
524
	call  calculatefatchain
524
	call  calculatefatchain
525
 
525
 
526
; LOAD VMODE DRIVER
526
; LOAD VMODE DRIVER
527
 
527
 
528
;!!!!!!!!!!!!!!!!!!!!!!!
528
;!!!!!!!!!!!!!!!!!!!!!!!
529
;include 'vmodeld.inc'
529
;include 'vmodeld.inc'
530
;!!!!!!!!!!!!!!!!!!!!!!!
530
;!!!!!!!!!!!!!!!!!!!!!!!
531
 
531
 
532
 
532
 
533
; LOAD FONTS I and II
533
; LOAD FONTS I and II
534
 
534
 
535
	stdcall read_file, char, FONT_I, 0, 2304
535
	stdcall read_file, char, FONT_I, 0, 2304
536
	stdcall read_file, char2, FONT_II, 0, 2560
536
	stdcall read_file, char2, FONT_II, 0, 2560
537
 
537
 
538
;        mov   esi,boot_fonts
538
;        mov   esi,boot_fonts
539
;        call  boot_log
539
;        call  boot_log
540
 
540
 
541
; PRINT AMOUNT OF MEMORY
541
; PRINT AMOUNT OF MEMORY
542
;        mov     esi, boot_memdetect
542
;        mov     esi, boot_memdetect
543
;        call    boot_log
543
;        call    boot_log
544
 
544
 
545
	movzx	ecx, word [boot_y]
545
	movzx	ecx, word [boot_y]
546
	or	ecx, (10+29*6) shl 16 ; "Determining amount of memory"
546
	or	ecx, (10+29*6) shl 16 ; "Determining amount of memory"
547
	sub	ecx, 10
547
	sub	ecx, 10
548
	mov	edx, 0xFFFFFF
548
	mov	edx, 0xFFFFFF
549
	mov	ebx, [MEM_AMOUNT]
549
	mov	ebx, [MEM_AMOUNT]
550
	shr	ebx, 20
550
	shr	ebx, 20
551
	xor	edi,edi
551
	xor	edi,edi
552
	mov	eax, 0x00040000
552
	mov	eax, 0x00040000
553
		inc		edi
553
		inc		edi
554
	call	display_number_force
554
	call	display_number_force
555
 
555
 
556
; BUILD SCHEDULER
556
; BUILD SCHEDULER
557
 
557
 
558
	call   build_scheduler ; sys32.inc
558
	call   build_scheduler ; sys32.inc
559
 
559
 
560
;        mov    esi,boot_devices
560
;        mov    esi,boot_devices
561
;        call   boot_log
561
;        call   boot_log
562
 
562
 
563
	mov  [pci_access_enabled],1
563
	mov  [pci_access_enabled],1
564
 
564
 
565
 
565
 
566
; SET PRELIMINARY WINDOW STACK AND POSITIONS
566
; SET PRELIMINARY WINDOW STACK AND POSITIONS
567
 
567
 
568
	mov   esi,boot_windefs
568
	mov   esi,boot_windefs
569
	call  boot_log
569
	call  boot_log
570
	call  set_window_defaults
570
	call  set_window_defaults
571
 
571
 
572
; SET BACKGROUND DEFAULTS
572
; SET BACKGROUND DEFAULTS
573
 
573
 
574
;        mov   esi,boot_bgr
574
;        mov   esi,boot_bgr
575
;        call  boot_log
575
;        call  boot_log
576
	call  init_background	;
576
	call  init_background	;
577
	call  calculatebackground
577
	call  calculatebackground
578
 
578
 
579
; SET UP OS TASK
579
; SET UP OS TASK
580
 
580
 
581
;        mov  esi,boot_setostask
581
;        mov  esi,boot_setostask
582
;        call boot_log
582
;        call boot_log
583
 
583
 
584
	xor  eax, eax
584
	xor  eax, eax
585
	mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
585
	mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
586
	mov  dword [SLOT_BASE+APPDATA.exc_handler], eax
586
	mov  dword [SLOT_BASE+APPDATA.exc_handler], eax
587
	mov  dword [SLOT_BASE+APPDATA.except_mask], eax
587
	mov  dword [SLOT_BASE+APPDATA.except_mask], eax
588
 
588
 
589
	; name for OS/IDLE process
589
	; name for OS/IDLE process
590
 
590
 
591
	mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
591
	mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
592
	mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
592
	mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
593
	mov edi, [os_stack_seg]
593
	mov edi, [os_stack_seg]
594
	mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
594
	mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
595
	add edi, 0x2000-512
595
	add edi, 0x2000-512
596
	mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
596
	mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
597
	mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
597
	mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
598
	; [SLOT_BASE+256+APPDATA.io_map] was set earlier
598
	; [SLOT_BASE+256+APPDATA.io_map] was set earlier
599
 
599
 
600
	mov esi, fpu_data
600
	mov esi, fpu_data
601
	mov ecx, 512/4
601
	mov ecx, 512/4
602
	cld
602
	cld
603
	rep movsd
603
	rep movsd
604
 
604
 
605
	mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax
605
	mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax
606
	mov dword [SLOT_BASE+256+APPDATA.except_mask], eax
606
	mov dword [SLOT_BASE+256+APPDATA.except_mask], eax
607
 
607
 
608
	mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
608
	mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
609
	mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
609
	mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
610
	mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
610
	mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
611
 
611
 
612
	mov  dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
612
	mov  dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
613
	mov dword [SLOT_BASE+256+APPDATA.tls_base], eax
613
	mov dword [SLOT_BASE+256+APPDATA.tls_base], eax
614
 
614
 
615
	; task list
615
	; task list
616
	mov  dword [TASK_DATA+TASKDATA.mem_start],eax	; process base address
616
	mov  dword [TASK_DATA+TASKDATA.mem_start],eax	; process base address
617
	inc  eax
617
	inc  eax
618
	mov  dword [CURRENT_TASK],eax
618
	mov  dword [CURRENT_TASK],eax
619
	mov  dword [TASK_COUNT],eax
619
	mov  dword [TASK_COUNT],eax
620
	mov  [current_slot], SLOT_BASE+256
620
	mov  [current_slot], SLOT_BASE+256
621
	mov  [TASK_BASE],dword TASK_DATA
621
	mov  [TASK_BASE],dword TASK_DATA
622
	mov  byte[TASK_DATA+TASKDATA.wnd_number],al	; on screen number
622
	mov  byte[TASK_DATA+TASKDATA.wnd_number],al	; on screen number
623
	mov  dword [TASK_DATA+TASKDATA.pid], eax	; process id number
623
	mov  dword [TASK_DATA+TASKDATA.pid], eax	; process id number
624
 
624
 
625
	call init_display
625
	call init_display
626
	mov eax, [def_cursor]
626
	mov eax, [def_cursor]
627
	mov [SLOT_BASE+APPDATA.cursor],eax
627
	mov [SLOT_BASE+APPDATA.cursor],eax
628
	mov [SLOT_BASE+APPDATA.cursor+256],eax
628
	mov [SLOT_BASE+APPDATA.cursor+256],eax
629
 
629
 
630
 
630
 
-
 
631
  ; READ TSC / SECOND === Fusion fam.14h only! ===
631
  ; READ TSC / SECOND == Fusion only!
632
 
632
 
633
uglobal
633
	cli
634
align 4
634
	mov	edx, PCIe_CONFIG_SPACE + 0xE0
635
diff16 "pll_freq : ", 0, $
635
	mov	eax, 0x013080F0 	; BIOS timer reg.
636
pll_frequency:
-
 
637
	.main	dd ?
636
	mov	[edx], eax
638
	.divd	dd ?
-
 
639
	.nclk	dd ?
637
	add	dl, 4
640
	.osc	dd ?
-
 
641
endg
638
	mov	edi, edx
642
	mov	ecx, 0xC0010064 	; P0-state register
639
	mov	eax, [edi]		; old microseconds
643
	rdmsr
640
	inc	eax			; next precise microsecond
644
	and	eax, 0x000001F3
-
 
645
	xor	ebx, ebx
641
	mov	esi, eax
646
	mov	bl, al
642
 @@:
647
	shr	eax, 2			; divd = 4*((1 + bits[8:4]) + 0.25*(bits[1:0]))
643
	mov	eax, [edi]
648
	add	al, 4
-
 
649
	and	bl, 3
-
 
650
	add	al, bl
644
	cmp	eax, esi
651
	mov	[pll_frequency.divd], eax
-
 
652
 
-
 
653
 
645
	jne	@b
654
	mov	eax, [PCIe_CONFIG_SPACE + 0xC30D4]  ; bdf: 0.18.3; reg.0xD4
646
 
655
	and	eax, 0x0000003F 	; 100 * (16 + bits[5:0]) = MHz
647
	rdtsc
656
	add	al, 16
648
	mov	ebp, eax		; clockmark
657
	imul	eax, 100
649
	add	esi, 20 		; wait 20us
658
	mov	[pll_frequency.main], eax
650
 @@:
659
 
-
 
660
	shl	eax, 2
651
	mov	eax, [edi]
661
	xor	edx, edx
-
 
662
	mov	ebx, [pll_frequency.divd]
652
	cmp	eax, esi
663
	div	ebx
-
 
664
	mov	ecx, 1000000
653
	jne	@b
665
	push	edx
-
 
666
	xor	edx, edx
654
 
667
	mul	ecx
655
	rdtsc
668
	mov	[CPU_FREQ], eax 	; Hz
656
	sub	eax, ebp
669
	pop	eax
-
 
670
	xor	edx, edx
657
	mov	ebx, 50000
671
	mov	ecx, 250000		; remainder in MHz/4
-
 
672
	mul	ecx
658
	mul	ebx		      ; clks per second
673
	div	ebx
659
	sti
674
	add	eax, [CPU_FREQ]
660
 
675
 
661
	mov   [CPU_FREQ],eax	      ; save tsc / sec
676
	mov	[CPU_FREQ],eax		; save tsc / sec
662
	mov   ebx, 1000000
677
	mov	ebx, 1000000
663
	div   ebx
678
	div	ebx
-
 
679
	mov	[stall_mcs], eax	; (core/memory.inc:stall)
-
 
680
 
-
 
681
	mov	ebx, [PCIe_CONFIG_SPACE + 0xC30DC]  ; bdf: 0.18.3; reg.0xDC
-
 
682
	shr	ebx, 20
-
 
683
	and	bx, 0x3F		; NbP0NclkDiv
-
 
684
	mov	eax, [pll_frequency.main]
-
 
685
	shl	eax, 2
-
 
686
	xor	edx, edx
-
 
687
	div	ebx
-
 
688
	push	edx
-
 
689
	imul	eax, 1000000
-
 
690
	mov	[pll_frequency.nclk], eax  ; +-MHz
-
 
691
	pop	eax
-
 
692
	xor	edx, edx
-
 
693
	imul	eax, 1000000
-
 
694
	div	ebx
-
 
695
	add	[pll_frequency.nclk], eax  ; precise bus clk
664
	mov [stall_mcs], eax
696
	mov	eax, 200000000
-
 
697
	mov	[pll_frequency.osc], eax   ; 200MHz main oscillator
-
 
698
 
-
 
699
 
665
; PRINT CPU FREQUENCY
700
; PRINT CPU FREQUENCY
666
	mov	esi, boot_cpufreq
701
	mov	esi, boot_cpufreq
667
	call	boot_log
702
	call	boot_log
-
 
703
 
-
 
704
	mov	eax, [CPU_FREQ]
-
 
705
	xor	edx, edx
-
 
706
	mov	ebx, 1000000
668
 
707
	div	ebx
669
	mov	ebx, eax
708
	mov	ebx, eax
670
	movzx	ecx, word [boot_y]
709
	movzx	ecx, word [boot_y]
671
	add	ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is '
710
	add	ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is '
672
	mov	edx, 0xFFFFFF
711
	mov	edx, 0xFFFFFF
673
	xor	edi,edi
712
	xor	edi,edi
674
	mov	eax, 0x00040000
713
	mov	eax, 0x00040000
675
		inc		edi
714
	inc	edi
676
	call	display_number_force
715
	call	display_number_force
677
 
716
 
678
; SET VARIABLES
717
; SET VARIABLES
679
 
718
 
680
	call  set_variables
719
	call  set_variables
681
 
720
 
682
; SET MOUSE
721
; SET MOUSE
683
 
722
 
684
	stdcall load_driver, szPS2MDriver
723
	stdcall load_driver, szPS2MDriver
685
 
724
 
686
	cli
725
	cli
687
 
726
 
688
; STACK AND FDC
727
; STACK AND FDC
689
 
728
 
690
	call  stack_init
729
	call  stack_init
691
;       call  fdc_init
730
;       call  fdc_init
692
 
731
 
693
 
732
 
694
; LOAD DEFAULT SKIN
733
; LOAD DEFAULT SKIN
695
 
734
 
696
	call	load_default_skin
735
	call	load_default_skin
697
 
736
 
698
;protect io permission map
737
;protect io permission map
699
 
738
 
700
	   mov esi, [default_io_map]
739
	   mov esi, [default_io_map]
701
	   stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map], PG_MAP
740
	   stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map], PG_MAP
702
	   add esi, 0x1000
741
	   add esi, 0x1000
703
	   stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
742
	   stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
704
 
743
 
705
	   stdcall map_page,tss._io_map_0,\
744
	   stdcall map_page,tss._io_map_0,\
706
		   [SLOT_BASE+256+APPDATA.io_map], PG_MAP
745
		   [SLOT_BASE+256+APPDATA.io_map], PG_MAP
707
	   stdcall map_page,tss._io_map_1,\
746
	   stdcall map_page,tss._io_map_1,\
708
		   [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
747
		   [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
709
 
748
 
710
 
749
 
711
	call init_userDMA	; <<<<<<<<< ============== core/memory.inc =================
750
	call init_userDMA	; <<<<<<<<< ============== core/memory.inc =================
712
;        mov     esi, boot_uDMA_ok
751
;        mov     esi, boot_uDMA_ok
713
;        call    boot_log
752
;        call    boot_log
714
 
753
 
715
	call apic_timer_reset
754
	call apic_timer_reset
716
 
755
 
717
; LOAD FIRST APPLICATION
756
; LOAD FIRST APPLICATION
718
	cli
757
	cli
719
if 0
758
if 0
720
 
759
 
721
	cmp   byte [BOOT_VAR+0x9030],1
760
	cmp   byte [BOOT_VAR+0x9030],1
722
	jne   no_load_vrr_m
761
	jne   no_load_vrr_m
723
 
762
 
724
	mov	ebp, vrr_m
763
	mov	ebp, vrr_m
725
	call	fs_execute_from_sysdir
764
	call	fs_execute_from_sysdir
726
 
765
 
727
;        cmp   eax,2                  ; if vrr_m app found (PID=2)
766
;        cmp   eax,2                  ; if vrr_m app found (PID=2)
728
	sub   eax,2
767
	sub   eax,2
729
	jz    first_app_found
768
	jz    first_app_found
730
 
769
 
731
no_load_vrr_m: <<<
770
no_load_vrr_m: <<<
732
end if
771
end if
733
	mov	ebp, firstapp
772
	mov	ebp, firstapp
734
	call	fs_execute_from_sysdir
773
	call	fs_execute_from_sysdir
735
 
774
 
736
;        cmp   eax,2                  ; continue if a process has been loaded
775
;        cmp   eax,2                  ; continue if a process has been loaded
737
	sub   eax,2
776
	sub   eax,2
738
	jz    first_app_found
777
	jz    first_app_found
739
 
778
 
740
;        mov     esi, boot_failed
779
;        mov     esi, boot_failed
741
;        call    boot_log
780
;        call    boot_log
742
 
781
 
743
	mov   eax, 0xDEADBEEF	     ; otherwise halt
782
	mov   eax, 0xDEADBEEF	     ; otherwise halt
744
	hlt
783
	hlt
745
 
784
 
746
first_app_found:
785
first_app_found:
747
 
786
 
748
	cli
787
	cli
749
 
788
 
750
	;mov   [TASK_COUNT],dword 2
789
	;mov   [TASK_COUNT],dword 2
751
	push  1
790
	push  1
752
	pop   dword [CURRENT_TASK]	; set OS task fisrt
791
	pop   dword [CURRENT_TASK]	; set OS task fisrt
753
 
792
 
754
; SET KEYBOARD PARAMETERS
793
; SET KEYBOARD PARAMETERS
755
	mov   al, 0xf6	       ; reset keyboard, scan enabled
794
	mov   al, 0xf6	       ; reset keyboard, scan enabled
756
	call  kb_write
795
	call  kb_write
757
 
796
 
758
	; wait until 8042 is ready
797
	; wait until 8042 is ready
759
	xor ecx,ecx
798
	xor ecx,ecx
760
      @@:
799
      @@:
761
	in     al,64h
800
	in     al,64h
762
	and    al,00000010b
801
	and    al,00000010b
763
	loopnz @b
802
	loopnz @b
764
 
803
 
765
 
804
 
766
	mov   al, 0xF3	     ; set repeat rate & delay
805
	mov   al, 0xF3	     ; set repeat rate & delay
767
	call  kb_write
806
	call  kb_write
768
;        call  kb_read
807
;        call  kb_read
769
	mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
808
	mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
770
	call  kb_write
809
	call  kb_write
771
;        call  kb_read
810
;        call  kb_read
772
     ;// mike.dld [
811
     ;// mike.dld [
773
	call  set_lights
812
	call  set_lights
774
     ;// mike.dld ]
813
     ;// mike.dld ]
775
 
814
 
776
 
815
 
777
 
816
 
778
; START MULTITASKING
817
; START MULTITASKING
779
 
818
 
780
	stdcall attach_int_handler, 1, irq1, 0
819
	stdcall attach_int_handler, 1, irq1, 0
781
 
820
 
782
	cmp	[IDEContrRegsBaseAddr], 0
821
	cmp	[IDEContrRegsBaseAddr], 0
783
	setnz	[dma_hdd]
822
	setnz	[dma_hdd]
784
	mov [timer_ticks_enable],1		; for cd driver
823
	mov [timer_ticks_enable],1		; for cd driver
785
 
824
 
786
	sti
825
	sti
787
	call change_task
826
	call change_task
788
 
827
 
789
	jmp osloop				; Fly :)
828
	jmp osloop				; Fly :)
790
 
829
 
791
diff16 "init code end  ",0,$
830
diff16 "init code end  ",0,$
792
 
831
 
793
unpacker_inc:
832
unpacker_inc:
794
include 'unpacker.inc'
833
include 'unpacker.inc'
795
diff16 "unpacker code  ",unpacker_inc,$
834
diff16 "unpacker code  ",unpacker_inc,$
796
 
835
 
797
include 'fdo.inc'
836
include 'fdo.inc'
798
 
837
 
799
align 4
838
align 4
800
boot_log:
839
boot_log:
801
	 pushad
840
	 pushad
802
 
841
 
803
	mov   ebx,10*65536
842
	mov   ebx,10*65536
804
	mov   bx,word [boot_y]
843
	mov   bx,word [boot_y]
805
	add   [boot_y],dword 10
844
	add   [boot_y],dword 10
806
	mov   ecx,0x80ffffff   ; ASCIIZ string with white color
845
	mov   ecx,0x80ffffff   ; ASCIIZ string with white color
807
		xor	  edi,edi
846
		xor	  edi,edi
808
	mov   edx,esi
847
	mov   edx,esi
809
		inc	  edi
848
		inc	  edi
810
	call  dtext
849
	call  dtext
811
 
850
 
812
	popad
851
	popad
813
 
852
 
814
	ret
853
	ret
815
 
854
 
816
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
855
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
817
;                                                                    ;
856
;                                                                    ;
818
;                    MAIN OS LOOP START                              ;
857
;                    MAIN OS LOOP START                              ;
819
;                                                                    ;
858
;                                                                    ;
820
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
859
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
821
align 32
860
align 32
822
osloop:
861
osloop:
823
	call   [draw_pointer]
862
	call   [draw_pointer]
824
	call	window_check_events
863
	call	window_check_events
825
	call	mouse_check_events
864
	call	mouse_check_events
826
	call   checkmisc
865
	call   checkmisc
827
	call   stack_handler
866
	call   stack_handler
828
	call   checkidle
867
	call   checkidle
829
	jmp    osloop
868
	jmp    osloop
830
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
869
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
831
;                                                                    ;
870
;                                                                    ;
832
;                      MAIN OS LOOP END                              ;
871
;                      MAIN OS LOOP END                              ;
833
;                                                                    ;
872
;                                                                    ;
834
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
873
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
835
align 4
874
align 4
836
checkidle:
875
checkidle:
837
	pushad
876
	pushad
838
	call	change_task
877
	call	change_task
839
	jmp	idle_loop_entry
878
	jmp	idle_loop_entry
840
  idle_loop:
879
  idle_loop:
841
	cmp	eax,[idlemem]	  ; eax == [timer_ticks]
880
	cmp	eax,[idlemem]	  ; eax == [timer_ticks]
842
	jne	idle_exit
881
	jne	idle_exit
843
	rdtsc	;call _rdtsc
882
	rdtsc	;call _rdtsc
844
	mov	ecx,eax
883
	mov	ecx,eax
845
	hlt
884
	hlt
846
	rdtsc	;call _rdtsc
885
	rdtsc	;call _rdtsc
847
	sub	eax,ecx
886
	sub	eax,ecx
848
	add	[idleuse],eax
887
	add	[idleuse],eax
849
  idle_loop_entry:
888
  idle_loop_entry:
850
	mov	eax,[timer_ticks] ; eax =  [timer_ticks]
889
	mov	eax,[timer_ticks] ; eax =  [timer_ticks]
851
	cmp	[check_idle_semaphore],0
890
	cmp	[check_idle_semaphore],0
852
	je	idle_loop
891
	je	idle_loop
853
	dec	[check_idle_semaphore]
892
	dec	[check_idle_semaphore]
854
  idle_exit:
893
  idle_exit:
855
	mov	[idlemem],eax	  ; eax == [timer_ticks]
894
	mov	[idlemem],eax	  ; eax == [timer_ticks]
856
	popad
895
	popad
857
	ret
896
	ret
858
 
897
 
859
uglobal
898
uglobal
860
  idlemem		dd   0x0
899
  idlemem		dd   0x0
861
  idleuse		dd   0x0
900
  idleuse		dd   0x0
862
  idleusesec		dd   0x0
901
  idleusesec		dd   0x0
863
  check_idle_semaphore	dd   0x0
902
  check_idle_semaphore	dd   0x0
864
endg
903
endg
865
 
904
 
866
 
905
 
867
 
906
 
868
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
907
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
869
;                                                                      ;
908
;                                                                      ;
870
;                   INCLUDED SYSTEM FILES                              ;
909
;                   INCLUDED SYSTEM FILES                              ;
871
;                                                                      ;
910
;                                                                      ;
872
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
873
 
912
 
874
 
913
 
875
include "kernel32.inc"
914
include "kernel32.inc"
876
 
915
 
877
 
916
 
878
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
879
;                                                                      ;
918
;                                                                      ;
880
;                       KERNEL FUNCTIONS                               ;
919
;                       KERNEL FUNCTIONS                               ;
881
;                                                                      ;
920
;                                                                      ;
882
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
921
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
883
 
922
 
884
reserve_irqs_ports:
923
reserve_irqs_ports:
885
	; removed
924
	; removed
886
	ret
925
	ret
887
 
926
 
888
setirqreadports:
927
setirqreadports:
889
	; removed
928
	; removed
890
	ret
929
	ret
891
 
930
 
892
iglobal
931
iglobal
893
  process_number dd 0x1
932
  process_number dd 0x1
894
endg
933
endg
895
 
934
 
896
set_variables:
935
set_variables:
897
 
936
 
898
	mov   ecx,0x100 		      ; flush port 0x60
937
	mov   ecx,0x100 		      ; flush port 0x60
899
.fl60:	in    al,0x60
938
.fl60:	in    al,0x60
900
	loop  .fl60
939
	loop  .fl60
901
	push  eax
940
	push  eax
902
 
941
 
903
	mov   ax,[BOOT_VAR+0x900c]
942
	mov   ax,[BOOT_VAR+0x900c]
904
	shr   ax,1
943
	shr   ax,1
905
	shl   eax,16
944
	shl   eax,16
906
	mov   ax,[BOOT_VAR+0x900A]
945
	mov   ax,[BOOT_VAR+0x900A]
907
	shr   ax,1
946
	shr   ax,1
908
	mov   [MOUSE_X],eax
947
	mov   [MOUSE_X],eax
909
 
948
 
910
	xor   eax,eax
949
	xor   eax,eax
911
	mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
950
	mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
912
 
951
 
913
	mov   byte [MOUSE_BUFF_COUNT],al		 ; mouse buffer
952
	mov   byte [MOUSE_BUFF_COUNT],al		 ; mouse buffer
914
	mov   byte [KEY_COUNT],al		  ; keyboard buffer
953
	mov   byte [KEY_COUNT],al		  ; keyboard buffer
915
	mov   byte [BTN_COUNT],al		  ; button buffer
954
	mov   byte [BTN_COUNT],al		  ; button buffer
916
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
955
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
917
 
956
 
918
     ;!! IP 04.02.2005:
957
     ;!! IP 04.02.2005:
919
	mov   byte [DONT_SWITCH],al ; change task if possible
958
	mov   byte [DONT_SWITCH],al ; change task if possible
920
	pop   eax
959
	pop   eax
921
	ret
960
	ret
922
 
961
 
923
align 4
962
align 4
924
;input  eax=43,bl-byte of output, ecx - number of port
963
;input  eax=43,bl-byte of output, ecx - number of port
925
sys_outport:
964
sys_outport:
926
     and   [esp+32],dword 1	; for backward compatibility: operation failed
965
     and   [esp+32],dword 1	; for backward compatibility: operation failed
927
    ret
966
    ret
928
 
967
 
929
display_number:
968
display_number:
930
;It is not optimization
969
;It is not optimization
931
	mov	eax, ebx
970
	mov	eax, ebx
932
	mov	ebx, ecx
971
	mov	ebx, ecx
933
	mov	ecx, edx
972
	mov	ecx, edx
934
	mov	edx, esi
973
	mov	edx, esi
935
	mov	esi, edi
974
	mov	esi, edi
936
; eax = print type, al=0 -> ebx is number
975
; eax = print type, al=0 -> ebx is number
937
;                   al=1 -> ebx is pointer
976
;                   al=1 -> ebx is pointer
938
;                   ah=0 -> display decimal
977
;                   ah=0 -> display decimal
939
;                   ah=1 -> display hexadecimal
978
;                   ah=1 -> display hexadecimal
940
;                   ah=2 -> display binary
979
;                   ah=2 -> display binary
941
;                   eax bits 16-21 = number of digits to display (0-32)
980
;                   eax bits 16-21 = number of digits to display (0-32)
942
;                   eax bits 22-31 = reserved
981
;                   eax bits 22-31 = reserved
943
;
982
;
944
; ebx = number or pointer
983
; ebx = number or pointer
945
; ecx = x shl 16 + y
984
; ecx = x shl 16 + y
946
; edx = color
985
; edx = color
947
    xor     edi, edi
986
    xor     edi, edi
948
display_number_force:
987
display_number_force:
949
    push  eax
988
    push  eax
950
    and   eax,0x3fffffff
989
    and   eax,0x3fffffff
951
    cmp   eax,0xffff		; length > 0 ?
990
    cmp   eax,0xffff		; length > 0 ?
952
    pop   eax
991
    pop   eax
953
    jge   cont_displ
992
    jge   cont_displ
954
    ret
993
    ret
955
   cont_displ:
994
   cont_displ:
956
     push  eax
995
     push  eax
957
     and   eax,0x3fffffff
996
     and   eax,0x3fffffff
958
     cmp   eax,61*0x10000	 ; length <= 60 ?
997
     cmp   eax,61*0x10000	 ; length <= 60 ?
959
     pop   eax
998
     pop   eax
960
     jb    cont_displ2
999
     jb    cont_displ2
961
     ret
1000
     ret
962
   cont_displ2:
1001
   cont_displ2:
963
 
1002
 
964
     pushad
1003
     pushad
965
 
1004
 
966
     cmp   al,1 		 ; ecx is a pointer ?
1005
     cmp   al,1 		 ; ecx is a pointer ?
967
     jne   displnl1
1006
     jne   displnl1
968
     mov   ebp,ebx
1007
     mov   ebp,ebx
969
     add   ebp,4
1008
     add   ebp,4
970
     mov   ebp,[ebp+std_application_base_address]
1009
     mov   ebp,[ebp+std_application_base_address]
971
     mov   ebx,[ebx+std_application_base_address]
1010
     mov   ebx,[ebx+std_application_base_address]
972
 displnl1:
1011
 displnl1:
973
     sub   esp,64
1012
     sub   esp,64
974
 
1013
 
975
    test   ah,ah		  ; DECIMAL
1014
    test   ah,ah		  ; DECIMAL
976
    jnz   no_display_desnum
1015
    jnz   no_display_desnum
977
    shr   eax,16
1016
    shr   eax,16
978
    and   eax,0xC03f
1017
    and   eax,0xC03f
979
;     and   eax,0x3f
1018
;     and   eax,0x3f
980
    push  eax
1019
    push  eax
981
    and   eax,0x3f
1020
    and   eax,0x3f
982
    mov   edi,esp
1021
    mov   edi,esp
983
    add   edi,4+64-1
1022
    add   edi,4+64-1
984
    mov   ecx,eax
1023
    mov   ecx,eax
985
    mov   eax,ebx
1024
    mov   eax,ebx
986
    mov   ebx,10
1025
    mov   ebx,10
987
 d_desnum:
1026
 d_desnum:
988
     xor   edx,edx
1027
     xor   edx,edx
989
     call  division_64_bits
1028
     call  division_64_bits
990
     div   ebx
1029
     div   ebx
991
     add   dl,48
1030
     add   dl,48
992
     mov   [edi],dl
1031
     mov   [edi],dl
993
     dec   edi
1032
     dec   edi
994
     loop  d_desnum
1033
     loop  d_desnum
995
     pop   eax
1034
     pop   eax
996
     call  normalize_number
1035
     call  normalize_number
997
     call  draw_num_text
1036
     call  draw_num_text
998
     add   esp,64
1037
     add   esp,64
999
     popad
1038
     popad
1000
     ret
1039
     ret
1001
   no_display_desnum:
1040
   no_display_desnum:
1002
 
1041
 
1003
     cmp   ah,0x01		 ; HEXADECIMAL
1042
     cmp   ah,0x01		 ; HEXADECIMAL
1004
     jne   no_display_hexnum
1043
     jne   no_display_hexnum
1005
     shr   eax,16
1044
     shr   eax,16
1006
     and   eax,0xC03f
1045
     and   eax,0xC03f
1007
;     and   eax,0x3f
1046
;     and   eax,0x3f
1008
     push  eax
1047
     push  eax
1009
     and   eax,0x3f
1048
     and   eax,0x3f
1010
     mov   edi,esp
1049
     mov   edi,esp
1011
     add   edi,4+64-1
1050
     add   edi,4+64-1
1012
     mov   ecx,eax
1051
     mov   ecx,eax
1013
     mov   eax,ebx
1052
     mov   eax,ebx
1014
     mov   ebx,16
1053
     mov   ebx,16
1015
   d_hexnum:
1054
   d_hexnum:
1016
     xor   edx,edx
1055
     xor   edx,edx
1017
     call  division_64_bits
1056
     call  division_64_bits
1018
     div   ebx
1057
     div   ebx
1019
   hexletters = __fdo_hexdigits
1058
   hexletters = __fdo_hexdigits
1020
     add   edx,hexletters
1059
     add   edx,hexletters
1021
     mov   dl,[edx]
1060
     mov   dl,[edx]
1022
     mov   [edi],dl
1061
     mov   [edi],dl
1023
     dec   edi
1062
     dec   edi
1024
     loop  d_hexnum
1063
     loop  d_hexnum
1025
     pop   eax
1064
     pop   eax
1026
     call  normalize_number
1065
     call  normalize_number
1027
     call  draw_num_text
1066
     call  draw_num_text
1028
     add   esp,64
1067
     add   esp,64
1029
     popad
1068
     popad
1030
     ret
1069
     ret
1031
   no_display_hexnum:
1070
   no_display_hexnum:
1032
 
1071
 
1033
     cmp   ah,0x02		 ; BINARY
1072
     cmp   ah,0x02		 ; BINARY
1034
     jne   no_display_binnum
1073
     jne   no_display_binnum
1035
     shr   eax,16
1074
     shr   eax,16
1036
     and   eax,0xC03f
1075
     and   eax,0xC03f
1037
;     and   eax,0x3f
1076
;     and   eax,0x3f
1038
     push  eax
1077
     push  eax
1039
     and   eax,0x3f
1078
     and   eax,0x3f
1040
     mov   edi,esp
1079
     mov   edi,esp
1041
     add   edi,4+64-1
1080
     add   edi,4+64-1
1042
     mov   ecx,eax
1081
     mov   ecx,eax
1043
     mov   eax,ebx
1082
     mov   eax,ebx
1044
     mov   ebx,2
1083
     mov   ebx,2
1045
   d_binnum:
1084
   d_binnum:
1046
     xor   edx,edx
1085
     xor   edx,edx
1047
     call  division_64_bits
1086
     call  division_64_bits
1048
     div   ebx
1087
     div   ebx
1049
     add   dl,48
1088
     add   dl,48
1050
     mov   [edi],dl
1089
     mov   [edi],dl
1051
     dec   edi
1090
     dec   edi
1052
     loop  d_binnum
1091
     loop  d_binnum
1053
     pop   eax
1092
     pop   eax
1054
     call  normalize_number
1093
     call  normalize_number
1055
     call  draw_num_text
1094
     call  draw_num_text
1056
     add   esp,64
1095
     add   esp,64
1057
     popad
1096
     popad
1058
     ret
1097
     ret
1059
   no_display_binnum:
1098
   no_display_binnum:
1060
 
1099
 
1061
     add   esp,64
1100
     add   esp,64
1062
     popad
1101
     popad
1063
     ret
1102
     ret
1064
 
1103
 
1065
normalize_number:
1104
normalize_number:
1066
     test  ah,0x80
1105
     test  ah,0x80
1067
     jz   .continue
1106
     jz   .continue
1068
     mov  ecx,48
1107
     mov  ecx,48
1069
     and   eax,0x3f
1108
     and   eax,0x3f
1070
@@:
1109
@@:
1071
     inc   edi
1110
     inc   edi
1072
     cmp   [edi],cl
1111
     cmp   [edi],cl
1073
     jne   .continue
1112
     jne   .continue
1074
     dec   eax
1113
     dec   eax
1075
     cmp   eax,1
1114
     cmp   eax,1
1076
     ja    @r
1115
     ja    @r
1077
     mov   al,1
1116
     mov   al,1
1078
.continue:
1117
.continue:
1079
     and   eax,0x3f
1118
     and   eax,0x3f
1080
     ret
1119
     ret
1081
 
1120
 
1082
division_64_bits:
1121
division_64_bits:
1083
     test  [esp+1+4],byte 0x40
1122
     test  [esp+1+4],byte 0x40
1084
     jz   .continue
1123
     jz   .continue
1085
     push  eax
1124
     push  eax
1086
     mov   eax,ebp
1125
     mov   eax,ebp
1087
     div   ebx
1126
     div   ebx
1088
     mov   ebp,eax
1127
     mov   ebp,eax
1089
     pop   eax
1128
     pop   eax
1090
.continue:
1129
.continue:
1091
     ret
1130
     ret
1092
 
1131
 
1093
draw_num_text:
1132
draw_num_text:
1094
     mov   esi,eax
1133
     mov   esi,eax
1095
     mov   edx,64+4
1134
     mov   edx,64+4
1096
     sub   edx,eax
1135
     sub   edx,eax
1097
     add   edx,esp
1136
     add   edx,esp
1098
     mov   ebx,[esp+64+32-8+4]
1137
     mov   ebx,[esp+64+32-8+4]
1099
; add window start x & y
1138
; add window start x & y
1100
     mov   ecx,[TASK_BASE]
1139
     mov   ecx,[TASK_BASE]
1101
 
1140
 
1102
     mov   edi,[CURRENT_TASK]
1141
     mov   edi,[CURRENT_TASK]
1103
     shl   edi,8
1142
     shl   edi,8
1104
 
1143
 
1105
     mov   eax,[ecx-twdw+WDATA.box.left]
1144
     mov   eax,[ecx-twdw+WDATA.box.left]
1106
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1145
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1107
     shl   eax,16
1146
     shl   eax,16
1108
     add   eax,[ecx-twdw+WDATA.box.top]
1147
     add   eax,[ecx-twdw+WDATA.box.top]
1109
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1148
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1110
     add   ebx,eax
1149
     add   ebx,eax
1111
     mov   ecx,[esp+64+32-12+4]
1150
     mov   ecx,[esp+64+32-12+4]
1112
	and	ecx, not 0x80000000	; force counted string
1151
	and	ecx, not 0x80000000	; force counted string
1113
	mov	eax, [esp+64+8] 	; background color (if given)
1152
	mov	eax, [esp+64+8] 	; background color (if given)
1114
	mov	edi, [esp+64+4]
1153
	mov	edi, [esp+64+4]
1115
     jmp   dtext
1154
     jmp   dtext
1116
 
1155
 
1117
align 4
1156
align 4
1118
 
1157
 
1119
sys_setup:
1158
sys_setup:
1120
 
1159
 
1121
; 1=roland mpu midi base , base io address
1160
; 1=roland mpu midi base , base io address
1122
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1161
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1123
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1162
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1124
; 5=system language, 1eng 2fi 3ger 4rus
1163
; 5=system language, 1eng 2fi 3ger 4rus
1125
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1164
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1126
; 8=fat32 partition in hd
1165
; 8=fat32 partition in hd
1127
; 9
1166
; 9
1128
; 10 = sound dma channel
1167
; 10 = sound dma channel
1129
; 11 = enable lba read
1168
; 11 = enable lba read
1130
; 12 = enable pci access
1169
; 12 = enable pci access
1131
 
1170
 
1132
 
1171
 
1133
	and  [esp+32],dword 0
1172
	and  [esp+32],dword 0
1134
	dec	ebx				; MIDI
1173
	dec	ebx				; MIDI
1135
	jnz  nsyse1
1174
	jnz  nsyse1
1136
	cmp  ecx,0x100
1175
	cmp  ecx,0x100
1137
 
1176
 
1138
	jb   nsyse1
1177
	jb   nsyse1
1139
	mov	esi,65535
1178
	mov	esi,65535
1140
	cmp	esi,ecx
1179
	cmp	esi,ecx
1141
 
1180
 
1142
	jb   nsyse1
1181
	jb   nsyse1
1143
	mov  [midi_base],cx	;bx
1182
	mov  [midi_base],cx	;bx
1144
	mov  word [mididp],cx	;bx
1183
	mov  word [mididp],cx	;bx
1145
	inc  cx 		;bx
1184
	inc  cx 		;bx
1146
	mov  word [midisp],cx	;bx
1185
	mov  word [midisp],cx	;bx
1147
	ret
1186
	ret
1148
 
1187
 
1149
iglobal
1188
iglobal
1150
midi_base dw 0
1189
midi_base dw 0
1151
endg
1190
endg
1152
 
1191
 
1153
   nsyse1:
1192
   nsyse1:
1154
	dec	ebx				 ; KEYBOARD
1193
	dec	ebx				 ; KEYBOARD
1155
	jnz  nsyse2
1194
	jnz  nsyse2
1156
	mov  edi,[TASK_BASE]
1195
	mov  edi,[TASK_BASE]
1157
	mov  eax,[edi+TASKDATA.mem_start]
1196
	mov  eax,[edi+TASKDATA.mem_start]
1158
	add  eax,edx
1197
	add  eax,edx
1159
 
1198
 
1160
	dec	ecx
1199
	dec	ecx
1161
	jnz  kbnobase
1200
	jnz  kbnobase
1162
	mov  ebx,keymap
1201
	mov  ebx,keymap
1163
	mov  ecx,128
1202
	mov  ecx,128
1164
	call memmove
1203
	call memmove
1165
	ret
1204
	ret
1166
   kbnobase:
1205
   kbnobase:
1167
	dec  ecx
1206
	dec  ecx
1168
	jnz  kbnoshift
1207
	jnz  kbnoshift
1169
 
1208
 
1170
	mov  ebx,keymap_shift
1209
	mov  ebx,keymap_shift
1171
	mov  ecx,128
1210
	mov  ecx,128
1172
	call memmove
1211
	call memmove
1173
	ret
1212
	ret
1174
   kbnoshift:
1213
   kbnoshift:
1175
	dec  ecx
1214
	dec  ecx
1176
	jnz  kbnoalt
1215
	jnz  kbnoalt
1177
	mov  ebx,keymap_alt
1216
	mov  ebx,keymap_alt
1178
	mov  ecx,128
1217
	mov  ecx,128
1179
	call memmove
1218
	call memmove
1180
	ret
1219
	ret
1181
   kbnoalt:
1220
   kbnoalt:
1182
	sub  ecx,6
1221
	sub  ecx,6
1183
	jnz  kbnocountry
1222
	jnz  kbnocountry
1184
	mov  word [keyboard],dx
1223
	mov  word [keyboard],dx
1185
	ret
1224
	ret
1186
   kbnocountry:
1225
   kbnocountry:
1187
	mov  [esp+32],dword 1
1226
	mov  [esp+32],dword 1
1188
	ret
1227
	ret
1189
   nsyse2:
1228
   nsyse2:
1190
	dec  ebx			    ; CD
1229
	dec  ebx			    ; CD
1191
	jnz  nsyse4
1230
	jnz  nsyse4
1192
 
1231
 
1193
	test ecx,ecx
1232
	test ecx,ecx
1194
	jz   nosesl
1233
	jz   nosesl
1195
 
1234
 
1196
	cmp  ecx, 4
1235
	cmp  ecx, 4
1197
	ja   nosesl
1236
	ja   nosesl
1198
	mov  [cd_base],cl
1237
	mov  [cd_base],cl
1199
 
1238
 
1200
	dec	ecx
1239
	dec	ecx
1201
	jnz  noprma
1240
	jnz  noprma
1202
	mov  [cdbase],0x1f0
1241
	mov  [cdbase],0x1f0
1203
	mov  [cdid],0xa0
1242
	mov  [cdid],0xa0
1204
   noprma:
1243
   noprma:
1205
 
1244
 
1206
	dec	ecx
1245
	dec	ecx
1207
	jnz  noprsl
1246
	jnz  noprsl
1208
	mov  [cdbase],0x1f0
1247
	mov  [cdbase],0x1f0
1209
	mov  [cdid],0xb0
1248
	mov  [cdid],0xb0
1210
   noprsl:
1249
   noprsl:
1211
	dec	ecx
1250
	dec	ecx
1212
	jnz  nosema
1251
	jnz  nosema
1213
	mov  [cdbase],0x170
1252
	mov  [cdbase],0x170
1214
	mov  [cdid],0xa0
1253
	mov  [cdid],0xa0
1215
   nosema:
1254
   nosema:
1216
	dec	ecx
1255
	dec	ecx
1217
	jnz  nosesl
1256
	jnz  nosesl
1218
	mov  [cdbase],0x170
1257
	mov  [cdbase],0x170
1219
	mov  [cdid],0xb0
1258
	mov  [cdid],0xb0
1220
   nosesl:
1259
   nosesl:
1221
	ret
1260
	ret
1222
 
1261
 
1223
iglobal
1262
iglobal
1224
cd_base db 0
1263
cd_base db 0
1225
 
1264
 
1226
endg
1265
endg
1227
   nsyse4:
1266
   nsyse4:
1228
 
1267
 
1229
	sub  ebx,2		 ; SYSTEM LANGUAGE
1268
	sub  ebx,2		 ; SYSTEM LANGUAGE
1230
	jnz  nsyse5
1269
	jnz  nsyse5
1231
	mov  [syslang],ecx
1270
	mov  [syslang],ecx
1232
	ret
1271
	ret
1233
   nsyse5:
1272
   nsyse5:
1234
 
1273
 
1235
	sub  ebx,2		; HD BASE
1274
	sub  ebx,2		; HD BASE
1236
	jnz  nsyse7
1275
	jnz  nsyse7
1237
 
1276
 
1238
	test ecx,ecx
1277
	test ecx,ecx
1239
	jz   nosethd
1278
	jz   nosethd
1240
 
1279
 
1241
	cmp  ecx,4
1280
	cmp  ecx,4
1242
	ja   nosethd
1281
	ja   nosethd
1243
	mov  [hd_base],cl
1282
	mov  [hd_base],cl
1244
 
1283
 
1245
	cmp  ecx,1
1284
	cmp  ecx,1
1246
	jnz  noprmahd
1285
	jnz  noprmahd
1247
	mov  [hdbase],0x1f0
1286
	mov  [hdbase],0x1f0
1248
	and  dword [hdid],0x0
1287
	and  dword [hdid],0x0
1249
	mov  dword [hdpos],ecx
1288
	mov  dword [hdpos],ecx
1250
;     call set_FAT32_variables
1289
;     call set_FAT32_variables
1251
   noprmahd:
1290
   noprmahd:
1252
 
1291
 
1253
	cmp  ecx,2
1292
	cmp  ecx,2
1254
	jnz  noprslhd
1293
	jnz  noprslhd
1255
	mov  [hdbase],0x1f0
1294
	mov  [hdbase],0x1f0
1256
	mov  [hdid],0x10
1295
	mov  [hdid],0x10
1257
	mov  dword [hdpos],ecx
1296
	mov  dword [hdpos],ecx
1258
;     call set_FAT32_variables
1297
;     call set_FAT32_variables
1259
   noprslhd:
1298
   noprslhd:
1260
 
1299
 
1261
	cmp  ecx,3
1300
	cmp  ecx,3
1262
	jnz  nosemahd
1301
	jnz  nosemahd
1263
	mov  [hdbase],0x170
1302
	mov  [hdbase],0x170
1264
	and  dword [hdid],0x0
1303
	and  dword [hdid],0x0
1265
	mov  dword [hdpos],ecx
1304
	mov  dword [hdpos],ecx
1266
;     call set_FAT32_variables
1305
;     call set_FAT32_variables
1267
   nosemahd:
1306
   nosemahd:
1268
 
1307
 
1269
	cmp  ecx,4
1308
	cmp  ecx,4
1270
	jnz  noseslhd
1309
	jnz  noseslhd
1271
	mov  [hdbase],0x170
1310
	mov  [hdbase],0x170
1272
	mov  [hdid],0x10
1311
	mov  [hdid],0x10
1273
	mov  dword [hdpos],ecx
1312
	mov  dword [hdpos],ecx
1274
;     call set_FAT32_variables
1313
;     call set_FAT32_variables
1275
   noseslhd:
1314
   noseslhd:
1276
	call  reserve_hd1
1315
	call  reserve_hd1
1277
	call  reserve_hd_channel
1316
	call  reserve_hd_channel
1278
	call  free_hd_channel
1317
	call  free_hd_channel
1279
	and   dword [hd1_status],0	  ; free
1318
	and   dword [hd1_status],0	  ; free
1280
   nosethd:
1319
   nosethd:
1281
	ret
1320
	ret
1282
 
1321
 
1283
iglobal
1322
iglobal
1284
hd_base db 0
1323
hd_base db 0
1285
endg
1324
endg
1286
 
1325
 
1287
nsyse7:
1326
nsyse7:
1288
 
1327
 
1289
;     cmp  eax,8                      ; HD PARTITION
1328
;     cmp  eax,8                      ; HD PARTITION
1290
	dec  ebx
1329
	dec  ebx
1291
	jnz  nsyse8
1330
	jnz  nsyse8
1292
	mov  [fat32part],ecx
1331
	mov  [fat32part],ecx
1293
;     call set_FAT32_variables
1332
;     call set_FAT32_variables
1294
	call  reserve_hd1
1333
	call  reserve_hd1
1295
	call  reserve_hd_channel
1334
	call  reserve_hd_channel
1296
	call  free_hd_channel
1335
	call  free_hd_channel
1297
;       pusha
1336
;       pusha
1298
	call  choice_necessity_partition_1
1337
	call  choice_necessity_partition_1
1299
;       popa
1338
;       popa
1300
	and dword [hd1_status],0	; free
1339
	and dword [hd1_status],0	; free
1301
	ret
1340
	ret
1302
 
1341
 
1303
nsyse8:
1342
nsyse8:
1304
;     cmp  eax,11                     ; ENABLE LBA READ
1343
;     cmp  eax,11                     ; ENABLE LBA READ
1305
	and  ecx,1
1344
	and  ecx,1
1306
	sub  ebx,3
1345
	sub  ebx,3
1307
	jnz  no_set_lba_read
1346
	jnz  no_set_lba_read
1308
	mov  [lba_read_enabled],ecx
1347
	mov  [lba_read_enabled],ecx
1309
	ret
1348
	ret
1310
 
1349
 
1311
no_set_lba_read:
1350
no_set_lba_read:
1312
;     cmp  eax,12                     ; ENABLE PCI ACCESS
1351
;     cmp  eax,12                     ; ENABLE PCI ACCESS
1313
	dec  ebx
1352
	dec  ebx
1314
	jnz  no_set_pci_access
1353
	jnz  no_set_pci_access
1315
	mov  [pci_access_enabled],ecx
1354
	mov  [pci_access_enabled],ecx
1316
	ret
1355
	ret
1317
no_set_pci_access:
1356
no_set_pci_access:
1318
 
1357
 
1319
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1358
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1320
;include 'vmodeint.inc'
1359
;include 'vmodeint.inc'
1321
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1360
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1322
 
1361
 
1323
sys_setup_err:
1362
sys_setup_err:
1324
	or  [esp+32],dword -1
1363
	or  [esp+32],dword -1
1325
	ret
1364
	ret
1326
 
1365
 
1327
align 4
1366
align 4
1328
 
1367
 
1329
sys_getsetup:
1368
sys_getsetup:
1330
 
1369
 
1331
; 1=roland mpu midi base , base io address
1370
; 1=roland mpu midi base , base io address
1332
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1371
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1333
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1372
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1334
; 5=system language, 1eng 2fi 3ger 4rus
1373
; 5=system language, 1eng 2fi 3ger 4rus
1335
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1374
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1336
; 8=fat32 partition in hd
1375
; 8=fat32 partition in hd
1337
; 9=get hs timer tic
1376
; 9=get hs timer tic
1338
 
1377
 
1339
;     cmp  eax,1
1378
;     cmp  eax,1
1340
	dec	ebx
1379
	dec	ebx
1341
	jnz  ngsyse1
1380
	jnz  ngsyse1
1342
	movzx eax,[midi_base]
1381
	movzx eax,[midi_base]
1343
	mov  [esp+32],eax
1382
	mov  [esp+32],eax
1344
	ret
1383
	ret
1345
ngsyse1:
1384
ngsyse1:
1346
;     cmp  eax,2
1385
;     cmp  eax,2
1347
	dec	ebx
1386
	dec	ebx
1348
	jnz  ngsyse2
1387
	jnz  ngsyse2
1349
 
1388
 
1350
	mov  edi,[TASK_BASE]
1389
	mov  edi,[TASK_BASE]
1351
	mov  ebx,[edi+TASKDATA.mem_start]
1390
	mov  ebx,[edi+TASKDATA.mem_start]
1352
	add  ebx,edx
1391
	add  ebx,edx
1353
 
1392
 
1354
;     cmp  ebx,1
1393
;     cmp  ebx,1
1355
	dec	ecx
1394
	dec	ecx
1356
	jnz  kbnobaseret
1395
	jnz  kbnobaseret
1357
	mov  eax,keymap
1396
	mov  eax,keymap
1358
	mov  ecx,128
1397
	mov  ecx,128
1359
	call memmove
1398
	call memmove
1360
	ret
1399
	ret
1361
kbnobaseret:
1400
kbnobaseret:
1362
;     cmp  ebx,2
1401
;     cmp  ebx,2
1363
	dec	ecx
1402
	dec	ecx
1364
	jnz  kbnoshiftret
1403
	jnz  kbnoshiftret
1365
 
1404
 
1366
	mov  eax,keymap_shift
1405
	mov  eax,keymap_shift
1367
	mov  ecx,128
1406
	mov  ecx,128
1368
	call memmove
1407
	call memmove
1369
	ret
1408
	ret
1370
kbnoshiftret:
1409
kbnoshiftret:
1371
;     cmp  ebx,3
1410
;     cmp  ebx,3
1372
	dec	ecx
1411
	dec	ecx
1373
	jne  kbnoaltret
1412
	jne  kbnoaltret
1374
 
1413
 
1375
	mov  eax,keymap_alt
1414
	mov  eax,keymap_alt
1376
	mov  ecx,128
1415
	mov  ecx,128
1377
	call memmove
1416
	call memmove
1378
	ret
1417
	ret
1379
kbnoaltret:
1418
kbnoaltret:
1380
;     cmp  ebx,9
1419
;     cmp  ebx,9
1381
	sub	ecx,6
1420
	sub	ecx,6
1382
	jnz  ngsyse2
1421
	jnz  ngsyse2
1383
	movzx eax,word [keyboard]
1422
	movzx eax,word [keyboard]
1384
	mov  [esp+32],eax
1423
	mov  [esp+32],eax
1385
	ret
1424
	ret
1386
 
1425
 
1387
 
1426
 
1388
ngsyse2:
1427
ngsyse2:
1389
;         cmp  eax,3
1428
;         cmp  eax,3
1390
	dec	ebx
1429
	dec	ebx
1391
	jnz  ngsyse3
1430
	jnz  ngsyse3
1392
	movzx eax,[cd_base]
1431
	movzx eax,[cd_base]
1393
	mov  [esp+32],eax
1432
	mov  [esp+32],eax
1394
	ret
1433
	ret
1395
ngsyse3:
1434
ngsyse3:
1396
;         cmp  eax,5
1435
;         cmp  eax,5
1397
	sub	ebx,2
1436
	sub	ebx,2
1398
	jnz  ngsyse5
1437
	jnz  ngsyse5
1399
	mov  eax,[syslang]
1438
	mov  eax,[syslang]
1400
	mov  [esp+32],eax
1439
	mov  [esp+32],eax
1401
	ret
1440
	ret
1402
ngsyse5:
1441
ngsyse5:
1403
;     cmp  eax,7
1442
;     cmp  eax,7
1404
	sub	ebx,2
1443
	sub	ebx,2
1405
	jnz  ngsyse7
1444
	jnz  ngsyse7
1406
	movzx eax,[hd_base]
1445
	movzx eax,[hd_base]
1407
	mov  [esp+32],eax
1446
	mov  [esp+32],eax
1408
	ret
1447
	ret
1409
ngsyse7:
1448
ngsyse7:
1410
;     cmp  eax,8
1449
;     cmp  eax,8
1411
	dec	ebx
1450
	dec	ebx
1412
	jnz  ngsyse8
1451
	jnz  ngsyse8
1413
	mov eax,[fat32part]
1452
	mov eax,[fat32part]
1414
	mov  [esp+32],eax
1453
	mov  [esp+32],eax
1415
	ret
1454
	ret
1416
ngsyse8:
1455
ngsyse8:
1417
;     cmp  eax,9
1456
;     cmp  eax,9
1418
	dec	ebx
1457
	dec	ebx
1419
	jnz  ngsyse9
1458
	jnz  ngsyse9
1420
	mov  eax,[timer_ticks] ;[0xfdf0]
1459
	mov  eax,[timer_ticks] ;[0xfdf0]
1421
	mov  [esp+32],eax
1460
	mov  [esp+32],eax
1422
	ret
1461
	ret
1423
ngsyse9:
1462
ngsyse9:
1424
;     cmp  eax,11
1463
;     cmp  eax,11
1425
	sub	ebx,2
1464
	sub	ebx,2
1426
	jnz  ngsyse11
1465
	jnz  ngsyse11
1427
	mov eax,[lba_read_enabled]
1466
	mov eax,[lba_read_enabled]
1428
	mov  [esp+32],eax
1467
	mov  [esp+32],eax
1429
	ret
1468
	ret
1430
ngsyse11:
1469
ngsyse11:
1431
;     cmp  eax,12
1470
;     cmp  eax,12
1432
	dec	ebx
1471
	dec	ebx
1433
	jnz  ngsyse12
1472
	jnz  ngsyse12
1434
	mov eax,[pci_access_enabled]
1473
	mov eax,[pci_access_enabled]
1435
	mov  [esp+32],eax
1474
	mov  [esp+32],eax
1436
	ret
1475
	ret
1437
ngsyse12:
1476
ngsyse12:
1438
	mov  [esp+32],dword 1
1477
	mov  [esp+32],dword 1
1439
	ret
1478
	ret
1440
 
1479
 
1441
 
1480
 
1442
get_timer_ticks:
1481
get_timer_ticks:
1443
	mov eax,[timer_ticks]
1482
	mov eax,[timer_ticks]
1444
	ret
1483
	ret
1445
 
1484
 
1446
iglobal
1485
iglobal
1447
align 4
1486
align 4
1448
mousefn dd msscreen, mswin, msbutton, msset
1487
mousefn dd msscreen, mswin, msbutton, msset
1449
	dd app_load_cursor
1488
	dd app_load_cursor
1450
	dd app_set_cursor
1489
	dd app_set_cursor
1451
	dd app_delete_cursor
1490
	dd app_delete_cursor
1452
	dd msz
1491
	dd msz
1453
endg
1492
endg
1454
 
1493
 
1455
readmousepos:
1494
readmousepos:
1456
 
1495
 
1457
; eax=0 screen relative
1496
; eax=0 screen relative
1458
; eax=1 window relative
1497
; eax=1 window relative
1459
; eax=2 buttons pressed
1498
; eax=2 buttons pressed
1460
; eax=3 set mouse pos   ; reserved
1499
; eax=3 set mouse pos   ; reserved
1461
; eax=4 load cursor
1500
; eax=4 load cursor
1462
; eax=5 set cursor
1501
; eax=5 set cursor
1463
; eax=6 delete cursor   ; reserved
1502
; eax=6 delete cursor   ; reserved
1464
; eax=7 get mouse_z
1503
; eax=7 get mouse_z
1465
 
1504
 
1466
	   cmp ebx, 7
1505
	   cmp ebx, 7
1467
	   ja msset
1506
	   ja msset
1468
	   jmp [mousefn+ebx*4]
1507
	   jmp [mousefn+ebx*4]
1469
msscreen:
1508
msscreen:
1470
	   mov	eax,[MOUSE_X]
1509
	   mov	eax,[MOUSE_X]
1471
	   shl	eax,16
1510
	   shl	eax,16
1472
	   mov	ax,[MOUSE_Y]
1511
	   mov	ax,[MOUSE_Y]
1473
	   mov	[esp+36-4],eax
1512
	   mov	[esp+36-4],eax
1474
	   ret
1513
	   ret
1475
mswin:
1514
mswin:
1476
	   mov	eax,[MOUSE_X]
1515
	   mov	eax,[MOUSE_X]
1477
	   shl	eax,16
1516
	   shl	eax,16
1478
	   mov	ax,[MOUSE_Y]
1517
	   mov	ax,[MOUSE_Y]
1479
	   mov	esi,[TASK_BASE]
1518
	   mov	esi,[TASK_BASE]
1480
	   mov	bx, word [esi-twdw+WDATA.box.left]
1519
	   mov	bx, word [esi-twdw+WDATA.box.left]
1481
	   shl	ebx,16
1520
	   shl	ebx,16
1482
	   mov	bx, word [esi-twdw+WDATA.box.top]
1521
	   mov	bx, word [esi-twdw+WDATA.box.top]
1483
	   sub	eax,ebx
1522
	   sub	eax,ebx
1484
 
1523
 
1485
	   mov	edi,[CURRENT_TASK]
1524
	   mov	edi,[CURRENT_TASK]
1486
	   shl	edi,8
1525
	   shl	edi,8
1487
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1526
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1488
	   rol	eax,16
1527
	   rol	eax,16
1489
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1528
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1490
	   rol	eax,16
1529
	   rol	eax,16
1491
	   mov	[esp+36-4],eax
1530
	   mov	[esp+36-4],eax
1492
	   ret
1531
	   ret
1493
msbutton:
1532
msbutton:
1494
	   movzx eax,byte [BTN_DOWN]
1533
	   movzx eax,byte [BTN_DOWN]
1495
	   mov	[esp+36-4],eax
1534
	   mov	[esp+36-4],eax
1496
	   ret
1535
	   ret
1497
msz:
1536
msz:
1498
	   mov	 edi, [TASK_COUNT]
1537
	   mov	 edi, [TASK_COUNT]
1499
	   movzx edi, word [WIN_POS + edi*2]
1538
	   movzx edi, word [WIN_POS + edi*2]
1500
	   cmp	 edi, [CURRENT_TASK]
1539
	   cmp	 edi, [CURRENT_TASK]
1501
	   jne	 @f
1540
	   jne	 @f
1502
	   mov	 ax,[MOUSE_SCROLL_H]
1541
	   mov	 ax,[MOUSE_SCROLL_H]
1503
	   shl	 eax,16
1542
	   shl	 eax,16
1504
	   mov	 ax,[MOUSE_SCROLL_V]
1543
	   mov	 ax,[MOUSE_SCROLL_V]
1505
	   mov	 [esp+36-4],eax
1544
	   mov	 [esp+36-4],eax
1506
	   and	 [MOUSE_SCROLL_H],word 0
1545
	   and	 [MOUSE_SCROLL_H],word 0
1507
	   and	 [MOUSE_SCROLL_V],word 0
1546
	   and	 [MOUSE_SCROLL_V],word 0
1508
	   ret
1547
	   ret
1509
       @@:
1548
       @@:
1510
	   and	[esp+36-4],dword 0
1549
	   and	[esp+36-4],dword 0
1511
;           ret
1550
;           ret
1512
msset:
1551
msset:
1513
	   ret
1552
	   ret
1514
 
1553
 
1515
app_load_cursor:
1554
app_load_cursor:
1516
	   cmp ecx, OS_BASE
1555
	   cmp ecx, OS_BASE
1517
	   jae msset
1556
	   jae msset
1518
	   stdcall load_cursor, ecx, edx
1557
	   stdcall load_cursor, ecx, edx
1519
	   mov [esp+36-4], eax
1558
	   mov [esp+36-4], eax
1520
	   ret
1559
	   ret
1521
 
1560
 
1522
app_set_cursor:
1561
app_set_cursor:
1523
	   stdcall set_cursor, ecx
1562
	   stdcall set_cursor, ecx
1524
	   mov [esp+36-4], eax
1563
	   mov [esp+36-4], eax
1525
	   ret
1564
	   ret
1526
 
1565
 
1527
app_delete_cursor:
1566
app_delete_cursor:
1528
	   stdcall delete_cursor, ecx
1567
	   stdcall delete_cursor, ecx
1529
	   mov [esp+36-4], eax
1568
	   mov [esp+36-4], eax
1530
	   ret
1569
	   ret
1531
 
1570
 
1532
is_input:
1571
is_input:
1533
 
1572
 
1534
   push edx
1573
   push edx
1535
   mov	dx,word [midisp]
1574
   mov	dx,word [midisp]
1536
   in	al,dx
1575
   in	al,dx
1537
   and	al,0x80
1576
   and	al,0x80
1538
   pop	edx
1577
   pop	edx
1539
   ret
1578
   ret
1540
 
1579
 
1541
is_output:
1580
is_output:
1542
 
1581
 
1543
   push edx
1582
   push edx
1544
   mov	dx,word [midisp]
1583
   mov	dx,word [midisp]
1545
   in	al,dx
1584
   in	al,dx
1546
   and	al,0x40
1585
   and	al,0x40
1547
   pop	edx
1586
   pop	edx
1548
   ret
1587
   ret
1549
 
1588
 
1550
 
1589
 
1551
get_mpu_in:
1590
get_mpu_in:
1552
 
1591
 
1553
   push edx
1592
   push edx
1554
   mov	dx,word [mididp]
1593
   mov	dx,word [mididp]
1555
   in	al,dx
1594
   in	al,dx
1556
   pop	edx
1595
   pop	edx
1557
   ret
1596
   ret
1558
 
1597
 
1559
 
1598
 
1560
put_mpu_out:
1599
put_mpu_out:
1561
 
1600
 
1562
   push edx
1601
   push edx
1563
   mov	dx,word [mididp]
1602
   mov	dx,word [mididp]
1564
   out	dx,al
1603
   out	dx,al
1565
   pop	edx
1604
   pop	edx
1566
   ret
1605
   ret
1567
 
1606
 
1568
 
1607
 
1569
 
1608
 
1570
align 4
1609
align 4
1571
 
1610
 
1572
sys_midi:
1611
sys_midi:
1573
	cmp  [mididp],0
1612
	cmp  [mididp],0
1574
	jnz  sm0
1613
	jnz  sm0
1575
	mov  [esp+36],dword 1
1614
	mov  [esp+36],dword 1
1576
	ret
1615
	ret
1577
sm0:
1616
sm0:
1578
	and  [esp+36],dword 0
1617
	and  [esp+36],dword 0
1579
	dec  ebx
1618
	dec  ebx
1580
	jnz  smn1
1619
	jnz  smn1
1581
 ;    call setuart
1620
 ;    call setuart
1582
su1:
1621
su1:
1583
	call is_output
1622
	call is_output
1584
	test al,al
1623
	test al,al
1585
	jnz  su1
1624
	jnz  su1
1586
	mov  dx,word [midisp]
1625
	mov  dx,word [midisp]
1587
	mov  al,0xff
1626
	mov  al,0xff
1588
	out  dx,al
1627
	out  dx,al
1589
su2:
1628
su2:
1590
	mov  dx,word [midisp]
1629
	mov  dx,word [midisp]
1591
	mov  al,0xff
1630
	mov  al,0xff
1592
	out  dx,al
1631
	out  dx,al
1593
	call is_input
1632
	call is_input
1594
	test al,al
1633
	test al,al
1595
	jnz  su2
1634
	jnz  su2
1596
	call get_mpu_in
1635
	call get_mpu_in
1597
	cmp  al,0xfe
1636
	cmp  al,0xfe
1598
	jnz  su2
1637
	jnz  su2
1599
su3:
1638
su3:
1600
	call is_output
1639
	call is_output
1601
	test  al,al
1640
	test  al,al
1602
	jnz  su3
1641
	jnz  su3
1603
	mov  dx,word [midisp]
1642
	mov  dx,word [midisp]
1604
	mov  al,0x3f
1643
	mov  al,0x3f
1605
	out  dx,al
1644
	out  dx,al
1606
	ret
1645
	ret
1607
smn1:
1646
smn1:
1608
	dec  ebx
1647
	dec  ebx
1609
	jnz  smn2
1648
	jnz  smn2
1610
sm10:
1649
sm10:
1611
	call get_mpu_in
1650
	call get_mpu_in
1612
	call is_output
1651
	call is_output
1613
	test al,al
1652
	test al,al
1614
	jnz  sm10
1653
	jnz  sm10
1615
	mov  al,bl
1654
	mov  al,bl
1616
	call put_mpu_out
1655
	call put_mpu_out
1617
	smn2:
1656
	smn2:
1618
	ret
1657
	ret
1619
 
1658
 
1620
detect_devices:
1659
detect_devices:
1621
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1660
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1622
;include 'detect/commouse.inc'
1661
;include 'detect/commouse.inc'
1623
;include 'detect/ps2mouse.inc'
1662
;include 'detect/ps2mouse.inc'
1624
;include 'detect/dev_fd.inc'
1663
;include 'detect/dev_fd.inc'
1625
;include 'detect/dev_hdcd.inc'
1664
;include 'detect/dev_hdcd.inc'
1626
;include 'detect/sear_par.inc'
1665
;include 'detect/sear_par.inc'
1627
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1666
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1628
    ret
1667
    ret
1629
 
1668
 
1630
sys_end:
1669
sys_end:
1631
 
1670
 
1632
     mov ecx, [current_slot]
1671
     mov ecx, [current_slot]
1633
     mov eax, [ecx+APPDATA.tls_base]
1672
     mov eax, [ecx+APPDATA.tls_base]
1634
     test eax, eax
1673
     test eax, eax
1635
     jz @F
1674
     jz @F
1636
 
1675
 
1637
     stdcall user_free, eax
1676
     stdcall user_free, eax
1638
@@:
1677
@@:
1639
 
1678
 
1640
     mov   eax,[TASK_BASE]
1679
     mov   eax,[TASK_BASE]
1641
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1680
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1642
 
1681
 
1643
    waitterm:		 ; wait here for termination
1682
    waitterm:		 ; wait here for termination
1644
     mov   ebx,100
1683
     mov   ebx,100
1645
     call  delay_hs
1684
     call  delay_hs
1646
     jmp   waitterm
1685
     jmp   waitterm
1647
 
1686
 
1648
iglobal
1687
iglobal
1649
align 4
1688
align 4
1650
sys_system_table:
1689
sys_system_table:
1651
	dd	exit_for_anyone 	; 1 = obsolete
1690
	dd	exit_for_anyone 	; 1 = obsolete
1652
	dd	sysfn_terminate 	; 2 = terminate thread
1691
	dd	sysfn_terminate 	; 2 = terminate thread
1653
	dd	sysfn_activate		; 3 = activate window
1692
	dd	sysfn_activate		; 3 = activate window
1654
	dd	sysfn_getidletime	; 4 = get idle time
1693
	dd	sysfn_getidletime	; 4 = get idle time
1655
	dd	sysfn_getcpuclock	; 5 = get cpu clock
1694
	dd	sysfn_getcpuclock	; 5 = get cpu clock
1656
	dd	sysfn_saveramdisk	; 6 = save ramdisk
1695
	dd	sysfn_saveramdisk	; 6 = save ramdisk
1657
	dd	sysfn_getactive 	; 7 = get active window
1696
	dd	sysfn_getactive 	; 7 = get active window
1658
	dd	sysfn_sound_flag	; 8 = get/set sound_flag
1697
	dd	sysfn_sound_flag	; 8 = get/set sound_flag
1659
	dd	sysfn_shutdown		; 9 = shutdown with parameter
1698
	dd	sysfn_shutdown		; 9 = shutdown with parameter
1660
	dd	sysfn_minimize		; 10 = minimize window
1699
	dd	sysfn_minimize		; 10 = minimize window
1661
	dd	sysfn_getdiskinfo	; 11 = get disk subsystem info
1700
	dd	sysfn_getdiskinfo	; 11 = get disk subsystem info
1662
	dd	sysfn_lastkey		; 12 = get last pressed key
1701
	dd	sysfn_lastkey		; 12 = get last pressed key
1663
	dd	sysfn_getversion	; 13 = get kernel version
1702
	dd	sysfn_getversion	; 13 = get kernel version
1664
	dd	sysfn_waitretrace	; 14 = wait retrace
1703
	dd	sysfn_waitretrace	; 14 = wait retrace
1665
	dd	sysfn_centermouse	; 15 = center mouse cursor
1704
	dd	sysfn_centermouse	; 15 = center mouse cursor
1666
	dd	sysfn_getfreemem	; 16 = get free memory size
1705
	dd	sysfn_getfreemem	; 16 = get free memory size
1667
	dd	sysfn_getallmem 	; 17 = get total memory size
1706
	dd	sysfn_getallmem 	; 17 = get total memory size
1668
	dd	sysfn_terminate2	; 18 = terminate thread using PID
1707
	dd	sysfn_terminate2	; 18 = terminate thread using PID
1669
					;                 instead of slot
1708
					;                 instead of slot
1670
	dd	sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1709
	dd	sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1671
	dd	sysfn_meminfo		; 20 = get extended memory info
1710
	dd	sysfn_meminfo		; 20 = get extended memory info
1672
	dd	sysfn_pid_to_slot	; 21 = get slot number for pid
1711
	dd	sysfn_pid_to_slot	; 21 = get slot number for pid
1673
	dd	sysfn_min_rest_window	; 22 = minimize and restore any window
1712
	dd	sysfn_min_rest_window	; 22 = minimize and restore any window
1674
sysfn_num = ($ - sys_system_table)/4
1713
sysfn_num = ($ - sys_system_table)/4
1675
endg
1714
endg
1676
 
1715
 
1677
sys_system:
1716
sys_system:
1678
	dec	ebx
1717
	dec	ebx
1679
	cmp	ebx, sysfn_num
1718
	cmp	ebx, sysfn_num
1680
	jae	@f
1719
	jae	@f
1681
	jmp	dword [sys_system_table + ebx*4]
1720
	jmp	dword [sys_system_table + ebx*4]
1682
@@:
1721
@@:
1683
	ret
1722
	ret
1684
 
1723
 
1685
 
1724
 
1686
sysfn_shutdown: 	 ; 18.9 = system shutdown
1725
sysfn_shutdown: 	 ; 18.9 = system shutdown
1687
     cmp  ecx,1
1726
     cmp  ecx,1
1688
     jl   exit_for_anyone
1727
     jl   exit_for_anyone
1689
     cmp  ecx,4
1728
     cmp  ecx,4
1690
     jg   exit_for_anyone
1729
     jg   exit_for_anyone
1691
     mov  [BOOT_VAR+0x9030],cl
1730
     mov  [BOOT_VAR+0x9030],cl
1692
 
1731
 
1693
     mov  eax,[TASK_COUNT]
1732
     mov  eax,[TASK_COUNT]
1694
     mov  [SYS_SHUTDOWN],al
1733
     mov  [SYS_SHUTDOWN],al
1695
     mov  [shutdown_processes],eax
1734
     mov  [shutdown_processes],eax
1696
     and  dword [esp+32], 0
1735
     and  dword [esp+32], 0
1697
 exit_for_anyone:
1736
 exit_for_anyone:
1698
     ret
1737
     ret
1699
  uglobal
1738
  uglobal
1700
   shutdown_processes: dd 0x0
1739
   shutdown_processes: dd 0x0
1701
  endg
1740
  endg
1702
 
1741
 
1703
sysfn_terminate:	; 18.2 = TERMINATE
1742
sysfn_terminate:	; 18.2 = TERMINATE
1704
     cmp  ecx,2
1743
     cmp  ecx,2
1705
     jb   noprocessterminate
1744
     jb   noprocessterminate
1706
     mov  edx,[TASK_COUNT]
1745
     mov  edx,[TASK_COUNT]
1707
     cmp  ecx,edx
1746
     cmp  ecx,edx
1708
     ja   noprocessterminate
1747
     ja   noprocessterminate
1709
     mov  eax,[TASK_COUNT]
1748
     mov  eax,[TASK_COUNT]
1710
     shl  ecx,5
1749
     shl  ecx,5
1711
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
1750
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
1712
     add  ecx,CURRENT_TASK+TASKDATA.state
1751
     add  ecx,CURRENT_TASK+TASKDATA.state
1713
     cmp  byte [ecx], 9
1752
     cmp  byte [ecx], 9
1714
     jz   noprocessterminate
1753
     jz   noprocessterminate
1715
 
1754
 
1716
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1755
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1717
     mov  [ecx],byte 3	     ; clear possible i40's
1756
     mov  [ecx],byte 3	     ; clear possible i40's
1718
     ;call MEM_Heap_UnLock
1757
     ;call MEM_Heap_UnLock
1719
 
1758
 
1720
     cmp  edx,[application_table_status]    ; clear app table stat
1759
     cmp  edx,[application_table_status]    ; clear app table stat
1721
     jne  noatsc
1760
     jne  noatsc
1722
 
1761
 
1723
     and  [application_table_status],0
1762
     and  [application_table_status],0
1724
   noatsc:
1763
   noatsc:
1725
   noprocessterminate:
1764
   noprocessterminate:
1726
     ret
1765
     ret
1727
 
1766
 
1728
sysfn_terminate2:
1767
sysfn_terminate2:
1729
;lock application_table_status mutex
1768
;lock application_table_status mutex
1730
.table_status:
1769
.table_status:
1731
    cli
1770
    cli
1732
    cmp    [application_table_status],0
1771
    cmp    [application_table_status],0
1733
    je	   .stf
1772
    je	   .stf
1734
    sti
1773
    sti
1735
    call   change_task
1774
    call   change_task
1736
    jmp    .table_status
1775
    jmp    .table_status
1737
.stf:
1776
.stf:
1738
    call   set_application_table_status
1777
    call   set_application_table_status
1739
    mov    eax,ecx
1778
    mov    eax,ecx
1740
    call   pid_to_slot
1779
    call   pid_to_slot
1741
    test   eax,eax
1780
    test   eax,eax
1742
    jz	   .not_found
1781
    jz	   .not_found
1743
    mov    ecx,eax
1782
    mov    ecx,eax
1744
    cli
1783
    cli
1745
    call   sysfn_terminate
1784
    call   sysfn_terminate
1746
    and    [application_table_status],0
1785
    and    [application_table_status],0
1747
    sti
1786
    sti
1748
    and    dword [esp+32],0
1787
    and    dword [esp+32],0
1749
    ret
1788
    ret
1750
.not_found:
1789
.not_found:
1751
    mov    [application_table_status],0
1790
    mov    [application_table_status],0
1752
    or	   dword [esp+32],-1
1791
    or	   dword [esp+32],-1
1753
    ret
1792
    ret
1754
 
1793
 
1755
sysfn_activate: 	; 18.3 = ACTIVATE WINDOW
1794
sysfn_activate: 	; 18.3 = ACTIVATE WINDOW
1756
     cmp  ecx,2
1795
     cmp  ecx,2
1757
     jb   .nowindowactivate
1796
     jb   .nowindowactivate
1758
     cmp  ecx,[TASK_COUNT]
1797
     cmp  ecx,[TASK_COUNT]
1759
     ja   .nowindowactivate
1798
     ja   .nowindowactivate
1760
 
1799
 
1761
     mov   [window_minimize], 2   ; restore window if minimized
1800
     mov   [window_minimize], 2   ; restore window if minimized
1762
 
1801
 
1763
     movzx esi, word [WIN_STACK + ecx*2]
1802
     movzx esi, word [WIN_STACK + ecx*2]
1764
     cmp   esi, [TASK_COUNT]
1803
     cmp   esi, [TASK_COUNT]
1765
     je    .nowindowactivate ; already active
1804
     je    .nowindowactivate ; already active
1766
 
1805
 
1767
     mov   edi, ecx
1806
     mov   edi, ecx
1768
     shl   edi, 5
1807
     shl   edi, 5
1769
     add   edi, window_data
1808
     add   edi, window_data
1770
     movzx esi, word [WIN_STACK + ecx * 2]
1809
     movzx esi, word [WIN_STACK + ecx * 2]
1771
     lea   esi, [WIN_POS + esi * 2]
1810
     lea   esi, [WIN_POS + esi * 2]
1772
     call  waredraw
1811
     call  waredraw
1773
.nowindowactivate:
1812
.nowindowactivate:
1774
     ret
1813
     ret
1775
 
1814
 
1776
sysfn_getidletime:		; 18.4 = GET IDLETIME
1815
sysfn_getidletime:		; 18.4 = GET IDLETIME
1777
     mov  eax,[idleusesec]
1816
     mov  eax,[idleusesec]
1778
     mov  [esp+32], eax
1817
     mov  [esp+32], eax
1779
     ret
1818
     ret
1780
 
1819
 
1781
sysfn_getcpuclock:		; 18.5 = GET TSC/SEC
1820
sysfn_getcpuclock:		; 18.5 = GET TSC/SEC
1782
     mov  eax,[CPU_FREQ]
1821
     mov  eax,[CPU_FREQ]
1783
     mov  [esp+32], eax
1822
     mov  [esp+32], eax
1784
     ret
1823
     ret
1785
 
1824
 
1786
;  SAVE ramdisk to /hd/1/menuet.img
1825
;  SAVE ramdisk to /hd/1/menuet.img
1787
;!!!!!!!!!!!!!!!!!!!!!!!!
1826
;!!!!!!!!!!!!!!!!!!!!!!!!
1788
   include 'blkdev/rdsave.inc'
1827
   include 'blkdev/rdsave.inc'
1789
;!!!!!!!!!!!!!!!!!!!!!!!!
1828
;!!!!!!!!!!!!!!!!!!!!!!!!
1790
align 4
1829
align 4
1791
sysfn_getactive:	; 18.7 = get active window
1830
sysfn_getactive:	; 18.7 = get active window
1792
     mov  eax, [TASK_COUNT]
1831
     mov  eax, [TASK_COUNT]
1793
   movzx  eax, word [WIN_POS + eax*2]
1832
   movzx  eax, word [WIN_POS + eax*2]
1794
     mov  [esp+32],eax
1833
     mov  [esp+32],eax
1795
     ret
1834
     ret
1796
 
1835
 
1797
sysfn_sound_flag:	; 18.8 = get/set sound_flag
1836
sysfn_sound_flag:	; 18.8 = get/set sound_flag
1798
;     cmp  ecx,1
1837
;     cmp  ecx,1
1799
     dec  ecx
1838
     dec  ecx
1800
     jnz  nogetsoundflag
1839
     jnz  nogetsoundflag
1801
     movzx  eax,byte [sound_flag] ; get sound_flag
1840
     movzx  eax,byte [sound_flag] ; get sound_flag
1802
     mov  [esp+32],eax
1841
     mov  [esp+32],eax
1803
     ret
1842
     ret
1804
 nogetsoundflag:
1843
 nogetsoundflag:
1805
;     cmp  ecx,2
1844
;     cmp  ecx,2
1806
     dec  ecx
1845
     dec  ecx
1807
     jnz  nosoundflag
1846
     jnz  nosoundflag
1808
     xor  byte [sound_flag], 1
1847
     xor  byte [sound_flag], 1
1809
 nosoundflag:
1848
 nosoundflag:
1810
     ret
1849
     ret
1811
 
1850
 
1812
sysfn_minimize: 	; 18.10 = minimize window
1851
sysfn_minimize: 	; 18.10 = minimize window
1813
     mov   [window_minimize],1
1852
     mov   [window_minimize],1
1814
     ret
1853
     ret
1815
align 4
1854
align 4
1816
sysfn_getdiskinfo:	; 18.11 = get disk info table
1855
sysfn_getdiskinfo:	; 18.11 = get disk info table
1817
;     cmp  ecx,1
1856
;     cmp  ecx,1
1818
     dec  ecx
1857
     dec  ecx
1819
     jnz  full_table
1858
     jnz  full_table
1820
  small_table:
1859
  small_table:
1821
     call for_all_tables
1860
     call for_all_tables
1822
     mov ecx,10
1861
     mov ecx,10
1823
     cld
1862
     cld
1824
     rep movsb
1863
     rep movsb
1825
     ret
1864
     ret
1826
   for_all_tables:
1865
   for_all_tables:
1827
     mov edi,edx
1866
     mov edi,edx
1828
     mov esi,DRIVE_DATA
1867
     mov esi,DRIVE_DATA
1829
     ret
1868
     ret
1830
  full_table:
1869
  full_table:
1831
;     cmp  ecx,2
1870
;     cmp  ecx,2
1832
     dec  ecx
1871
     dec  ecx
1833
     jnz  exit_for_anyone
1872
     jnz  exit_for_anyone
1834
     call for_all_tables
1873
     call for_all_tables
1835
     mov ecx,16384
1874
     mov ecx,16384
1836
     cld
1875
     cld
1837
     rep movsd
1876
     rep movsd
1838
     ret
1877
     ret
1839
 
1878
 
1840
sysfn_lastkey:		; 18.12 = return 0 (backward compatibility)
1879
sysfn_lastkey:		; 18.12 = return 0 (backward compatibility)
1841
	and	dword [esp+32], 0
1880
	and	dword [esp+32], 0
1842
	ret
1881
	ret
1843
 
1882
 
1844
sysfn_getversion:	; 18.13 = get kernel ID and version
1883
sysfn_getversion:	; 18.13 = get kernel ID and version
1845
     mov edi,ecx
1884
     mov edi,ecx
1846
     mov esi,version_inf
1885
     mov esi,version_inf
1847
     mov ecx,version_end-version_inf
1886
     mov ecx,version_end-version_inf
1848
     rep movsb
1887
     rep movsb
1849
     ret
1888
     ret
1850
 
1889
 
1851
sysfn_waitretrace:     ; 18.14 = sys wait retrace
1890
sysfn_waitretrace:     ; 18.14 = sys wait retrace
1852
     ;wait retrace functions
1891
     ;wait retrace functions
1853
 sys_wait_retrace:
1892
 sys_wait_retrace:
1854
     mov edx,0x3da
1893
     mov edx,0x3da
1855
 WaitRetrace_loop:
1894
 WaitRetrace_loop:
1856
     in al,dx
1895
     in al,dx
1857
     test al,1000b
1896
     test al,1000b
1858
     jz WaitRetrace_loop
1897
     jz WaitRetrace_loop
1859
     and [esp+32],dword 0
1898
     and [esp+32],dword 0
1860
     ret
1899
     ret
1861
 
1900
 
1862
align 4
1901
align 4
1863
sysfn_centermouse:	; 18.15 = mouse centered
1902
sysfn_centermouse:	; 18.15 = mouse centered
1864
; removed here by 
1903
; removed here by 
1865
;     call  mouse_centered
1904
;     call  mouse_centered
1866
;* mouse centered - start code- Mario79
1905
;* mouse centered - start code- Mario79
1867
;mouse_centered:
1906
;mouse_centered:
1868
;        push  eax
1907
;        push  eax
1869
	mov   eax,[Screen_Max_X]
1908
	mov   eax,[Screen_Max_X]
1870
	shr   eax,1
1909
	shr   eax,1
1871
	mov   [MOUSE_X],ax
1910
	mov   [MOUSE_X],ax
1872
	mov   eax,[Screen_Max_Y]
1911
	mov   eax,[Screen_Max_Y]
1873
	shr   eax,1
1912
	shr   eax,1
1874
	mov   [MOUSE_Y],ax
1913
	mov   [MOUSE_Y],ax
1875
;        ret
1914
;        ret
1876
;* mouse centered - end code- Mario79
1915
;* mouse centered - end code- Mario79
1877
	xor   eax,eax
1916
	xor   eax,eax
1878
	and   [esp+32],eax
1917
	and   [esp+32],eax
1879
;        pop   eax
1918
;        pop   eax
1880
 
1919
 
1881
     ret
1920
     ret
1882
align 4
1921
align 4
1883
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
1922
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
1884
     test ecx,ecx  ; get mouse speed factor
1923
     test ecx,ecx  ; get mouse speed factor
1885
     jnz  .set_mouse_acceleration
1924
     jnz  .set_mouse_acceleration
1886
     xor  eax,eax
1925
     xor  eax,eax
1887
     mov  ax,[mouse_speed_factor]
1926
     mov  ax,[mouse_speed_factor]
1888
     mov  [esp+32],eax
1927
     mov  [esp+32],eax
1889
     ret
1928
     ret
1890
 .set_mouse_acceleration:
1929
 .set_mouse_acceleration:
1891
;     cmp  ecx,1  ; set mouse speed factor
1930
;     cmp  ecx,1  ; set mouse speed factor
1892
     dec  ecx
1931
     dec  ecx
1893
     jnz  .get_mouse_delay
1932
     jnz  .get_mouse_delay
1894
     mov  [mouse_speed_factor],dx
1933
     mov  [mouse_speed_factor],dx
1895
     ret
1934
     ret
1896
 .get_mouse_delay:
1935
 .get_mouse_delay:
1897
;     cmp  ecx,2  ; get mouse delay
1936
;     cmp  ecx,2  ; get mouse delay
1898
     dec  ecx
1937
     dec  ecx
1899
     jnz  .set_mouse_delay
1938
     jnz  .set_mouse_delay
1900
     mov  eax,[mouse_delay]
1939
     mov  eax,[mouse_delay]
1901
     mov  [esp+32],eax
1940
     mov  [esp+32],eax
1902
     ret
1941
     ret
1903
 .set_mouse_delay:
1942
 .set_mouse_delay:
1904
;     cmp  ecx,3  ; set mouse delay
1943
;     cmp  ecx,3  ; set mouse delay
1905
     dec  ecx
1944
     dec  ecx
1906
     jnz  .set_pointer_position
1945
     jnz  .set_pointer_position
1907
     mov  [mouse_delay],edx
1946
     mov  [mouse_delay],edx
1908
     ret
1947
     ret
1909
 .set_pointer_position:
1948
 .set_pointer_position:
1910
;     cmp  ecx,4  ; set mouse pointer position
1949
;     cmp  ecx,4  ; set mouse pointer position
1911
     dec   ecx
1950
     dec   ecx
1912
     jnz  .set_mouse_button
1951
     jnz  .set_mouse_button
1913
     cmp   dx, word[Screen_Max_Y]
1952
     cmp   dx, word[Screen_Max_Y]
1914
     ja    .end
1953
     ja    .end
1915
 
1954
 
1916
     rol   edx,16
1955
     rol   edx,16
1917
     cmp   dx, word[Screen_Max_X]
1956
     cmp   dx, word[Screen_Max_X]
1918
     ja    .end
1957
     ja    .end
1919
     mov   [MOUSE_X], edx
1958
     mov   [MOUSE_X], edx
1920
     ret
1959
     ret
1921
 .set_mouse_button:
1960
 .set_mouse_button:
1922
;     cmp   ecx,5  ; set mouse button features
1961
;     cmp   ecx,5  ; set mouse button features
1923
     dec   ecx
1962
     dec   ecx
1924
     jnz  .end
1963
     jnz  .end
1925
     mov   [BTN_DOWN],dl
1964
     mov   [BTN_DOWN],dl
1926
     mov   [mouse_active],1
1965
     mov   [mouse_active],1
1927
 .end:
1966
 .end:
1928
     ret
1967
     ret
1929
 
1968
 
1930
sysfn_getfreemem:
1969
sysfn_getfreemem:
1931
     mov eax, [pg_data.pages_free]
1970
     mov eax, [pg_data.pages_free]
1932
     shl eax, 2
1971
     shl eax, 2
1933
     mov [esp+32],eax
1972
     mov [esp+32],eax
1934
     ret
1973
     ret
1935
 
1974
 
1936
sysfn_getallmem:
1975
sysfn_getallmem:
1937
     mov  eax,[MEM_AMOUNT]
1976
     mov  eax,[MEM_AMOUNT]
1938
     shr eax, 10
1977
     shr eax, 10
1939
     mov  [esp+32],eax
1978
     mov  [esp+32],eax
1940
     ret
1979
     ret
1941
 
1980
 
1942
; // Alver, 2007-22-08 // {
1981
; // Alver, 2007-22-08 // {
1943
sysfn_pid_to_slot:
1982
sysfn_pid_to_slot:
1944
     mov   eax, ecx
1983
     mov   eax, ecx
1945
     call  pid_to_slot
1984
     call  pid_to_slot
1946
     mov   [esp+32], eax
1985
     mov   [esp+32], eax
1947
     ret
1986
     ret
1948
 
1987
 
1949
sysfn_min_rest_window:
1988
sysfn_min_rest_window:
1950
     pushad
1989
     pushad
1951
     mov   eax, edx	 ; ebx - operating
1990
     mov   eax, edx	 ; ebx - operating
1952
     shr   ecx, 1
1991
     shr   ecx, 1
1953
     jnc    @f
1992
     jnc    @f
1954
     call  pid_to_slot
1993
     call  pid_to_slot
1955
@@:
1994
@@:
1956
     or    eax, eax	 ; eax - number of slot
1995
     or    eax, eax	 ; eax - number of slot
1957
     jz    .error
1996
     jz    .error
1958
     cmp   eax, 255	    ; varify maximal slot number
1997
     cmp   eax, 255	    ; varify maximal slot number
1959
     ja    .error
1998
     ja    .error
1960
     movzx eax, word [WIN_STACK + eax*2]
1999
     movzx eax, word [WIN_STACK + eax*2]
1961
     shr   ecx, 1
2000
     shr   ecx, 1
1962
     jc    .restore
2001
     jc    .restore
1963
 ; .minimize:
2002
 ; .minimize:
1964
     call  minimize_window
2003
     call  minimize_window
1965
     jmp   .exit
2004
     jmp   .exit
1966
.restore:
2005
.restore:
1967
     call  restore_minimized_window
2006
     call  restore_minimized_window
1968
.exit:
2007
.exit:
1969
     popad
2008
     popad
1970
     xor   eax, eax
2009
     xor   eax, eax
1971
     mov   [esp+32], eax
2010
     mov   [esp+32], eax
1972
     ret
2011
     ret
1973
.error:
2012
.error:
1974
     popad
2013
     popad
1975
     xor   eax, eax
2014
     xor   eax, eax
1976
     dec   eax
2015
     dec   eax
1977
     mov   [esp+32], eax
2016
     mov   [esp+32], eax
1978
     ret
2017
     ret
1979
; } \\ Alver, 2007-22-08 \\
2018
; } \\ Alver, 2007-22-08 \\
1980
 
2019
 
1981
uglobal
2020
uglobal
1982
;// mike.dld, 2006-29-01 [
2021
;// mike.dld, 2006-29-01 [
1983
screen_workarea RECT
2022
screen_workarea RECT
1984
;// mike.dld, 2006-29-01 ]
2023
;// mike.dld, 2006-29-01 ]
1985
window_minimize db 0
2024
window_minimize db 0
1986
sound_flag	db 0
2025
sound_flag	db 0
1987
endg
2026
endg
1988
 
2027
 
1989
iglobal
2028
iglobal
1990
version_inf:
2029
version_inf:
1991
  db 0,7,7,0  ; version 0.7.7.0
2030
  db 0,7,7,0  ; version 0.7.7.0
1992
  db 0		;reserved
2031
  db 0		;reserved
1993
  dd __REV__
2032
  dd __REV__
1994
version_end:
2033
version_end:
1995
endg
2034
endg
1996
 
2035
 
1997
sys_cachetodiskette:		; << removed
2036
sys_cachetodiskette:		; << removed
1998
	mov	[esp + 32], ebx
2037
	mov	[esp + 32], ebx
1999
	ret
2038
	ret
2000
 
2039
 
2001
uglobal
2040
uglobal
2002
;  bgrchanged  dd  0x0
2041
;  bgrchanged  dd  0x0
2003
align 4
2042
align 4
2004
bgrlockpid dd 0
2043
bgrlockpid dd 0
2005
bgrlock db 0
2044
bgrlock db 0
2006
endg
2045
endg
2007
 
2046
 
2008
;===============================  SysFn 15  ================================
2047
;===============================  SysFn 15  ================================
2009
sys_background:
2048
sys_background:
2010
 
2049
 
2011
    cmp   ebx,1 			   ; BACKGROUND SIZE
2050
    cmp   ebx,1 			   ; BACKGROUND SIZE
2012
    jnz   nosb1
2051
    jnz   nosb1
2013
    test  ecx,ecx
2052
    test  ecx,ecx
2014
;    cmp   ecx,0
2053
;    cmp   ecx,0
2015
    jz	  sbgrr
2054
    jz	  sbgrr
2016
    test  edx,edx
2055
    test  edx,edx
2017
;    cmp   edx,0
2056
;    cmp   edx,0
2018
    jz	  sbgrr
2057
    jz	  sbgrr
2019
@@:
2058
@@:
2020
;;Maxis use atomic bts for mutexes  4.4.2009
2059
;;Maxis use atomic bts for mutexes  4.4.2009
2021
	bts	dword [bgrlock], 0
2060
	bts	dword [bgrlock], 0
2022
	jnc	@f
2061
	jnc	@f
2023
	call	change_task
2062
	call	change_task
2024
	jmp	@b
2063
	jmp	@b
2025
@@:
2064
@@:
2026
    mov   [BgrDataWidth],ecx
2065
    mov   [BgrDataWidth],ecx
2027
    mov   [BgrDataHeight],edx
2066
    mov   [BgrDataHeight],edx
2028
;    mov   [bgrchanged],1
2067
;    mov   [bgrchanged],1
2029
 
2068
 
2030
    pushad
2069
    pushad
2031
; return memory for old background
2070
; return memory for old background
2032
	mov	eax, [img_background]
2071
	mov	eax, [img_background]
2033
	cmp	eax, static_background_data
2072
	cmp	eax, static_background_data
2034
	jz	@f
2073
	jz	@f
2035
	stdcall kernel_free, eax
2074
	stdcall kernel_free, eax
2036
@@:
2075
@@:
2037
; calculate RAW size
2076
; calculate RAW size
2038
    xor  eax,eax
2077
    xor  eax,eax
2039
    inc  eax
2078
    inc  eax
2040
    cmp  [BgrDataWidth],eax
2079
    cmp  [BgrDataWidth],eax
2041
    jae   @f
2080
    jae   @f
2042
    mov [BgrDataWidth],eax
2081
    mov [BgrDataWidth],eax
2043
@@:
2082
@@:
2044
    cmp  [BgrDataHeight],eax
2083
    cmp  [BgrDataHeight],eax
2045
    jae   @f
2084
    jae   @f
2046
    mov [BgrDataHeight],eax
2085
    mov [BgrDataHeight],eax
2047
@@:
2086
@@:
2048
    mov  eax,[BgrDataWidth]
2087
    mov  eax,[BgrDataWidth]
2049
    imul eax,[BgrDataHeight]
2088
    imul eax,[BgrDataHeight]
2050
    lea  eax,[eax*3]
2089
    lea  eax,[eax*3]
2051
    mov  [mem_BACKGROUND],eax
2090
    mov  [mem_BACKGROUND],eax
2052
; get memory for new background
2091
; get memory for new background
2053
    stdcall kernel_alloc, eax
2092
    stdcall kernel_alloc, eax
2054
    test eax, eax
2093
    test eax, eax
2055
    jz .memfailed
2094
    jz .memfailed
2056
    mov [img_background], eax
2095
    mov [img_background], eax
2057
    jmp .exit
2096
    jmp .exit
2058
.memfailed:
2097
.memfailed:
2059
; revert to static monotone data
2098
; revert to static monotone data
2060
	mov	[img_background], static_background_data
2099
	mov	[img_background], static_background_data
2061
	xor	eax, eax
2100
	xor	eax, eax
2062
	inc	eax
2101
	inc	eax
2063
	mov	[BgrDataWidth], eax
2102
	mov	[BgrDataWidth], eax
2064
	mov	[BgrDataHeight], eax
2103
	mov	[BgrDataHeight], eax
2065
	mov	[mem_BACKGROUND], 4
2104
	mov	[mem_BACKGROUND], 4
2066
.exit:
2105
.exit:
2067
    popad
2106
    popad
2068
	mov	[bgrlock], 0
2107
	mov	[bgrlock], 0
2069
 
2108
 
2070
  sbgrr:
2109
  sbgrr:
2071
    ret
2110
    ret
2072
 
2111
 
2073
nosb1:
2112
nosb1:
2074
 
2113
 
2075
    cmp   ebx,2 			   ; SET PIXEL
2114
    cmp   ebx,2 			   ; SET PIXEL
2076
    jnz   nosb2
2115
    jnz   nosb2
2077
 
2116
 
2078
    mov   eax, [img_background]
2117
    mov   eax, [img_background]
2079
    test  ecx, ecx
2118
    test  ecx, ecx
2080
    jz	  @f
2119
    jz	  @f
2081
    cmp   eax, static_background_data
2120
    cmp   eax, static_background_data
2082
 
2121
 
2083
    jz	  .ret
2122
    jz	  .ret
2084
@@:
2123
@@:
2085
    mov ebx, [mem_BACKGROUND]
2124
    mov ebx, [mem_BACKGROUND]
2086
    add ebx, 4095
2125
    add ebx, 4095
2087
    and ebx, -4096
2126
    and ebx, -4096
2088
    sub ebx, 4
2127
    sub ebx, 4
2089
    cmp   ecx, ebx
2128
    cmp   ecx, ebx
2090
    ja	 .ret
2129
    ja	 .ret
2091
 
2130
 
2092
    mov   ebx,[eax+ecx]
2131
    mov   ebx,[eax+ecx]
2093
    and   ebx,0xFF000000 ;255*256*256*256
2132
    and   ebx,0xFF000000 ;255*256*256*256
2094
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2133
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2095
    add   edx,ebx
2134
    add   edx,ebx
2096
    mov   [eax+ecx],edx
2135
    mov   [eax+ecx],edx
2097
.ret:
2136
.ret:
2098
    ret
2137
    ret
2099
nosb2:
2138
nosb2:
2100
 
2139
 
2101
    cmp   ebx,3 			   ; DRAW BACKGROUND
2140
    cmp   ebx,3 			   ; DRAW BACKGROUND
2102
    jnz   nosb3
2141
    jnz   nosb3
2103
draw_background_temp:
2142
draw_background_temp:
2104
;    cmp   [bgrchanged],1 ;0
2143
;    cmp   [bgrchanged],1 ;0
2105
;    je    nosb31
2144
;    je    nosb31
2106
;draw_background_temp:
2145
;draw_background_temp:
2107
;    mov   [bgrchanged],1 ;0
2146
;    mov   [bgrchanged],1 ;0
2108
    mov    [background_defined], 1
2147
    mov    [background_defined], 1
2109
    mov    byte[BACKGROUND_CHANGED], 1
2148
    mov    byte[BACKGROUND_CHANGED], 1
2110
    call  force_redraw_background
2149
    call  force_redraw_background
2111
   nosb31:
2150
   nosb31:
2112
    ret
2151
    ret
2113
  nosb3:
2152
  nosb3:
2114
 
2153
 
2115
    cmp   ebx,4 			   ; TILED / STRETCHED
2154
    cmp   ebx,4 			   ; TILED / STRETCHED
2116
    jnz   nosb4
2155
    jnz   nosb4
2117
    cmp   ecx,[BgrDrawMode]
2156
    cmp   ecx,[BgrDrawMode]
2118
    je	  nosb41
2157
    je	  nosb41
2119
    mov   [BgrDrawMode],ecx
2158
    mov   [BgrDrawMode],ecx
2120
;    mov   [bgrchanged],1
2159
;    mov   [bgrchanged],1
2121
   nosb41:
2160
   nosb41:
2122
    ret
2161
    ret
2123
  nosb4:
2162
  nosb4:
2124
 
2163
 
2125
    cmp   ebx,5 			   ; BLOCK MOVE TO BGR
2164
    cmp   ebx,5 			   ; BLOCK MOVE TO BGR
2126
    jnz   nosb5
2165
    jnz   nosb5
2127
    cmp   [img_background], static_background_data
2166
    cmp   [img_background], static_background_data
2128
    jnz   @f
2167
    jnz   @f
2129
    test  edx, edx
2168
    test  edx, edx
2130
    jnz   .fin
2169
    jnz   .fin
2131
    cmp   esi, 4
2170
    cmp   esi, 4
2132
    ja	  .fin
2171
    ja	  .fin
2133
  @@:
2172
  @@:
2134
  ; bughere
2173
  ; bughere
2135
    mov   eax, ecx
2174
    mov   eax, ecx
2136
    mov   ebx, edx
2175
    mov   ebx, edx
2137
    add   ebx, [img_background]   ;IMG_BACKGROUND
2176
    add   ebx, [img_background]   ;IMG_BACKGROUND
2138
    mov   ecx, esi
2177
    mov   ecx, esi
2139
    call  memmove
2178
    call  memmove
2140
  .fin:
2179
  .fin:
2141
    ret
2180
    ret
2142
  nosb5:
2181
  nosb5:
2143
 
2182
 
2144
	cmp	ebx, 6
2183
	cmp	ebx, 6
2145
	jnz	nosb6
2184
	jnz	nosb6
2146
;;Maxis use atomic bts for mutex 4.4.2009
2185
;;Maxis use atomic bts for mutex 4.4.2009
2147
@@:
2186
@@:
2148
	bts	dword [bgrlock], 0
2187
	bts	dword [bgrlock], 0
2149
	jnc	@f
2188
	jnc	@f
2150
	call	change_task
2189
	call	change_task
2151
	jmp	@b
2190
	jmp	@b
2152
@@:
2191
@@:
2153
	mov	eax, [CURRENT_TASK]
2192
	mov	eax, [CURRENT_TASK]
2154
	mov	[bgrlockpid], eax
2193
	mov	[bgrlockpid], eax
2155
	cmp	[img_background], static_background_data
2194
	cmp	[img_background], static_background_data
2156
	jz	.nomem
2195
	jz	.nomem
2157
	stdcall user_alloc, [mem_BACKGROUND]
2196
	stdcall user_alloc, [mem_BACKGROUND]
2158
	mov	[esp+32], eax
2197
	mov	[esp+32], eax
2159
	test	eax, eax
2198
	test	eax, eax
2160
	jz	.nomem
2199
	jz	.nomem
2161
	mov	ebx, eax
2200
	mov	ebx, eax
2162
	shr	ebx, 12
2201
	shr	ebx, 12
2163
	or	dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2202
	or	dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2164
	mov	esi, [img_background]
2203
	mov	esi, [img_background]
2165
	shr	esi, 12
2204
	shr	esi, 12
2166
	mov	ecx, [mem_BACKGROUND]
2205
	mov	ecx, [mem_BACKGROUND]
2167
	add	ecx, 0xFFF
2206
	add	ecx, 0xFFF
2168
	shr	ecx, 12
2207
	shr	ecx, 12
2169
.z:
2208
.z:
2170
	mov	eax, [page_tabs+ebx*4]
2209
	mov	eax, [page_tabs+ebx*4]
2171
	test	al, 1
2210
	test	al, 1
2172
	jz	@f
2211
	jz	@f
2173
	call	free_page
2212
	call	free_page
2174
@@:
2213
@@:
2175
	mov	eax, [page_tabs+esi*4]
2214
	mov	eax, [page_tabs+esi*4]
2176
	or	al, PG_UW
2215
	or	al, PG_UW
2177
	mov	[page_tabs+ebx*4], eax
2216
	mov	[page_tabs+ebx*4], eax
2178
	mov	eax, ebx
2217
	mov	eax, ebx
2179
	shl	eax, 12
2218
	shl	eax, 12
2180
	invlpg	[eax]
2219
	invlpg	[eax]
2181
	inc	ebx
2220
	inc	ebx
2182
	inc	esi
2221
	inc	esi
2183
	loop	.z
2222
	loop	.z
2184
	ret
2223
	ret
2185
.nomem:
2224
.nomem:
2186
	and	[bgrlockpid], 0
2225
	and	[bgrlockpid], 0
2187
	mov	[bgrlock], 0
2226
	mov	[bgrlock], 0
2188
nosb6:
2227
nosb6:
2189
	cmp	ebx, 7
2228
	cmp	ebx, 7
2190
	jnz	nosb7
2229
	jnz	nosb7
2191
	cmp	[bgrlock], 0
2230
	cmp	[bgrlock], 0
2192
	jz	.err
2231
	jz	.err
2193
	mov	eax, [CURRENT_TASK]
2232
	mov	eax, [CURRENT_TASK]
2194
	cmp	[bgrlockpid], eax
2233
	cmp	[bgrlockpid], eax
2195
	jnz	.err
2234
	jnz	.err
2196
	mov	eax, ecx
2235
	mov	eax, ecx
2197
	mov	ebx, ecx
2236
	mov	ebx, ecx
2198
	shr	eax, 12
2237
	shr	eax, 12
2199
	mov	ecx, [page_tabs+(eax-1)*4]
2238
	mov	ecx, [page_tabs+(eax-1)*4]
2200
	test	cl, USED_BLOCK+DONT_FREE_BLOCK
2239
	test	cl, USED_BLOCK+DONT_FREE_BLOCK
2201
	jz	.err
2240
	jz	.err
2202
	jnp	.err
2241
	jnp	.err
2203
	push	eax
2242
	push	eax
2204
	shr	ecx, 12
2243
	shr	ecx, 12
2205
	dec	ecx
2244
	dec	ecx
2206
@@:
2245
@@:
2207
	and	dword [page_tabs+eax*4], 0
2246
	and	dword [page_tabs+eax*4], 0
2208
	mov	edx, eax
2247
	mov	edx, eax
2209
	shl	edx, 12
2248
	shl	edx, 12
2210
	push eax
2249
	push eax
2211
	invlpg	[edx]
2250
	invlpg	[edx]
2212
	pop eax
2251
	pop eax
2213
	inc	eax
2252
	inc	eax
2214
	loop	@b
2253
	loop	@b
2215
	pop	eax
2254
	pop	eax
2216
	and	dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2255
	and	dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2217
	stdcall user_free, ebx
2256
	stdcall user_free, ebx
2218
	mov	[esp+32], eax
2257
	mov	[esp+32], eax
2219
	and	[bgrlockpid], 0
2258
	and	[bgrlockpid], 0
2220
	mov	[bgrlock], 0
2259
	mov	[bgrlock], 0
2221
	ret
2260
	ret
2222
.err:
2261
.err:
2223
	and	dword [esp+32], 0
2262
	and	dword [esp+32], 0
2224
	ret
2263
	ret
2225
 
2264
 
2226
nosb7:
2265
nosb7:
2227
    ret
2266
    ret
2228
 
2267
 
2229
;===============================  SysFn 39  ================================
2268
;===============================  SysFn 39  ================================
2230
align 4
2269
align 4
2231
 
2270
 
2232
sys_getbackground:
2271
sys_getbackground:
2233
    dec   ebx
2272
    dec   ebx
2234
    jnz   nogb1
2273
    jnz   nogb1
2235
    mov   eax,[BgrDataWidth]
2274
    mov   eax,[BgrDataWidth]
2236
    shl   eax,16
2275
    shl   eax,16
2237
    mov   ax,[BgrDataHeight]
2276
    mov   ax,[BgrDataHeight]
2238
    mov   [esp+32],eax
2277
    mov   [esp+32],eax
2239
    ret
2278
    ret
2240
 
2279
 
2241
nogb1:
2280
nogb1:
2242
;    cmp   eax,2                                  ; PIXEL
2281
;    cmp   eax,2                                  ; PIXEL
2243
    dec   ebx
2282
    dec   ebx
2244
    jnz   nogb2
2283
    jnz   nogb2
2245
 
2284
 
2246
	mov	eax, [img_background]
2285
	mov	eax, [img_background]
2247
	test	ecx, ecx
2286
	test	ecx, ecx
2248
	jz	@f
2287
	jz	@f
2249
	cmp	eax, static_background_data
2288
	cmp	eax, static_background_data
2250
	jz	.ret
2289
	jz	.ret
2251
@@:
2290
@@:
2252
    mov ebx, [mem_BACKGROUND]
2291
    mov ebx, [mem_BACKGROUND]
2253
    add ebx, 4095
2292
    add ebx, 4095
2254
    and ebx, -4096
2293
    and ebx, -4096
2255
    sub ebx, 4
2294
    sub ebx, 4
2256
    cmp ecx, ebx
2295
    cmp ecx, ebx
2257
    ja	.ret
2296
    ja	.ret
2258
 
2297
 
2259
    mov   eax,[ecx+eax]
2298
    mov   eax,[ecx+eax]
2260
 
2299
 
2261
    and   eax, 0xFFFFFF
2300
    and   eax, 0xFFFFFF
2262
    mov   [esp+32],eax
2301
    mov   [esp+32],eax
2263
.ret:
2302
.ret:
2264
    ret
2303
    ret
2265
  nogb2:
2304
  nogb2:
2266
 
2305
 
2267
;    cmp   eax,4                                  ; TILED / STRETCHED
2306
;    cmp   eax,4                                  ; TILED / STRETCHED
2268
    dec   ebx
2307
    dec   ebx
2269
    dec   ebx
2308
    dec   ebx
2270
    jnz   nogb4
2309
    jnz   nogb4
2271
    mov   eax,[BgrDrawMode]
2310
    mov   eax,[BgrDrawMode]
2272
  nogb4:
2311
  nogb4:
2273
    mov   [esp+32],eax
2312
    mov   [esp+32],eax
2274
    ret
2313
    ret
2275
 
2314
 
2276
;===========================================
2315
;===========================================
2277
 
2316
 
2278
force_redraw_background:
2317
force_redraw_background:
2279
    and   [draw_data+32 + RECT.left], 0
2318
    and   [draw_data+32 + RECT.left], 0
2280
    and   [draw_data+32 + RECT.top], 0
2319
    and   [draw_data+32 + RECT.top], 0
2281
    push  eax ebx
2320
    push  eax ebx
2282
    mov   eax,[Screen_Max_X]
2321
    mov   eax,[Screen_Max_X]
2283
    mov   ebx,[Screen_Max_Y]
2322
    mov   ebx,[Screen_Max_Y]
2284
    mov   [draw_data+32 + RECT.right],eax
2323
    mov   [draw_data+32 + RECT.right],eax
2285
    mov   [draw_data+32 + RECT.bottom],ebx
2324
    mov   [draw_data+32 + RECT.bottom],ebx
2286
    pop   ebx eax
2325
    pop   ebx eax
2287
    inc   byte[REDRAW_BACKGROUND]
2326
    inc   byte[REDRAW_BACKGROUND]
2288
    ret
2327
    ret
2289
;===========================================
2328
;===========================================
2290
 
2329
 
2291
 
2330
 
2292
align 4
2331
align 4
2293
 
2332
 
2294
sys_getkey:
2333
sys_getkey:
2295
	mov	[esp + 32],dword 1
2334
	mov	[esp + 32],dword 1
2296
	; test main buffer
2335
	; test main buffer
2297
	mov	ebx, [CURRENT_TASK]			     ; TOP OF WINDOW STACK
2336
	mov	ebx, [CURRENT_TASK]			     ; TOP OF WINDOW STACK
2298
	movzx	ecx, word [WIN_STACK + ebx * 2]
2337
	movzx	ecx, word [WIN_STACK + ebx * 2]
2299
	mov	edx, [TASK_COUNT]
2338
	mov	edx, [TASK_COUNT]
2300
	cmp	ecx, edx
2339
	cmp	ecx, edx
2301
	jne	.finish
2340
	jne	.finish
2302
	cmp	[KEY_COUNT], byte 0
2341
	cmp	[KEY_COUNT], byte 0
2303
	je	.finish
2342
	je	.finish
2304
	movzx	eax, byte [KEY_BUFF]
2343
	movzx	eax, byte [KEY_BUFF]
2305
	shl	eax, 8
2344
	shl	eax, 8
2306
	push	eax
2345
	push	eax
2307
	dec	byte [KEY_COUNT]
2346
	dec	byte [KEY_COUNT]
2308
	and	byte [KEY_COUNT], 127
2347
	and	byte [KEY_COUNT], 127
2309
	movzx	ecx, byte [KEY_COUNT]
2348
	movzx	ecx, byte [KEY_COUNT]
2310
	add	ecx, 2
2349
	add	ecx, 2
2311
	mov	eax, KEY_BUFF + 1
2350
	mov	eax, KEY_BUFF + 1
2312
	mov	ebx, KEY_BUFF
2351
	mov	ebx, KEY_BUFF
2313
	call	memmove
2352
	call	memmove
2314
	pop	eax
2353
	pop	eax
2315
.ret_eax:
2354
.ret_eax:
2316
	mov	[esp + 32], eax
2355
	mov	[esp + 32], eax
2317
	ret
2356
	ret
2318
.finish:
2357
.finish:
2319
; test hotkeys buffer
2358
; test hotkeys buffer
2320
	mov	ecx, hotkey_buffer
2359
	mov	ecx, hotkey_buffer
2321
@@:
2360
@@:
2322
	cmp	[ecx], ebx
2361
	cmp	[ecx], ebx
2323
	jz	.found
2362
	jz	.found
2324
	add	ecx, 8
2363
	add	ecx, 8
2325
	cmp	ecx, hotkey_buffer + 120 * 8
2364
	cmp	ecx, hotkey_buffer + 120 * 8
2326
	jb	@b
2365
	jb	@b
2327
	ret
2366
	ret
2328
.found:
2367
.found:
2329
	mov	ax, [ecx + 6]
2368
	mov	ax, [ecx + 6]
2330
	shl	eax, 16
2369
	shl	eax, 16
2331
	mov	ah, [ecx + 4]
2370
	mov	ah, [ecx + 4]
2332
	mov	al, 2
2371
	mov	al, 2
2333
	and	dword [ecx + 4], 0
2372
	and	dword [ecx + 4], 0
2334
	and	dword [ecx], 0
2373
	and	dword [ecx], 0
2335
	jmp	.ret_eax
2374
	jmp	.ret_eax
2336
 
2375
 
2337
align 4
2376
align 4
2338
 
2377
 
2339
sys_getbutton:
2378
sys_getbutton:
2340
 
2379
 
2341
	mov	ebx, [CURRENT_TASK]			    ; TOP OF WINDOW STACK
2380
	mov	ebx, [CURRENT_TASK]			    ; TOP OF WINDOW STACK
2342
	mov	[esp + 32], dword 1
2381
	mov	[esp + 32], dword 1
2343
	movzx	ecx, word [WIN_STACK + ebx * 2]
2382
	movzx	ecx, word [WIN_STACK + ebx * 2]
2344
	mov	edx, [TASK_COUNT] ; less than 256 processes
2383
	mov	edx, [TASK_COUNT] ; less than 256 processes
2345
	cmp	ecx, edx
2384
	cmp	ecx, edx
2346
	jne	.exit
2385
	jne	.exit
2347
	movzx	eax, byte [BTN_COUNT]
2386
	movzx	eax, byte [BTN_COUNT]
2348
	test	eax, eax
2387
	test	eax, eax
2349
	jz	.exit
2388
	jz	.exit
2350
	mov	eax, [BTN_BUFF]
2389
	mov	eax, [BTN_BUFF]
2351
	and	al, 0xFE				    ; delete left button bit
2390
	and	al, 0xFE				    ; delete left button bit
2352
	mov	[BTN_COUNT], byte 0
2391
	mov	[BTN_COUNT], byte 0
2353
	mov	[esp + 32], eax
2392
	mov	[esp + 32], eax
2354
.exit:
2393
.exit:
2355
	ret
2394
	ret
2356
 
2395
 
2357
 
2396
 
2358
align 4
2397
align 4
2359
 
2398
 
2360
sys_cpuusage:
2399
sys_cpuusage:
2361
 
2400
 
2362
;  RETURN:
2401
;  RETURN:
2363
;
2402
;
2364
;  +00 dword     process cpu usage
2403
;  +00 dword     process cpu usage
2365
;  +04  word     position in windowing stack
2404
;  +04  word     position in windowing stack
2366
;  +06  word     windowing stack value at current position (cpu nro)
2405
;  +06  word     windowing stack value at current position (cpu nro)
2367
;  +10 12 bytes  name
2406
;  +10 12 bytes  name
2368
;  +22 dword     start in mem
2407
;  +22 dword     start in mem
2369
;  +26 dword     used mem
2408
;  +26 dword     used mem
2370
;  +30 dword     PID , process idenfification number
2409
;  +30 dword     PID , process idenfification number
2371
;
2410
;
2372
 
2411
 
2373
    cmp  ecx,-1 	; who am I ?
2412
    cmp  ecx,-1 	; who am I ?
2374
    jne  .no_who_am_i
2413
    jne  .no_who_am_i
2375
    mov  ecx,[CURRENT_TASK]
2414
    mov  ecx,[CURRENT_TASK]
2376
  .no_who_am_i:
2415
  .no_who_am_i:
2377
	cmp	ecx, max_processes
2416
	cmp	ecx, max_processes
2378
	ja	.nofillbuf
2417
	ja	.nofillbuf
2379
 
2418
 
2380
; +4: word: position of the window of thread in the window stack
2419
; +4: word: position of the window of thread in the window stack
2381
	mov	ax, [WIN_STACK + ecx * 2]
2420
	mov	ax, [WIN_STACK + ecx * 2]
2382
	mov	[ebx+4], ax
2421
	mov	[ebx+4], ax
2383
; +6: word: number of the thread slot, which window has in the window stack
2422
; +6: word: number of the thread slot, which window has in the window stack
2384
;           position ecx (has no relation to the specific thread)
2423
;           position ecx (has no relation to the specific thread)
2385
	mov	ax, [WIN_POS + ecx * 2]
2424
	mov	ax, [WIN_POS + ecx * 2]
2386
	mov	[ebx+6], ax
2425
	mov	[ebx+6], ax
2387
 
2426
 
2388
	shl	ecx, 5
2427
	shl	ecx, 5
2389
 
2428
 
2390
; +0: dword: memory usage
2429
; +0: dword: memory usage
2391
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2430
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2392
	mov	[ebx], eax
2431
	mov	[ebx], eax
2393
; +10: 11 bytes: name of the process
2432
; +10: 11 bytes: name of the process
2394
	push	ecx
2433
	push	ecx
2395
	lea	eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2434
	lea	eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2396
	add	ebx, 10
2435
	add	ebx, 10
2397
	mov	ecx, 11
2436
	mov	ecx, 11
2398
	call	memmove
2437
	call	memmove
2399
	pop	ecx
2438
	pop	ecx
2400
 
2439
 
2401
; +22: address of the process in memory
2440
; +22: address of the process in memory
2402
; +26: size of used memory - 1
2441
; +26: size of used memory - 1
2403
	push	edi
2442
	push	edi
2404
	lea	edi, [ebx+12]
2443
	lea	edi, [ebx+12]
2405
	xor	eax, eax
2444
	xor	eax, eax
2406
	mov	edx, 0x100000*16
2445
	mov	edx, 0x100000*16
2407
	cmp	ecx, 1 shl 5
2446
	cmp	ecx, 1 shl 5
2408
	je	.os_mem
2447
	je	.os_mem
2409
	mov	edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2448
	mov	edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2410
	mov	eax, std_application_base_address
2449
	mov	eax, std_application_base_address
2411
.os_mem:
2450
.os_mem:
2412
	stosd
2451
	stosd
2413
	lea	eax, [edx-1]
2452
	lea	eax, [edx-1]
2414
	stosd
2453
	stosd
2415
 
2454
 
2416
; +30: PID/TID
2455
; +30: PID/TID
2417
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2456
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2418
	stosd
2457
	stosd
2419
 
2458
 
2420
    ; window position and size
2459
    ; window position and size
2421
	push	esi
2460
	push	esi
2422
	lea	esi, [ecx + window_data + WDATA.box]
2461
	lea	esi, [ecx + window_data + WDATA.box]
2423
	movsd
2462
	movsd
2424
	movsd
2463
	movsd
2425
	movsd
2464
	movsd
2426
	movsd
2465
	movsd
2427
 
2466
 
2428
    ; Process state (+50)
2467
    ; Process state (+50)
2429
	mov	eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2468
	mov	eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2430
	stosd
2469
	stosd
2431
 
2470
 
2432
    ; Window client area box
2471
    ; Window client area box
2433
	lea	esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2472
	lea	esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2434
	movsd
2473
	movsd
2435
	movsd
2474
	movsd
2436
	movsd
2475
	movsd
2437
	movsd
2476
	movsd
2438
 
2477
 
2439
    ; Window state
2478
    ; Window state
2440
	mov	al, [ecx+window_data+WDATA.fl_wstate]
2479
	mov	al, [ecx+window_data+WDATA.fl_wstate]
2441
	stosb
2480
	stosb
2442
 
2481
 
2443
    ; Event mask (+71)
2482
    ; Event mask (+71)
2444
	mov	EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
2483
	mov	EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
2445
	stosd
2484
	stosd
2446
 
2485
 
2447
	pop	esi
2486
	pop	esi
2448
	pop	edi
2487
	pop	edi
2449
 
2488
 
2450
.nofillbuf:
2489
.nofillbuf:
2451
    ; return number of processes
2490
    ; return number of processes
2452
 
2491
 
2453
    mov    eax,[TASK_COUNT]
2492
    mov    eax,[TASK_COUNT]
2454
    mov    [esp+32],eax
2493
    mov    [esp+32],eax
2455
    ret
2494
    ret
2456
 
2495
 
2457
align 4
2496
align 4
2458
sys_clock:
2497
sys_clock:
2459
	cli
2498
	cli
2460
  ; Mikhail Lisovin  xx Jan 2005
2499
  ; Mikhail Lisovin  xx Jan 2005
2461
  @@:	mov   al, 10
2500
  @@:	mov   al, 10
2462
	out   0x70, al
2501
	out   0x70, al
2463
	in    al, 0x71
2502
	in    al, 0x71
2464
	test  al, al
2503
	test  al, al
2465
	jns   @f
2504
	jns   @f
2466
	mov   esi, 1
2505
	mov   esi, 1
2467
	call  delay_ms
2506
	call  delay_ms
2468
	jmp   @b
2507
	jmp   @b
2469
  @@:
2508
  @@:
2470
  ; end Lisovin's fix
2509
  ; end Lisovin's fix
2471
 
2510
 
2472
	xor   al,al	      ; seconds
2511
	xor   al,al	      ; seconds
2473
	out   0x70,al
2512
	out   0x70,al
2474
	in    al,0x71
2513
	in    al,0x71
2475
	movzx ecx,al
2514
	movzx ecx,al
2476
	mov   al,02	      ; minutes
2515
	mov   al,02	      ; minutes
2477
	shl   ecx,16
2516
	shl   ecx,16
2478
	out   0x70,al
2517
	out   0x70,al
2479
	in    al,0x71
2518
	in    al,0x71
2480
	movzx edx,al
2519
	movzx edx,al
2481
	mov   al,04	      ; hours
2520
	mov   al,04	      ; hours
2482
	shl   edx,8
2521
	shl   edx,8
2483
	out   0x70,al
2522
	out   0x70,al
2484
	in    al,0x71
2523
	in    al,0x71
2485
	add   ecx,edx
2524
	add   ecx,edx
2486
	movzx edx,al
2525
	movzx edx,al
2487
	add   ecx,edx
2526
	add   ecx,edx
2488
	sti
2527
	sti
2489
	mov	[esp + 32], ecx
2528
	mov	[esp + 32], ecx
2490
	ret
2529
	ret
2491
 
2530
 
2492
 
2531
 
2493
align 4
2532
align 4
2494
 
2533
 
2495
sys_date:
2534
sys_date:
2496
 
2535
 
2497
	cli
2536
	cli
2498
  @@:	mov   al, 10
2537
  @@:	mov   al, 10
2499
	out   0x70, al
2538
	out   0x70, al
2500
	in    al, 0x71
2539
	in    al, 0x71
2501
	test  al, al
2540
	test  al, al
2502
	jns   @f
2541
	jns   @f
2503
	mov   esi, 1
2542
	mov   esi, 1
2504
	call  delay_ms
2543
	call  delay_ms
2505
	jmp   @b
2544
	jmp   @b
2506
  @@:
2545
  @@:
2507
 
2546
 
2508
	mov	ch,0
2547
	mov	ch,0
2509
	mov	al,7		; date
2548
	mov	al,7		; date
2510
	out	0x70,al
2549
	out	0x70,al
2511
	in	al,0x71
2550
	in	al,0x71
2512
	mov	cl,al
2551
	mov	cl,al
2513
	mov	al,8		; month
2552
	mov	al,8		; month
2514
	shl	ecx,16
2553
	shl	ecx,16
2515
	out	0x70,al
2554
	out	0x70,al
2516
	in	al,0x71
2555
	in	al,0x71
2517
	mov	ch,al
2556
	mov	ch,al
2518
	mov	al,9		; year
2557
	mov	al,9		; year
2519
	out	0x70,al
2558
	out	0x70,al
2520
	in	al,0x71
2559
	in	al,0x71
2521
	mov	cl,al
2560
	mov	cl,al
2522
	sti
2561
	sti
2523
	mov	[esp+32], ecx
2562
	mov	[esp+32], ecx
2524
	ret
2563
	ret
2525
 
2564
 
2526
 
2565
 
2527
; redraw status
2566
; redraw status
2528
 
2567
 
2529
sys_redrawstat:
2568
sys_redrawstat:
2530
	cmp	ebx, 1
2569
	cmp	ebx, 1
2531
	jne	no_widgets_away
2570
	jne	no_widgets_away
2532
	; buttons away
2571
	; buttons away
2533
	mov	ecx,[CURRENT_TASK]
2572
	mov	ecx,[CURRENT_TASK]
2534
  sys_newba2:
2573
  sys_newba2:
2535
	mov	edi,[BTN_ADDR]
2574
	mov	edi,[BTN_ADDR]
2536
	cmp	[edi], dword 0	; empty button list ?
2575
	cmp	[edi], dword 0	; empty button list ?
2537
	je	end_of_buttons_away
2576
	je	end_of_buttons_away
2538
	movzx	ebx, word [edi]
2577
	movzx	ebx, word [edi]
2539
	inc	ebx
2578
	inc	ebx
2540
	mov	eax,edi
2579
	mov	eax,edi
2541
  sys_newba:
2580
  sys_newba:
2542
	dec	ebx
2581
	dec	ebx
2543
	jz	end_of_buttons_away
2582
	jz	end_of_buttons_away
2544
 
2583
 
2545
	add	eax, 0x10
2584
	add	eax, 0x10
2546
	cmp	cx, [eax]
2585
	cmp	cx, [eax]
2547
	jnz	sys_newba
2586
	jnz	sys_newba
2548
 
2587
 
2549
	push	eax ebx ecx
2588
	push	eax ebx ecx
2550
	mov	ecx,ebx
2589
	mov	ecx,ebx
2551
	inc	ecx
2590
	inc	ecx
2552
	shl	ecx, 4
2591
	shl	ecx, 4
2553
	mov	ebx, eax
2592
	mov	ebx, eax
2554
	add	eax, 0x10
2593
	add	eax, 0x10
2555
	call	memmove
2594
	call	memmove
2556
	dec	dword [edi]
2595
	dec	dword [edi]
2557
	pop	ecx ebx eax
2596
	pop	ecx ebx eax
2558
 
2597
 
2559
	jmp	sys_newba2
2598
	jmp	sys_newba2
2560
 
2599
 
2561
  end_of_buttons_away:
2600
  end_of_buttons_away:
2562
 
2601
 
2563
	ret
2602
	ret
2564
 
2603
 
2565
  no_widgets_away:
2604
  no_widgets_away:
2566
 
2605
 
2567
	cmp	ebx, 2
2606
	cmp	ebx, 2
2568
	jnz	srl1
2607
	jnz	srl1
2569
 
2608
 
2570
	mov	edx, [TASK_BASE]      ; return whole screen draw area for this app
2609
	mov	edx, [TASK_BASE]      ; return whole screen draw area for this app
2571
	add	edx, draw_data - CURRENT_TASK
2610
	add	edx, draw_data - CURRENT_TASK
2572
	mov	[edx + RECT.left], 0
2611
	mov	[edx + RECT.left], 0
2573
	mov	[edx + RECT.top], 0
2612
	mov	[edx + RECT.top], 0
2574
	mov	eax, [Screen_Max_X]
2613
	mov	eax, [Screen_Max_X]
2575
 
2614
 
2576
	mov	[edx + RECT.right], eax
2615
	mov	[edx + RECT.right], eax
2577
	mov	eax, [Screen_Max_Y]
2616
	mov	eax, [Screen_Max_Y]
2578
	mov	[edx + RECT.bottom], eax
2617
	mov	[edx + RECT.bottom], eax
2579
 
2618
 
2580
  srl1:
2619
  srl1:
2581
	ret
2620
	ret
2582
 
2621
 
2583
;ok - 100% work
2622
;ok - 100% work
2584
;nt - not tested
2623
;nt - not tested
2585
;---------------------------------------------------------------------------------------------
2624
;---------------------------------------------------------------------------------------------
2586
;eax
2625
;eax
2587
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2626
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2588
;1 - change task. Ret nothing. Block. ok.
2627
;1 - change task. Ret nothing. Block. ok.
2589
;2 - performance control
2628
;2 - performance control
2590
; ebx
2629
; ebx
2591
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2630
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2592
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2631
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2593
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2632
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2594
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2633
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2595
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2634
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2596
;eax
2635
;eax
2597
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2636
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2598
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2637
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2599
;---------------------------------------------------------------------------------------------
2638
;---------------------------------------------------------------------------------------------
2600
iglobal
2639
iglobal
2601
align 4
2640
align 4
2602
sheduler:
2641
sheduler:
2603
	dd	sys_sheduler.00
2642
	dd	sys_sheduler.00
2604
	dd	change_task
2643
	dd	change_task
2605
	dd	sys_sheduler.02
2644
	dd	sys_sheduler.02
2606
	dd	sys_sheduler.03
2645
	dd	sys_sheduler.03
2607
	dd	sys_sheduler.04
2646
	dd	sys_sheduler.04
2608
endg
2647
endg
2609
sys_sheduler:
2648
sys_sheduler:
2610
;rewritten by   29.12.2009
2649
;rewritten by   29.12.2009
2611
	jmp	dword [sheduler+ebx*4]
2650
	jmp	dword [sheduler+ebx*4]
2612
;.shed_counter:
2651
;.shed_counter:
2613
.00:
2652
.00:
2614
	mov eax,[context_counter]
2653
	mov eax,[context_counter]
2615
	mov [esp+32],eax
2654
	mov [esp+32],eax
2616
	ret
2655
	ret
2617
 
2656
 
2618
.02:
2657
.02:
2619
;.perf_control:
2658
;.perf_control:
2620
	inc	ebx			;before ebx=2, ebx=3
2659
	inc	ebx			;before ebx=2, ebx=3
2621
	cmp	ebx,ecx 		;if ecx=3, ebx=3
2660
	cmp	ebx,ecx 		;if ecx=3, ebx=3
2622
	jz	cache_disable
2661
	jz	cache_disable
2623
 
2662
 
2624
	dec	ebx			;ebx=2
2663
	dec	ebx			;ebx=2
2625
	cmp	ebx,ecx 		;
2664
	cmp	ebx,ecx 		;
2626
	jz	cache_enable		;if ecx=2 and ebx=2
2665
	jz	cache_enable		;if ecx=2 and ebx=2
2627
 
2666
 
2628
	dec	ebx			;ebx=1
2667
	dec	ebx			;ebx=1
2629
	cmp	ebx,ecx
2668
	cmp	ebx,ecx
2630
	jz	is_cache_enabled	;if ecx=1 and ebx=1
2669
	jz	is_cache_enabled	;if ecx=1 and ebx=1
2631
 
2670
 
2632
	dec	ebx
2671
	dec	ebx
2633
	test	ebx,ecx 		;ebx=0 and ecx=0
2672
	test	ebx,ecx 		;ebx=0 and ecx=0
2634
	jz	modify_pce		;if ecx=0
2673
	jz	modify_pce		;if ecx=0
2635
 
2674
 
2636
	ret
2675
	ret
2637
 
2676
 
2638
.03:
2677
.03:
2639
;.rdmsr_instr:
2678
;.rdmsr_instr:
2640
;now counter in ecx
2679
;now counter in ecx
2641
;(edx:eax) esi:edi => edx:esi
2680
;(edx:eax) esi:edi => edx:esi
2642
	mov	eax,esi
2681
	mov	eax,esi
2643
	mov	ecx,edx
2682
	mov	ecx,edx
2644
	rdmsr
2683
	rdmsr
2645
	mov	[esp+32],eax
2684
	mov	[esp+32],eax
2646
	mov	[esp+20],edx		;ret in ebx?
2685
	mov	[esp+20],edx		;ret in ebx?
2647
	ret
2686
	ret
2648
 
2687
 
2649
.04:
2688
.04:
2650
;.wrmsr_instr:
2689
;.wrmsr_instr:
2651
;now counter in ecx
2690
;now counter in ecx
2652
;(edx:eax) esi:edi => edx:esi
2691
;(edx:eax) esi:edi => edx:esi
2653
	; Fast Call MSR can't be destroy
2692
	; Fast Call MSR can't be destroy
2654
	; ® MSR_AMD_EFER ¬®¦­® ¨§¬¥­ïâì, â.ª. ¢ í⮬ ॣ¨áâॠ«¨è
2693
	; ® MSR_AMD_EFER ¬®¦­® ¨§¬¥­ïâì, â.ª. ¢ í⮬ ॣ¨áâॠ«¨è
2655
	; ¢ª«îç îâáï/¢ëª«îç îâáï à áè¨à¥­­ë¥ ¢®§¬®¦­®áâ¨
2694
	; ¢ª«îç îâáï/¢ëª«îç îâáï à áè¨à¥­­ë¥ ¢®§¬®¦­®áâ¨
2656
	cmp	edx,MSR_SYSENTER_CS
2695
	cmp	edx,MSR_SYSENTER_CS
2657
	je	@f
2696
	je	@f
2658
	cmp	edx,MSR_SYSENTER_ESP
2697
	cmp	edx,MSR_SYSENTER_ESP
2659
	je	@f
2698
	je	@f
2660
	cmp	edx,MSR_SYSENTER_EIP
2699
	cmp	edx,MSR_SYSENTER_EIP
2661
	je	@f
2700
	je	@f
2662
	cmp	edx,MSR_AMD_STAR
2701
	cmp	edx,MSR_AMD_STAR
2663
	je	@f
2702
	je	@f
2664
 
2703
 
2665
	mov	eax,esi
2704
	mov	eax,esi
2666
	mov	ecx,edx
2705
	mov	ecx,edx
2667
	wrmsr
2706
	wrmsr
2668
	; mov   [esp + 32], eax
2707
	; mov   [esp + 32], eax
2669
	; mov   [esp + 20], edx ;ret in ebx?
2708
	; mov   [esp + 20], edx ;ret in ebx?
2670
@@:
2709
@@:
2671
	ret
2710
	ret
2672
 
2711
 
2673
cache_disable:
2712
cache_disable:
2674
       mov eax,cr0
2713
       mov eax,cr0
2675
       or  eax,01100000000000000000000000000000b
2714
       or  eax,01100000000000000000000000000000b
2676
       mov cr0,eax
2715
       mov cr0,eax
2677
       wbinvd ;set MESI
2716
       wbinvd ;set MESI
2678
ret
2717
ret
2679
 
2718
 
2680
cache_enable:
2719
cache_enable:
2681
       mov eax,cr0
2720
       mov eax,cr0
2682
       and eax,10011111111111111111111111111111b
2721
       and eax,10011111111111111111111111111111b
2683
       mov cr0,eax
2722
       mov cr0,eax
2684
ret
2723
ret
2685
 
2724
 
2686
is_cache_enabled:
2725
is_cache_enabled:
2687
       mov eax,cr0
2726
       mov eax,cr0
2688
       mov ebx,eax
2727
       mov ebx,eax
2689
       and eax,01100000000000000000000000000000b
2728
       and eax,01100000000000000000000000000000b
2690
       jz cache_disabled
2729
       jz cache_disabled
2691
       mov [esp+32],ebx
2730
       mov [esp+32],ebx
2692
cache_disabled:
2731
cache_disabled:
2693
       mov dword [esp+32],eax ;0
2732
       mov dword [esp+32],eax ;0
2694
ret
2733
ret
2695
 
2734
 
2696
modify_pce:
2735
modify_pce:
2697
       mov eax,cr4
2736
       mov eax,cr4
2698
;       mov ebx,0
2737
;       mov ebx,0
2699
;       or  bx,100000000b ;pce
2738
;       or  bx,100000000b ;pce
2700
;       xor eax,ebx ;invert pce
2739
;       xor eax,ebx ;invert pce
2701
       bts eax,8 ;pce=cr4[8]
2740
       bts eax,8 ;pce=cr4[8]
2702
       mov cr4,eax
2741
       mov cr4,eax
2703
       mov [esp+32],eax
2742
       mov [esp+32],eax
2704
ret
2743
ret
2705
;---------------------------------------------------------------------------------------------
2744
;---------------------------------------------------------------------------------------------
2706
 
2745
 
2707
 
2746
 
2708
iglobal
2747
iglobal
2709
  cpustring db 'CPU',0
2748
  cpustring db 'CPU',0
2710
endg
2749
endg
2711
 
2750
 
2712
uglobal
2751
uglobal
2713
background_defined    db    0	 ; diamond, 11.04.2006
2752
background_defined    db    0	 ; diamond, 11.04.2006
2714
endg
2753
endg
2715
 
2754
 
2716
align 4
2755
align 4
2717
; check misc
2756
; check misc
2718
 
2757
 
2719
checkmisc:
2758
checkmisc:
2720
 
2759
 
2721
    cmp   [ctrl_alt_del], 1
2760
    cmp   [ctrl_alt_del], 1
2722
    jne   nocpustart
2761
    jne   nocpustart
2723
 
2762
 
2724
	mov	ebp, cpustring
2763
	mov	ebp, cpustring
2725
	call	fs_execute_from_sysdir
2764
	call	fs_execute_from_sysdir
2726
 
2765
 
2727
    mov   [ctrl_alt_del], 0
2766
    mov   [ctrl_alt_del], 0
2728
 
2767
 
2729
nocpustart:
2768
nocpustart:
2730
    cmp   [mouse_active], 1
2769
    cmp   [mouse_active], 1
2731
    jne   mouse_not_active
2770
    jne   mouse_not_active
2732
    mov   [mouse_active], 0
2771
    mov   [mouse_active], 0
2733
    xor   edi, edi
2772
    xor   edi, edi
2734
    mov   ecx,	[TASK_COUNT]
2773
    mov   ecx,	[TASK_COUNT]
2735
set_mouse_event:
2774
set_mouse_event:
2736
    add   edi, 256
2775
    add   edi, 256
2737
    or	  [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
2776
    or	  [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
2738
    loop  set_mouse_event
2777
    loop  set_mouse_event
2739
 
2778
 
2740
mouse_not_active:
2779
mouse_not_active:
2741
    cmp   byte[BACKGROUND_CHANGED], 0
2780
    cmp   byte[BACKGROUND_CHANGED], 0
2742
    jz	  no_set_bgr_event
2781
    jz	  no_set_bgr_event
2743
    xor   edi, edi
2782
    xor   edi, edi
2744
    mov   ecx, [TASK_COUNT]
2783
    mov   ecx, [TASK_COUNT]
2745
set_bgr_event:
2784
set_bgr_event:
2746
    add   edi, 256
2785
    add   edi, 256
2747
    or	  [edi+SLOT_BASE+APPDATA.event_mask], 16
2786
    or	  [edi+SLOT_BASE+APPDATA.event_mask], 16
2748
    loop  set_bgr_event
2787
    loop  set_bgr_event
2749
    mov   byte[BACKGROUND_CHANGED], 0
2788
    mov   byte[BACKGROUND_CHANGED], 0
2750
no_set_bgr_event:
2789
no_set_bgr_event:
2751
    cmp   byte[REDRAW_BACKGROUND], 0		   ; background update ?
2790
    cmp   byte[REDRAW_BACKGROUND], 0		   ; background update ?
2752
    jz	  nobackgr
2791
    jz	  nobackgr
2753
    cmp    [background_defined], 0
2792
    cmp    [background_defined], 0
2754
    jz	  nobackgr
2793
    jz	  nobackgr
2755
@@:
2794
@@:
2756
    call  drawbackground
2795
    call  drawbackground
2757
    xor   eax, eax
2796
    xor   eax, eax
2758
    xchg  al, [REDRAW_BACKGROUND]
2797
    xchg  al, [REDRAW_BACKGROUND]
2759
    test  al, al				   ; got new update request?
2798
    test  al, al				   ; got new update request?
2760
    jnz   @b
2799
    jnz   @b
2761
    mov   [draw_data+32 + RECT.left], eax
2800
    mov   [draw_data+32 + RECT.left], eax
2762
    mov   [draw_data+32 + RECT.top], eax
2801
    mov   [draw_data+32 + RECT.top], eax
2763
    mov   [draw_data+32 + RECT.right], eax
2802
    mov   [draw_data+32 + RECT.right], eax
2764
    mov   [draw_data+32 + RECT.bottom], eax
2803
    mov   [draw_data+32 + RECT.bottom], eax
2765
    mov   [MOUSE_BACKGROUND],byte 0
2804
    mov   [MOUSE_BACKGROUND],byte 0
2766
 
2805
 
2767
nobackgr:
2806
nobackgr:
2768
 
2807
 
2769
    ; system shutdown request
2808
    ; system shutdown request
2770
 
2809
 
2771
    cmp  [SYS_SHUTDOWN],byte 0
2810
    cmp  [SYS_SHUTDOWN],byte 0
2772
    je	 noshutdown
2811
    je	 noshutdown
2773
 
2812
 
2774
    mov  edx,[shutdown_processes]
2813
    mov  edx,[shutdown_processes]
2775
 
2814
 
2776
    cmp  [SYS_SHUTDOWN],dl
2815
    cmp  [SYS_SHUTDOWN],dl
2777
    jne  no_mark_system_shutdown
2816
    jne  no_mark_system_shutdown
2778
 
2817
 
2779
    lea   ecx,[edx-1]
2818
    lea   ecx,[edx-1]
2780
    mov   edx,OS_BASE+0x3040
2819
    mov   edx,OS_BASE+0x3040
2781
    jecxz @f
2820
    jecxz @f
2782
markz:
2821
markz:
2783
    mov   [edx+TASKDATA.state],byte 3
2822
    mov   [edx+TASKDATA.state],byte 3
2784
    add   edx,0x20
2823
    add   edx,0x20
2785
    loop  markz
2824
    loop  markz
2786
@@:
2825
@@:
2787
 
2826
 
2788
  no_mark_system_shutdown:
2827
  no_mark_system_shutdown:
2789
 
2828
 
2790
    call [_display.disable_mouse]
2829
    call [_display.disable_mouse]
2791
 
2830
 
2792
    dec  byte [SYS_SHUTDOWN]
2831
    dec  byte [SYS_SHUTDOWN]
2793
    je	 system_shutdown
2832
    je	 system_shutdown
2794
 
2833
 
2795
noshutdown:
2834
noshutdown:
2796
    mov   eax,[TASK_COUNT]		    ; termination
2835
    mov   eax,[TASK_COUNT]		    ; termination
2797
    mov   ebx,TASK_DATA+TASKDATA.state
2836
    mov   ebx,TASK_DATA+TASKDATA.state
2798
    mov   esi,1
2837
    mov   esi,1
2799
 
2838
 
2800
newct:
2839
newct:
2801
    mov   cl,[ebx]
2840
    mov   cl,[ebx]
2802
    cmp   cl,byte 3
2841
    cmp   cl,byte 3
2803
    jz	  terminate
2842
    jz	  terminate
2804
    cmp   cl,byte 4
2843
    cmp   cl,byte 4
2805
    jz	  terminate
2844
    jz	  terminate
2806
 
2845
 
2807
    add   ebx,0x20
2846
    add   ebx,0x20
2808
    inc   esi
2847
    inc   esi
2809
    dec   eax
2848
    dec   eax
2810
    jnz   newct
2849
    jnz   newct
2811
    ret
2850
    ret
2812
 
2851
 
2813
; redraw screen
2852
; redraw screen
2814
; eax , if process window_data base is eax, do not set flag/limits
2853
; eax , if process window_data base is eax, do not set flag/limits
2815
 
2854
 
2816
redrawscreen:
2855
redrawscreen:
2817
	 pushad
2856
	 pushad
2818
	 push  eax
2857
	 push  eax
2819
 
2858
 
2820
	 xor   ecx,ecx			; redraw flags for apps
2859
	 xor   ecx,ecx			; redraw flags for apps
2821
       newdw2:
2860
       newdw2:
2822
 
2861
 
2823
	 inc   ecx
2862
	 inc   ecx
2824
	 push  ecx
2863
	 push  ecx
2825
 
2864
 
2826
	 mov   eax,ecx
2865
	 mov   eax,ecx
2827
	 shl   eax,5
2866
	 shl   eax,5
2828
	 add   eax,window_data
2867
	 add   eax,window_data
2829
 
2868
 
2830
	 cmp   eax,[esp+4]
2869
	 cmp   eax,[esp+4]
2831
	 je    not_this_task
2870
	 je    not_this_task
2832
				   ; check if window in redraw area
2871
				   ; check if window in redraw area
2833
	 mov   edi,eax
2872
	 mov   edi,eax
2834
 
2873
 
2835
	 cmp   ecx,1		   ; limit for background
2874
	 cmp   ecx,1		   ; limit for background
2836
	 jz    bgli
2875
	 jz    bgli
2837
 
2876
 
2838
	 mov   eax, [edi + WDATA.box.left]
2877
	 mov   eax, [edi + WDATA.box.left]
2839
	 mov   ebx, [edi + WDATA.box.top]
2878
	 mov   ebx, [edi + WDATA.box.top]
2840
	 mov   ecx, [edi + WDATA.box.width]
2879
	 mov   ecx, [edi + WDATA.box.width]
2841
	 mov   edx, [edi + WDATA.box.height]
2880
	 mov   edx, [edi + WDATA.box.height]
2842
	 add   ecx,eax
2881
	 add   ecx,eax
2843
	 add   edx,ebx
2882
	 add   edx,ebx
2844
 
2883
 
2845
	 mov   ecx,[draw_limits.bottom]   ; ecx = area y end     ebx = window y start
2884
	 mov   ecx,[draw_limits.bottom]   ; ecx = area y end     ebx = window y start
2846
	 cmp   ecx,ebx
2885
	 cmp   ecx,ebx
2847
	 jb    ricino
2886
	 jb    ricino
2848
 
2887
 
2849
	 mov   ecx,[draw_limits.right]	 ; ecx = area x end     eax = window x start
2888
	 mov   ecx,[draw_limits.right]	 ; ecx = area x end     eax = window x start
2850
	 cmp   ecx,eax
2889
	 cmp   ecx,eax
2851
	 jb    ricino
2890
	 jb    ricino
2852
 
2891
 
2853
	 mov   eax, [edi + WDATA.box.left]
2892
	 mov   eax, [edi + WDATA.box.left]
2854
	 mov   ebx, [edi + WDATA.box.top]
2893
	 mov   ebx, [edi + WDATA.box.top]
2855
	 mov   ecx, [edi + WDATA.box.width]
2894
	 mov   ecx, [edi + WDATA.box.width]
2856
	 mov   edx, [edi + WDATA.box.height]
2895
	 mov   edx, [edi + WDATA.box.height]
2857
	 add   ecx, eax
2896
	 add   ecx, eax
2858
	 add   edx, ebx
2897
	 add   edx, ebx
2859
 
2898
 
2860
	 mov   eax,[draw_limits.top]	; eax = area y start     edx = window y end
2899
	 mov   eax,[draw_limits.top]	; eax = area y start     edx = window y end
2861
	 cmp   edx,eax
2900
	 cmp   edx,eax
2862
	 jb    ricino
2901
	 jb    ricino
2863
 
2902
 
2864
	 mov   eax,[draw_limits.left]	 ; eax = area x start     ecx = window x end
2903
	 mov   eax,[draw_limits.left]	 ; eax = area x start     ecx = window x end
2865
	 cmp   ecx,eax
2904
	 cmp   ecx,eax
2866
	 jb    ricino
2905
	 jb    ricino
2867
 
2906
 
2868
	bgli:
2907
	bgli:
2869
 
2908
 
2870
	 cmp   dword[esp], 1
2909
	 cmp   dword[esp], 1
2871
	 jnz   .az
2910
	 jnz   .az
2872
	 cmp   byte[REDRAW_BACKGROUND], 0
2911
	 cmp   byte[REDRAW_BACKGROUND], 0
2873
	 jz    .az
2912
	 jz    .az
2874
	 mov   dl, 0
2913
	 mov   dl, 0
2875
	 lea   eax,[edi+draw_data-window_data]
2914
	 lea   eax,[edi+draw_data-window_data]
2876
	 mov   ebx,[draw_limits.left]
2915
	 mov   ebx,[draw_limits.left]
2877
	 cmp   ebx,[eax+RECT.left]
2916
	 cmp   ebx,[eax+RECT.left]
2878
	 jae   @f
2917
	 jae   @f
2879
	 mov   [eax+RECT.left],ebx
2918
	 mov   [eax+RECT.left],ebx
2880
	 mov   dl, 1
2919
	 mov   dl, 1
2881
	@@:
2920
	@@:
2882
	 mov   ebx,[draw_limits.top]
2921
	 mov   ebx,[draw_limits.top]
2883
	 cmp   ebx,[eax+RECT.top]
2922
	 cmp   ebx,[eax+RECT.top]
2884
	 jae   @f
2923
	 jae   @f
2885
	 mov   [eax+RECT.top],ebx
2924
	 mov   [eax+RECT.top],ebx
2886
	 mov   dl, 1
2925
	 mov   dl, 1
2887
	@@:
2926
	@@:
2888
	 mov   ebx,[draw_limits.right]
2927
	 mov   ebx,[draw_limits.right]
2889
	 cmp   ebx,[eax+RECT.right]
2928
	 cmp   ebx,[eax+RECT.right]
2890
	 jbe   @f
2929
	 jbe   @f
2891
	 mov   [eax+RECT.right],ebx
2930
	 mov   [eax+RECT.right],ebx
2892
	 mov   dl, 1
2931
	 mov   dl, 1
2893
	@@:
2932
	@@:
2894
	 mov   ebx,[draw_limits.bottom]
2933
	 mov   ebx,[draw_limits.bottom]
2895
	 cmp   ebx,[eax+RECT.bottom]
2934
	 cmp   ebx,[eax+RECT.bottom]
2896
	 jbe   @f
2935
	 jbe   @f
2897
	 mov   [eax+RECT.bottom],ebx
2936
	 mov   [eax+RECT.bottom],ebx
2898
	 mov   dl, 1
2937
	 mov   dl, 1
2899
	@@:
2938
	@@:
2900
	 add   byte[REDRAW_BACKGROUND], dl
2939
	 add   byte[REDRAW_BACKGROUND], dl
2901
	 jmp   newdw8
2940
	 jmp   newdw8
2902
	.az:
2941
	.az:
2903
 
2942
 
2904
	 mov   eax,edi
2943
	 mov   eax,edi
2905
	 add   eax,draw_data-window_data
2944
	 add   eax,draw_data-window_data
2906
 
2945
 
2907
	 mov   ebx,[draw_limits.left]	       ; set limits
2946
	 mov   ebx,[draw_limits.left]	       ; set limits
2908
	 mov   [eax + RECT.left], ebx
2947
	 mov   [eax + RECT.left], ebx
2909
	 mov   ebx,[draw_limits.top]
2948
	 mov   ebx,[draw_limits.top]
2910
	 mov   [eax + RECT.top], ebx
2949
	 mov   [eax + RECT.top], ebx
2911
	 mov   ebx,[draw_limits.right]
2950
	 mov   ebx,[draw_limits.right]
2912
	 mov   [eax + RECT.right], ebx
2951
	 mov   [eax + RECT.right], ebx
2913
	 mov   ebx,[draw_limits.bottom]
2952
	 mov   ebx,[draw_limits.bottom]
2914
	 mov   [eax + RECT.bottom], ebx
2953
	 mov   [eax + RECT.bottom], ebx
2915
 
2954
 
2916
	 sub   eax,draw_data-window_data
2955
	 sub   eax,draw_data-window_data
2917
 
2956
 
2918
	 cmp   dword [esp],1
2957
	 cmp   dword [esp],1
2919
	 jne   nobgrd
2958
	 jne   nobgrd
2920
	 inc   byte[REDRAW_BACKGROUND]
2959
	 inc   byte[REDRAW_BACKGROUND]
2921
 
2960
 
2922
 
2961
 
2923
       newdw8:
2962
       newdw8:
2924
       nobgrd:
2963
       nobgrd:
2925
 
2964
 
2926
	 mov   [eax + WDATA.fl_redraw],byte 1	 ; mark as redraw
2965
	 mov   [eax + WDATA.fl_redraw],byte 1	 ; mark as redraw
2927
 
2966
 
2928
       ricino:
2967
       ricino:
2929
 
2968
 
2930
       not_this_task:
2969
       not_this_task:
2931
 
2970
 
2932
	 pop   ecx
2971
	 pop   ecx
2933
 
2972
 
2934
	 cmp   ecx,[TASK_COUNT]
2973
	 cmp   ecx,[TASK_COUNT]
2935
	 jle   newdw2
2974
	 jle   newdw2
2936
 
2975
 
2937
	 pop  eax
2976
	 pop  eax
2938
	 popad
2977
	 popad
2939
 
2978
 
2940
	 ret
2979
	 ret
2941
 
2980
 
2942
calculatebackground:   ; background
2981
calculatebackground:   ; background
2943
	mov   edi, [_WinMapAddress]		   ; set os to use all pixels
2982
	mov   edi, [_WinMapAddress]		   ; set os to use all pixels
2944
	mov   eax, 0x01010101
2983
	mov   eax, 0x01010101
2945
	mov   ecx, [_WinMapSize]
2984
	mov   ecx, [_WinMapSize]
2946
	shr   ecx, 2
2985
	shr   ecx, 2
2947
	rep   stosd
2986
	rep   stosd
2948
 
2987
 
2949
	mov   byte[REDRAW_BACKGROUND], 0	      ; do not draw background!
2988
	mov   byte[REDRAW_BACKGROUND], 0	      ; do not draw background!
2950
	mov   byte[BACKGROUND_CHANGED], 0
2989
	mov   byte[BACKGROUND_CHANGED], 0
2951
 
2990
 
2952
	ret
2991
	ret
2953
 
2992
 
2954
uglobal
2993
uglobal
2955
  imax	  dd 0x0
2994
  imax	  dd 0x0
2956
endg
2995
endg
2957
 
2996
 
2958
delay_ms:     ; delay in 1/1000 sec
2997
delay_ms:     ; delay in 1/1000 sec
2959
	push  eax
2998
	push  eax
2960
	push  ecx
2999
	push  ecx
2961
 
3000
 
2962
	mov   ecx,esi
3001
	mov   ecx,esi
2963
	; 
3002
	; 
2964
	imul  ecx, 33941
3003
	imul  ecx, 33941
2965
	shr   ecx, 9
3004
	shr   ecx, 9
2966
	; 
3005
	; 
2967
 
3006
 
2968
	in    al,0x61
3007
	in    al,0x61
2969
	and   al,0x10
3008
	and   al,0x10
2970
	mov   ah,al
3009
	mov   ah,al
2971
	cld
3010
	cld
2972
 
3011
 
2973
 cnt1:	in    al,0x61
3012
 cnt1:	in    al,0x61
2974
	and   al,0x10
3013
	and   al,0x10
2975
	cmp   al,ah
3014
	cmp   al,ah
2976
	jz    cnt1
3015
	jz    cnt1
2977
 
3016
 
2978
	mov   ah,al
3017
	mov   ah,al
2979
	loop  cnt1
3018
	loop  cnt1
2980
 
3019
 
2981
	pop   ecx
3020
	pop   ecx
2982
	pop   eax
3021
	pop   eax
2983
 
3022
 
2984
	ret
3023
	ret
2985
 
3024
 
2986
set_app_param:
3025
set_app_param:
2987
	mov	edi, [TASK_BASE]
3026
	mov	edi, [TASK_BASE]
2988
	mov	eax, [edi + TASKDATA.event_mask]
3027
	mov	eax, [edi + TASKDATA.event_mask]
2989
	mov	[edi + TASKDATA.event_mask], ebx
3028
	mov	[edi + TASKDATA.event_mask], ebx
2990
	mov	[esp+32], eax
3029
	mov	[esp+32], eax
2991
	ret
3030
	ret
2992
 
3031
 
2993
delay_hs:     ; delay in 1/100 secs
3032
delay_hs:     ; delay in 1/100 secs
2994
; ebx = delay time
3033
; ebx = delay time
2995
	push  ecx
3034
	push  ecx
2996
	push  edx
3035
	push  edx
2997
 
3036
 
2998
	mov   edx,[timer_ticks]
3037
	mov   edx,[timer_ticks]
2999
 
3038
 
3000
      newtic:
3039
      newtic:
3001
	mov   ecx,[timer_ticks]
3040
	mov   ecx,[timer_ticks]
3002
	sub   ecx,edx
3041
	sub   ecx,edx
3003
	cmp   ecx,ebx
3042
	cmp   ecx,ebx
3004
	jae   zerodelay
3043
	jae   zerodelay
3005
 
3044
 
3006
	call  change_task
3045
	call  change_task
3007
 
3046
 
3008
	jmp   newtic
3047
	jmp   newtic
3009
 
3048
 
3010
      zerodelay:
3049
      zerodelay:
3011
	pop   edx
3050
	pop   edx
3012
	pop   ecx
3051
	pop   ecx
3013
 
3052
 
3014
	ret
3053
	ret
3015
 
3054
 
3016
align 16	;very often call this subrutine
3055
align 16	;very often call this subrutine
3017
memmove:       ; memory move in bytes
3056
memmove:       ; memory move in bytes
3018
; eax = from
3057
; eax = from
3019
; ebx = to
3058
; ebx = to
3020
; ecx = no of bytes
3059
; ecx = no of bytes
3021
    test ecx, ecx
3060
    test ecx, ecx
3022
    jle  .ret
3061
    jle  .ret
3023
 
3062
 
3024
    push esi edi ecx
3063
    push esi edi ecx
3025
 
3064
 
3026
    mov  edi, ebx
3065
    mov  edi, ebx
3027
    mov  esi, eax
3066
    mov  esi, eax
3028
 
3067
 
3029
    test ecx, not 11b
3068
    test ecx, not 11b
3030
    jz	 @f
3069
    jz	 @f
3031
 
3070
 
3032
    push ecx
3071
    push ecx
3033
    shr  ecx, 2
3072
    shr  ecx, 2
3034
    rep  movsd
3073
    rep  movsd
3035
    pop  ecx
3074
    pop  ecx
3036
    and  ecx, 11b
3075
    and  ecx, 11b
3037
    jz	 .finish
3076
    jz	 .finish
3038
  @@:
3077
  @@:
3039
    rep  movsb
3078
    rep  movsb
3040
 
3079
 
3041
  .finish:
3080
  .finish:
3042
    pop  ecx edi esi
3081
    pop  ecx edi esi
3043
  .ret:
3082
  .ret:
3044
    ret
3083
    ret
3045
 
3084
 
3046
 
3085
 
3047
align 4
3086
align 4
3048
 
3087
 
3049
sys_programirq:
3088
sys_programirq:
3050
	; removed
3089
	; removed
3051
    mov   dword [esp+32], 1	; operation failed
3090
    mov   dword [esp+32], 1	; operation failed
3052
    ret
3091
    ret
3053
 
3092
 
3054
 
3093
 
3055
align 4
3094
align 4
3056
 
3095
 
3057
get_irq_data:
3096
get_irq_data:
3058
	; removed
3097
	; removed
3059
     mov   dword [esp+32], -1
3098
     mov   dword [esp+32], -1
3060
     ret
3099
     ret
3061
 
3100
 
3062
 
3101
 
3063
set_io_access_rights:
3102
set_io_access_rights:
3064
	;removed
3103
	;removed
3065
     ret
3104
     ret
3066
 
3105
 
3067
r_f_port_area:
3106
r_f_port_area:
3068
	; removed; always returns 0
3107
	; removed; always returns 0
3069
     xor   eax, eax
3108
     xor   eax, eax
3070
     ret
3109
     ret
3071
 
3110
 
3072
 
3111
 
3073
reserve_free_irq:
3112
reserve_free_irq:
3074
     xor   esi, esi
3113
     xor   esi, esi
3075
     inc   esi
3114
     inc   esi
3076
     cmp   ecx, 16
3115
     cmp   ecx, 16
3077
     jae   ril1
3116
     jae   ril1
3078
 
3117
 
3079
     push  ecx
3118
     push  ecx
3080
     lea   ecx, [irq_owner + 4 * ecx]
3119
     lea   ecx, [irq_owner + 4 * ecx]
3081
     mov   edx, [ecx]
3120
     mov   edx, [ecx]
3082
     mov   eax, [TASK_BASE]
3121
     mov   eax, [TASK_BASE]
3083
     mov   edi, [eax + TASKDATA.pid]
3122
     mov   edi, [eax + TASKDATA.pid]
3084
     pop   eax
3123
     pop   eax
3085
     dec   ebx
3124
     dec   ebx
3086
     jnz   reserve_irq
3125
     jnz   reserve_irq
3087
 
3126
 
3088
     cmp   edx, edi
3127
     cmp   edx, edi
3089
     jne   ril1
3128
     jne   ril1
3090
     dec   esi
3129
     dec   esi
3091
     mov   [ecx], esi
3130
     mov   [ecx], esi
3092
 
3131
 
3093
     jmp   ril1
3132
     jmp   ril1
3094
 
3133
 
3095
  reserve_irq:
3134
  reserve_irq:
3096
     cmp   dword [ecx], 0
3135
     cmp   dword [ecx], 0
3097
     jne   ril1
3136
     jne   ril1
3098
 
3137
 
3099
     mov   ebx, [f_irqs + 4 * eax]
3138
     mov   ebx, [f_irqs + 4 * eax]
3100
 
3139
 
3101
     stdcall attach_int_handler, eax, ebx, dword 0
3140
     stdcall attach_int_handler, eax, ebx, dword 0
3102
 
3141
 
3103
     mov   [ecx], edi
3142
     mov   [ecx], edi
3104
 
3143
 
3105
     dec   esi
3144
     dec   esi
3106
   ril1:
3145
   ril1:
3107
     mov   [esp+32], esi ; return in eax
3146
     mov   [esp+32], esi ; return in eax
3108
     ret
3147
     ret
3109
 
3148
 
3110
iglobal
3149
iglobal
3111
f_irqs:
3150
f_irqs:
3112
     dd 0x0
3151
     dd 0x0
3113
     dd 0x0
3152
     dd 0x0
3114
     dd p_irq2
3153
     dd p_irq2
3115
     dd p_irq3
3154
     dd p_irq3
3116
     dd p_irq4
3155
     dd p_irq4
3117
     dd p_irq5
3156
     dd p_irq5
3118
     dd p_irq6
3157
     dd p_irq6
3119
     dd p_irq7
3158
     dd p_irq7
3120
     dd p_irq8
3159
     dd p_irq8
3121
     dd p_irq9
3160
     dd p_irq9
3122
     dd p_irq10
3161
     dd p_irq10
3123
     dd p_irq11
3162
     dd p_irq11
3124
     dd 0x0
3163
     dd 0x0
3125
     dd 0x0
3164
     dd 0x0
3126
     dd p_irq14
3165
     dd p_irq14
3127
     dd p_irq15
3166
     dd p_irq15
3128
 
3167
 
3129
endg
3168
endg
3130
 
3169
 
3131
drawbackground:
3170
drawbackground:
3132
;       inc   [mouse_pause]
3171
;       inc   [mouse_pause]
3133
;       call  draw_background    ; graph32.inc
3172
;       call  draw_background    ; graph32.inc
3134
;       dec   [mouse_pause]
3173
;       dec   [mouse_pause]
3135
;       call   [draw_pointer]
3174
;       call   [draw_pointer]
3136
;       ret
3175
;       ret
3137
       inc   [mouse_pause]
3176
       inc   [mouse_pause]
3138
       cmp   [BgrDrawMode],dword 1
3177
       cmp   [BgrDrawMode],dword 1
3139
       jne   .bgrstr
3178
       jne   .bgrstr
3140
       call  vesa20_drawbackground_tiled
3179
       call  vesa20_drawbackground_tiled
3141
	 jmp  @f
3180
	 jmp  @f
3142
.bgrstr:
3181
.bgrstr:
3143
       call  vesa20_drawbackground_stretch
3182
       call  vesa20_drawbackground_stretch
3144
@@:
3183
@@:
3145
       dec   [mouse_pause]
3184
       dec   [mouse_pause]
3146
       call   [draw_pointer]
3185
       call   [draw_pointer]
3147
       ret
3186
       ret
3148
 
3187
 
3149
; ====================================================================
3188
; ====================================================================
3150
if 0
3189
if 0
3151
; the new GFX sys
3190
; the new GFX sys
3152
 
3191
 
3153
align 4
3192
align 4
3154
syscall_putimage:			; PutImage = SysFn07
3193
syscall_putimage:			; PutImage = SysFn07
3155
sys_putimage:
3194
sys_putimage:
3156
     test  ecx,0x80008000		; ecx = { SizeX | SizeY }
3195
     test  ecx,0x80008000		; ecx = { SizeX | SizeY }
3157
     jnz   .exit			; edx = { OrigX | OrigY }
3196
     jnz   .exit			; edx = { OrigX | OrigY }
3158
     test  ecx,0x0000FFFF		; ebx points to the 24bpp-image
3197
     test  ecx,0x0000FFFF		; ebx points to the 24bpp-image
3159
     jz    .exit
3198
     jz    .exit
3160
     test  ecx,0xFFFF0000
3199
     test  ecx,0xFFFF0000
3161
     jnz   @f
3200
     jnz   @f
3162
  .exit:
3201
  .exit:
3163
     ret
3202
     ret
3164
 @@:
3203
 @@:
3165
	push	edi
3204
	push	edi
3166
	mov	edi,[current_slot]
3205
	mov	edi,[current_slot]
3167
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
3206
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
3168
	rol	edx,16
3207
	rol	edx,16
3169
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
3208
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
3170
	pop	edi
3209
	pop	edi
3171
	rol	edx,16
3210
	rol	edx,16
3172
  .forced:				; called from gui/skincode.inc [215]
3211
  .forced:				; called from gui/skincode.inc [215]
3173
	push	esi
3212
	push	esi
3174
	mov	esi, ecx
3213
	mov	esi, ecx
3175
	shr	esi, 16 		; SizeX
3214
	shr	esi, 16 		; SizeX
3176
	lea	esi, [esi*2+esi]	; 3 bytes per pixel
3215
	lea	esi, [esi*2+esi]	; 3 bytes per pixel
3177
	mov	[img_buf_line_size], esi
3216
	mov	[img_buf_line_size], esi
3178
	mov	[img_draw_core_fn], draw_core_24bpp
3217
	mov	[img_draw_core_fn], draw_core_24bpp
3179
	mov	[img_draw_edge_fn], draw_edge_24bpp
3218
	mov	[img_draw_edge_fn], draw_edge_24bpp
3180
	mov	[img_bytes_per_pix], 3
3219
	mov	[img_bytes_per_pix], 3
3181
	pop	esi
3220
	pop	esi
3182
 
3221
 
3183
sys_putimage_bpp:			; only called from sys_putimage_palette
3222
sys_putimage_bpp:			; only called from sys_putimage_palette
3184
	inc	[mouse_pause]
3223
	inc	[mouse_pause]
3185
	call	_putimage
3224
	call	_putimage
3186
	dec	[mouse_pause]
3225
	dec	[mouse_pause]
3187
	call	[draw_pointer]
3226
	call	[draw_pointer]
3188
	ret
3227
	ret
3189
 
3228
 
3190
 
3229
 
3191
align 4
3230
align 4
3192
sys_putimage_palette:			; sysFn 65
3231
sys_putimage_palette:			; sysFn 65
3193
; ebx = pointer to image
3232
; ebx = pointer to image
3194
; ecx = [xsize]*65536 + [ysize]
3233
; ecx = [xsize]*65536 + [ysize]
3195
; edx = [xstart]*65536 + [ystart]
3234
; edx = [xstart]*65536 + [ystart]
3196
; esi = number of bits per pixel, must be 1, 8, 24 or 32
3235
; esi = number of bits per pixel, must be 1, 8, 24 or 32
3197
; edi = pointer to palette
3236
; edi = pointer to palette
3198
; ebp = line offset
3237
; ebp = line offset
3199
	mov	eax, [CURRENT_TASK]
3238
	mov	eax, [CURRENT_TASK]
3200
	shl	eax, 8
3239
	shl	eax, 8
3201
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
3240
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
3202
	rol	edx, 16
3241
	rol	edx, 16
3203
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
3242
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
3204
	rol	edx, 16
3243
	rol	edx, 16
3205
.forced:
3244
.forced:
3206
	push	eax
3245
	push	eax
3207
	push	esi
3246
	push	esi
3208
	mov	[img_palette], edi
3247
	mov	[img_palette], edi
3209
	mov	eax, esi
3248
	mov	eax, esi
3210
	cmp	eax, 32 		;>32bpp (stupid call)
3249
	cmp	eax, 32 		;>32bpp (stupid call)
3211
	ja	.exit
3250
	ja	.exit
3212
	shr	al, 3			; 0=1bpp or solid color
3251
	shr	al, 3			; 0=1bpp or solid color
3213
	mov	[img_bytes_per_pix], eax
3252
	mov	[img_bytes_per_pix], eax
3214
	mov	esi, [eax*4 + img_core_proc_0]
3253
	mov	esi, [eax*4 + img_core_proc_0]
3215
	mov	[img_draw_core_fn], esi
3254
	mov	[img_draw_core_fn], esi
3216
	mov	esi, [eax*4 + img_edge_proc_0]
3255
	mov	esi, [eax*4 + img_edge_proc_0]
3217
	mov	[img_draw_edge_fn], esi
3256
	mov	[img_draw_edge_fn], esi
3218
	mov	esi, ecx
3257
	mov	esi, ecx
3219
	shr	esi, 16 		; esi = SizeX
3258
	shr	esi, 16 		; esi = SizeX
3220
	imul	esi, eax
3259
	imul	esi, eax
3221
	or	al, al
3260
	or	al, al
3222
	jnz	.done
3261
	jnz	.done
3223
	mov	eax, [esp]		; bits per pixel
3262
	mov	eax, [esp]		; bits per pixel
3224
	or	al, al
3263
	or	al, al
3225
	jz	.done
3264
	jz	.done
3226
.1bpp:
3265
.1bpp:
3227
	add	esi, 7
3266
	add	esi, 7
3228
	shr	esi, 3			; 8 pixels per byte
3267
	shr	esi, 3			; 8 pixels per byte
3229
	mov	[img_draw_edge_fn], draw_edge_1bpp
3268
	mov	[img_draw_edge_fn], draw_edge_1bpp
3230
	mov	[img_draw_core_fn], draw_core_1bpp
3269
	mov	[img_draw_core_fn], draw_core_1bpp
3231
.done:
3270
.done:
3232
	add	esi, ebp		; + line offset
3271
	add	esi, ebp		; + line offset
3233
	mov	[img_buf_line_size], esi
3272
	mov	[img_buf_line_size], esi
3234
	pop	esi
3273
	pop	esi
3235
	pop	eax
3274
	pop	eax
3236
	jmp	sys_putimage_bpp
3275
	jmp	sys_putimage_bpp
3237
.exit:
3276
.exit:
3238
	ret
3277
	ret
3239
 
3278
 
3240
align 4
3279
align 4
3241
img_core_proc_0 	dd	draw_core_0bpp
3280
img_core_proc_0 	dd	draw_core_0bpp
3242
img_core_proc_1 	dd	draw_core_8bpp
3281
img_core_proc_1 	dd	draw_core_8bpp
3243
img_core_proc_2 	dd	draw_core_16bpp
3282
img_core_proc_2 	dd	draw_core_16bpp
3244
img_core_proc_3 	dd	draw_core_24bpp
3283
img_core_proc_3 	dd	draw_core_24bpp
3245
img_core_proc_4 	dd	draw_core_32bpp
3284
img_core_proc_4 	dd	draw_core_32bpp
3246
 
3285
 
3247
img_edge_proc_0 	dd	draw_edge_0bpp
3286
img_edge_proc_0 	dd	draw_edge_0bpp
3248
img_edge_proc_1 	dd	draw_edge_8bpp
3287
img_edge_proc_1 	dd	draw_edge_8bpp
3249
img_edge_proc_2 	dd	draw_edge_16bpp
3288
img_edge_proc_2 	dd	draw_edge_16bpp
3250
img_edge_proc_3 	dd	draw_edge_24bpp
3289
img_edge_proc_3 	dd	draw_edge_24bpp
3251
img_edge_proc_4 	dd	draw_edge_32bpp
3290
img_edge_proc_4 	dd	draw_edge_32bpp
3252
 
3291
 
3253
end if
3292
end if
3254
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
3293
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
3255
; the old GFX sys
3294
; the old GFX sys
3256
align 4
3295
align 4
3257
 
3296
 
3258
syscall_putimage:			; PutImage
3297
syscall_putimage:			; PutImage
3259
sys_putimage:
3298
sys_putimage:
3260
     test  ecx,0x80008000
3299
     test  ecx,0x80008000
3261
     jnz   .exit
3300
     jnz   .exit
3262
     test  ecx,0x0000FFFF
3301
     test  ecx,0x0000FFFF
3263
     jz    .exit
3302
     jz    .exit
3264
     test  ecx,0xFFFF0000
3303
     test  ecx,0xFFFF0000
3265
     jnz   @f
3304
     jnz   @f
3266
  .exit:
3305
  .exit:
3267
     ret
3306
     ret
3268
 @@:
3307
 @@:
3269
	mov	edi,[current_slot]
3308
	mov	edi,[current_slot]
3270
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
3309
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
3271
	rol	edx,16
3310
	rol	edx,16
3272
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
3311
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
3273
	rol	edx,16
3312
	rol	edx,16
3274
  .forced:
3313
  .forced:
3275
	push	ebp esi 0
3314
	push	ebp esi 0
3276
	mov	ebp, putimage_get24bpp
3315
	mov	ebp, putimage_get24bpp
3277
	mov	esi, putimage_init24bpp
3316
	mov	esi, putimage_init24bpp
3278
sys_putimage_bpp:
3317
sys_putimage_bpp:
3279
;        cmp     [SCR_MODE], word 0x12
3318
;        cmp     [SCR_MODE], word 0x12
3280
;        jz      @f   ;.doit
3319
;        jz      @f   ;.doit
3281
;        mov     eax, vesa12_putimage
3320
;        mov     eax, vesa12_putimage
3282
;        cmp     [SCR_MODE], word 0100000000000000b
3321
;        cmp     [SCR_MODE], word 0100000000000000b
3283
;        jae     @f
3322
;        jae     @f
3284
;        cmp     [SCR_MODE], word 0x13
3323
;        cmp     [SCR_MODE], word 0x13
3285
;        jnz     .doit
3324
;        jnz     .doit
3286
;@@:
3325
;@@:
3287
	mov	eax, vesa20_putimage
3326
	mov	eax, vesa20_putimage
3288
.doit:
3327
.doit:
3289
	inc	[mouse_pause]
3328
	inc	[mouse_pause]
3290
	call	eax
3329
	call	eax
3291
	dec	[mouse_pause]
3330
	dec	[mouse_pause]
3292
	pop	ebp esi ebp
3331
	pop	ebp esi ebp
3293
	jmp	[draw_pointer]
3332
	jmp	[draw_pointer]
3294
align 4
3333
align 4
3295
sys_putimage_palette:
3334
sys_putimage_palette:
3296
; ebx = pointer to image
3335
; ebx = pointer to image
3297
; ecx = [xsize]*65536 + [ysize]
3336
; ecx = [xsize]*65536 + [ysize]
3298
; edx = [xstart]*65536 + [ystart]
3337
; edx = [xstart]*65536 + [ystart]
3299
; esi = number of bits per pixel, must be 8, 24 or 32
3338
; esi = number of bits per pixel, must be 8, 24 or 32
3300
; edi = pointer to palette
3339
; edi = pointer to palette
3301
; ebp = row delta
3340
; ebp = row delta
3302
	mov	eax, [CURRENT_TASK]
3341
	mov	eax, [CURRENT_TASK]
3303
	shl	eax, 8
3342
	shl	eax, 8
3304
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
3343
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
3305
	rol	edx, 16
3344
	rol	edx, 16
3306
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
3345
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
3307
	rol	edx, 16
3346
	rol	edx, 16
3308
.forced:
3347
.forced:
3309
	cmp	esi, 1
3348
	cmp	esi, 1
3310
	jnz	@f
3349
	jnz	@f
3311
	push	edi
3350
	push	edi
3312
	mov	eax, [edi+4]
3351
	mov	eax, [edi+4]
3313
	sub	eax, [edi]
3352
	sub	eax, [edi]
3314
	push	eax
3353
	push	eax
3315
	push	dword [edi]
3354
	push	dword [edi]
3316
	push	0ffffff80h
3355
	push	0ffffff80h
3317
	mov	edi, esp
3356
	mov	edi, esp
3318
	call	put_mono_image
3357
	call	put_mono_image
3319
	add	esp, 12
3358
	add	esp, 12
3320
	pop	edi
3359
	pop	edi
3321
	ret
3360
	ret
3322
@@:
3361
@@:
3323
	cmp	esi, 2
3362
	cmp	esi, 2
3324
	jnz	@f
3363
	jnz	@f
3325
	push	edi
3364
	push	edi
3326
	push	0ffffff80h
3365
	push	0ffffff80h
3327
	mov	edi, esp
3366
	mov	edi, esp
3328
	call	put_2bit_image
3367
	call	put_2bit_image
3329
	pop	eax
3368
	pop	eax
3330
	pop	edi
3369
	pop	edi
3331
	ret
3370
	ret
3332
@@:
3371
@@:
3333
	cmp	esi, 4
3372
	cmp	esi, 4
3334
	jnz	@f
3373
	jnz	@f
3335
	push	edi
3374
	push	edi
3336
	push	0ffffff80h
3375
	push	0ffffff80h
3337
	mov	edi, esp
3376
	mov	edi, esp
3338
	call	put_4bit_image
3377
	call	put_4bit_image
3339
	pop	eax
3378
	pop	eax
3340
	pop	edi
3379
	pop	edi
3341
	ret
3380
	ret
3342
@@:
3381
@@:
3343
	push	ebp esi ebp
3382
	push	ebp esi ebp
3344
	cmp	esi, 8
3383
	cmp	esi, 8
3345
	jnz	@f
3384
	jnz	@f
3346
	mov	ebp, putimage_get8bpp
3385
	mov	ebp, putimage_get8bpp
3347
	mov	esi, putimage_init8bpp
3386
	mov	esi, putimage_init8bpp
3348
	jmp	sys_putimage_bpp
3387
	jmp	sys_putimage_bpp
3349
@@:
3388
@@:
3350
	cmp	esi, 15
3389
	cmp	esi, 15
3351
	jnz	@f
3390
	jnz	@f
3352
	mov	ebp, putimage_get15bpp
3391
	mov	ebp, putimage_get15bpp
3353
	mov	esi, putimage_init15bpp
3392
	mov	esi, putimage_init15bpp
3354
	jmp	sys_putimage_bpp
3393
	jmp	sys_putimage_bpp
3355
@@:
3394
@@:
3356
	cmp	esi, 16
3395
	cmp	esi, 16
3357
	jnz	@f
3396
	jnz	@f
3358
	mov	ebp, putimage_get16bpp
3397
	mov	ebp, putimage_get16bpp
3359
	mov	esi, putimage_init16bpp
3398
	mov	esi, putimage_init16bpp
3360
	jmp	sys_putimage_bpp
3399
	jmp	sys_putimage_bpp
3361
@@:
3400
@@:
3362
	cmp	esi, 24
3401
	cmp	esi, 24
3363
	jnz	@f
3402
	jnz	@f
3364
	mov	ebp, putimage_get24bpp
3403
	mov	ebp, putimage_get24bpp
3365
	mov	esi, putimage_init24bpp
3404
	mov	esi, putimage_init24bpp
3366
	jmp	sys_putimage_bpp
3405
	jmp	sys_putimage_bpp
3367
@@:
3406
@@:
3368
	cmp	esi, 32
3407
	cmp	esi, 32
3369
	jnz	@f
3408
	jnz	@f
3370
	mov	ebp, putimage_get32bpp
3409
	mov	ebp, putimage_get32bpp
3371
	mov	esi, putimage_init32bpp
3410
	mov	esi, putimage_init32bpp
3372
	jmp	sys_putimage_bpp
3411
	jmp	sys_putimage_bpp
3373
@@:
3412
@@:
3374
	pop	ebp esi ebp
3413
	pop	ebp esi ebp
3375
	ret
3414
	ret
3376
 
3415
 
3377
put_mono_image:
3416
put_mono_image:
3378
	push	ebp esi ebp
3417
	push	ebp esi ebp
3379
	mov	ebp, putimage_get1bpp
3418
	mov	ebp, putimage_get1bpp
3380
	mov	esi, putimage_init1bpp
3419
	mov	esi, putimage_init1bpp
3381
	jmp	sys_putimage_bpp
3420
	jmp	sys_putimage_bpp
3382
put_2bit_image:
3421
put_2bit_image:
3383
	push	ebp esi ebp
3422
	push	ebp esi ebp
3384
	mov	ebp, putimage_get2bpp
3423
	mov	ebp, putimage_get2bpp
3385
	mov	esi, putimage_init2bpp
3424
	mov	esi, putimage_init2bpp
3386
	jmp	sys_putimage_bpp
3425
	jmp	sys_putimage_bpp
3387
put_4bit_image:
3426
put_4bit_image:
3388
	push	ebp esi ebp
3427
	push	ebp esi ebp
3389
	mov	ebp, putimage_get4bpp
3428
	mov	ebp, putimage_get4bpp
3390
	mov	esi, putimage_init4bpp
3429
	mov	esi, putimage_init4bpp
3391
	jmp	sys_putimage_bpp
3430
	jmp	sys_putimage_bpp
3392
 
3431
 
3393
putimage_init24bpp:
3432
putimage_init24bpp:
3394
	lea	eax, [eax*3]
3433
	lea	eax, [eax*3]
3395
putimage_init8bpp:
3434
putimage_init8bpp:
3396
	ret
3435
	ret
3397
 
3436
 
3398
align 16
3437
align 16
3399
putimage_get24bpp:
3438
putimage_get24bpp:
3400
	movzx	eax, byte [esi+2]
3439
	movzx	eax, byte [esi+2]
3401
	shl	eax, 16
3440
	shl	eax, 16
3402
	mov	ax, [esi]
3441
	mov	ax, [esi]
3403
	add	esi, 3
3442
	add	esi, 3
3404
	ret	4
3443
	ret	4
3405
align 16
3444
align 16
3406
putimage_get8bpp:
3445
putimage_get8bpp:
3407
	movzx	eax, byte [esi]
3446
	movzx	eax, byte [esi]
3408
	push	edx
3447
	push	edx
3409
	mov	edx, [esp+8]
3448
	mov	edx, [esp+8]
3410
	mov	eax, [edx+eax*4]
3449
	mov	eax, [edx+eax*4]
3411
	pop	edx
3450
	pop	edx
3412
	inc	esi
3451
	inc	esi
3413
	ret	4
3452
	ret	4
3414
 
3453
 
3415
putimage_init1bpp:
3454
putimage_init1bpp:
3416
	add	eax, ecx
3455
	add	eax, ecx
3417
	push	ecx
3456
	push	ecx
3418
	add	eax, 7
3457
	add	eax, 7
3419
	add	ecx, 7
3458
	add	ecx, 7
3420
	shr	eax, 3
3459
	shr	eax, 3
3421
	shr	ecx, 3
3460
	shr	ecx, 3
3422
	sub	eax, ecx
3461
	sub	eax, ecx
3423
	pop	ecx
3462
	pop	ecx
3424
	ret
3463
	ret
3425
align 16
3464
align 16
3426
putimage_get1bpp:
3465
putimage_get1bpp:
3427
	push	edx
3466
	push	edx
3428
	mov	edx, [esp+8]
3467
	mov	edx, [esp+8]
3429
	mov	al, [edx]
3468
	mov	al, [edx]
3430
	add	al, al
3469
	add	al, al
3431
	jnz	@f
3470
	jnz	@f
3432
	lodsb
3471
	lodsb
3433
	adc	al, al
3472
	adc	al, al
3434
@@:
3473
@@:
3435
	mov	[edx], al
3474
	mov	[edx], al
3436
	sbb	eax, eax
3475
	sbb	eax, eax
3437
	and	eax, [edx+8]
3476
	and	eax, [edx+8]
3438
	add	eax, [edx+4]
3477
	add	eax, [edx+4]
3439
	pop	edx
3478
	pop	edx
3440
	ret	4
3479
	ret	4
3441
 
3480
 
3442
putimage_init2bpp:
3481
putimage_init2bpp:
3443
	add	eax, ecx
3482
	add	eax, ecx
3444
	push	ecx
3483
	push	ecx
3445
	add	ecx, 3
3484
	add	ecx, 3
3446
	add	eax, 3
3485
	add	eax, 3
3447
	shr	ecx, 2
3486
	shr	ecx, 2
3448
	shr	eax, 2
3487
	shr	eax, 2
3449
	sub	eax, ecx
3488
	sub	eax, ecx
3450
	pop	ecx
3489
	pop	ecx
3451
	ret
3490
	ret
3452
align 16
3491
align 16
3453
putimage_get2bpp:
3492
putimage_get2bpp:
3454
	push	edx
3493
	push	edx
3455
	mov	edx, [esp+8]
3494
	mov	edx, [esp+8]
3456
	mov	al, [edx]
3495
	mov	al, [edx]
3457
	mov	ah, al
3496
	mov	ah, al
3458
	shr	al, 6
3497
	shr	al, 6
3459
	shl	ah, 2
3498
	shl	ah, 2
3460
	jnz	.nonewbyte
3499
	jnz	.nonewbyte
3461
	lodsb
3500
	lodsb
3462
	mov	ah, al
3501
	mov	ah, al
3463
	shr	al, 6
3502
	shr	al, 6
3464
	shl	ah, 2
3503
	shl	ah, 2
3465
	add	ah, 1
3504
	add	ah, 1
3466
.nonewbyte:
3505
.nonewbyte:
3467
	mov	[edx], ah
3506
	mov	[edx], ah
3468
	mov	edx, [edx+4]
3507
	mov	edx, [edx+4]
3469
	movzx	eax, al
3508
	movzx	eax, al
3470
	mov	eax, [edx+eax*4]
3509
	mov	eax, [edx+eax*4]
3471
	pop	edx
3510
	pop	edx
3472
	ret	4
3511
	ret	4
3473
 
3512
 
3474
putimage_init4bpp:
3513
putimage_init4bpp:
3475
	add	eax, ecx
3514
	add	eax, ecx
3476
	push	ecx
3515
	push	ecx
3477
	add	ecx, 1
3516
	add	ecx, 1
3478
	add	eax, 1
3517
	add	eax, 1
3479
	shr	ecx, 1
3518
	shr	ecx, 1
3480
	shr	eax, 1
3519
	shr	eax, 1
3481
	sub	eax, ecx
3520
	sub	eax, ecx
3482
	pop	ecx
3521
	pop	ecx
3483
	ret
3522
	ret
3484
align 16
3523
align 16
3485
putimage_get4bpp:
3524
putimage_get4bpp:
3486
	push	edx
3525
	push	edx
3487
	mov	edx, [esp+8]
3526
	mov	edx, [esp+8]
3488
	add	byte [edx], 80h
3527
	add	byte [edx], 80h
3489
	jc	@f
3528
	jc	@f
3490
	movzx	eax, byte [edx+1]
3529
	movzx	eax, byte [edx+1]
3491
	mov	edx, [edx+4]
3530
	mov	edx, [edx+4]
3492
	and	eax, 0x0F
3531
	and	eax, 0x0F
3493
	mov	eax, [edx+eax*4]
3532
	mov	eax, [edx+eax*4]
3494
	pop	edx
3533
	pop	edx
3495
	ret	4
3534
	ret	4
3496
@@:
3535
@@:
3497
	movzx	eax, byte [esi]
3536
	movzx	eax, byte [esi]
3498
	add	esi, 1
3537
	add	esi, 1
3499
	mov	[edx+1], al
3538
	mov	[edx+1], al
3500
	shr	eax, 4
3539
	shr	eax, 4
3501
	mov	edx, [edx+4]
3540
	mov	edx, [edx+4]
3502
	mov	eax, [edx+eax*4]
3541
	mov	eax, [edx+eax*4]
3503
	pop	edx
3542
	pop	edx
3504
	ret	4
3543
	ret	4
3505
 
3544
 
3506
putimage_init32bpp:
3545
putimage_init32bpp:
3507
	shl	eax, 2
3546
	shl	eax, 2
3508
	ret
3547
	ret
3509
align 16
3548
align 16
3510
putimage_get32bpp:
3549
putimage_get32bpp:
3511
	lodsd
3550
	lodsd
3512
	ret	4
3551
	ret	4
3513
 
3552
 
3514
putimage_init15bpp:
3553
putimage_init15bpp:
3515
putimage_init16bpp:
3554
putimage_init16bpp:
3516
	add	eax, eax
3555
	add	eax, eax
3517
	ret
3556
	ret
3518
align 16
3557
align 16
3519
putimage_get15bpp:
3558
putimage_get15bpp:
3520
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
3559
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
3521
	push	ecx edx
3560
	push	ecx edx
3522
	movzx	eax, word [esi]
3561
	movzx	eax, word [esi]
3523
	add	esi, 2
3562
	add	esi, 2
3524
	mov	ecx, eax
3563
	mov	ecx, eax
3525
	mov	edx, eax
3564
	mov	edx, eax
3526
	and	eax, 0x1F
3565
	and	eax, 0x1F
3527
	and	ecx, 0x1F shl 5
3566
	and	ecx, 0x1F shl 5
3528
	and	edx, 0x1F shl 10
3567
	and	edx, 0x1F shl 10
3529
	shl	eax, 3
3568
	shl	eax, 3
3530
	shl	ecx, 6
3569
	shl	ecx, 6
3531
	shl	edx, 9
3570
	shl	edx, 9
3532
	or	eax, ecx
3571
	or	eax, ecx
3533
	or	eax, edx
3572
	or	eax, edx
3534
	pop	edx ecx
3573
	pop	edx ecx
3535
	ret	4
3574
	ret	4
3536
 
3575
 
3537
align 16
3576
align 16
3538
putimage_get16bpp:
3577
putimage_get16bpp:
3539
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
3578
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
3540
	push	ecx edx
3579
	push	ecx edx
3541
	movzx	eax, word [esi]
3580
	movzx	eax, word [esi]
3542
	add	esi, 2
3581
	add	esi, 2
3543
	mov	ecx, eax
3582
	mov	ecx, eax
3544
	mov	edx, eax
3583
	mov	edx, eax
3545
	and	eax, 0x1F
3584
	and	eax, 0x1F
3546
	and	ecx, 0x3F shl 5
3585
	and	ecx, 0x3F shl 5
3547
	and	edx, 0x1F shl 11
3586
	and	edx, 0x1F shl 11
3548
	shl	eax, 3
3587
	shl	eax, 3
3549
	shl	ecx, 5
3588
	shl	ecx, 5
3550
	shl	edx, 8
3589
	shl	edx, 8
3551
	or	eax, ecx
3590
	or	eax, ecx
3552
	or	eax, edx
3591
	or	eax, edx
3553
	pop	edx ecx
3592
	pop	edx ecx
3554
	ret	4
3593
	ret	4
3555
 
3594
 
3556
 
3595
 
3557
 
3596
 
3558
; ==================================================
3597
; ==================================================
3559
; eax x beginning
3598
; eax x beginning
3560
; ebx y beginning
3599
; ebx y beginning
3561
; ecx x end
3600
; ecx x end
3562
; edx y end
3601
; edx y end
3563
; edi color
3602
; edi color
3564
 
3603
 
3565
__sys_drawbar:
3604
__sys_drawbar:
3566
	mov	esi,[current_slot]
3605
	mov	esi,[current_slot]
3567
	add	eax,[esi+APPDATA.wnd_clientbox.left]
3606
	add	eax,[esi+APPDATA.wnd_clientbox.left]
3568
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
3607
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
3569
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
3608
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
3570
	add	edx,[esi+APPDATA.wnd_clientbox.top]
3609
	add	edx,[esi+APPDATA.wnd_clientbox.top]
3571
  .forced:
3610
  .forced:
3572
    inc   [mouse_pause]
3611
    inc   [mouse_pause]
3573
    call  vesa20_drawbar
3612
    call  vesa20_drawbar
3574
    dec   [mouse_pause]
3613
    dec   [mouse_pause]
3575
    jmp   [draw_pointer]
3614
    jmp   [draw_pointer]
3576
 
3615
 
3577
 
3616
 
3578
kb_read:
3617
kb_read:
3579
	push	ecx edx
3618
	push	ecx edx
3580
 
3619
 
3581
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3620
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3582
      kr_loop:
3621
      kr_loop:
3583
	in	al,0x64
3622
	in	al,0x64
3584
	test	al,1
3623
	test	al,1
3585
	jnz	kr_ready
3624
	jnz	kr_ready
3586
	loop	kr_loop
3625
	loop	kr_loop
3587
	mov	ah,1
3626
	mov	ah,1
3588
	jmp	kr_exit
3627
	jmp	kr_exit
3589
      kr_ready:
3628
      kr_ready:
3590
	push	ecx
3629
	push	ecx
3591
	mov	ecx,32
3630
	mov	ecx,32
3592
      kr_delay:
3631
      kr_delay:
3593
	loop	kr_delay
3632
	loop	kr_delay
3594
	pop	ecx
3633
	pop	ecx
3595
	in	al,0x60
3634
	in	al,0x60
3596
	xor	ah,ah
3635
	xor	ah,ah
3597
      kr_exit:
3636
      kr_exit:
3598
 
3637
 
3599
	pop	edx ecx
3638
	pop	edx ecx
3600
 
3639
 
3601
	ret
3640
	ret
3602
 
3641
 
3603
 
3642
 
3604
kb_write:
3643
kb_write:
3605
 
3644
 
3606
	push	ecx edx
3645
	push	ecx edx
3607
 
3646
 
3608
	mov	dl,al
3647
	mov	dl,al
3609
	in	al,0x60
3648
	in	al,0x60
3610
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3649
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3611
      kw_loop:
3650
      kw_loop:
3612
	in	al,0x64
3651
	in	al,0x64
3613
	test	al,2
3652
	test	al,2
3614
	jz	kw_ok
3653
	jz	kw_ok
3615
	loop	kw_loop
3654
	loop	kw_loop
3616
	mov	ah,1
3655
	mov	ah,1
3617
	jmp	kw_exit
3656
	jmp	kw_exit
3618
      kw_ok:
3657
      kw_ok:
3619
	mov	al,dl
3658
	mov	al,dl
3620
	out	0x60,al
3659
	out	0x60,al
3621
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3660
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3622
      kw_loop3:
3661
      kw_loop3:
3623
	in	al,0x64
3662
	in	al,0x64
3624
	test	al,2
3663
	test	al,2
3625
	jz	kw_ok3
3664
	jz	kw_ok3
3626
	loop	kw_loop3
3665
	loop	kw_loop3
3627
	mov	ah,1
3666
	mov	ah,1
3628
	jmp	kw_exit
3667
	jmp	kw_exit
3629
      kw_ok3:
3668
      kw_ok3:
3630
	mov	ah,8
3669
	mov	ah,8
3631
      kw_loop4:
3670
      kw_loop4:
3632
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3671
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3633
      kw_loop5:
3672
      kw_loop5:
3634
	in	al,0x64
3673
	in	al,0x64
3635
	test	al,1
3674
	test	al,1
3636
	jnz	kw_ok4
3675
	jnz	kw_ok4
3637
	loop	kw_loop5
3676
	loop	kw_loop5
3638
	dec	ah
3677
	dec	ah
3639
	jnz	kw_loop4
3678
	jnz	kw_loop4
3640
      kw_ok4:
3679
      kw_ok4:
3641
	xor	ah,ah
3680
	xor	ah,ah
3642
      kw_exit:
3681
      kw_exit:
3643
 
3682
 
3644
	pop	edx ecx
3683
	pop	edx ecx
3645
 
3684
 
3646
	ret
3685
	ret
3647
 
3686
 
3648
 
3687
 
3649
kb_cmd:
3688
kb_cmd:
3650
 
3689
 
3651
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3690
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3652
      c_wait:
3691
      c_wait:
3653
	in	al,0x64
3692
	in	al,0x64
3654
	test	al,2
3693
	test	al,2
3655
	jz	c_send
3694
	jz	c_send
3656
	loop	c_wait
3695
	loop	c_wait
3657
	jmp	c_error
3696
	jmp	c_error
3658
      c_send:
3697
      c_send:
3659
	mov	al,bl
3698
	mov	al,bl
3660
	out	0x64,al
3699
	out	0x64,al
3661
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3700
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
3662
      c_accept:
3701
      c_accept:
3663
	in	al,0x64
3702
	in	al,0x64
3664
	test	al,2
3703
	test	al,2
3665
	jz	c_ok
3704
	jz	c_ok
3666
	loop	c_accept
3705
	loop	c_accept
3667
      c_error:
3706
      c_error:
3668
	mov	ah,1
3707
	mov	ah,1
3669
	jmp	c_exit
3708
	jmp	c_exit
3670
      c_ok:
3709
      c_ok:
3671
	xor	ah,ah
3710
	xor	ah,ah
3672
      c_exit:
3711
      c_exit:
3673
	ret
3712
	ret
3674
 
3713
 
3675
 
3714
 
3676
rerouteirqs:
3715
rerouteirqs:
3677
 
3716
 
3678
	cli
3717
	cli
3679
 
3718
 
3680
	mov	al,0x11 	;  icw4, edge triggered
3719
	mov	al,0x11 	;  icw4, edge triggered
3681
	out	0x20,al
3720
	out	0x20,al
3682
	call	pic_delay
3721
	call	pic_delay
3683
	out	0xA0,al
3722
	out	0xA0,al
3684
	call	pic_delay
3723
	call	pic_delay
3685
 
3724
 
3686
	mov	al,0x20 	;  generate 0x20 +
3725
	mov	al,0x20 	;  generate 0x20 +
3687
	out	0x21,al
3726
	out	0x21,al
3688
	call	pic_delay
3727
	call	pic_delay
3689
	mov	al,0x28 	;  generate 0x28 +
3728
	mov	al,0x28 	;  generate 0x28 +
3690
	out	0xA1,al
3729
	out	0xA1,al
3691
	call	pic_delay
3730
	call	pic_delay
3692
 
3731
 
3693
	mov	al,0x04 	;  slave at irq2
3732
	mov	al,0x04 	;  slave at irq2
3694
	out	0x21,al
3733
	out	0x21,al
3695
	call	pic_delay
3734
	call	pic_delay
3696
	mov	al,0x02 	;  at irq9
3735
	mov	al,0x02 	;  at irq9
3697
	out	0xA1,al
3736
	out	0xA1,al
3698
	call	pic_delay
3737
	call	pic_delay
3699
 
3738
 
3700
	mov	al,0x01 	;  8086 mode
3739
	mov	al,0x01 	;  8086 mode
3701
	out	0x21,al
3740
	out	0x21,al
3702
	call	pic_delay
3741
	call	pic_delay
3703
	out	0xA1,al
3742
	out	0xA1,al
3704
	call	pic_delay
3743
	call	pic_delay
3705
 
3744
 
3706
	mov	al,255		; mask all irq's
3745
	mov	al,255		; mask all irq's
3707
	out	0xA1,al
3746
	out	0xA1,al
3708
	call	pic_delay
3747
	call	pic_delay
3709
	out	0x21,al
3748
	out	0x21,al
3710
	call	pic_delay
3749
	call	pic_delay
3711
 
3750
 
3712
	mov	ecx,0x1000
3751
	mov	ecx,0x1000
3713
	cld
3752
	cld
3714
picl1:	call	pic_delay
3753
picl1:	call	pic_delay
3715
	loop	picl1
3754
	loop	picl1
3716
 
3755
 
3717
	mov	al,255		; mask all irq's
3756
	mov	al,255		; mask all irq's
3718
	out	0xA1,al
3757
	out	0xA1,al
3719
	call	pic_delay
3758
	call	pic_delay
3720
	out	0x21,al
3759
	out	0x21,al
3721
	call	pic_delay
3760
	call	pic_delay
3722
 
3761
 
3723
	cli
3762
	cli
3724
 
3763
 
3725
	ret
3764
	ret
3726
 
3765
 
3727
 
3766
 
3728
pic_delay:
3767
pic_delay:
3729
 
3768
 
3730
	jmp	pdl1
3769
	jmp	pdl1
3731
pdl1:	ret
3770
pdl1:	ret
3732
 
3771
 
3733
 
3772
 
3734
sys_msg_board_str:
3773
sys_msg_board_str:
3735
 
3774
 
3736
     pushad
3775
     pushad
3737
   @@:
3776
   @@:
3738
     cmp    [esi],byte 0
3777
     cmp    [esi],byte 0
3739
     je     @f
3778
     je     @f
3740
     mov    eax,1
3779
     mov    eax,1
3741
     movzx  ebx,byte [esi]
3780
     movzx  ebx,byte [esi]
3742
     call   sys_msg_board
3781
     call   sys_msg_board
3743
     inc    esi
3782
     inc    esi
3744
     jmp    @b
3783
     jmp    @b
3745
   @@:
3784
   @@:
3746
     popad
3785
     popad
3747
     ret
3786
     ret
3748
 
3787
 
3749
sys_msg_board_byte:
3788
sys_msg_board_byte:
3750
; in: al = byte to display
3789
; in: al = byte to display
3751
; out: nothing
3790
; out: nothing
3752
; destroys: nothing
3791
; destroys: nothing
3753
	pushad
3792
	pushad
3754
	mov	ecx, 2
3793
	mov	ecx, 2
3755
	shl	eax, 24
3794
	shl	eax, 24
3756
	jmp	@f
3795
	jmp	@f
3757
 
3796
 
3758
sys_msg_board_word:
3797
sys_msg_board_word:
3759
; in: ax = word to display
3798
; in: ax = word to display
3760
; out: nothing
3799
; out: nothing
3761
; destroys: nothing
3800
; destroys: nothing
3762
	pushad
3801
	pushad
3763
	mov	ecx, 4
3802
	mov	ecx, 4
3764
	shl	eax, 16
3803
	shl	eax, 16
3765
	jmp	@f
3804
	jmp	@f
3766
 
3805
 
3767
sys_msg_board_dword:
3806
sys_msg_board_dword:
3768
; in: eax = dword to display
3807
; in: eax = dword to display
3769
; out: nothing
3808
; out: nothing
3770
; destroys: nothing
3809
; destroys: nothing
3771
	pushad
3810
	pushad
3772
	mov	ecx, 8
3811
	mov	ecx, 8
3773
@@:
3812
@@:
3774
	push	ecx
3813
	push	ecx
3775
	rol	eax, 4
3814
	rol	eax, 4
3776
	push	eax
3815
	push	eax
3777
	and	al, 0xF
3816
	and	al, 0xF
3778
	cmp	al, 10
3817
	cmp	al, 10
3779
	sbb	al, 69h
3818
	sbb	al, 69h
3780
	das
3819
	das
3781
	mov	bl, al
3820
	mov	bl, al
3782
	xor	eax, eax
3821
	xor	eax, eax
3783
	inc	eax
3822
	inc	eax
3784
	call	sys_msg_board
3823
	call	sys_msg_board
3785
	pop	eax
3824
	pop	eax
3786
	pop	ecx
3825
	pop	ecx
3787
	loop	@b
3826
	loop	@b
3788
	popad
3827
	popad
3789
	ret
3828
	ret
3790
 
3829
 
3791
uglobal
3830
uglobal
3792
  msg_board_data: times 4096 db 0
3831
  msg_board_data: times 4096 db 0
3793
  msg_board_count dd 0x0
3832
  msg_board_count dd 0x0
3794
endg
3833
endg
3795
 
3834
 
3796
sys_msg_board:
3835
sys_msg_board:
3797
 
3836
 
3798
; eax=1 : write :  bl byte to write
3837
; eax=1 : write :  bl byte to write
3799
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
3838
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
3800
 
3839
 
3801
	mov	ecx, [msg_board_count]
3840
	mov	ecx, [msg_board_count]
3802
	cmp	eax, 1
3841
	cmp	eax, 1
3803
	jne	.smbl1
3842
	jne	.smbl1
3804
 
3843
 
3805
	mov	[msg_board_data+ecx],bl
3844
	mov	[msg_board_data+ecx],bl
3806
	inc	ecx
3845
	inc	ecx
3807
	and	ecx, 4095
3846
	and	ecx, 4095
3808
	mov	[msg_board_count], ecx
3847
	mov	[msg_board_count], ecx
3809
	mov	[check_idle_semaphore], 5
3848
	mov	[check_idle_semaphore], 5
3810
	ret
3849
	ret
3811
.smbl1:
3850
.smbl1:
3812
	cmp	eax, 2
3851
	cmp	eax, 2
3813
	jne	.smbl2
3852
	jne	.smbl2
3814
	test	ecx, ecx
3853
	test	ecx, ecx
3815
	jz	.smbl21
3854
	jz	.smbl21
3816
	mov	eax, msg_board_data+1
3855
	mov	eax, msg_board_data+1
3817
	mov	ebx, msg_board_data
3856
	mov	ebx, msg_board_data
3818
	movzx	edx, byte [ebx]
3857
	movzx	edx, byte [ebx]
3819
	call	memmove
3858
	call	memmove
3820
	dec	[msg_board_count]
3859
	dec	[msg_board_count]
3821
	mov	[esp + 36], edx ;eax
3860
	mov	[esp + 36], edx ;eax
3822
	mov	[esp + 24], dword 1
3861
	mov	[esp + 24], dword 1
3823
	ret
3862
	ret
3824
.smbl21:
3863
.smbl21:
3825
	mov	[esp+36], ecx
3864
	mov	[esp+36], ecx
3826
	mov	[esp+24], ecx
3865
	mov	[esp+24], ecx
3827
.smbl2:
3866
.smbl2:
3828
	ret
3867
	ret
3829
 
3868
 
3830
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3869
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3831
;; 66 sys function.                                                ;;
3870
;; 66 sys function.                                                ;;
3832
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
3871
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
3833
;; out eax                                                         ;;
3872
;; out eax                                                         ;;
3834
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3873
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3835
iglobal
3874
iglobal
3836
align 4
3875
align 4
3837
f66call:
3876
f66call:
3838
	   dd sys_process_def.1   ; 1 = set keyboard mode
3877
	   dd sys_process_def.1   ; 1 = set keyboard mode
3839
	   dd sys_process_def.2   ; 2 = get keyboard mode
3878
	   dd sys_process_def.2   ; 2 = get keyboard mode
3840
	   dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
3879
	   dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
3841
	   dd sys_process_def.4
3880
	   dd sys_process_def.4
3842
	   dd sys_process_def.5
3881
	   dd sys_process_def.5
3843
endg
3882
endg
3844
 
3883
 
3845
 
3884
 
3846
 
3885
 
3847
 
3886
 
3848
sys_process_def:
3887
sys_process_def:
3849
	dec	ebx
3888
	dec	ebx
3850
	cmp	ebx,5
3889
	cmp	ebx,5
3851
	jae	.not_support	;if >=6 then or eax,-1
3890
	jae	.not_support	;if >=6 then or eax,-1
3852
 
3891
 
3853
	mov	edi, [CURRENT_TASK]
3892
	mov	edi, [CURRENT_TASK]
3854
	jmp	dword [f66call+ebx*4]
3893
	jmp	dword [f66call+ebx*4]
3855
 
3894
 
3856
.not_support:
3895
.not_support:
3857
	or	eax,-1
3896
	or	eax,-1
3858
	ret
3897
	ret
3859
 
3898
 
3860
.1:
3899
.1:
3861
     shl   edi,8
3900
     shl   edi,8
3862
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],cl
3901
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],cl
3863
 
3902
 
3864
     ret
3903
     ret
3865
 
3904
 
3866
.2:				; 2 = get keyboard mode
3905
.2:				; 2 = get keyboard mode
3867
     shl   edi,8
3906
     shl   edi,8
3868
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
3907
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
3869
     mov   [esp+32],eax
3908
     mov   [esp+32],eax
3870
     ret
3909
     ret
3871
;     xor   eax,eax
3910
;     xor   eax,eax
3872
;     movzx eax,byte [shift]
3911
;     movzx eax,byte [shift]
3873
;     movzx ebx,byte [ctrl]
3912
;     movzx ebx,byte [ctrl]
3874
;     shl   ebx,2
3913
;     shl   ebx,2
3875
;     add   eax,ebx
3914
;     add   eax,ebx
3876
;     movzx ebx,byte [alt]
3915
;     movzx ebx,byte [alt]
3877
;     shl   ebx,3
3916
;     shl   ebx,3
3878
;     add   eax,ebx
3917
;     add   eax,ebx
3879
.3:				;3 = get keyboard ctrl, alt, shift
3918
.3:				;3 = get keyboard ctrl, alt, shift
3880
 ;// mike.dld [
3919
 ;// mike.dld [
3881
     mov   eax, [kb_state]
3920
     mov   eax, [kb_state]
3882
 ;// mike.dld ]
3921
 ;// mike.dld ]
3883
     mov   [esp+32],eax
3922
     mov   [esp+32],eax
3884
     ret
3923
     ret
3885
 
3924
 
3886
.4:
3925
.4:
3887
	mov	eax, hotkey_list
3926
	mov	eax, hotkey_list
3888
@@:
3927
@@:
3889
	cmp	dword [eax+8], 0
3928
	cmp	dword [eax+8], 0
3890
	jz	.found_free
3929
	jz	.found_free
3891
	add	eax, 16
3930
	add	eax, 16
3892
	cmp	eax, hotkey_list+16*256
3931
	cmp	eax, hotkey_list+16*256
3893
	jb	@b
3932
	jb	@b
3894
	mov	dword [esp+32], 1
3933
	mov	dword [esp+32], 1
3895
	ret
3934
	ret
3896
.found_free:
3935
.found_free:
3897
	mov	[eax+8], edi
3936
	mov	[eax+8], edi
3898
	mov	[eax+4], edx
3937
	mov	[eax+4], edx
3899
	movzx	ecx, cl
3938
	movzx	ecx, cl
3900
	lea	ecx, [hotkey_scancodes+ecx*4]
3939
	lea	ecx, [hotkey_scancodes+ecx*4]
3901
	mov	edx, [ecx]
3940
	mov	edx, [ecx]
3902
	mov	[eax], edx
3941
	mov	[eax], edx
3903
	mov	[ecx], eax
3942
	mov	[ecx], eax
3904
	mov	[eax+12], ecx
3943
	mov	[eax+12], ecx
3905
	jecxz	@f
3944
	jecxz	@f
3906
	mov	[edx+12], eax
3945
	mov	[edx+12], eax
3907
@@:
3946
@@:
3908
	and	dword [esp+32], 0
3947
	and	dword [esp+32], 0
3909
	ret
3948
	ret
3910
 
3949
 
3911
.5:
3950
.5:
3912
	movzx	ebx, cl
3951
	movzx	ebx, cl
3913
	lea	ebx, [hotkey_scancodes+ebx*4]
3952
	lea	ebx, [hotkey_scancodes+ebx*4]
3914
	mov	eax, [ebx]
3953
	mov	eax, [ebx]
3915
.scan:
3954
.scan:
3916
	test	eax, eax
3955
	test	eax, eax
3917
	jz	.notfound
3956
	jz	.notfound
3918
	cmp	[eax+8], edi
3957
	cmp	[eax+8], edi
3919
	jnz	.next
3958
	jnz	.next
3920
	cmp	[eax+4], edx
3959
	cmp	[eax+4], edx
3921
	jz	.found
3960
	jz	.found
3922
.next:
3961
.next:
3923
	mov	eax, [eax]
3962
	mov	eax, [eax]
3924
	jmp	.scan
3963
	jmp	.scan
3925
.notfound:
3964
.notfound:
3926
	mov	dword [esp+32], 1
3965
	mov	dword [esp+32], 1
3927
	ret
3966
	ret
3928
.found:
3967
.found:
3929
	mov	ecx, [eax]
3968
	mov	ecx, [eax]
3930
	jecxz	@f
3969
	jecxz	@f
3931
	mov	edx, [eax+12]
3970
	mov	edx, [eax+12]
3932
	mov	[ecx+12], edx
3971
	mov	[ecx+12], edx
3933
@@:
3972
@@:
3934
	mov	ecx, [eax+12]
3973
	mov	ecx, [eax+12]
3935
	mov	edx, [eax]
3974
	mov	edx, [eax]
3936
	mov	[ecx], edx
3975
	mov	[ecx], edx
3937
	xor	edx, edx
3976
	xor	edx, edx
3938
	mov	[eax+4], edx
3977
	mov	[eax+4], edx
3939
	mov	[eax+8], edx
3978
	mov	[eax+8], edx
3940
	mov	[eax+12], edx
3979
	mov	[eax+12], edx
3941
	mov	[eax], edx
3980
	mov	[eax], edx
3942
	mov	[esp+32], edx
3981
	mov	[esp+32], edx
3943
	ret
3982
	ret
3944
 
3983
 
3945
 
3984
 
3946
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3985
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3947
;; 61 sys function.                                                ;;
3986
;; 61 sys function.                                                ;;
3948
;; in eax=61,ebx in [1..3]                                         ;;
3987
;; in eax=61,ebx in [1..3]                                         ;;
3949
;; out eax                                                         ;;
3988
;; out eax                                                         ;;
3950
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3989
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3951
iglobal
3990
iglobal
3952
align 4
3991
align 4
3953
f61call:
3992
f61call:
3954
	   dd sys_gs.1	 ; resolution
3993
	   dd sys_gs.1	 ; resolution
3955
	   dd sys_gs.2	 ; bits per pixel
3994
	   dd sys_gs.2	 ; bits per pixel
3956
	   dd sys_gs.3	 ; bytes per scanline
3995
	   dd sys_gs.3	 ; bytes per scanline
3957
endg
3996
endg
3958
 
3997
 
3959
 
3998
 
3960
align 4
3999
align 4
3961
 
4000
 
3962
sys_gs: 			; direct screen access
4001
sys_gs: 			; direct screen access
3963
	dec	ebx
4002
	dec	ebx
3964
	cmp	ebx,2
4003
	cmp	ebx,2
3965
	ja	.not_support
4004
	ja	.not_support
3966
	jmp	dword [f61call+ebx*4]
4005
	jmp	dword [f61call+ebx*4]
3967
.not_support:
4006
.not_support:
3968
	or  [esp+32],dword -1
4007
	or  [esp+32],dword -1
3969
	ret
4008
	ret
3970
 
4009
 
3971
 
4010
 
3972
.1:				; resolution
4011
.1:				; resolution
3973
     mov  eax,[Screen_Max_X]
4012
     mov  eax,[Screen_Max_X]
3974
     shl  eax,16
4013
     shl  eax,16
3975
     mov  ax,[Screen_Max_Y]
4014
     mov  ax,[Screen_Max_Y]
3976
     add  eax,0x00010001
4015
     add  eax,0x00010001
3977
     mov  [esp+32],eax
4016
     mov  [esp+32],eax
3978
     ret
4017
     ret
3979
.2:				; bits per pixel
4018
.2:				; bits per pixel
3980
     movzx eax,byte [ScreenBPP]
4019
     movzx eax,byte [ScreenBPP]
3981
     mov   [esp+32],eax
4020
     mov   [esp+32],eax
3982
     ret
4021
     ret
3983
.3:				; bytes per scanline
4022
.3:				; bytes per scanline
3984
     mov   eax,[BytesPerScanLine]
4023
     mov   eax,[BytesPerScanLine]
3985
     mov   [esp+32],eax
4024
     mov   [esp+32],eax
3986
     ret
4025
     ret
3987
 
4026
 
3988
align 4  ;  system functions
4027
align 4  ;  system functions
3989
 
4028
 
3990
syscall_setpixel:			; SetPixel
4029
syscall_setpixel:			; SetPixel
3991
 
4030
 
3992
	mov	eax, ebx
4031
	mov	eax, ebx
3993
	mov	ebx, ecx
4032
	mov	ebx, ecx
3994
	mov	ecx, edx
4033
	mov	ecx, edx
3995
	xor	edi, edi ; no force
4034
	xor	edi, edi ; no force
3996
	call	[_display.disable_mouse]
4035
	call	[_display.disable_mouse]
3997
	jmp	[putpixel]
4036
	jmp	[putpixel]
3998
 
4037
 
3999
align 4
4038
align 4
4000
 
4039
 
4001
syscall_writetext:			; WriteText
4040
syscall_writetext:			; WriteText
4002
 
4041
 
4003
	mov   eax,[TASK_BASE]
4042
	mov   eax,[TASK_BASE]
4004
	mov   ebp,[eax-twdw+WDATA.box.left]
4043
	mov   ebp,[eax-twdw+WDATA.box.left]
4005
	push  esi
4044
	push  esi
4006
	mov   esi,[current_slot]
4045
	mov   esi,[current_slot]
4007
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4046
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4008
	shl   ebp,16
4047
	shl   ebp,16
4009
	add   ebp,[eax-twdw+WDATA.box.top]
4048
	add   ebp,[eax-twdw+WDATA.box.top]
4010
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4049
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4011
	pop   esi
4050
	pop   esi
4012
	add   ebx,ebp
4051
	add   ebx,ebp
4013
	mov   eax,edi
4052
	mov   eax,edi
4014
	xor   edi,edi
4053
	xor   edi,edi
4015
	jmp   dtext
4054
	jmp   dtext
4016
 
4055
 
4017
align 4
4056
align 4
4018
 
4057
 
4019
syscall_openramdiskfile:		; OpenRamdiskFile
4058
syscall_openramdiskfile:		; OpenRamdiskFile
4020
 
4059
 
4021
	mov	eax, ebx
4060
	mov	eax, ebx
4022
	mov	ebx, ecx
4061
	mov	ebx, ecx
4023
	mov	ecx, edx
4062
	mov	ecx, edx
4024
	mov	edx, esi
4063
	mov	edx, esi
4025
	mov	esi, 12
4064
	mov	esi, 12
4026
	call	fileread
4065
	call	fileread
4027
	mov	[esp+32], eax
4066
	mov	[esp+32], eax
4028
	ret
4067
	ret
4029
 
4068
 
4030
align 4
4069
align 4
4031
 
4070
 
4032
syscall_drawrect:			; DrawRect
4071
syscall_drawrect:			; DrawRect
4033
 
4072
 
4034
	mov	edi, edx ; color + gradient
4073
	mov	edi, edx ; color + gradient
4035
	and	edi, 0x80FFFFFF
4074
	and	edi, 0x80FFFFFF
4036
	test	bx, bx	; x.size
4075
	test	bx, bx	; x.size
4037
	je	.drectr
4076
	je	.drectr
4038
	test	cx, cx ; y.size
4077
	test	cx, cx ; y.size
4039
	je	.drectr
4078
	je	.drectr
4040
 
4079
 
4041
	mov	eax, ebx ; bad idea
4080
	mov	eax, ebx ; bad idea
4042
	mov	ebx, ecx
4081
	mov	ebx, ecx
4043
 
4082
 
4044
	movzx	ecx, ax ; ecx - x.size
4083
	movzx	ecx, ax ; ecx - x.size
4045
	shr	eax, 16 ; eax - x.coord
4084
	shr	eax, 16 ; eax - x.coord
4046
	movzx	edx, bx ; edx - y.size
4085
	movzx	edx, bx ; edx - y.size
4047
	shr	ebx, 16 ; ebx - y.coord
4086
	shr	ebx, 16 ; ebx - y.coord
4048
	mov	esi, [current_slot]
4087
	mov	esi, [current_slot]
4049
 
4088
 
4050
	add	eax, [esi + APPDATA.wnd_clientbox.left]
4089
	add	eax, [esi + APPDATA.wnd_clientbox.left]
4051
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4090
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4052
	add	ecx, eax
4091
	add	ecx, eax
4053
	add	edx, ebx
4092
	add	edx, ebx
4054
	jmp	[drawbar]
4093
	jmp	[drawbar]
4055
.drectr:
4094
.drectr:
4056
	ret
4095
	ret
4057
 
4096
 
4058
align 4
4097
align 4
4059
syscall_getscreensize:			; GetScreenSize
4098
syscall_getscreensize:			; GetScreenSize
4060
	mov	ax, [Screen_Max_X]
4099
	mov	ax, [Screen_Max_X]
4061
	shl	eax, 16
4100
	shl	eax, 16
4062
	mov	ax, [Screen_Max_Y]
4101
	mov	ax, [Screen_Max_Y]
4063
	mov	[esp + 32], eax
4102
	mov	[esp + 32], eax
4064
	ret
4103
	ret
4065
 
4104
 
4066
align 4
4105
align 4
4067
 
4106
 
4068
 
4107
 
4069
align 4
4108
align 4
4070
 
4109
 
4071
syscall_getpixel:			; GetPixel
4110
syscall_getpixel:			; GetPixel
4072
     mov   ecx, [Screen_Max_X]
4111
     mov   ecx, [Screen_Max_X]
4073
     inc   ecx
4112
     inc   ecx
4074
     xor   edx, edx
4113
     xor   edx, edx
4075
     mov   eax, ebx
4114
     mov   eax, ebx
4076
     div   ecx
4115
     div   ecx
4077
     mov   ebx, edx
4116
     mov   ebx, edx
4078
     xchg  eax, ebx
4117
     xchg  eax, ebx
4079
     call  get_pixel	; eax - x, ebx - y
4118
     call  get_pixel	; eax - x, ebx - y
4080
     mov   [esp + 32], ecx
4119
     mov   [esp + 32], ecx
4081
     ret
4120
     ret
4082
 
4121
 
4083
align 4
4122
align 4
4084
 
4123
 
4085
syscall_getarea:
4124
syscall_getarea:
4086
;eax = 36
4125
;eax = 36
4087
;ebx = pointer to bufer for img BBGGRRBBGGRR...
4126
;ebx = pointer to bufer for img BBGGRRBBGGRR...
4088
;ecx = [size x]*65536 + [size y]
4127
;ecx = [size x]*65536 + [size y]
4089
;edx = [start x]*65536 + [start y]
4128
;edx = [start x]*65536 + [start y]
4090
     pushad
4129
     pushad
4091
	 inc   [mouse_pause]
4130
	 inc   [mouse_pause]
4092
; Check of use of the hardware cursor.
4131
; Check of use of the hardware cursor.
4093
      cmp  [_display.disable_mouse],__sys_disable_mouse
4132
      cmp  [_display.disable_mouse],__sys_disable_mouse
4094
	  jne  @f
4133
	  jne  @f
4095
; Since the test for the coordinates of the mouse should not be used,
4134
; Since the test for the coordinates of the mouse should not be used,
4096
; then use the call [disable_mouse] is not possible!
4135
; then use the call [disable_mouse] is not possible!
4097
      cmp  dword [MOUSE_VISIBLE],dword 0
4136
      cmp  dword [MOUSE_VISIBLE],dword 0
4098
      jne  @f
4137
      jne  @f
4099
      pushf
4138
      pushf
4100
      cli
4139
      cli
4101
      call draw_mouse_under
4140
      call draw_mouse_under
4102
      popf
4141
      popf
4103
      mov  [MOUSE_VISIBLE],dword 1
4142
      mov  [MOUSE_VISIBLE],dword 1
4104
@@:
4143
@@:
4105
     mov   edi,ebx
4144
     mov   edi,ebx
4106
     mov   eax,edx
4145
     mov   eax,edx
4107
     shr   eax,16
4146
     shr   eax,16
4108
     mov   ebx,edx
4147
     mov   ebx,edx
4109
     and   ebx,0xffff
4148
     and   ebx,0xffff
4110
     dec   eax
4149
     dec   eax
4111
	   dec	 ebx
4150
	   dec	 ebx
4112
     ; eax - x, ebx - y
4151
     ; eax - x, ebx - y
4113
     mov   edx,ecx
4152
     mov   edx,ecx
4114
 
4153
 
4115
     shr   ecx,16
4154
     shr   ecx,16
4116
     and   edx,0xffff
4155
     and   edx,0xffff
4117
     mov   esi,ecx
4156
     mov   esi,ecx
4118
     ; ecx - size x, edx - size y
4157
     ; ecx - size x, edx - size y
4119
 
4158
 
4120
	 mov   ebp,edx
4159
	 mov   ebp,edx
4121
	 dec   ebp
4160
	 dec   ebp
4122
     lea   ebp,[ebp*3]
4161
     lea   ebp,[ebp*3]
4123
 
4162
 
4124
	 imul  ebp,esi
4163
	 imul  ebp,esi
4125
 
4164
 
4126
	 mov   esi,ecx
4165
	 mov   esi,ecx
4127
	 dec   esi
4166
	 dec   esi
4128
	 lea   esi,[esi*3]
4167
	 lea   esi,[esi*3]
4129
 
4168
 
4130
     add   ebp,esi
4169
     add   ebp,esi
4131
     add   ebp,edi
4170
     add   ebp,edi
4132
 
4171
 
4133
     add   ebx,edx
4172
     add   ebx,edx
4134
 
4173
 
4135
.start_y:
4174
.start_y:
4136
     push  ecx edx
4175
     push  ecx edx
4137
.start_x:
4176
.start_x:
4138
     push  eax ebx ecx
4177
     push  eax ebx ecx
4139
     add   eax,ecx
4178
     add   eax,ecx
4140
 
4179
 
4141
     call  get_pixel ; eax - x, ebx - y
4180
     call  get_pixel ; eax - x, ebx - y
4142
 
4181
 
4143
     mov   [ebp],cx
4182
     mov   [ebp],cx
4144
     shr   ecx,16
4183
     shr   ecx,16
4145
     mov   [ebp+2],cl
4184
     mov   [ebp+2],cl
4146
 
4185
 
4147
     pop   ecx ebx eax
4186
     pop   ecx ebx eax
4148
     sub   ebp,3
4187
     sub   ebp,3
4149
     dec   ecx
4188
     dec   ecx
4150
     jnz   .start_x
4189
     jnz   .start_x
4151
	 pop   edx ecx
4190
	 pop   edx ecx
4152
	 dec   ebx
4191
	 dec   ebx
4153
     dec   edx
4192
     dec   edx
4154
     jnz   .start_y
4193
     jnz   .start_y
4155
     dec	[mouse_pause]
4194
     dec	[mouse_pause]
4156
; Check of use of the hardware cursor.
4195
; Check of use of the hardware cursor.
4157
      cmp  [_display.disable_mouse],__sys_disable_mouse
4196
      cmp  [_display.disable_mouse],__sys_disable_mouse
4158
	  jne  @f
4197
	  jne  @f
4159
	 call  [draw_pointer]
4198
	 call  [draw_pointer]
4160
@@:
4199
@@:
4161
     popad
4200
     popad
4162
     ret
4201
     ret
4163
 
4202
 
4164
align 4
4203
align 4
4165
 
4204
 
4166
syscall_drawline:			; DrawLine
4205
syscall_drawline:			; DrawLine
4167
 
4206
 
4168
	mov	edi, [TASK_BASE]
4207
	mov	edi, [TASK_BASE]
4169
	movzx	eax, word[edi-twdw+WDATA.box.left]
4208
	movzx	eax, word[edi-twdw+WDATA.box.left]
4170
	mov	ebp, eax
4209
	mov	ebp, eax
4171
	mov	esi, [current_slot]
4210
	mov	esi, [current_slot]
4172
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
4211
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
4173
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
4212
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
4174
	add	ebp,ebx
4213
	add	ebp,ebx
4175
	shl	eax, 16
4214
	shl	eax, 16
4176
	movzx	ebx, word[edi-twdw+WDATA.box.top]
4215
	movzx	ebx, word[edi-twdw+WDATA.box.top]
4177
	add	eax, ebp
4216
	add	eax, ebp
4178
	mov	ebp, ebx
4217
	mov	ebp, ebx
4179
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
4218
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
4180
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
4219
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
4181
	add	ebp, ecx
4220
	add	ebp, ecx
4182
	shl	ebx, 16
4221
	shl	ebx, 16
4183
	xor	edi, edi
4222
	xor	edi, edi
4184
	add	ebx, ebp
4223
	add	ebx, ebp
4185
	mov	ecx, edx
4224
	mov	ecx, edx
4186
	jmp	[draw_line]
4225
	jmp	[draw_line]
4187
 
4226
 
4188
align 4
4227
align 4
4189
 
4228
 
4190
syscall_getirqowner:			; GetIrqOwner
4229
syscall_getirqowner:			; GetIrqOwner
4191
 
4230
 
4192
     cmp   ebx,16
4231
     cmp   ebx,16
4193
     jae   .err
4232
     jae   .err
4194
 
4233
 
4195
     cmp   [irq_rights + 4 * ebx], dword 2
4234
     cmp   [irq_rights + 4 * ebx], dword 2
4196
     je    .err
4235
     je    .err
4197
 
4236
 
4198
     mov   eax,[4 * ebx + irq_owner]
4237
     mov   eax,[4 * ebx + irq_owner]
4199
     mov   [esp+32],eax
4238
     mov   [esp+32],eax
4200
 
4239
 
4201
     ret
4240
     ret
4202
.err:
4241
.err:
4203
     or    dword [esp+32], -1
4242
     or    dword [esp+32], -1
4204
     ret
4243
     ret
4205
 
4244
 
4206
align 4
4245
align 4
4207
 
4246
 
4208
syscall_reserveportarea:		; ReservePortArea and FreePortArea
4247
syscall_reserveportarea:		; ReservePortArea and FreePortArea
4209
 
4248
 
4210
     call  r_f_port_area
4249
     call  r_f_port_area
4211
     mov   [esp+32],eax
4250
     mov   [esp+32],eax
4212
     ret
4251
     ret
4213
 
4252
 
4214
align 4
4253
align 4
4215
 
4254
 
4216
syscall_threads:			; CreateThreads
4255
syscall_threads:			; CreateThreads
4217
; eax=1 create thread
4256
; eax=1 create thread
4218
;
4257
;
4219
;   ebx=thread start
4258
;   ebx=thread start
4220
;   ecx=thread stack value
4259
;   ecx=thread stack value
4221
;
4260
;
4222
; on return : eax = pid
4261
; on return : eax = pid
4223
 
4262
 
4224
     call  new_sys_threads
4263
     call  new_sys_threads
4225
 
4264
 
4226
     mov   [esp+32],eax
4265
     mov   [esp+32],eax
4227
     ret
4266
     ret
4228
 
4267
 
4229
align 4
4268
align 4
4230
 
4269
 
4231
stack_driver_stat:
4270
stack_driver_stat:
4232
 
4271
 
4233
     call  app_stack_handler		; Stack status
4272
     call  app_stack_handler		; Stack status
4234
 
4273
 
4235
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4274
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4236
;     call  change_task                 ; between sent packet
4275
;     call  change_task                 ; between sent packet
4237
 
4276
 
4238
     mov   [esp+32],eax
4277
     mov   [esp+32],eax
4239
     ret
4278
     ret
4240
 
4279
 
4241
align 4
4280
align 4
4242
 
4281
 
4243
socket: 				; Socket interface
4282
socket: 				; Socket interface
4244
     call  app_socket_handler
4283
     call  app_socket_handler
4245
 
4284
 
4246
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4285
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4247
;     call  change_task                 ; between sent packet
4286
;     call  change_task                 ; between sent packet
4248
 
4287
 
4249
     mov   [esp+36],eax
4288
     mov   [esp+36],eax
4250
     mov   [esp+24],ebx
4289
     mov   [esp+24],ebx
4251
     ret
4290
     ret
4252
 
4291
 
4253
align 4
4292
align 4
4254
 
4293
 
4255
read_from_hd:				; Read from hd - fn not in use
4294
read_from_hd:				; Read from hd - fn not in use
4256
 
4295
 
4257
     mov   edi,[TASK_BASE]
4296
     mov   edi,[TASK_BASE]
4258
     add   edi,TASKDATA.mem_start
4297
     add   edi,TASKDATA.mem_start
4259
     add   eax,[edi]
4298
     add   eax,[edi]
4260
     add   ecx,[edi]
4299
     add   ecx,[edi]
4261
     add   edx,[edi]
4300
     add   edx,[edi]
4262
     call  file_read
4301
     call  file_read
4263
 
4302
 
4264
     mov   [esp+36],eax
4303
     mov   [esp+36],eax
4265
     mov   [esp+24],ebx
4304
     mov   [esp+24],ebx
4266
 
4305
 
4267
     ret
4306
     ret
4268
 
4307
 
4269
paleholder:
4308
paleholder:
4270
	ret
4309
	ret
4271
 
4310
 
4272
align 4
4311
align 4
4273
set_screen:
4312
set_screen:
4274
	cmp eax, [Screen_Max_X]
4313
	cmp eax, [Screen_Max_X]
4275
	jne .set
4314
	jne .set
4276
 
4315
 
4277
	cmp edx, [Screen_Max_Y]
4316
	cmp edx, [Screen_Max_Y]
4278
	jne .set
4317
	jne .set
4279
	ret
4318
	ret
4280
.set:
4319
.set:
4281
	pushfd
4320
	pushfd
4282
	cli
4321
	cli
4283
 
4322
 
4284
	mov [Screen_Max_X], eax
4323
	mov [Screen_Max_X], eax
4285
	mov [Screen_Max_Y], edx
4324
	mov [Screen_Max_Y], edx
4286
	mov [BytesPerScanLine], ecx
4325
	mov [BytesPerScanLine], ecx
4287
 
4326
 
4288
	mov [screen_workarea.right],eax
4327
	mov [screen_workarea.right],eax
4289
	mov [screen_workarea.bottom], edx
4328
	mov [screen_workarea.bottom], edx
4290
 
4329
 
4291
	push ebx
4330
	push ebx
4292
	push esi
4331
	push esi
4293
	push edi
4332
	push edi
4294
 
4333
 
4295
	pushad
4334
	pushad
4296
 
4335
 
4297
	stdcall kernel_free, [_WinMapAddress]
4336
	stdcall kernel_free, [_WinMapAddress]
4298
 
4337
 
4299
	mov eax, [_display.width]
4338
	mov eax, [_display.width]
4300
	mul [_display.height]
4339
	mul [_display.height]
4301
	mov [_WinMapSize], eax
4340
	mov [_WinMapSize], eax
4302
 
4341
 
4303
	stdcall kernel_alloc, eax
4342
	stdcall kernel_alloc, eax
4304
	mov [_WinMapAddress], eax
4343
	mov [_WinMapAddress], eax
4305
	test eax, eax
4344
	test eax, eax
4306
	jz .epic_fail
4345
	jz .epic_fail
4307
 
4346
 
4308
	popad
4347
	popad
4309
 
4348
 
4310
	call	repos_windows
4349
	call	repos_windows
4311
	xor eax, eax
4350
	xor eax, eax
4312
	xor ebx, ebx
4351
	xor ebx, ebx
4313
	mov	ecx, [Screen_Max_X]
4352
	mov	ecx, [Screen_Max_X]
4314
	mov	edx, [Screen_Max_Y]
4353
	mov	edx, [Screen_Max_Y]
4315
	call	calculatescreen
4354
	call	calculatescreen
4316
	pop edi
4355
	pop edi
4317
	pop esi
4356
	pop esi
4318
	pop ebx
4357
	pop ebx
4319
 
4358
 
4320
	popfd
4359
	popfd
4321
	ret
4360
	ret
4322
 
4361
 
4323
.epic_fail:
4362
.epic_fail:
4324
	hlt			; Houston, we've had a problem
4363
	hlt			; Houston, we've had a problem
4325
 
4364
 
4326
; --------------- APM ---------------------
4365
; --------------- APM ---------------------
4327
 
4366
 
4328
align 4
4367
align 4
4329
sys_apm:
4368
sys_apm:
4330
	xor	eax,eax
4369
	xor	eax,eax
4331
	inc	eax
4370
	inc	eax
4332
	or	dword [esp + 44], eax	; error
4371
	or	dword [esp + 44], eax	; error
4333
	add	eax,7
4372
	add	eax,7
4334
	mov	dword [esp + 32], eax	; 32-bit protected-mode interface not supported
4373
	mov	dword [esp + 32], eax	; 32-bit protected-mode interface not supported
4335
	ret
4374
	ret
4336
 
4375
 
4337
; -----------------------------------------
4376
; -----------------------------------------
4338
 
4377
 
4339
align 4
4378
align 4
4340
 
4379
 
4341
undefined_syscall:			; Undefined system call
4380
undefined_syscall:			; Undefined system call
4342
     mov   [esp + 32], dword -1
4381
     mov   [esp + 32], dword -1
4343
     ret
4382
     ret
4344
 
4383
 
4345
align 4
4384
align 4
4346
system_shutdown:	  ; shut down the system
4385
system_shutdown:	  ; shut down the system
4347
 
4386
 
4348
	   cmp byte [BOOT_VAR+0x9030], 1
4387
	   cmp byte [BOOT_VAR+0x9030], 1
4349
	   jne @F
4388
	   jne @F
4350
	   ret
4389
	   ret
4351
@@:
4390
@@:
4352
	   call stop_all_services
4391
	   call stop_all_services
4353
 
4392
 
4354
yes_shutdown_param:
4393
yes_shutdown_param:
4355
	   cli
4394
	   cli
4356
 
4395
 
4357
 
4396
 
4358
	   mov al, 0xFF
4397
	   mov al, 0xFF
4359
	   out 0x21, al 	;IntrCntrl1Reg2
4398
	   out 0x21, al 	;IntrCntrl1Reg2
4360
	   out 0xA1, al 	;IntrCntrl2Reg2
4399
	   out 0xA1, al 	;IntrCntrl2Reg2
4361
 
4400
 
4362
	cmp	byte [BOOT_VAR + 0x9030], 2
4401
	cmp	byte [BOOT_VAR + 0x9030], 2
4363
	jnz	pm_restart
4402
	jnz	pm_restart
4364
if 0
4403
if 0
4365
	mov	al, SB_PM_CTRL_BLK
4404
	mov	al, SB_PM_CTRL_BLK
4366
	mov	ah, al
4405
	mov	ah, al
4367
	inc	ah
4406
	inc	ah
4368
	mov	dx, 0x0CD6
4407
	mov	dx, 0x0CD6
4369
	out	dx, al
4408
	out	dx, al
4370
	inc	dl
4409
	inc	dl
4371
	in	al, dx
4410
	in	al, dx
4372
	mov	cl, al
4411
	mov	cl, al
4373
	dec	dl
4412
	dec	dl
4374
	mov	al, ah
4413
	mov	al, ah
4375
	out	dx, al
4414
	out	dx, al
4376
	inc	dl
4415
	inc	dl
4377
	in	al, dx
4416
	in	al, dx
4378
	mov	ch, al
4417
	mov	ch, al
4379
end if
4418
end if
4380
	mov	dx, 0x0804	;cx
4419
	mov	dx, 0x0804	;cx
4381
	mov	ax, 0x03400
4420
	mov	ax, 0x03400
4382
	out	dx, ax
4421
	out	dx, ax
4383
; THE END...
4422
; THE END...
4384
	jmp	$	; just to be absolutely sure
4423
	jmp	$	; just to be absolutely sure
4385
 
4424
 
4386
 
4425
 
4387
pm_restart:
4426
pm_restart:
4388
 
4427
 
4389
	   mov	al,0x0F
4428
	   mov	al,0x0F
4390
	   out	0x70,al 	; NmiEnable
4429
	   out	0x70,al 	; NmiEnable
4391
	   mov	al,0x05
4430
	   mov	al,0x05
4392
	   out	0x71,al 	; RtcData
4431
	   out	0x71,al 	; RtcData
4393
 
4432
 
4394
	   mov	ax, 6
4433
	   mov	ax, 6
4395
	   mov	dx, 0xCF9	; reset reg
4434
	   mov	dx, 0xCF9	; reset reg
4396
	   out	dx, ax
4435
	   out	dx, ax
4397
 
4436
 
4398
	   hlt
4437
	   hlt
4399
	   jmp $-1
4438
	   jmp $-1
4400
 
4439
 
4401
 
4440
 
4402
diff16 "End of 32-code ",0,$
4441
diff16 "End of 32-code ",0,$
4403
 
4442
 
4404
include "data32.inc"
4443
include "data32.inc"
4405
 
4444
 
4406
__REV__ = __REV
4445
__REV__ = __REV
4407
 
4446
 
4408
uglobals_size = $ - endofcode
4447
uglobals_size = $ - endofcode
4409
diff16 "Zero-filled blk",0,endofcode
4448
diff16 "Zero-filled blk",0,endofcode
4410
diff16 "End of kernel  ",0,$
4449
diff16 "End of kernel  ",0,$
4411
;>
4450
;>
4412
;>
4451
;>
4413
;>
4452
;>
4414
;>
4453
;>
4415
;>
4454
;>
4416
;>
4455
;>
4417
;>
4456
;>
4418
;>
4457
;>
4419
;>
4458
;>
4420
;>
4459
;>
4421
;>
4460
;>
4422
;>
4461
;>
4423
;>
4462
;>
4424
;>
4463
;>
4425
;>
4464
;>
4426
;>
4465
;>
4427
;>
4466
;>
4428
;>
4467
;>
4429
;>
4468
;>
4430
;>
4469
;>
4431
;>
4470
;>
4432
;>
4471
;>
4433
;>
4472
;>
4434
;>
4473
;>
4435
;>
4474
;>
4436
;>
4475
;>
4437
;>
4476
;>
4438
;>
4477
;>
4439
;>
4478
;>
4440
;>
4479
;>
4441
;>
4480
;>
4442
;>
4481
;>
4443
;>
4482
;>
4444
;>
4483
;>
4445
;>
4484
;>
4446
;>
4485
;>
4447
;>
4486
;>
4448
;>
4487
;>
4449
;>
4488
;>
4450
;>
4489
;>
4451
;>
4490
;>
4452
;>
4491
;>
4453
;>
4492
;>
4454
;>
4493
;>
4455
;>
4494
;>
4456
;>
4495
;>
4457
;>
4496
;>
4458
;>
4497
;>
4459
;>
4498
;>
4460
;>
4499
;>
4461
;>
4500
;>
4462
;>
4501
;>
4463
;>
4502
;>
4464
;>
4503
;>
4465
;>
4504
;>
4466
;>
4505
;>
4467
;>
4506
;>
4468
;>
4507
;>
4469
;>
4508
;>
4470
;>
4509
;>
4471
;>
4510
;>
4472
;>
4511
;>
4473
;>
4512
;>
4474
;>
4513
;>
4475
;>
4514
;>
4476
;>
4515
;>
4477
;>
4516
;>
4478
;>
4517
;>
4479
;>
4518
;>
4480
;>
4519
;>
4481
;>
4520
;>
4482
;>
4521
;>
4483
;>
4522
;>
4484
end>
4523
end>
4485
end>
4524
end>
4486
end>
4525
end>
4487
>
4526
>
4488
>
4527
>
4489
>
4528
>
4490
 
4529
 
4491
>
4530
>
4492
 
4531
 
4493
>
4532
>
4494
 
4533
 
4495
>
4534
>
4496
 
4535
 
4497
>
4536
>
4498
 
4537
 
4499
>
4538
>
4500
 
4539
 
4501
>
4540
>
4502
 
4541
 
4503
>
4542
>
4504
 
4543
 
4505
>
4544
>
4506
 
4545
 
4507
>
4546
>
4508
 
4547
 
4509
>
4548
>
4510
 
4549
 
4511
>
4550
>
4512
 
4551
 
4513
>
4552
>
4514
 
4553
 
4515
>
4554
>
4516
 
4555
 
4517
>
4556
>
4518
 
4557
 
4519
>
4558
>
4520
 
4559
 
4521
>
4560
>
4522
>
4561
>
4523
>
4562
>
4524
>
4563
>
4525
>
4564
>
4526
>
4565
>
4527
>
4566
>
4528
>
4567
>
4529
>
4568
>
4530
>
4569
>
4531
>
4570
>
4532
>
4571
>
4533
>
4572
>
4534
>
4573
>
4535
>
4574
>
4536
>
4575
>
4537
>
4576
>