Subversion Repositories Kolibri OS

Rev

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

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