Subversion Repositories Kolibri OS

Rev

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

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