Subversion Repositories Kolibri OS

Rev

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

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