Subversion Repositories Kolibri OS

Rev

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

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