Subversion Repositories Kolibri OS

Rev

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

Rev 538 Rev 540
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: 538 $
57
$Revision: 540 $
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
        mov [timer_ticks_enable],1		; for cd driver
861
 
861
 
862
;        stdcall init_uart_service, DRV_ENTRY
862
;        stdcall init_uart_service, DRV_ENTRY
863
 
863
 
864
        sti
864
        sti
865
        call change_task
865
        call change_task
866
 
866
 
867
        jmp osloop
867
        jmp osloop
868
 
868
 
869
        jmp   $                      ; wait here for timer to take control
869
        jmp   $                      ; wait here for timer to take control
870
 
870
 
871
        ; Fly :)
871
        ; Fly :)
872
 
872
 
873
include 'unpacker.inc'
873
include 'unpacker.inc'
874
include 'fdo.inc'
874
include 'fdo.inc'
875
 
875
 
876
align 4
876
align 4
877
boot_log:
877
boot_log:
878
         pushad
878
         pushad
879
 
879
 
880
         mov   eax,10*65536
880
         mov   eax,10*65536
881
         mov   ax,word [boot_y]
881
         mov   ax,word [boot_y]
882
         add   [boot_y],dword 10
882
         add   [boot_y],dword 10
883
         mov   ebx,0x80ffffff   ; ASCIIZ string with white color
883
         mov   ebx,0x80ffffff   ; ASCIIZ string with white color
884
         mov   ecx,esi
884
         mov   ecx,esi
885
         mov   edi,1
885
         mov   edi,1
886
         call  dtext
886
         call  dtext
887
 
887
 
888
         mov   [novesachecksum],1000
888
         mov   [novesachecksum],1000
889
         call  checkVga_N13
889
         call  checkVga_N13
890
 
890
 
891
         cmp   [preboot_blogesc+OS_BASE+0x10000],byte 1
891
         cmp   [preboot_blogesc+OS_BASE+0x10000],byte 1
892
         je    .bll2
892
         je    .bll2
893
 
893
 
894
         cmp   esi,boot_tasking
894
         cmp   esi,boot_tasking
895
         jne   .bll2
895
         jne   .bll2
896
         ; begin ealex 04.08.05
896
         ; begin ealex 04.08.05
897
;         in    al,0x61
897
;         in    al,0x61
898
;         and   al,01111111b
898
;         and   al,01111111b
899
;         out   0x61,al
899
;         out   0x61,al
900
         ; end ealex 04.08.05
900
         ; end ealex 04.08.05
901
.bll1:   in    al,0x60    ; wait for ESC key press
901
.bll1:   in    al,0x60    ; wait for ESC key press
902
         cmp   al,129
902
         cmp   al,129
903
         jne   .bll1
903
         jne   .bll1
904
 
904
 
905
.bll2:   popad
905
.bll2:   popad
906
 
906
 
907
         ret
907
         ret
908
 
908
 
909
 
909
 
910
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
910
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911
;                                                                    ;
911
;                                                                    ;
912
;                    MAIN OS LOOP START                              ;
912
;                    MAIN OS LOOP START                              ;
913
;                                                                    ;
913
;                                                                    ;
914
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
914
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
915
align 32
915
align 32
916
osloop:
916
osloop:
917
        call   [draw_pointer]
917
        call   [draw_pointer]
918
        call   checkbuttons
918
        call   checkbuttons
919
        call   checkwindows
919
        call   checkwindows
920
;       call   check_window_move_request
920
;       call   check_window_move_request
921
        call   checkmisc
921
        call   checkmisc
922
        call   checkVga_N13
922
        call   checkVga_N13
923
        call   stack_handler
923
        call   stack_handler
924
        call   checkidle
924
        call   checkidle
925
        call   check_fdd_motor_status
925
        call   check_fdd_motor_status
926
        jmp    osloop
926
        jmp    osloop
927
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
927
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
928
;                                                                    ;
928
;                                                                    ;
929
;                      MAIN OS LOOP END                              ;
929
;                      MAIN OS LOOP END                              ;
930
;                                                                    ;
930
;                                                                    ;
931
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
932
 
932
 
933
checkidle:
933
checkidle:
934
        pushad
934
        pushad
935
 
935
 
936
        cmp  [check_idle_semaphore],0
936
        cmp  [check_idle_semaphore],0
937
        jne  no_idle_state
937
        jne  no_idle_state
938
 
938
 
939
        call change_task
939
        call change_task
940
        mov  eax,[idlemem]
940
        mov  eax,[idlemem]
941
        mov  ebx,[timer_ticks] ;[0xfdf0]
941
        mov  ebx,[timer_ticks] ;[0xfdf0]
942
        cmp  eax,ebx
942
        cmp  eax,ebx
943
        jnz  idle_exit
943
        jnz  idle_exit
944
        call _rdtsc
944
        call _rdtsc
945
        mov  ecx,eax
945
        mov  ecx,eax
946
      idle_loop:
946
      idle_loop:
947
        hlt
947
        hlt
948
        cmp  [check_idle_semaphore],0
948
        cmp  [check_idle_semaphore],0
949
        jne  idle_loop_exit
949
        jne  idle_loop_exit
950
        mov  eax,[timer_ticks] ;[0xfdf0]
950
        mov  eax,[timer_ticks] ;[0xfdf0]
951
        cmp  ebx,eax
951
        cmp  ebx,eax
952
        jz   idle_loop
952
        jz   idle_loop
953
      idle_loop_exit:
953
      idle_loop_exit:
954
        mov  [idlemem],eax
954
        mov  [idlemem],eax
955
        call _rdtsc
955
        call _rdtsc
956
        sub  eax,ecx
956
        sub  eax,ecx
957
        mov  ebx,[idleuse]
957
        mov  ebx,[idleuse]
958
        add  ebx,eax
958
        add  ebx,eax
959
        mov  [idleuse],ebx
959
        mov  [idleuse],ebx
960
 
960
 
961
        popad
961
        popad
962
        ret
962
        ret
963
 
963
 
964
      idle_exit:
964
      idle_exit:
965
 
965
 
966
        mov  ebx,[timer_ticks] ;[0xfdf0]
966
        mov  ebx,[timer_ticks] ;[0xfdf0]
967
        mov  [idlemem],ebx
967
        mov  [idlemem],ebx
968
        call change_task
968
        call change_task
969
 
969
 
970
        popad
970
        popad
971
        ret
971
        ret
972
 
972
 
973
      no_idle_state:
973
      no_idle_state:
974
 
974
 
975
        dec  [check_idle_semaphore]
975
        dec  [check_idle_semaphore]
976
 
976
 
977
        mov  ebx,[timer_ticks] ;[0xfdf0]
977
        mov  ebx,[timer_ticks] ;[0xfdf0]
978
        mov  [idlemem],ebx
978
        mov  [idlemem],ebx
979
        call change_task
979
        call change_task
980
 
980
 
981
        popad
981
        popad
982
        ret
982
        ret
983
 
983
 
984
uglobal
984
uglobal
985
  idlemem               dd   0x0
985
  idlemem               dd   0x0
986
  idleuse               dd   0x0
986
  idleuse               dd   0x0
987
  idleusesec            dd   0x0
987
  idleusesec            dd   0x0
988
  check_idle_semaphore  dd   0x0
988
  check_idle_semaphore  dd   0x0
989
endg
989
endg
990
 
990
 
991
 
991
 
992
 
992
 
993
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
993
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
994
;                                                                      ;
994
;                                                                      ;
995
;                   INCLUDED SYSTEM FILES                              ;
995
;                   INCLUDED SYSTEM FILES                              ;
996
;                                                                      ;
996
;                                                                      ;
997
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
997
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
998
 
998
 
999
 
999
 
1000
include "kernel32.inc"
1000
include "kernel32.inc"
1001
 
1001
 
1002
 
1002
 
1003
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1003
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1004
;                                                                      ;
1004
;                                                                      ;
1005
;                       KERNEL FUNCTIONS                               ;
1005
;                       KERNEL FUNCTIONS                               ;
1006
;                                                                      ;
1006
;                                                                      ;
1007
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1007
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1008
 
1008
 
1009
reserve_irqs_ports:
1009
reserve_irqs_ports:
1010
 
1010
 
1011
        pushad
1011
        pushad
1012
 
1012
 
1013
        mov  [irq_owner+4*0], 1    ; timer
1013
        mov  [irq_owner+4*0], 1    ; timer
1014
        mov  [irq_owner+4*1], 1    ; keyboard
1014
        mov  [irq_owner+4*1], 1    ; keyboard
1015
        mov  [irq_owner+4*5], 1    ; sound blaster
1015
        mov  [irq_owner+4*5], 1    ; sound blaster
1016
        mov  [irq_owner+4*6], 1    ; floppy diskette
1016
        mov  [irq_owner+4*6], 1    ; floppy diskette
1017
        mov  [irq_owner+4*13], 1   ; math co-pros
1017
        mov  [irq_owner+4*13], 1   ; math co-pros
1018
        mov  [irq_owner+4*14], 1   ; ide I
1018
        mov  [irq_owner+4*14], 1   ; ide I
1019
        mov  [irq_owner+4*15], 1   ; ide II
1019
        mov  [irq_owner+4*15], 1   ; ide II
1020
 
1020
 
1021
;        movzx eax,byte [0xf604]        ; mouse irq
1021
;        movzx eax,byte [0xf604]        ; mouse irq
1022
;        dec   eax
1022
;        dec   eax
1023
;        add   eax,mouseirqtable
1023
;        add   eax,mouseirqtable
1024
;        movzx eax,byte [eax]
1024
;        movzx eax,byte [eax]
1025
;        shl   eax,2
1025
;        shl   eax,2
1026
;        mov   [irq_owner+eax],byte 1
1026
;        mov   [irq_owner+eax],byte 1
1027
 
1027
 
1028
 
1028
 
1029
                                       ; RESERVE PORTS
1029
                                       ; RESERVE PORTS
1030
        mov   edi,1                    ; 0x00-0x2d
1030
        mov   edi,1                    ; 0x00-0x2d
1031
        mov   [RESERVED_PORTS],edi
1031
        mov   [RESERVED_PORTS],edi
1032
        shl   edi,4
1032
        shl   edi,4
1033
        mov   [RESERVED_PORTS+edi+0],dword 1
1033
        mov   [RESERVED_PORTS+edi+0],dword 1
1034
        mov   [RESERVED_PORTS+edi+4],dword 0x0
1034
        mov   [RESERVED_PORTS+edi+4],dword 0x0
1035
        mov   [RESERVED_PORTS+edi+8],dword 0x2d
1035
        mov   [RESERVED_PORTS+edi+8],dword 0x2d
1036
 
1036
 
1037
        inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
1037
        inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
1038
        mov   edi,[RESERVED_PORTS]
1038
        mov   edi,[RESERVED_PORTS]
1039
        shl   edi,4
1039
        shl   edi,4
1040
        mov   [RESERVED_PORTS+edi+0],dword 1
1040
        mov   [RESERVED_PORTS+edi+0],dword 1
1041
        mov   [RESERVED_PORTS+edi+4],dword 0x30
1041
        mov   [RESERVED_PORTS+edi+4],dword 0x30
1042
        mov   [RESERVED_PORTS+edi+8],dword 0x4d
1042
        mov   [RESERVED_PORTS+edi+8],dword 0x4d
1043
 
1043
 
1044
        inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
1044
        inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
1045
        mov   edi,[RESERVED_PORTS]
1045
        mov   edi,[RESERVED_PORTS]
1046
        shl   edi,4
1046
        shl   edi,4
1047
        mov   [RESERVED_PORTS+edi+0],dword 1
1047
        mov   [RESERVED_PORTS+edi+0],dword 1
1048
        mov   [RESERVED_PORTS+edi+4],dword 0x50
1048
        mov   [RESERVED_PORTS+edi+4],dword 0x50
1049
        mov   [RESERVED_PORTS+edi+8],dword 0xdf
1049
        mov   [RESERVED_PORTS+edi+8],dword 0xdf
1050
 
1050
 
1051
        inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
1051
        inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
1052
        mov   edi,[RESERVED_PORTS]
1052
        mov   edi,[RESERVED_PORTS]
1053
        shl   edi,4
1053
        shl   edi,4
1054
        mov   [RESERVED_PORTS+edi+0],dword 1
1054
        mov   [RESERVED_PORTS+edi+0],dword 1
1055
        mov   [RESERVED_PORTS+edi+4],dword 0xe5
1055
        mov   [RESERVED_PORTS+edi+4],dword 0xe5
1056
        mov   [RESERVED_PORTS+edi+8],dword 0xff
1056
        mov   [RESERVED_PORTS+edi+8],dword 0xff
1057
 
1057
 
1058
 
1058
 
1059
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
1059
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
1060
;        jne   ripl1
1060
;        jne   ripl1
1061
;        inc   dword [0x2d0000]
1061
;        inc   dword [0x2d0000]
1062
;        mov   edi,[0x2d0000]
1062
;        mov   edi,[0x2d0000]
1063
;        shl   edi,4
1063
;        shl   edi,4
1064
;        mov   [0x2d0000+edi+0],dword 1
1064
;        mov   [0x2d0000+edi+0],dword 1
1065
;        mov   [0x2d0000+edi+4],dword 0x3f0
1065
;        mov   [0x2d0000+edi+4],dword 0x3f0
1066
;        mov   [0x2d0000+edi+8],dword 0x3ff
1066
;        mov   [0x2d0000+edi+8],dword 0x3ff
1067
;      ripl1:
1067
;      ripl1:
1068
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
1068
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
1069
;        jne   ripl2
1069
;        jne   ripl2
1070
;        inc   dword [0x2d0000]
1070
;        inc   dword [0x2d0000]
1071
;        mov   edi,[0x2d0000]
1071
;        mov   edi,[0x2d0000]
1072
;        shl   edi,4
1072
;        shl   edi,4
1073
;        mov   [0x2d0000+edi+0],dword 1
1073
;        mov   [0x2d0000+edi+0],dword 1
1074
;        mov   [0x2d0000+edi+4],dword 0x2f0
1074
;        mov   [0x2d0000+edi+4],dword 0x2f0
1075
;        mov   [0x2d0000+edi+8],dword 0x2ff
1075
;        mov   [0x2d0000+edi+8],dword 0x2ff
1076
;      ripl2:
1076
;      ripl2:
1077
 
1077
 
1078
        popad
1078
        popad
1079
        ret
1079
        ret
1080
 
1080
 
1081
iglobal
1081
iglobal
1082
mouseirqtable   db  12    ; ps2
1082
mouseirqtable   db  12    ; ps2
1083
                db  4     ; com1
1083
                db  4     ; com1
1084
                db  3     ; com2
1084
                db  3     ; com2
1085
endg
1085
endg
1086
 
1086
 
1087
setirqreadports:
1087
setirqreadports:
1088
 
1088
 
1089
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1089
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1090
        mov   [irq12read+4],dword 0                  ; end of port list
1090
        mov   [irq12read+4],dword 0                  ; end of port list
1091
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1091
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1092
        mov   [irq04read+4],dword 0                  ; end of port list
1092
        mov   [irq04read+4],dword 0                  ; end of port list
1093
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1093
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1094
        mov   [irq03read+4],dword 0                  ; end of port list
1094
        mov   [irq03read+4],dword 0                  ; end of port list
1095
 
1095
 
1096
        ret
1096
        ret
1097
 
1097
 
1098
iglobal
1098
iglobal
1099
  process_number dd 0x1
1099
  process_number dd 0x1
1100
endg
1100
endg
1101
 
1101
 
1102
set_variables:
1102
set_variables:
1103
 
1103
 
1104
        mov   ecx,0x100                       ; flush port 0x60
1104
        mov   ecx,0x100                       ; flush port 0x60
1105
.fl60:  in    al,0x60
1105
.fl60:  in    al,0x60
1106
        loop  .fl60
1106
        loop  .fl60
1107
        mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
1107
        mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
1108
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
1108
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
1109
        mov   [BTN_COUNT],byte 0                 ; button buffer
1109
        mov   [BTN_COUNT],byte 0                 ; button buffer
1110
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1110
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1111
 
1111
 
1112
        push  eax
1112
        push  eax
1113
        mov   ax,[BOOT_VAR+0x900c]
1113
        mov   ax,[BOOT_VAR+0x900c]
1114
        shr   ax,1
1114
        shr   ax,1
1115
        shl   eax,16
1115
        shl   eax,16
1116
        mov   ax,[BOOT_VAR+0x900A]
1116
        mov   ax,[BOOT_VAR+0x900A]
1117
        shr   ax,1
1117
        shr   ax,1
1118
        mov   [MOUSE_X],eax
1118
        mov   [MOUSE_X],eax
1119
        pop   eax
1119
        pop   eax
1120
 
1120
 
1121
        mov   byte [SB16_Status],0            ; Minazzi Paolo
1121
        mov   byte [SB16_Status],0            ; Minazzi Paolo
1122
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1122
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1123
 
1123
 
1124
     ;!! IP 04.02.2005:
1124
     ;!! IP 04.02.2005:
1125
        mov   [next_usage_update], 100
1125
        mov   [next_usage_update], 100
1126
        mov   byte [DONT_SWITCH], 0 ; change task if possible
1126
        mov   byte [DONT_SWITCH], 0 ; change task if possible
1127
 
1127
 
1128
        ret
1128
        ret
1129
 
1129
 
1130
;* mouse centered - start code- Mario79
1130
;* mouse centered - start code- Mario79
1131
mouse_centered:
1131
mouse_centered:
1132
        push  eax
1132
        push  eax
1133
        mov   eax,[ScreenWidth]
1133
        mov   eax,[ScreenWidth]
1134
        shr   eax,1
1134
        shr   eax,1
1135
        mov   [MOUSE_X],ax
1135
        mov   [MOUSE_X],ax
1136
        mov   eax,[ScreenHeight]
1136
        mov   eax,[ScreenHeight]
1137
        shr   eax,1
1137
        shr   eax,1
1138
        mov   [MOUSE_Y],ax
1138
        mov   [MOUSE_Y],ax
1139
        pop   eax
1139
        pop   eax
1140
        ret
1140
        ret
1141
;* mouse centered - end code- Mario79
1141
;* mouse centered - end code- Mario79
1142
 
1142
 
1143
align 4
1143
align 4
1144
 
1144
 
1145
sys_outport:
1145
sys_outport:
1146
 
1146
 
1147
    mov   edi,ebx          ; separate flag for read / write
1147
    mov   edi,ebx          ; separate flag for read / write
1148
    and   ebx,65535
1148
    and   ebx,65535
1149
 
1149
 
1150
    mov   ecx,[RESERVED_PORTS]
1150
    mov   ecx,[RESERVED_PORTS]
1151
    test  ecx,ecx
1151
    test  ecx,ecx
1152
    jne   sopl8
1152
    jne   sopl8
1153
    mov   [esp+36],dword 1
1153
    mov   [esp+36],dword 1
1154
    ret
1154
    ret
1155
 
1155
 
1156
  sopl8:
1156
  sopl8:
1157
    mov   edx,[TASK_BASE]
1157
    mov   edx,[TASK_BASE]
1158
    mov   edx,[edx+0x4]
1158
    mov   edx,[edx+0x4]
1159
    and   ebx,65535
1159
    and   ebx,65535
1160
    cld
1160
    cld
1161
  sopl1:
1161
  sopl1:
1162
 
1162
 
1163
    mov   esi,ecx
1163
    mov   esi,ecx
1164
    shl   esi,4
1164
    shl   esi,4
1165
    add   esi,RESERVED_PORTS
1165
    add   esi,RESERVED_PORTS
1166
    cmp   edx,[esi+0]
1166
    cmp   edx,[esi+0]
1167
    jne   sopl2
1167
    jne   sopl2
1168
    cmp   ebx,[esi+4]
1168
    cmp   ebx,[esi+4]
1169
    jb    sopl2
1169
    jb    sopl2
1170
    cmp   ebx,[esi+8]
1170
    cmp   ebx,[esi+8]
1171
    jg    sopl2
1171
    jg    sopl2
1172
    jmp   sopl3
1172
    jmp   sopl3
1173
 
1173
 
1174
  sopl2:
1174
  sopl2:
1175
 
1175
 
1176
    dec   ecx
1176
    dec   ecx
1177
    jnz   sopl1
1177
    jnz   sopl1
1178
    mov   [esp+36],dword 1
1178
    mov   [esp+36],dword 1
1179
    ret
1179
    ret
1180
 
1180
 
1181
  sopl3:
1181
  sopl3:
1182
 
1182
 
1183
    test  edi,0x80000000 ; read ?
1183
    test  edi,0x80000000 ; read ?
1184
    jnz   sopl4
1184
    jnz   sopl4
1185
 
1185
 
1186
    mov   dx,bx          ; write
1186
    mov   dx,bx          ; write
1187
    out   dx,al
1187
    out   dx,al
1188
    mov   [esp+36],dword 0
1188
    mov   [esp+36],dword 0
1189
    ret
1189
    ret
1190
 
1190
 
1191
  sopl4:
1191
  sopl4:
1192
 
1192
 
1193
    mov   dx,bx          ; read
1193
    mov   dx,bx          ; read
1194
    in    al,dx
1194
    in    al,dx
1195
    and   eax,0xff
1195
    and   eax,0xff
1196
    mov   [esp+36],dword 0
1196
    mov   [esp+36],dword 0
1197
    mov   [esp+24],eax
1197
    mov   [esp+24],eax
1198
    ret
1198
    ret
1199
 
1199
 
1200
 
1200
 
1201
 
1201
 
1202
align 4
1202
align 4
1203
sys_sb16:
1203
sys_sb16:
1204
 
1204
 
1205
     cmp  word [sb16],word 0
1205
     cmp  word [sb16],word 0
1206
     jnz  sb16l1
1206
     jnz  sb16l1
1207
     mov  [esp+36],dword 1
1207
     mov  [esp+36],dword 1
1208
     ret
1208
     ret
1209
   sb16l1:
1209
   sb16l1:
1210
     mov  [esp+36],dword 0
1210
     mov  [esp+36],dword 0
1211
     cmp  eax,1    ; set volume - main
1211
     cmp  eax,1    ; set volume - main
1212
     jnz  sb16l2
1212
     jnz  sb16l2
1213
     mov  dx,word [sb16]
1213
     mov  dx,word [sb16]
1214
     add  dx,4
1214
     add  dx,4
1215
     mov  al,0x22
1215
     mov  al,0x22
1216
     out  dx,al
1216
     out  dx,al
1217
     mov  esi,1
1217
     mov  esi,1
1218
     call delay_ms
1218
     call delay_ms
1219
     mov  eax,ebx
1219
     mov  eax,ebx
1220
     inc  edx
1220
     inc  edx
1221
     out  dx,al
1221
     out  dx,al
1222
     ret
1222
     ret
1223
   sb16l2:
1223
   sb16l2:
1224
 
1224
 
1225
     cmp  eax,2    ; set volume - cd
1225
     cmp  eax,2    ; set volume - cd
1226
     jnz  sb16l3
1226
     jnz  sb16l3
1227
     mov  dx,word [sb16]
1227
     mov  dx,word [sb16]
1228
     add  dx,4
1228
     add  dx,4
1229
     mov  al,0x28
1229
     mov  al,0x28
1230
     out  dx,al
1230
     out  dx,al
1231
     mov  esi,1
1231
     mov  esi,1
1232
     call delay_ms
1232
     call delay_ms
1233
     mov  eax,ebx
1233
     mov  eax,ebx
1234
     add  edx,1
1234
     add  edx,1
1235
     out  dx,al
1235
     out  dx,al
1236
     ret
1236
     ret
1237
   sb16l3:
1237
   sb16l3:
1238
      mov  [esp+36],dword 2
1238
      mov  [esp+36],dword 2
1239
      ret
1239
      ret
1240
 
1240
 
1241
 
1241
 
1242
align 4
1242
align 4
1243
 
1243
 
1244
sys_sb16II:
1244
sys_sb16II:
1245
 
1245
 
1246
     cmp  word [sb16],word 0
1246
     cmp  word [sb16],word 0
1247
     jnz  IIsb16l1
1247
     jnz  IIsb16l1
1248
     mov  [esp+36],dword 1
1248
     mov  [esp+36],dword 1
1249
     ret
1249
     ret
1250
   IIsb16l1:
1250
   IIsb16l1:
1251
 
1251
 
1252
     cmp  eax,1    ; set volume - main
1252
     cmp  eax,1    ; set volume - main
1253
     jnz  IIsb16l2
1253
     jnz  IIsb16l2
1254
     ; L
1254
     ; L
1255
     mov  dx,word [sb16]
1255
     mov  dx,word [sb16]
1256
     add  dx,4
1256
     add  dx,4
1257
     mov  al,0x30
1257
     mov  al,0x30
1258
     out  dx,al
1258
     out  dx,al
1259
     mov  eax,ebx
1259
     mov  eax,ebx
1260
     inc  edx
1260
     inc  edx
1261
     out  dx,al
1261
     out  dx,al
1262
     ; R
1262
     ; R
1263
     mov  dx,word [sb16]
1263
     mov  dx,word [sb16]
1264
     add  dx,4
1264
     add  dx,4
1265
     mov  al,0x31
1265
     mov  al,0x31
1266
     out  dx,al
1266
     out  dx,al
1267
     mov  eax,ebx
1267
     mov  eax,ebx
1268
     inc  edx
1268
     inc  edx
1269
     out  dx,al
1269
     out  dx,al
1270
     mov  [esp+36],dword 0
1270
     mov  [esp+36],dword 0
1271
     ret
1271
     ret
1272
   IIsb16l2:
1272
   IIsb16l2:
1273
 
1273
 
1274
     cmp  eax,2    ; set volume - cd
1274
     cmp  eax,2    ; set volume - cd
1275
     jnz  IIsb16l3
1275
     jnz  IIsb16l3
1276
     ; L
1276
     ; L
1277
     mov  dx,word [sb16]
1277
     mov  dx,word [sb16]
1278
     add  dx,4
1278
     add  dx,4
1279
     mov  al,0x36
1279
     mov  al,0x36
1280
     out  dx,al
1280
     out  dx,al
1281
     mov  eax,ebx
1281
     mov  eax,ebx
1282
     inc  edx
1282
     inc  edx
1283
     out  dx,al
1283
     out  dx,al
1284
     ; R
1284
     ; R
1285
     mov  dx,word [sb16]
1285
     mov  dx,word [sb16]
1286
     add  dx,4
1286
     add  dx,4
1287
     mov  al,0x37
1287
     mov  al,0x37
1288
     out  dx,al
1288
     out  dx,al
1289
     mov  eax,ebx
1289
     mov  eax,ebx
1290
     inc  edx
1290
     inc  edx
1291
     out  dx,al
1291
     out  dx,al
1292
     mov  [esp+36],dword 0
1292
     mov  [esp+36],dword 0
1293
     ret
1293
     ret
1294
   IIsb16l3:
1294
   IIsb16l3:
1295
 
1295
 
1296
     mov  [esp+36],dword 2
1296
     mov  [esp+36],dword 2
1297
     ret
1297
     ret
1298
 
1298
 
1299
 
1299
 
1300
display_number:
1300
display_number:
1301
 
1301
 
1302
; eax = print type, al=0 -> ebx is number
1302
; eax = print type, al=0 -> ebx is number
1303
;                   al=1 -> ebx is pointer
1303
;                   al=1 -> ebx is pointer
1304
;                   ah=0 -> display decimal
1304
;                   ah=0 -> display decimal
1305
;                   ah=1 -> display hexadecimal
1305
;                   ah=1 -> display hexadecimal
1306
;                   ah=2 -> display binary
1306
;                   ah=2 -> display binary
1307
;                   eax bits 16-21 = number of digits to display (0-32)
1307
;                   eax bits 16-21 = number of digits to display (0-32)
1308
;                   eax bits 22-31 = reserved
1308
;                   eax bits 22-31 = reserved
1309
;
1309
;
1310
; ebx = number or pointer
1310
; ebx = number or pointer
1311
; ecx = x shl 16 + y
1311
; ecx = x shl 16 + y
1312
; edx = color
1312
; edx = color
1313
        xor     edi, edi
1313
        xor     edi, edi
1314
display_number_force:
1314
display_number_force:
1315
 
1315
 
1316
     cmp   eax,0xffff            ; length > 0 ?
1316
     cmp   eax,0xffff            ; length > 0 ?
1317
     jge   cont_displ
1317
     jge   cont_displ
1318
     ret
1318
     ret
1319
   cont_displ:
1319
   cont_displ:
1320
 
1320
 
1321
     cmp   eax,61*0x10000        ; length <= 60 ?
1321
     cmp   eax,61*0x10000        ; length <= 60 ?
1322
     jb    cont_displ2
1322
     jb    cont_displ2
1323
     ret
1323
     ret
1324
   cont_displ2:
1324
   cont_displ2:
1325
 
1325
 
1326
     pushad
1326
     pushad
1327
 
1327
 
1328
     cmp   al,1                  ; ecx is a pointer ?
1328
     cmp   al,1                  ; ecx is a pointer ?
1329
     jne   displnl1
1329
     jne   displnl1
1330
     mov   ebx,[ebx+std_application_base_address]
1330
     mov   ebx,[ebx+std_application_base_address]
1331
   displnl1:
1331
   displnl1:
1332
     sub   esp,64
1332
     sub   esp,64
1333
 
1333
 
1334
     cmp   ah,0                  ; DECIMAL
1334
     cmp   ah,0                  ; DECIMAL
1335
     jne   no_display_desnum
1335
     jne   no_display_desnum
1336
     shr   eax,16
1336
     shr   eax,16
1337
     and   eax,0x3f
1337
     and   eax,0x3f
1338
     push  eax
1338
     push  eax
1339
     mov   edi,esp
1339
     mov   edi,esp
1340
     add   edi,4+64-1
1340
     add   edi,4+64-1
1341
     mov   ecx,eax
1341
     mov   ecx,eax
1342
     mov   eax,ebx
1342
     mov   eax,ebx
1343
     mov   ebx,10
1343
     mov   ebx,10
1344
   d_desnum:
1344
   d_desnum:
1345
     xor   edx,edx
1345
     xor   edx,edx
1346
     div   ebx
1346
     div   ebx
1347
     add   dl,48
1347
     add   dl,48
1348
     mov   [edi],dl
1348
     mov   [edi],dl
1349
     dec   edi
1349
     dec   edi
1350
     loop  d_desnum
1350
     loop  d_desnum
1351
     pop   eax
1351
     pop   eax
1352
     call  draw_num_text
1352
     call  draw_num_text
1353
     add   esp,64
1353
     add   esp,64
1354
     popad
1354
     popad
1355
     ret
1355
     ret
1356
   no_display_desnum:
1356
   no_display_desnum:
1357
 
1357
 
1358
     cmp   ah,0x01               ; HEXADECIMAL
1358
     cmp   ah,0x01               ; HEXADECIMAL
1359
     jne   no_display_hexnum
1359
     jne   no_display_hexnum
1360
     shr   eax,16
1360
     shr   eax,16
1361
     and   eax,0x3f
1361
     and   eax,0x3f
1362
     push  eax
1362
     push  eax
1363
     mov   edi,esp
1363
     mov   edi,esp
1364
     add   edi,4+64-1
1364
     add   edi,4+64-1
1365
     mov   ecx,eax
1365
     mov   ecx,eax
1366
     mov   eax,ebx
1366
     mov   eax,ebx
1367
     mov   ebx,16
1367
     mov   ebx,16
1368
   d_hexnum:
1368
   d_hexnum:
1369
     xor   edx,edx
1369
     xor   edx,edx
1370
     div   ebx
1370
     div   ebx
1371
     add   edx,hexletters
1371
     add   edx,hexletters
1372
     mov   dl,[edx]
1372
     mov   dl,[edx]
1373
     mov   [edi],dl
1373
     mov   [edi],dl
1374
     dec   edi
1374
     dec   edi
1375
     loop  d_hexnum
1375
     loop  d_hexnum
1376
     pop   eax
1376
     pop   eax
1377
     call  draw_num_text
1377
     call  draw_num_text
1378
     add   esp,64
1378
     add   esp,64
1379
     popad
1379
     popad
1380
     ret
1380
     ret
1381
   no_display_hexnum:
1381
   no_display_hexnum:
1382
 
1382
 
1383
     cmp   ah,0x02               ; BINARY
1383
     cmp   ah,0x02               ; BINARY
1384
     jne   no_display_binnum
1384
     jne   no_display_binnum
1385
     shr   eax,16
1385
     shr   eax,16
1386
     and   eax,0x3f
1386
     and   eax,0x3f
1387
     push  eax
1387
     push  eax
1388
     mov   edi,esp
1388
     mov   edi,esp
1389
     add   edi,4+64-1
1389
     add   edi,4+64-1
1390
     mov   ecx,eax
1390
     mov   ecx,eax
1391
     mov   eax,ebx
1391
     mov   eax,ebx
1392
     mov   ebx,2
1392
     mov   ebx,2
1393
   d_binnum:
1393
   d_binnum:
1394
     xor   edx,edx
1394
     xor   edx,edx
1395
     div   ebx
1395
     div   ebx
1396
     add   dl,48
1396
     add   dl,48
1397
     mov   [edi],dl
1397
     mov   [edi],dl
1398
     dec   edi
1398
     dec   edi
1399
     loop  d_binnum
1399
     loop  d_binnum
1400
     pop   eax
1400
     pop   eax
1401
     call  draw_num_text
1401
     call  draw_num_text
1402
     add   esp,64
1402
     add   esp,64
1403
     popad
1403
     popad
1404
     ret
1404
     ret
1405
   no_display_binnum:
1405
   no_display_binnum:
1406
 
1406
 
1407
     add   esp,64
1407
     add   esp,64
1408
     popad
1408
     popad
1409
     ret
1409
     ret
1410
 
1410
 
1411
 
1411
 
1412
draw_num_text:
1412
draw_num_text:
1413
 
1413
 
1414
     ; dtext
1414
     ; dtext
1415
     ;
1415
     ;
1416
     ; eax x & y
1416
     ; eax x & y
1417
     ; ebx color
1417
     ; ebx color
1418
     ; ecx start of text
1418
     ; ecx start of text
1419
     ; edx length
1419
     ; edx length
1420
     ; edi 1 force
1420
     ; edi 1 force
1421
 
1421
 
1422
;        mov     edi,[CURRENT_TASK]
1422
;        mov     edi,[CURRENT_TASK]
1423
;        shl     edi,8
1423
;        shl     edi,8
1424
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1424
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1425
;        rol     eax,16
1425
;        rol     eax,16
1426
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1426
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1427
;        rol     eax,16
1427
;        rol     eax,16
1428
 
1428
 
1429
     mov   edx,eax
1429
     mov   edx,eax
1430
     mov   ecx,64+4
1430
     mov   ecx,64+4
1431
     sub   ecx,eax
1431
     sub   ecx,eax
1432
     add   ecx,esp
1432
     add   ecx,esp
1433
     mov   eax,[esp+64+32-8+4]
1433
     mov   eax,[esp+64+32-8+4]
1434
     push  edx                       ; add window start x & y
1434
     push  edx                       ; add window start x & y
1435
     mov   edx,[TASK_BASE]
1435
     mov   edx,[TASK_BASE]
1436
 
1436
 
1437
     mov   edi,[CURRENT_TASK]
1437
     mov   edi,[CURRENT_TASK]
1438
     shl   edi,8
1438
     shl   edi,8
1439
 
1439
 
1440
     mov   ebx,[edx-twdw+WDATA.box.left]
1440
     mov   ebx,[edx-twdw+WDATA.box.left]
1441
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1441
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1442
     shl   ebx,16
1442
     shl   ebx,16
1443
     add   ebx,[edx-twdw+WDATA.box.top]
1443
     add   ebx,[edx-twdw+WDATA.box.top]
1444
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1444
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1445
     add   eax,ebx
1445
     add   eax,ebx
1446
     pop   edx
1446
     pop   edx
1447
     mov   ebx,[esp+64+32-12+4]
1447
     mov   ebx,[esp+64+32-12+4]
1448
        and     ebx, not 0x80000000     ; force counted string
1448
        and     ebx, not 0x80000000     ; force counted string
1449
        mov     esi, [esp+64+4+4]
1449
        mov     esi, [esp+64+4+4]
1450
        mov     edi, [esp+64+4]
1450
        mov     edi, [esp+64+4]
1451
     jmp   dtext
1451
     jmp   dtext
1452
 
1452
 
1453
read_string:
1453
read_string:
1454
 
1454
 
1455
    ; eax  read_area
1455
    ; eax  read_area
1456
    ; ebx  color of letter
1456
    ; ebx  color of letter
1457
    ; ecx  color of background
1457
    ; ecx  color of background
1458
    ; edx  number of letters to read
1458
    ; edx  number of letters to read
1459
    ; esi  [x start]*65536 + [y_start]
1459
    ; esi  [x start]*65536 + [y_start]
1460
 
1460
 
1461
    ret
1461
    ret
1462
 
1462
 
1463
 
1463
 
1464
align 4
1464
align 4
1465
 
1465
 
1466
sys_setup:
1466
sys_setup:
1467
 
1467
 
1468
; 1=roland mpu midi base , base io address
1468
; 1=roland mpu midi base , base io address
1469
; 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
1470
; 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
1471
; 4=sb16 base , base io address
1471
; 4=sb16 base , base io address
1472
; 5=system language, 1eng 2fi 3ger 4rus
1472
; 5=system language, 1eng 2fi 3ger 4rus
1473
; 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
1474
; 8=fat32 partition in hd
1474
; 8=fat32 partition in hd
1475
; 9
1475
; 9
1476
; 10 = sound dma channel
1476
; 10 = sound dma channel
1477
; 11 = enable lba read
1477
; 11 = enable lba read
1478
; 12 = enable pci access
1478
; 12 = enable pci access
1479
 
1479
 
1480
 
1480
 
1481
     mov  [esp+36],dword 0
1481
     mov  [esp+36],dword 0
1482
     cmp  eax,1                      ; MIDI
1482
     cmp  eax,1                      ; MIDI
1483
     jnz  nsyse1
1483
     jnz  nsyse1
1484
     cmp  ebx,0x100
1484
     cmp  ebx,0x100
1485
     jb   nsyse1
1485
     jb   nsyse1
1486
     mov  edx,65535
1486
     mov  edx,65535
1487
     cmp  edx,ebx
1487
     cmp  edx,ebx
1488
     jb   nsyse1
1488
     jb   nsyse1
1489
     mov  [midi_base],bx
1489
     mov  [midi_base],bx
1490
     mov  word [mididp],bx
1490
     mov  word [mididp],bx
1491
     inc  bx
1491
     inc  bx
1492
     mov  word [midisp],bx
1492
     mov  word [midisp],bx
1493
     ret
1493
     ret
1494
 
1494
 
1495
iglobal
1495
iglobal
1496
midi_base dw 0
1496
midi_base dw 0
1497
endg
1497
endg
1498
 
1498
 
1499
   nsyse1:
1499
   nsyse1:
1500
 
1500
 
1501
     cmp  eax,2                      ; KEYBOARD
1501
     cmp  eax,2                      ; KEYBOARD
1502
     jnz  nsyse2
1502
     jnz  nsyse2
1503
     cmp  ebx,1
1503
     cmp  ebx,1
1504
     jnz  kbnobase
1504
     jnz  kbnobase
1505
     mov  edi,[TASK_BASE]
1505
     mov  edi,[TASK_BASE]
1506
     add  ecx,[edi+TASKDATA.mem_start]
1506
     add  ecx,[edi+TASKDATA.mem_start]
1507
     mov  eax,ecx
1507
     mov  eax,ecx
1508
     mov  ebx,keymap
1508
     mov  ebx,keymap
1509
     mov  ecx,128
1509
     mov  ecx,128
1510
     call memmove
1510
     call memmove
1511
     ret
1511
     ret
1512
   kbnobase:
1512
   kbnobase:
1513
     cmp  ebx,2
1513
     cmp  ebx,2
1514
     jnz  kbnoshift
1514
     jnz  kbnoshift
1515
     mov  edi,[TASK_BASE]
1515
     mov  edi,[TASK_BASE]
1516
     add  ecx,[edi+TASKDATA.mem_start]
1516
     add  ecx,[edi+TASKDATA.mem_start]
1517
     mov  eax,ecx
1517
     mov  eax,ecx
1518
     mov  ebx,keymap_shift
1518
     mov  ebx,keymap_shift
1519
     mov  ecx,128
1519
     mov  ecx,128
1520
     call memmove
1520
     call memmove
1521
     ret
1521
     ret
1522
   kbnoshift:
1522
   kbnoshift:
1523
     cmp  ebx,3
1523
     cmp  ebx,3
1524
     jne  kbnoalt
1524
     jne  kbnoalt
1525
     mov  edi,[TASK_BASE]
1525
     mov  edi,[TASK_BASE]
1526
     add  ecx,[edi+TASKDATA.mem_start]
1526
     add  ecx,[edi+TASKDATA.mem_start]
1527
     mov  eax,ecx
1527
     mov  eax,ecx
1528
     mov  ebx,keymap_alt
1528
     mov  ebx,keymap_alt
1529
     mov  ecx,128
1529
     mov  ecx,128
1530
     call memmove
1530
     call memmove
1531
     ret
1531
     ret
1532
   kbnoalt:
1532
   kbnoalt:
1533
     cmp  ebx,9
1533
     cmp  ebx,9
1534
     jnz  kbnocountry
1534
     jnz  kbnocountry
1535
     mov  word [keyboard],cx
1535
     mov  word [keyboard],cx
1536
     ret
1536
     ret
1537
   kbnocountry:
1537
   kbnocountry:
1538
     mov  [esp+36],dword 1
1538
     mov  [esp+36],dword 1
1539
     ret
1539
     ret
1540
   nsyse2:
1540
   nsyse2:
1541
     cmp  eax,3                      ; CD
1541
     cmp  eax,3                      ; CD
1542
     jnz  nsyse3
1542
     jnz  nsyse3
1543
     test ebx,ebx
1543
     test ebx,ebx
1544
     jz   nosesl
1544
     jz   nosesl
1545
     cmp  ebx, 4
1545
     cmp  ebx, 4
1546
     ja   nosesl
1546
     ja   nosesl
1547
     mov  [cd_base],bl
1547
     mov  [cd_base],bl
1548
     cmp  ebx,1
1548
     cmp  ebx,1
1549
     jnz  noprma
1549
     jnz  noprma
1550
     mov  [cdbase],0x1f0
1550
     mov  [cdbase],0x1f0
1551
     mov  [cdid],0xa0
1551
     mov  [cdid],0xa0
1552
   noprma:
1552
   noprma:
1553
     cmp  ebx,2
1553
     cmp  ebx,2
1554
     jnz  noprsl
1554
     jnz  noprsl
1555
     mov  [cdbase],0x1f0
1555
     mov  [cdbase],0x1f0
1556
     mov  [cdid],0xb0
1556
     mov  [cdid],0xb0
1557
   noprsl:
1557
   noprsl:
1558
     cmp  ebx,3
1558
     cmp  ebx,3
1559
     jnz  nosema
1559
     jnz  nosema
1560
     mov  [cdbase],0x170
1560
     mov  [cdbase],0x170
1561
     mov  [cdid],0xa0
1561
     mov  [cdid],0xa0
1562
   nosema:
1562
   nosema:
1563
     cmp  ebx,4
1563
     cmp  ebx,4
1564
     jnz  nosesl
1564
     jnz  nosesl
1565
     mov  [cdbase],0x170
1565
     mov  [cdbase],0x170
1566
     mov  [cdid],0xb0
1566
     mov  [cdid],0xb0
1567
   nosesl:
1567
   nosesl:
1568
     ret
1568
     ret
1569
 
1569
 
1570
cd_base db 0
1570
cd_base db 0
1571
 
1571
 
1572
   nsyse3:
1572
   nsyse3:
1573
 
1573
 
1574
     cmp  eax,4                      ; SB
1574
     cmp  eax,4                      ; SB
1575
     jnz  nsyse4
1575
     jnz  nsyse4
1576
     cmp  ebx,0x100
1576
     cmp  ebx,0x100
1577
     jb   nsyse4
1577
     jb   nsyse4
1578
     mov  edx,65535
1578
     mov  edx,65535
1579
     cmp  edx,ebx
1579
     cmp  edx,ebx
1580
     jb   nsyse4
1580
     jb   nsyse4
1581
     mov  word [sb16],bx
1581
     mov  word [sb16],bx
1582
     ret
1582
     ret
1583
   nsyse4:
1583
   nsyse4:
1584
 
1584
 
1585
     cmp  eax,5                      ; SYSTEM LANGUAGE
1585
     cmp  eax,5                      ; SYSTEM LANGUAGE
1586
     jnz  nsyse5
1586
     jnz  nsyse5
1587
     mov  [syslang],ebx
1587
     mov  [syslang],ebx
1588
     ret
1588
     ret
1589
   nsyse5:
1589
   nsyse5:
1590
 
1590
 
1591
     cmp  eax,7                      ; HD BASE
1591
     cmp  eax,7                      ; HD BASE
1592
     jne  nsyse7
1592
     jne  nsyse7
1593
     test ebx,ebx
1593
     test ebx,ebx
1594
     jz   nosethd
1594
     jz   nosethd
1595
     cmp  ebx,4
1595
     cmp  ebx,4
1596
     ja   nosethd
1596
     ja   nosethd
1597
     mov  [hd_base],bl
1597
     mov  [hd_base],bl
1598
     cmp  ebx,1
1598
     cmp  ebx,1
1599
     jnz  noprmahd
1599
     jnz  noprmahd
1600
     mov  [hdbase],0x1f0
1600
     mov  [hdbase],0x1f0
1601
     mov  [hdid],0x0
1601
     mov  [hdid],0x0
1602
     mov  [hdpos],1
1602
     mov  [hdpos],1
1603
;     call set_FAT32_variables
1603
;     call set_FAT32_variables
1604
   noprmahd:
1604
   noprmahd:
1605
     cmp  ebx,2
1605
     cmp  ebx,2
1606
     jnz  noprslhd
1606
     jnz  noprslhd
1607
     mov  [hdbase],0x1f0
1607
     mov  [hdbase],0x1f0
1608
     mov  [hdid],0x10
1608
     mov  [hdid],0x10
1609
     mov  [hdpos],2
1609
     mov  [hdpos],2
1610
;     call set_FAT32_variables
1610
;     call set_FAT32_variables
1611
   noprslhd:
1611
   noprslhd:
1612
     cmp  ebx,3
1612
     cmp  ebx,3
1613
     jnz  nosemahd
1613
     jnz  nosemahd
1614
     mov  [hdbase],0x170
1614
     mov  [hdbase],0x170
1615
     mov  [hdid],0x0
1615
     mov  [hdid],0x0
1616
     mov  [hdpos],3
1616
     mov  [hdpos],3
1617
;     call set_FAT32_variables
1617
;     call set_FAT32_variables
1618
   nosemahd:
1618
   nosemahd:
1619
     cmp  ebx,4
1619
     cmp  ebx,4
1620
     jnz  noseslhd
1620
     jnz  noseslhd
1621
     mov  [hdbase],0x170
1621
     mov  [hdbase],0x170
1622
     mov  [hdid],0x10
1622
     mov  [hdid],0x10
1623
     mov  [hdpos],4
1623
     mov  [hdpos],4
1624
;     call set_FAT32_variables
1624
;     call set_FAT32_variables
1625
   noseslhd:
1625
   noseslhd:
1626
    call  reserve_hd1
1626
    call  reserve_hd1
1627
    call  reserve_hd_channel
1627
    call  reserve_hd_channel
1628
    call  free_hd_channel
1628
    call  free_hd_channel
1629
    mov   [hd1_status],0        ; free
1629
    mov   [hd1_status],0        ; free
1630
   nosethd:
1630
   nosethd:
1631
     ret
1631
     ret
1632
 
1632
 
1633
iglobal
1633
iglobal
1634
hd_base db 0
1634
hd_base db 0
1635
endg
1635
endg
1636
 
1636
 
1637
   nsyse7:
1637
   nsyse7:
1638
 
1638
 
1639
     cmp  eax,8                      ; HD PARTITION
1639
     cmp  eax,8                      ; HD PARTITION
1640
     jne  nsyse8
1640
     jne  nsyse8
1641
     mov  [fat32part],ebx
1641
     mov  [fat32part],ebx
1642
;     call set_FAT32_variables
1642
;     call set_FAT32_variables
1643
    call  reserve_hd1
1643
    call  reserve_hd1
1644
    call  reserve_hd_channel
1644
    call  reserve_hd_channel
1645
    call  free_hd_channel
1645
    call  free_hd_channel
1646
     pusha
1646
     pusha
1647
     call  choice_necessity_partition_1
1647
     call  choice_necessity_partition_1
1648
     popa
1648
     popa
1649
    mov   [hd1_status],0        ; free
1649
    mov   [hd1_status],0        ; free
1650
     ret
1650
     ret
1651
   nsyse8:
1651
   nsyse8:
1652
 
1652
 
1653
     cmp  eax,10                     ; SOUND DMA CHANNEL
1653
     cmp  eax,10                     ; SOUND DMA CHANNEL
1654
     jne  no_set_sound_dma
1654
     jne  no_set_sound_dma
1655
     cmp  ebx,3
1655
     cmp  ebx,3
1656
     ja   sys_setup_err
1656
     ja   sys_setup_err
1657
     mov  [sound_dma],ebx
1657
     mov  [sound_dma],ebx
1658
     ret
1658
     ret
1659
   no_set_sound_dma:
1659
   no_set_sound_dma:
1660
 
1660
 
1661
     cmp  eax,11                     ; ENABLE LBA READ
1661
     cmp  eax,11                     ; ENABLE LBA READ
1662
     jne  no_set_lba_read
1662
     jne  no_set_lba_read
1663
     and  ebx,1
1663
     and  ebx,1
1664
     mov  [lba_read_enabled],ebx
1664
     mov  [lba_read_enabled],ebx
1665
     ret
1665
     ret
1666
   no_set_lba_read:
1666
   no_set_lba_read:
1667
 
1667
 
1668
     cmp  eax,12                     ; ENABLE PCI ACCESS
1668
     cmp  eax,12                     ; ENABLE PCI ACCESS
1669
     jne  no_set_pci_access
1669
     jne  no_set_pci_access
1670
     and  ebx,1
1670
     and  ebx,1
1671
     mov  [pci_access_enabled],ebx
1671
     mov  [pci_access_enabled],ebx
1672
     ret
1672
     ret
1673
   no_set_pci_access:
1673
   no_set_pci_access:
1674
 
1674
 
1675
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1675
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1676
include 'vmodeint.inc'
1676
include 'vmodeint.inc'
1677
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1677
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1678
 
1678
 
1679
sys_setup_err:
1679
sys_setup_err:
1680
     mov  [esp+36],dword -1
1680
     mov  [esp+36],dword -1
1681
     ret
1681
     ret
1682
 
1682
 
1683
align 4
1683
align 4
1684
 
1684
 
1685
sys_getsetup:
1685
sys_getsetup:
1686
 
1686
 
1687
; 1=roland mpu midi base , base io address
1687
; 1=roland mpu midi base , base io address
1688
; 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
1689
; 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
1690
; 4=sb16 base , base io address
1690
; 4=sb16 base , base io address
1691
; 5=system language, 1eng 2fi 3ger 4rus
1691
; 5=system language, 1eng 2fi 3ger 4rus
1692
; 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
1693
; 8=fat32 partition in hd
1693
; 8=fat32 partition in hd
1694
; 9=get hs timer tic
1694
; 9=get hs timer tic
1695
 
1695
 
1696
     cmp  eax,1
1696
     cmp  eax,1
1697
     jne  ngsyse1
1697
     jne  ngsyse1
1698
     movzx eax,[midi_base]
1698
     movzx eax,[midi_base]
1699
     mov  [esp+36],eax
1699
     mov  [esp+36],eax
1700
     ret
1700
     ret
1701
   ngsyse1:
1701
   ngsyse1:
1702
 
1702
 
1703
     cmp  eax,2
1703
     cmp  eax,2
1704
     jne  ngsyse2
1704
     jne  ngsyse2
1705
     cmp  ebx,1
1705
     cmp  ebx,1
1706
     jnz  kbnobaseret
1706
     jnz  kbnobaseret
1707
     mov  edi,[TASK_BASE]
1707
     mov  edi,[TASK_BASE]
1708
     add  ecx,[edi+TASKDATA.mem_start]
1708
     add  ecx,[edi+TASKDATA.mem_start]
1709
     mov  ebx,ecx
1709
     mov  ebx,ecx
1710
     mov  eax,keymap
1710
     mov  eax,keymap
1711
     mov  ecx,128
1711
     mov  ecx,128
1712
     call memmove
1712
     call memmove
1713
     ret
1713
     ret
1714
   kbnobaseret:
1714
   kbnobaseret:
1715
     cmp  ebx,2
1715
     cmp  ebx,2
1716
     jnz  kbnoshiftret
1716
     jnz  kbnoshiftret
1717
     mov  edi,[TASK_BASE]
1717
     mov  edi,[TASK_BASE]
1718
     add  ecx,[edi+TASKDATA.mem_start]
1718
     add  ecx,[edi+TASKDATA.mem_start]
1719
     mov  ebx,ecx
1719
     mov  ebx,ecx
1720
     mov  eax,keymap_shift
1720
     mov  eax,keymap_shift
1721
     mov  ecx,128
1721
     mov  ecx,128
1722
     call memmove
1722
     call memmove
1723
     ret
1723
     ret
1724
   kbnoshiftret:
1724
   kbnoshiftret:
1725
     cmp  ebx,3
1725
     cmp  ebx,3
1726
     jne  kbnoaltret
1726
     jne  kbnoaltret
1727
     mov  edi,[TASK_BASE]
1727
     mov  edi,[TASK_BASE]
1728
     add  ecx,[edi+TASKDATA.mem_start]
1728
     add  ecx,[edi+TASKDATA.mem_start]
1729
     mov  ebx,ecx
1729
     mov  ebx,ecx
1730
     mov  eax,keymap_alt
1730
     mov  eax,keymap_alt
1731
     mov  ecx,128
1731
     mov  ecx,128
1732
     call memmove
1732
     call memmove
1733
     ret
1733
     ret
1734
   kbnoaltret:
1734
   kbnoaltret:
1735
     cmp  ebx,9
1735
     cmp  ebx,9
1736
     jnz  ngsyse2
1736
     jnz  ngsyse2
1737
     movzx eax,word [keyboard]
1737
     movzx eax,word [keyboard]
1738
     mov  [esp+36],eax
1738
     mov  [esp+36],eax
1739
     ret
1739
     ret
1740
   ngsyse2:
1740
   ngsyse2:
1741
 
1741
 
1742
     cmp  eax,3
1742
     cmp  eax,3
1743
     jnz  ngsyse3
1743
     jnz  ngsyse3
1744
     movzx eax,[cd_base]
1744
     movzx eax,[cd_base]
1745
     mov  [esp+36],eax
1745
     mov  [esp+36],eax
1746
     ret
1746
     ret
1747
   ngsyse3:
1747
   ngsyse3:
1748
 
1748
 
1749
     cmp  eax,4
1749
     cmp  eax,4
1750
     jne  ngsyse4
1750
     jne  ngsyse4
1751
     mov  eax,[sb16]
1751
     mov  eax,[sb16]
1752
     mov  [esp+36],eax
1752
     mov  [esp+36],eax
1753
     ret
1753
     ret
1754
   ngsyse4:
1754
   ngsyse4:
1755
 
1755
 
1756
     cmp  eax,5
1756
     cmp  eax,5
1757
     jnz  ngsyse5
1757
     jnz  ngsyse5
1758
     mov  eax,[syslang]
1758
     mov  eax,[syslang]
1759
     mov  [esp+36],eax
1759
     mov  [esp+36],eax
1760
     ret
1760
     ret
1761
   ngsyse5:
1761
   ngsyse5:
1762
     cmp  eax,7
1762
     cmp  eax,7
1763
     jnz  ngsyse7
1763
     jnz  ngsyse7
1764
     movzx eax,[hd_base]
1764
     movzx eax,[hd_base]
1765
     mov  [esp+36],eax
1765
     mov  [esp+36],eax
1766
     ret
1766
     ret
1767
   ngsyse7:
1767
   ngsyse7:
1768
     cmp  eax,8
1768
     cmp  eax,8
1769
     jnz  ngsyse8
1769
     jnz  ngsyse8
1770
     mov eax,[fat32part]
1770
     mov eax,[fat32part]
1771
     mov  [esp+36],eax
1771
     mov  [esp+36],eax
1772
     ret
1772
     ret
1773
   ngsyse8:
1773
   ngsyse8:
1774
     cmp  eax,9
1774
     cmp  eax,9
1775
     jne  ngsyse9
1775
     jne  ngsyse9
1776
     mov  eax,[timer_ticks] ;[0xfdf0]
1776
     mov  eax,[timer_ticks] ;[0xfdf0]
1777
     mov  [esp+36],eax
1777
     mov  [esp+36],eax
1778
     ret
1778
     ret
1779
   ngsyse9:
1779
   ngsyse9:
1780
     cmp  eax,10
1780
     cmp  eax,10
1781
     jnz  ngsyse10
1781
     jnz  ngsyse10
1782
     mov eax,[sound_dma]
1782
     mov eax,[sound_dma]
1783
     mov  [esp+36],eax
1783
     mov  [esp+36],eax
1784
     ret
1784
     ret
1785
   ngsyse10:
1785
   ngsyse10:
1786
     cmp  eax,11
1786
     cmp  eax,11
1787
     jnz  ngsyse11
1787
     jnz  ngsyse11
1788
     mov eax,[lba_read_enabled]
1788
     mov eax,[lba_read_enabled]
1789
     mov  [esp+36],eax
1789
     mov  [esp+36],eax
1790
     ret
1790
     ret
1791
   ngsyse11:
1791
   ngsyse11:
1792
     cmp  eax,12
1792
     cmp  eax,12
1793
     jnz  ngsyse12
1793
     jnz  ngsyse12
1794
     mov eax,[pci_access_enabled]
1794
     mov eax,[pci_access_enabled]
1795
     mov  [esp+36],eax
1795
     mov  [esp+36],eax
1796
     ret
1796
     ret
1797
   ngsyse12:
1797
   ngsyse12:
1798
     mov  [esp+36],dword 1
1798
     mov  [esp+36],dword 1
1799
     ret
1799
     ret
1800
 
1800
 
1801
get_timer_ticks:
1801
get_timer_ticks:
1802
    mov eax,[timer_ticks]
1802
    mov eax,[timer_ticks]
1803
    ret
1803
    ret
1804
 
1804
 
1805
iglobal
1805
iglobal
1806
align 4
1806
align 4
1807
mousefn dd msscreen, mswin, msbutton, msset
1807
mousefn dd msscreen, mswin, msbutton, msset
1808
        dd app_load_cursor
1808
        dd app_load_cursor
1809
        dd app_set_cursor
1809
        dd app_set_cursor
1810
        dd app_delete_cursor
1810
        dd app_delete_cursor
1811
        dd msz
1811
        dd msz
1812
endg
1812
endg
1813
 
1813
 
1814
readmousepos:
1814
readmousepos:
1815
 
1815
 
1816
; eax=0 screen relative
1816
; eax=0 screen relative
1817
; eax=1 window relative
1817
; eax=1 window relative
1818
; eax=2 buttons pressed
1818
; eax=2 buttons pressed
1819
; eax=3 set mouse pos   ; reserved
1819
; eax=3 set mouse pos   ; reserved
1820
; eax=4 load cursor
1820
; eax=4 load cursor
1821
; eax=5 set cursor
1821
; eax=5 set cursor
1822
; eax=6 delete cursor   ; reserved
1822
; eax=6 delete cursor   ; reserved
1823
; eax=7 get mouse_z
1823
; eax=7 get mouse_z
1824
 
1824
 
1825
           cmp eax, 7
1825
           cmp eax, 7
1826
           ja msset
1826
           ja msset
1827
           jmp [mousefn+eax*4]
1827
           jmp [mousefn+eax*4]
1828
msscreen:
1828
msscreen:
1829
           mov  eax,[MOUSE_X]
1829
           mov  eax,[MOUSE_X]
1830
           shl  eax,16
1830
           shl  eax,16
1831
           mov  ax,[MOUSE_Y]
1831
           mov  ax,[MOUSE_Y]
1832
           mov  [esp+36],eax
1832
           mov  [esp+36],eax
1833
           ret
1833
           ret
1834
mswin:
1834
mswin:
1835
           mov  eax,[MOUSE_X]
1835
           mov  eax,[MOUSE_X]
1836
           shl  eax,16
1836
           shl  eax,16
1837
           mov  ax,[MOUSE_Y]
1837
           mov  ax,[MOUSE_Y]
1838
           mov  esi,[TASK_BASE]
1838
           mov  esi,[TASK_BASE]
1839
           mov  bx, word [esi-twdw+WDATA.box.left]
1839
           mov  bx, word [esi-twdw+WDATA.box.left]
1840
           shl  ebx,16
1840
           shl  ebx,16
1841
           mov  bx, word [esi-twdw+WDATA.box.top]
1841
           mov  bx, word [esi-twdw+WDATA.box.top]
1842
           sub  eax,ebx
1842
           sub  eax,ebx
1843
 
1843
 
1844
           mov  edi,[CURRENT_TASK]
1844
           mov  edi,[CURRENT_TASK]
1845
           shl  edi,8
1845
           shl  edi,8
1846
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1846
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1847
           rol  eax,16
1847
           rol  eax,16
1848
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1848
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1849
           rol  eax,16
1849
           rol  eax,16
1850
           mov  [esp+36],eax
1850
           mov  [esp+36],eax
1851
           ret
1851
           ret
1852
msbutton:
1852
msbutton:
1853
           movzx eax,byte [BTN_DOWN]
1853
           movzx eax,byte [BTN_DOWN]
1854
           mov  [esp+36],eax
1854
           mov  [esp+36],eax
1855
           ret
1855
           ret
1856
msz:
1856
msz:
1857
           mov   edi, [TASK_COUNT]
1857
           mov   edi, [TASK_COUNT]
1858
           movzx edi, word [WIN_POS + edi*2]
1858
           movzx edi, word [WIN_POS + edi*2]
1859
           cmp   edi, [CURRENT_TASK]
1859
           cmp   edi, [CURRENT_TASK]
1860
           jne   @f
1860
           jne   @f
1861
           mov   ax,[MOUSE_SCROLL_H]
1861
           mov   ax,[MOUSE_SCROLL_H]
1862
           shl   eax,16
1862
           shl   eax,16
1863
           mov   ax,[MOUSE_SCROLL_V]
1863
           mov   ax,[MOUSE_SCROLL_V]
1864
           mov   [esp+36],eax
1864
           mov   [esp+36],eax
1865
           mov   [MOUSE_SCROLL_H],word 0
1865
           mov   [MOUSE_SCROLL_H],word 0
1866
           mov   [MOUSE_SCROLL_V],word 0
1866
           mov   [MOUSE_SCROLL_V],word 0
1867
           ret
1867
           ret
1868
       @@:
1868
       @@:
1869
           mov  [esp+36],dword 0
1869
           mov  [esp+36],dword 0
1870
           ret
1870
           ret
1871
msset:
1871
msset:
1872
           ret
1872
           ret
1873
 
1873
 
1874
app_load_cursor:
1874
app_load_cursor:
1875
      ;     add ebx, new_app_base
1875
      ;     add ebx, new_app_base
1876
           cmp ebx, OS_BASE
1876
           cmp ebx, OS_BASE
1877
           jae msset
1877
           jae msset
1878
           stdcall load_cursor, ebx, ecx
1878
           stdcall load_cursor, ebx, ecx
1879
           mov [esp+36], eax
1879
           mov [esp+36], eax
1880
           ret
1880
           ret
1881
 
1881
 
1882
app_set_cursor:
1882
app_set_cursor:
1883
           stdcall set_cursor, ebx
1883
           stdcall set_cursor, ebx
1884
           mov [esp+36], eax
1884
           mov [esp+36], eax
1885
           ret
1885
           ret
1886
 
1886
 
1887
app_delete_cursor:
1887
app_delete_cursor:
1888
           stdcall delete_cursor, ebx
1888
           stdcall delete_cursor, ebx
1889
           mov [esp+36], eax
1889
           mov [esp+36], eax
1890
           ret
1890
           ret
1891
 
1891
 
1892
is_input:
1892
is_input:
1893
 
1893
 
1894
   push edx
1894
   push edx
1895
   mov  dx,word [midisp]
1895
   mov  dx,word [midisp]
1896
   in   al,dx
1896
   in   al,dx
1897
   and  al,0x80
1897
   and  al,0x80
1898
   pop  edx
1898
   pop  edx
1899
   ret
1899
   ret
1900
 
1900
 
1901
is_output:
1901
is_output:
1902
 
1902
 
1903
   push edx
1903
   push edx
1904
   mov  dx,word [midisp]
1904
   mov  dx,word [midisp]
1905
   in   al,dx
1905
   in   al,dx
1906
   and  al,0x40
1906
   and  al,0x40
1907
   pop  edx
1907
   pop  edx
1908
   ret
1908
   ret
1909
 
1909
 
1910
 
1910
 
1911
get_mpu_in:
1911
get_mpu_in:
1912
 
1912
 
1913
   push edx
1913
   push edx
1914
   mov  dx,word [mididp]
1914
   mov  dx,word [mididp]
1915
   in   al,dx
1915
   in   al,dx
1916
   pop  edx
1916
   pop  edx
1917
   ret
1917
   ret
1918
 
1918
 
1919
 
1919
 
1920
put_mpu_out:
1920
put_mpu_out:
1921
 
1921
 
1922
   push edx
1922
   push edx
1923
   mov  dx,word [mididp]
1923
   mov  dx,word [mididp]
1924
   out  dx,al
1924
   out  dx,al
1925
   pop  edx
1925
   pop  edx
1926
   ret
1926
   ret
1927
 
1927
 
1928
 
1928
 
1929
setuart:
1929
setuart:
1930
 
1930
 
1931
 su1:
1931
 su1:
1932
   call is_output
1932
   call is_output
1933
   cmp  al,0
1933
   cmp  al,0
1934
   jnz  su1
1934
   jnz  su1
1935
   mov  dx,word [midisp]
1935
   mov  dx,word [midisp]
1936
   mov  al,0xff
1936
   mov  al,0xff
1937
   out  dx,al
1937
   out  dx,al
1938
 su2:
1938
 su2:
1939
   mov  dx,word [midisp]
1939
   mov  dx,word [midisp]
1940
   mov  al,0xff
1940
   mov  al,0xff
1941
   out  dx,al
1941
   out  dx,al
1942
   call is_input
1942
   call is_input
1943
   cmp  al,0
1943
   cmp  al,0
1944
   jnz  su2
1944
   jnz  su2
1945
   call get_mpu_in
1945
   call get_mpu_in
1946
   cmp  al,0xfe
1946
   cmp  al,0xfe
1947
   jnz  su2
1947
   jnz  su2
1948
 su3:
1948
 su3:
1949
   call is_output
1949
   call is_output
1950
   cmp  al,0
1950
   cmp  al,0
1951
   jnz  su3
1951
   jnz  su3
1952
   mov  dx,word [midisp]
1952
   mov  dx,word [midisp]
1953
   mov  al,0x3f
1953
   mov  al,0x3f
1954
   out  dx,al
1954
   out  dx,al
1955
 
1955
 
1956
   ret
1956
   ret
1957
 
1957
 
1958
 
1958
 
1959
align 4
1959
align 4
1960
 
1960
 
1961
sys_midi:
1961
sys_midi:
1962
 
1962
 
1963
     cmp  [mididp],0
1963
     cmp  [mididp],0
1964
     jnz  sm0
1964
     jnz  sm0
1965
     mov  [esp+36],dword 1
1965
     mov  [esp+36],dword 1
1966
     ret
1966
     ret
1967
   sm0:
1967
   sm0:
1968
 
1968
 
1969
     cmp  eax,1
1969
     cmp  eax,1
1970
     mov  [esp+36],dword 0
1970
     mov  [esp+36],dword 0
1971
     jnz  smn1
1971
     jnz  smn1
1972
     call setuart
1972
     call setuart
1973
     ret
1973
     ret
1974
   smn1:
1974
   smn1:
1975
 
1975
 
1976
     cmp  eax,2
1976
     cmp  eax,2
1977
     jnz  smn2
1977
     jnz  smn2
1978
   sm10:
1978
   sm10:
1979
     call get_mpu_in
1979
     call get_mpu_in
1980
     call is_output
1980
     call is_output
1981
     test al,al
1981
     test al,al
1982
     jnz  sm10
1982
     jnz  sm10
1983
     mov  al,bl
1983
     mov  al,bl
1984
     call put_mpu_out
1984
     call put_mpu_out
1985
     ret
1985
     ret
1986
   smn2:
1986
   smn2:
1987
 
1987
 
1988
     ret
1988
     ret
1989
 
1989
 
1990
 
1990
 
1991
detect_devices:
1991
detect_devices:
1992
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1992
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1993
include 'detect/commouse.inc'
1993
include 'detect/commouse.inc'
1994
;include 'detect/ps2mouse.inc'
1994
;include 'detect/ps2mouse.inc'
1995
;include 'detect/dev_fd.inc'
1995
;include 'detect/dev_fd.inc'
1996
;include 'detect/dev_hdcd.inc'
1996
;include 'detect/dev_hdcd.inc'
1997
;include 'detect/sear_par.inc'
1997
;include 'detect/sear_par.inc'
1998
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1998
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1999
    ret
1999
    ret
2000
 
2000
 
2001
 
2001
 
2002
sys_end:
2002
sys_end:
2003
 
2003
 
2004
     mov   eax,[TASK_BASE]
2004
     mov   eax,[TASK_BASE]
2005
     mov   [eax+TASKDATA.state], 3  ; terminate this program
2005
     mov   [eax+TASKDATA.state], 3  ; terminate this program
2006
 
2006
 
2007
    waitterm:            ; wait here for termination
2007
    waitterm:            ; wait here for termination
2008
     mov   eax,5
2008
     mov   eax,5
2009
     call  delay_hs
2009
     call  delay_hs
2010
     jmp   waitterm
2010
     jmp   waitterm
2011
 
2011
 
2012
iglobal
2012
iglobal
2013
align 4
2013
align 4
2014
sys_system_table:
2014
sys_system_table:
2015
        dd      sysfn_shutdown          ; 1 = system shutdown
2015
        dd      sysfn_shutdown          ; 1 = system shutdown
2016
        dd      sysfn_terminate         ; 2 = terminate thread
2016
        dd      sysfn_terminate         ; 2 = terminate thread
2017
        dd      sysfn_activate          ; 3 = activate window
2017
        dd      sysfn_activate          ; 3 = activate window
2018
        dd      sysfn_getidletime       ; 4 = get idle time
2018
        dd      sysfn_getidletime       ; 4 = get idle time
2019
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
2019
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
2020
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
2020
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
2021
        dd      sysfn_getactive         ; 7 = get active window
2021
        dd      sysfn_getactive         ; 7 = get active window
2022
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
2022
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
2023
        dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
2023
        dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
2024
        dd      sysfn_minimize          ; 10 = minimize window
2024
        dd      sysfn_minimize          ; 10 = minimize window
2025
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
2025
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
2026
        dd      sysfn_lastkey           ; 12 = get last pressed key
2026
        dd      sysfn_lastkey           ; 12 = get last pressed key
2027
        dd      sysfn_getversion        ; 13 = get kernel version
2027
        dd      sysfn_getversion        ; 13 = get kernel version
2028
        dd      sysfn_waitretrace       ; 14 = wait retrace
2028
        dd      sysfn_waitretrace       ; 14 = wait retrace
2029
        dd      sysfn_centermouse       ; 15 = center mouse cursor
2029
        dd      sysfn_centermouse       ; 15 = center mouse cursor
2030
        dd      sysfn_getfreemem        ; 16 = get free memory size
2030
        dd      sysfn_getfreemem        ; 16 = get free memory size
2031
        dd      sysfn_getallmem         ; 17 = get total memory size
2031
        dd      sysfn_getallmem         ; 17 = get total memory size
2032
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
2032
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
2033
                                        ;                 instead of slot
2033
                                        ;                 instead of slot
2034
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2034
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2035
        dd      sysfn_meminfo           ; 20 = get extended memory info
2035
        dd      sysfn_meminfo           ; 20 = get extended memory info
2036
sysfn_num = ($ - sys_system_table)/4
2036
sysfn_num = ($ - sys_system_table)/4
2037
endg
2037
endg
2038
 
2038
 
2039
sys_system:
2039
sys_system:
2040
        dec     eax
2040
        dec     eax
2041
        cmp     eax, sysfn_num
2041
        cmp     eax, sysfn_num
2042
        jae     @f
2042
        jae     @f
2043
        jmp     dword [sys_system_table + eax*4]
2043
        jmp     dword [sys_system_table + eax*4]
2044
@@:
2044
@@:
2045
        ret
2045
        ret
2046
 
2046
 
2047
sysfn_shutdown:         ; 18.1 = BOOT
2047
sysfn_shutdown:         ; 18.1 = BOOT
2048
     mov  [BOOT_VAR+0x9030],byte 0
2048
     mov  [BOOT_VAR+0x9030],byte 0
2049
  for_shutdown_parameter:
2049
  for_shutdown_parameter:
2050
 
2050
 
2051
     mov  eax,[TASK_COUNT]
2051
     mov  eax,[TASK_COUNT]
2052
     add  eax,2
2052
     add  eax,2
2053
     mov  [shutdown_processes],eax
2053
     mov  [shutdown_processes],eax
2054
     mov  [SYS_SHUTDOWN],al
2054
     mov  [SYS_SHUTDOWN],al
2055
     and  dword [esp+36], 0
2055
     and  dword [esp+36], 0
2056
     ret
2056
     ret
2057
  uglobal
2057
  uglobal
2058
   shutdown_processes: dd 0x0
2058
   shutdown_processes: dd 0x0
2059
  endg
2059
  endg
2060
 
2060
 
2061
sysfn_terminate:        ; 18.2 = TERMINATE
2061
sysfn_terminate:        ; 18.2 = TERMINATE
2062
     cmp  ebx,2
2062
     cmp  ebx,2
2063
     jb   noprocessterminate
2063
     jb   noprocessterminate
2064
     mov  edx,[TASK_COUNT]
2064
     mov  edx,[TASK_COUNT]
2065
     cmp  ebx,edx
2065
     cmp  ebx,edx
2066
     ja   noprocessterminate
2066
     ja   noprocessterminate
2067
     mov  eax,[TASK_COUNT]
2067
     mov  eax,[TASK_COUNT]
2068
     shl  ebx,5
2068
     shl  ebx,5
2069
     mov  edx,[ebx+CURRENT_TASK+TASKDATA.pid]
2069
     mov  edx,[ebx+CURRENT_TASK+TASKDATA.pid]
2070
     add  ebx,CURRENT_TASK+TASKDATA.state
2070
     add  ebx,CURRENT_TASK+TASKDATA.state
2071
     cmp  byte [ebx], 9
2071
     cmp  byte [ebx], 9
2072
     jz   noprocessterminate
2072
     jz   noprocessterminate
2073
 
2073
 
2074
     ;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
2075
     mov  [ebx],byte 3       ; clear possible i40's
2075
     mov  [ebx],byte 3       ; clear possible i40's
2076
     ;call MEM_Heap_UnLock
2076
     ;call MEM_Heap_UnLock
2077
 
2077
 
2078
     cmp  edx,[application_table_status]    ; clear app table stat
2078
     cmp  edx,[application_table_status]    ; clear app table stat
2079
     jne  noatsc
2079
     jne  noatsc
2080
     mov  [application_table_status],0
2080
     mov  [application_table_status],0
2081
   noatsc:
2081
   noatsc:
2082
   noprocessterminate:
2082
   noprocessterminate:
2083
     ret
2083
     ret
2084
 
2084
 
2085
sysfn_terminate2:
2085
sysfn_terminate2:
2086
;lock application_table_status mutex
2086
;lock application_table_status mutex
2087
.table_status:
2087
.table_status:
2088
    cli
2088
    cli
2089
    cmp    [application_table_status],0
2089
    cmp    [application_table_status],0
2090
    je     .stf
2090
    je     .stf
2091
    sti
2091
    sti
2092
    call   change_task
2092
    call   change_task
2093
    jmp    .table_status
2093
    jmp    .table_status
2094
.stf:
2094
.stf:
2095
    call   set_application_table_status
2095
    call   set_application_table_status
2096
    mov    eax,ebx
2096
    mov    eax,ebx
2097
    call   pid_to_slot
2097
    call   pid_to_slot
2098
    test   eax,eax
2098
    test   eax,eax
2099
    jz     .not_found
2099
    jz     .not_found
2100
    mov    ebx,eax
2100
    mov    ebx,eax
2101
    cli
2101
    cli
2102
    call   sysfn_terminate
2102
    call   sysfn_terminate
2103
    mov    [application_table_status],0
2103
    mov    [application_table_status],0
2104
    sti
2104
    sti
2105
    and    dword [esp+36],0
2105
    and    dword [esp+36],0
2106
    ret
2106
    ret
2107
.not_found:
2107
.not_found:
2108
    mov    [application_table_status],0
2108
    mov    [application_table_status],0
2109
    or     dword [esp+36],-1
2109
    or     dword [esp+36],-1
2110
    ret
2110
    ret
2111
 
2111
 
2112
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2112
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2113
     cmp  ebx,2
2113
     cmp  ebx,2
2114
     jb   .nowindowactivate
2114
     jb   .nowindowactivate
2115
     cmp  ebx,[TASK_COUNT]
2115
     cmp  ebx,[TASK_COUNT]
2116
     ja   .nowindowactivate
2116
     ja   .nowindowactivate
2117
 
2117
 
2118
     mov   [window_minimize], 2   ; restore window if minimized
2118
     mov   [window_minimize], 2   ; restore window if minimized
2119
 
2119
 
2120
     movzx esi, word [WIN_STACK + ebx*2]
2120
     movzx esi, word [WIN_STACK + ebx*2]
2121
     cmp   esi, [TASK_COUNT]
2121
     cmp   esi, [TASK_COUNT]
2122
     je    .nowindowactivate ; already active
2122
     je    .nowindowactivate ; already active
2123
 
2123
 
2124
     mov   edi, ebx
2124
     mov   edi, ebx
2125
     shl   edi, 5
2125
     shl   edi, 5
2126
     add   edi, window_data
2126
     add   edi, window_data
2127
     movzx esi, word [WIN_STACK + ebx * 2]
2127
     movzx esi, word [WIN_STACK + ebx * 2]
2128
     lea   esi, [WIN_POS + esi * 2]
2128
     lea   esi, [WIN_POS + esi * 2]
2129
     call  waredraw
2129
     call  waredraw
2130
.nowindowactivate:
2130
.nowindowactivate:
2131
     ret
2131
     ret
2132
 
2132
 
2133
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2133
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2134
     mov  eax,[idleusesec]
2134
     mov  eax,[idleusesec]
2135
     mov  [esp+36], eax
2135
     mov  [esp+36], eax
2136
     ret
2136
     ret
2137
 
2137
 
2138
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2138
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2139
     mov  eax,[CPU_FREQ]
2139
     mov  eax,[CPU_FREQ]
2140
     mov  [esp+36], eax
2140
     mov  [esp+36], eax
2141
     ret
2141
     ret
2142
 
2142
 
2143
;  SAVE ramdisk to /hd/1/menuet.img
2143
;  SAVE ramdisk to /hd/1/menuet.img
2144
;!!!!!!!!!!!!!!!!!!!!!!!!
2144
;!!!!!!!!!!!!!!!!!!!!!!!!
2145
   include 'blkdev/rdsave.inc'
2145
   include 'blkdev/rdsave.inc'
2146
;!!!!!!!!!!!!!!!!!!!!!!!!
2146
;!!!!!!!!!!!!!!!!!!!!!!!!
2147
 
2147
 
2148
sysfn_getactive:        ; 18.7 = get active window
2148
sysfn_getactive:        ; 18.7 = get active window
2149
     mov  eax, [TASK_COUNT]
2149
     mov  eax, [TASK_COUNT]
2150
   movzx  eax, word [WIN_POS + eax*2]
2150
   movzx  eax, word [WIN_POS + eax*2]
2151
     mov  [esp+36],eax
2151
     mov  [esp+36],eax
2152
     ret
2152
     ret
2153
 
2153
 
2154
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2154
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2155
     cmp  ebx,1
2155
     cmp  ebx,1
2156
     jne  nogetsoundflag
2156
     jne  nogetsoundflag
2157
     movzx  eax,byte [sound_flag] ; get sound_flag
2157
     movzx  eax,byte [sound_flag] ; get sound_flag
2158
     mov  [esp+36],eax
2158
     mov  [esp+36],eax
2159
     ret
2159
     ret
2160
 nogetsoundflag:
2160
 nogetsoundflag:
2161
     cmp  ebx,2
2161
     cmp  ebx,2
2162
     jnz  nosoundflag
2162
     jnz  nosoundflag
2163
     xor  byte [sound_flag], 1
2163
     xor  byte [sound_flag], 1
2164
 nosoundflag:
2164
 nosoundflag:
2165
     ret
2165
     ret
2166
 
2166
 
2167
sysfn_shutdown_param:   ; 18.9 = system shutdown with param
2167
sysfn_shutdown_param:   ; 18.9 = system shutdown with param
2168
     cmp  ebx,1
2168
     cmp  ebx,1
2169
     jl   exit_for_anyone
2169
     jl   exit_for_anyone
2170
     cmp  ebx,4
2170
     cmp  ebx,4
2171
     jg   exit_for_anyone
2171
     jg   exit_for_anyone
2172
     mov  [BOOT_VAR+0x9030],bl
2172
     mov  [BOOT_VAR+0x9030],bl
2173
     jmp  for_shutdown_parameter
2173
     jmp  for_shutdown_parameter
2174
 
2174
 
2175
sysfn_minimize:         ; 18.10 = minimize window
2175
sysfn_minimize:         ; 18.10 = minimize window
2176
     mov   [window_minimize],1
2176
     mov   [window_minimize],1
2177
 exit_for_anyone:
2177
 exit_for_anyone:
2178
     ret
2178
     ret
2179
 
2179
 
2180
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2180
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2181
     cmp  ebx,1
2181
     cmp  ebx,1
2182
     jnz  full_table
2182
     jnz  full_table
2183
  small_table:
2183
  small_table:
2184
     call for_all_tables
2184
     call for_all_tables
2185
     mov ecx,10
2185
     mov ecx,10
2186
     cld
2186
     cld
2187
     rep movsb
2187
     rep movsb
2188
     ret
2188
     ret
2189
   for_all_tables:
2189
   for_all_tables:
2190
     mov edi,[TASK_BASE]
2190
     mov edi,[TASK_BASE]
2191
     mov edi,[edi+TASKDATA.mem_start]
2191
     mov edi,[edi+TASKDATA.mem_start]
2192
     add edi,ecx
2192
     add edi,ecx
2193
     mov esi,DRIVE_DATA
2193
     mov esi,DRIVE_DATA
2194
     ret
2194
     ret
2195
  full_table:
2195
  full_table:
2196
     cmp  ebx,2
2196
     cmp  ebx,2
2197
     jnz  exit_for_anyone
2197
     jnz  exit_for_anyone
2198
     call for_all_tables
2198
     call for_all_tables
2199
     mov ecx,16384
2199
     mov ecx,16384
2200
     cld
2200
     cld
2201
     rep movsd
2201
     rep movsd
2202
     ret
2202
     ret
2203
 
2203
 
2204
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2204
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2205
        and     dword [esp+36], 0
2205
        and     dword [esp+36], 0
2206
        ret
2206
        ret
2207
 
2207
 
2208
sysfn_getversion:       ; 18.13 = get kernel ID and version
2208
sysfn_getversion:       ; 18.13 = get kernel ID and version
2209
     mov edi,[TASK_BASE]
2209
     mov edi,[TASK_BASE]
2210
     mov edi,[edi+TASKDATA.mem_start]
2210
     mov edi,[edi+TASKDATA.mem_start]
2211
     add edi,ebx
2211
     add edi,ebx
2212
     mov esi,version_inf
2212
     mov esi,version_inf
2213
     mov ecx,version_end-version_inf
2213
     mov ecx,version_end-version_inf
2214
     cld
2214
     cld
2215
     rep movsb
2215
     rep movsb
2216
     ret
2216
     ret
2217
 
2217
 
2218
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2218
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2219
     ;wait retrace functions
2219
     ;wait retrace functions
2220
 sys_wait_retrace:
2220
 sys_wait_retrace:
2221
     mov edx,0x3da
2221
     mov edx,0x3da
2222
 WaitRetrace_loop:
2222
 WaitRetrace_loop:
2223
     in al,dx
2223
     in al,dx
2224
     test al,1000b
2224
     test al,1000b
2225
     jz WaitRetrace_loop
2225
     jz WaitRetrace_loop
2226
     mov [esp+36],dword 0
2226
     mov [esp+36],dword 0
2227
     ret
2227
     ret
2228
 
2228
 
2229
sysfn_centermouse:      ; 18.15 = mouse centered
2229
sysfn_centermouse:      ; 18.15 = mouse centered
2230
     call  mouse_centered
2230
     call  mouse_centered
2231
     mov [esp+36],dword 0
2231
     mov [esp+36],dword 0
2232
     ret
2232
     ret
2233
 
2233
 
2234
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2234
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2235
     cmp  ebx,0  ; get mouse speed factor
2235
     cmp  ebx,0  ; get mouse speed factor
2236
     jnz  .set_mouse_acceleration
2236
     jnz  .set_mouse_acceleration
2237
     xor  eax,eax
2237
     xor  eax,eax
2238
     mov  ax,[mouse_speed_factor]
2238
     mov  ax,[mouse_speed_factor]
2239
     mov  [esp+36],eax
2239
     mov  [esp+36],eax
2240
     ret
2240
     ret
2241
 .set_mouse_acceleration:
2241
 .set_mouse_acceleration:
2242
     cmp  ebx,1  ; set mouse speed factor
2242
     cmp  ebx,1  ; set mouse speed factor
2243
     jnz  .get_mouse_delay
2243
     jnz  .get_mouse_delay
2244
     mov  [mouse_speed_factor],cx
2244
     mov  [mouse_speed_factor],cx
2245
     ret
2245
     ret
2246
 .get_mouse_delay:
2246
 .get_mouse_delay:
2247
     cmp  ebx,2  ; get mouse delay
2247
     cmp  ebx,2  ; get mouse delay
2248
     jnz  .set_mouse_delay
2248
     jnz  .set_mouse_delay
2249
     mov  eax,[mouse_delay]
2249
     mov  eax,[mouse_delay]
2250
     mov  [esp+36],eax
2250
     mov  [esp+36],eax
2251
     ret
2251
     ret
2252
 .set_mouse_delay:
2252
 .set_mouse_delay:
2253
     cmp  ebx,3  ; set mouse delay
2253
     cmp  ebx,3  ; set mouse delay
2254
     jnz  .set_pointer_position
2254
     jnz  .set_pointer_position
2255
     mov  [mouse_delay],ecx
2255
     mov  [mouse_delay],ecx
2256
     ret
2256
     ret
2257
 .set_pointer_position:
2257
 .set_pointer_position:
2258
     cmp  ebx,4  ; set mouse pointer position
2258
     cmp  ebx,4  ; set mouse pointer position
2259
     jnz  .end
2259
     jnz  .end
2260
     mov   [MOUSE_Y],cx    ;y
2260
     mov   [MOUSE_Y],cx    ;y
2261
     ror   ecx,16
2261
     ror   ecx,16
2262
     mov   [MOUSE_X],cx    ;x
2262
     mov   [MOUSE_X],cx    ;x
2263
     rol   ecx,16
2263
     rol   ecx,16
2264
 .end:
2264
 .end:
2265
     ret
2265
     ret
2266
 
2266
 
2267
sysfn_getfreemem:
2267
sysfn_getfreemem:
2268
     mov eax, [pg_data.pages_free]
2268
     mov eax, [pg_data.pages_free]
2269
     shl eax, 2
2269
     shl eax, 2
2270
     mov [esp+36],eax
2270
     mov [esp+36],eax
2271
     ret
2271
     ret
2272
 
2272
 
2273
sysfn_getallmem:
2273
sysfn_getallmem:
2274
     mov  eax,[MEM_AMOUNT]
2274
     mov  eax,[MEM_AMOUNT]
2275
     shr eax, 10
2275
     shr eax, 10
2276
     mov  [esp+36],eax
2276
     mov  [esp+36],eax
2277
     ret
2277
     ret
2278
 
2278
 
2279
uglobal
2279
uglobal
2280
;// mike.dld, 2006-29-01 [
2280
;// mike.dld, 2006-29-01 [
2281
screen_workarea RECT
2281
screen_workarea RECT
2282
;// mike.dld, 2006-29-01 ]
2282
;// mike.dld, 2006-29-01 ]
2283
window_minimize db 0
2283
window_minimize db 0
2284
sound_flag      db 0
2284
sound_flag      db 0
2285
endg
2285
endg
2286
 
2286
 
2287
iglobal
2287
iglobal
2288
version_inf:
2288
version_inf:
2289
  db 0,7,0,0  ; version 0.7.0.0
2289
  db 0,7,0,0  ; version 0.7.0.0
2290
  db UID_KOLIBRI
2290
  db UID_KOLIBRI
2291
  db 'Kolibri',0
2291
  dd __REV__
2292
version_end:
2292
version_end:
2293
endg
2293
endg
2294
 
2294
 
2295
UID_NONE=0
2295
UID_NONE=0
2296
UID_MENUETOS=1   ;official
2296
UID_MENUETOS=1   ;official
2297
UID_KOLIBRI=2    ;russian
2297
UID_KOLIBRI=2    ;russian
2298
 
2298
 
2299
sys_cachetodiskette:
2299
sys_cachetodiskette:
2300
;    pushad
2300
;    pushad
2301
;    cmp  eax,1
2301
;    cmp  eax,1
2302
;    jne  no_write_all_of_ramdisk
2302
;    jne  no_write_all_of_ramdisk
2303
;    call fdc_writeramdisk
2303
;    call fdc_writeramdisk
2304
;    popad
2304
;    popad
2305
;    ret
2305
;    ret
2306
;  no_write_all_of_ramdisk:
2306
;  no_write_all_of_ramdisk:
2307
;    cmp eax,2
2307
;    cmp eax,2
2308
;    jne no_write_part_of_ramdisk
2308
;    jne no_write_part_of_ramdisk
2309
;    call fdc_commitflush
2309
;    call fdc_commitflush
2310
;    popad
2310
;    popad
2311
;    ret
2311
;    ret
2312
;  no_write_part_of_ramdisk:
2312
;  no_write_part_of_ramdisk:
2313
;    cmp  eax,3
2313
;    cmp  eax,3
2314
;    jne  no_set_fdc
2314
;    jne  no_set_fdc
2315
;    call fdc_set
2315
;    call fdc_set
2316
;    popad
2316
;    popad
2317
;    ret
2317
;    ret
2318
;  no_set_fdc:
2318
;  no_set_fdc:
2319
;    cmp  eax,4
2319
;    cmp  eax,4
2320
;    jne  no_get_fdc
2320
;    jne  no_get_fdc
2321
;    popad
2321
;    popad
2322
;    call fdc_get
2322
;    call fdc_get
2323
;    mov    [esp+36],ecx
2323
;    mov    [esp+36],ecx
2324
;    ret
2324
;    ret
2325
;  no_get_fdc:
2325
;  no_get_fdc:
2326
;    popad
2326
;    popad
2327
;    ret
2327
;    ret
2328
    cmp eax,1
2328
    cmp eax,1
2329
    jne no_floppy_a_save
2329
    jne no_floppy_a_save
2330
    mov   [flp_number],1
2330
    mov   [flp_number],1
2331
    jmp save_image_on_floppy
2331
    jmp save_image_on_floppy
2332
  no_floppy_a_save:
2332
  no_floppy_a_save:
2333
    cmp eax,2
2333
    cmp eax,2
2334
    jne no_floppy_b_save
2334
    jne no_floppy_b_save
2335
    mov   [flp_number],2
2335
    mov   [flp_number],2
2336
  save_image_on_floppy:
2336
  save_image_on_floppy:
2337
    call save_image
2337
    call save_image
2338
    mov  [esp+36],dword 0
2338
    mov  [esp+36],dword 0
2339
    cmp  [FDC_Status],0
2339
    cmp  [FDC_Status],0
2340
    je   yes_floppy_save
2340
    je   yes_floppy_save
2341
  no_floppy_b_save:
2341
  no_floppy_b_save:
2342
    mov [esp+36],dword 1
2342
    mov [esp+36],dword 1
2343
  yes_floppy_save:
2343
  yes_floppy_save:
2344
    ret
2344
    ret
2345
 
2345
 
2346
uglobal
2346
uglobal
2347
;  bgrchanged  dd  0x0
2347
;  bgrchanged  dd  0x0
2348
endg
2348
endg
2349
 
2349
 
2350
sys_background:
2350
sys_background:
2351
 
2351
 
2352
    cmp   eax,1                            ; BACKGROUND SIZE
2352
    cmp   eax,1                            ; BACKGROUND SIZE
2353
    jnz   nosb1
2353
    jnz   nosb1
2354
    cmp   ebx,0
2354
    cmp   ebx,0
2355
    je    sbgrr
2355
    je    sbgrr
2356
    cmp   ecx,0
2356
    cmp   ecx,0
2357
    je    sbgrr
2357
    je    sbgrr
2358
    mov   [BgrDataWidth],ebx
2358
    mov   [BgrDataWidth],ebx
2359
    mov   [BgrDataHeight],ecx
2359
    mov   [BgrDataHeight],ecx
2360
;    mov   [bgrchanged],1
2360
;    mov   [bgrchanged],1
2361
 
2361
 
2362
    pushad
2362
    pushad
2363
; return memory for old background
2363
; return memory for old background
2364
    stdcall kernel_free, [img_background]
2364
    stdcall kernel_free, [img_background]
2365
; calculate RAW size
2365
; calculate RAW size
2366
    xor  eax,eax
2366
    xor  eax,eax
2367
    inc  eax
2367
    inc  eax
2368
    cmp  [BgrDataWidth],eax
2368
    cmp  [BgrDataWidth],eax
2369
    jae   @f
2369
    jae   @f
2370
    mov [BgrDataWidth],eax
2370
    mov [BgrDataWidth],eax
2371
@@:
2371
@@:
2372
    cmp  [BgrDataHeight],eax
2372
    cmp  [BgrDataHeight],eax
2373
    jae   @f
2373
    jae   @f
2374
    mov [BgrDataHeight],eax
2374
    mov [BgrDataHeight],eax
2375
@@:
2375
@@:
2376
    mov  eax,[BgrDataWidth]
2376
    mov  eax,[BgrDataWidth]
2377
    imul eax,[BgrDataHeight]
2377
    imul eax,[BgrDataHeight]
2378
    lea  eax,[eax*3]
2378
    lea  eax,[eax*3]
2379
    mov  [mem_BACKGROUND],eax
2379
    mov  [mem_BACKGROUND],eax
2380
; get memory for new background
2380
; get memory for new background
2381
    stdcall kernel_alloc, [mem_BACKGROUND]
2381
    stdcall kernel_alloc, [mem_BACKGROUND]
2382
    test eax, eax
2382
    test eax, eax
2383
    jz .exit_mem
2383
    jz .exit_mem
2384
    mov [img_background], eax
2384
    mov [img_background], eax
2385
.exit_mem:
2385
.exit_mem:
2386
    popad
2386
    popad
2387
 
2387
 
2388
  sbgrr:
2388
  sbgrr:
2389
    ret
2389
    ret
2390
 
2390
 
2391
  nosb1:
2391
  nosb1:
2392
 
2392
 
2393
    cmp   eax,2                            ; SET PIXEL
2393
    cmp   eax,2                            ; SET PIXEL
2394
    jnz   nosb2
2394
    jnz   nosb2
2395
    mov   edx,[mem_BACKGROUND]
2395
    mov   edx,[mem_BACKGROUND]
2396
    cmp   edx,ebx
2396
    cmp   edx,ebx
2397
    jbe   nosb2
2397
    jbe   nosb2
2398
    mov   edx,[ebx]
2398
    mov   edx,[ebx]
2399
    and   edx,0xFF000000 ;255*256*256*256
2399
    and   edx,0xFF000000 ;255*256*256*256
2400
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2400
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2401
    add   edx,ecx
2401
    add   edx,ecx
2402
    ;mov   [ebx+IMG_BACKGROUND],edx
2402
    ;mov   [ebx+IMG_BACKGROUND],edx
2403
    push  eax
2403
    push  eax
2404
    mov   eax,[img_background]
2404
    mov   eax,[img_background]
2405
    mov   [ebx+eax],edx
2405
    mov   [ebx+eax],edx
2406
    pop   eax
2406
    pop   eax
2407
;    mov   [bgrchanged],1
2407
;    mov   [bgrchanged],1
2408
    ret
2408
    ret
2409
  nosb2:
2409
  nosb2:
2410
 
2410
 
2411
    cmp   eax,3                            ; DRAW BACKGROUND
2411
    cmp   eax,3                            ; DRAW BACKGROUND
2412
    jnz   nosb3
2412
    jnz   nosb3
2413
draw_background_temp:
2413
draw_background_temp:
2414
;    cmp   [bgrchanged],1 ;0
2414
;    cmp   [bgrchanged],1 ;0
2415
;    je    nosb31
2415
;    je    nosb31
2416
;draw_background_temp:
2416
;draw_background_temp:
2417
;    mov   [bgrchanged],1 ;0
2417
;    mov   [bgrchanged],1 ;0
2418
    mov   [REDRAW_BACKGROUND],byte 1
2418
    mov   [REDRAW_BACKGROUND],byte 1
2419
    mov    [background_defined], 1
2419
    mov    [background_defined], 1
2420
   nosb31:
2420
   nosb31:
2421
    ret
2421
    ret
2422
  nosb3:
2422
  nosb3:
2423
 
2423
 
2424
    cmp   eax,4                            ; TILED / STRETCHED
2424
    cmp   eax,4                            ; TILED / STRETCHED
2425
    jnz   nosb4
2425
    jnz   nosb4
2426
    cmp   ebx,[BgrDrawMode]
2426
    cmp   ebx,[BgrDrawMode]
2427
    je    nosb41
2427
    je    nosb41
2428
    mov   [BgrDrawMode],ebx
2428
    mov   [BgrDrawMode],ebx
2429
;    mov   [bgrchanged],1
2429
;    mov   [bgrchanged],1
2430
   nosb41:
2430
   nosb41:
2431
    ret
2431
    ret
2432
  nosb4:
2432
  nosb4:
2433
 
2433
 
2434
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2434
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2435
    jnz   nosb5
2435
    jnz   nosb5
2436
  ; bughere
2436
  ; bughere
2437
    mov   eax, ebx
2437
    mov   eax, ebx
2438
    mov   ebx, ecx
2438
    mov   ebx, ecx
2439
    add   ebx, [img_background]   ;IMG_BACKGROUND
2439
    add   ebx, [img_background]   ;IMG_BACKGROUND
2440
    mov   ecx, edx
2440
    mov   ecx, edx
2441
    call  memmove
2441
    call  memmove
2442
  .fin:
2442
  .fin:
2443
    ret
2443
    ret
2444
  nosb5:
2444
  nosb5:
2445
 
2445
 
2446
    ret
2446
    ret
2447
 
2447
 
2448
 
2448
 
2449
align 4
2449
align 4
2450
 
2450
 
2451
sys_getbackground:
2451
sys_getbackground:
2452
 
2452
 
2453
    cmp   eax,1                                  ; SIZE
2453
    cmp   eax,1                                  ; SIZE
2454
    jnz   nogb1
2454
    jnz   nogb1
2455
    mov   eax,[BgrDataWidth]
2455
    mov   eax,[BgrDataWidth]
2456
    shl   eax,16
2456
    shl   eax,16
2457
    mov   ax,[BgrDataHeight]
2457
    mov   ax,[BgrDataHeight]
2458
    mov   [esp+36],eax
2458
    mov   [esp+36],eax
2459
    ret
2459
    ret
2460
  nogb1:
2460
  nogb1:
2461
 
2461
 
2462
    cmp   eax,2                                  ; PIXEL
2462
    cmp   eax,2                                  ; PIXEL
2463
    jnz   nogb2
2463
    jnz   nogb2
2464
;    mov   edx,0x160000-16
2464
;    mov   edx,0x160000-16
2465
;    cmp   edx,ebx
2465
;    cmp   edx,ebx
2466
;    jbe   nogb2
2466
;    jbe   nogb2
2467
;    mov   eax, [ebx+IMG_BACKGROUND]
2467
;    mov   eax, [ebx+IMG_BACKGROUND]
2468
    mov   eax,[img_background]
2468
    mov   eax,[img_background]
2469
    mov   eax,[ebx+eax]
2469
    mov   eax,[ebx+eax]
2470
 
2470
 
2471
    and   eax, 0xFFFFFF
2471
    and   eax, 0xFFFFFF
2472
    mov   [esp+36],eax
2472
    mov   [esp+36],eax
2473
    ret
2473
    ret
2474
  nogb2:
2474
  nogb2:
2475
 
2475
 
2476
    cmp   eax,4                                  ; TILED / STRETCHED
2476
    cmp   eax,4                                  ; TILED / STRETCHED
2477
    jnz   nogb4
2477
    jnz   nogb4
2478
    mov   eax,[BgrDrawMode]
2478
    mov   eax,[BgrDrawMode]
2479
  nogb4:
2479
  nogb4:
2480
    mov   [esp+36],eax
2480
    mov   [esp+36],eax
2481
    ret
2481
    ret
2482
 
2482
 
2483
 
2483
 
2484
align 4
2484
align 4
2485
 
2485
 
2486
sys_getkey:
2486
sys_getkey:
2487
    mov   [esp+36],dword 1
2487
    mov   [esp+36],dword 1
2488
; test main buffer
2488
; test main buffer
2489
    mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2489
    mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2490
    movzx ecx,word [WIN_STACK + ebx * 2]
2490
    movzx ecx,word [WIN_STACK + ebx * 2]
2491
    mov   edx,[TASK_COUNT]
2491
    mov   edx,[TASK_COUNT]
2492
    cmp   ecx,edx
2492
    cmp   ecx,edx
2493
    jne   .finish
2493
    jne   .finish
2494
    cmp   [KEY_COUNT],byte 0
2494
    cmp   [KEY_COUNT],byte 0
2495
    je    .finish
2495
    je    .finish
2496
    movzx eax,byte [KEY_BUFF]
2496
    movzx eax,byte [KEY_BUFF]
2497
    shl   eax,8
2497
    shl   eax,8
2498
    push  eax
2498
    push  eax
2499
    dec   byte [KEY_COUNT]
2499
    dec   byte [KEY_COUNT]
2500
    and   byte [KEY_COUNT],127
2500
    and   byte [KEY_COUNT],127
2501
    movzx ecx,byte [KEY_COUNT]
2501
    movzx ecx,byte [KEY_COUNT]
2502
    add   ecx,2
2502
    add   ecx,2
2503
 ;   mov   esi,0xf402
2503
 ;   mov   esi,0xf402
2504
 ;   mov   edi,0xf401
2504
 ;   mov   edi,0xf401
2505
 ;   cld
2505
 ;   cld
2506
 ;  rep   movsb
2506
 ;  rep   movsb
2507
    mov   eax, KEY_BUFF+1
2507
    mov   eax, KEY_BUFF+1
2508
    mov   ebx, KEY_BUFF
2508
    mov   ebx, KEY_BUFF
2509
    call  memmove
2509
    call  memmove
2510
    pop   eax
2510
    pop   eax
2511
.ret_eax:
2511
.ret_eax:
2512
    mov   [esp+36],eax
2512
    mov   [esp+36],eax
2513
    ret
2513
    ret
2514
 .finish:
2514
 .finish:
2515
; test hotkeys buffer
2515
; test hotkeys buffer
2516
        mov     ecx, hotkey_buffer
2516
        mov     ecx, hotkey_buffer
2517
@@:
2517
@@:
2518
        cmp     [ecx], ebx
2518
        cmp     [ecx], ebx
2519
        jz      .found
2519
        jz      .found
2520
        add     ecx, 8
2520
        add     ecx, 8
2521
        cmp     ecx, hotkey_buffer+120*8
2521
        cmp     ecx, hotkey_buffer+120*8
2522
        jb      @b
2522
        jb      @b
2523
        ret
2523
        ret
2524
.found:
2524
.found:
2525
        mov     ax, [ecx+6]
2525
        mov     ax, [ecx+6]
2526
        shl     eax, 16
2526
        shl     eax, 16
2527
        mov     ah, [ecx+4]
2527
        mov     ah, [ecx+4]
2528
        mov     al, 2
2528
        mov     al, 2
2529
        and     dword [ecx+4], 0
2529
        and     dword [ecx+4], 0
2530
        and     dword [ecx], 0
2530
        and     dword [ecx], 0
2531
        jmp     .ret_eax
2531
        jmp     .ret_eax
2532
 
2532
 
2533
align 4
2533
align 4
2534
 
2534
 
2535
sys_getbutton:
2535
sys_getbutton:
2536
 
2536
 
2537
    mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2537
    mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2538
    mov   [esp+36],dword 1
2538
    mov   [esp+36],dword 1
2539
    movzx ecx, word [WIN_STACK + ebx * 2]
2539
    movzx ecx, word [WIN_STACK + ebx * 2]
2540
    mov   edx, [TASK_COUNT] ; less than 256 processes
2540
    mov   edx, [TASK_COUNT] ; less than 256 processes
2541
    cmp   ecx,edx
2541
    cmp   ecx,edx
2542
    jne   .exit
2542
    jne   .exit
2543
    movzx eax,byte [BTN_COUNT]
2543
    movzx eax,byte [BTN_COUNT]
2544
    test  eax,eax
2544
    test  eax,eax
2545
    jz    .exit
2545
    jz    .exit
2546
    mov   eax,[BTN_BUFF]
2546
    mov   eax,[BTN_BUFF]
2547
    shl   eax,8
2547
    shl   eax,8
2548
    mov   [BTN_COUNT],byte 0
2548
    mov   [BTN_COUNT],byte 0
2549
    mov   [esp+36],eax
2549
    mov   [esp+36],eax
2550
 .exit:
2550
 .exit:
2551
    ret
2551
    ret
2552
 
2552
 
2553
 
2553
 
2554
align 4
2554
align 4
2555
 
2555
 
2556
sys_cpuusage:
2556
sys_cpuusage:
2557
 
2557
 
2558
;  RETURN:
2558
;  RETURN:
2559
;
2559
;
2560
;  +00 dword     process cpu usage
2560
;  +00 dword     process cpu usage
2561
;  +04  word     position in windowing stack
2561
;  +04  word     position in windowing stack
2562
;  +06  word     windowing stack value at current position (cpu nro)
2562
;  +06  word     windowing stack value at current position (cpu nro)
2563
;  +10 12 bytes  name
2563
;  +10 12 bytes  name
2564
;  +22 dword     start in mem
2564
;  +22 dword     start in mem
2565
;  +26 dword     used mem
2565
;  +26 dword     used mem
2566
;  +30 dword     PID , process idenfification number
2566
;  +30 dword     PID , process idenfification number
2567
;
2567
;
2568
 
2568
 
2569
    mov  edi,[TASK_BASE]   ; eax = return area
2569
    mov  edi,[TASK_BASE]   ; eax = return area
2570
    add  eax,[edi + TASKDATA.mem_start]
2570
    add  eax,[edi + TASKDATA.mem_start]
2571
 
2571
 
2572
    cmp  ebx,-1         ; who am I ?
2572
    cmp  ebx,-1         ; who am I ?
2573
    jne  no_who_am_i
2573
    jne  no_who_am_i
2574
    mov  ebx,[CURRENT_TASK]
2574
    mov  ebx,[CURRENT_TASK]
2575
  no_who_am_i:
2575
  no_who_am_i:
2576
 
2576
 
2577
    push eax            ; return area
2577
    push eax            ; return area
2578
    push ebx            ; process number
2578
    push ebx            ; process number
2579
 
2579
 
2580
    push ebx
2580
    push ebx
2581
    push ebx
2581
    push ebx
2582
    push eax
2582
    push eax
2583
 
2583
 
2584
    ; return memory usage
2584
    ; return memory usage
2585
 
2585
 
2586
    xor  edx,edx
2586
    xor  edx,edx
2587
    mov  eax,0x20
2587
    mov  eax,0x20
2588
    mul  ebx
2588
    mul  ebx
2589
    add  eax,CURRENT_TASK+TASKDATA.cpu_usage
2589
    add  eax,CURRENT_TASK+TASKDATA.cpu_usage
2590
    mov  ebx,eax
2590
    mov  ebx,eax
2591
    pop  eax
2591
    pop  eax
2592
    mov  ecx,[ebx]
2592
    mov  ecx,[ebx]
2593
    mov  [eax],ecx
2593
    mov  [eax],ecx
2594
    pop  ebx
2594
    pop  ebx
2595
    mov  cx, [WIN_STACK + ebx * 2]
2595
    mov  cx, [WIN_STACK + ebx * 2]
2596
    mov  [eax+4],cx
2596
    mov  [eax+4],cx
2597
    mov  cx, [WIN_POS + ebx * 2]
2597
    mov  cx, [WIN_POS + ebx * 2]
2598
    mov  [eax+6],cx
2598
    mov  [eax+6],cx
2599
    push eax
2599
    push eax
2600
    mov  eax,ebx
2600
    mov  eax,ebx
2601
    shl  eax,8
2601
    shl  eax,8
2602
    add  eax,SLOT_BASE+APPDATA.app_name
2602
    add  eax,SLOT_BASE+APPDATA.app_name
2603
    pop  ebx
2603
    pop  ebx
2604
    add  ebx,10
2604
    add  ebx,10
2605
    mov  ecx,11
2605
    mov  ecx,11
2606
    call memmove
2606
    call memmove
2607
 
2607
 
2608
    ; memory usage
2608
    ; memory usage
2609
 
2609
 
2610
    xor    eax,eax
2610
    xor    eax,eax
2611
    mov    edx,0x100000*16
2611
    mov    edx,0x100000*16
2612
    pop    ecx                                   ; get gdt of tss
2612
    pop    ecx                                   ; get gdt of tss
2613
    cmp    ecx,1
2613
    cmp    ecx,1
2614
    je     os_mem
2614
    je     os_mem
2615
    shl    ecx,8
2615
    shl    ecx,8
2616
    mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
2616
    mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
2617
    mov    eax,std_application_base_address
2617
    mov    eax,std_application_base_address
2618
    ; eax run base -> edx used memory
2618
    ; eax run base -> edx used memory
2619
  os_mem:
2619
  os_mem:
2620
    dec    edx
2620
    dec    edx
2621
    mov    [ebx+12],eax
2621
    mov    [ebx+12],eax
2622
    mov    [ebx+16],edx
2622
    mov    [ebx+16],edx
2623
 
2623
 
2624
    ; PID (+30)
2624
    ; PID (+30)
2625
 
2625
 
2626
    mov    eax,[esp]
2626
    mov    eax,[esp]
2627
    shl    eax,5
2627
    shl    eax,5
2628
    add    eax,CURRENT_TASK+TASKDATA.pid
2628
    add    eax,CURRENT_TASK+TASKDATA.pid
2629
    mov    eax,[eax]
2629
    mov    eax,[eax]
2630
    mov    [ebx+20],eax
2630
    mov    [ebx+20],eax
2631
 
2631
 
2632
    ; window position and size
2632
    ; window position and size
2633
 
2633
 
2634
    mov    esi,[esp]
2634
    mov    esi,[esp]
2635
    shl    esi,5
2635
    shl    esi,5
2636
    add    esi,window_data + WDATA.box
2636
    add    esi,window_data + WDATA.box
2637
    mov    edi,[esp+4]
2637
    mov    edi,[esp+4]
2638
    add    edi,34
2638
    add    edi,34
2639
    mov    ecx,4
2639
    mov    ecx,4
2640
    cld
2640
    cld
2641
    rep    movsd
2641
    rep    movsd
2642
 
2642
 
2643
    ; Process state (+50)
2643
    ; Process state (+50)
2644
 
2644
 
2645
    mov    eax,[esp]
2645
    mov    eax,[esp]
2646
    shl    eax,5
2646
    shl    eax,5
2647
    add    eax,CURRENT_TASK+TASKDATA.state
2647
    add    eax,CURRENT_TASK+TASKDATA.state
2648
    mov    eax,[eax]
2648
    mov    eax,[eax]
2649
    mov    [ebx+40],ax
2649
    mov    [ebx+40],ax
2650
 
2650
 
2651
    ; Window client area box
2651
    ; Window client area box
2652
 
2652
 
2653
    mov    esi,[esp]
2653
    mov    esi,[esp]
2654
    shl    esi,8
2654
    shl    esi,8
2655
    add    esi,SLOT_BASE+APPDATA.wnd_clientbox
2655
    add    esi,SLOT_BASE+APPDATA.wnd_clientbox
2656
    lea    edi,[ebx+44]
2656
    lea    edi,[ebx+44]
2657
    mov    ecx,4
2657
    mov    ecx,4
2658
    rep    movsd
2658
    rep    movsd
2659
 
2659
 
2660
    ; Window state
2660
    ; Window state
2661
 
2661
 
2662
    mov    esi,[esp]
2662
    mov    esi,[esp]
2663
    shl    esi,5
2663
    shl    esi,5
2664
    add    esi,window_data + WDATA.box
2664
    add    esi,window_data + WDATA.box
2665
    mov    al,[esi+WDATA.fl_wstate]
2665
    mov    al,[esi+WDATA.fl_wstate]
2666
    mov    [edi],al
2666
    mov    [edi],al
2667
 
2667
 
2668
    pop    ebx
2668
    pop    ebx
2669
    pop    eax
2669
    pop    eax
2670
 
2670
 
2671
    ; return number of processes
2671
    ; return number of processes
2672
 
2672
 
2673
    mov    eax,[TASK_COUNT]
2673
    mov    eax,[TASK_COUNT]
2674
    mov    [esp+36],eax
2674
    mov    [esp+36],eax
2675
    ret
2675
    ret
2676
 
2676
 
2677
align 4
2677
align 4
2678
sys_clock:
2678
sys_clock:
2679
        cli
2679
        cli
2680
  ; Mikhail Lisovin  xx Jan 2005
2680
  ; Mikhail Lisovin  xx Jan 2005
2681
  @@:   mov   al, 10
2681
  @@:   mov   al, 10
2682
        out   0x70, al
2682
        out   0x70, al
2683
        in    al, 0x71
2683
        in    al, 0x71
2684
        test  al, al
2684
        test  al, al
2685
        jns   @f
2685
        jns   @f
2686
        mov   esi, 1
2686
        mov   esi, 1
2687
        call  delay_ms
2687
        call  delay_ms
2688
        jmp   @b
2688
        jmp   @b
2689
  @@:
2689
  @@:
2690
  ; end Lisovin's fix
2690
  ; end Lisovin's fix
2691
 
2691
 
2692
        xor   al,al           ; seconds
2692
        xor   al,al           ; seconds
2693
        out   0x70,al
2693
        out   0x70,al
2694
        in    al,0x71
2694
        in    al,0x71
2695
        movzx ecx,al
2695
        movzx ecx,al
2696
        mov   al,02           ; minutes
2696
        mov   al,02           ; minutes
2697
        shl   ecx,16
2697
        shl   ecx,16
2698
        out   0x70,al
2698
        out   0x70,al
2699
        in    al,0x71
2699
        in    al,0x71
2700
        movzx edx,al
2700
        movzx edx,al
2701
        mov   al,04           ; hours
2701
        mov   al,04           ; hours
2702
        shl   edx,8
2702
        shl   edx,8
2703
        out   0x70,al
2703
        out   0x70,al
2704
        in    al,0x71
2704
        in    al,0x71
2705
        add   ecx,edx
2705
        add   ecx,edx
2706
        movzx edx,al
2706
        movzx edx,al
2707
        add   ecx,edx
2707
        add   ecx,edx
2708
        sti
2708
        sti
2709
        mov   [esp+36],ecx
2709
        mov   [esp+36],ecx
2710
        ret
2710
        ret
2711
 
2711
 
2712
 
2712
 
2713
align 4
2713
align 4
2714
 
2714
 
2715
sys_date:
2715
sys_date:
2716
 
2716
 
2717
        cli
2717
        cli
2718
 
2718
 
2719
  @@:   mov   al, 10
2719
  @@:   mov   al, 10
2720
        out   0x70, al
2720
        out   0x70, al
2721
        in    al, 0x71
2721
        in    al, 0x71
2722
        test  al, al
2722
        test  al, al
2723
        jns   @f
2723
        jns   @f
2724
        mov   esi, 1
2724
        mov   esi, 1
2725
        call  delay_ms
2725
        call  delay_ms
2726
        jmp   @b
2726
        jmp   @b
2727
  @@:
2727
  @@:
2728
 
2728
 
2729
        mov     ch,0
2729
        mov     ch,0
2730
        mov     al,7            ; date
2730
        mov     al,7            ; date
2731
        out     0x70,al
2731
        out     0x70,al
2732
        in      al,0x71
2732
        in      al,0x71
2733
        mov     cl,al
2733
        mov     cl,al
2734
        mov     al,8            ; month
2734
        mov     al,8            ; month
2735
        shl     ecx,16
2735
        shl     ecx,16
2736
        out     0x70,al
2736
        out     0x70,al
2737
        in      al,0x71
2737
        in      al,0x71
2738
        mov     ch,al
2738
        mov     ch,al
2739
        mov     al,9            ; year
2739
        mov     al,9            ; year
2740
        out     0x70,al
2740
        out     0x70,al
2741
        in      al,0x71
2741
        in      al,0x71
2742
        mov     cl,al
2742
        mov     cl,al
2743
        sti
2743
        sti
2744
        mov     [esp+36],ecx
2744
        mov     [esp+36],ecx
2745
        ret
2745
        ret
2746
 
2746
 
2747
 
2747
 
2748
; redraw status
2748
; redraw status
2749
 
2749
 
2750
sys_redrawstat:
2750
sys_redrawstat:
2751
 
2751
 
2752
    cmp  eax,1
2752
    cmp  eax,1
2753
    jne  no_widgets_away
2753
    jne  no_widgets_away
2754
 
2754
 
2755
    ; buttons away
2755
    ; buttons away
2756
 
2756
 
2757
    mov   ecx,[CURRENT_TASK]
2757
    mov   ecx,[CURRENT_TASK]
2758
 
2758
 
2759
  sys_newba2:
2759
  sys_newba2:
2760
 
2760
 
2761
    mov   edi,[BTN_ADDR]
2761
    mov   edi,[BTN_ADDR]
2762
    cmp   [edi],dword 0  ; empty button list ?
2762
    cmp   [edi],dword 0  ; empty button list ?
2763
    je    end_of_buttons_away
2763
    je    end_of_buttons_away
2764
 
2764
 
2765
    movzx ebx,word [edi]
2765
    movzx ebx,word [edi]
2766
    inc   ebx
2766
    inc   ebx
2767
 
2767
 
2768
    mov   eax,edi
2768
    mov   eax,edi
2769
 
2769
 
2770
  sys_newba:
2770
  sys_newba:
2771
 
2771
 
2772
    dec   ebx
2772
    dec   ebx
2773
    jz    end_of_buttons_away
2773
    jz    end_of_buttons_away
2774
 
2774
 
2775
    add   eax,0x10
2775
    add   eax,0x10
2776
    cmp   cx,[eax]
2776
    cmp   cx,[eax]
2777
    jnz   sys_newba
2777
    jnz   sys_newba
2778
 
2778
 
2779
    push  eax ebx ecx
2779
    push  eax ebx ecx
2780
    mov   ecx,ebx
2780
    mov   ecx,ebx
2781
    inc   ecx
2781
    inc   ecx
2782
    shl   ecx,4
2782
    shl   ecx,4
2783
    mov   ebx,eax
2783
    mov   ebx,eax
2784
    add   eax,0x10
2784
    add   eax,0x10
2785
    call  memmove
2785
    call  memmove
2786
    dec   dword [edi]
2786
    dec   dword [edi]
2787
    pop   ecx ebx eax
2787
    pop   ecx ebx eax
2788
 
2788
 
2789
    jmp   sys_newba2
2789
    jmp   sys_newba2
2790
 
2790
 
2791
  end_of_buttons_away:
2791
  end_of_buttons_away:
2792
 
2792
 
2793
    ret
2793
    ret
2794
 
2794
 
2795
  no_widgets_away:
2795
  no_widgets_away:
2796
 
2796
 
2797
    cmp   eax,2
2797
    cmp   eax,2
2798
    jnz   srl1
2798
    jnz   srl1
2799
 
2799
 
2800
    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
2801
    add   edx,draw_data-CURRENT_TASK
2801
    add   edx,draw_data-CURRENT_TASK
2802
    mov   [edx+RECT.left], 0
2802
    mov   [edx+RECT.left], 0
2803
    mov   [edx+RECT.top], 0
2803
    mov   [edx+RECT.top], 0
2804
    mov   eax,[ScreenWidth]
2804
    mov   eax,[ScreenWidth]
2805
    mov   [edx+RECT.right],eax
2805
    mov   [edx+RECT.right],eax
2806
    mov   eax,[ScreenHeight]
2806
    mov   eax,[ScreenHeight]
2807
    mov   [edx+RECT.bottom],eax
2807
    mov   [edx+RECT.bottom],eax
2808
 
2808
 
2809
    mov   edi,[TASK_BASE]
2809
    mov   edi,[TASK_BASE]
2810
    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
2811
 
2811
 
2812
    call  sys_window_mouse
2812
    call  sys_window_mouse
2813
 
2813
 
2814
    ret
2814
    ret
2815
 
2815
 
2816
  srl1:
2816
  srl1:
2817
 
2817
 
2818
    ret
2818
    ret
2819
 
2819
 
2820
 
2820
 
2821
sys_drawwindow:
2821
sys_drawwindow:
2822
 
2822
 
2823
    mov   edi,ecx
2823
    mov   edi,ecx
2824
    shr   edi,16+8
2824
    shr   edi,16+8
2825
    and   edi,15
2825
    and   edi,15
2826
 
2826
 
2827
    cmp   edi,0   ; type I    - original style
2827
    cmp   edi,0   ; type I    - original style
2828
    jne   nosyswI
2828
    jne   nosyswI
2829
    inc   [mouse_pause]
2829
    inc   [mouse_pause]
2830
    call  [disable_mouse]
2830
    call  [disable_mouse]
2831
    call  sys_set_window
2831
    call  sys_set_window
2832
    call  [disable_mouse]
2832
    call  [disable_mouse]
2833
    call  drawwindow_I
2833
    call  drawwindow_I
2834
    ;dec   [mouse_pause]
2834
    ;dec   [mouse_pause]
2835
    ;call   [draw_pointer]
2835
    ;call   [draw_pointer]
2836
    ;ret
2836
    ;ret
2837
    jmp   draw_window_caption.2
2837
    jmp   draw_window_caption.2
2838
  nosyswI:
2838
  nosyswI:
2839
 
2839
 
2840
    cmp   edi,1   ; type II   - only reserve area, no draw
2840
    cmp   edi,1   ; type II   - only reserve area, no draw
2841
    jne   nosyswII
2841
    jne   nosyswII
2842
    inc   [mouse_pause]
2842
    inc   [mouse_pause]
2843
    call  [disable_mouse]
2843
    call  [disable_mouse]
2844
    call  sys_set_window
2844
    call  sys_set_window
2845
    call  [disable_mouse]
2845
    call  [disable_mouse]
2846
    call  sys_window_mouse
2846
    call  sys_window_mouse
2847
    dec   [mouse_pause]
2847
    dec   [mouse_pause]
2848
    call   [draw_pointer]
2848
    call   [draw_pointer]
2849
    ret
2849
    ret
2850
  nosyswII:
2850
  nosyswII:
2851
 
2851
 
2852
    cmp   edi,2   ; type III  - new style
2852
    cmp   edi,2   ; type III  - new style
2853
    jne   nosyswIII
2853
    jne   nosyswIII
2854
    inc   [mouse_pause]
2854
    inc   [mouse_pause]
2855
    call  [disable_mouse]
2855
    call  [disable_mouse]
2856
    call  sys_set_window
2856
    call  sys_set_window
2857
    call  [disable_mouse]
2857
    call  [disable_mouse]
2858
    call  drawwindow_III
2858
    call  drawwindow_III
2859
    ;dec   [mouse_pause]
2859
    ;dec   [mouse_pause]
2860
    ;call   [draw_pointer]
2860
    ;call   [draw_pointer]
2861
    ;ret
2861
    ;ret
2862
    jmp   draw_window_caption.2
2862
    jmp   draw_window_caption.2
2863
  nosyswIII:
2863
  nosyswIII:
2864
 
2864
 
2865
    cmp   edi,3   ; type IV - skinned window
2865
    cmp   edi,3   ; type IV - skinned window
2866
    jne   nosyswIV
2866
    jne   nosyswIV
2867
 
2867
 
2868
    ; parameter for drawwindow_IV
2868
    ; parameter for drawwindow_IV
2869
    push  0
2869
    push  0
2870
    mov   edi, [TASK_COUNT]
2870
    mov   edi, [TASK_COUNT]
2871
    movzx edi, word [WIN_POS + edi*2]
2871
    movzx edi, word [WIN_POS + edi*2]
2872
    cmp   edi, [CURRENT_TASK]
2872
    cmp   edi, [CURRENT_TASK]
2873
    jne   @f
2873
    jne   @f
2874
    inc   dword [esp]
2874
    inc   dword [esp]
2875
 @@:
2875
 @@:
2876
 
2876
 
2877
    inc   [mouse_pause]
2877
    inc   [mouse_pause]
2878
    call  [disable_mouse]
2878
    call  [disable_mouse]
2879
    call  sys_set_window
2879
    call  sys_set_window
2880
    call  [disable_mouse]
2880
    call  [disable_mouse]
2881
    call  drawwindow_IV
2881
    call  drawwindow_IV
2882
    ;dec   [mouse_pause]
2882
    ;dec   [mouse_pause]
2883
    ;call   [draw_pointer]
2883
    ;call   [draw_pointer]
2884
    ;ret
2884
    ;ret
2885
    jmp   draw_window_caption.2
2885
    jmp   draw_window_caption.2
2886
  nosyswIV:
2886
  nosyswIV:
2887
 
2887
 
2888
    ret
2888
    ret
2889
 
2889
 
2890
 
2890
 
2891
draw_window_caption:
2891
draw_window_caption:
2892
        inc     [mouse_pause]
2892
        inc     [mouse_pause]
2893
        call    [disable_mouse]
2893
        call    [disable_mouse]
2894
 
2894
 
2895
        xor     eax,eax
2895
        xor     eax,eax
2896
        mov     edx,[TASK_COUNT]
2896
        mov     edx,[TASK_COUNT]
2897
        movzx   edx,word[WIN_POS+edx*2]
2897
        movzx   edx,word[WIN_POS+edx*2]
2898
        cmp     edx,[CURRENT_TASK]
2898
        cmp     edx,[CURRENT_TASK]
2899
        jne     @f
2899
        jne     @f
2900
        inc     eax
2900
        inc     eax
2901
    @@: mov     edx,[CURRENT_TASK]
2901
    @@: mov     edx,[CURRENT_TASK]
2902
        shl     edx,5
2902
        shl     edx,5
2903
        add     edx,window_data
2903
        add     edx,window_data
2904
        movzx   ebx,[edx+WDATA.fl_wstyle]
2904
        movzx   ebx,[edx+WDATA.fl_wstyle]
2905
        and     bl,0x0F
2905
        and     bl,0x0F
2906
        cmp     bl,3
2906
        cmp     bl,3
2907
        jne     .not_style_3
2907
        jne     .not_style_3
2908
 
2908
 
2909
        push    edx
2909
        push    edx
2910
        call    drawwindow_IV_caption
2910
        call    drawwindow_IV_caption
2911
        add     esp,4
2911
        add     esp,4
2912
        jmp     .2
2912
        jmp     .2
2913
 
2913
 
2914
  .not_style_3:
2914
  .not_style_3:
2915
        cmp     bl,2
2915
        cmp     bl,2
2916
        jne     .not_style_2
2916
        jne     .not_style_2
2917
 
2917
 
2918
        call    drawwindow_III_caption
2918
        call    drawwindow_III_caption
2919
        jmp     .2
2919
        jmp     .2
2920
 
2920
 
2921
  .not_style_2:
2921
  .not_style_2:
2922
        cmp     bl,0
2922
        cmp     bl,0
2923
        jne     .2
2923
        jne     .2
2924
 
2924
 
2925
        call    drawwindow_I_caption
2925
        call    drawwindow_I_caption
2926
 
2926
 
2927
;--------------------------------------------------------------
2927
;--------------------------------------------------------------
2928
  .2:   ;jmp     @f
2928
  .2:   ;jmp     @f
2929
        mov     edi,[CURRENT_TASK]
2929
        mov     edi,[CURRENT_TASK]
2930
        shl     edi,5
2930
        shl     edi,5
2931
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2931
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2932
        jz      @f
2932
        jz      @f
2933
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2933
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2934
        or      ecx,ecx
2934
        or      ecx,ecx
2935
        jz      @f
2935
        jz      @f
2936
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
2936
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
2937
 
2937
 
2938
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2938
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2939
        and     al,0x0F
2939
        and     al,0x0F
2940
        cmp     al,3
2940
        cmp     al,3
2941
        jne     .not_skinned
2941
        jne     .not_skinned
2942
 
2942
 
2943
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2943
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2944
        mov     bp,word[edi+window_data+WDATA.box.top]
2944
        mov     bp,word[edi+window_data+WDATA.box.top]
2945
        movzx   eax,word[edi+window_data+WDATA.box.width]
2945
        movzx   eax,word[edi+window_data+WDATA.box.width]
2946
        sub     ax,[_skinmargins.left]
2946
        sub     ax,[_skinmargins.left]
2947
        sub     ax,[_skinmargins.right]
2947
        sub     ax,[_skinmargins.right]
2948
        cwde
2948
        cwde
2949
        cdq
2949
        cdq
2950
        mov     ebx,6
2950
        mov     ebx,6
2951
        idiv    ebx
2951
        idiv    ebx
2952
        or      eax,eax
2952
        or      eax,eax
2953
        js      @f
2953
        js      @f
2954
        mov     edx,eax
2954
        mov     edx,eax
2955
        mov     eax,dword[_skinmargins.left-2]
2955
        mov     eax,dword[_skinmargins.left-2]
2956
        mov     ax,word[_skinh]
2956
        mov     ax,word[_skinh]
2957
        sub     ax,[_skinmargins.bottom]
2957
        sub     ax,[_skinmargins.bottom]
2958
        sub     ax,[_skinmargins.top]
2958
        sub     ax,[_skinmargins.top]
2959
        sar     ax,1
2959
        sar     ax,1
2960
        adc     ax,0
2960
        adc     ax,0
2961
        add     ax,[_skinmargins.top]
2961
        add     ax,[_skinmargins.top]
2962
        add     ax,-3
2962
        add     ax,-3
2963
        add     eax,ebp
2963
        add     eax,ebp
2964
        jmp     .dodraw
2964
        jmp     .dodraw
2965
 
2965
 
2966
  .not_skinned:
2966
  .not_skinned:
2967
        cmp     al,1
2967
        cmp     al,1
2968
        je      @f
2968
        je      @f
2969
 
2969
 
2970
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2970
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2971
        mov     bp,word[edi+window_data+WDATA.box.top]
2971
        mov     bp,word[edi+window_data+WDATA.box.top]
2972
        movzx   eax,word[edi+window_data+WDATA.box.width]
2972
        movzx   eax,word[edi+window_data+WDATA.box.width]
2973
        sub     eax,16
2973
        sub     eax,16
2974
        cwde
2974
        cwde
2975
        cdq
2975
        cdq
2976
        mov     ebx,6
2976
        mov     ebx,6
2977
        idiv    ebx
2977
        idiv    ebx
2978
        or      eax,eax
2978
        or      eax,eax
2979
        js      @f
2979
        js      @f
2980
        mov     edx,eax
2980
        mov     edx,eax
2981
        mov     eax,0x00080007
2981
        mov     eax,0x00080007
2982
        add     eax,ebp
2982
        add     eax,ebp
2983
.dodraw:
2983
.dodraw:
2984
        mov     ebx,[common_colours+16];0x00FFFFFF
2984
        mov     ebx,[common_colours+16];0x00FFFFFF
2985
        or      ebx, 0x80000000
2985
        or      ebx, 0x80000000
2986
        xor     edi,edi
2986
        xor     edi,edi
2987
        call    dtext
2987
        call    dtext
2988
 
2988
 
2989
    @@:
2989
    @@:
2990
;--------------------------------------------------------------
2990
;--------------------------------------------------------------
2991
        dec     [mouse_pause]
2991
        dec     [mouse_pause]
2992
        call    [draw_pointer]
2992
        call    [draw_pointer]
2993
        ret
2993
        ret
2994
 
2994
 
2995
iglobal
2995
iglobal
2996
align 4
2996
align 4
2997
window_topleft dd \
2997
window_topleft dd \
2998
  1, 21,\
2998
  1, 21,\
2999
  0,  0,\
2999
  0,  0,\
3000
  5, 20,\
3000
  5, 20,\
3001
  5,  ?
3001
  5,  ?
3002
endg
3002
endg
3003
 
3003
 
3004
set_window_clientbox:
3004
set_window_clientbox:
3005
        push    eax ecx edi
3005
        push    eax ecx edi
3006
 
3006
 
3007
        mov     eax,[_skinh]
3007
        mov     eax,[_skinh]
3008
        mov     [window_topleft+4*7],eax
3008
        mov     [window_topleft+4*7],eax
3009
 
3009
 
3010
        mov     ecx,edi
3010
        mov     ecx,edi
3011
        sub     edi,window_data
3011
        sub     edi,window_data
3012
        shl     edi,3
3012
        shl     edi,3
3013
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3013
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3014
        jz      @f
3014
        jz      @f
3015
 
3015
 
3016
        movzx   eax,[ecx+WDATA.fl_wstyle]
3016
        movzx   eax,[ecx+WDATA.fl_wstyle]
3017
        and     eax,0x0F
3017
        and     eax,0x0F
3018
        mov     eax,[eax*8+window_topleft+0]
3018
        mov     eax,[eax*8+window_topleft+0]
3019
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3019
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3020
        shl     eax,1
3020
        shl     eax,1
3021
        neg     eax
3021
        neg     eax
3022
        add     eax,[ecx+WDATA.box.width]
3022
        add     eax,[ecx+WDATA.box.width]
3023
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3023
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3024
 
3024
 
3025
        movzx   eax,[ecx+WDATA.fl_wstyle]
3025
        movzx   eax,[ecx+WDATA.fl_wstyle]
3026
        and     eax,0x0F
3026
        and     eax,0x0F
3027
        push    [eax*8+window_topleft+0]
3027
        push    [eax*8+window_topleft+0]
3028
        mov     eax,[eax*8+window_topleft+4]
3028
        mov     eax,[eax*8+window_topleft+4]
3029
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3029
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3030
        neg     eax
3030
        neg     eax
3031
        sub     eax,[esp]
3031
        sub     eax,[esp]
3032
        add     eax,[ecx+WDATA.box.height]
3032
        add     eax,[ecx+WDATA.box.height]
3033
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3033
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3034
        add     esp,4
3034
        add     esp,4
3035
 
3035
 
3036
        pop     edi ecx eax
3036
        pop     edi ecx eax
3037
        ret
3037
        ret
3038
    @@:
3038
    @@:
3039
        xor     eax,eax
3039
        xor     eax,eax
3040
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3040
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3041
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3041
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3042
        mov     eax,[ecx+WDATA.box.width]
3042
        mov     eax,[ecx+WDATA.box.width]
3043
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3043
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3044
        mov     eax,[ecx+WDATA.box.height]
3044
        mov     eax,[ecx+WDATA.box.height]
3045
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3045
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3046
 
3046
 
3047
        pop     edi ecx eax
3047
        pop     edi ecx eax
3048
        ret
3048
        ret
3049
 
3049
 
3050
sys_set_window:
3050
sys_set_window:
3051
 
3051
 
3052
    mov   edi,[CURRENT_TASK]
3052
    mov   edi,[CURRENT_TASK]
3053
    shl   edi,5
3053
    shl   edi,5
3054
    add   edi,window_data
3054
    add   edi,window_data
3055
 
3055
 
3056
    ; colors
3056
    ; colors
3057
    mov   [edi+WDATA.cl_workarea],ecx
3057
    mov   [edi+WDATA.cl_workarea],ecx
3058
    mov   [edi+WDATA.cl_titlebar],edx
3058
    mov   [edi+WDATA.cl_titlebar],edx
3059
    mov   [edi+WDATA.cl_frames],esi
3059
    mov   [edi+WDATA.cl_frames],esi
3060
 
3060
 
3061
    ; check flag (?)
3061
    ; check flag (?)
3062
    test  [edi+WDATA.fl_wdrawn],1
3062
    test  [edi+WDATA.fl_wdrawn],1
3063
    jnz   newd
3063
    jnz   newd
3064
 
3064
 
3065
    push  eax
3065
    push  eax
3066
    mov   eax,[timer_ticks] ;[0xfdf0]
3066
    mov   eax,[timer_ticks] ;[0xfdf0]
3067
    add   eax,100
3067
    add   eax,100
3068
    mov   [new_window_starting],eax
3068
    mov   [new_window_starting],eax
3069
    pop   eax
3069
    pop   eax
3070
 
3070
 
3071
    mov   word[edi+WDATA.box.width],ax
3071
    mov   word[edi+WDATA.box.width],ax
3072
    mov   word[edi+WDATA.box.height],bx
3072
    mov   word[edi+WDATA.box.height],bx
3073
    sar   eax,16
3073
    sar   eax,16
3074
    sar   ebx,16
3074
    sar   ebx,16
3075
    mov   word[edi+WDATA.box.left],ax
3075
    mov   word[edi+WDATA.box.left],ax
3076
    mov   word[edi+WDATA.box.top],bx
3076
    mov   word[edi+WDATA.box.top],bx
3077
 
3077
 
3078
    call  check_window_position
3078
    call  check_window_position
3079
 
3079
 
3080
    call  set_window_clientbox
3080
    call  set_window_clientbox
3081
 
3081
 
3082
    push  ecx esi edi               ; save for window fullscreen/resize
3082
    push  ecx esi edi               ; save for window fullscreen/resize
3083
    ;mov   esi,edi
3083
    ;mov   esi,edi
3084
 
3084
 
3085
        mov     cl,[edi+WDATA.fl_wstyle]
3085
        mov     cl,[edi+WDATA.fl_wstyle]
3086
 
3086
 
3087
    sub   edi,window_data
3087
    sub   edi,window_data
3088
    shl   edi,3
3088
    shl   edi,3
3089
    add   edi,SLOT_BASE
3089
    add   edi,SLOT_BASE
3090
 
3090
 
3091
        and     cl,0x0F
3091
        and     cl,0x0F
3092
        mov     [edi+APPDATA.wnd_caption],0
3092
        mov     [edi+APPDATA.wnd_caption],0
3093
        cmp     cl,3
3093
        cmp     cl,3
3094
        jne     @f
3094
        jne     @f
3095
        mov     [edi+APPDATA.wnd_caption],esi
3095
        mov     [edi+APPDATA.wnd_caption],esi
3096
    @@: mov     esi,[esp+0]
3096
    @@: mov     esi,[esp+0]
3097
 
3097
 
3098
    add   edi, APPDATA.saved_box
3098
    add   edi, APPDATA.saved_box
3099
        movsd
3099
        movsd
3100
        movsd
3100
        movsd
3101
        movsd
3101
        movsd
3102
        movsd
3102
        movsd
3103
    pop   edi esi ecx
3103
    pop   edi esi ecx
3104
 
3104
 
3105
    push  eax ebx ecx edx
3105
    push  eax ebx ecx edx
3106
;;;    mov   eax, 1
3106
;;;    mov   eax, 1
3107
;;;    call  delay_hs
3107
;;;    call  delay_hs
3108
    mov   eax, [edi+WDATA.box.left]
3108
    mov   eax, [edi+WDATA.box.left]
3109
    mov   ebx, [edi+WDATA.box.top]
3109
    mov   ebx, [edi+WDATA.box.top]
3110
    mov   ecx, [edi+WDATA.box.width]
3110
    mov   ecx, [edi+WDATA.box.width]
3111
    mov   edx, [edi+WDATA.box.height]
3111
    mov   edx, [edi+WDATA.box.height]
3112
    add   ecx, eax
3112
    add   ecx, eax
3113
    add   edx, ebx
3113
    add   edx, ebx
3114
    call  calculatescreen
3114
    call  calculatescreen
3115
    pop   edx ecx ebx eax
3115
    pop   edx ecx ebx eax
3116
 
3116
 
3117
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3117
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3118
    mov   [BTN_COUNT],byte 0           ; empty button buffer
3118
    mov   [BTN_COUNT],byte 0           ; empty button buffer
3119
 
3119
 
3120
  newd:
3120
  newd:
3121
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
3121
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
3122
    mov   edx,edi
3122
    mov   edx,edi
3123
 
3123
 
3124
    ret
3124
    ret
3125
 
3125
 
3126
syscall_windowsettings:
3126
syscall_windowsettings:
3127
 
3127
 
3128
  .set_window_caption:
3128
  .set_window_caption:
3129
        dec     eax     ; subfunction #1 - set window caption
3129
        dec     eax     ; subfunction #1 - set window caption
3130
        jnz     .get_window_caption
3130
        jnz     .get_window_caption
3131
 
3131
 
3132
        ; NOTE: only window owner thread can set its caption,
3132
        ; NOTE: only window owner thread can set its caption,
3133
        ;       so there's no parameter for PID/TID
3133
        ;       so there's no parameter for PID/TID
3134
 
3134
 
3135
        mov     edi,[CURRENT_TASK]
3135
        mov     edi,[CURRENT_TASK]
3136
        shl     edi,5
3136
        shl     edi,5
3137
 
3137
 
3138
        ; have to check if caption is within application memory limit
3138
        ; have to check if caption is within application memory limit
3139
        ; check is trivial, and if application resizes its memory,
3139
        ; check is trivial, and if application resizes its memory,
3140
        ;   caption still can become over bounds
3140
        ;   caption still can become over bounds
3141
; diamond, 31.10.2006: check removed because with new memory manager
3141
; diamond, 31.10.2006: check removed because with new memory manager
3142
; there can be valid data after APPDATA.mem_size bound
3142
; there can be valid data after APPDATA.mem_size bound
3143
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3143
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3144
;        add     ecx,255 ; max caption length
3144
;        add     ecx,255 ; max caption length
3145
;        cmp     ebx,ecx
3145
;        cmp     ebx,ecx
3146
;        ja      .exit_fail
3146
;        ja      .exit_fail
3147
 
3147
 
3148
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3148
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3149
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3149
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3150
 
3150
 
3151
        call    draw_window_caption
3151
        call    draw_window_caption
3152
 
3152
 
3153
        xor     eax,eax ; eax = 0 (success)
3153
        xor     eax,eax ; eax = 0 (success)
3154
        ret
3154
        ret
3155
 
3155
 
3156
  .get_window_caption:
3156
  .get_window_caption:
3157
        dec     eax     ; subfunction #2 - get window caption
3157
        dec     eax     ; subfunction #2 - get window caption
3158
        jnz     .exit_fail
3158
        jnz     .exit_fail
3159
 
3159
 
3160
        ; not implemented yet
3160
        ; not implemented yet
3161
 
3161
 
3162
  .exit_fail:
3162
  .exit_fail:
3163
        xor     eax,eax
3163
        xor     eax,eax
3164
        inc     eax     ; eax = 1 (fail)
3164
        inc     eax     ; eax = 1 (fail)
3165
        ret
3165
        ret
3166
 
3166
 
3167
 
3167
 
3168
sys_window_move:
3168
sys_window_move:
3169
 
3169
 
3170
        mov     edi,[CURRENT_TASK]
3170
        mov     edi,[CURRENT_TASK]
3171
        shl     edi,5
3171
        shl     edi,5
3172
        add     edi,window_data
3172
        add     edi,window_data
3173
 
3173
 
3174
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3174
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3175
        jnz     .window_move_return
3175
        jnz     .window_move_return
3176
 
3176
 
3177
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3177
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3178
        push    dword [edi + WDATA.box.top]
3178
        push    dword [edi + WDATA.box.top]
3179
        push    dword [edi + WDATA.box.width]
3179
        push    dword [edi + WDATA.box.width]
3180
        push    dword [edi + WDATA.box.height]
3180
        push    dword [edi + WDATA.box.height]
3181
 
3181
 
3182
        cmp   eax,-1                  ; set new position and size
3182
        cmp   eax,-1                  ; set new position and size
3183
        je    .no_x_reposition
3183
        je    .no_x_reposition
3184
        mov     [edi + WDATA.box.left], eax
3184
        mov     [edi + WDATA.box.left], eax
3185
      .no_x_reposition:
3185
      .no_x_reposition:
3186
        cmp   ebx,-1
3186
        cmp   ebx,-1
3187
        je    .no_y_reposition
3187
        je    .no_y_reposition
3188
        mov     [edi + WDATA.box.top], ebx
3188
        mov     [edi + WDATA.box.top], ebx
3189
      .no_y_reposition:
3189
      .no_y_reposition:
3190
 
3190
 
3191
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3191
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3192
        jnz     .no_y_resizing
3192
        jnz     .no_y_resizing
3193
 
3193
 
3194
        cmp   ecx,-1
3194
        cmp   ecx,-1
3195
        je    .no_x_resizing
3195
        je    .no_x_resizing
3196
        mov     [edi + WDATA.box.width], ecx
3196
        mov     [edi + WDATA.box.width], ecx
3197
      .no_x_resizing:
3197
      .no_x_resizing:
3198
        cmp   edx,-1
3198
        cmp   edx,-1
3199
        je    .no_y_resizing
3199
        je    .no_y_resizing
3200
        mov     [edi + WDATA.box.height], edx
3200
        mov     [edi + WDATA.box.height], edx
3201
      .no_y_resizing:
3201
      .no_y_resizing:
3202
 
3202
 
3203
        call  check_window_position
3203
        call  check_window_position
3204
        call  set_window_clientbox
3204
        call  set_window_clientbox
3205
 
3205
 
3206
        pushad                       ; save for window fullscreen/resize
3206
        pushad                       ; save for window fullscreen/resize
3207
        mov   esi,edi
3207
        mov   esi,edi
3208
        sub   edi,window_data
3208
        sub   edi,window_data
3209
        shr   edi,5
3209
        shr   edi,5
3210
        shl   edi,8
3210
        shl   edi,8
3211
        add   edi, SLOT_BASE + APPDATA.saved_box
3211
        add   edi, SLOT_BASE + APPDATA.saved_box
3212
        mov   ecx,4
3212
        mov   ecx,4
3213
        cld
3213
        cld
3214
        rep   movsd
3214
        rep   movsd
3215
        popad
3215
        popad
3216
 
3216
 
3217
        pushad                       ; calculcate screen at new position
3217
        pushad                       ; calculcate screen at new position
3218
        mov   eax, [edi + WDATA.box.left]
3218
        mov   eax, [edi + WDATA.box.left]
3219
        mov   ebx, [edi + WDATA.box.top]
3219
        mov   ebx, [edi + WDATA.box.top]
3220
        mov   ecx, [edi + WDATA.box.width]
3220
        mov   ecx, [edi + WDATA.box.width]
3221
        mov   edx, [edi + WDATA.box.height]
3221
        mov   edx, [edi + WDATA.box.height]
3222
        add   ecx,eax
3222
        add   ecx,eax
3223
        add   edx,ebx
3223
        add   edx,ebx
3224
 
3224
 
3225
        call  calculatescreen
3225
        call  calculatescreen
3226
        popad
3226
        popad
3227
 
3227
 
3228
        pop   edx                   ; calculcate screen at old position
3228
        pop   edx                   ; calculcate screen at old position
3229
        pop   ecx
3229
        pop   ecx
3230
        pop   ebx
3230
        pop   ebx
3231
        pop   eax
3231
        pop   eax
3232
        add   ecx,eax
3232
        add   ecx,eax
3233
        add   edx,ebx
3233
        add   edx,ebx
3234
        mov   [dlx],eax             ; save for drawlimits
3234
        mov   [dlx],eax             ; save for drawlimits
3235
        mov   [dly],ebx
3235
        mov   [dly],ebx
3236
        mov   [dlxe],ecx
3236
        mov   [dlxe],ecx
3237
        mov   [dlye],edx
3237
        mov   [dlye],edx
3238
        call  calculatescreen
3238
        call  calculatescreen
3239
 
3239
 
3240
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3240
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3241
 
3241
 
3242
        mov   eax,edi               ; redraw screen at old position
3242
        mov   eax,edi               ; redraw screen at old position
3243
        xor   esi,esi
3243
        xor   esi,esi
3244
        call  redrawscreen
3244
        call  redrawscreen
3245
 
3245
 
3246
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3246
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3247
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3247
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3248
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3248
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3249
 
3249
 
3250
        call  [draw_pointer]
3250
        call  [draw_pointer]
3251
 
3251
 
3252
        mov   [window_move_pr],0
3252
        mov   [window_move_pr],0
3253
 
3253
 
3254
      .window_move_return:
3254
      .window_move_return:
3255
 
3255
 
3256
        ret
3256
        ret
3257
 
3257
 
3258
uglobal
3258
uglobal
3259
  window_move_pr   dd  0x0
3259
  window_move_pr   dd  0x0
3260
  window_move_eax  dd  0x0
3260
  window_move_eax  dd  0x0
3261
  window_move_ebx  dd  0x0
3261
  window_move_ebx  dd  0x0
3262
  window_move_ecx  dd  0x0
3262
  window_move_ecx  dd  0x0
3263
  window_move_edx  dd  0x0
3263
  window_move_edx  dd  0x0
3264
endg
3264
endg
3265
 
3265
 
3266
;ok - 100% work
3266
;ok - 100% work
3267
;nt - not tested
3267
;nt - not tested
3268
;---------------------------------------------------------------------------------------------
3268
;---------------------------------------------------------------------------------------------
3269
;eax
3269
;eax
3270
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3270
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3271
;1 - change task. Ret nothing. Block. ok.
3271
;1 - change task. Ret nothing. Block. ok.
3272
;2 - performance control
3272
;2 - performance control
3273
; ebx
3273
; ebx
3274
; 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.
3275
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3275
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3276
; 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.
3277
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3277
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3278
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3278
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3279
;eax
3279
;eax
3280
;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.
3281
;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.
3282
;---------------------------------------------------------------------------------------------
3282
;---------------------------------------------------------------------------------------------
3283
sys_sheduler: ;noname & halyavin
3283
sys_sheduler: ;noname & halyavin
3284
    cmp eax,0
3284
    cmp eax,0
3285
    je shed_counter
3285
    je shed_counter
3286
    cmp eax,2
3286
    cmp eax,2
3287
    je perf_control
3287
    je perf_control
3288
    cmp eax,3
3288
    cmp eax,3
3289
    je rdmsr_instr
3289
    je rdmsr_instr
3290
    cmp eax,4
3290
    cmp eax,4
3291
    je wrmsr_instr
3291
    je wrmsr_instr
3292
    cmp eax,1
3292
    cmp eax,1
3293
    jne not_supported
3293
    jne not_supported
3294
    call change_task ;delay,0
3294
    call change_task ;delay,0
3295
ret
3295
ret
3296
shed_counter:
3296
shed_counter:
3297
    mov eax,[context_counter]
3297
    mov eax,[context_counter]
3298
    mov [esp+36],eax
3298
    mov [esp+36],eax
3299
not_supported:
3299
not_supported:
3300
ret
3300
ret
3301
perf_control:
3301
perf_control:
3302
    inc eax ;now eax=3
3302
    inc eax ;now eax=3
3303
    cmp ebx,eax
3303
    cmp ebx,eax
3304
    je cache_disable
3304
    je cache_disable
3305
    dec eax
3305
    dec eax
3306
    cmp ebx,eax
3306
    cmp ebx,eax
3307
    je cache_enable
3307
    je cache_enable
3308
    dec eax
3308
    dec eax
3309
    cmp ebx,eax
3309
    cmp ebx,eax
3310
    je is_cache_enabled
3310
    je is_cache_enabled
3311
    dec eax
3311
    dec eax
3312
    cmp ebx,eax
3312
    cmp ebx,eax
3313
    je modify_pce
3313
    je modify_pce
3314
ret
3314
ret
3315
 
3315
 
3316
rdmsr_instr:
3316
rdmsr_instr:
3317
;now counter in ecx
3317
;now counter in ecx
3318
;(edx:eax) esi:edi => edx:esi
3318
;(edx:eax) esi:edi => edx:esi
3319
mov eax,esi
3319
mov eax,esi
3320
rdmsr
3320
rdmsr
3321
mov [esp+36],eax
3321
mov [esp+36],eax
3322
mov [esp+24],edx ;ret in ebx?
3322
mov [esp+24],edx ;ret in ebx?
3323
ret
3323
ret
3324
 
3324
 
3325
wrmsr_instr:
3325
wrmsr_instr:
3326
;now counter in ecx
3326
;now counter in ecx
3327
;(edx:eax) esi:edi => edx:esi
3327
;(edx:eax) esi:edi => edx:esi
3328
	; Fast Call MSR can't be destroy
3328
	; Fast Call MSR can't be destroy
3329
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3329
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3330
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3330
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3331
	cmp	ecx, MSR_SYSENTER_CS
3331
	cmp	ecx, MSR_SYSENTER_CS
3332
	je	@f
3332
	je	@f
3333
	cmp	ecx, MSR_SYSENTER_ESP
3333
	cmp	ecx, MSR_SYSENTER_ESP
3334
	je	@f
3334
	je	@f
3335
	cmp	ecx, MSR_SYSENTER_EIP
3335
	cmp	ecx, MSR_SYSENTER_EIP
3336
	je	@f
3336
	je	@f
3337
	cmp	ecx, MSR_AMD_STAR
3337
	cmp	ecx, MSR_AMD_STAR
3338
	je	@f
3338
	je	@f
3339
 
3339
 
3340
	mov	eax, esi
3340
	mov	eax, esi
3341
	wrmsr
3341
	wrmsr
3342
	; mov	[esp + 36], eax
3342
	; mov	[esp + 36], eax
3343
	; mov	[esp + 24], edx ;ret in ebx?
3343
	; mov	[esp + 24], edx ;ret in ebx?
3344
@@:
3344
@@:
3345
ret
3345
ret
3346
 
3346
 
3347
cache_disable:
3347
cache_disable:
3348
       mov eax,cr0
3348
       mov eax,cr0
3349
       or  eax,01100000000000000000000000000000b
3349
       or  eax,01100000000000000000000000000000b
3350
       mov cr0,eax
3350
       mov cr0,eax
3351
       wbinvd ;set MESI
3351
       wbinvd ;set MESI
3352
ret
3352
ret
3353
 
3353
 
3354
cache_enable:
3354
cache_enable:
3355
       mov eax,cr0
3355
       mov eax,cr0
3356
       and eax,10011111111111111111111111111111b
3356
       and eax,10011111111111111111111111111111b
3357
       mov cr0,eax
3357
       mov cr0,eax
3358
ret
3358
ret
3359
 
3359
 
3360
is_cache_enabled:
3360
is_cache_enabled:
3361
       mov eax,cr0
3361
       mov eax,cr0
3362
       mov ebx,eax
3362
       mov ebx,eax
3363
       and eax,01100000000000000000000000000000b
3363
       and eax,01100000000000000000000000000000b
3364
       jz cache_disabled
3364
       jz cache_disabled
3365
       mov [esp+36],ebx
3365
       mov [esp+36],ebx
3366
cache_disabled:
3366
cache_disabled:
3367
       mov dword [esp+36],eax ;0
3367
       mov dword [esp+36],eax ;0
3368
ret
3368
ret
3369
 
3369
 
3370
modify_pce:
3370
modify_pce:
3371
       mov eax,cr4
3371
       mov eax,cr4
3372
;       mov ebx,0
3372
;       mov ebx,0
3373
;       or  bx,100000000b ;pce
3373
;       or  bx,100000000b ;pce
3374
;       xor eax,ebx ;invert pce
3374
;       xor eax,ebx ;invert pce
3375
       bts eax,8 ;pce=cr4[8]
3375
       bts eax,8 ;pce=cr4[8]
3376
       mov cr4,eax
3376
       mov cr4,eax
3377
       mov [esp+36],eax
3377
       mov [esp+36],eax
3378
ret
3378
ret
3379
;---------------------------------------------------------------------------------------------
3379
;---------------------------------------------------------------------------------------------
3380
 
3380
 
3381
 
3381
 
3382
; check if pixel is allowed to be drawn
3382
; check if pixel is allowed to be drawn
3383
 
3383
 
3384
checkpixel:
3384
checkpixel:
3385
        push eax edx
3385
        push eax edx
3386
 
3386
 
3387
        mov  edx,[ScreenWidth]     ; screen x size
3387
        mov  edx,[ScreenWidth]     ; screen x size
3388
        inc  edx
3388
        inc  edx
3389
        imul edx, ebx
3389
        imul edx, ebx
3390
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3390
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3391
 
3391
 
3392
        xor  ecx, ecx
3392
        xor  ecx, ecx
3393
        mov  eax, [CURRENT_TASK]
3393
        mov  eax, [CURRENT_TASK]
3394
        cmp  al, dl
3394
        cmp  al, dl
3395
        setne cl
3395
        setne cl
3396
 
3396
 
3397
        pop  edx eax
3397
        pop  edx eax
3398
        ret
3398
        ret
3399
 
3399
 
3400
iglobal
3400
iglobal
3401
  cpustring db 'CPU',0
3401
  cpustring db 'CPU',0
3402
endg
3402
endg
3403
 
3403
 
3404
uglobal
3404
uglobal
3405
background_defined    db    0    ; diamond, 11.04.2006
3405
background_defined    db    0    ; diamond, 11.04.2006
3406
endg
3406
endg
3407
 
3407
 
3408
align 4
3408
align 4
3409
; check misc
3409
; check misc
3410
 
3410
 
3411
checkmisc:
3411
checkmisc:
3412
 
3412
 
3413
    cmp   [ctrl_alt_del], 1
3413
    cmp   [ctrl_alt_del], 1
3414
    jne   nocpustart
3414
    jne   nocpustart
3415
 
3415
 
3416
        mov     ebp, cpustring
3416
        mov     ebp, cpustring
3417
        call    fs_execute_from_sysdir
3417
        call    fs_execute_from_sysdir
3418
 
3418
 
3419
    mov   [ctrl_alt_del], 0
3419
    mov   [ctrl_alt_del], 0
3420
 
3420
 
3421
nocpustart:
3421
nocpustart:
3422
    cmp   [mouse_active], 1
3422
    cmp   [mouse_active], 1
3423
    jne   mouse_not_active
3423
    jne   mouse_not_active
3424
    mov   [mouse_active], 0
3424
    mov   [mouse_active], 0
3425
    xor   edi, edi
3425
    xor   edi, edi
3426
    mov   ecx,  [TASK_COUNT]
3426
    mov   ecx,  [TASK_COUNT]
3427
set_mouse_event:
3427
set_mouse_event:
3428
    add   edi, 256
3428
    add   edi, 256
3429
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3429
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3430
    loop  set_mouse_event
3430
    loop  set_mouse_event
3431
 
3431
 
3432
mouse_not_active:
3432
mouse_not_active:
3433
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3433
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3434
    jz    nobackgr
3434
    jz    nobackgr
3435
    cmp    [background_defined], 0
3435
    cmp    [background_defined], 0
3436
    jz    nobackgr
3436
    jz    nobackgr
3437
;    mov   [REDRAW_BACKGROUND],byte 2
3437
;    mov   [REDRAW_BACKGROUND],byte 2
3438
;    call  change_task
3438
;    call  change_task
3439
    xor   edi, edi
3439
    xor   edi, edi
3440
    mov   ecx,  [TASK_COUNT]
3440
    mov   ecx,  [TASK_COUNT]
3441
set_bgr_event:
3441
set_bgr_event:
3442
    add   edi, 256
3442
    add   edi, 256
3443
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3443
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3444
    loop  set_bgr_event
3444
    loop  set_bgr_event
3445
    mov   [draw_data+32 + RECT.left],dword 0
3445
    mov   [draw_data+32 + RECT.left],dword 0
3446
    mov   [draw_data+32 + RECT.top],dword 0
3446
    mov   [draw_data+32 + RECT.top],dword 0
3447
    mov   eax,[ScreenWidth]
3447
    mov   eax,[ScreenWidth]
3448
    mov   ebx,[ScreenHeight]
3448
    mov   ebx,[ScreenHeight]
3449
    mov   [draw_data+32 + RECT.right],eax
3449
    mov   [draw_data+32 + RECT.right],eax
3450
    mov   [draw_data+32 + RECT.bottom],ebx
3450
    mov   [draw_data+32 + RECT.bottom],ebx
3451
    call  drawbackground
3451
    call  drawbackground
3452
    mov   [REDRAW_BACKGROUND],byte 0
3452
    mov   [REDRAW_BACKGROUND],byte 0
3453
    mov   [MOUSE_BACKGROUND],byte 0
3453
    mov   [MOUSE_BACKGROUND],byte 0
3454
 
3454
 
3455
nobackgr:
3455
nobackgr:
3456
 
3456
 
3457
    ; system shutdown request
3457
    ; system shutdown request
3458
 
3458
 
3459
    cmp  [SYS_SHUTDOWN],byte 0
3459
    cmp  [SYS_SHUTDOWN],byte 0
3460
    je   noshutdown
3460
    je   noshutdown
3461
 
3461
 
3462
    mov  edx,[shutdown_processes]
3462
    mov  edx,[shutdown_processes]
3463
    sub  dl,2
3463
    sub  dl,2
3464
 
3464
 
3465
    cmp  [SYS_SHUTDOWN],dl
3465
    cmp  [SYS_SHUTDOWN],dl
3466
    jne  no_mark_system_shutdown
3466
    jne  no_mark_system_shutdown
3467
 
3467
 
3468
    mov   edx,OS_BASE+0x3040
3468
    mov   edx,OS_BASE+0x3040
3469
    movzx ecx,byte [SYS_SHUTDOWN]
3469
    movzx ecx,byte [SYS_SHUTDOWN]
3470
    add   ecx,5
3470
    add   ecx,5
3471
markz:
3471
markz:
3472
    mov   [edx+TASKDATA.state],byte 3
3472
    mov   [edx+TASKDATA.state],byte 3
3473
    add   edx,0x20
3473
    add   edx,0x20
3474
    loop  markz
3474
    loop  markz
3475
 
3475
 
3476
  no_mark_system_shutdown:
3476
  no_mark_system_shutdown:
3477
 
3477
 
3478
    call [disable_mouse]
3478
    call [disable_mouse]
3479
 
3479
 
3480
    dec  byte [SYS_SHUTDOWN]
3480
    dec  byte [SYS_SHUTDOWN]
3481
 
3481
 
3482
    cmp  [SYS_SHUTDOWN],byte 0
3482
    cmp  [SYS_SHUTDOWN],byte 0
3483
    je   system_shutdown
3483
    je   system_shutdown
3484
 
3484
 
3485
noshutdown:
3485
noshutdown:
3486
 
3486
 
3487
 
3487
 
3488
    mov   eax,[TASK_COUNT]                  ; termination
3488
    mov   eax,[TASK_COUNT]                  ; termination
3489
    mov   ebx,TASK_DATA+TASKDATA.state
3489
    mov   ebx,TASK_DATA+TASKDATA.state
3490
    mov   esi,1
3490
    mov   esi,1
3491
 
3491
 
3492
newct:
3492
newct:
3493
    mov   cl,[ebx]
3493
    mov   cl,[ebx]
3494
    cmp   cl,byte 3
3494
    cmp   cl,byte 3
3495
    jz    terminate
3495
    jz    terminate
3496
    cmp   cl,byte 4
3496
    cmp   cl,byte 4
3497
    jz    terminate
3497
    jz    terminate
3498
 
3498
 
3499
    add   ebx,0x20
3499
    add   ebx,0x20
3500
    inc   esi
3500
    inc   esi
3501
    dec   eax
3501
    dec   eax
3502
    jnz   newct
3502
    jnz   newct
3503
 
3503
 
3504
    ret
3504
    ret
3505
 
3505
 
3506
 
3506
 
3507
; redraw screen
3507
; redraw screen
3508
 
3508
 
3509
redrawscreen:
3509
redrawscreen:
3510
 
3510
 
3511
; 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
3512
 
3512
 
3513
         pushad
3513
         pushad
3514
         push  eax
3514
         push  eax
3515
 
3515
 
3516
;;;         mov   eax,2
3516
;;;         mov   eax,2
3517
;;;         call  delay_hs
3517
;;;         call  delay_hs
3518
 
3518
 
3519
         ;mov   ecx,0               ; redraw flags for apps
3519
         ;mov   ecx,0               ; redraw flags for apps
3520
         xor   ecx,ecx
3520
         xor   ecx,ecx
3521
       newdw2:
3521
       newdw2:
3522
 
3522
 
3523
         inc   ecx
3523
         inc   ecx
3524
         push  ecx
3524
         push  ecx
3525
 
3525
 
3526
         mov   eax,ecx
3526
         mov   eax,ecx
3527
         shl   eax,5
3527
         shl   eax,5
3528
         add   eax,window_data
3528
         add   eax,window_data
3529
 
3529
 
3530
         cmp   eax,[esp+4]
3530
         cmp   eax,[esp+4]
3531
         je    not_this_task
3531
         je    not_this_task
3532
                                   ; check if window in redraw area
3532
                                   ; check if window in redraw area
3533
         mov   edi,eax
3533
         mov   edi,eax
3534
 
3534
 
3535
         cmp   ecx,1               ; limit for background
3535
         cmp   ecx,1               ; limit for background
3536
         jz    bgli
3536
         jz    bgli
3537
 
3537
 
3538
         mov   eax, [edi + WDATA.box.left]
3538
         mov   eax, [edi + WDATA.box.left]
3539
         mov   ebx, [edi + WDATA.box.top]
3539
         mov   ebx, [edi + WDATA.box.top]
3540
         mov   ecx, [edi + WDATA.box.width]
3540
         mov   ecx, [edi + WDATA.box.width]
3541
         mov   edx, [edi + WDATA.box.height]
3541
         mov   edx, [edi + WDATA.box.height]
3542
         add   ecx,eax
3542
         add   ecx,eax
3543
         add   edx,ebx
3543
         add   edx,ebx
3544
 
3544
 
3545
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3545
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3546
         cmp   ecx,ebx
3546
         cmp   ecx,ebx
3547
         jb    ricino
3547
         jb    ricino
3548
 
3548
 
3549
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3549
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3550
         cmp   ecx,eax
3550
         cmp   ecx,eax
3551
         jb    ricino
3551
         jb    ricino
3552
 
3552
 
3553
         mov   eax, [edi + WDATA.box.left]
3553
         mov   eax, [edi + WDATA.box.left]
3554
         mov   ebx, [edi + WDATA.box.top]
3554
         mov   ebx, [edi + WDATA.box.top]
3555
         mov   ecx, [edi + WDATA.box.width]
3555
         mov   ecx, [edi + WDATA.box.width]
3556
         mov   edx, [edi + WDATA.box.height]
3556
         mov   edx, [edi + WDATA.box.height]
3557
         add   ecx, eax
3557
         add   ecx, eax
3558
         add   edx, ebx
3558
         add   edx, ebx
3559
 
3559
 
3560
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3560
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3561
         cmp   edx,eax
3561
         cmp   edx,eax
3562
         jb    ricino
3562
         jb    ricino
3563
 
3563
 
3564
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3564
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3565
         cmp   ecx,eax
3565
         cmp   ecx,eax
3566
         jb    ricino
3566
         jb    ricino
3567
 
3567
 
3568
        bgli:
3568
        bgli:
3569
 
3569
 
3570
         cmp   edi,esi
3570
         cmp   edi,esi
3571
         jz    ricino
3571
         jz    ricino
3572
 
3572
 
3573
         mov   eax,edi
3573
         mov   eax,edi
3574
         add   eax,draw_data-window_data
3574
         add   eax,draw_data-window_data
3575
 
3575
 
3576
         mov   ebx,[dlx]          ; set limits
3576
         mov   ebx,[dlx]          ; set limits
3577
         mov   [eax + RECT.left], ebx
3577
         mov   [eax + RECT.left], ebx
3578
         mov   ebx,[dly]
3578
         mov   ebx,[dly]
3579
         mov   [eax + RECT.top], ebx
3579
         mov   [eax + RECT.top], ebx
3580
         mov   ebx,[dlxe]
3580
         mov   ebx,[dlxe]
3581
         mov   [eax + RECT.right], ebx
3581
         mov   [eax + RECT.right], ebx
3582
         mov   ebx,[dlye]
3582
         mov   ebx,[dlye]
3583
         mov   [eax + RECT.bottom], ebx
3583
         mov   [eax + RECT.bottom], ebx
3584
 
3584
 
3585
         sub   eax,draw_data-window_data
3585
         sub   eax,draw_data-window_data
3586
 
3586
 
3587
         cmp   ecx,1
3587
         cmp   ecx,1
3588
         jne   nobgrd
3588
         jne   nobgrd
3589
         cmp   esi,1
3589
         cmp   esi,1
3590
         je    newdw8
3590
         je    newdw8
3591
         call  drawbackground
3591
         call  drawbackground
3592
 
3592
 
3593
       newdw8:
3593
       newdw8:
3594
       nobgrd:
3594
       nobgrd:
3595
 
3595
 
3596
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3596
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3597
 
3597
 
3598
       ricino:
3598
       ricino:
3599
 
3599
 
3600
       not_this_task:
3600
       not_this_task:
3601
 
3601
 
3602
         pop   ecx
3602
         pop   ecx
3603
 
3603
 
3604
         cmp   ecx,[TASK_COUNT]
3604
         cmp   ecx,[TASK_COUNT]
3605
         jle   newdw2
3605
         jle   newdw2
3606
 
3606
 
3607
         pop  eax
3607
         pop  eax
3608
         popad
3608
         popad
3609
 
3609
 
3610
         ret
3610
         ret
3611
 
3611
 
3612
calculatebackground:   ; background
3612
calculatebackground:   ; background
3613
 
3613
 
3614
        ; all black
3614
        ; all black
3615
 
3615
 
3616
        mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3616
        mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3617
        xor   eax, eax
3617
        xor   eax, eax
3618
        mov   ecx, 1023    ;0x0fff00 / 4
3618
        mov   ecx, 1023    ;0x0fff00 / 4
3619
        cld
3619
        cld
3620
        rep   stosd
3620
        rep   stosd
3621
 
3621
 
3622
        mov   edi,display_data              ; set os to use all pixels
3622
        mov   edi,display_data              ; set os to use all pixels
3623
        mov   eax,0x01010101
3623
        mov   eax,0x01010101
3624
        mov   ecx,1280*1024 / 4
3624
        mov   ecx,1280*1024 / 4
3625
        rep   stosd
3625
        rep   stosd
3626
 
3626
 
3627
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3627
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3628
 
3628
 
3629
        ret
3629
        ret
3630
 
3630
 
3631
uglobal
3631
uglobal
3632
  imax    dd 0x0
3632
  imax    dd 0x0
3633
endg
3633
endg
3634
 
3634
 
3635
 
3635
 
3636
 
3636
 
3637
delay_ms:     ; delay in 1/1000 sec
3637
delay_ms:     ; delay in 1/1000 sec
3638
 
3638
 
3639
 
3639
 
3640
        push  eax
3640
        push  eax
3641
        push  ecx
3641
        push  ecx
3642
 
3642
 
3643
        mov   ecx,esi
3643
        mov   ecx,esi
3644
        ; 
3644
        ; 
3645
        imul  ecx, 33941
3645
        imul  ecx, 33941
3646
        shr   ecx, 9
3646
        shr   ecx, 9
3647
        ; 
3647
        ; 
3648
 
3648
 
3649
        in    al,0x61
3649
        in    al,0x61
3650
        and   al,0x10
3650
        and   al,0x10
3651
        mov   ah,al
3651
        mov   ah,al
3652
        cld
3652
        cld
3653
 
3653
 
3654
 cnt1:  in    al,0x61
3654
 cnt1:  in    al,0x61
3655
        and   al,0x10
3655
        and   al,0x10
3656
        cmp   al,ah
3656
        cmp   al,ah
3657
        jz    cnt1
3657
        jz    cnt1
3658
 
3658
 
3659
        mov   ah,al
3659
        mov   ah,al
3660
        loop  cnt1
3660
        loop  cnt1
3661
 
3661
 
3662
        pop   ecx
3662
        pop   ecx
3663
        pop   eax
3663
        pop   eax
3664
 
3664
 
3665
        ret
3665
        ret
3666
 
3666
 
3667
 
3667
 
3668
set_app_param:
3668
set_app_param:
3669
        push edi
3669
        push edi
3670
 
3670
 
3671
        mov  edi,[TASK_BASE]
3671
        mov  edi,[TASK_BASE]
3672
        mov  [edi+TASKDATA.event_mask],eax
3672
        mov  [edi+TASKDATA.event_mask],eax
3673
 
3673
 
3674
        pop  edi
3674
        pop  edi
3675
        ret
3675
        ret
3676
 
3676
 
3677
 
3677
 
3678
 
3678
 
3679
delay_hs:     ; delay in 1/100 secs
3679
delay_hs:     ; delay in 1/100 secs
3680
        push  eax
3680
        push  eax
3681
        push  ecx
3681
        push  ecx
3682
        push  edx
3682
        push  edx
3683
 
3683
 
3684
        mov   edx,[timer_ticks]
3684
        mov   edx,[timer_ticks]
3685
        add   edx,eax
3685
        add   edx,eax
3686
 
3686
 
3687
      newtic:
3687
      newtic:
3688
        mov   ecx,[timer_ticks]
3688
        mov   ecx,[timer_ticks]
3689
        cmp   edx,ecx
3689
        cmp   edx,ecx
3690
        jbe   zerodelay
3690
        jbe   zerodelay
3691
 
3691
 
3692
        call  change_task
3692
        call  change_task
3693
 
3693
 
3694
        jmp   newtic
3694
        jmp   newtic
3695
 
3695
 
3696
      zerodelay:
3696
      zerodelay:
3697
        pop   edx
3697
        pop   edx
3698
        pop   ecx
3698
        pop   ecx
3699
        pop   eax
3699
        pop   eax
3700
 
3700
 
3701
        ret
3701
        ret
3702
 
3702
 
3703
 
3703
 
3704
memmove:       ; memory move in bytes
3704
memmove:       ; memory move in bytes
3705
 
3705
 
3706
; eax = from
3706
; eax = from
3707
; ebx = to
3707
; ebx = to
3708
; ecx = no of bytes
3708
; ecx = no of bytes
3709
    test ecx, ecx
3709
    test ecx, ecx
3710
    jle  .ret
3710
    jle  .ret
3711
 
3711
 
3712
 
3712
 
3713
    push esi edi ecx
3713
    push esi edi ecx
3714
 
3714
 
3715
    mov  edi, ebx
3715
    mov  edi, ebx
3716
    mov  esi, eax
3716
    mov  esi, eax
3717
 
3717
 
3718
    test ecx, not 11b
3718
    test ecx, not 11b
3719
    jz   @f
3719
    jz   @f
3720
 
3720
 
3721
    push ecx
3721
    push ecx
3722
    shr  ecx, 2
3722
    shr  ecx, 2
3723
    rep  movsd
3723
    rep  movsd
3724
    pop  ecx
3724
    pop  ecx
3725
    and  ecx, 11b
3725
    and  ecx, 11b
3726
    jz   .finish
3726
    jz   .finish
3727
  @@:
3727
  @@:
3728
    rep  movsb
3728
    rep  movsb
3729
 
3729
 
3730
  .finish:
3730
  .finish:
3731
    pop  ecx edi esi
3731
    pop  ecx edi esi
3732
  .ret:
3732
  .ret:
3733
    ret
3733
    ret
3734
 
3734
 
3735
 
3735
 
3736
;  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.
3737
;align 4
3737
;align 4
3738
;
3738
;
3739
;read_floppy_file:
3739
;read_floppy_file:
3740
;
3740
;
3741
;; as input
3741
;; as input
3742
;;
3742
;;
3743
;; eax pointer to file
3743
;; eax pointer to file
3744
;; ebx file lenght
3744
;; ebx file lenght
3745
;; ecx start 512 byte block number
3745
;; ecx start 512 byte block number
3746
;; edx number of blocks to read
3746
;; edx number of blocks to read
3747
;; esi pointer to return/work area (atleast 20 000 bytes)
3747
;; esi pointer to return/work area (atleast 20 000 bytes)
3748
;;
3748
;;
3749
;;
3749
;;
3750
;; on return
3750
;; on return
3751
;;
3751
;;
3752
;; eax = 0 command succesful
3752
;; eax = 0 command succesful
3753
;;       1 no fd base and/or partition defined
3753
;;       1 no fd base and/or partition defined
3754
;;       2 yet unsupported FS
3754
;;       2 yet unsupported FS
3755
;;       3 unknown FS
3755
;;       3 unknown FS
3756
;;       4 partition not defined at hd
3756
;;       4 partition not defined at hd
3757
;;       5 file not found
3757
;;       5 file not found
3758
;; ebx = size of file
3758
;; ebx = size of file
3759
;
3759
;
3760
;     mov   edi,[TASK_BASE]
3760
;     mov   edi,[TASK_BASE]
3761
;     add   edi,0x10
3761
;     add   edi,0x10
3762
;     add   esi,[edi]
3762
;     add   esi,[edi]
3763
;     add   eax,[edi]
3763
;     add   eax,[edi]
3764
;
3764
;
3765
;     pushad
3765
;     pushad
3766
;     mov  edi,esi
3766
;     mov  edi,esi
3767
;     add  edi,1024
3767
;     add  edi,1024
3768
;     mov  esi,0x100000+19*512
3768
;     mov  esi,0x100000+19*512
3769
;     sub  ecx,1
3769
;     sub  ecx,1
3770
;     shl  ecx,9
3770
;     shl  ecx,9
3771
;     add  esi,ecx
3771
;     add  esi,ecx
3772
;     shl  edx,9
3772
;     shl  edx,9
3773
;     mov  ecx,edx
3773
;     mov  ecx,edx
3774
;     cld
3774
;     cld
3775
;     rep  movsb
3775
;     rep  movsb
3776
;     popad
3776
;     popad
3777
;
3777
;
3778
;     mov   [esp+36],eax
3778
;     mov   [esp+36],eax
3779
;     mov   [esp+24],ebx
3779
;     mov   [esp+24],ebx
3780
;     ret
3780
;     ret
3781
 
3781
 
3782
 
3782
 
3783
 
3783
 
3784
align 4
3784
align 4
3785
 
3785
 
3786
sys_programirq:
3786
sys_programirq:
3787
 
3787
 
3788
    mov   edi,[TASK_BASE]
3788
    mov   edi,[TASK_BASE]
3789
    add   eax,[edi+TASKDATA.mem_start]
3789
    add   eax,[edi+TASKDATA.mem_start]
3790
 
3790
 
3791
    cmp   ebx,16
3791
    cmp   ebx,16
3792
    jae   .not_owner
3792
    jae   .not_owner
3793
    mov   edi,[TASK_BASE]
3793
    mov   edi,[TASK_BASE]
3794
    mov   edi,[edi+TASKDATA.pid]
3794
    mov   edi,[edi+TASKDATA.pid]
3795
    cmp   edi,[irq_owner+ebx*4]
3795
    cmp   edi,[irq_owner+ebx*4]
3796
    je    spril1
3796
    je    spril1
3797
.not_owner:
3797
.not_owner:
3798
    mov   [esp+36],dword 1
3798
    mov   [esp+36],dword 1
3799
    ret
3799
    ret
3800
  spril1:
3800
  spril1:
3801
 
3801
 
3802
    mov   esi,eax
3802
    mov   esi,eax
3803
    shl   ebx,6
3803
    shl   ebx,6
3804
    add   ebx,irq00read
3804
    add   ebx,irq00read
3805
    mov   edi,ebx
3805
    mov   edi,ebx
3806
    mov   ecx,16
3806
    mov   ecx,16
3807
    cld
3807
    cld
3808
    rep   movsd
3808
    rep   movsd
3809
    mov   [esp+36],dword 0
3809
    mov   [esp+36],dword 0
3810
    ret
3810
    ret
3811
 
3811
 
3812
 
3812
 
3813
align 4
3813
align 4
3814
 
3814
 
3815
get_irq_data:
3815
get_irq_data:
3816
     cmp   eax,16
3816
     cmp   eax,16
3817
     jae   .not_owner
3817
     jae   .not_owner
3818
     mov   edx,eax           ; check for correct owner
3818
     mov   edx,eax           ; check for correct owner
3819
     shl   edx,2
3819
     shl   edx,2
3820
     add   edx,irq_owner
3820
     add   edx,irq_owner
3821
     mov   edx,[edx]
3821
     mov   edx,[edx]
3822
     mov   edi,[TASK_BASE]
3822
     mov   edi,[TASK_BASE]
3823
     mov   edi,[edi+TASKDATA.pid]
3823
     mov   edi,[edi+TASKDATA.pid]
3824
     cmp   edx,edi
3824
     cmp   edx,edi
3825
     je    gidril1
3825
     je    gidril1
3826
.not_owner:
3826
.not_owner:
3827
     mov   [esp+32],dword 2     ; ecx=2
3827
     mov   [esp+32],dword 2     ; ecx=2
3828
     ret
3828
     ret
3829
 
3829
 
3830
  gidril1:
3830
  gidril1:
3831
 
3831
 
3832
     mov   ebx,eax
3832
     mov   ebx,eax
3833
     shl   ebx,12
3833
     shl   ebx,12
3834
     add   ebx,IRQ_SAVE
3834
     add   ebx,IRQ_SAVE
3835
     mov   eax,[ebx]
3835
     mov   eax,[ebx]
3836
     mov   ecx,1
3836
     mov   ecx,1
3837
     test  eax,eax
3837
     test  eax,eax
3838
     jz    gid1
3838
     jz    gid1
3839
 
3839
 
3840
     dec   eax
3840
     dec   eax
3841
     mov   esi,ebx
3841
     mov   esi,ebx
3842
     mov   [ebx],eax
3842
     mov   [ebx],eax
3843
     movzx ebx,byte [ebx+0x10]
3843
     movzx ebx,byte [ebx+0x10]
3844
     add   esi,0x10
3844
     add   esi,0x10
3845
     mov   edi,esi
3845
     mov   edi,esi
3846
     inc   esi
3846
     inc   esi
3847
     mov   ecx,4000 / 4
3847
     mov   ecx,4000 / 4
3848
     cld
3848
     cld
3849
     rep   movsd
3849
     rep   movsd
3850
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
3850
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
3851
   gid1:
3851
   gid1:
3852
     mov   [esp+36],eax
3852
     mov   [esp+36],eax
3853
     mov   [esp+32],ecx
3853
     mov   [esp+32],ecx
3854
     mov   [esp+24],ebx
3854
     mov   [esp+24],ebx
3855
     ret
3855
     ret
3856
 
3856
 
3857
 
3857
 
3858
set_io_access_rights:
3858
set_io_access_rights:
3859
 
3859
 
3860
     pushad
3860
     pushad
3861
 
3861
 
3862
     mov edi, tss._io_map_0
3862
     mov edi, tss._io_map_0
3863
 
3863
 
3864
;     mov   ecx,eax
3864
;     mov   ecx,eax
3865
;     and   ecx,7    ; offset in byte
3865
;     and   ecx,7    ; offset in byte
3866
 
3866
 
3867
;     shr   eax,3    ; number of byte
3867
;     shr   eax,3    ; number of byte
3868
;     add   edi,eax
3868
;     add   edi,eax
3869
 
3869
 
3870
;     mov   ebx,1
3870
;     mov   ebx,1
3871
;     shl   ebx,cl
3871
;     shl   ebx,cl
3872
 
3872
 
3873
     cmp   ebp,0                ; enable access - ebp = 0
3873
     cmp   ebp,0                ; enable access - ebp = 0
3874
     jne   siar1
3874
     jne   siar1
3875
 
3875
 
3876
;     not   ebx
3876
;     not   ebx
3877
;     and   [edi],byte bl
3877
;     and   [edi],byte bl
3878
     btr [edi], eax
3878
     btr [edi], eax
3879
 
3879
 
3880
     popad
3880
     popad
3881
 
3881
 
3882
     ret
3882
     ret
3883
 
3883
 
3884
siar1:
3884
siar1:
3885
 
3885
 
3886
     bts [edi], eax
3886
     bts [edi], eax
3887
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3887
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3888
 
3888
 
3889
     popad
3889
     popad
3890
 
3890
 
3891
     ret
3891
     ret
3892
 
3892
 
3893
r_f_port_area:
3893
r_f_port_area:
3894
 
3894
 
3895
     test  eax, eax
3895
     test  eax, eax
3896
     jnz   free_port_area
3896
     jnz   free_port_area
3897
;     je    r_port_area
3897
;     je    r_port_area
3898
;     jmp   free_port_area
3898
;     jmp   free_port_area
3899
 
3899
 
3900
;   r_port_area:
3900
;   r_port_area:
3901
 
3901
 
3902
     pushad
3902
     pushad
3903
 
3903
 
3904
     cmp   ebx,ecx            ; beginning > end ?
3904
     cmp   ebx,ecx            ; beginning > end ?
3905
     ja    rpal1
3905
     ja    rpal1
3906
     cmp   ecx,65536
3906
     cmp   ecx,65536
3907
     jae   rpal1
3907
     jae   rpal1
3908
     mov   esi,[RESERVED_PORTS]
3908
     mov   esi,[RESERVED_PORTS]
3909
     test  esi,esi            ; no reserved areas ?
3909
     test  esi,esi            ; no reserved areas ?
3910
     je    rpal2
3910
     je    rpal2
3911
     cmp   esi,255            ; max reserved
3911
     cmp   esi,255            ; max reserved
3912
     jae   rpal1
3912
     jae   rpal1
3913
 rpal3:
3913
 rpal3:
3914
     mov   edi,esi
3914
     mov   edi,esi
3915
     shl   edi,4
3915
     shl   edi,4
3916
     add   edi,RESERVED_PORTS
3916
     add   edi,RESERVED_PORTS
3917
     cmp   ebx,[edi+8]
3917
     cmp   ebx,[edi+8]
3918
     ja    rpal4
3918
     ja    rpal4
3919
     cmp   ecx,[edi+4]
3919
     cmp   ecx,[edi+4]
3920
     jae   rpal1
3920
     jae   rpal1
3921
;     jb    rpal4
3921
;     jb    rpal4
3922
;     jmp   rpal1
3922
;     jmp   rpal1
3923
 rpal4:
3923
 rpal4:
3924
 
3924
 
3925
     dec   esi
3925
     dec   esi
3926
     jnz   rpal3
3926
     jnz   rpal3
3927
     jmp   rpal2
3927
     jmp   rpal2
3928
   rpal1:
3928
   rpal1:
3929
     popad
3929
     popad
3930
     mov   eax,1
3930
     mov   eax,1
3931
     ret
3931
     ret
3932
 
3932
 
3933
   rpal2:
3933
   rpal2:
3934
     popad
3934
     popad
3935
 
3935
 
3936
 
3936
 
3937
     ; enable port access at port IO map
3937
     ; enable port access at port IO map
3938
     cli
3938
     cli
3939
     pushad                        ; start enable io map
3939
     pushad                        ; start enable io map
3940
 
3940
 
3941
     cmp   ecx,65536 ;16384
3941
     cmp   ecx,65536 ;16384
3942
     jae   no_unmask_io ; jge
3942
     jae   no_unmask_io ; jge
3943
 
3943
 
3944
     mov   eax,ebx
3944
     mov   eax,ebx
3945
 
3945
 
3946
   new_port_access:
3946
   new_port_access:
3947
 
3947
 
3948
     pushad
3948
     pushad
3949
 
3949
 
3950
     xor   ebp,ebp                ; enable - eax = port
3950
     xor   ebp,ebp                ; enable - eax = port
3951
     call  set_io_access_rights
3951
     call  set_io_access_rights
3952
 
3952
 
3953
     popad
3953
     popad
3954
 
3954
 
3955
     inc   eax
3955
     inc   eax
3956
     cmp   eax,ecx
3956
     cmp   eax,ecx
3957
     jbe   new_port_access
3957
     jbe   new_port_access
3958
 
3958
 
3959
   no_unmask_io:
3959
   no_unmask_io:
3960
 
3960
 
3961
     popad                         ; end enable io map
3961
     popad                         ; end enable io map
3962
     sti
3962
     sti
3963
 
3963
 
3964
     mov   edi,[RESERVED_PORTS]
3964
     mov   edi,[RESERVED_PORTS]
3965
     add   edi,1
3965
     add   edi,1
3966
     mov   [RESERVED_PORTS],edi
3966
     mov   [RESERVED_PORTS],edi
3967
     shl   edi,4
3967
     shl   edi,4
3968
     add   edi,RESERVED_PORTS
3968
     add   edi,RESERVED_PORTS
3969
     mov   esi,[TASK_BASE]
3969
     mov   esi,[TASK_BASE]
3970
     mov   esi,[esi+TASKDATA.pid]
3970
     mov   esi,[esi+TASKDATA.pid]
3971
     mov   [edi],esi
3971
     mov   [edi],esi
3972
     mov   [edi+4],ebx
3972
     mov   [edi+4],ebx
3973
     mov   [edi+8],ecx
3973
     mov   [edi+8],ecx
3974
 
3974
 
3975
     xor   eax, eax
3975
     xor   eax, eax
3976
     ret
3976
     ret
3977
 
3977
 
3978
free_port_area:
3978
free_port_area:
3979
 
3979
 
3980
     pushad
3980
     pushad
3981
 
3981
 
3982
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
3982
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
3983
     test  esi,esi
3983
     test  esi,esi
3984
     je    frpal2
3984
     je    frpal2
3985
     mov   edx,[TASK_BASE]
3985
     mov   edx,[TASK_BASE]
3986
     mov   edx,[edx+TASKDATA.pid]
3986
     mov   edx,[edx+TASKDATA.pid]
3987
   frpal3:
3987
   frpal3:
3988
     mov   edi,esi
3988
     mov   edi,esi
3989
     shl   edi,4
3989
     shl   edi,4
3990
     add   edi,RESERVED_PORTS
3990
     add   edi,RESERVED_PORTS
3991
     cmp   edx,[edi]
3991
     cmp   edx,[edi]
3992
     jne   frpal4
3992
     jne   frpal4
3993
     cmp   ebx,[edi+4]
3993
     cmp   ebx,[edi+4]
3994
     jne   frpal4
3994
     jne   frpal4
3995
     cmp   ecx,[edi+8]
3995
     cmp   ecx,[edi+8]
3996
     jne   frpal4
3996
     jne   frpal4
3997
     jmp   frpal1
3997
     jmp   frpal1
3998
   frpal4:
3998
   frpal4:
3999
     dec   esi
3999
     dec   esi
4000
     jnz   frpal3
4000
     jnz   frpal3
4001
   frpal2:
4001
   frpal2:
4002
     popad
4002
     popad
4003
     mov   eax,1
4003
     mov   eax,1
4004
     ret
4004
     ret
4005
   frpal1:
4005
   frpal1:
4006
     mov   ecx,256
4006
     mov   ecx,256
4007
     sub   ecx,esi
4007
     sub   ecx,esi
4008
     shl   ecx,4
4008
     shl   ecx,4
4009
     mov   esi,edi
4009
     mov   esi,edi
4010
     add   esi,16
4010
     add   esi,16
4011
     cld
4011
     cld
4012
     rep   movsb
4012
     rep   movsb
4013
 
4013
 
4014
     dec   dword [RESERVED_PORTS]
4014
     dec   dword [RESERVED_PORTS]
4015
 
4015
 
4016
     popad
4016
     popad
4017
 
4017
 
4018
 
4018
 
4019
     ; disable port access at port IO map
4019
     ; disable port access at port IO map
4020
 
4020
 
4021
     pushad                        ; start disable io map
4021
     pushad                        ; start disable io map
4022
 
4022
 
4023
     cmp   ecx,65536 ;16384
4023
     cmp   ecx,65536 ;16384
4024
     jge   no_mask_io
4024
     jge   no_mask_io
4025
 
4025
 
4026
     mov   eax,ebx
4026
     mov   eax,ebx
4027
 
4027
 
4028
   new_port_access_disable:
4028
   new_port_access_disable:
4029
 
4029
 
4030
     pushad
4030
     pushad
4031
 
4031
 
4032
     mov   ebp,1                  ; disable - eax = port
4032
     mov   ebp,1                  ; disable - eax = port
4033
     call  set_io_access_rights
4033
     call  set_io_access_rights
4034
 
4034
 
4035
     popad
4035
     popad
4036
 
4036
 
4037
     inc   eax
4037
     inc   eax
4038
     cmp   eax,ecx
4038
     cmp   eax,ecx
4039
     jbe   new_port_access_disable
4039
     jbe   new_port_access_disable
4040
 
4040
 
4041
   no_mask_io:
4041
   no_mask_io:
4042
 
4042
 
4043
     popad                         ; end disable io map
4043
     popad                         ; end disable io map
4044
 
4044
 
4045
     xor   eax, eax
4045
     xor   eax, eax
4046
     ret
4046
     ret
4047
 
4047
 
4048
 
4048
 
4049
reserve_free_irq:
4049
reserve_free_irq:
4050
 
4050
 
4051
     mov   ecx, 1
4051
     mov   ecx, 1
4052
     cmp   ebx, 16
4052
     cmp   ebx, 16
4053
     jae   fril1
4053
     jae   fril1
4054
     test  eax,eax
4054
     test  eax,eax
4055
     jz    reserve_irq
4055
     jz    reserve_irq
4056
 
4056
 
4057
     lea   edi,[irq_owner+ebx*4]
4057
     lea   edi,[irq_owner+ebx*4]
4058
     mov   edx,[edi]
4058
     mov   edx,[edi]
4059
     mov   eax,[TASK_BASE]
4059
     mov   eax,[TASK_BASE]
4060
     cmp   edx,[eax+TASKDATA.pid]
4060
     cmp   edx,[eax+TASKDATA.pid]
4061
     jne   fril1
4061
     jne   fril1
4062
     dec   ecx
4062
     dec   ecx
4063
     mov   [edi],ecx
4063
     mov   [edi],ecx
4064
   fril1:
4064
   fril1:
4065
     mov   [esp+36],ecx ; return in eax
4065
     mov   [esp+36],ecx ; return in eax
4066
     ret
4066
     ret
4067
 
4067
 
4068
  reserve_irq:
4068
  reserve_irq:
4069
 
4069
 
4070
     lea   edi,[irq_owner+ebx*4]
4070
     lea   edi,[irq_owner+ebx*4]
4071
     cmp   dword [edi], 0
4071
     cmp   dword [edi], 0
4072
     jnz   ril1
4072
     jnz   ril1
4073
 
4073
 
4074
     mov   edx,[TASK_BASE]
4074
     mov   edx,[TASK_BASE]
4075
     mov   edx,[edx+TASKDATA.pid]
4075
     mov   edx,[edx+TASKDATA.pid]
4076
     mov   [edi],edx
4076
     mov   [edi],edx
4077
     dec   ecx
4077
     dec   ecx
4078
   ril1:
4078
   ril1:
4079
     mov   [esp+36],ecx ; return in eax
4079
     mov   [esp+36],ecx ; return in eax
4080
     ret
4080
     ret
4081
 
4081
 
4082
drawbackground:
4082
drawbackground:
4083
       inc   [mouse_pause]
4083
       inc   [mouse_pause]
4084
       cmp   [SCR_MODE],word 0x12
4084
       cmp   [SCR_MODE],word 0x12
4085
       je   dbrv20
4085
       je   dbrv20
4086
     dbrv12:
4086
     dbrv12:
4087
       cmp  [SCR_MODE],word 0100000000000000b
4087
       cmp  [SCR_MODE],word 0100000000000000b
4088
       jge  dbrv20
4088
       jge  dbrv20
4089
       cmp  [SCR_MODE],word 0x13
4089
       cmp  [SCR_MODE],word 0x13
4090
       je   dbrv20
4090
       je   dbrv20
4091
       call  vesa12_drawbackground
4091
       call  vesa12_drawbackground
4092
       dec   [mouse_pause]
4092
       dec   [mouse_pause]
4093
       call   [draw_pointer]
4093
       call   [draw_pointer]
4094
       ret
4094
       ret
4095
     dbrv20:
4095
     dbrv20:
4096
       cmp   [BgrDrawMode],dword 1
4096
       cmp   [BgrDrawMode],dword 1
4097
       jne   bgrstr
4097
       jne   bgrstr
4098
       call  vesa20_drawbackground_tiled
4098
       call  vesa20_drawbackground_tiled
4099
       dec   [mouse_pause]
4099
       dec   [mouse_pause]
4100
       call   [draw_pointer]
4100
       call   [draw_pointer]
4101
       ret
4101
       ret
4102
     bgrstr:
4102
     bgrstr:
4103
       call  vesa20_drawbackground_stretch
4103
       call  vesa20_drawbackground_stretch
4104
       dec   [mouse_pause]
4104
       dec   [mouse_pause]
4105
       call   [draw_pointer]
4105
       call   [draw_pointer]
4106
       ret
4106
       ret
4107
 
4107
 
4108
align 4
4108
align 4
4109
 
4109
 
4110
syscall_putimage:                       ; PutImage
4110
syscall_putimage:                       ; PutImage
4111
 
4111
 
4112
     mov   edx,ecx
4112
     mov   edx,ecx
4113
     mov   ecx,ebx
4113
     mov   ecx,ebx
4114
     mov   ebx, eax
4114
     mov   ebx, eax
4115
 
4115
 
4116
sys_putimage:
4116
sys_putimage:
4117
     test  ecx,0x80008000
4117
     test  ecx,0x80008000
4118
     jnz   .exit
4118
     jnz   .exit
4119
     test  ecx,0x0000FFFF
4119
     test  ecx,0x0000FFFF
4120
     jz    .exit
4120
     jz    .exit
4121
     test  ecx,0xFFFF0000
4121
     test  ecx,0xFFFF0000
4122
     jnz   @f
4122
     jnz   @f
4123
  .exit:
4123
  .exit:
4124
     ret
4124
     ret
4125
 @@:
4125
 @@:
4126
        mov     edi,[current_slot]
4126
        mov     edi,[current_slot]
4127
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4127
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4128
        rol     edx,16
4128
        rol     edx,16
4129
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4129
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4130
        rol     edx,16
4130
        rol     edx,16
4131
  .forced:
4131
  .forced:
4132
        push    ebp esi 0
4132
        push    ebp esi 0
4133
        mov     ebp, putimage_get24bpp
4133
        mov     ebp, putimage_get24bpp
4134
        mov     esi, putimage_init24bpp
4134
        mov     esi, putimage_init24bpp
4135
sys_putimage_bpp:
4135
sys_putimage_bpp:
4136
;        call    [disable_mouse] ; this will be done in xxx_putimage
4136
;        call    [disable_mouse] ; this will be done in xxx_putimage
4137
;        mov     eax, vga_putimage
4137
;        mov     eax, vga_putimage
4138
        cmp     [SCR_MODE], word 0x12
4138
        cmp     [SCR_MODE], word 0x12
4139
        jz      @f   ;.doit
4139
        jz      @f   ;.doit
4140
        mov     eax, vesa12_putimage
4140
        mov     eax, vesa12_putimage
4141
        cmp     [SCR_MODE], word 0100000000000000b
4141
        cmp     [SCR_MODE], word 0100000000000000b
4142
        jae     @f
4142
        jae     @f
4143
        cmp     [SCR_MODE], word 0x13
4143
        cmp     [SCR_MODE], word 0x13
4144
        jnz     .doit
4144
        jnz     .doit
4145
@@:
4145
@@:
4146
        mov     eax, vesa20_putimage
4146
        mov     eax, vesa20_putimage
4147
.doit:
4147
.doit:
4148
        inc     [mouse_pause]
4148
        inc     [mouse_pause]
4149
        call    eax
4149
        call    eax
4150
        dec     [mouse_pause]
4150
        dec     [mouse_pause]
4151
        pop     ebp esi ebp
4151
        pop     ebp esi ebp
4152
        jmp     [draw_pointer]
4152
        jmp     [draw_pointer]
4153
 
4153
 
4154
syscall_putimage_palette:
4154
syscall_putimage_palette:
4155
        mov     edi, esi
4155
        mov     edi, esi
4156
        mov     esi, edx
4156
        mov     esi, edx
4157
        mov     edx, ecx
4157
        mov     edx, ecx
4158
        mov     ecx, ebx
4158
        mov     ecx, ebx
4159
        mov     ebx, eax
4159
        mov     ebx, eax
4160
sys_putimage_palette:
4160
sys_putimage_palette:
4161
; ebx = pointer to image
4161
; ebx = pointer to image
4162
; ecx = [xsize]*65536 + [ysize]
4162
; ecx = [xsize]*65536 + [ysize]
4163
; edx = [xstart]*65536 + [ystart]
4163
; edx = [xstart]*65536 + [ystart]
4164
; 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
4165
; edi = pointer to palette
4165
; edi = pointer to palette
4166
; ebp = row delta
4166
; ebp = row delta
4167
        mov     eax, [CURRENT_TASK]
4167
        mov     eax, [CURRENT_TASK]
4168
        shl     eax, 8
4168
        shl     eax, 8
4169
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4169
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4170
        rol     edx, 16
4170
        rol     edx, 16
4171
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4171
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4172
        rol     edx, 16
4172
        rol     edx, 16
4173
.forced:
4173
.forced:
4174
        push    ebp esi ebp
4174
        push    ebp esi ebp
4175
        cmp     esi, 8
4175
        cmp     esi, 8
4176
        jnz     @f
4176
        jnz     @f
4177
        mov     ebp, putimage_get8bpp
4177
        mov     ebp, putimage_get8bpp
4178
        mov     esi, putimage_init8bpp
4178
        mov     esi, putimage_init8bpp
4179
        jmp     sys_putimage_bpp
4179
        jmp     sys_putimage_bpp
4180
@@:
4180
@@:
4181
        cmp     esi, 24
4181
        cmp     esi, 24
4182
        jnz     @f
4182
        jnz     @f
4183
        mov     ebp, putimage_get24bpp
4183
        mov     ebp, putimage_get24bpp
4184
        mov     esi, putimage_init24bpp
4184
        mov     esi, putimage_init24bpp
4185
        jmp     sys_putimage_bpp
4185
        jmp     sys_putimage_bpp
4186
@@:
4186
@@:
4187
        cmp     esi, 32
4187
        cmp     esi, 32
4188
        jnz     @f
4188
        jnz     @f
4189
        mov     ebp, putimage_get32bpp
4189
        mov     ebp, putimage_get32bpp
4190
        mov     esi, putimage_init32bpp
4190
        mov     esi, putimage_init32bpp
4191
        jmp     sys_putimage_bpp
4191
        jmp     sys_putimage_bpp
4192
@@:
4192
@@:
4193
        pop     ebp esi
4193
        pop     ebp esi
4194
        ret
4194
        ret
4195
 
4195
 
4196
putimage_init24bpp:
4196
putimage_init24bpp:
4197
        lea     eax, [eax*3]
4197
        lea     eax, [eax*3]
4198
putimage_init8bpp:
4198
putimage_init8bpp:
4199
        ret
4199
        ret
4200
 
4200
 
4201
putimage_get24bpp:
4201
putimage_get24bpp:
4202
        mov     eax, [esi]
4202
        mov     eax, [esi]
4203
        add     esi, 3
4203
        add     esi, 3
4204
        ret     4
4204
        ret     4
4205
putimage_get8bpp:
4205
putimage_get8bpp:
4206
        movzx   eax, byte [esi]
4206
        movzx   eax, byte [esi]
4207
        push    edx
4207
        push    edx
4208
        mov     edx, [esp+8]
4208
        mov     edx, [esp+8]
4209
        mov     eax, [edx+eax*4]
4209
        mov     eax, [edx+eax*4]
4210
        pop     edx
4210
        pop     edx
4211
        inc     esi
4211
        inc     esi
4212
        ret     4
4212
        ret     4
4213
 
4213
 
4214
putimage_init32bpp:
4214
putimage_init32bpp:
4215
        shl     eax, 2
4215
        shl     eax, 2
4216
        ret
4216
        ret
4217
putimage_get32bpp:
4217
putimage_get32bpp:
4218
        lodsd
4218
        lodsd
4219
        ret     4
4219
        ret     4
4220
 
4220
 
4221
; eax x beginning
4221
; eax x beginning
4222
; ebx y beginning
4222
; ebx y beginning
4223
; ecx x end
4223
; ecx x end
4224
	; edx y end
4224
	; edx y end
4225
; edi color
4225
; edi color
4226
 
4226
 
4227
__sys_drawbar:
4227
__sys_drawbar:
4228
        mov     esi,[current_slot]
4228
        mov     esi,[current_slot]
4229
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4229
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4230
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4230
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4231
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4231
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4232
        add     edx,[esi+APPDATA.wnd_clientbox.top]
4232
        add     edx,[esi+APPDATA.wnd_clientbox.top]
4233
  .forced:
4233
  .forced:
4234
    inc   [mouse_pause]
4234
    inc   [mouse_pause]
4235
;        call    [disable_mouse]
4235
;        call    [disable_mouse]
4236
    cmp   [SCR_MODE],word 0x12
4236
    cmp   [SCR_MODE],word 0x12
4237
    je   dbv20
4237
    je   dbv20
4238
   sdbv20:
4238
   sdbv20:
4239
    cmp  [SCR_MODE],word 0100000000000000b
4239
    cmp  [SCR_MODE],word 0100000000000000b
4240
    jge  dbv20
4240
    jge  dbv20
4241
    cmp  [SCR_MODE],word 0x13
4241
    cmp  [SCR_MODE],word 0x13
4242
    je   dbv20
4242
    je   dbv20
4243
    call vesa12_drawbar
4243
    call vesa12_drawbar
4244
    dec   [mouse_pause]
4244
    dec   [mouse_pause]
4245
    call   [draw_pointer]
4245
    call   [draw_pointer]
4246
    ret
4246
    ret
4247
  dbv20:
4247
  dbv20:
4248
    call vesa20_drawbar
4248
    call vesa20_drawbar
4249
    dec   [mouse_pause]
4249
    dec   [mouse_pause]
4250
    call   [draw_pointer]
4250
    call   [draw_pointer]
4251
    ret
4251
    ret
4252
 
4252
 
4253
 
4253
 
4254
 
4254
 
4255
kb_read:
4255
kb_read:
4256
 
4256
 
4257
        push    ecx edx
4257
        push    ecx edx
4258
 
4258
 
4259
        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
4260
      kr_loop:
4260
      kr_loop:
4261
        in      al,0x64
4261
        in      al,0x64
4262
        test    al,1
4262
        test    al,1
4263
        jnz     kr_ready
4263
        jnz     kr_ready
4264
        loop    kr_loop
4264
        loop    kr_loop
4265
        mov     ah,1
4265
        mov     ah,1
4266
        jmp     kr_exit
4266
        jmp     kr_exit
4267
      kr_ready:
4267
      kr_ready:
4268
        push    ecx
4268
        push    ecx
4269
        mov     ecx,32
4269
        mov     ecx,32
4270
      kr_delay:
4270
      kr_delay:
4271
        loop    kr_delay
4271
        loop    kr_delay
4272
        pop     ecx
4272
        pop     ecx
4273
        in      al,0x60
4273
        in      al,0x60
4274
        xor     ah,ah
4274
        xor     ah,ah
4275
      kr_exit:
4275
      kr_exit:
4276
 
4276
 
4277
        pop     edx ecx
4277
        pop     edx ecx
4278
 
4278
 
4279
        ret
4279
        ret
4280
 
4280
 
4281
 
4281
 
4282
kb_write:
4282
kb_write:
4283
 
4283
 
4284
        push    ecx edx
4284
        push    ecx edx
4285
 
4285
 
4286
        mov     dl,al
4286
        mov     dl,al
4287
;        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
4288
;      kw_loop1:
4288
;      kw_loop1:
4289
;        in      al,0x64
4289
;        in      al,0x64
4290
;        test    al,0x20
4290
;        test    al,0x20
4291
;        jz      kw_ok1
4291
;        jz      kw_ok1
4292
;        loop    kw_loop1
4292
;        loop    kw_loop1
4293
;        mov     ah,1
4293
;        mov     ah,1
4294
;        jmp     kw_exit
4294
;        jmp     kw_exit
4295
;      kw_ok1:
4295
;      kw_ok1:
4296
        in      al,0x60
4296
        in      al,0x60
4297
        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
4298
      kw_loop:
4298
      kw_loop:
4299
        in      al,0x64
4299
        in      al,0x64
4300
        test    al,2
4300
        test    al,2
4301
        jz      kw_ok
4301
        jz      kw_ok
4302
        loop    kw_loop
4302
        loop    kw_loop
4303
        mov     ah,1
4303
        mov     ah,1
4304
        jmp     kw_exit
4304
        jmp     kw_exit
4305
      kw_ok:
4305
      kw_ok:
4306
        mov     al,dl
4306
        mov     al,dl
4307
        out     0x60,al
4307
        out     0x60,al
4308
        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
4309
      kw_loop3:
4309
      kw_loop3:
4310
        in      al,0x64
4310
        in      al,0x64
4311
        test    al,2
4311
        test    al,2
4312
        jz      kw_ok3
4312
        jz      kw_ok3
4313
        loop    kw_loop3
4313
        loop    kw_loop3
4314
        mov     ah,1
4314
        mov     ah,1
4315
        jmp     kw_exit
4315
        jmp     kw_exit
4316
      kw_ok3:
4316
      kw_ok3:
4317
        mov     ah,8
4317
        mov     ah,8
4318
      kw_loop4:
4318
      kw_loop4:
4319
        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
4320
      kw_loop5:
4320
      kw_loop5:
4321
        in      al,0x64
4321
        in      al,0x64
4322
        test    al,1
4322
        test    al,1
4323
        jnz     kw_ok4
4323
        jnz     kw_ok4
4324
        loop    kw_loop5
4324
        loop    kw_loop5
4325
        dec     ah
4325
        dec     ah
4326
        jnz     kw_loop4
4326
        jnz     kw_loop4
4327
      kw_ok4:
4327
      kw_ok4:
4328
        xor     ah,ah
4328
        xor     ah,ah
4329
      kw_exit:
4329
      kw_exit:
4330
 
4330
 
4331
        pop     edx ecx
4331
        pop     edx ecx
4332
 
4332
 
4333
        ret
4333
        ret
4334
 
4334
 
4335
 
4335
 
4336
kb_cmd:
4336
kb_cmd:
4337
 
4337
 
4338
        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
4339
      c_wait:
4339
      c_wait:
4340
        in      al,0x64
4340
        in      al,0x64
4341
        test    al,2
4341
        test    al,2
4342
        jz      c_send
4342
        jz      c_send
4343
        loop    c_wait
4343
        loop    c_wait
4344
        jmp     c_error
4344
        jmp     c_error
4345
      c_send:
4345
      c_send:
4346
        mov     al,bl
4346
        mov     al,bl
4347
        out     0x64,al
4347
        out     0x64,al
4348
        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
4349
      c_accept:
4349
      c_accept:
4350
        in      al,0x64
4350
        in      al,0x64
4351
        test    al,2
4351
        test    al,2
4352
        jz      c_ok
4352
        jz      c_ok
4353
        loop    c_accept
4353
        loop    c_accept
4354
      c_error:
4354
      c_error:
4355
        mov     ah,1
4355
        mov     ah,1
4356
        jmp     c_exit
4356
        jmp     c_exit
4357
      c_ok:
4357
      c_ok:
4358
        xor     ah,ah
4358
        xor     ah,ah
4359
      c_exit:
4359
      c_exit:
4360
        ret
4360
        ret
4361
 
4361
 
4362
 
4362
 
4363
setmouse:  ; set mousepicture -pointer
4363
setmouse:  ; set mousepicture -pointer
4364
           ; ps2 mouse enable
4364
           ; ps2 mouse enable
4365
 
4365
 
4366
     mov     [MOUSE_PICTURE],dword mousepointer
4366
     mov     [MOUSE_PICTURE],dword mousepointer
4367
 
4367
 
4368
     cli
4368
     cli
4369
;     mov     bl,0xa8                 ; enable mouse cmd
4369
;     mov     bl,0xa8                 ; enable mouse cmd
4370
;     call    kb_cmd
4370
;     call    kb_cmd
4371
;     call    kb_read                 ; read status
4371
;     call    kb_read                 ; read status
4372
;     mov     bl,0x20                 ; get command byte
4372
;     mov     bl,0x20                 ; get command byte
4373
;     call    kb_cmd
4373
;     call    kb_cmd
4374
;     call    kb_read
4374
;     call    kb_read
4375
;     or      al,3                    ; enable interrupt
4375
;     or      al,3                    ; enable interrupt
4376
;     mov     bl,0x60                 ; write command
4376
;     mov     bl,0x60                 ; write command
4377
;     push    eax
4377
;     push    eax
4378
;     call    kb_cmd
4378
;     call    kb_cmd
4379
;     pop     eax
4379
;     pop     eax
4380
;     call    kb_write
4380
;     call    kb_write
4381
;     mov     bl,0xd4                 ; for mouse
4381
;     mov     bl,0xd4                 ; for mouse
4382
;     call    kb_cmd
4382
;     call    kb_cmd
4383
;     mov     al,0xf4                 ; enable mouse device
4383
;     mov     al,0xf4                 ; enable mouse device
4384
;     call    kb_write
4384
;     call    kb_write
4385
;     call    kb_read           ; read status return
4385
;     call    kb_read           ; read status return
4386
 
4386
 
4387
     ; com1 mouse enable
4387
     ; com1 mouse enable
4388
 
4388
 
4389
     mov   bx,0x3f8 ; combase
4389
     mov   bx,0x3f8 ; combase
4390
 
4390
 
4391
     mov   dx,bx
4391
     mov   dx,bx
4392
     add   dx,3
4392
     add   dx,3
4393
     mov   al,0x80
4393
     mov   al,0x80
4394
     out   dx,al
4394
     out   dx,al
4395
 
4395
 
4396
     mov   dx,bx
4396
     mov   dx,bx
4397
     add   dx,1
4397
     add   dx,1
4398
     mov   al,0
4398
     mov   al,0
4399
     out   dx,al
4399
     out   dx,al
4400
 
4400
 
4401
     mov   dx,bx
4401
     mov   dx,bx
4402
     add   dx,0
4402
     add   dx,0
4403
     mov   al,0x30*2    ; 0x30 / 4
4403
     mov   al,0x30*2    ; 0x30 / 4
4404
     out   dx,al
4404
     out   dx,al
4405
 
4405
 
4406
     mov   dx,bx
4406
     mov   dx,bx
4407
     add   dx,3
4407
     add   dx,3
4408
     mov   al,2         ; 3
4408
     mov   al,2         ; 3
4409
     out   dx,al
4409
     out   dx,al
4410
 
4410
 
4411
     mov   dx,bx
4411
     mov   dx,bx
4412
     add   dx,4
4412
     add   dx,4
4413
     mov   al,0xb
4413
     mov   al,0xb
4414
     out   dx,al
4414
     out   dx,al
4415
 
4415
 
4416
     mov   dx,bx
4416
     mov   dx,bx
4417
     add   dx,1
4417
     add   dx,1
4418
     mov   al,1
4418
     mov   al,1
4419
     out   dx,al
4419
     out   dx,al
4420
 
4420
 
4421
 
4421
 
4422
     ; com2 mouse enable
4422
     ; com2 mouse enable
4423
 
4423
 
4424
     mov   bx,0x2f8 ; combase
4424
     mov   bx,0x2f8 ; combase
4425
 
4425
 
4426
     mov   dx,bx
4426
     mov   dx,bx
4427
     add   dx,3
4427
     add   dx,3
4428
     mov   al,0x80
4428
     mov   al,0x80
4429
     out   dx,al
4429
     out   dx,al
4430
 
4430
 
4431
     mov   dx,bx
4431
     mov   dx,bx
4432
     add   dx,1
4432
     add   dx,1
4433
     mov   al,0
4433
     mov   al,0
4434
     out   dx,al
4434
     out   dx,al
4435
 
4435
 
4436
     mov   dx,bx
4436
     mov   dx,bx
4437
     add   dx,0
4437
     add   dx,0
4438
     mov   al,0x30*2
4438
     mov   al,0x30*2
4439
     out   dx,al
4439
     out   dx,al
4440
 
4440
 
4441
     mov   dx,bx
4441
     mov   dx,bx
4442
     add   dx,3
4442
     add   dx,3
4443
     mov   al,2
4443
     mov   al,2
4444
     out   dx,al
4444
     out   dx,al
4445
 
4445
 
4446
     mov   dx,bx
4446
     mov   dx,bx
4447
     add   dx,4
4447
     add   dx,4
4448
     mov   al,0xb
4448
     mov   al,0xb
4449
     out   dx,al
4449
     out   dx,al
4450
 
4450
 
4451
     mov   dx,bx
4451
     mov   dx,bx
4452
     add   dx,1
4452
     add   dx,1
4453
     mov   al,1
4453
     mov   al,1
4454
     out   dx,al
4454
     out   dx,al
4455
 
4455
 
4456
     ret
4456
     ret
4457
 
4457
 
4458
 
4458
 
4459
_rdtsc:
4459
_rdtsc:
4460
     bt [cpu_caps], CAPS_TSC
4460
     bt [cpu_caps], CAPS_TSC
4461
     jnc ret_rdtsc
4461
     jnc ret_rdtsc
4462
     rdtsc
4462
     rdtsc
4463
     ret
4463
     ret
4464
   ret_rdtsc:
4464
   ret_rdtsc:
4465
     mov   edx,0xffffffff
4465
     mov   edx,0xffffffff
4466
     mov   eax,0xffffffff
4466
     mov   eax,0xffffffff
4467
     ret
4467
     ret
4468
 
4468
 
4469
rerouteirqs:
4469
rerouteirqs:
4470
 
4470
 
4471
        cli
4471
        cli
4472
 
4472
 
4473
        mov     al,0x11         ;  icw4, edge triggered
4473
        mov     al,0x11         ;  icw4, edge triggered
4474
        out     0x20,al
4474
        out     0x20,al
4475
        call    pic_delay
4475
        call    pic_delay
4476
        out     0xA0,al
4476
        out     0xA0,al
4477
        call    pic_delay
4477
        call    pic_delay
4478
 
4478
 
4479
        mov     al,0x20         ;  generate 0x20 +
4479
        mov     al,0x20         ;  generate 0x20 +
4480
        out     0x21,al
4480
        out     0x21,al
4481
        call    pic_delay
4481
        call    pic_delay
4482
        mov     al,0x28         ;  generate 0x28 +
4482
        mov     al,0x28         ;  generate 0x28 +
4483
        out     0xA1,al
4483
        out     0xA1,al
4484
        call    pic_delay
4484
        call    pic_delay
4485
 
4485
 
4486
        mov     al,0x04         ;  slave at irq2
4486
        mov     al,0x04         ;  slave at irq2
4487
        out     0x21,al
4487
        out     0x21,al
4488
        call    pic_delay
4488
        call    pic_delay
4489
        mov     al,0x02         ;  at irq9
4489
        mov     al,0x02         ;  at irq9
4490
        out     0xA1,al
4490
        out     0xA1,al
4491
        call    pic_delay
4491
        call    pic_delay
4492
 
4492
 
4493
        mov     al,0x01         ;  8086 mode
4493
        mov     al,0x01         ;  8086 mode
4494
        out     0x21,al
4494
        out     0x21,al
4495
        call    pic_delay
4495
        call    pic_delay
4496
        out     0xA1,al
4496
        out     0xA1,al
4497
        call    pic_delay
4497
        call    pic_delay
4498
 
4498
 
4499
        mov     al,255          ; mask all irq's
4499
        mov     al,255          ; mask all irq's
4500
        out     0xA1,al
4500
        out     0xA1,al
4501
        call    pic_delay
4501
        call    pic_delay
4502
        out     0x21,al
4502
        out     0x21,al
4503
        call    pic_delay
4503
        call    pic_delay
4504
 
4504
 
4505
        mov     ecx,0x1000
4505
        mov     ecx,0x1000
4506
        cld
4506
        cld
4507
picl1:  call    pic_delay
4507
picl1:  call    pic_delay
4508
        loop    picl1
4508
        loop    picl1
4509
 
4509
 
4510
        mov     al,255          ; mask all irq's
4510
        mov     al,255          ; mask all irq's
4511
        out     0xA1,al
4511
        out     0xA1,al
4512
        call    pic_delay
4512
        call    pic_delay
4513
        out     0x21,al
4513
        out     0x21,al
4514
        call    pic_delay
4514
        call    pic_delay
4515
 
4515
 
4516
        cli
4516
        cli
4517
 
4517
 
4518
        ret
4518
        ret
4519
 
4519
 
4520
 
4520
 
4521
pic_delay:
4521
pic_delay:
4522
 
4522
 
4523
        jmp     pdl1
4523
        jmp     pdl1
4524
pdl1:   ret
4524
pdl1:   ret
4525
 
4525
 
4526
 
4526
 
4527
sys_msg_board_str:
4527
sys_msg_board_str:
4528
 
4528
 
4529
     pushad
4529
     pushad
4530
   @@:
4530
   @@:
4531
     cmp    [esi],byte 0
4531
     cmp    [esi],byte 0
4532
     je     @f
4532
     je     @f
4533
     mov    eax,1
4533
     mov    eax,1
4534
     movzx  ebx,byte [esi]
4534
     movzx  ebx,byte [esi]
4535
     call   sys_msg_board
4535
     call   sys_msg_board
4536
     inc    esi
4536
     inc    esi
4537
     jmp    @b
4537
     jmp    @b
4538
   @@:
4538
   @@:
4539
     popad
4539
     popad
4540
     ret
4540
     ret
4541
 
4541
 
4542
uglobal
4542
uglobal
4543
  msg_board_data: times 4096 db 0
4543
  msg_board_data: times 4096 db 0
4544
  msg_board_count dd 0x0
4544
  msg_board_count dd 0x0
4545
endg
4545
endg
4546
 
4546
 
4547
sys_msg_board:
4547
sys_msg_board:
4548
 
4548
 
4549
; eax=1 : write :  bl byte to write
4549
; eax=1 : write :  bl byte to write
4550
; 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
4551
 
4551
 
4552
     mov  ecx,[msg_board_count]
4552
     mov  ecx,[msg_board_count]
4553
     cmp  eax, 1
4553
     cmp  eax, 1
4554
     jne  smbl1
4554
     jne  smbl1
4555
 
4555
 
4556
 
4556
 
4557
     mov  [msg_board_data+ecx],bl
4557
     mov  [msg_board_data+ecx],bl
4558
     inc  ecx
4558
     inc  ecx
4559
     and  ecx, 4095
4559
     and  ecx, 4095
4560
     mov  [msg_board_count], ecx
4560
     mov  [msg_board_count], ecx
4561
     mov  [check_idle_semaphore], 5
4561
     mov  [check_idle_semaphore], 5
4562
     ret
4562
     ret
4563
   smbl1:
4563
   smbl1:
4564
 
4564
 
4565
     cmp   eax, 2
4565
     cmp   eax, 2
4566
     jne   smbl2
4566
     jne   smbl2
4567
     test  ecx, ecx
4567
     test  ecx, ecx
4568
     jz    smbl21
4568
     jz    smbl21
4569
;     mov   edi, msg_board_data
4569
;     mov   edi, msg_board_data
4570
;     mov   esi, msg_board_data+1
4570
;     mov   esi, msg_board_data+1
4571
;     movzx eax, byte [edi]
4571
;     movzx eax, byte [edi]
4572
     mov   eax, msg_board_data+1
4572
     mov   eax, msg_board_data+1
4573
     mov   ebx, msg_board_data
4573
     mov   ebx, msg_board_data
4574
     movzx edx, byte [ebx]
4574
     movzx edx, byte [ebx]
4575
     call  memmove
4575
     call  memmove
4576
;     push  ecx
4576
;     push  ecx
4577
;     shr   ecx, 2
4577
;     shr   ecx, 2
4578
;     cld
4578
;     cld
4579
;     rep   movsd
4579
;     rep   movsd
4580
;     pop   ecx
4580
;     pop   ecx
4581
;     and   ecx, 3
4581
;     and   ecx, 3
4582
;     rep   movsb
4582
;     rep   movsb
4583
     dec   [msg_board_count]
4583
     dec   [msg_board_count]
4584
     mov   [esp+36], edx ;eax
4584
     mov   [esp+36], edx ;eax
4585
     mov   [esp+24], dword 1
4585
     mov   [esp+24], dword 1
4586
     ret
4586
     ret
4587
   smbl21:
4587
   smbl21:
4588
     mov   [esp+36], ecx
4588
     mov   [esp+36], ecx
4589
     mov   [esp+24], ecx
4589
     mov   [esp+24], ecx
4590
 
4590
 
4591
   smbl2:
4591
   smbl2:
4592
     ret
4592
     ret
4593
 
4593
 
4594
 
4594
 
4595
 
4595
 
4596
sys_process_def:
4596
sys_process_def:
4597
        mov     edi, [CURRENT_TASK]
4597
        mov     edi, [CURRENT_TASK]
4598
 
4598
 
4599
        dec     eax             ; 1 = set keyboard mode
4599
        dec     eax             ; 1 = set keyboard mode
4600
     jne   no_set_keyboard_setup
4600
     jne   no_set_keyboard_setup
4601
 
4601
 
4602
     shl   edi,8
4602
     shl   edi,8
4603
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4603
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4604
 
4604
 
4605
     ret
4605
     ret
4606
 
4606
 
4607
   no_set_keyboard_setup:
4607
   no_set_keyboard_setup:
4608
 
4608
 
4609
        dec     eax             ; 2 = get keyboard mode
4609
        dec     eax             ; 2 = get keyboard mode
4610
     jne   no_get_keyboard_setup
4610
     jne   no_get_keyboard_setup
4611
 
4611
 
4612
     shl   edi,8
4612
     shl   edi,8
4613
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4613
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4614
 
4614
 
4615
     mov   [esp+36],eax
4615
     mov   [esp+36],eax
4616
 
4616
 
4617
     ret
4617
     ret
4618
 
4618
 
4619
   no_get_keyboard_setup:
4619
   no_get_keyboard_setup:
4620
 
4620
 
4621
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4621
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4622
     jne   no_get_keyboard_cas
4622
     jne   no_get_keyboard_cas
4623
 
4623
 
4624
;     xor   eax,eax
4624
;     xor   eax,eax
4625
;     movzx eax,byte [shift]
4625
;     movzx eax,byte [shift]
4626
;     movzx ebx,byte [ctrl]
4626
;     movzx ebx,byte [ctrl]
4627
;     shl   ebx,2
4627
;     shl   ebx,2
4628
;     add   eax,ebx
4628
;     add   eax,ebx
4629
;     movzx ebx,byte [alt]
4629
;     movzx ebx,byte [alt]
4630
;     shl   ebx,3
4630
;     shl   ebx,3
4631
;     add   eax,ebx
4631
;     add   eax,ebx
4632
 
4632
 
4633
 ;// mike.dld [
4633
 ;// mike.dld [
4634
     mov   eax, [kb_state]
4634
     mov   eax, [kb_state]
4635
 ;// mike.dld ]
4635
 ;// mike.dld ]
4636
 
4636
 
4637
     mov   [esp+36],eax
4637
     mov   [esp+36],eax
4638
 
4638
 
4639
     ret
4639
     ret
4640
 
4640
 
4641
   no_get_keyboard_cas:
4641
   no_get_keyboard_cas:
4642
 
4642
 
4643
        dec     eax
4643
        dec     eax
4644
        jnz     no_add_keyboard_hotkey
4644
        jnz     no_add_keyboard_hotkey
4645
 
4645
 
4646
        mov     eax, hotkey_list
4646
        mov     eax, hotkey_list
4647
@@:
4647
@@:
4648
        cmp     dword [eax+8], 0
4648
        cmp     dword [eax+8], 0
4649
        jz      .found_free
4649
        jz      .found_free
4650
        add     eax, 16
4650
        add     eax, 16
4651
        cmp     eax, hotkey_list+16*256
4651
        cmp     eax, hotkey_list+16*256
4652
        jb      @b
4652
        jb      @b
4653
        mov     dword [esp+36], 1
4653
        mov     dword [esp+36], 1
4654
        ret
4654
        ret
4655
.found_free:
4655
.found_free:
4656
        mov     [eax+8], edi
4656
        mov     [eax+8], edi
4657
        mov     [eax+4], ecx
4657
        mov     [eax+4], ecx
4658
        movzx   ebx, bl
4658
        movzx   ebx, bl
4659
        lea     ebx, [hotkey_scancodes+ebx*4]
4659
        lea     ebx, [hotkey_scancodes+ebx*4]
4660
        mov     ecx, [ebx]
4660
        mov     ecx, [ebx]
4661
        mov     [eax], ecx
4661
        mov     [eax], ecx
4662
        mov     [ebx], eax
4662
        mov     [ebx], eax
4663
        mov     [eax+12], ebx
4663
        mov     [eax+12], ebx
4664
        jecxz   @f
4664
        jecxz   @f
4665
        mov     [ecx+12], eax
4665
        mov     [ecx+12], eax
4666
@@:
4666
@@:
4667
        and     dword [esp+36], 0
4667
        and     dword [esp+36], 0
4668
        ret
4668
        ret
4669
 
4669
 
4670
no_add_keyboard_hotkey:
4670
no_add_keyboard_hotkey:
4671
 
4671
 
4672
        dec     eax
4672
        dec     eax
4673
        jnz     no_del_keyboard_hotkey
4673
        jnz     no_del_keyboard_hotkey
4674
 
4674
 
4675
        movzx   ebx, bl
4675
        movzx   ebx, bl
4676
        lea     ebx, [hotkey_scancodes+ebx*4]
4676
        lea     ebx, [hotkey_scancodes+ebx*4]
4677
        mov     eax, [ebx]
4677
        mov     eax, [ebx]
4678
.scan:
4678
.scan:
4679
        test    eax, eax
4679
        test    eax, eax
4680
        jz      .notfound
4680
        jz      .notfound
4681
        cmp     [eax+8], edi
4681
        cmp     [eax+8], edi
4682
        jnz     .next
4682
        jnz     .next
4683
        cmp     [eax+4], ecx
4683
        cmp     [eax+4], ecx
4684
        jz      .found
4684
        jz      .found
4685
.next:
4685
.next:
4686
        mov     eax, [eax]
4686
        mov     eax, [eax]
4687
        jmp     .scan
4687
        jmp     .scan
4688
.notfound:
4688
.notfound:
4689
        mov     dword [esp+36], 1
4689
        mov     dword [esp+36], 1
4690
        ret
4690
        ret
4691
.found:
4691
.found:
4692
        mov     ecx, [eax]
4692
        mov     ecx, [eax]
4693
        jecxz   @f
4693
        jecxz   @f
4694
        mov     edx, [eax+12]
4694
        mov     edx, [eax+12]
4695
        mov     [ecx+12], edx
4695
        mov     [ecx+12], edx
4696
@@:
4696
@@:
4697
        mov     ecx, [eax+12]
4697
        mov     ecx, [eax+12]
4698
        mov     edx, [eax]
4698
        mov     edx, [eax]
4699
        mov     [ecx], edx
4699
        mov     [ecx], edx
4700
        xor     edx, edx
4700
        xor     edx, edx
4701
        mov     [eax+4], edx
4701
        mov     [eax+4], edx
4702
        mov     [eax+8], edx
4702
        mov     [eax+8], edx
4703
        mov     [eax+12], edx
4703
        mov     [eax+12], edx
4704
        mov     [eax], edx
4704
        mov     [eax], edx
4705
        mov     [esp+36], edx
4705
        mov     [esp+36], edx
4706
        ret
4706
        ret
4707
 
4707
 
4708
no_del_keyboard_hotkey:
4708
no_del_keyboard_hotkey:
4709
     ret
4709
     ret
4710
 
4710
 
4711
 
4711
 
4712
align 4
4712
align 4
4713
 
4713
 
4714
sys_gs:                         ; direct screen access
4714
sys_gs:                         ; direct screen access
4715
 
4715
 
4716
     cmp  eax,1                 ; resolution
4716
     cmp  eax,1                 ; resolution
4717
     jne  no_gs1
4717
     jne  no_gs1
4718
     mov  eax,[ScreenWidth]
4718
     mov  eax,[ScreenWidth]
4719
     shl  eax,16
4719
     shl  eax,16
4720
     mov  ax,[ScreenHeight]
4720
     mov  ax,[ScreenHeight]
4721
     add  eax,0x00010001
4721
     add  eax,0x00010001
4722
     mov  [esp+36],eax
4722
     mov  [esp+36],eax
4723
     ret
4723
     ret
4724
   no_gs1:
4724
   no_gs1:
4725
 
4725
 
4726
     cmp   eax,2                ; bits per pixel
4726
     cmp   eax,2                ; bits per pixel
4727
     jne   no_gs2
4727
     jne   no_gs2
4728
     movzx eax,byte [ScreenBPP]
4728
     movzx eax,byte [ScreenBPP]
4729
     mov   [esp+36],eax
4729
     mov   [esp+36],eax
4730
     ret
4730
     ret
4731
   no_gs2:
4731
   no_gs2:
4732
 
4732
 
4733
     cmp   eax,3                ; bytes per scanline
4733
     cmp   eax,3                ; bytes per scanline
4734
     jne   no_gs3
4734
     jne   no_gs3
4735
     mov   eax,[BytesPerScanLine]
4735
     mov   eax,[BytesPerScanLine]
4736
     mov   [esp+36],eax
4736
     mov   [esp+36],eax
4737
     ret
4737
     ret
4738
   no_gs3:
4738
   no_gs3:
4739
 
4739
 
4740
     mov  [esp+36],dword -1
4740
     mov  [esp+36],dword -1
4741
     ret
4741
     ret
4742
 
4742
 
4743
 
4743
 
4744
align 4 ; PCI functions
4744
align 4 ; PCI functions
4745
 
4745
 
4746
sys_pci:
4746
sys_pci:
4747
 
4747
 
4748
     call  pci_api
4748
     call  pci_api
4749
     mov   [esp+36],eax
4749
     mov   [esp+36],eax
4750
     ret
4750
     ret
4751
 
4751
 
4752
 
4752
 
4753
align 4  ;  system functions
4753
align 4  ;  system functions
4754
 
4754
 
4755
syscall_setpixel:                       ; SetPixel
4755
syscall_setpixel:                       ; SetPixel
4756
 
4756
 
4757
 
4757
 
4758
     mov   edx,[TASK_BASE]
4758
     mov   edx,[TASK_BASE]
4759
     add   eax,[edx-twdw+WDATA.box.left]
4759
     add   eax,[edx-twdw+WDATA.box.left]
4760
     add   ebx,[edx-twdw+WDATA.box.top]
4760
     add   ebx,[edx-twdw+WDATA.box.top]
4761
        mov     edi,[current_slot]
4761
        mov     edi,[current_slot]
4762
        add     eax,[edi+APPDATA.wnd_clientbox.left]
4762
        add     eax,[edi+APPDATA.wnd_clientbox.left]
4763
        add     ebx,[edi+APPDATA.wnd_clientbox.top]
4763
        add     ebx,[edi+APPDATA.wnd_clientbox.top]
4764
     xor   edi,edi ; no force
4764
     xor   edi,edi ; no force
4765
;     mov   edi,1
4765
;     mov   edi,1
4766
     call  [disable_mouse]
4766
     call  [disable_mouse]
4767
     jmp   [putpixel]
4767
     jmp   [putpixel]
4768
 
4768
 
4769
align 4
4769
align 4
4770
 
4770
 
4771
syscall_writetext:                      ; WriteText
4771
syscall_writetext:                      ; WriteText
4772
 
4772
 
4773
        mov   edi,[TASK_BASE]
4773
        mov   edi,[TASK_BASE]
4774
        mov   ebp,[edi-twdw+WDATA.box.left]
4774
        mov   ebp,[edi-twdw+WDATA.box.left]
4775
        push  esi
4775
        push  esi
4776
        mov   esi,[current_slot]
4776
        mov   esi,[current_slot]
4777
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
4777
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
4778
        shl   ebp,16
4778
        shl   ebp,16
4779
        add   ebp,[edi-twdw+WDATA.box.top]
4779
        add   ebp,[edi-twdw+WDATA.box.top]
4780
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
4780
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
4781
        pop   esi
4781
        pop   esi
4782
        add   ecx,[edi+TASKDATA.mem_start]
4782
        add   ecx,[edi+TASKDATA.mem_start]
4783
        add   eax,ebp
4783
        add   eax,ebp
4784
        xor   edi,edi
4784
        xor   edi,edi
4785
        jmp   dtext
4785
        jmp   dtext
4786
 
4786
 
4787
align 4
4787
align 4
4788
 
4788
 
4789
syscall_openramdiskfile:                ; OpenRamdiskFile
4789
syscall_openramdiskfile:                ; OpenRamdiskFile
4790
 
4790
 
4791
 
4791
 
4792
     mov   edi,[TASK_BASE]
4792
     mov   edi,[TASK_BASE]
4793
     add   edi,TASKDATA.mem_start
4793
     add   edi,TASKDATA.mem_start
4794
     add   eax,[edi]
4794
     add   eax,[edi]
4795
     add   edx,[edi]
4795
     add   edx,[edi]
4796
     mov   esi,12
4796
     mov   esi,12
4797
     call  fileread
4797
     call  fileread
4798
     mov   [esp+36],ebx
4798
     mov   [esp+36],ebx
4799
     ret
4799
     ret
4800
 
4800
 
4801
align 4
4801
align 4
4802
 
4802
 
4803
syscall_drawrect:                       ; DrawRect
4803
syscall_drawrect:                       ; DrawRect
4804
 
4804
 
4805
     mov   edi,ecx
4805
     mov   edi,ecx
4806
     and   edi,0x80FFFFFF
4806
     and   edi,0x80FFFFFF
4807
     test  ax,ax
4807
     test  ax,ax
4808
     je    drectr
4808
     je    drectr
4809
     test  bx,bx
4809
     test  bx,bx
4810
     je    drectr
4810
     je    drectr
4811
     movzx ecx,ax
4811
     movzx ecx,ax
4812
     shr   eax,16
4812
     shr   eax,16
4813
     movzx edx,bx
4813
     movzx edx,bx
4814
     shr   ebx,16
4814
     shr   ebx,16
4815
        mov     esi,[current_slot]
4815
        mov     esi,[current_slot]
4816
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4816
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4817
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4817
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4818
     add   ecx,eax
4818
     add   ecx,eax
4819
     add   edx,ebx
4819
     add   edx,ebx
4820
     jmp   [drawbar]
4820
     jmp   [drawbar]
4821
    drectr:
4821
    drectr:
4822
     ret
4822
     ret
4823
 
4823
 
4824
align 4
4824
align 4
4825
 
4825
 
4826
syscall_getscreensize:                  ; GetScreenSize
4826
syscall_getscreensize:                  ; GetScreenSize
4827
 
4827
 
4828
     movzx eax,word[ScreenWidth]
4828
     movzx eax,word[ScreenWidth]
4829
     shl   eax,16
4829
     shl   eax,16
4830
     mov   ax,[ScreenHeight]
4830
     mov   ax,[ScreenHeight]
4831
     mov   [esp+36],eax
4831
     mov   [esp+36],eax
4832
     ret
4832
     ret
4833
 
4833
 
4834
align 4
4834
align 4
4835
 
4835
 
4836
syscall_cdaudio:                        ; CD
4836
syscall_cdaudio:                        ; CD
4837
 
4837
 
4838
     call  sys_cd_audio
4838
     call  sys_cd_audio
4839
     mov   [esp+36],eax
4839
     mov   [esp+36],eax
4840
     ret
4840
     ret
4841
 
4841
 
4842
align 4
4842
align 4
4843
 
4843
 
4844
syscall_delramdiskfile:                 ; DelRamdiskFile
4844
syscall_delramdiskfile:                 ; DelRamdiskFile
4845
 
4845
 
4846
     mov   edi,[TASK_BASE]
4846
     mov   edi,[TASK_BASE]
4847
     add   edi,TASKDATA.mem_start
4847
     add   edi,TASKDATA.mem_start
4848
     add   eax,[edi]
4848
     add   eax,[edi]
4849
     call  filedelete
4849
     call  filedelete
4850
     mov   [esp+36],eax
4850
     mov   [esp+36],eax
4851
     ret
4851
     ret
4852
 
4852
 
4853
align 4
4853
align 4
4854
 
4854
 
4855
syscall_writeramdiskfile:               ; WriteRamdiskFile
4855
syscall_writeramdiskfile:               ; WriteRamdiskFile
4856
 
4856
 
4857
     mov   edi,[TASK_BASE]
4857
     mov   edi,[TASK_BASE]
4858
     add   edi,TASKDATA.mem_start
4858
     add   edi,TASKDATA.mem_start
4859
     add   eax,[edi]
4859
     add   eax,[edi]
4860
     add   ebx,[edi]
4860
     add   ebx,[edi]
4861
     call  filesave
4861
     call  filesave
4862
     mov   [esp+36],eax
4862
     mov   [esp+36],eax
4863
     ret
4863
     ret
4864
 
4864
 
4865
align 4
4865
align 4
4866
 
4866
 
4867
syscall_getpixel:                       ; GetPixel
4867
syscall_getpixel:                       ; GetPixel
4868
     mov   ecx,[ScreenWidth]
4868
     mov   ecx,[ScreenWidth]
4869
     inc   ecx
4869
     inc   ecx
4870
     xor   edx,edx
4870
     xor   edx,edx
4871
     div   ecx
4871
     div   ecx
4872
     mov   ebx,edx
4872
     mov   ebx,edx
4873
     xchg  eax,ebx
4873
     xchg  eax,ebx
4874
     call  dword [GETPIXEL]
4874
     call  dword [GETPIXEL]
4875
     mov   [esp+36],ecx
4875
     mov   [esp+36],ecx
4876
     ret
4876
     ret
4877
 
4877
 
4878
align 4
4878
align 4
4879
 
4879
 
4880
syscall_readstring:                     ; ReadString
4880
syscall_readstring:                     ; ReadString
4881
 
4881
 
4882
     mov   edi,[TASK_BASE]
4882
     mov   edi,[TASK_BASE]
4883
     add   edi,TASKDATA.mem_start
4883
     add   edi,TASKDATA.mem_start
4884
     add   eax,[edi]
4884
     add   eax,[edi]
4885
     call  read_string
4885
     call  read_string
4886
     mov   [esp+36],eax
4886
     mov   [esp+36],eax
4887
     ret
4887
     ret
4888
 
4888
 
4889
align 4
4889
align 4
4890
 
4890
 
4891
syscall_drawline:                       ; DrawLine
4891
syscall_drawline:                       ; DrawLine
4892
 
4892
 
4893
     mov   edi,[TASK_BASE]
4893
     mov   edi,[TASK_BASE]
4894
     movzx edx,word[edi-twdw+WDATA.box.left]
4894
     movzx edx,word[edi-twdw+WDATA.box.left]
4895
     mov   ebp,edx
4895
     mov   ebp,edx
4896
        mov     esi,[current_slot]
4896
        mov     esi,[current_slot]
4897
        add     ebp,[esi+APPDATA.wnd_clientbox.left]
4897
        add     ebp,[esi+APPDATA.wnd_clientbox.left]
4898
        add     dx,word[esi+APPDATA.wnd_clientbox.left]
4898
        add     dx,word[esi+APPDATA.wnd_clientbox.left]
4899
     shl   edx,16
4899
     shl   edx,16
4900
     add   ebp,edx
4900
     add   ebp,edx
4901
     movzx edx,word[edi-twdw+WDATA.box.top]
4901
     movzx edx,word[edi-twdw+WDATA.box.top]
4902
     add   eax,ebp
4902
     add   eax,ebp
4903
     mov   ebp,edx
4903
     mov   ebp,edx
4904
        add     ebp,[esi+APPDATA.wnd_clientbox.top]
4904
        add     ebp,[esi+APPDATA.wnd_clientbox.top]
4905
        add     dx,word[esi+APPDATA.wnd_clientbox.top]
4905
        add     dx,word[esi+APPDATA.wnd_clientbox.top]
4906
     shl   edx,16
4906
     shl   edx,16
4907
     xor   edi,edi
4907
     xor   edi,edi
4908
     add   edx,ebp
4908
     add   edx,ebp
4909
     add   ebx,edx
4909
     add   ebx,edx
4910
     jmp   [draw_line]
4910
     jmp   [draw_line]
4911
 
4911
 
4912
align 4
4912
align 4
4913
 
4913
 
4914
syscall_getirqowner:                    ; GetIrqOwner
4914
syscall_getirqowner:                    ; GetIrqOwner
4915
     cmp   eax,16
4915
     cmp   eax,16
4916
     jae   .err
4916
     jae   .err
4917
     shl   eax,2
4917
     shl   eax,2
4918
     add   eax,irq_owner
4918
     add   eax,irq_owner
4919
     mov   eax,[eax]
4919
     mov   eax,[eax]
4920
     mov   [esp+36],eax
4920
     mov   [esp+36],eax
4921
     ret
4921
     ret
4922
.err:
4922
.err:
4923
     or    dword [esp+36], -1
4923
     or    dword [esp+36], -1
4924
     ret
4924
     ret
4925
 
4925
 
4926
align 4
4926
align 4
4927
 
4927
 
4928
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4928
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4929
 
4929
 
4930
     call  r_f_port_area
4930
     call  r_f_port_area
4931
     mov   [esp+36],eax
4931
     mov   [esp+36],eax
4932
     ret
4932
     ret
4933
 
4933
 
4934
align 4
4934
align 4
4935
 
4935
 
4936
syscall_threads:                        ; CreateThreads
4936
syscall_threads:                        ; CreateThreads
4937
 
4937
 
4938
     call  sys_threads
4938
     call  sys_threads
4939
     mov   [esp+36],eax
4939
     mov   [esp+36],eax
4940
     ret
4940
     ret
4941
 
4941
 
4942
align 4
4942
align 4
4943
 
4943
 
4944
stack_driver_stat:
4944
stack_driver_stat:
4945
 
4945
 
4946
     call  app_stack_handler            ; Stack status
4946
     call  app_stack_handler            ; Stack status
4947
 
4947
 
4948
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4948
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4949
;     call  change_task                 ; between sent packet
4949
;     call  change_task                 ; between sent packet
4950
 
4950
 
4951
     mov   [esp+36],eax
4951
     mov   [esp+36],eax
4952
     ret
4952
     ret
4953
 
4953
 
4954
align 4
4954
align 4
4955
 
4955
 
4956
socket:                                 ; Socket interface
4956
socket:                                 ; Socket interface
4957
     call  app_socket_handler
4957
     call  app_socket_handler
4958
 
4958
 
4959
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4959
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4960
;     call  change_task                 ; between sent packet
4960
;     call  change_task                 ; between sent packet
4961
 
4961
 
4962
     mov   [esp+36],eax
4962
     mov   [esp+36],eax
4963
     mov   [esp+24],ebx
4963
     mov   [esp+24],ebx
4964
     ret
4964
     ret
4965
 
4965
 
4966
align 4
4966
align 4
4967
 
4967
 
4968
user_events:                            ; User event times
4968
user_events:                            ; User event times
4969
 
4969
 
4970
     mov   eax,0x12345678
4970
     mov   eax,0x12345678
4971
     mov   [esp+36],eax
4971
     mov   [esp+36],eax
4972
 
4972
 
4973
     ret
4973
     ret
4974
 
4974
 
4975
align 4
4975
align 4
4976
 
4976
 
4977
read_from_hd:                           ; Read from hd - fn not in use
4977
read_from_hd:                           ; Read from hd - fn not in use
4978
 
4978
 
4979
     mov   edi,[TASK_BASE]
4979
     mov   edi,[TASK_BASE]
4980
     add   edi,TASKDATA.mem_start
4980
     add   edi,TASKDATA.mem_start
4981
     add   eax,[edi]
4981
     add   eax,[edi]
4982
     add   ecx,[edi]
4982
     add   ecx,[edi]
4983
     add   edx,[edi]
4983
     add   edx,[edi]
4984
     call  file_read
4984
     call  file_read
4985
 
4985
 
4986
     mov   [esp+36],eax
4986
     mov   [esp+36],eax
4987
     mov   [esp+24],ebx
4987
     mov   [esp+24],ebx
4988
 
4988
 
4989
     ret
4989
     ret
4990
 
4990
 
4991
align 4
4991
align 4
4992
paleholder:
4992
paleholder:
4993
	ret
4993
	ret
4994
 
4994
 
4995
; --------------- APM ---------------------
4995
; --------------- APM ---------------------
4996
apm_entry    dp    0
4996
apm_entry    dp    0
4997
apm_vf        dd    0
4997
apm_vf        dd    0
4998
align 4
4998
align 4
4999
sys_apm:
4999
sys_apm:
5000
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5000
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5001
    jne    @f
5001
    jne    @f
5002
    or    [esp + 56], byte 1    ; error
5002
    or    [esp + 56], byte 1    ; error
5003
    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
5004
    ret
5004
    ret
5005
 
5005
 
5006
@@:
5006
@@:
5007
    xchg    eax, ecx
5007
    xchg    eax, ecx
5008
    xchg    ebx, ecx
5008
    xchg    ebx, ecx
5009
 
5009
 
5010
    cmp    al, 3
5010
    cmp    al, 3
5011
    ja    @f
5011
    ja    @f
5012
    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
5013
    mov    eax, [apm_vf]
5013
    mov    eax, [apm_vf]
5014
    mov    [esp + 36], eax
5014
    mov    [esp + 36], eax
5015
    shr    eax, 16
5015
    shr    eax, 16
5016
    mov    [esp + 32], eax
5016
    mov    [esp + 32], eax
5017
    ret
5017
    ret
5018
 
5018
 
5019
@@:
5019
@@:
5020
 
5020
 
5021
    mov esi, [master_tab+(OS_BASE shr 20)]
5021
    mov esi, [master_tab+(OS_BASE shr 20)]
5022
    xchg [master_tab], esi
5022
    xchg [master_tab], esi
5023
    push esi
5023
    push esi
5024
    mov edi, cr3
5024
    mov edi, cr3
5025
    mov cr3, edi                 ;flush TLB
5025
    mov cr3, edi                 ;flush TLB
5026
 
5026
 
5027
    call    pword [apm_entry]    ; call APM BIOS
5027
    call    pword [apm_entry]    ; call APM BIOS
5028
 
5028
 
5029
    xchg eax, [esp]
5029
    xchg eax, [esp]
5030
    mov [master_tab], eax
5030
    mov [master_tab], eax
5031
    mov eax, cr3
5031
    mov eax, cr3
5032
    mov cr3, eax
5032
    mov cr3, eax
5033
    pop eax
5033
    pop eax
5034
 
5034
 
5035
    mov    [esp + 8 ], edi
5035
    mov    [esp + 8 ], edi
5036
    mov    [esp + 12], esi
5036
    mov    [esp + 12], esi
5037
    mov    [esp + 24], ebx
5037
    mov    [esp + 24], ebx
5038
    mov    [esp + 28], edx
5038
    mov    [esp + 28], edx
5039
    mov    [esp + 32], ecx
5039
    mov    [esp + 32], ecx
5040
    mov    [esp + 36], eax
5040
    mov    [esp + 36], eax
5041
    setc    al
5041
    setc    al
5042
    and    [esp + 56], byte 0xfe
5042
    and    [esp + 56], byte 0xfe
5043
    or    [esp + 56], al
5043
    or    [esp + 56], al
5044
 
5044
 
5045
 
5045
 
5046
    ret
5046
    ret
5047
; -----------------------------------------
5047
; -----------------------------------------
5048
 
5048
 
5049
align 4
5049
align 4
5050
 
5050
 
5051
undefined_syscall:                      ; Undefined system call
5051
undefined_syscall:                      ; Undefined system call
5052
 
5052
 
5053
     mov   [esp+36],dword -1
5053
     mov   [esp+36],dword -1
5054
     ret
5054
     ret
5055
 
5055
 
5056
align 4
5056
align 4
5057
system_shutdown:          ; shut down the system
5057
system_shutdown:          ; shut down the system
5058
 
5058
 
5059
           cmp byte [BOOT_VAR+0x9030], 1
5059
           cmp byte [BOOT_VAR+0x9030], 1
5060
           jne @F
5060
           jne @F
5061
           ret
5061
           ret
5062
@@:
5062
@@:
5063
           call stop_all_services
5063
           call stop_all_services
5064
           push 3                ; stop playing cd
5064
           push 3                ; stop playing cd
5065
           pop  eax
5065
           pop  eax
5066
           call sys_cd_audio
5066
           call sys_cd_audio
5067
 
5067
 
5068
yes_shutdown_param:
5068
yes_shutdown_param:
5069
           cli
5069
           cli
5070
 
5070
 
5071
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
5071
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
5072
           push 12
5072
           push 12
5073
           pop  esi
5073
           pop  esi
5074
           xor  ebx,ebx
5074
           xor  ebx,ebx
5075
           or   ecx,-1
5075
           or   ecx,-1
5076
           mov  edx, OS_BASE+0x80000
5076
           mov  edx, OS_BASE+0x80000
5077
           call fileread
5077
           call fileread
5078
 
5078
 
5079
           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
5080
           mov  edi,OS_BASE+0x40000
5080
           mov  edi,OS_BASE+0x40000
5081
           mov  ecx,1000
5081
           mov  ecx,1000
5082
           rep  movsb
5082
           rep  movsb
5083
 
5083
 
5084
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5084
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5085
           mov  edi, OS_BASE
5085
           mov  edi, OS_BASE
5086
           mov  ecx,0x10000/4
5086
           mov  ecx,0x10000/4
5087
           cld
5087
           cld
5088
           rep movsd
5088
           rep movsd
5089
 
5089
 
5090
           call restorefatchain
5090
           call restorefatchain
5091
 
5091
 
5092
           mov al, 0xFF
5092
           mov al, 0xFF
5093
           out 0x21, al
5093
           out 0x21, al
5094
           out 0xA1, al
5094
           out 0xA1, al
5095
 
5095
 
5096
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5096
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5097
           mov  word [OS_BASE+0x467+2],0x1000
5097
           mov  word [OS_BASE+0x467+2],0x1000
5098
 
5098
 
5099
           mov  al,0x0F
5099
           mov  al,0x0F
5100
           out  0x70,al
5100
           out  0x70,al
5101
           mov  al,0x05
5101
           mov  al,0x05
5102
           out  0x71,al
5102
           out  0x71,al
5103
 
5103
 
5104
           mov  al,0xFE
5104
           mov  al,0xFE
5105
           out  0x64,al
5105
           out  0x64,al
5106
           hlt
5106
           hlt
5107
 
5107
 
5108
 
5108
 
5109
include "data32.inc"
5109
include "data32.inc"
5110
 
5110
 
5111
__REV__ = __REV
5111
__REV__ = __REV
5112
 
5112
 
5113
uglobals_size = $ - endofcode
5113
uglobals_size = $ - endofcode
5114
diff16 "end of kernel code",0,$
5114
diff16 "end of kernel code",0,$