Subversion Repositories Kolibri OS

Rev

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

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