Subversion Repositories Kolibri OS

Rev

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

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