Subversion Repositories Kolibri OS

Rev

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

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