Subversion Repositories Kolibri OS

Rev

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

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