Subversion Repositories Kolibri OS

Rev

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

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