Subversion Repositories Kolibri OS

Rev

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

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