Subversion Repositories Kolibri OS

Rev

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

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