Subversion Repositories Kolibri OS

Rev

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

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