Subversion Repositories Kolibri OS

Rev

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

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