Subversion Repositories Kolibri OS

Rev

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

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