Subversion Repositories Kolibri OS

Rev

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

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