Subversion Repositories Kolibri OS

Rev

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

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