Subversion Repositories Kolibri OS

Rev

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

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