Subversion Repositories Kolibri OS

Rev

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

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