Subversion Repositories Kolibri OS

Rev

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

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