Subversion Repositories Kolibri OS

Rev

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

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