Subversion Repositories Kolibri OS

Rev

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

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