Subversion Repositories Kolibri OS

Rev

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

Rev 477 Rev 479
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
2
;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved.
3
;; Copyright (C) KolibriOS team 2004-2007. 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
;;
19
;;
20
;; Data in this file was originally part of MenuetOS project which is
20
;; Data in this file was originally part of MenuetOS project which is
21
;; distributed under the terms of GNU GPL. It is modified and redistributed as
21
;; distributed under the terms of GNU GPL. It is modified and redistributed as
22
;; part of KolibriOS project under the terms of GNU GPL.
22
;; part of KolibriOS project under the terms of GNU GPL.
23
;;
23
;;
24
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
24
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
25
;; PROGRAMMING:
25
;; PROGRAMMING:
26
;;
26
;;
27
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
27
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
28
;; - main os coding/design
28
;; - main os coding/design
29
;; Jan-Michael Brummer, BUZZ2@gmx.de
29
;; Jan-Michael Brummer, BUZZ2@gmx.de
30
;; Felix Kaiser, info@felix-kaiser.de
30
;; Felix Kaiser, info@felix-kaiser.de
31
;; Paolo Minazzi, paolo.minazzi@inwind.it
31
;; Paolo Minazzi, paolo.minazzi@inwind.it
32
;; quickcode@mail.ru
32
;; quickcode@mail.ru
33
;; Alexey, kgaz@crosswinds.net
33
;; Alexey, kgaz@crosswinds.net
34
;; Juan M. Caravaca, bitrider@wanadoo.es
34
;; Juan M. Caravaca, bitrider@wanadoo.es
35
;; kristol@nic.fi
35
;; kristol@nic.fi
36
;; Mike Hibbett, mikeh@oceanfree.net
36
;; Mike Hibbett, mikeh@oceanfree.net
37
;; Lasse Kuusijarvi, kuusijar@lut.fi
37
;; Lasse Kuusijarvi, kuusijar@lut.fi
38
;; Jarek Pelczar, jarekp3@wp.pl
38
;; Jarek Pelczar, jarekp3@wp.pl
39
;;
39
;;
40
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
40
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
41
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
41
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
42
;; consequences of using it or for whether it serves any particular purpose or
42
;; consequences of using it or for whether it serves any particular purpose or
43
;; works at all, unless he says so in writing. Refer to the GNU General Public
43
;; works at all, unless he says so in writing. Refer to the GNU General Public
44
;; License (the "GPL") for full details.
44
;; License (the "GPL") for full details.
45
;
45
;
46
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
46
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
47
;; but only under the conditions described in the GPL. A copy of this license
47
;; but only under the conditions described in the GPL. A copy of this license
48
;; is supposed to have been given to you along with KolibriOS so you can know
48
;; is supposed to have been given to you along with KolibriOS so you can know
49
;; your rights and responsibilities. It should be in a file named COPYING.
49
;; your rights and responsibilities. It should be in a file named COPYING.
50
;; Among other things, the copyright notice and this notice must be preserved
50
;; Among other things, the copyright notice and this notice must be preserved
51
;; on all copies.
51
;; on all copies.
52
;;
52
;;
53
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54
 
54
 
55
include 'macros.inc'
55
include 'macros.inc'
56
 
56
 
57
$Revision: 477 $
57
$Revision: 479 $
58
 
58
 
59
include "proc32.inc"
59
include "proc32.inc"
60
include "kglobals.inc"
60
include "kglobals.inc"
61
include "lang.inc"
61
include "lang.inc"
62
 
62
 
63
include "const.inc"
63
include "const.inc"
64
max_processes    equ   255
64
max_processes    equ   255
65
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
65
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
66
 
66
 
67
 
67
 
68
os_stack       equ  (os_data_l-gdts)    ; GDTs
68
os_stack       equ  (os_data_l-gdts)    ; GDTs
69
os_code        equ  (os_code_l-gdts)
69
os_code        equ  (os_code_l-gdts)
70
graph_data     equ  (3+graph_data_l-gdts)
70
graph_data     equ  (3+graph_data_l-gdts)
71
tss0           equ  (tss0_l-gdts)
71
tss0           equ  (tss0_l-gdts)
72
app_code       equ  (3+app_code_l-gdts)
72
app_code       equ  (3+app_code_l-gdts)
73
app_data       equ  (3+app_data_l-gdts)
73
app_data       equ  (3+app_data_l-gdts)
74
 
74
 
75
 
75
 
76
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77
;;
77
;;
78
;;   Included files:
78
;;   Included files:
79
;;
79
;;
80
;;   Kernel16.inc
80
;;   Kernel16.inc
81
;;    - Booteng.inc   English text for bootup
81
;;    - Booteng.inc   English text for bootup
82
;;    - Bootcode.inc  Hardware setup
82
;;    - Bootcode.inc  Hardware setup
83
;;    - Pci16.inc     PCI functions
83
;;    - Pci16.inc     PCI functions
84
;;
84
;;
85
;;   Kernel32.inc
85
;;   Kernel32.inc
86
;;    - Sys32.inc     Process management
86
;;    - Sys32.inc     Process management
87
;;    - Shutdown.inc  Shutdown and restart
87
;;    - Shutdown.inc  Shutdown and restart
88
;;    - Fat32.inc     Read / write hd
88
;;    - Fat32.inc     Read / write hd
89
;;    - Vesa12.inc    Vesa 1.2 driver
89
;;    - Vesa12.inc    Vesa 1.2 driver
90
;;    - Vesa20.inc    Vesa 2.0 driver
90
;;    - Vesa20.inc    Vesa 2.0 driver
91
;;    - Vga.inc       VGA driver
91
;;    - Vga.inc       VGA driver
92
;;    - Stack.inc     Network interface
92
;;    - Stack.inc     Network interface
93
;;    - Mouse.inc     Mouse pointer
93
;;    - Mouse.inc     Mouse pointer
94
;;    - Scincode.inc  Window skinning
94
;;    - Scincode.inc  Window skinning
95
;;    - Pci32.inc     PCI functions
95
;;    - Pci32.inc     PCI functions
96
;;
96
;;
97
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
97
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
98
 
98
 
99
 
99
 
100
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
101
;;                                                                      ;;
101
;;                                                                      ;;
102
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
102
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
103
;;                                                                      ;;
103
;;                                                                      ;;
104
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105
 
105
 
106
use16
106
use16
107
                  org   0x0
107
                  org   0x0
108
                  jmp   start_of_code
108
                  jmp   start_of_code
109
 
109
 
110
version db    'Kolibri OS  version 0.6.5.0      ',13,10,13,10,0
110
version db    'Kolibri OS  version 0.6.5.0      ',13,10,13,10,0
111
 
111
 
112
include "boot/bootstr.inc"     ; language-independent boot messages
112
include "boot/bootstr.inc"     ; language-independent boot messages
113
include "boot/preboot.inc"
113
include "boot/preboot.inc"
114
 
114
 
115
if lang eq en
115
if lang eq en
116
include "boot/booteng.inc"     ; english system boot messages
116
include "boot/booteng.inc"     ; english system boot messages
117
else if lang eq ru
117
else if lang eq ru
118
include "boot/bootru.inc"      ; russian system boot messages
118
include "boot/bootru.inc"      ; russian system boot messages
119
include "boot/ru.inc"          ; Russian font
119
include "boot/ru.inc"          ; Russian font
120
else if lang eq et
120
else if lang eq et
121
include "boot/bootet.inc"      ; estonian system boot messages
121
include "boot/bootet.inc"      ; estonian system boot messages
122
include "boot/et.inc"          ; Estonian font
122
include "boot/et.inc"          ; Estonian font
123
else
123
else
124
include "boot/bootge.inc"      ; german system boot messages
124
include "boot/bootge.inc"      ; german system boot messages
125
end if
125
end if
126
 
126
 
127
include "boot/bootcode.inc"    ; 16 bit system boot code
127
include "boot/bootcode.inc"    ; 16 bit system boot code
128
include "bus/pci/pci16.inc"
128
include "bus/pci/pci16.inc"
129
 
129
 
130
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
130
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
131
;;                                                                      ;;
131
;;                                                                      ;;
132
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
132
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
133
;;                                                                      ;;
133
;;                                                                      ;;
134
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135
 
135
 
136
 
136
 
137
; CR0 Flags - Protected mode and Paging
137
; CR0 Flags - Protected mode and Paging
138
 
138
 
139
        mov ecx, CR0_PE
139
        mov ecx, CR0_PE
140
 
140
 
141
; Enabling 32 bit protected mode
141
; Enabling 32 bit protected mode
142
 
142
 
143
        sidt    [cs:old_ints_h]
143
        sidt    [cs:old_ints_h]
144
 
144
 
145
        cli                             ; disable all irqs
145
        cli                             ; disable all irqs
146
        cld
146
        cld
147
        mov     al,255                  ; mask all irqs
147
        mov     al,255                  ; mask all irqs
148
        out     0xa1,al
148
        out     0xa1,al
149
        out     0x21,al
149
        out     0x21,al
150
   l.5: in      al, 0x64                ; Enable A20
150
   l.5: in      al, 0x64                ; Enable A20
151
        test    al, 2
151
        test    al, 2
152
        jnz     l.5
152
        jnz     l.5
153
        mov     al, 0xD1
153
        mov     al, 0xD1
154
        out     0x64, al
154
        out     0x64, al
155
   l.6: in      al, 0x64
155
   l.6: in      al, 0x64
156
        test    al, 2
156
        test    al, 2
157
        jnz     l.6
157
        jnz     l.6
158
        mov     al, 0xDF
158
        mov     al, 0xDF
159
        out     0x60, al
159
        out     0x60, al
160
   l.7: in      al, 0x64
160
   l.7: in      al, 0x64
161
        test    al, 2
161
        test    al, 2
162
        jnz     l.7
162
        jnz     l.7
163
        mov     al, 0xFF
163
        mov     al, 0xFF
164
        out     0x64, al
164
        out     0x64, al
165
 
165
 
166
        lgdt    [cs:tmp_gdt]            ; Load GDT
166
        lgdt    [cs:tmp_gdt]            ; Load GDT
167
        mov     eax, cr0                ; protected mode
167
        mov     eax, cr0                ; protected mode
168
        or      eax, ecx
168
        or      eax, ecx
169
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
169
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
170
        mov     cr0, eax
170
        mov     cr0, eax
171
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
171
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
172
 
172
 
173
include "boot/shutdown.inc" ; shutdown or restart
173
include "boot/shutdown.inc" ; shutdown or restart
174
 
174
 
175
align 8
175
align 8
176
tmp_gdt:
176
tmp_gdt:
177
 
177
 
178
        dw     23
178
        dw     23
179
        dd     tmp_gdt+0x10000
179
        dd     tmp_gdt+0x10000
180
        dw     0
180
        dw     0
181
 
181
 
182
        dw     0xffff
182
        dw     0xffff
183
        dw     0x0000
183
        dw     0x0000
184
        db     0x00
184
        db     0x00
185
        dw     11011111b *256 +10011010b
185
        dw     11011111b *256 +10011010b
186
        db     0x00
186
        db     0x00
187
 
187
 
188
        dw     0xffff
188
        dw     0xffff
189
        dw     0x0000
189
        dw     0x0000
190
        db     0x00
190
        db     0x00
191
        dw     11011111b *256 +10010010b
191
        dw     11011111b *256 +10010010b
192
        db     0x00
192
        db     0x00
193
 
193
 
194
include "data16.inc"
194
include "data16.inc"
195
 
195
 
196
use32
196
use32
197
org $+0x10000
197
org $+0x10000
198
 
198
 
199
align 4
199
align 4
200
B32:
200
B32:
201
           mov   ax,os_stack       ; Selector for os
201
           mov   ax,os_stack       ; Selector for os
202
           mov   ds,ax
202
           mov   ds,ax
203
           mov   es,ax
203
           mov   es,ax
204
           mov   fs,ax
204
           mov   fs,ax
205
           mov   gs,ax
205
           mov   gs,ax
206
           mov   ss,ax
206
           mov   ss,ax
207
           mov   esp,0x3ec00       ; Set stack
207
           mov   esp,0x3ec00       ; Set stack
208
 
208
 
209
; CLEAR 0x280000 - HEAP_BASE
209
; CLEAR 0x280000 - HEAP_BASE
210
 
210
 
211
           xor   eax,eax
211
           xor   eax,eax
212
           mov   edi,0x280000
212
           mov   edi,0x280000
213
           mov   ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
213
           mov   ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
214
           cld
214
           cld
215
           rep   stosd
215
           rep   stosd
216
 
216
 
217
           mov   edi,0x40000
217
           mov   edi,0x40000
218
           mov   ecx,(0x90000-0x40000)/4
218
           mov   ecx,(0x90000-0x40000)/4
219
           rep   stosd
219
           rep   stosd
220
 
220
 
221
; CLEAR KERNEL UNDEFINED GLOBALS
221
; CLEAR KERNEL UNDEFINED GLOBALS
222
           mov   edi, endofcode-OS_BASE
222
           mov   edi, endofcode-OS_BASE
223
           mov   ecx, (uglobals_size/4)+4
223
           mov   ecx, (uglobals_size/4)+4
224
           rep   stosd
224
           rep   stosd
225
 
225
 
226
; SAVE & CLEAR 0-0xffff
226
; SAVE & CLEAR 0-0xffff
227
 
227
 
228
           xor esi, esi
228
           xor esi, esi
229
           mov   edi,0x2F0000
229
           mov   edi,0x2F0000
230
           mov   ecx,0x10000 / 4
230
           mov   ecx,0x10000 / 4
231
           rep   movsd
231
           rep   movsd
232
           xor edi, edi
232
           xor edi, edi
233
           mov   ecx,0x10000 / 4
233
           mov   ecx,0x10000 / 4
234
           rep   stosd
234
           rep   stosd
235
 
235
 
236
           call test_cpu
236
           call test_cpu
237
           bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
237
           bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
238
 
238
 
239
; MEMORY MODEL
239
; MEMORY MODEL
240
           call mem_test
240
           call mem_test
241
           call init_mem
241
           call init_mem
242
           call init_page_map
242
           call init_page_map
243
 
243
 
244
; ENABLE PAGING
244
; ENABLE PAGING
245
 
245
 
246
           mov eax, sys_pgdir-OS_BASE
246
           mov eax, sys_pgdir-OS_BASE
247
           mov cr3, eax
247
           mov cr3, eax
248
 
248
 
249
           mov eax,cr0
249
           mov eax,cr0
250
           or eax,CR0_PG+CR0_WP
250
           or eax,CR0_PG+CR0_WP
251
           mov cr0,eax
251
           mov cr0,eax
252
 
252
 
253
           lgdt [gdts]
253
           lgdt [gdts]
254
           jmp pword os_code:high_code
254
           jmp pword os_code:high_code
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
align 4
262
align 4
263
high_code:
263
high_code:
264
           mov   ax,os_stack
264
           mov   ax,os_stack
265
           mov   bx,app_data
265
           mov   bx,app_data
266
           mov   ss,ax
266
           mov   ss,ax
267
           add esp, OS_BASE
267
           add esp, OS_BASE
268
 
268
 
269
           mov   ds,bx
269
           mov   ds,bx
270
           mov   es,bx
270
           mov   es,bx
271
           mov   fs,bx
271
           mov   fs,bx
272
           mov   gs,bx
272
           mov   gs,bx
273
 
273
 
274
           mov dword [sys_pgdir], 0
274
           mov dword [sys_pgdir], 0
275
           mov dword [sys_pgdir+4], 0
275
           mov dword [sys_pgdir+4], 0
276
           mov dword [sys_pgdir+8], 0
276
           mov dword [sys_pgdir+8], 0
277
 
277
 
278
           mov eax, cr3
278
           mov eax, cr3
279
           mov cr3, eax           ; flush TLB
279
           mov cr3, eax           ; flush TLB
280
 
280
 
281
; SAVE REAL MODE VARIABLES
281
; SAVE REAL MODE VARIABLES
282
        mov     ax, [BOOT_VAR + 0x9031]
282
        mov     ax, [BOOT_VAR + 0x9031]
283
        mov     [IDEContrRegsBaseAddr], ax
283
        mov     [IDEContrRegsBaseAddr], ax
284
; --------------- APM ---------------------
284
; --------------- APM ---------------------
285
 
285
 
286
; init selectors
286
; init selectors
287
    mov ebx,    [BOOT_VAR+0x9040]              ; offset of APM entry point
287
    mov ebx,    [BOOT_VAR+0x9040]              ; offset of APM entry point
288
    movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of
288
    movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of
289
                                      ; protected-mode 32-bit code segment
289
                                      ; protected-mode 32-bit code segment
290
    movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of
290
    movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of
291
                                      ; protected-mode 16-bit code segment
291
                                      ; protected-mode 16-bit code segment
292
    movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of
292
    movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of
293
                                      ; protected-mode 16-bit data segment
293
                                      ; protected-mode 16-bit data segment
294
 
294
 
295
    shl    eax, 4
295
    shl    eax, 4
296
    mov    [dword apm_code_32 + 2], ax
296
    mov    [dword apm_code_32 + 2], ax
297
    shr    eax, 16
297
    shr    eax, 16
298
    mov    [dword apm_code_32 + 4], al
298
    mov    [dword apm_code_32 + 4], al
299
 
299
 
300
    shl    ecx, 4
300
    shl    ecx, 4
301
    mov    [dword apm_code_16 + 2], cx
301
    mov    [dword apm_code_16 + 2], cx
302
    shr    ecx, 16
302
    shr    ecx, 16
303
    mov    [dword apm_code_16 + 4], cl
303
    mov    [dword apm_code_16 + 4], cl
304
 
304
 
305
    shl    edx, 4
305
    shl    edx, 4
306
    mov    [dword apm_data_16 + 2], dx
306
    mov    [dword apm_data_16 + 2], dx
307
    shr    edx, 16
307
    shr    edx, 16
308
    mov    [dword apm_data_16 + 4], dl
308
    mov    [dword apm_data_16 + 4], dl
309
 
309
 
310
    mov    dword[apm_entry], ebx
310
    mov    dword[apm_entry], ebx
311
    mov    word [apm_entry + 4], apm_code_32 - gdts
311
    mov    word [apm_entry + 4], apm_code_32 - gdts
312
 
312
 
313
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
313
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
314
    mov    [apm_vf], eax
314
    mov    [apm_vf], eax
315
; -----------------------------------------
315
; -----------------------------------------
316
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
316
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
317
;        mov   [0xF604],byte 1  ;al
317
;        mov   [0xF604],byte 1  ;al
318
        mov     al, [BOOT_VAR+0x901F]   ; DMA writing
318
        mov     al, [BOOT_VAR+0x901F]   ; DMA writing
319
        mov     [allow_dma_write], al
319
        mov     [allow_dma_write], al
320
        mov   al,[BOOT_VAR+0x9000]        ; bpp
320
        mov   al,[BOOT_VAR+0x9000]        ; bpp
321
        mov   [ScreenBPP],al
321
        mov   [ScreenBPP],al
322
        movzx eax,word [BOOT_VAR+0x900A]  ; X max
322
        movzx eax,word [BOOT_VAR+0x900A]  ; X max
323
        dec   eax
323
        dec   eax
324
        mov   [ScreenWidth],eax
324
        mov   [ScreenWidth],eax
325
        mov   [screen_workarea.right],eax
325
        mov   [screen_workarea.right],eax
326
        movzx eax,word [BOOT_VAR+0x900C]  ; Y max
326
        movzx eax,word [BOOT_VAR+0x900C]  ; Y max
327
        dec   eax
327
        dec   eax
328
        mov   [ScreenHeight],eax
328
        mov   [ScreenHeight],eax
329
        mov   [screen_workarea.bottom],eax
329
        mov   [screen_workarea.bottom],eax
330
        movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
330
        movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
331
        mov   [SCR_MODE],eax
331
        mov   [SCR_MODE],eax
332
        mov   eax,[BOOT_VAR+0x9014]       ; Vesa 1.2 bnk sw add
332
        mov   eax,[BOOT_VAR+0x9014]       ; Vesa 1.2 bnk sw add
333
        mov   [BANK_SWITCH],eax
333
        mov   [BANK_SWITCH],eax
334
        mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
334
        mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
335
        cmp   [SCR_MODE],word 0x13          ; 320x200
335
        cmp   [SCR_MODE],word 0x13          ; 320x200
336
        je    @f
336
        je    @f
337
        cmp   [SCR_MODE],word 0x12          ; VGA 640x480
337
        cmp   [SCR_MODE],word 0x12          ; VGA 640x480
338
        je    @f
338
        je    @f
339
        mov   ax,[BOOT_VAR+0x9001]        ; for other modes
339
        mov   ax,[BOOT_VAR+0x9001]        ; for other modes
340
        mov   [BytesPerScanLine],ax
340
        mov   [BytesPerScanLine],ax
341
@@:
341
@@:
342
 
342
 
343
; GRAPHICS ADDRESSES
343
; GRAPHICS ADDRESSES
344
 
344
 
345
        mov     byte [BOOT_VAR+0x901e],0x0
345
        mov     byte [BOOT_VAR+0x901e],0x0
346
        mov     eax,[BOOT_VAR+0x9018]
346
        mov     eax,[BOOT_VAR+0x9018]
347
        mov     [LFBAddress],eax
347
        mov     [LFBAddress],eax
348
 
348
 
349
        cmp     [SCR_MODE],word 0100000000000000b
349
        cmp     [SCR_MODE],word 0100000000000000b
350
        jge     setvesa20
350
        jge     setvesa20
351
        cmp     [SCR_MODE],word 0x13
351
        cmp     [SCR_MODE],word 0x13
352
        je      v20ga32
352
        je      v20ga32
353
        mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
353
        mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
354
        mov     [GETPIXEL],dword Vesa12_getpixel24
354
        mov     [GETPIXEL],dword Vesa12_getpixel24
355
        cmp     [ScreenBPP],byte 24
355
        cmp     [ScreenBPP],byte 24
356
        jz      ga24
356
        jz      ga24
357
        mov     [PUTPIXEL],dword Vesa12_putpixel32
357
        mov     [PUTPIXEL],dword Vesa12_putpixel32
358
        mov     [GETPIXEL],dword Vesa12_getpixel32
358
        mov     [GETPIXEL],dword Vesa12_getpixel32
359
      ga24:
359
      ga24:
360
        jmp     v20ga24
360
        jmp     v20ga24
361
      setvesa20:
361
      setvesa20:
362
        mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
362
        mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
363
        mov     [GETPIXEL],dword Vesa20_getpixel24
363
        mov     [GETPIXEL],dword Vesa20_getpixel24
364
        cmp     [ScreenBPP],byte 24
364
        cmp     [ScreenBPP],byte 24
365
        jz      v20ga24
365
        jz      v20ga24
366
      v20ga32:
366
      v20ga32:
367
        mov     [PUTPIXEL],dword Vesa20_putpixel32
367
        mov     [PUTPIXEL],dword Vesa20_putpixel32
368
        mov     [GETPIXEL],dword Vesa20_getpixel32
368
        mov     [GETPIXEL],dword Vesa20_getpixel32
369
      v20ga24:
369
      v20ga24:
370
        cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
370
        cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
371
        jne     no_mode_0x12
371
        jne     no_mode_0x12
372
        mov     [PUTPIXEL],dword VGA_putpixel
372
        mov     [PUTPIXEL],dword VGA_putpixel
373
        mov     [GETPIXEL],dword Vesa20_getpixel32
373
        mov     [GETPIXEL],dword Vesa20_getpixel32
374
      no_mode_0x12:
374
      no_mode_0x12:
375
 
375
 
376
; -------- Fast System Call init ----------
376
; -------- Fast System Call init ----------
377
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
377
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
378
           bt [cpu_caps], CAPS_SEP
378
           bt [cpu_caps], CAPS_SEP
379
           jnc .SEnP   ; SysEnter not Present
379
           jnc .SEnP   ; SysEnter not Present
380
           xor edx, edx
380
           xor edx, edx
381
           mov ecx, MSR_SYSENTER_CS
381
           mov ecx, MSR_SYSENTER_CS
382
           mov eax, os_code
382
           mov eax, os_code
383
           wrmsr
383
           wrmsr
384
           mov ecx, MSR_SYSENTER_ESP
384
           mov ecx, MSR_SYSENTER_ESP
385
;           mov eax, sysenter_stack ; Check it
385
;           mov eax, sysenter_stack ; Check it
386
           xor     eax, eax
386
           xor     eax, eax
387
           wrmsr
387
           wrmsr
388
           mov ecx, MSR_SYSENTER_EIP
388
           mov ecx, MSR_SYSENTER_EIP
389
           mov eax, sysenter_entry
389
           mov eax, sysenter_entry
390
           wrmsr
390
           wrmsr
391
.SEnP:
391
.SEnP:
392
; AMD SYSCALL/SYSRET
392
; AMD SYSCALL/SYSRET
393
           cmp byte[cpu_vendor], 'A'
393
           cmp byte[cpu_vendor], 'A'
394
           jne .noSYSCALL
394
           jne .noSYSCALL
395
           mov eax, 0x80000001
395
           mov eax, 0x80000001
396
           cpuid
396
           cpuid
397
           test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
397
           test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
398
           jz .noSYSCALL
398
           jz .noSYSCALL
399
           mov ecx, MSR_AMD_EFER
399
           mov ecx, MSR_AMD_EFER
400
           rdmsr
400
           rdmsr
401
           or eax, 1   ; bit_0 - System Call Extension (SCE)
401
           or eax, 1   ; bit_0 - System Call Extension (SCE)
402
           wrmsr
402
           wrmsr
403
 
403
 
404
	; !!!! It`s dirty hack, fix it !!!
404
	; !!!! It`s dirty hack, fix it !!!
405
	; Bits of EDX :
405
	; Bits of EDX :
406
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
406
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
407
	;  and the contents of this field, plus 8, are copied into the SS register.
407
	;  and the contents of this field, plus 8, are copied into the SS register.
408
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
408
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
409
	;  and the contents of this field, plus 8, are copied into the SS register.
409
	;  and the contents of this field, plus 8, are copied into the SS register.
410
 
410
 
411
	; mov	edx, (os_code + 16) * 65536 + os_code
411
	; mov	edx, (os_code + 16) * 65536 + os_code
412
           mov edx, 0x1B0008
412
           mov edx, 0x1B0008
413
 
413
 
414
           mov eax, syscall_entry
414
           mov eax, syscall_entry
415
           mov ecx, MSR_AMD_STAR
415
           mov ecx, MSR_AMD_STAR
416
           wrmsr
416
           wrmsr
417
.noSYSCALL:
417
.noSYSCALL:
418
; -----------------------------------------
418
; -----------------------------------------
419
 
419
 
420
; LOAD IDT
420
; LOAD IDT
421
 
421
 
422
           call build_interrupt_table
422
           call build_interrupt_table
423
           lidt [idtreg]
423
           lidt [idtreg]
424
 
424
 
425
           call init_kernel_heap
425
           call init_kernel_heap
426
           stdcall kernel_alloc, RING0_STACK_SIZE+512
426
           stdcall kernel_alloc, RING0_STACK_SIZE+512
427
           mov [os_stack_seg], eax
427
           mov [os_stack_seg], eax
428
 
428
 
429
           lea esp, [eax+RING0_STACK_SIZE]
429
           lea esp, [eax+RING0_STACK_SIZE]
430
 
430
 
431
           mov [tss._ss0], os_stack
431
           mov [tss._ss0], os_stack
432
           mov [tss._esp0], esp
432
           mov [tss._esp0], esp
433
           mov [tss._esp], esp
433
           mov [tss._esp], esp
434
           mov [tss._cs],os_code
434
           mov [tss._cs],os_code
435
           mov [tss._ss],os_stack
435
           mov [tss._ss],os_stack
436
           mov [tss._ds],app_data
436
           mov [tss._ds],app_data
437
           mov [tss._es],app_data
437
           mov [tss._es],app_data
438
           mov [tss._fs],app_data
438
           mov [tss._fs],app_data
439
           mov [tss._gs],app_data
439
           mov [tss._gs],app_data
440
           mov [tss._io],128
440
           mov [tss._io],128
441
;Add IO access table - bit array of permitted ports
441
;Add IO access table - bit array of permitted ports
442
           mov edi, tss._io_map_0
442
           mov edi, tss._io_map_0
443
           xor eax, eax
443
           xor eax, eax
444
           not eax
444
           not eax
445
           mov ecx, 8192/4
445
           mov ecx, 8192/4
446
           rep stosd                 ; access to 4096*8=65536 ports
446
           rep stosd                 ; access to 4096*8=65536 ports
447
 
447
 
448
           mov  ax,tss0
448
           mov  ax,tss0
449
           ltr  ax
449
           ltr  ax
450
 
450
 
451
           mov [LFBSize], 0x800000
451
           mov [LFBSize], 0x800000
452
           call init_mtrr
452
           call init_mtrr
453
 
453
 
454
           call init_LFB
454
           call init_LFB
455
           call init_fpu
455
           call init_fpu
456
           call init_malloc
456
           call init_malloc
457
 
457
 
458
           stdcall alloc_kernel_space, 0x51000
458
           stdcall alloc_kernel_space, 0x51000
459
           mov [default_io_map], eax
459
           mov [default_io_map], eax
460
 
460
 
461
           add eax, 0x2000
461
           add eax, 0x2000
462
           mov [ipc_tmp], eax
462
           mov [ipc_tmp], eax
463
           mov ebx, 0x1000
463
           mov ebx, 0x1000
464
 
464
 
465
           add eax, 0x40000
465
           add eax, 0x40000
466
           mov [proc_mem_map], eax
466
           mov [proc_mem_map], eax
467
 
467
 
468
           add eax, 0x8000
468
           add eax, 0x8000
469
           mov [proc_mem_pdir], eax
469
           mov [proc_mem_pdir], eax
470
 
470
 
471
           add eax, ebx
471
           add eax, ebx
472
           mov [proc_mem_tab], eax
472
           mov [proc_mem_tab], eax
473
 
473
 
474
           add eax, ebx
474
           add eax, ebx
475
           mov [tmp_task_pdir], eax
475
           mov [tmp_task_pdir], eax
476
 
476
 
477
           add eax, ebx
477
           add eax, ebx
478
           mov [tmp_task_ptab], eax
478
           mov [tmp_task_ptab], eax
479
 
479
 
480
           add eax, ebx
480
           add eax, ebx
481
           mov [ipc_pdir], eax
481
           mov [ipc_pdir], eax
482
 
482
 
483
           add eax, ebx
483
           add eax, ebx
484
           mov [ipc_ptab], eax
484
           mov [ipc_ptab], eax
485
 
485
 
486
           call init_events
486
           call init_events
487
           mov eax, srv.fd-SRV_FD_OFFSET
487
           mov eax, srv.fd-SRV_FD_OFFSET
488
           mov [srv.fd], eax
488
           mov [srv.fd], eax
489
           mov [srv.bk], eax
489
           mov [srv.bk], eax
490
 
490
 
491
           mov edi, irq_tab
491
           mov edi, irq_tab
492
           xor eax, eax
492
           xor eax, eax
493
           mov ecx, 16
493
           mov ecx, 16
494
           rep stosd
494
           rep stosd
495
 
495
 
496
;Set base of graphic segment to linear address of LFB
496
;Set base of graphic segment to linear address of LFB
497
        mov     eax,[LFBAddress]          ; set for gs
497
        mov     eax,[LFBAddress]          ; set for gs
498
        mov     [graph_data_l+2],ax
498
        mov     [graph_data_l+2],ax
499
        shr     eax,16
499
        shr     eax,16
500
        mov     [graph_data_l+4],al
500
        mov     [graph_data_l+4],al
501
        mov     [graph_data_l+7],ah
501
        mov     [graph_data_l+7],ah
502
 
502
 
503
        mov [CURRENT_TASK],dword 1
503
        mov [CURRENT_TASK],dword 1
504
        mov [TASK_COUNT],dword 1
504
        mov [TASK_COUNT],dword 1
505
        mov [TASK_BASE],dword TASK_DATA
505
        mov [TASK_BASE],dword TASK_DATA
506
        mov [current_slot], SLOT_BASE+256
506
        mov [current_slot], SLOT_BASE+256
507
 
507
 
508
; set background
508
; set background
509
        xor  eax,eax
509
        xor  eax,eax
510
        inc  eax
510
        inc  eax
511
        mov   [display_data-12],eax
511
        mov   [display_data-12],eax
512
        mov   [display_data-8],eax
512
        mov   [display_data-8],eax
513
        mov   [display_data-4],eax
513
        mov   [display_data-4],eax
514
        mov    [mem_BACKGROUND],4095
514
        mov    [mem_BACKGROUND],4095
515
        stdcall kernel_alloc, [mem_BACKGROUND]
515
        stdcall kernel_alloc, [mem_BACKGROUND]
516
        mov [img_background], eax
516
        mov [img_background], eax
517
 
517
 
518
 
518
 
519
;!!!!!!!!!!!!!!!!!!!!!!!!!!
519
;!!!!!!!!!!!!!!!!!!!!!!!!!!
520
include 'detect/disks.inc'
520
include 'detect/disks.inc'
521
;!!!!!!!!!!!!!!!!!!!!!!!!!!
521
;!!!!!!!!!!!!!!!!!!!!!!!!!!
522
 
522
 
523
; READ RAMDISK IMAGE FROM HD
523
; READ RAMDISK IMAGE FROM HD
524
 
524
 
525
;!!!!!!!!!!!!!!!!!!!!!!!
525
;!!!!!!!!!!!!!!!!!!!!!!!
526
include 'boot/rdload.inc'
526
include 'boot/rdload.inc'
527
;!!!!!!!!!!!!!!!!!!!!!!!
527
;!!!!!!!!!!!!!!!!!!!!!!!
528
;    mov    [dma_hdd],1
528
;    mov    [dma_hdd],1
529
; CALCULATE FAT CHAIN FOR RAMDISK
529
; CALCULATE FAT CHAIN FOR RAMDISK
530
 
530
 
531
        call  calculatefatchain
531
        call  calculatefatchain
532
 
532
 
533
; LOAD VMODE DRIVER
533
; LOAD VMODE DRIVER
534
 
534
 
535
;!!!!!!!!!!!!!!!!!!!!!!!
535
;!!!!!!!!!!!!!!!!!!!!!!!
536
include 'vmodeld.inc'
536
include 'vmodeld.inc'
537
;!!!!!!!!!!!!!!!!!!!!!!!
537
;!!!!!!!!!!!!!!!!!!!!!!!
538
 
538
 
539
; LOAD FONTS I and II
539
; LOAD FONTS I and II
540
 
540
 
541
        mov   esi,char
541
        mov   esi,char
542
        xor   ebx,ebx
542
        xor   ebx,ebx
543
        mov   ecx,2560
543
        mov   ecx,2560
544
        mov   edx,FONT_I
544
        mov   edx,FONT_I
545
        call  fs_RamdiskRead
545
        call  fs_RamdiskRead
546
 
546
 
547
        mov   esi,char2
547
        mov   esi,char2
548
        xor   ebx,ebx
548
        xor   ebx,ebx
549
        mov   ecx,2560;26000
549
        mov   ecx,2560;26000
550
        mov   edx,FONT_II
550
        mov   edx,FONT_II
551
        call  fs_RamdiskRead
551
        call  fs_RamdiskRead
552
 
552
 
553
        mov   esi,boot_fonts
553
        mov   esi,boot_fonts
554
        call  boot_log
554
        call  boot_log
555
 
555
 
556
; PRINT AMOUNT OF MEMORY
556
; PRINT AMOUNT OF MEMORY
557
        mov     esi, boot_memdetect
557
        mov     esi, boot_memdetect
558
        call    boot_log
558
        call    boot_log
559
 
559
 
560
        movzx   ecx, word [boot_y]
560
        movzx   ecx, word [boot_y]
561
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
561
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
562
        sub     ecx, 10
562
        sub     ecx, 10
563
        mov     edx, 0xFFFFFF
563
        mov     edx, 0xFFFFFF
564
        mov     ebx, [MEM_AMOUNT]
564
        mov     ebx, [MEM_AMOUNT]
565
        shr     ebx, 20
565
        shr     ebx, 20
566
        mov     edi, 1
566
        mov     edi, 1
567
        mov     eax, 0x00040000
567
        mov     eax, 0x00040000
568
        call    display_number_force
568
        call    display_number_force
569
 
569
 
570
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
570
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
571
 
571
 
572
        mov   esi,boot_irqs
572
        mov   esi,boot_irqs
573
        call  boot_log
573
        call  boot_log
574
        call  rerouteirqs
574
        call  rerouteirqs
575
 
575
 
576
        mov    esi,boot_tss
576
        mov    esi,boot_tss
577
        call   boot_log
577
        call   boot_log
578
 
578
 
579
; BUILD SCHEDULER
579
; BUILD SCHEDULER
580
 
580
 
581
        call   build_scheduler ; sys32.inc
581
        call   build_scheduler ; sys32.inc
582
 
582
 
583
        mov    esi,boot_devices
583
        mov    esi,boot_devices
584
        call   boot_log
584
        call   boot_log
585
        call   detect_devices
585
        call   detect_devices
-
 
586
        stdcall load_driver, szPS2MDriver
586
 
587
 
587
; TIMER SET TO 1/100 S
588
; TIMER SET TO 1/100 S
588
 
589
 
589
        mov   esi,boot_timer
590
        mov   esi,boot_timer
590
        call  boot_log
591
        call  boot_log
591
        mov   al,0x34              ; set to 100Hz
592
        mov   al,0x34              ; set to 100Hz
592
        out   0x43,al
593
        out   0x43,al
593
        mov   al,0x9b              ; lsb    1193180 / 1193
594
        mov   al,0x9b              ; lsb    1193180 / 1193
594
        out   0x40,al
595
        out   0x40,al
595
        mov   al,0x2e              ; msb
596
        mov   al,0x2e              ; msb
596
        out   0x40,al
597
        out   0x40,al
597
 
598
 
598
; SET MOUSE
599
; SET MOUSE
599
 
600
 
600
        mov   esi,boot_setmouse
601
        mov   esi,boot_setmouse
601
        call  boot_log
602
        call  boot_log
602
        call  setmouse
603
        call  setmouse
603
 
604
 
604
        mov  [pci_access_enabled],1
605
        mov  [pci_access_enabled],1
605
 
606
 
606
; SET PRELIMINARY WINDOW STACK AND POSITIONS
607
; SET PRELIMINARY WINDOW STACK AND POSITIONS
607
 
608
 
608
        mov   esi,boot_windefs
609
        mov   esi,boot_windefs
609
        call  boot_log
610
        call  boot_log
610
        call  setwindowdefaults
611
        call  setwindowdefaults
611
 
612
 
612
; SET BACKGROUND DEFAULTS
613
; SET BACKGROUND DEFAULTS
613
 
614
 
614
        mov   esi,boot_bgr
615
        mov   esi,boot_bgr
615
        call  boot_log
616
        call  boot_log
616
        call  calculatebackground
617
        call  calculatebackground
617
 
618
 
618
; RESERVE SYSTEM IRQ'S JA PORT'S
619
; RESERVE SYSTEM IRQ'S JA PORT'S
619
 
620
 
620
        mov   esi,boot_resirqports
621
        mov   esi,boot_resirqports
621
        call  boot_log
622
        call  boot_log
622
        call  reserve_irqs_ports
623
        call  reserve_irqs_ports
623
 
624
 
624
; SET PORTS FOR IRQ HANDLERS
625
; SET PORTS FOR IRQ HANDLERS
625
 
626
 
626
        mov  esi,boot_setrports
627
        mov  esi,boot_setrports
627
        call boot_log
628
        call boot_log
628
        call setirqreadports
629
        call setirqreadports
629
 
630
 
630
; SET UP OS TASK
631
; SET UP OS TASK
631
 
632
 
632
        mov  esi,boot_setostask
633
        mov  esi,boot_setostask
633
        call boot_log
634
        call boot_log
634
 
635
 
635
        mov eax, fpu_data
636
        mov eax, fpu_data
636
        mov  dword [SLOT_BASE+APPDATA.fpu_state], eax
637
        mov  dword [SLOT_BASE+APPDATA.fpu_state], eax
637
        mov  dword [SLOT_BASE+APPDATA.fpu_handler], 0
638
        mov  dword [SLOT_BASE+APPDATA.fpu_handler], 0
638
        mov  dword [SLOT_BASE+APPDATA.sse_handler], 0
639
        mov  dword [SLOT_BASE+APPDATA.sse_handler], 0
639
 
640
 
640
        ; name for OS/IDLE process
641
        ; name for OS/IDLE process
641
 
642
 
642
        mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
643
        mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
643
        mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
644
        mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
644
        mov edi, [os_stack_seg]
645
        mov edi, [os_stack_seg]
645
        mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
646
        mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
646
        add edi, 0x2000-512
647
        add edi, 0x2000-512
647
        mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
648
        mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
648
        mov dword [SLOT_BASE+256+APPDATA.io_map],\
649
        mov dword [SLOT_BASE+256+APPDATA.io_map],\
649
                  (tss._io_map_0-OS_BASE+PG_MAP)
650
                  (tss._io_map_0-OS_BASE+PG_MAP)
650
        mov dword [SLOT_BASE+256+APPDATA.io_map+4],\
651
        mov dword [SLOT_BASE+256+APPDATA.io_map+4],\
651
                  (tss._io_map_1-OS_BASE+PG_MAP)
652
                  (tss._io_map_1-OS_BASE+PG_MAP)
652
 
653
 
653
        mov esi, fpu_data
654
        mov esi, fpu_data
654
        mov ecx, 512/4
655
        mov ecx, 512/4
655
        cld
656
        cld
656
        rep movsd
657
        rep movsd
657
 
658
 
658
        mov dword [SLOT_BASE+256+APPDATA.fpu_handler], 0
659
        mov dword [SLOT_BASE+256+APPDATA.fpu_handler], 0
659
        mov dword [SLOT_BASE+256+APPDATA.sse_handler], 0
660
        mov dword [SLOT_BASE+256+APPDATA.sse_handler], 0
660
        mov dword [SLOT_BASE+256+APPDATA.cursor], ebx
661
        mov dword [SLOT_BASE+256+APPDATA.cursor], ebx
661
 
662
 
662
        mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
663
        mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
663
        mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
664
        mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
664
        mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
665
        mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
665
 
666
 
666
        ; task list
667
        ; task list
667
        mov  [CURRENT_TASK],dword 1
668
        mov  [CURRENT_TASK],dword 1
668
        mov  [TASK_COUNT],dword 1
669
        mov  [TASK_COUNT],dword 1
669
        mov  [current_slot], SLOT_BASE+256
670
        mov  [current_slot], SLOT_BASE+256
670
        mov  [TASK_BASE],dword TASK_DATA
671
        mov  [TASK_BASE],dword TASK_DATA
671
        mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
672
        mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
672
        mov  [TASK_DATA+TASKDATA.pid], 1        ; process id number
673
        mov  [TASK_DATA+TASKDATA.pid], 1        ; process id number
673
        mov  [TASK_DATA+TASKDATA.mem_start], 0  ; process base address
674
        mov  [TASK_DATA+TASKDATA.mem_start], 0  ; process base address
674
 
675
 
675
        call init_cursors
676
        call init_cursors
676
        mov eax, [def_cursor]
677
        mov eax, [def_cursor]
677
        mov [SLOT_BASE+APPDATA.cursor],eax
678
        mov [SLOT_BASE+APPDATA.cursor],eax
678
        mov [SLOT_BASE+APPDATA.cursor+256],eax
679
        mov [SLOT_BASE+APPDATA.cursor+256],eax
679
 
680
 
680
  ; READ TSC / SECOND
681
  ; READ TSC / SECOND
681
 
682
 
682
        mov   esi,boot_tsc
683
        mov   esi,boot_tsc
683
        call  boot_log
684
        call  boot_log
684
        call  _rdtsc
685
        call  _rdtsc
685
        mov   ecx,eax
686
        mov   ecx,eax
686
        mov   esi,250               ; wait 1/4 a second
687
        mov   esi,250               ; wait 1/4 a second
687
        call  delay_ms
688
        call  delay_ms
688
        call  _rdtsc
689
        call  _rdtsc
689
        sub   eax,ecx
690
        sub   eax,ecx
690
        shl   eax,2
691
        shl   eax,2
691
        mov   [CPU_FREQ],eax          ; save tsc / sec
692
        mov   [CPU_FREQ],eax          ; save tsc / sec
692
        mov ebx, 1000000
693
        mov ebx, 1000000
693
        div ebx
694
        div ebx
694
        mov [stall_mcs], eax
695
        mov [stall_mcs], eax
695
 
696
 
696
; SET VARIABLES
697
; SET VARIABLES
697
 
698
 
698
        call  set_variables
699
        call  set_variables
699
 
700
 
700
; STACK AND FDC
701
; STACK AND FDC
701
 
702
 
702
        call  stack_init
703
        call  stack_init
703
        call  fdc_init
704
        call  fdc_init
704
 
705
 
705
; PALETTE FOR 320x200 and 640x480 16 col
706
; PALETTE FOR 320x200 and 640x480 16 col
706
 
707
 
707
        cmp   [SCR_MODE],word 0x12
708
        cmp   [SCR_MODE],word 0x12
708
        jne   no_pal_vga
709
        jne   no_pal_vga
709
        mov   esi,boot_pal_vga
710
        mov   esi,boot_pal_vga
710
        call  boot_log
711
        call  boot_log
711
        call  paletteVGA
712
        call  paletteVGA
712
      no_pal_vga:
713
      no_pal_vga:
713
 
714
 
714
        cmp   [SCR_MODE],word 0x13
715
        cmp   [SCR_MODE],word 0x13
715
        jne   no_pal_ega
716
        jne   no_pal_ega
716
        mov   esi,boot_pal_ega
717
        mov   esi,boot_pal_ega
717
        call  boot_log
718
        call  boot_log
718
        call  palette320x200
719
        call  palette320x200
719
      no_pal_ega:
720
      no_pal_ega:
720
 
721
 
721
; LOAD DEFAULT SKIN
722
; LOAD DEFAULT SKIN
722
 
723
 
723
        mov     esi,_skin_file_default
724
        mov     esi,_skin_file_default
724
        mov     edi,_skin_file
725
        mov     edi,_skin_file
725
        movsd
726
        movsd
726
        movsd
727
        movsd
727
        movsd
728
        movsd
728
        call    load_skin
729
        call    load_skin
729
 
730
 
730
;protect io permission map
731
;protect io permission map
731
 
732
 
732
           mov esi, [default_io_map]
733
           mov esi, [default_io_map]
733
           stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
734
           stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
734
           add esi, 0x1000
735
           add esi, 0x1000
735
           stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
736
           stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
736
 
737
 
737
           stdcall map_page,tss._io_map_0,\
738
           stdcall map_page,tss._io_map_0,\
738
                   (tss._io_map_0-OS_BASE), PG_MAP
739
                   (tss._io_map_0-OS_BASE), PG_MAP
739
           stdcall map_page,tss._io_map_1,\
740
           stdcall map_page,tss._io_map_1,\
740
                   (tss._io_map_1-OS_BASE), PG_MAP
741
                   (tss._io_map_1-OS_BASE), PG_MAP
741
 
742
 
742
; LOAD FIRST APPLICATION
743
; LOAD FIRST APPLICATION
743
        cli
744
        cli
744
        cmp   byte [BOOT_VAR+0x9030],1
745
        cmp   byte [BOOT_VAR+0x9030],1
745
        jne   no_load_vrr_m
746
        jne   no_load_vrr_m
746
 
747
 
747
        mov ebp, vrr_m
748
        mov ebp, vrr_m
748
        xor ebx, ebx
749
        xor ebx, ebx
749
        xor edx, edx
750
        xor edx, edx
750
        call fs_execute
751
        call fs_execute
751
        cmp   eax,2                  ; if vrr_m app found (PID=2)
752
        cmp   eax,2                  ; if vrr_m app found (PID=2)
752
        je    first_app_found
753
        je    first_app_found
753
 
754
 
754
no_load_vrr_m:
755
no_load_vrr_m:
755
        mov ebp, firstapp
756
        mov ebp, firstapp
756
        xor ebx, ebx
757
        xor ebx, ebx
757
        xor edx, edx
758
        xor edx, edx
758
        call fs_execute
759
        call fs_execute
759
        cmp   eax,2                  ; continue if a process has been loaded
760
        cmp   eax,2                  ; continue if a process has been loaded
760
        je    first_app_found
761
        je    first_app_found
761
        mov   eax, 0xDEADBEEF        ; otherwise halt
762
        mov   eax, 0xDEADBEEF        ; otherwise halt
762
        hlt
763
        hlt
763
first_app_found:
764
first_app_found:
764
        cli
765
        cli
765
 
766
 
766
        ;mov   [TASK_COUNT],dword 2
767
        ;mov   [TASK_COUNT],dword 2
767
        mov   [CURRENT_TASK],dword 1       ; set OS task fisrt
768
        mov   [CURRENT_TASK],dword 1       ; set OS task fisrt
768
 
769
 
769
; SET KEYBOARD PARAMETERS
770
; SET KEYBOARD PARAMETERS
770
        mov   al, 0xf6         ; reset keyboard, scan enabled
771
        mov   al, 0xf6         ; reset keyboard, scan enabled
771
        call  kb_write
772
        call  kb_write
772
 
773
 
773
        ; wait until 8042 is ready
774
        ; wait until 8042 is ready
774
        xor ecx,ecx
775
        xor ecx,ecx
775
      @@:
776
      @@:
776
        in     al,64h
777
        in     al,64h
777
        and    al,00000010b
778
        and    al,00000010b
778
        loopnz @b
779
        loopnz @b
779
 
780
 
780
       ; mov   al, 0xED       ; svetodiody - only for testing!
781
       ; mov   al, 0xED       ; svetodiody - only for testing!
781
       ; call  kb_write
782
       ; call  kb_write
782
       ; call  kb_read
783
       ; call  kb_read
783
       ; mov   al, 111b
784
       ; mov   al, 111b
784
       ; call  kb_write
785
       ; call  kb_write
785
       ; call  kb_read
786
       ; call  kb_read
786
 
787
 
787
        mov   al, 0xF3       ; set repeat rate & delay
788
        mov   al, 0xF3       ; set repeat rate & delay
788
        call  kb_write
789
        call  kb_write
789
;        call  kb_read
790
;        call  kb_read
790
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
791
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
791
        call  kb_write
792
        call  kb_write
792
;        call  kb_read
793
;        call  kb_read
793
     ;// mike.dld [
794
     ;// mike.dld [
794
        call  set_lights
795
        call  set_lights
795
     ;// mike.dld ]
796
     ;// mike.dld ]
796
 
797
 
797
; START MULTITASKING
798
; START MULTITASKING
798
 
799
 
799
        mov   esi,boot_tasking
800
        mov   esi,boot_tasking
800
        call  boot_log
801
        call  boot_log
801
 
802
 
802
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
803
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
803
 
804
 
804
; UNMASK ALL IRQ'S
805
; UNMASK ALL IRQ'S
805
 
806
 
806
        mov   esi,boot_allirqs
807
        mov   esi,boot_allirqs
807
        call  boot_log
808
        call  boot_log
808
 
809
 
809
        cli                          ;guarantee forbidance of interrupts.
810
        cli                          ;guarantee forbidance of interrupts.
810
        mov   al,0                   ; unmask all irq's
811
        mov   al,0                   ; unmask all irq's
811
        out   0xA1,al
812
        out   0xA1,al
812
        out   0x21,al
813
        out   0x21,al
813
 
814
 
814
        mov   ecx,32
815
        mov   ecx,32
815
 
816
 
816
     ready_for_irqs:
817
     ready_for_irqs:
817
 
818
 
818
        mov   al,0x20                ; ready for irqs
819
        mov   al,0x20                ; ready for irqs
819
        out   0x20,al
820
        out   0x20,al
820
        out   0xa0,al
821
        out   0xa0,al
821
 
822
 
822
        loop  ready_for_irqs         ; flush the queue
823
        loop  ready_for_irqs         ; flush the queue
823
 
824
 
824
        stdcall attach_int_handler, dword 1, irq1
825
        stdcall attach_int_handler, dword 1, irq1
825
 
826
 
826
;        mov    [dma_hdd],1
827
;        mov    [dma_hdd],1
827
        cmp     [IDEContrRegsBaseAddr], 0
828
        cmp     [IDEContrRegsBaseAddr], 0
828
        setnz   [dma_hdd]
829
        setnz   [dma_hdd]
829
 
830
 
830
;        stdcall init_uart_service, DRV_ENTRY
831
;        stdcall init_uart_service, DRV_ENTRY
831
 
832
 
832
        sti
833
        sti
833
        call change_task
834
        call change_task
834
 
835
 
835
        jmp osloop
836
        jmp osloop
836
 
837
 
837
        jmp   $                      ; wait here for timer to take control
838
        jmp   $                      ; wait here for timer to take control
838
 
839
 
839
        ; Fly :)
840
        ; Fly :)
840
 
841
 
841
include 'unpacker.inc'
842
include 'unpacker.inc'
842
include 'fdo.inc'
843
include 'fdo.inc'
843
 
844
 
844
align 4
845
align 4
845
boot_log:
846
boot_log:
846
         pushad
847
         pushad
847
 
848
 
848
         mov   eax,10*65536
849
         mov   eax,10*65536
849
         mov   ax,word [boot_y]
850
         mov   ax,word [boot_y]
850
         add   [boot_y],dword 10
851
         add   [boot_y],dword 10
851
         mov   ebx,0x80ffffff   ; ASCIIZ string with white color
852
         mov   ebx,0x80ffffff   ; ASCIIZ string with white color
852
         mov   ecx,esi
853
         mov   ecx,esi
853
         mov   edi,1
854
         mov   edi,1
854
         call  dtext
855
         call  dtext
855
 
856
 
856
         mov   [novesachecksum],1000
857
         mov   [novesachecksum],1000
857
         call  checkVga_N13
858
         call  checkVga_N13
858
 
859
 
859
         cmp   [preboot_blogesc+OS_BASE+0x10000],byte 1
860
         cmp   [preboot_blogesc+OS_BASE+0x10000],byte 1
860
         je    .bll2
861
         je    .bll2
861
 
862
 
862
         cmp   esi,boot_tasking
863
         cmp   esi,boot_tasking
863
         jne   .bll2
864
         jne   .bll2
864
         ; begin ealex 04.08.05
865
         ; begin ealex 04.08.05
865
;         in    al,0x61
866
;         in    al,0x61
866
;         and   al,01111111b
867
;         and   al,01111111b
867
;         out   0x61,al
868
;         out   0x61,al
868
         ; end ealex 04.08.05
869
         ; end ealex 04.08.05
869
.bll1:   in    al,0x60    ; wait for ESC key press
870
.bll1:   in    al,0x60    ; wait for ESC key press
870
         cmp   al,129
871
         cmp   al,129
871
         jne   .bll1
872
         jne   .bll1
872
 
873
 
873
.bll2:   popad
874
.bll2:   popad
874
 
875
 
875
         ret
876
         ret
876
 
877
 
877
 
878
 
878
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
879
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
879
;                                                                    ;
880
;                                                                    ;
880
;                    MAIN OS LOOP START                              ;
881
;                    MAIN OS LOOP START                              ;
881
;                                                                    ;
882
;                                                                    ;
882
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
883
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
883
align 32
884
align 32
884
osloop:
885
osloop:
885
        call   [draw_pointer]
886
        call   [draw_pointer]
886
        call   checkbuttons
887
        call   checkbuttons
887
        call   checkwindows
888
        call   checkwindows
888
;       call   check_window_move_request
889
;       call   check_window_move_request
889
        call   checkmisc
890
        call   checkmisc
890
        call   checkVga_N13
891
        call   checkVga_N13
891
        call   stack_handler
892
        call   stack_handler
892
        call   checkidle
893
        call   checkidle
893
        call   check_fdd_motor_status
894
        call   check_fdd_motor_status
894
        jmp    osloop
895
        jmp    osloop
895
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
896
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
896
;                                                                    ;
897
;                                                                    ;
897
;                      MAIN OS LOOP END                              ;
898
;                      MAIN OS LOOP END                              ;
898
;                                                                    ;
899
;                                                                    ;
899
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
900
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
900
 
901
 
901
checkidle:
902
checkidle:
902
        pushad
903
        pushad
903
 
904
 
904
        cmp  [check_idle_semaphore],0
905
        cmp  [check_idle_semaphore],0
905
        jne  no_idle_state
906
        jne  no_idle_state
906
 
907
 
907
        call change_task
908
        call change_task
908
        mov  eax,[idlemem]
909
        mov  eax,[idlemem]
909
        mov  ebx,[timer_ticks] ;[0xfdf0]
910
        mov  ebx,[timer_ticks] ;[0xfdf0]
910
        cmp  eax,ebx
911
        cmp  eax,ebx
911
        jnz  idle_exit
912
        jnz  idle_exit
912
        call _rdtsc
913
        call _rdtsc
913
        mov  ecx,eax
914
        mov  ecx,eax
914
      idle_loop:
915
      idle_loop:
915
        hlt
916
        hlt
916
        cmp  [check_idle_semaphore],0
917
        cmp  [check_idle_semaphore],0
917
        jne  idle_loop_exit
918
        jne  idle_loop_exit
918
        mov  eax,[timer_ticks] ;[0xfdf0]
919
        mov  eax,[timer_ticks] ;[0xfdf0]
919
        cmp  ebx,eax
920
        cmp  ebx,eax
920
        jz   idle_loop
921
        jz   idle_loop
921
      idle_loop_exit:
922
      idle_loop_exit:
922
        mov  [idlemem],eax
923
        mov  [idlemem],eax
923
        call _rdtsc
924
        call _rdtsc
924
        sub  eax,ecx
925
        sub  eax,ecx
925
        mov  ebx,[idleuse]
926
        mov  ebx,[idleuse]
926
        add  ebx,eax
927
        add  ebx,eax
927
        mov  [idleuse],ebx
928
        mov  [idleuse],ebx
928
 
929
 
929
        popad
930
        popad
930
        ret
931
        ret
931
 
932
 
932
      idle_exit:
933
      idle_exit:
933
 
934
 
934
        mov  ebx,[timer_ticks] ;[0xfdf0]
935
        mov  ebx,[timer_ticks] ;[0xfdf0]
935
        mov  [idlemem],ebx
936
        mov  [idlemem],ebx
936
        call change_task
937
        call change_task
937
 
938
 
938
        popad
939
        popad
939
        ret
940
        ret
940
 
941
 
941
      no_idle_state:
942
      no_idle_state:
942
 
943
 
943
        dec  [check_idle_semaphore]
944
        dec  [check_idle_semaphore]
944
 
945
 
945
        mov  ebx,[timer_ticks] ;[0xfdf0]
946
        mov  ebx,[timer_ticks] ;[0xfdf0]
946
        mov  [idlemem],ebx
947
        mov  [idlemem],ebx
947
        call change_task
948
        call change_task
948
 
949
 
949
        popad
950
        popad
950
        ret
951
        ret
951
 
952
 
952
uglobal
953
uglobal
953
  idlemem               dd   0x0
954
  idlemem               dd   0x0
954
  idleuse               dd   0x0
955
  idleuse               dd   0x0
955
  idleusesec            dd   0x0
956
  idleusesec            dd   0x0
956
  check_idle_semaphore  dd   0x0
957
  check_idle_semaphore  dd   0x0
957
endg
958
endg
958
 
959
 
959
 
960
 
960
 
961
 
961
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
962
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
962
;                                                                      ;
963
;                                                                      ;
963
;                   INCLUDED SYSTEM FILES                              ;
964
;                   INCLUDED SYSTEM FILES                              ;
964
;                                                                      ;
965
;                                                                      ;
965
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
966
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
966
 
967
 
967
 
968
 
968
include "kernel32.inc"
969
include "kernel32.inc"
969
 
970
 
970
 
971
 
971
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
972
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
972
;                                                                      ;
973
;                                                                      ;
973
;                       KERNEL FUNCTIONS                               ;
974
;                       KERNEL FUNCTIONS                               ;
974
;                                                                      ;
975
;                                                                      ;
975
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
976
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
976
 
977
 
977
reserve_irqs_ports:
978
reserve_irqs_ports:
978
 
979
 
979
        pushad
980
        pushad
980
 
981
 
981
        mov  [irq_owner+4*0], 1    ; timer
982
        mov  [irq_owner+4*0], 1    ; timer
982
        mov  [irq_owner+4*1], 1    ; keyboard
983
        mov  [irq_owner+4*1], 1    ; keyboard
983
        mov  [irq_owner+4*5], 1    ; sound blaster
984
        mov  [irq_owner+4*5], 1    ; sound blaster
984
        mov  [irq_owner+4*6], 1    ; floppy diskette
985
        mov  [irq_owner+4*6], 1    ; floppy diskette
985
        mov  [irq_owner+4*13], 1   ; math co-pros
986
        mov  [irq_owner+4*13], 1   ; math co-pros
986
        mov  [irq_owner+4*14], 1   ; ide I
987
        mov  [irq_owner+4*14], 1   ; ide I
987
        mov  [irq_owner+4*15], 1   ; ide II
988
        mov  [irq_owner+4*15], 1   ; ide II
988
 
989
 
989
;        movzx eax,byte [0xf604]        ; mouse irq
990
;        movzx eax,byte [0xf604]        ; mouse irq
990
;        dec   eax
991
;        dec   eax
991
;        add   eax,mouseirqtable
992
;        add   eax,mouseirqtable
992
;        movzx eax,byte [eax]
993
;        movzx eax,byte [eax]
993
;        shl   eax,2
994
;        shl   eax,2
994
;        mov   [irq_owner+eax],byte 1
995
;        mov   [irq_owner+eax],byte 1
995
 
996
 
996
 
997
 
997
                                       ; RESERVE PORTS
998
                                       ; RESERVE PORTS
998
        mov   edi,1                    ; 0x00-0x2d
999
        mov   edi,1                    ; 0x00-0x2d
999
        mov   [RESERVED_PORTS],edi
1000
        mov   [RESERVED_PORTS],edi
1000
        shl   edi,4
1001
        shl   edi,4
1001
        mov   [RESERVED_PORTS+edi+0],dword 1
1002
        mov   [RESERVED_PORTS+edi+0],dword 1
1002
        mov   [RESERVED_PORTS+edi+4],dword 0x0
1003
        mov   [RESERVED_PORTS+edi+4],dword 0x0
1003
        mov   [RESERVED_PORTS+edi+8],dword 0x2d
1004
        mov   [RESERVED_PORTS+edi+8],dword 0x2d
1004
 
1005
 
1005
        inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
1006
        inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
1006
        mov   edi,[RESERVED_PORTS]
1007
        mov   edi,[RESERVED_PORTS]
1007
        shl   edi,4
1008
        shl   edi,4
1008
        mov   [RESERVED_PORTS+edi+0],dword 1
1009
        mov   [RESERVED_PORTS+edi+0],dword 1
1009
        mov   [RESERVED_PORTS+edi+4],dword 0x30
1010
        mov   [RESERVED_PORTS+edi+4],dword 0x30
1010
        mov   [RESERVED_PORTS+edi+8],dword 0x4d
1011
        mov   [RESERVED_PORTS+edi+8],dword 0x4d
1011
 
1012
 
1012
        inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
1013
        inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
1013
        mov   edi,[RESERVED_PORTS]
1014
        mov   edi,[RESERVED_PORTS]
1014
        shl   edi,4
1015
        shl   edi,4
1015
        mov   [RESERVED_PORTS+edi+0],dword 1
1016
        mov   [RESERVED_PORTS+edi+0],dword 1
1016
        mov   [RESERVED_PORTS+edi+4],dword 0x50
1017
        mov   [RESERVED_PORTS+edi+4],dword 0x50
1017
        mov   [RESERVED_PORTS+edi+8],dword 0xdf
1018
        mov   [RESERVED_PORTS+edi+8],dword 0xdf
1018
 
1019
 
1019
        inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
1020
        inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
1020
        mov   edi,[RESERVED_PORTS]
1021
        mov   edi,[RESERVED_PORTS]
1021
        shl   edi,4
1022
        shl   edi,4
1022
        mov   [RESERVED_PORTS+edi+0],dword 1
1023
        mov   [RESERVED_PORTS+edi+0],dword 1
1023
        mov   [RESERVED_PORTS+edi+4],dword 0xe5
1024
        mov   [RESERVED_PORTS+edi+4],dword 0xe5
1024
        mov   [RESERVED_PORTS+edi+8],dword 0xff
1025
        mov   [RESERVED_PORTS+edi+8],dword 0xff
1025
 
1026
 
1026
 
1027
 
1027
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
1028
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
1028
;        jne   ripl1
1029
;        jne   ripl1
1029
;        inc   dword [0x2d0000]
1030
;        inc   dword [0x2d0000]
1030
;        mov   edi,[0x2d0000]
1031
;        mov   edi,[0x2d0000]
1031
;        shl   edi,4
1032
;        shl   edi,4
1032
;        mov   [0x2d0000+edi+0],dword 1
1033
;        mov   [0x2d0000+edi+0],dword 1
1033
;        mov   [0x2d0000+edi+4],dword 0x3f0
1034
;        mov   [0x2d0000+edi+4],dword 0x3f0
1034
;        mov   [0x2d0000+edi+8],dword 0x3ff
1035
;        mov   [0x2d0000+edi+8],dword 0x3ff
1035
;      ripl1:
1036
;      ripl1:
1036
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
1037
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
1037
;        jne   ripl2
1038
;        jne   ripl2
1038
;        inc   dword [0x2d0000]
1039
;        inc   dword [0x2d0000]
1039
;        mov   edi,[0x2d0000]
1040
;        mov   edi,[0x2d0000]
1040
;        shl   edi,4
1041
;        shl   edi,4
1041
;        mov   [0x2d0000+edi+0],dword 1
1042
;        mov   [0x2d0000+edi+0],dword 1
1042
;        mov   [0x2d0000+edi+4],dword 0x2f0
1043
;        mov   [0x2d0000+edi+4],dword 0x2f0
1043
;        mov   [0x2d0000+edi+8],dword 0x2ff
1044
;        mov   [0x2d0000+edi+8],dword 0x2ff
1044
;      ripl2:
1045
;      ripl2:
1045
 
1046
 
1046
        popad
1047
        popad
1047
        ret
1048
        ret
1048
 
1049
 
1049
iglobal
1050
iglobal
1050
mouseirqtable   db  12    ; ps2
1051
mouseirqtable   db  12    ; ps2
1051
                db  4     ; com1
1052
                db  4     ; com1
1052
                db  3     ; com2
1053
                db  3     ; com2
1053
endg
1054
endg
1054
 
1055
 
1055
setirqreadports:
1056
setirqreadports:
1056
 
1057
 
1057
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1058
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1058
        mov   [irq12read+4],dword 0                  ; end of port list
1059
        mov   [irq12read+4],dword 0                  ; end of port list
1059
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1060
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1060
        mov   [irq04read+4],dword 0                  ; end of port list
1061
        mov   [irq04read+4],dword 0                  ; end of port list
1061
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1062
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1062
        mov   [irq03read+4],dword 0                  ; end of port list
1063
        mov   [irq03read+4],dword 0                  ; end of port list
1063
 
1064
 
1064
        ret
1065
        ret
1065
 
1066
 
1066
iglobal
1067
iglobal
1067
  process_number dd 0x1
1068
  process_number dd 0x1
1068
endg
1069
endg
1069
 
1070
 
1070
set_variables:
1071
set_variables:
1071
 
1072
 
1072
        mov   ecx,0x100                       ; flush port 0x60
1073
        mov   ecx,0x100                       ; flush port 0x60
1073
.fl60:  in    al,0x60
1074
.fl60:  in    al,0x60
1074
        loop  .fl60
1075
        loop  .fl60
1075
        mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
1076
        mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
1076
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
1077
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
1077
        mov   [BTN_COUNT],byte 0                 ; button buffer
1078
        mov   [BTN_COUNT],byte 0                 ; button buffer
1078
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1079
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1079
 
1080
 
1080
        push  eax
1081
        push  eax
1081
        mov   ax,[BOOT_VAR+0x900c]
1082
        mov   ax,[BOOT_VAR+0x900c]
1082
        shr   ax,1
1083
        shr   ax,1
1083
        shl   eax,16
1084
        shl   eax,16
1084
        mov   ax,[BOOT_VAR+0x900A]
1085
        mov   ax,[BOOT_VAR+0x900A]
1085
        shr   ax,1
1086
        shr   ax,1
1086
        mov   [MOUSE_X],eax
1087
        mov   [MOUSE_X],eax
1087
        pop   eax
1088
        pop   eax
1088
 
1089
 
1089
        mov   byte [SB16_Status],0            ; Minazzi Paolo
1090
        mov   byte [SB16_Status],0            ; Minazzi Paolo
1090
        mov   [display_data-12],dword 1       ; tiled background
1091
        mov   [display_data-12],dword 1       ; tiled background
1091
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1092
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1092
 
1093
 
1093
     ;!! IP 04.02.2005:
1094
     ;!! IP 04.02.2005:
1094
        mov   [next_usage_update], 100
1095
        mov   [next_usage_update], 100
1095
        mov   byte [DONT_SWITCH], 0 ; change task if possible
1096
        mov   byte [DONT_SWITCH], 0 ; change task if possible
1096
 
1097
 
1097
        ret
1098
        ret
1098
 
1099
 
1099
;* mouse centered - start code- Mario79
1100
;* mouse centered - start code- Mario79
1100
mouse_centered:
1101
mouse_centered:
1101
        push  eax
1102
        push  eax
1102
        mov   eax,[ScreenWidth]
1103
        mov   eax,[ScreenWidth]
1103
        shr   eax,1
1104
        shr   eax,1
1104
        mov   [MOUSE_X],ax
1105
        mov   [MOUSE_X],ax
1105
        mov   eax,[ScreenHeight]
1106
        mov   eax,[ScreenHeight]
1106
        shr   eax,1
1107
        shr   eax,1
1107
        mov   [MOUSE_Y],ax
1108
        mov   [MOUSE_Y],ax
1108
        pop   eax
1109
        pop   eax
1109
        ret
1110
        ret
1110
;* mouse centered - end code- Mario79
1111
;* mouse centered - end code- Mario79
1111
 
1112
 
1112
align 4
1113
align 4
1113
 
1114
 
1114
sys_outport:
1115
sys_outport:
1115
 
1116
 
1116
    mov   edi,ebx          ; separate flag for read / write
1117
    mov   edi,ebx          ; separate flag for read / write
1117
    and   ebx,65535
1118
    and   ebx,65535
1118
 
1119
 
1119
    mov   ecx,[RESERVED_PORTS]
1120
    mov   ecx,[RESERVED_PORTS]
1120
    test  ecx,ecx
1121
    test  ecx,ecx
1121
    jne   sopl8
1122
    jne   sopl8
1122
    mov   [esp+36],dword 1
1123
    mov   [esp+36],dword 1
1123
    ret
1124
    ret
1124
 
1125
 
1125
  sopl8:
1126
  sopl8:
1126
    mov   edx,[TASK_BASE]
1127
    mov   edx,[TASK_BASE]
1127
    mov   edx,[edx+0x4]
1128
    mov   edx,[edx+0x4]
1128
    and   ebx,65535
1129
    and   ebx,65535
1129
    cld
1130
    cld
1130
  sopl1:
1131
  sopl1:
1131
 
1132
 
1132
    mov   esi,ecx
1133
    mov   esi,ecx
1133
    shl   esi,4
1134
    shl   esi,4
1134
    add   esi,RESERVED_PORTS
1135
    add   esi,RESERVED_PORTS
1135
    cmp   edx,[esi+0]
1136
    cmp   edx,[esi+0]
1136
    jne   sopl2
1137
    jne   sopl2
1137
    cmp   ebx,[esi+4]
1138
    cmp   ebx,[esi+4]
1138
    jb    sopl2
1139
    jb    sopl2
1139
    cmp   ebx,[esi+8]
1140
    cmp   ebx,[esi+8]
1140
    jg    sopl2
1141
    jg    sopl2
1141
    jmp   sopl3
1142
    jmp   sopl3
1142
 
1143
 
1143
  sopl2:
1144
  sopl2:
1144
 
1145
 
1145
    dec   ecx
1146
    dec   ecx
1146
    jnz   sopl1
1147
    jnz   sopl1
1147
    mov   [esp+36],dword 1
1148
    mov   [esp+36],dword 1
1148
    ret
1149
    ret
1149
 
1150
 
1150
  sopl3:
1151
  sopl3:
1151
 
1152
 
1152
    test  edi,0x80000000 ; read ?
1153
    test  edi,0x80000000 ; read ?
1153
    jnz   sopl4
1154
    jnz   sopl4
1154
 
1155
 
1155
    mov   dx,bx          ; write
1156
    mov   dx,bx          ; write
1156
    out   dx,al
1157
    out   dx,al
1157
    mov   [esp+36],dword 0
1158
    mov   [esp+36],dword 0
1158
    ret
1159
    ret
1159
 
1160
 
1160
  sopl4:
1161
  sopl4:
1161
 
1162
 
1162
    mov   dx,bx          ; read
1163
    mov   dx,bx          ; read
1163
    in    al,dx
1164
    in    al,dx
1164
    and   eax,0xff
1165
    and   eax,0xff
1165
    mov   [esp+36],dword 0
1166
    mov   [esp+36],dword 0
1166
    mov   [esp+24],eax
1167
    mov   [esp+24],eax
1167
    ret
1168
    ret
1168
 
1169
 
1169
 
1170
 
1170
 
1171
 
1171
align 4
1172
align 4
1172
sys_sb16:
1173
sys_sb16:
1173
 
1174
 
1174
     cmp  word [sb16],word 0
1175
     cmp  word [sb16],word 0
1175
     jnz  sb16l1
1176
     jnz  sb16l1
1176
     mov  [esp+36],dword 1
1177
     mov  [esp+36],dword 1
1177
     ret
1178
     ret
1178
   sb16l1:
1179
   sb16l1:
1179
     mov  [esp+36],dword 0
1180
     mov  [esp+36],dword 0
1180
     cmp  eax,1    ; set volume - main
1181
     cmp  eax,1    ; set volume - main
1181
     jnz  sb16l2
1182
     jnz  sb16l2
1182
     mov  dx,word [sb16]
1183
     mov  dx,word [sb16]
1183
     add  dx,4
1184
     add  dx,4
1184
     mov  al,0x22
1185
     mov  al,0x22
1185
     out  dx,al
1186
     out  dx,al
1186
     mov  esi,1
1187
     mov  esi,1
1187
     call delay_ms
1188
     call delay_ms
1188
     mov  eax,ebx
1189
     mov  eax,ebx
1189
     inc  edx
1190
     inc  edx
1190
     out  dx,al
1191
     out  dx,al
1191
     ret
1192
     ret
1192
   sb16l2:
1193
   sb16l2:
1193
 
1194
 
1194
     cmp  eax,2    ; set volume - cd
1195
     cmp  eax,2    ; set volume - cd
1195
     jnz  sb16l3
1196
     jnz  sb16l3
1196
     mov  dx,word [sb16]
1197
     mov  dx,word [sb16]
1197
     add  dx,4
1198
     add  dx,4
1198
     mov  al,0x28
1199
     mov  al,0x28
1199
     out  dx,al
1200
     out  dx,al
1200
     mov  esi,1
1201
     mov  esi,1
1201
     call delay_ms
1202
     call delay_ms
1202
     mov  eax,ebx
1203
     mov  eax,ebx
1203
     add  edx,1
1204
     add  edx,1
1204
     out  dx,al
1205
     out  dx,al
1205
     ret
1206
     ret
1206
   sb16l3:
1207
   sb16l3:
1207
      mov  [esp+36],dword 2
1208
      mov  [esp+36],dword 2
1208
      ret
1209
      ret
1209
 
1210
 
1210
 
1211
 
1211
align 4
1212
align 4
1212
 
1213
 
1213
sys_sb16II:
1214
sys_sb16II:
1214
 
1215
 
1215
     cmp  word [sb16],word 0
1216
     cmp  word [sb16],word 0
1216
     jnz  IIsb16l1
1217
     jnz  IIsb16l1
1217
     mov  [esp+36],dword 1
1218
     mov  [esp+36],dword 1
1218
     ret
1219
     ret
1219
   IIsb16l1:
1220
   IIsb16l1:
1220
 
1221
 
1221
     cmp  eax,1    ; set volume - main
1222
     cmp  eax,1    ; set volume - main
1222
     jnz  IIsb16l2
1223
     jnz  IIsb16l2
1223
     ; L
1224
     ; L
1224
     mov  dx,word [sb16]
1225
     mov  dx,word [sb16]
1225
     add  dx,4
1226
     add  dx,4
1226
     mov  al,0x30
1227
     mov  al,0x30
1227
     out  dx,al
1228
     out  dx,al
1228
     mov  eax,ebx
1229
     mov  eax,ebx
1229
     inc  edx
1230
     inc  edx
1230
     out  dx,al
1231
     out  dx,al
1231
     ; R
1232
     ; R
1232
     mov  dx,word [sb16]
1233
     mov  dx,word [sb16]
1233
     add  dx,4
1234
     add  dx,4
1234
     mov  al,0x31
1235
     mov  al,0x31
1235
     out  dx,al
1236
     out  dx,al
1236
     mov  eax,ebx
1237
     mov  eax,ebx
1237
     inc  edx
1238
     inc  edx
1238
     out  dx,al
1239
     out  dx,al
1239
     mov  [esp+36],dword 0
1240
     mov  [esp+36],dword 0
1240
     ret
1241
     ret
1241
   IIsb16l2:
1242
   IIsb16l2:
1242
 
1243
 
1243
     cmp  eax,2    ; set volume - cd
1244
     cmp  eax,2    ; set volume - cd
1244
     jnz  IIsb16l3
1245
     jnz  IIsb16l3
1245
     ; L
1246
     ; L
1246
     mov  dx,word [sb16]
1247
     mov  dx,word [sb16]
1247
     add  dx,4
1248
     add  dx,4
1248
     mov  al,0x36
1249
     mov  al,0x36
1249
     out  dx,al
1250
     out  dx,al
1250
     mov  eax,ebx
1251
     mov  eax,ebx
1251
     inc  edx
1252
     inc  edx
1252
     out  dx,al
1253
     out  dx,al
1253
     ; R
1254
     ; R
1254
     mov  dx,word [sb16]
1255
     mov  dx,word [sb16]
1255
     add  dx,4
1256
     add  dx,4
1256
     mov  al,0x37
1257
     mov  al,0x37
1257
     out  dx,al
1258
     out  dx,al
1258
     mov  eax,ebx
1259
     mov  eax,ebx
1259
     inc  edx
1260
     inc  edx
1260
     out  dx,al
1261
     out  dx,al
1261
     mov  [esp+36],dword 0
1262
     mov  [esp+36],dword 0
1262
     ret
1263
     ret
1263
   IIsb16l3:
1264
   IIsb16l3:
1264
 
1265
 
1265
     mov  [esp+36],dword 2
1266
     mov  [esp+36],dword 2
1266
     ret
1267
     ret
1267
 
1268
 
1268
 
1269
 
1269
display_number:
1270
display_number:
1270
 
1271
 
1271
; eax = print type, al=0 -> ebx is number
1272
; eax = print type, al=0 -> ebx is number
1272
;                   al=1 -> ebx is pointer
1273
;                   al=1 -> ebx is pointer
1273
;                   ah=0 -> display decimal
1274
;                   ah=0 -> display decimal
1274
;                   ah=1 -> display hexadecimal
1275
;                   ah=1 -> display hexadecimal
1275
;                   ah=2 -> display binary
1276
;                   ah=2 -> display binary
1276
;                   eax bits 16-21 = number of digits to display (0-32)
1277
;                   eax bits 16-21 = number of digits to display (0-32)
1277
;                   eax bits 22-31 = reserved
1278
;                   eax bits 22-31 = reserved
1278
;
1279
;
1279
; ebx = number or pointer
1280
; ebx = number or pointer
1280
; ecx = x shl 16 + y
1281
; ecx = x shl 16 + y
1281
; edx = color
1282
; edx = color
1282
        xor     edi, edi
1283
        xor     edi, edi
1283
display_number_force:
1284
display_number_force:
1284
 
1285
 
1285
     cmp   eax,0xffff            ; length > 0 ?
1286
     cmp   eax,0xffff            ; length > 0 ?
1286
     jge   cont_displ
1287
     jge   cont_displ
1287
     ret
1288
     ret
1288
   cont_displ:
1289
   cont_displ:
1289
 
1290
 
1290
     cmp   eax,61*0x10000        ; length <= 60 ?
1291
     cmp   eax,61*0x10000        ; length <= 60 ?
1291
     jb    cont_displ2
1292
     jb    cont_displ2
1292
     ret
1293
     ret
1293
   cont_displ2:
1294
   cont_displ2:
1294
 
1295
 
1295
     pushad
1296
     pushad
1296
 
1297
 
1297
     cmp   al,1                  ; ecx is a pointer ?
1298
     cmp   al,1                  ; ecx is a pointer ?
1298
     jne   displnl1
1299
     jne   displnl1
1299
     mov   ebx,[ebx+std_application_base_address]
1300
     mov   ebx,[ebx+std_application_base_address]
1300
   displnl1:
1301
   displnl1:
1301
     sub   esp,64
1302
     sub   esp,64
1302
 
1303
 
1303
     cmp   ah,0                  ; DECIMAL
1304
     cmp   ah,0                  ; DECIMAL
1304
     jne   no_display_desnum
1305
     jne   no_display_desnum
1305
     shr   eax,16
1306
     shr   eax,16
1306
     and   eax,0x3f
1307
     and   eax,0x3f
1307
     push  eax
1308
     push  eax
1308
     mov   edi,esp
1309
     mov   edi,esp
1309
     add   edi,4+64-1
1310
     add   edi,4+64-1
1310
     mov   ecx,eax
1311
     mov   ecx,eax
1311
     mov   eax,ebx
1312
     mov   eax,ebx
1312
     mov   ebx,10
1313
     mov   ebx,10
1313
   d_desnum:
1314
   d_desnum:
1314
     xor   edx,edx
1315
     xor   edx,edx
1315
     div   ebx
1316
     div   ebx
1316
     add   dl,48
1317
     add   dl,48
1317
     mov   [edi],dl
1318
     mov   [edi],dl
1318
     dec   edi
1319
     dec   edi
1319
     loop  d_desnum
1320
     loop  d_desnum
1320
     pop   eax
1321
     pop   eax
1321
     call  draw_num_text
1322
     call  draw_num_text
1322
     add   esp,64
1323
     add   esp,64
1323
     popad
1324
     popad
1324
     ret
1325
     ret
1325
   no_display_desnum:
1326
   no_display_desnum:
1326
 
1327
 
1327
     cmp   ah,0x01               ; HEXADECIMAL
1328
     cmp   ah,0x01               ; HEXADECIMAL
1328
     jne   no_display_hexnum
1329
     jne   no_display_hexnum
1329
     shr   eax,16
1330
     shr   eax,16
1330
     and   eax,0x3f
1331
     and   eax,0x3f
1331
     push  eax
1332
     push  eax
1332
     mov   edi,esp
1333
     mov   edi,esp
1333
     add   edi,4+64-1
1334
     add   edi,4+64-1
1334
     mov   ecx,eax
1335
     mov   ecx,eax
1335
     mov   eax,ebx
1336
     mov   eax,ebx
1336
     mov   ebx,16
1337
     mov   ebx,16
1337
   d_hexnum:
1338
   d_hexnum:
1338
     xor   edx,edx
1339
     xor   edx,edx
1339
     div   ebx
1340
     div   ebx
1340
     add   edx,hexletters
1341
     add   edx,hexletters
1341
     mov   dl,[edx]
1342
     mov   dl,[edx]
1342
     mov   [edi],dl
1343
     mov   [edi],dl
1343
     dec   edi
1344
     dec   edi
1344
     loop  d_hexnum
1345
     loop  d_hexnum
1345
     pop   eax
1346
     pop   eax
1346
     call  draw_num_text
1347
     call  draw_num_text
1347
     add   esp,64
1348
     add   esp,64
1348
     popad
1349
     popad
1349
     ret
1350
     ret
1350
   no_display_hexnum:
1351
   no_display_hexnum:
1351
 
1352
 
1352
     cmp   ah,0x02               ; BINARY
1353
     cmp   ah,0x02               ; BINARY
1353
     jne   no_display_binnum
1354
     jne   no_display_binnum
1354
     shr   eax,16
1355
     shr   eax,16
1355
     and   eax,0x3f
1356
     and   eax,0x3f
1356
     push  eax
1357
     push  eax
1357
     mov   edi,esp
1358
     mov   edi,esp
1358
     add   edi,4+64-1
1359
     add   edi,4+64-1
1359
     mov   ecx,eax
1360
     mov   ecx,eax
1360
     mov   eax,ebx
1361
     mov   eax,ebx
1361
     mov   ebx,2
1362
     mov   ebx,2
1362
   d_binnum:
1363
   d_binnum:
1363
     xor   edx,edx
1364
     xor   edx,edx
1364
     div   ebx
1365
     div   ebx
1365
     add   dl,48
1366
     add   dl,48
1366
     mov   [edi],dl
1367
     mov   [edi],dl
1367
     dec   edi
1368
     dec   edi
1368
     loop  d_binnum
1369
     loop  d_binnum
1369
     pop   eax
1370
     pop   eax
1370
     call  draw_num_text
1371
     call  draw_num_text
1371
     add   esp,64
1372
     add   esp,64
1372
     popad
1373
     popad
1373
     ret
1374
     ret
1374
   no_display_binnum:
1375
   no_display_binnum:
1375
 
1376
 
1376
     add   esp,64
1377
     add   esp,64
1377
     popad
1378
     popad
1378
     ret
1379
     ret
1379
 
1380
 
1380
 
1381
 
1381
draw_num_text:
1382
draw_num_text:
1382
 
1383
 
1383
     ; dtext
1384
     ; dtext
1384
     ;
1385
     ;
1385
     ; eax x & y
1386
     ; eax x & y
1386
     ; ebx color
1387
     ; ebx color
1387
     ; ecx start of text
1388
     ; ecx start of text
1388
     ; edx length
1389
     ; edx length
1389
     ; edi 1 force
1390
     ; edi 1 force
1390
 
1391
 
1391
;        mov     edi,[CURRENT_TASK]
1392
;        mov     edi,[CURRENT_TASK]
1392
;        shl     edi,8
1393
;        shl     edi,8
1393
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1394
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1394
;        rol     eax,16
1395
;        rol     eax,16
1395
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1396
;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1396
;        rol     eax,16
1397
;        rol     eax,16
1397
 
1398
 
1398
     mov   edx,eax
1399
     mov   edx,eax
1399
     mov   ecx,64+4
1400
     mov   ecx,64+4
1400
     sub   ecx,eax
1401
     sub   ecx,eax
1401
     add   ecx,esp
1402
     add   ecx,esp
1402
     mov   eax,[esp+64+32-8+4]
1403
     mov   eax,[esp+64+32-8+4]
1403
     push  edx                       ; add window start x & y
1404
     push  edx                       ; add window start x & y
1404
     mov   edx,[TASK_BASE]
1405
     mov   edx,[TASK_BASE]
1405
 
1406
 
1406
     mov   edi,[CURRENT_TASK]
1407
     mov   edi,[CURRENT_TASK]
1407
     shl   edi,8
1408
     shl   edi,8
1408
 
1409
 
1409
     mov   ebx,[edx-twdw+WDATA.box.left]
1410
     mov   ebx,[edx-twdw+WDATA.box.left]
1410
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1411
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1411
     shl   ebx,16
1412
     shl   ebx,16
1412
     add   ebx,[edx-twdw+WDATA.box.top]
1413
     add   ebx,[edx-twdw+WDATA.box.top]
1413
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1414
     add   ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1414
     add   eax,ebx
1415
     add   eax,ebx
1415
     pop   edx
1416
     pop   edx
1416
     mov   ebx,[esp+64+32-12+4]
1417
     mov   ebx,[esp+64+32-12+4]
1417
        and     ebx, not 0x80000000     ; force counted string
1418
        and     ebx, not 0x80000000     ; force counted string
1418
        mov     esi, [esp+64+4+4]
1419
        mov     esi, [esp+64+4+4]
1419
        mov     edi, [esp+64+4]
1420
        mov     edi, [esp+64+4]
1420
     jmp   dtext
1421
     jmp   dtext
1421
 
1422
 
1422
read_string:
1423
read_string:
1423
 
1424
 
1424
    ; eax  read_area
1425
    ; eax  read_area
1425
    ; ebx  color of letter
1426
    ; ebx  color of letter
1426
    ; ecx  color of background
1427
    ; ecx  color of background
1427
    ; edx  number of letters to read
1428
    ; edx  number of letters to read
1428
    ; esi  [x start]*65536 + [y_start]
1429
    ; esi  [x start]*65536 + [y_start]
1429
 
1430
 
1430
    ret
1431
    ret
1431
 
1432
 
1432
 
1433
 
1433
align 4
1434
align 4
1434
 
1435
 
1435
sys_setup:
1436
sys_setup:
1436
 
1437
 
1437
; 1=roland mpu midi base , base io address
1438
; 1=roland mpu midi base , base io address
1438
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1439
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1439
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1440
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1440
; 4=sb16 base , base io address
1441
; 4=sb16 base , base io address
1441
; 5=system language, 1eng 2fi 3ger 4rus
1442
; 5=system language, 1eng 2fi 3ger 4rus
1442
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1443
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1443
; 8=fat32 partition in hd
1444
; 8=fat32 partition in hd
1444
; 9
1445
; 9
1445
; 10 = sound dma channel
1446
; 10 = sound dma channel
1446
; 11 = enable lba read
1447
; 11 = enable lba read
1447
; 12 = enable pci access
1448
; 12 = enable pci access
1448
 
1449
 
1449
 
1450
 
1450
     mov  [esp+36],dword 0
1451
     mov  [esp+36],dword 0
1451
     cmp  eax,1                      ; MIDI
1452
     cmp  eax,1                      ; MIDI
1452
     jnz  nsyse1
1453
     jnz  nsyse1
1453
     cmp  ebx,0x100
1454
     cmp  ebx,0x100
1454
     jb   nsyse1
1455
     jb   nsyse1
1455
     mov  edx,65535
1456
     mov  edx,65535
1456
     cmp  edx,ebx
1457
     cmp  edx,ebx
1457
     jb   nsyse1
1458
     jb   nsyse1
1458
     mov  [midi_base],bx
1459
     mov  [midi_base],bx
1459
     mov  word [mididp],bx
1460
     mov  word [mididp],bx
1460
     inc  bx
1461
     inc  bx
1461
     mov  word [midisp],bx
1462
     mov  word [midisp],bx
1462
     ret
1463
     ret
1463
 
1464
 
1464
iglobal
1465
iglobal
1465
midi_base dw 0
1466
midi_base dw 0
1466
endg
1467
endg
1467
 
1468
 
1468
   nsyse1:
1469
   nsyse1:
1469
 
1470
 
1470
     cmp  eax,2                      ; KEYBOARD
1471
     cmp  eax,2                      ; KEYBOARD
1471
     jnz  nsyse2
1472
     jnz  nsyse2
1472
     cmp  ebx,1
1473
     cmp  ebx,1
1473
     jnz  kbnobase
1474
     jnz  kbnobase
1474
     mov  edi,[TASK_BASE]
1475
     mov  edi,[TASK_BASE]
1475
     add  ecx,[edi+TASKDATA.mem_start]
1476
     add  ecx,[edi+TASKDATA.mem_start]
1476
     mov  eax,ecx
1477
     mov  eax,ecx
1477
     mov  ebx,keymap
1478
     mov  ebx,keymap
1478
     mov  ecx,128
1479
     mov  ecx,128
1479
     call memmove
1480
     call memmove
1480
     ret
1481
     ret
1481
   kbnobase:
1482
   kbnobase:
1482
     cmp  ebx,2
1483
     cmp  ebx,2
1483
     jnz  kbnoshift
1484
     jnz  kbnoshift
1484
     mov  edi,[TASK_BASE]
1485
     mov  edi,[TASK_BASE]
1485
     add  ecx,[edi+TASKDATA.mem_start]
1486
     add  ecx,[edi+TASKDATA.mem_start]
1486
     mov  eax,ecx
1487
     mov  eax,ecx
1487
     mov  ebx,keymap_shift
1488
     mov  ebx,keymap_shift
1488
     mov  ecx,128
1489
     mov  ecx,128
1489
     call memmove
1490
     call memmove
1490
     ret
1491
     ret
1491
   kbnoshift:
1492
   kbnoshift:
1492
     cmp  ebx,3
1493
     cmp  ebx,3
1493
     jne  kbnoalt
1494
     jne  kbnoalt
1494
     mov  edi,[TASK_BASE]
1495
     mov  edi,[TASK_BASE]
1495
     add  ecx,[edi+TASKDATA.mem_start]
1496
     add  ecx,[edi+TASKDATA.mem_start]
1496
     mov  eax,ecx
1497
     mov  eax,ecx
1497
     mov  ebx,keymap_alt
1498
     mov  ebx,keymap_alt
1498
     mov  ecx,128
1499
     mov  ecx,128
1499
     call memmove
1500
     call memmove
1500
     ret
1501
     ret
1501
   kbnoalt:
1502
   kbnoalt:
1502
     cmp  ebx,9
1503
     cmp  ebx,9
1503
     jnz  kbnocountry
1504
     jnz  kbnocountry
1504
     mov  word [keyboard],cx
1505
     mov  word [keyboard],cx
1505
     ret
1506
     ret
1506
   kbnocountry:
1507
   kbnocountry:
1507
     mov  [esp+36],dword 1
1508
     mov  [esp+36],dword 1
1508
     ret
1509
     ret
1509
   nsyse2:
1510
   nsyse2:
1510
     cmp  eax,3                      ; CD
1511
     cmp  eax,3                      ; CD
1511
     jnz  nsyse3
1512
     jnz  nsyse3
1512
     test ebx,ebx
1513
     test ebx,ebx
1513
     jz   nosesl
1514
     jz   nosesl
1514
     cmp  ebx, 4
1515
     cmp  ebx, 4
1515
     ja   nosesl
1516
     ja   nosesl
1516
     mov  [cd_base],bl
1517
     mov  [cd_base],bl
1517
     cmp  ebx,1
1518
     cmp  ebx,1
1518
     jnz  noprma
1519
     jnz  noprma
1519
     mov  [cdbase],0x1f0
1520
     mov  [cdbase],0x1f0
1520
     mov  [cdid],0xa0
1521
     mov  [cdid],0xa0
1521
   noprma:
1522
   noprma:
1522
     cmp  ebx,2
1523
     cmp  ebx,2
1523
     jnz  noprsl
1524
     jnz  noprsl
1524
     mov  [cdbase],0x1f0
1525
     mov  [cdbase],0x1f0
1525
     mov  [cdid],0xb0
1526
     mov  [cdid],0xb0
1526
   noprsl:
1527
   noprsl:
1527
     cmp  ebx,3
1528
     cmp  ebx,3
1528
     jnz  nosema
1529
     jnz  nosema
1529
     mov  [cdbase],0x170
1530
     mov  [cdbase],0x170
1530
     mov  [cdid],0xa0
1531
     mov  [cdid],0xa0
1531
   nosema:
1532
   nosema:
1532
     cmp  ebx,4
1533
     cmp  ebx,4
1533
     jnz  nosesl
1534
     jnz  nosesl
1534
     mov  [cdbase],0x170
1535
     mov  [cdbase],0x170
1535
     mov  [cdid],0xb0
1536
     mov  [cdid],0xb0
1536
   nosesl:
1537
   nosesl:
1537
     ret
1538
     ret
1538
 
1539
 
1539
cd_base db 0
1540
cd_base db 0
1540
 
1541
 
1541
   nsyse3:
1542
   nsyse3:
1542
 
1543
 
1543
     cmp  eax,4                      ; SB
1544
     cmp  eax,4                      ; SB
1544
     jnz  nsyse4
1545
     jnz  nsyse4
1545
     cmp  ebx,0x100
1546
     cmp  ebx,0x100
1546
     jb   nsyse4
1547
     jb   nsyse4
1547
     mov  edx,65535
1548
     mov  edx,65535
1548
     cmp  edx,ebx
1549
     cmp  edx,ebx
1549
     jb   nsyse4
1550
     jb   nsyse4
1550
     mov  word [sb16],bx
1551
     mov  word [sb16],bx
1551
     ret
1552
     ret
1552
   nsyse4:
1553
   nsyse4:
1553
 
1554
 
1554
     cmp  eax,5                      ; SYSTEM LANGUAGE
1555
     cmp  eax,5                      ; SYSTEM LANGUAGE
1555
     jnz  nsyse5
1556
     jnz  nsyse5
1556
     mov  [syslang],ebx
1557
     mov  [syslang],ebx
1557
     ret
1558
     ret
1558
   nsyse5:
1559
   nsyse5:
1559
 
1560
 
1560
     cmp  eax,7                      ; HD BASE
1561
     cmp  eax,7                      ; HD BASE
1561
     jne  nsyse7
1562
     jne  nsyse7
1562
     test ebx,ebx
1563
     test ebx,ebx
1563
     jz   nosethd
1564
     jz   nosethd
1564
     cmp  ebx,4
1565
     cmp  ebx,4
1565
     ja   nosethd
1566
     ja   nosethd
1566
     mov  [hd_base],bl
1567
     mov  [hd_base],bl
1567
     cmp  ebx,1
1568
     cmp  ebx,1
1568
     jnz  noprmahd
1569
     jnz  noprmahd
1569
     mov  [hdbase],0x1f0
1570
     mov  [hdbase],0x1f0
1570
     mov  [hdid],0x0
1571
     mov  [hdid],0x0
1571
     mov  [hdpos],1
1572
     mov  [hdpos],1
1572
;     call set_FAT32_variables
1573
;     call set_FAT32_variables
1573
   noprmahd:
1574
   noprmahd:
1574
     cmp  ebx,2
1575
     cmp  ebx,2
1575
     jnz  noprslhd
1576
     jnz  noprslhd
1576
     mov  [hdbase],0x1f0
1577
     mov  [hdbase],0x1f0
1577
     mov  [hdid],0x10
1578
     mov  [hdid],0x10
1578
     mov  [hdpos],2
1579
     mov  [hdpos],2
1579
;     call set_FAT32_variables
1580
;     call set_FAT32_variables
1580
   noprslhd:
1581
   noprslhd:
1581
     cmp  ebx,3
1582
     cmp  ebx,3
1582
     jnz  nosemahd
1583
     jnz  nosemahd
1583
     mov  [hdbase],0x170
1584
     mov  [hdbase],0x170
1584
     mov  [hdid],0x0
1585
     mov  [hdid],0x0
1585
     mov  [hdpos],3
1586
     mov  [hdpos],3
1586
;     call set_FAT32_variables
1587
;     call set_FAT32_variables
1587
   nosemahd:
1588
   nosemahd:
1588
     cmp  ebx,4
1589
     cmp  ebx,4
1589
     jnz  noseslhd
1590
     jnz  noseslhd
1590
     mov  [hdbase],0x170
1591
     mov  [hdbase],0x170
1591
     mov  [hdid],0x10
1592
     mov  [hdid],0x10
1592
     mov  [hdpos],4
1593
     mov  [hdpos],4
1593
;     call set_FAT32_variables
1594
;     call set_FAT32_variables
1594
   noseslhd:
1595
   noseslhd:
1595
    call  reserve_hd1
1596
    call  reserve_hd1
1596
    call  reserve_hd_channel
1597
    call  reserve_hd_channel
1597
    call  free_hd_channel
1598
    call  free_hd_channel
1598
    mov   [hd1_status],0        ; free
1599
    mov   [hd1_status],0        ; free
1599
   nosethd:
1600
   nosethd:
1600
     ret
1601
     ret
1601
 
1602
 
1602
iglobal
1603
iglobal
1603
hd_base db 0
1604
hd_base db 0
1604
endg
1605
endg
1605
 
1606
 
1606
   nsyse7:
1607
   nsyse7:
1607
 
1608
 
1608
     cmp  eax,8                      ; HD PARTITION
1609
     cmp  eax,8                      ; HD PARTITION
1609
     jne  nsyse8
1610
     jne  nsyse8
1610
     mov  [fat32part],ebx
1611
     mov  [fat32part],ebx
1611
;     call set_FAT32_variables
1612
;     call set_FAT32_variables
1612
    call  reserve_hd1
1613
    call  reserve_hd1
1613
    call  reserve_hd_channel
1614
    call  reserve_hd_channel
1614
    call  free_hd_channel
1615
    call  free_hd_channel
1615
     pusha
1616
     pusha
1616
     call  choice_necessity_partition_1
1617
     call  choice_necessity_partition_1
1617
     popa
1618
     popa
1618
    mov   [hd1_status],0        ; free
1619
    mov   [hd1_status],0        ; free
1619
     ret
1620
     ret
1620
   nsyse8:
1621
   nsyse8:
1621
 
1622
 
1622
     cmp  eax,10                     ; SOUND DMA CHANNEL
1623
     cmp  eax,10                     ; SOUND DMA CHANNEL
1623
     jne  no_set_sound_dma
1624
     jne  no_set_sound_dma
1624
     cmp  ebx,3
1625
     cmp  ebx,3
1625
     ja   sys_setup_err
1626
     ja   sys_setup_err
1626
     mov  [sound_dma],ebx
1627
     mov  [sound_dma],ebx
1627
     ret
1628
     ret
1628
   no_set_sound_dma:
1629
   no_set_sound_dma:
1629
 
1630
 
1630
     cmp  eax,11                     ; ENABLE LBA READ
1631
     cmp  eax,11                     ; ENABLE LBA READ
1631
     jne  no_set_lba_read
1632
     jne  no_set_lba_read
1632
     and  ebx,1
1633
     and  ebx,1
1633
     mov  [lba_read_enabled],ebx
1634
     mov  [lba_read_enabled],ebx
1634
     ret
1635
     ret
1635
   no_set_lba_read:
1636
   no_set_lba_read:
1636
 
1637
 
1637
     cmp  eax,12                     ; ENABLE PCI ACCESS
1638
     cmp  eax,12                     ; ENABLE PCI ACCESS
1638
     jne  no_set_pci_access
1639
     jne  no_set_pci_access
1639
     and  ebx,1
1640
     and  ebx,1
1640
     mov  [pci_access_enabled],ebx
1641
     mov  [pci_access_enabled],ebx
1641
     ret
1642
     ret
1642
   no_set_pci_access:
1643
   no_set_pci_access:
1643
 
1644
 
1644
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1645
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1645
include 'vmodeint.inc'
1646
include 'vmodeint.inc'
1646
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1647
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1647
 
1648
 
1648
sys_setup_err:
1649
sys_setup_err:
1649
     mov  [esp+36],dword -1
1650
     mov  [esp+36],dword -1
1650
     ret
1651
     ret
1651
 
1652
 
1652
align 4
1653
align 4
1653
 
1654
 
1654
sys_getsetup:
1655
sys_getsetup:
1655
 
1656
 
1656
; 1=roland mpu midi base , base io address
1657
; 1=roland mpu midi base , base io address
1657
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1658
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1658
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1659
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1659
; 4=sb16 base , base io address
1660
; 4=sb16 base , base io address
1660
; 5=system language, 1eng 2fi 3ger 4rus
1661
; 5=system language, 1eng 2fi 3ger 4rus
1661
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1662
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1662
; 8=fat32 partition in hd
1663
; 8=fat32 partition in hd
1663
; 9=get hs timer tic
1664
; 9=get hs timer tic
1664
 
1665
 
1665
     cmp  eax,1
1666
     cmp  eax,1
1666
     jne  ngsyse1
1667
     jne  ngsyse1
1667
     movzx eax,[midi_base]
1668
     movzx eax,[midi_base]
1668
     mov  [esp+36],eax
1669
     mov  [esp+36],eax
1669
     ret
1670
     ret
1670
   ngsyse1:
1671
   ngsyse1:
1671
 
1672
 
1672
     cmp  eax,2
1673
     cmp  eax,2
1673
     jne  ngsyse2
1674
     jne  ngsyse2
1674
     cmp  ebx,1
1675
     cmp  ebx,1
1675
     jnz  kbnobaseret
1676
     jnz  kbnobaseret
1676
     mov  edi,[TASK_BASE]
1677
     mov  edi,[TASK_BASE]
1677
     add  ecx,[edi+TASKDATA.mem_start]
1678
     add  ecx,[edi+TASKDATA.mem_start]
1678
     mov  ebx,ecx
1679
     mov  ebx,ecx
1679
     mov  eax,keymap
1680
     mov  eax,keymap
1680
     mov  ecx,128
1681
     mov  ecx,128
1681
     call memmove
1682
     call memmove
1682
     ret
1683
     ret
1683
   kbnobaseret:
1684
   kbnobaseret:
1684
     cmp  ebx,2
1685
     cmp  ebx,2
1685
     jnz  kbnoshiftret
1686
     jnz  kbnoshiftret
1686
     mov  edi,[TASK_BASE]
1687
     mov  edi,[TASK_BASE]
1687
     add  ecx,[edi+TASKDATA.mem_start]
1688
     add  ecx,[edi+TASKDATA.mem_start]
1688
     mov  ebx,ecx
1689
     mov  ebx,ecx
1689
     mov  eax,keymap_shift
1690
     mov  eax,keymap_shift
1690
     mov  ecx,128
1691
     mov  ecx,128
1691
     call memmove
1692
     call memmove
1692
     ret
1693
     ret
1693
   kbnoshiftret:
1694
   kbnoshiftret:
1694
     cmp  ebx,3
1695
     cmp  ebx,3
1695
     jne  kbnoaltret
1696
     jne  kbnoaltret
1696
     mov  edi,[TASK_BASE]
1697
     mov  edi,[TASK_BASE]
1697
     add  ecx,[edi+TASKDATA.mem_start]
1698
     add  ecx,[edi+TASKDATA.mem_start]
1698
     mov  ebx,ecx
1699
     mov  ebx,ecx
1699
     mov  eax,keymap_alt
1700
     mov  eax,keymap_alt
1700
     mov  ecx,128
1701
     mov  ecx,128
1701
     call memmove
1702
     call memmove
1702
     ret
1703
     ret
1703
   kbnoaltret:
1704
   kbnoaltret:
1704
     cmp  ebx,9
1705
     cmp  ebx,9
1705
     jnz  ngsyse2
1706
     jnz  ngsyse2
1706
     movzx eax,word [keyboard]
1707
     movzx eax,word [keyboard]
1707
     mov  [esp+36],eax
1708
     mov  [esp+36],eax
1708
     ret
1709
     ret
1709
   ngsyse2:
1710
   ngsyse2:
1710
 
1711
 
1711
     cmp  eax,3
1712
     cmp  eax,3
1712
     jnz  ngsyse3
1713
     jnz  ngsyse3
1713
     movzx eax,[cd_base]
1714
     movzx eax,[cd_base]
1714
     mov  [esp+36],eax
1715
     mov  [esp+36],eax
1715
     ret
1716
     ret
1716
   ngsyse3:
1717
   ngsyse3:
1717
 
1718
 
1718
     cmp  eax,4
1719
     cmp  eax,4
1719
     jne  ngsyse4
1720
     jne  ngsyse4
1720
     mov  eax,[sb16]
1721
     mov  eax,[sb16]
1721
     mov  [esp+36],eax
1722
     mov  [esp+36],eax
1722
     ret
1723
     ret
1723
   ngsyse4:
1724
   ngsyse4:
1724
 
1725
 
1725
     cmp  eax,5
1726
     cmp  eax,5
1726
     jnz  ngsyse5
1727
     jnz  ngsyse5
1727
     mov  eax,[syslang]
1728
     mov  eax,[syslang]
1728
     mov  [esp+36],eax
1729
     mov  [esp+36],eax
1729
     ret
1730
     ret
1730
   ngsyse5:
1731
   ngsyse5:
1731
     cmp  eax,7
1732
     cmp  eax,7
1732
     jnz  ngsyse7
1733
     jnz  ngsyse7
1733
     movzx eax,[hd_base]
1734
     movzx eax,[hd_base]
1734
     mov  [esp+36],eax
1735
     mov  [esp+36],eax
1735
     ret
1736
     ret
1736
   ngsyse7:
1737
   ngsyse7:
1737
     cmp  eax,8
1738
     cmp  eax,8
1738
     jnz  ngsyse8
1739
     jnz  ngsyse8
1739
     mov eax,[fat32part]
1740
     mov eax,[fat32part]
1740
     mov  [esp+36],eax
1741
     mov  [esp+36],eax
1741
     ret
1742
     ret
1742
   ngsyse8:
1743
   ngsyse8:
1743
     cmp  eax,9
1744
     cmp  eax,9
1744
     jne  ngsyse9
1745
     jne  ngsyse9
1745
     mov  eax,[timer_ticks] ;[0xfdf0]
1746
     mov  eax,[timer_ticks] ;[0xfdf0]
1746
     mov  [esp+36],eax
1747
     mov  [esp+36],eax
1747
     ret
1748
     ret
1748
   ngsyse9:
1749
   ngsyse9:
1749
     cmp  eax,10
1750
     cmp  eax,10
1750
     jnz  ngsyse10
1751
     jnz  ngsyse10
1751
     mov eax,[sound_dma]
1752
     mov eax,[sound_dma]
1752
     mov  [esp+36],eax
1753
     mov  [esp+36],eax
1753
     ret
1754
     ret
1754
   ngsyse10:
1755
   ngsyse10:
1755
     cmp  eax,11
1756
     cmp  eax,11
1756
     jnz  ngsyse11
1757
     jnz  ngsyse11
1757
     mov eax,[lba_read_enabled]
1758
     mov eax,[lba_read_enabled]
1758
     mov  [esp+36],eax
1759
     mov  [esp+36],eax
1759
     ret
1760
     ret
1760
   ngsyse11:
1761
   ngsyse11:
1761
     cmp  eax,12
1762
     cmp  eax,12
1762
     jnz  ngsyse12
1763
     jnz  ngsyse12
1763
     mov eax,[pci_access_enabled]
1764
     mov eax,[pci_access_enabled]
1764
     mov  [esp+36],eax
1765
     mov  [esp+36],eax
1765
     ret
1766
     ret
1766
   ngsyse12:
1767
   ngsyse12:
1767
     mov  [esp+36],dword 1
1768
     mov  [esp+36],dword 1
1768
     ret
1769
     ret
-
 
1770
 
-
 
1771
get_timer_ticks:
-
 
1772
    mov eax,[timer_ticks]
-
 
1773
    ret
1769
 
1774
 
1770
iglobal
1775
iglobal
1771
align 4
1776
align 4
1772
mousefn dd msscreen, mswin, msbutton, msset
1777
mousefn dd msscreen, mswin, msbutton, msset
1773
        dd app_load_cursor
1778
        dd app_load_cursor
1774
        dd app_set_cursor
1779
        dd app_set_cursor
1775
        dd app_delete_cursor
1780
        dd app_delete_cursor
-
 
1781
        dd msz
1776
endg
1782
endg
1777
 
1783
 
1778
readmousepos:
1784
readmousepos:
1779
 
1785
 
1780
; eax=0 screen relative
1786
; eax=0 screen relative
1781
; eax=1 window relative
1787
; eax=1 window relative
1782
; eax=2 buttons pressed
1788
; eax=2 buttons pressed
1783
; eax=3 set mouse pos   ; reserved
1789
; eax=3 set mouse pos   ; reserved
1784
; eax=4 load cursor
1790
; eax=4 load cursor
1785
; eax=5 set cursor
1791
; eax=5 set cursor
1786
; eax=6 delete cursor   ; reserved
1792
; eax=6 delete cursor   ; reserved
-
 
1793
; eax=7 get mouse_z
1787
 
1794
 
1788
           cmp eax, 6
1795
           cmp eax, 7
1789
           ja msset
1796
           ja msset
1790
           jmp [mousefn+eax*4]
1797
           jmp [mousefn+eax*4]
1791
msscreen:
1798
msscreen:
1792
           mov  eax,[MOUSE_X]
1799
           mov  eax,[MOUSE_X]
1793
           shl  eax,16
1800
           shl  eax,16
1794
           mov  ax,[MOUSE_Y]
1801
           mov  ax,[MOUSE_Y]
1795
           mov  [esp+36],eax
1802
           mov  [esp+36],eax
1796
           ret
1803
           ret
1797
mswin:
1804
mswin:
1798
           mov  eax,[MOUSE_X]
1805
           mov  eax,[MOUSE_X]
1799
           shl  eax,16
1806
           shl  eax,16
1800
           mov  ax,[MOUSE_Y]
1807
           mov  ax,[MOUSE_Y]
1801
           mov  esi,[TASK_BASE]
1808
           mov  esi,[TASK_BASE]
1802
           mov  bx, word [esi-twdw+WDATA.box.left]
1809
           mov  bx, word [esi-twdw+WDATA.box.left]
1803
           shl  ebx,16
1810
           shl  ebx,16
1804
           mov  bx, word [esi-twdw+WDATA.box.top]
1811
           mov  bx, word [esi-twdw+WDATA.box.top]
1805
           sub  eax,ebx
1812
           sub  eax,ebx
1806
 
1813
 
1807
           mov  edi,[CURRENT_TASK]
1814
           mov  edi,[CURRENT_TASK]
1808
           shl  edi,8
1815
           shl  edi,8
1809
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1816
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1810
           rol  eax,16
1817
           rol  eax,16
1811
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1818
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1812
           rol  eax,16
1819
           rol  eax,16
1813
           mov  [esp+36],eax
1820
           mov  [esp+36],eax
1814
           ret
1821
           ret
1815
msbutton:
1822
msbutton:
1816
           movzx eax,byte [BTN_DOWN]
1823
           movzx eax,byte [BTN_DOWN]
1817
           mov  [esp+36],eax
1824
           mov  [esp+36],eax
1818
           ret
1825
           ret
-
 
1826
msz:
-
 
1827
           mov   edi, [TASK_COUNT]
-
 
1828
           movzx edi, word [WIN_POS + edi*2]
-
 
1829
           cmp   edi, [CURRENT_TASK]
-
 
1830
           jne   @f
-
 
1831
           mov   ax,[MOUSE_SCROLL_H]
-
 
1832
           shl   eax,16
-
 
1833
           mov   ax,[MOUSE_SCROLL_V]
-
 
1834
           mov   [esp+36],eax
-
 
1835
           mov   [MOUSE_SCROLL_H],word 0
-
 
1836
           mov   [MOUSE_SCROLL_V],word 0
-
 
1837
           ret
-
 
1838
       @@:
-
 
1839
           mov  [esp+36],dword 0
-
 
1840
           ret
1819
msset:
1841
msset:
1820
           ret
1842
           ret
1821
 
1843
 
1822
app_load_cursor:
1844
app_load_cursor:
1823
      ;     add ebx, new_app_base
1845
      ;     add ebx, new_app_base
1824
           cmp ebx, OS_BASE
1846
           cmp ebx, OS_BASE
1825
           jae msset
1847
           jae msset
1826
           stdcall load_cursor, ebx, ecx
1848
           stdcall load_cursor, ebx, ecx
1827
           mov [esp+36], eax
1849
           mov [esp+36], eax
1828
           ret
1850
           ret
1829
 
1851
 
1830
app_set_cursor:
1852
app_set_cursor:
1831
           stdcall set_cursor, ebx
1853
           stdcall set_cursor, ebx
1832
           mov [esp+36], eax
1854
           mov [esp+36], eax
1833
           ret
1855
           ret
1834
 
1856
 
1835
app_delete_cursor:
1857
app_delete_cursor:
1836
           stdcall delete_cursor, ebx
1858
           stdcall delete_cursor, ebx
1837
           mov [esp+36], eax
1859
           mov [esp+36], eax
1838
           ret
1860
           ret
1839
 
1861
 
1840
is_input:
1862
is_input:
1841
 
1863
 
1842
   push edx
1864
   push edx
1843
   mov  dx,word [midisp]
1865
   mov  dx,word [midisp]
1844
   in   al,dx
1866
   in   al,dx
1845
   and  al,0x80
1867
   and  al,0x80
1846
   pop  edx
1868
   pop  edx
1847
   ret
1869
   ret
1848
 
1870
 
1849
is_output:
1871
is_output:
1850
 
1872
 
1851
   push edx
1873
   push edx
1852
   mov  dx,word [midisp]
1874
   mov  dx,word [midisp]
1853
   in   al,dx
1875
   in   al,dx
1854
   and  al,0x40
1876
   and  al,0x40
1855
   pop  edx
1877
   pop  edx
1856
   ret
1878
   ret
1857
 
1879
 
1858
 
1880
 
1859
get_mpu_in:
1881
get_mpu_in:
1860
 
1882
 
1861
   push edx
1883
   push edx
1862
   mov  dx,word [mididp]
1884
   mov  dx,word [mididp]
1863
   in   al,dx
1885
   in   al,dx
1864
   pop  edx
1886
   pop  edx
1865
   ret
1887
   ret
1866
 
1888
 
1867
 
1889
 
1868
put_mpu_out:
1890
put_mpu_out:
1869
 
1891
 
1870
   push edx
1892
   push edx
1871
   mov  dx,word [mididp]
1893
   mov  dx,word [mididp]
1872
   out  dx,al
1894
   out  dx,al
1873
   pop  edx
1895
   pop  edx
1874
   ret
1896
   ret
1875
 
1897
 
1876
 
1898
 
1877
setuart:
1899
setuart:
1878
 
1900
 
1879
 su1:
1901
 su1:
1880
   call is_output
1902
   call is_output
1881
   cmp  al,0
1903
   cmp  al,0
1882
   jnz  su1
1904
   jnz  su1
1883
   mov  dx,word [midisp]
1905
   mov  dx,word [midisp]
1884
   mov  al,0xff
1906
   mov  al,0xff
1885
   out  dx,al
1907
   out  dx,al
1886
 su2:
1908
 su2:
1887
   mov  dx,word [midisp]
1909
   mov  dx,word [midisp]
1888
   mov  al,0xff
1910
   mov  al,0xff
1889
   out  dx,al
1911
   out  dx,al
1890
   call is_input
1912
   call is_input
1891
   cmp  al,0
1913
   cmp  al,0
1892
   jnz  su2
1914
   jnz  su2
1893
   call get_mpu_in
1915
   call get_mpu_in
1894
   cmp  al,0xfe
1916
   cmp  al,0xfe
1895
   jnz  su2
1917
   jnz  su2
1896
 su3:
1918
 su3:
1897
   call is_output
1919
   call is_output
1898
   cmp  al,0
1920
   cmp  al,0
1899
   jnz  su3
1921
   jnz  su3
1900
   mov  dx,word [midisp]
1922
   mov  dx,word [midisp]
1901
   mov  al,0x3f
1923
   mov  al,0x3f
1902
   out  dx,al
1924
   out  dx,al
1903
 
1925
 
1904
   ret
1926
   ret
1905
 
1927
 
1906
 
1928
 
1907
align 4
1929
align 4
1908
 
1930
 
1909
sys_midi:
1931
sys_midi:
1910
 
1932
 
1911
     cmp  [mididp],0
1933
     cmp  [mididp],0
1912
     jnz  sm0
1934
     jnz  sm0
1913
     mov  [esp+36],dword 1
1935
     mov  [esp+36],dword 1
1914
     ret
1936
     ret
1915
   sm0:
1937
   sm0:
1916
 
1938
 
1917
     cmp  eax,1
1939
     cmp  eax,1
1918
     mov  [esp+36],dword 0
1940
     mov  [esp+36],dword 0
1919
     jnz  smn1
1941
     jnz  smn1
1920
     call setuart
1942
     call setuart
1921
     ret
1943
     ret
1922
   smn1:
1944
   smn1:
1923
 
1945
 
1924
     cmp  eax,2
1946
     cmp  eax,2
1925
     jnz  smn2
1947
     jnz  smn2
1926
   sm10:
1948
   sm10:
1927
     call get_mpu_in
1949
     call get_mpu_in
1928
     call is_output
1950
     call is_output
1929
     test al,al
1951
     test al,al
1930
     jnz  sm10
1952
     jnz  sm10
1931
     mov  al,bl
1953
     mov  al,bl
1932
     call put_mpu_out
1954
     call put_mpu_out
1933
     ret
1955
     ret
1934
   smn2:
1956
   smn2:
1935
 
1957
 
1936
     ret
1958
     ret
1937
 
1959
 
1938
 
1960
 
1939
detect_devices:
1961
detect_devices:
1940
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1962
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1941
include 'detect/commouse.inc'
1963
include 'detect/commouse.inc'
1942
include 'detect/ps2mouse.inc'
1964
;include 'detect/ps2mouse.inc'
1943
;include 'detect/dev_fd.inc'
1965
;include 'detect/dev_fd.inc'
1944
;include 'detect/dev_hdcd.inc'
1966
;include 'detect/dev_hdcd.inc'
1945
;include 'detect/sear_par.inc'
1967
;include 'detect/sear_par.inc'
1946
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1968
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1947
    ret
1969
    ret
1948
 
1970
 
1949
 
1971
 
1950
sys_end:
1972
sys_end:
1951
 
1973
 
1952
     mov   eax,[TASK_BASE]
1974
     mov   eax,[TASK_BASE]
1953
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1975
     mov   [eax+TASKDATA.state], 3  ; terminate this program
1954
 
1976
 
1955
    waitterm:            ; wait here for termination
1977
    waitterm:            ; wait here for termination
1956
     mov   eax,5
1978
     mov   eax,5
1957
     call  delay_hs
1979
     call  delay_hs
1958
     jmp   waitterm
1980
     jmp   waitterm
1959
 
1981
 
1960
iglobal
1982
iglobal
1961
align 4
1983
align 4
1962
sys_system_table:
1984
sys_system_table:
1963
        dd      sysfn_shutdown          ; 1 = system shutdown
1985
        dd      sysfn_shutdown          ; 1 = system shutdown
1964
        dd      sysfn_terminate         ; 2 = terminate thread
1986
        dd      sysfn_terminate         ; 2 = terminate thread
1965
        dd      sysfn_activate          ; 3 = activate window
1987
        dd      sysfn_activate          ; 3 = activate window
1966
        dd      sysfn_getidletime       ; 4 = get idle time
1988
        dd      sysfn_getidletime       ; 4 = get idle time
1967
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1989
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1968
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1990
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1969
        dd      sysfn_getactive         ; 7 = get active window
1991
        dd      sysfn_getactive         ; 7 = get active window
1970
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1992
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1971
        dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
1993
        dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
1972
        dd      sysfn_minimize          ; 10 = minimize window
1994
        dd      sysfn_minimize          ; 10 = minimize window
1973
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
1995
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
1974
        dd      sysfn_lastkey           ; 12 = get last pressed key
1996
        dd      sysfn_lastkey           ; 12 = get last pressed key
1975
        dd      sysfn_getversion        ; 13 = get kernel version
1997
        dd      sysfn_getversion        ; 13 = get kernel version
1976
        dd      sysfn_waitretrace       ; 14 = wait retrace
1998
        dd      sysfn_waitretrace       ; 14 = wait retrace
1977
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1999
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1978
        dd      sysfn_getfreemem        ; 16 = get free memory size
2000
        dd      sysfn_getfreemem        ; 16 = get free memory size
1979
        dd      sysfn_getallmem         ; 17 = get total memory size
2001
        dd      sysfn_getallmem         ; 17 = get total memory size
1980
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
2002
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1981
                                        ;                 instead of slot
2003
                                        ;                 instead of slot
1982
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2004
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1983
        dd      sysfn_meminfo           ; 20 = get extended memory info
2005
        dd      sysfn_meminfo           ; 20 = get extended memory info
1984
sysfn_num = ($ - sys_system_table)/4
2006
sysfn_num = ($ - sys_system_table)/4
1985
endg
2007
endg
1986
 
2008
 
1987
sys_system:
2009
sys_system:
1988
        dec     eax
2010
        dec     eax
1989
        cmp     eax, sysfn_num
2011
        cmp     eax, sysfn_num
1990
        jae     @f
2012
        jae     @f
1991
        jmp     dword [sys_system_table + eax*4]
2013
        jmp     dword [sys_system_table + eax*4]
1992
@@:
2014
@@:
1993
        ret
2015
        ret
1994
 
2016
 
1995
sysfn_shutdown:         ; 18.1 = BOOT
2017
sysfn_shutdown:         ; 18.1 = BOOT
1996
     mov  [BOOT_VAR+0x9030],byte 0
2018
     mov  [BOOT_VAR+0x9030],byte 0
1997
  for_shutdown_parameter:
2019
  for_shutdown_parameter:
1998
 
2020
 
1999
     mov  eax,[TASK_COUNT]
2021
     mov  eax,[TASK_COUNT]
2000
     add  eax,2
2022
     add  eax,2
2001
     mov  [shutdown_processes],eax
2023
     mov  [shutdown_processes],eax
2002
     mov  [SYS_SHUTDOWN],al
2024
     mov  [SYS_SHUTDOWN],al
2003
     and  dword [esp+36], 0
2025
     and  dword [esp+36], 0
2004
     ret
2026
     ret
2005
  uglobal
2027
  uglobal
2006
   shutdown_processes: dd 0x0
2028
   shutdown_processes: dd 0x0
2007
  endg
2029
  endg
2008
 
2030
 
2009
sysfn_terminate:        ; 18.2 = TERMINATE
2031
sysfn_terminate:        ; 18.2 = TERMINATE
2010
     cmp  ebx,2
2032
     cmp  ebx,2
2011
     jb   noprocessterminate
2033
     jb   noprocessterminate
2012
     mov  edx,[TASK_COUNT]
2034
     mov  edx,[TASK_COUNT]
2013
     cmp  ebx,edx
2035
     cmp  ebx,edx
2014
     ja   noprocessterminate
2036
     ja   noprocessterminate
2015
     mov  eax,[TASK_COUNT]
2037
     mov  eax,[TASK_COUNT]
2016
     shl  ebx,5
2038
     shl  ebx,5
2017
     mov  edx,[ebx+CURRENT_TASK+TASKDATA.pid]
2039
     mov  edx,[ebx+CURRENT_TASK+TASKDATA.pid]
2018
     add  ebx,CURRENT_TASK+TASKDATA.state
2040
     add  ebx,CURRENT_TASK+TASKDATA.state
2019
     cmp  byte [ebx], 9
2041
     cmp  byte [ebx], 9
2020
     jz   noprocessterminate
2042
     jz   noprocessterminate
2021
 
2043
 
2022
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2044
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2023
     mov  [ebx],byte 3       ; clear possible i40's
2045
     mov  [ebx],byte 3       ; clear possible i40's
2024
     ;call MEM_Heap_UnLock
2046
     ;call MEM_Heap_UnLock
2025
 
2047
 
2026
     cmp  edx,[application_table_status]    ; clear app table stat
2048
     cmp  edx,[application_table_status]    ; clear app table stat
2027
     jne  noatsc
2049
     jne  noatsc
2028
     mov  [application_table_status],0
2050
     mov  [application_table_status],0
2029
   noatsc:
2051
   noatsc:
2030
   noprocessterminate:
2052
   noprocessterminate:
2031
     ret
2053
     ret
2032
 
2054
 
2033
sysfn_terminate2:
2055
sysfn_terminate2:
2034
;lock application_table_status mutex
2056
;lock application_table_status mutex
2035
.table_status:
2057
.table_status:
2036
    cli
2058
    cli
2037
    cmp    [application_table_status],0
2059
    cmp    [application_table_status],0
2038
    je     .stf
2060
    je     .stf
2039
    sti
2061
    sti
2040
    call   change_task
2062
    call   change_task
2041
    jmp    .table_status
2063
    jmp    .table_status
2042
.stf:
2064
.stf:
2043
    call   set_application_table_status
2065
    call   set_application_table_status
2044
    mov    eax,ebx
2066
    mov    eax,ebx
2045
    call   pid_to_slot
2067
    call   pid_to_slot
2046
    test   eax,eax
2068
    test   eax,eax
2047
    jz     .not_found
2069
    jz     .not_found
2048
    mov    ebx,eax
2070
    mov    ebx,eax
2049
    cli
2071
    cli
2050
    call   sysfn_terminate
2072
    call   sysfn_terminate
2051
    mov    [application_table_status],0
2073
    mov    [application_table_status],0
2052
    sti
2074
    sti
2053
    and    dword [esp+36],0
2075
    and    dword [esp+36],0
2054
    ret
2076
    ret
2055
.not_found:
2077
.not_found:
2056
    mov    [application_table_status],0
2078
    mov    [application_table_status],0
2057
    or     dword [esp+36],-1
2079
    or     dword [esp+36],-1
2058
    ret
2080
    ret
2059
 
2081
 
2060
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2082
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2061
     cmp  ebx,2
2083
     cmp  ebx,2
2062
     jb   .nowindowactivate
2084
     jb   .nowindowactivate
2063
     cmp  ebx,[TASK_COUNT]
2085
     cmp  ebx,[TASK_COUNT]
2064
     ja   .nowindowactivate
2086
     ja   .nowindowactivate
2065
 
2087
 
2066
     mov   [window_minimize], 2   ; restore window if minimized
2088
     mov   [window_minimize], 2   ; restore window if minimized
2067
 
2089
 
2068
     movzx esi, word [WIN_STACK + ebx*2]
2090
     movzx esi, word [WIN_STACK + ebx*2]
2069
     cmp   esi, [TASK_COUNT]
2091
     cmp   esi, [TASK_COUNT]
2070
     je    .nowindowactivate ; already active
2092
     je    .nowindowactivate ; already active
2071
 
2093
 
2072
     mov   edi, ebx
2094
     mov   edi, ebx
2073
     shl   edi, 5
2095
     shl   edi, 5
2074
     add   edi, window_data
2096
     add   edi, window_data
2075
     movzx esi, word [WIN_STACK + ebx * 2]
2097
     movzx esi, word [WIN_STACK + ebx * 2]
2076
     lea   esi, [WIN_POS + esi * 2]
2098
     lea   esi, [WIN_POS + esi * 2]
2077
     call  waredraw
2099
     call  waredraw
2078
.nowindowactivate:
2100
.nowindowactivate:
2079
     ret
2101
     ret
2080
 
2102
 
2081
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2103
sysfn_getidletime:              ; 18.4 = GET IDLETIME
2082
     mov  eax,[idleusesec]
2104
     mov  eax,[idleusesec]
2083
     mov  [esp+36], eax
2105
     mov  [esp+36], eax
2084
     ret
2106
     ret
2085
 
2107
 
2086
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2108
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
2087
     mov  eax,[CPU_FREQ]
2109
     mov  eax,[CPU_FREQ]
2088
     mov  [esp+36], eax
2110
     mov  [esp+36], eax
2089
     ret
2111
     ret
2090
 
2112
 
2091
;  SAVE ramdisk to /hd/1/menuet.img
2113
;  SAVE ramdisk to /hd/1/menuet.img
2092
;!!!!!!!!!!!!!!!!!!!!!!!!
2114
;!!!!!!!!!!!!!!!!!!!!!!!!
2093
   include 'blkdev/rdsave.inc'
2115
   include 'blkdev/rdsave.inc'
2094
;!!!!!!!!!!!!!!!!!!!!!!!!
2116
;!!!!!!!!!!!!!!!!!!!!!!!!
2095
 
2117
 
2096
sysfn_getactive:        ; 18.7 = get active window
2118
sysfn_getactive:        ; 18.7 = get active window
2097
     mov  eax, [TASK_COUNT]
2119
     mov  eax, [TASK_COUNT]
2098
   movzx  eax, word [WIN_POS + eax*2]
2120
   movzx  eax, word [WIN_POS + eax*2]
2099
     mov  [esp+36],eax
2121
     mov  [esp+36],eax
2100
     ret
2122
     ret
2101
 
2123
 
2102
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2124
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
2103
     cmp  ebx,1
2125
     cmp  ebx,1
2104
     jne  nogetsoundflag
2126
     jne  nogetsoundflag
2105
     movzx  eax,byte [sound_flag] ; get sound_flag
2127
     movzx  eax,byte [sound_flag] ; get sound_flag
2106
     mov  [esp+36],eax
2128
     mov  [esp+36],eax
2107
     ret
2129
     ret
2108
 nogetsoundflag:
2130
 nogetsoundflag:
2109
     cmp  ebx,2
2131
     cmp  ebx,2
2110
     jnz  nosoundflag
2132
     jnz  nosoundflag
2111
     xor  byte [sound_flag], 1
2133
     xor  byte [sound_flag], 1
2112
 nosoundflag:
2134
 nosoundflag:
2113
     ret
2135
     ret
2114
 
2136
 
2115
sysfn_shutdown_param:   ; 18.9 = system shutdown with param
2137
sysfn_shutdown_param:   ; 18.9 = system shutdown with param
2116
     cmp  ebx,1
2138
     cmp  ebx,1
2117
     jl   exit_for_anyone
2139
     jl   exit_for_anyone
2118
     cmp  ebx,4
2140
     cmp  ebx,4
2119
     jg   exit_for_anyone
2141
     jg   exit_for_anyone
2120
     mov  [BOOT_VAR+0x9030],bl
2142
     mov  [BOOT_VAR+0x9030],bl
2121
     jmp  for_shutdown_parameter
2143
     jmp  for_shutdown_parameter
2122
 
2144
 
2123
sysfn_minimize:         ; 18.10 = minimize window
2145
sysfn_minimize:         ; 18.10 = minimize window
2124
     mov   [window_minimize],1
2146
     mov   [window_minimize],1
2125
 exit_for_anyone:
2147
 exit_for_anyone:
2126
     ret
2148
     ret
2127
 
2149
 
2128
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2150
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2129
     cmp  ebx,1
2151
     cmp  ebx,1
2130
     jnz  full_table
2152
     jnz  full_table
2131
  small_table:
2153
  small_table:
2132
     call for_all_tables
2154
     call for_all_tables
2133
     mov ecx,10
2155
     mov ecx,10
2134
     cld
2156
     cld
2135
     rep movsb
2157
     rep movsb
2136
     ret
2158
     ret
2137
   for_all_tables:
2159
   for_all_tables:
2138
     mov edi,[TASK_BASE]
2160
     mov edi,[TASK_BASE]
2139
     mov edi,[edi+TASKDATA.mem_start]
2161
     mov edi,[edi+TASKDATA.mem_start]
2140
     add edi,ecx
2162
     add edi,ecx
2141
     mov esi,DRIVE_DATA
2163
     mov esi,DRIVE_DATA
2142
     ret
2164
     ret
2143
  full_table:
2165
  full_table:
2144
     cmp  ebx,2
2166
     cmp  ebx,2
2145
     jnz  exit_for_anyone
2167
     jnz  exit_for_anyone
2146
     call for_all_tables
2168
     call for_all_tables
2147
     mov ecx,16384
2169
     mov ecx,16384
2148
     cld
2170
     cld
2149
     rep movsd
2171
     rep movsd
2150
     ret
2172
     ret
2151
 
2173
 
2152
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2174
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2153
        and     dword [esp+36], 0
2175
        and     dword [esp+36], 0
2154
        ret
2176
        ret
2155
 
2177
 
2156
sysfn_getversion:       ; 18.13 = get kernel ID and version
2178
sysfn_getversion:       ; 18.13 = get kernel ID and version
2157
     mov edi,[TASK_BASE]
2179
     mov edi,[TASK_BASE]
2158
     mov edi,[edi+TASKDATA.mem_start]
2180
     mov edi,[edi+TASKDATA.mem_start]
2159
     add edi,ebx
2181
     add edi,ebx
2160
     mov esi,version_inf
2182
     mov esi,version_inf
2161
     mov ecx,version_end-version_inf
2183
     mov ecx,version_end-version_inf
2162
     cld
2184
     cld
2163
     rep movsb
2185
     rep movsb
2164
     ret
2186
     ret
2165
 
2187
 
2166
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2188
sysfn_waitretrace:     ; 18.14 = sys wait retrace
2167
     ;wait retrace functions
2189
     ;wait retrace functions
2168
 sys_wait_retrace:
2190
 sys_wait_retrace:
2169
     mov edx,0x3da
2191
     mov edx,0x3da
2170
 WaitRetrace_loop:
2192
 WaitRetrace_loop:
2171
     in al,dx
2193
     in al,dx
2172
     test al,1000b
2194
     test al,1000b
2173
     jz WaitRetrace_loop
2195
     jz WaitRetrace_loop
2174
     mov [esp+36],dword 0
2196
     mov [esp+36],dword 0
2175
     ret
2197
     ret
2176
 
2198
 
2177
sysfn_centermouse:      ; 18.15 = mouse centered
2199
sysfn_centermouse:      ; 18.15 = mouse centered
2178
     call  mouse_centered
2200
     call  mouse_centered
2179
     mov [esp+36],dword 0
2201
     mov [esp+36],dword 0
2180
     ret
2202
     ret
2181
 
2203
 
2182
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2204
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
2183
     cmp  ebx,0  ; get mouse speed factor
2205
     cmp  ebx,0  ; get mouse speed factor
2184
     jnz  .set_mouse_acceleration
2206
     jnz  .set_mouse_acceleration
2185
     xor  eax,eax
2207
     xor  eax,eax
2186
     mov  ax,[mouse_speed_factor]
2208
     mov  ax,[mouse_speed_factor]
2187
     mov  [esp+36],eax
2209
     mov  [esp+36],eax
2188
     ret
2210
     ret
2189
 .set_mouse_acceleration:
2211
 .set_mouse_acceleration:
2190
     cmp  ebx,1  ; set mouse speed factor
2212
     cmp  ebx,1  ; set mouse speed factor
2191
     jnz  .get_mouse_delay
2213
     jnz  .get_mouse_delay
2192
     mov  [mouse_speed_factor],cx
2214
     mov  [mouse_speed_factor],cx
2193
     ret
2215
     ret
2194
 .get_mouse_delay:
2216
 .get_mouse_delay:
2195
     cmp  ebx,2  ; get mouse delay
2217
     cmp  ebx,2  ; get mouse delay
2196
     jnz  .set_mouse_delay
2218
     jnz  .set_mouse_delay
2197
     mov  eax,[mouse_delay]
2219
     mov  eax,[mouse_delay]
2198
     mov  [esp+36],eax
2220
     mov  [esp+36],eax
2199
     ret
2221
     ret
2200
 .set_mouse_delay:
2222
 .set_mouse_delay:
2201
     cmp  ebx,3  ; set mouse delay
2223
     cmp  ebx,3  ; set mouse delay
2202
     jnz  .set_pointer_position
2224
     jnz  .set_pointer_position
2203
     mov  [mouse_delay],ecx
2225
     mov  [mouse_delay],ecx
2204
     ret
2226
     ret
2205
 .set_pointer_position:
2227
 .set_pointer_position:
2206
     cmp  ebx,4  ; set mouse pointer position
2228
     cmp  ebx,4  ; set mouse pointer position
2207
     jnz  .end
2229
     jnz  .end
2208
     mov   [MOUSE_Y],cx    ;y
2230
     mov   [MOUSE_Y],cx    ;y
2209
     ror   ecx,16
2231
     ror   ecx,16
2210
     mov   [MOUSE_X],cx    ;x
2232
     mov   [MOUSE_X],cx    ;x
2211
     rol   ecx,16
2233
     rol   ecx,16
2212
 .end:
2234
 .end:
2213
     ret
2235
     ret
2214
 
2236
 
2215
sysfn_getfreemem:
2237
sysfn_getfreemem:
2216
     mov eax, [pg_data.pages_free]
2238
     mov eax, [pg_data.pages_free]
2217
     shl eax, 2
2239
     shl eax, 2
2218
     mov [esp+36],eax
2240
     mov [esp+36],eax
2219
     ret
2241
     ret
2220
 
2242
 
2221
sysfn_getallmem:
2243
sysfn_getallmem:
2222
     mov  eax,[MEM_AMOUNT]
2244
     mov  eax,[MEM_AMOUNT]
2223
     shr eax, 10
2245
     shr eax, 10
2224
     mov  [esp+36],eax
2246
     mov  [esp+36],eax
2225
     ret
2247
     ret
2226
 
2248
 
2227
uglobal
2249
uglobal
2228
;// mike.dld, 2006-29-01 [
2250
;// mike.dld, 2006-29-01 [
2229
screen_workarea RECT
2251
screen_workarea RECT
2230
;// mike.dld, 2006-29-01 ]
2252
;// mike.dld, 2006-29-01 ]
2231
window_minimize db 0
2253
window_minimize db 0
2232
sound_flag      db 0
2254
sound_flag      db 0
2233
endg
2255
endg
2234
 
2256
 
2235
iglobal
2257
iglobal
2236
version_inf:
2258
version_inf:
2237
  db 0,6,5,0  ; version 0.6.5.0
2259
  db 0,6,5,0  ; version 0.6.5.0
2238
  db UID_KOLIBRI
2260
  db UID_KOLIBRI
2239
  db 'Kolibri',0
2261
  db 'Kolibri',0
2240
version_end:
2262
version_end:
2241
endg
2263
endg
2242
 
2264
 
2243
UID_NONE=0
2265
UID_NONE=0
2244
UID_MENUETOS=1   ;official
2266
UID_MENUETOS=1   ;official
2245
UID_KOLIBRI=2    ;russian
2267
UID_KOLIBRI=2    ;russian
2246
 
2268
 
2247
sys_cachetodiskette:
2269
sys_cachetodiskette:
2248
;    pushad
2270
;    pushad
2249
;    cmp  eax,1
2271
;    cmp  eax,1
2250
;    jne  no_write_all_of_ramdisk
2272
;    jne  no_write_all_of_ramdisk
2251
;    call fdc_writeramdisk
2273
;    call fdc_writeramdisk
2252
;    popad
2274
;    popad
2253
;    ret
2275
;    ret
2254
;  no_write_all_of_ramdisk:
2276
;  no_write_all_of_ramdisk:
2255
;    cmp eax,2
2277
;    cmp eax,2
2256
;    jne no_write_part_of_ramdisk
2278
;    jne no_write_part_of_ramdisk
2257
;    call fdc_commitflush
2279
;    call fdc_commitflush
2258
;    popad
2280
;    popad
2259
;    ret
2281
;    ret
2260
;  no_write_part_of_ramdisk:
2282
;  no_write_part_of_ramdisk:
2261
;    cmp  eax,3
2283
;    cmp  eax,3
2262
;    jne  no_set_fdc
2284
;    jne  no_set_fdc
2263
;    call fdc_set
2285
;    call fdc_set
2264
;    popad
2286
;    popad
2265
;    ret
2287
;    ret
2266
;  no_set_fdc:
2288
;  no_set_fdc:
2267
;    cmp  eax,4
2289
;    cmp  eax,4
2268
;    jne  no_get_fdc
2290
;    jne  no_get_fdc
2269
;    popad
2291
;    popad
2270
;    call fdc_get
2292
;    call fdc_get
2271
;    mov    [esp+36],ecx
2293
;    mov    [esp+36],ecx
2272
;    ret
2294
;    ret
2273
;  no_get_fdc:
2295
;  no_get_fdc:
2274
;    popad
2296
;    popad
2275
;    ret
2297
;    ret
2276
    cmp eax,1
2298
    cmp eax,1
2277
    jne no_floppy_a_save
2299
    jne no_floppy_a_save
2278
    mov   [flp_number],1
2300
    mov   [flp_number],1
2279
    jmp save_image_on_floppy
2301
    jmp save_image_on_floppy
2280
  no_floppy_a_save:
2302
  no_floppy_a_save:
2281
    cmp eax,2
2303
    cmp eax,2
2282
    jne no_floppy_b_save
2304
    jne no_floppy_b_save
2283
    mov   [flp_number],2
2305
    mov   [flp_number],2
2284
  save_image_on_floppy:
2306
  save_image_on_floppy:
2285
    call save_image
2307
    call save_image
2286
    mov  [esp+36],dword 0
2308
    mov  [esp+36],dword 0
2287
    cmp  [FDC_Status],0
2309
    cmp  [FDC_Status],0
2288
    je   yes_floppy_save
2310
    je   yes_floppy_save
2289
  no_floppy_b_save:
2311
  no_floppy_b_save:
2290
    mov [esp+36],dword 1
2312
    mov [esp+36],dword 1
2291
  yes_floppy_save:
2313
  yes_floppy_save:
2292
    ret
2314
    ret
2293
 
2315
 
2294
uglobal
2316
uglobal
2295
;  bgrchanged  dd  0x0
2317
;  bgrchanged  dd  0x0
2296
endg
2318
endg
2297
 
2319
 
2298
sys_background:
2320
sys_background:
2299
 
2321
 
2300
    cmp   eax,1                            ; BACKGROUND SIZE
2322
    cmp   eax,1                            ; BACKGROUND SIZE
2301
    jnz   nosb1
2323
    jnz   nosb1
2302
    cmp   ebx,0
2324
    cmp   ebx,0
2303
    je    sbgrr
2325
    je    sbgrr
2304
    cmp   ecx,0
2326
    cmp   ecx,0
2305
    je    sbgrr
2327
    je    sbgrr
2306
    mov   [display_data-8],ebx
2328
    mov   [display_data-8],ebx
2307
    mov   [display_data-4],ecx
2329
    mov   [display_data-4],ecx
2308
;    mov   [bgrchanged],1
2330
;    mov   [bgrchanged],1
2309
 
2331
 
2310
    pushad
2332
    pushad
2311
; return memory for old background
2333
; return memory for old background
2312
    stdcall kernel_free, [img_background]
2334
    stdcall kernel_free, [img_background]
2313
; calculate RAW size
2335
; calculate RAW size
2314
    xor  eax,eax
2336
    xor  eax,eax
2315
    inc  eax
2337
    inc  eax
2316
    cmp  [display_data-8],eax
2338
    cmp  [display_data-8],eax
2317
    jae   @f
2339
    jae   @f
2318
    mov [display_data-8],eax
2340
    mov [display_data-8],eax
2319
@@:
2341
@@:
2320
    cmp  [display_data-4],eax
2342
    cmp  [display_data-4],eax
2321
    jae   @f
2343
    jae   @f
2322
    mov [display_data-4],eax
2344
    mov [display_data-4],eax
2323
@@:
2345
@@:
2324
    mov  eax,[display_data-8]
2346
    mov  eax,[display_data-8]
2325
    imul eax,[display_data-4]
2347
    imul eax,[display_data-4]
2326
    inc  eax
2348
    inc  eax
2327
    imul eax,3
2349
    imul eax,3
2328
    mov  [mem_BACKGROUND],eax
2350
    mov  [mem_BACKGROUND],eax
2329
; get memory for new background
2351
; get memory for new background
2330
    stdcall kernel_alloc, [mem_BACKGROUND]
2352
    stdcall kernel_alloc, [mem_BACKGROUND]
2331
    test eax, eax
2353
    test eax, eax
2332
    jz .exit_mem
2354
    jz .exit_mem
2333
    mov [img_background], eax
2355
    mov [img_background], eax
2334
.exit_mem:
2356
.exit_mem:
2335
    popad
2357
    popad
2336
 
2358
 
2337
  sbgrr:
2359
  sbgrr:
2338
    ret
2360
    ret
2339
 
2361
 
2340
  nosb1:
2362
  nosb1:
2341
 
2363
 
2342
    cmp   eax,2                            ; SET PIXEL
2364
    cmp   eax,2                            ; SET PIXEL
2343
    jnz   nosb2
2365
    jnz   nosb2
2344
    mov   edx,0x160000-16
2366
    mov   edx,0x160000-16
2345
    cmp   edx,ebx
2367
    cmp   edx,ebx
2346
    jbe   nosb2
2368
    jbe   nosb2
2347
    mov   edx,[ebx]
2369
    mov   edx,[ebx]
2348
    and   edx,0xFF000000 ;255*256*256*256
2370
    and   edx,0xFF000000 ;255*256*256*256
2349
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2371
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2350
    add   edx,ecx
2372
    add   edx,ecx
2351
 
-
 
2352
;    mov   [ebx+IMG_BACKGROUND],edx
2373
    ;mov   [ebx+IMG_BACKGROUND],edx
2353
    push  eax
2374
    push  eax
2354
    mov   eax,[img_background]
2375
    mov   eax,[img_background]
2355
    mov   [ebx+eax],edx
2376
    mov   [ebx+eax],edx
2356
    pop   eax
2377
    pop   eax
2357
;    mov   [bgrchanged],1
2378
;    mov   [bgrchanged],1
2358
    ret
2379
    ret
2359
  nosb2:
2380
  nosb2:
2360
 
2381
 
2361
    cmp   eax,3                            ; DRAW BACKGROUND
2382
    cmp   eax,3                            ; DRAW BACKGROUND
2362
    jnz   nosb3
2383
    jnz   nosb3
2363
draw_background_temp:
2384
draw_background_temp:
2364
;    cmp   [bgrchanged],1 ;0
2385
;    cmp   [bgrchanged],1 ;0
2365
;    je    nosb31
2386
;    je    nosb31
2366
;draw_background_temp:
2387
;draw_background_temp:
2367
;    mov   [bgrchanged],1 ;0
2388
;    mov   [bgrchanged],1 ;0
2368
    mov   [REDRAW_BACKGROUND],byte 1
2389
    mov   [REDRAW_BACKGROUND],byte 1
2369
    mov    [background_defined], 1
2390
    mov    [background_defined], 1
2370
   nosb31:
2391
   nosb31:
2371
    ret
2392
    ret
2372
  nosb3:
2393
  nosb3:
2373
 
2394
 
2374
    cmp   eax,4                            ; TILED / STRETCHED
2395
    cmp   eax,4                            ; TILED / STRETCHED
2375
    jnz   nosb4
2396
    jnz   nosb4
2376
    cmp   ebx,[display_data-12]
2397
    cmp   ebx,[display_data-12]
2377
    je    nosb41
2398
    je    nosb41
2378
    mov   [display_data-12],ebx
2399
    mov   [display_data-12],ebx
2379
;    mov   [bgrchanged],1
2400
;    mov   [bgrchanged],1
2380
   nosb41:
2401
   nosb41:
2381
    ret
2402
    ret
2382
  nosb4:
2403
  nosb4:
2383
 
2404
 
2384
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2405
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2385
    jnz   nosb5
2406
    jnz   nosb5
2386
  ; bughere
2407
  ; bughere
2387
    mov   edi, [TASK_BASE]
2408
    mov   edi, [TASK_BASE]
2388
    add   ebx, [edi+TASKDATA.mem_start]
2409
    add   ebx, [edi+TASKDATA.mem_start]
2389
    mov   eax, ebx
2410
    mov   eax, ebx
2390
    mov   ebx, ecx
2411
    mov   ebx, ecx
2391
    add   ecx, edx
2412
    add   ecx, edx
2392
    add   ebx, [img_background]   ;IMG_BACKGROUND
2413
    add   ebx, [img_background]   ;IMG_BACKGROUND
2393
    mov   ecx, edx
2414
    mov   ecx, edx
2394
    call  memmove
2415
    call  memmove
2395
  .fin:
2416
  .fin:
2396
    ret
2417
    ret
2397
  nosb5:
2418
  nosb5:
-
 
2419
 
2398
    ret
2420
    ret
-
 
2421
 
2399
 
2422
 
2400
align 4
2423
align 4
2401
 
2424
 
2402
sys_getbackground:
2425
sys_getbackground:
2403
 
2426
 
2404
    cmp   eax,1                                  ; SIZE
2427
    cmp   eax,1                                  ; SIZE
2405
    jnz   nogb1
2428
    jnz   nogb1
2406
    mov   eax,[display_data-8]
2429
    mov   eax,[display_data-8]
2407
    shl   eax,16
2430
    shl   eax,16
2408
    mov   ax,[display_data-4]
2431
    mov   ax,[display_data-4]
2409
    mov   [esp+36],eax
2432
    mov   [esp+36],eax
2410
    ret
2433
    ret
2411
  nogb1:
2434
  nogb1:
2412
 
2435
 
2413
    cmp   eax,2                                  ; PIXEL
2436
    cmp   eax,2                                  ; PIXEL
2414
    jnz   nogb2
2437
    jnz   nogb2
2415
;    mov   edx,0x160000-16
2438
;    mov   edx,0x160000-16
2416
;    cmp   edx,ebx
2439
;    cmp   edx,ebx
2417
;    jbe   nogb2
2440
;    jbe   nogb2
2418
;    mov   eax, [ebx+IMG_BACKGROUND]
2441
;    mov   eax, [ebx+IMG_BACKGROUND]
2419
    mov   eax,[img_background]
2442
    mov   eax,[img_background]
2420
    mov   eax,[ebx+eax]
2443
    mov   eax,[ebx+eax]
2421
 
2444
 
2422
    and   eax, 0xFFFFFF
2445
    and   eax, 0xFFFFFF
2423
    mov   [esp+36],eax
2446
    mov   [esp+36],eax
2424
    ret
2447
    ret
2425
  nogb2:
2448
  nogb2:
2426
 
2449
 
2427
    cmp   eax,4                                  ; TILED / STRETCHED
2450
    cmp   eax,4                                  ; TILED / STRETCHED
2428
    jnz   nogb4
2451
    jnz   nogb4
2429
    mov   eax,[display_data-12]
2452
    mov   eax,[display_data-12]
2430
  nogb4:
2453
  nogb4:
2431
    mov   [esp+36],eax
2454
    mov   [esp+36],eax
2432
    ret
2455
    ret
2433
 
2456
 
2434
 
2457
 
2435
align 4
2458
align 4
2436
 
2459
 
2437
sys_getkey:
2460
sys_getkey:
2438
    mov   [esp+36],dword 1
2461
    mov   [esp+36],dword 1
2439
; test main buffer
2462
; test main buffer
2440
    mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2463
    mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2441
    movzx ecx,word [WIN_STACK + ebx * 2]
2464
    movzx ecx,word [WIN_STACK + ebx * 2]
2442
    mov   edx,[TASK_COUNT]
2465
    mov   edx,[TASK_COUNT]
2443
    cmp   ecx,edx
2466
    cmp   ecx,edx
2444
    jne   .finish
2467
    jne   .finish
2445
    cmp   [KEY_COUNT],byte 0
2468
    cmp   [KEY_COUNT],byte 0
2446
    je    .finish
2469
    je    .finish
2447
    movzx eax,byte [KEY_BUFF]
2470
    movzx eax,byte [KEY_BUFF]
2448
    shl   eax,8
2471
    shl   eax,8
2449
    push  eax
2472
    push  eax
2450
    dec   byte [KEY_COUNT]
2473
    dec   byte [KEY_COUNT]
2451
    and   byte [KEY_COUNT],127
2474
    and   byte [KEY_COUNT],127
2452
    movzx ecx,byte [KEY_COUNT]
2475
    movzx ecx,byte [KEY_COUNT]
2453
    add   ecx,2
2476
    add   ecx,2
2454
 ;   mov   esi,0xf402
2477
 ;   mov   esi,0xf402
2455
 ;   mov   edi,0xf401
2478
 ;   mov   edi,0xf401
2456
 ;   cld
2479
 ;   cld
2457
 ;  rep   movsb
2480
 ;  rep   movsb
2458
    mov   eax, KEY_BUFF+1
2481
    mov   eax, KEY_BUFF+1
2459
    mov   ebx, KEY_BUFF
2482
    mov   ebx, KEY_BUFF
2460
    call  memmove
2483
    call  memmove
2461
    pop   eax
2484
    pop   eax
2462
.ret_eax:
2485
.ret_eax:
2463
    mov   [esp+36],eax
2486
    mov   [esp+36],eax
2464
    ret
2487
    ret
2465
 .finish:
2488
 .finish:
2466
; test hotkeys buffer
2489
; test hotkeys buffer
2467
        mov     ecx, hotkey_buffer
2490
        mov     ecx, hotkey_buffer
2468
@@:
2491
@@:
2469
        cmp     [ecx], ebx
2492
        cmp     [ecx], ebx
2470
        jz      .found
2493
        jz      .found
2471
        add     ecx, 8
2494
        add     ecx, 8
2472
        cmp     ecx, hotkey_buffer+120*8
2495
        cmp     ecx, hotkey_buffer+120*8
2473
        jb      @b
2496
        jb      @b
2474
        ret
2497
        ret
2475
.found:
2498
.found:
2476
        mov     ax, [ecx+6]
2499
        mov     ax, [ecx+6]
2477
        shl     eax, 16
2500
        shl     eax, 16
2478
        mov     ah, [ecx+4]
2501
        mov     ah, [ecx+4]
2479
        mov     al, 2
2502
        mov     al, 2
2480
        and     dword [ecx+4], 0
2503
        and     dword [ecx+4], 0
2481
        and     dword [ecx], 0
2504
        and     dword [ecx], 0
2482
        jmp     .ret_eax
2505
        jmp     .ret_eax
2483
 
2506
 
2484
align 4
2507
align 4
2485
 
2508
 
2486
sys_getbutton:
2509
sys_getbutton:
2487
 
2510
 
2488
    mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2511
    mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2489
    mov   [esp+36],dword 1
2512
    mov   [esp+36],dword 1
2490
    movzx ecx, word [WIN_STACK + ebx * 2]
2513
    movzx ecx, word [WIN_STACK + ebx * 2]
2491
    mov   edx, [TASK_COUNT] ; less than 256 processes
2514
    mov   edx, [TASK_COUNT] ; less than 256 processes
2492
    cmp   ecx,edx
2515
    cmp   ecx,edx
2493
    jne   .exit
2516
    jne   .exit
2494
    movzx eax,byte [BTN_COUNT]
2517
    movzx eax,byte [BTN_COUNT]
2495
    test  eax,eax
2518
    test  eax,eax
2496
    jz    .exit
2519
    jz    .exit
2497
    mov   eax,[BTN_BUFF]
2520
    mov   eax,[BTN_BUFF]
2498
    shl   eax,8
2521
    shl   eax,8
2499
    mov   [BTN_COUNT],byte 0
2522
    mov   [BTN_COUNT],byte 0
2500
    mov   [esp+36],eax
2523
    mov   [esp+36],eax
2501
 .exit:
2524
 .exit:
2502
    ret
2525
    ret
2503
 
2526
 
2504
 
2527
 
2505
align 4
2528
align 4
2506
 
2529
 
2507
sys_cpuusage:
2530
sys_cpuusage:
2508
 
2531
 
2509
;  RETURN:
2532
;  RETURN:
2510
;
2533
;
2511
;  +00 dword     process cpu usage
2534
;  +00 dword     process cpu usage
2512
;  +04  word     position in windowing stack
2535
;  +04  word     position in windowing stack
2513
;  +06  word     windowing stack value at current position (cpu nro)
2536
;  +06  word     windowing stack value at current position (cpu nro)
2514
;  +10 12 bytes  name
2537
;  +10 12 bytes  name
2515
;  +22 dword     start in mem
2538
;  +22 dword     start in mem
2516
;  +26 dword     used mem
2539
;  +26 dword     used mem
2517
;  +30 dword     PID , process idenfification number
2540
;  +30 dword     PID , process idenfification number
2518
;
2541
;
2519
 
2542
 
2520
    mov  edi,[TASK_BASE]   ; eax = return area
2543
    mov  edi,[TASK_BASE]   ; eax = return area
2521
    add  eax,[edi + TASKDATA.mem_start]
2544
    add  eax,[edi + TASKDATA.mem_start]
2522
 
2545
 
2523
    cmp  ebx,-1         ; who am I ?
2546
    cmp  ebx,-1         ; who am I ?
2524
    jne  no_who_am_i
2547
    jne  no_who_am_i
2525
    mov  ebx,[CURRENT_TASK]
2548
    mov  ebx,[CURRENT_TASK]
2526
  no_who_am_i:
2549
  no_who_am_i:
2527
 
2550
 
2528
    push eax            ; return area
2551
    push eax            ; return area
2529
    push ebx            ; process number
2552
    push ebx            ; process number
2530
 
2553
 
2531
    push ebx
2554
    push ebx
2532
    push ebx
2555
    push ebx
2533
    push eax
2556
    push eax
2534
 
2557
 
2535
    ; return memory usage
2558
    ; return memory usage
2536
 
2559
 
2537
    xor  edx,edx
2560
    xor  edx,edx
2538
    mov  eax,0x20
2561
    mov  eax,0x20
2539
    mul  ebx
2562
    mul  ebx
2540
    add  eax,CURRENT_TASK+TASKDATA.cpu_usage
2563
    add  eax,CURRENT_TASK+TASKDATA.cpu_usage
2541
    mov  ebx,eax
2564
    mov  ebx,eax
2542
    pop  eax
2565
    pop  eax
2543
    mov  ecx,[ebx]
2566
    mov  ecx,[ebx]
2544
    mov  [eax],ecx
2567
    mov  [eax],ecx
2545
    pop  ebx
2568
    pop  ebx
2546
    mov  cx, [WIN_STACK + ebx * 2]
2569
    mov  cx, [WIN_STACK + ebx * 2]
2547
    mov  [eax+4],cx
2570
    mov  [eax+4],cx
2548
    mov  cx, [WIN_POS + ebx * 2]
2571
    mov  cx, [WIN_POS + ebx * 2]
2549
    mov  [eax+6],cx
2572
    mov  [eax+6],cx
2550
    push eax
2573
    push eax
2551
    mov  eax,ebx
2574
    mov  eax,ebx
2552
    shl  eax,8
2575
    shl  eax,8
2553
    add  eax,SLOT_BASE+APPDATA.app_name
2576
    add  eax,SLOT_BASE+APPDATA.app_name
2554
    pop  ebx
2577
    pop  ebx
2555
    add  ebx,10
2578
    add  ebx,10
2556
    mov  ecx,11
2579
    mov  ecx,11
2557
    call memmove
2580
    call memmove
2558
 
2581
 
2559
    ; memory usage
2582
    ; memory usage
2560
 
2583
 
2561
    xor    eax,eax
2584
    xor    eax,eax
2562
    mov    edx,0x100000*16
2585
    mov    edx,0x100000*16
2563
    pop    ecx                                   ; get gdt of tss
2586
    pop    ecx                                   ; get gdt of tss
2564
    cmp    ecx,1
2587
    cmp    ecx,1
2565
    je     os_mem
2588
    je     os_mem
2566
    shl    ecx,8
2589
    shl    ecx,8
2567
    mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
2590
    mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
2568
    mov    eax,std_application_base_address
2591
    mov    eax,std_application_base_address
2569
    ; eax run base -> edx used memory
2592
    ; eax run base -> edx used memory
2570
  os_mem:
2593
  os_mem:
2571
    dec    edx
2594
    dec    edx
2572
    mov    [ebx+12],eax
2595
    mov    [ebx+12],eax
2573
    mov    [ebx+16],edx
2596
    mov    [ebx+16],edx
2574
 
2597
 
2575
    ; PID (+30)
2598
    ; PID (+30)
2576
 
2599
 
2577
    mov    eax,[esp]
2600
    mov    eax,[esp]
2578
    shl    eax,5
2601
    shl    eax,5
2579
    add    eax,CURRENT_TASK+TASKDATA.pid
2602
    add    eax,CURRENT_TASK+TASKDATA.pid
2580
    mov    eax,[eax]
2603
    mov    eax,[eax]
2581
    mov    [ebx+20],eax
2604
    mov    [ebx+20],eax
2582
 
2605
 
2583
    ; window position and size
2606
    ; window position and size
2584
 
2607
 
2585
    mov    esi,[esp]
2608
    mov    esi,[esp]
2586
    shl    esi,5
2609
    shl    esi,5
2587
    add    esi,window_data + WDATA.box
2610
    add    esi,window_data + WDATA.box
2588
    mov    edi,[esp+4]
2611
    mov    edi,[esp+4]
2589
    add    edi,34
2612
    add    edi,34
2590
    mov    ecx,4
2613
    mov    ecx,4
2591
    cld
2614
    cld
2592
    rep    movsd
2615
    rep    movsd
2593
 
2616
 
2594
    ; Process state (+50)
2617
    ; Process state (+50)
2595
 
2618
 
2596
    mov    eax,[esp]
2619
    mov    eax,[esp]
2597
    shl    eax,5
2620
    shl    eax,5
2598
    add    eax,CURRENT_TASK+TASKDATA.state
2621
    add    eax,CURRENT_TASK+TASKDATA.state
2599
    mov    eax,[eax]
2622
    mov    eax,[eax]
2600
    mov    [ebx+40],ax
2623
    mov    [ebx+40],ax
2601
 
2624
 
2602
    ; Window client area box
2625
    ; Window client area box
2603
 
2626
 
2604
    mov    esi,[esp]
2627
    mov    esi,[esp]
2605
    shl    esi,8
2628
    shl    esi,8
2606
    add    esi,SLOT_BASE+APPDATA.wnd_clientbox
2629
    add    esi,SLOT_BASE+APPDATA.wnd_clientbox
2607
    lea    edi,[ebx+44]
2630
    lea    edi,[ebx+44]
2608
    mov    ecx,4
2631
    mov    ecx,4
2609
    rep    movsd
2632
    rep    movsd
2610
 
2633
 
2611
    ; Window state
2634
    ; Window state
2612
 
2635
 
2613
    mov    esi,[esp]
2636
    mov    esi,[esp]
2614
    shl    esi,5
2637
    shl    esi,5
2615
    add    esi,window_data + WDATA.box
2638
    add    esi,window_data + WDATA.box
2616
    mov    al,[esi+WDATA.fl_wstate]
2639
    mov    al,[esi+WDATA.fl_wstate]
2617
    mov    [edi],al
2640
    mov    [edi],al
2618
 
2641
 
2619
    pop    ebx
2642
    pop    ebx
2620
    pop    eax
2643
    pop    eax
2621
 
2644
 
2622
    ; return number of processes
2645
    ; return number of processes
2623
 
2646
 
2624
    mov    eax,[TASK_COUNT]
2647
    mov    eax,[TASK_COUNT]
2625
    mov    [esp+36],eax
2648
    mov    [esp+36],eax
2626
    ret
2649
    ret
2627
 
2650
 
2628
align 4
2651
align 4
2629
sys_clock:
2652
sys_clock:
2630
        cli
2653
        cli
2631
  ; Mikhail Lisovin  xx Jan 2005
2654
  ; Mikhail Lisovin  xx Jan 2005
2632
  @@:   mov   al, 10
2655
  @@:   mov   al, 10
2633
        out   0x70, al
2656
        out   0x70, al
2634
        in    al, 0x71
2657
        in    al, 0x71
2635
        test  al, al
2658
        test  al, al
2636
        jns   @f
2659
        jns   @f
2637
        mov   esi, 1
2660
        mov   esi, 1
2638
        call  delay_ms
2661
        call  delay_ms
2639
        jmp   @b
2662
        jmp   @b
2640
  @@:
2663
  @@:
2641
  ; end Lisovin's fix
2664
  ; end Lisovin's fix
2642
 
2665
 
2643
        xor   al,al           ; seconds
2666
        xor   al,al           ; seconds
2644
        out   0x70,al
2667
        out   0x70,al
2645
        in    al,0x71
2668
        in    al,0x71
2646
        movzx ecx,al
2669
        movzx ecx,al
2647
        mov   al,02           ; minutes
2670
        mov   al,02           ; minutes
2648
        shl   ecx,16
2671
        shl   ecx,16
2649
        out   0x70,al
2672
        out   0x70,al
2650
        in    al,0x71
2673
        in    al,0x71
2651
        movzx edx,al
2674
        movzx edx,al
2652
        mov   al,04           ; hours
2675
        mov   al,04           ; hours
2653
        shl   edx,8
2676
        shl   edx,8
2654
        out   0x70,al
2677
        out   0x70,al
2655
        in    al,0x71
2678
        in    al,0x71
2656
        add   ecx,edx
2679
        add   ecx,edx
2657
        movzx edx,al
2680
        movzx edx,al
2658
        add   ecx,edx
2681
        add   ecx,edx
2659
        sti
2682
        sti
2660
        mov   [esp+36],ecx
2683
        mov   [esp+36],ecx
2661
        ret
2684
        ret
2662
 
2685
 
2663
 
2686
 
2664
align 4
2687
align 4
2665
 
2688
 
2666
sys_date:
2689
sys_date:
2667
 
2690
 
2668
        cli
2691
        cli
2669
 
2692
 
2670
  @@:   mov   al, 10
2693
  @@:   mov   al, 10
2671
        out   0x70, al
2694
        out   0x70, al
2672
        in    al, 0x71
2695
        in    al, 0x71
2673
        test  al, al
2696
        test  al, al
2674
        jns   @f
2697
        jns   @f
2675
        mov   esi, 1
2698
        mov   esi, 1
2676
        call  delay_ms
2699
        call  delay_ms
2677
        jmp   @b
2700
        jmp   @b
2678
  @@:
2701
  @@:
2679
 
2702
 
2680
        mov     ch,0
2703
        mov     ch,0
2681
        mov     al,7            ; date
2704
        mov     al,7            ; date
2682
        out     0x70,al
2705
        out     0x70,al
2683
        in      al,0x71
2706
        in      al,0x71
2684
        mov     cl,al
2707
        mov     cl,al
2685
        mov     al,8            ; month
2708
        mov     al,8            ; month
2686
        shl     ecx,16
2709
        shl     ecx,16
2687
        out     0x70,al
2710
        out     0x70,al
2688
        in      al,0x71
2711
        in      al,0x71
2689
        mov     ch,al
2712
        mov     ch,al
2690
        mov     al,9            ; year
2713
        mov     al,9            ; year
2691
        out     0x70,al
2714
        out     0x70,al
2692
        in      al,0x71
2715
        in      al,0x71
2693
        mov     cl,al
2716
        mov     cl,al
2694
        sti
2717
        sti
2695
        mov     [esp+36],ecx
2718
        mov     [esp+36],ecx
2696
        ret
2719
        ret
2697
 
2720
 
2698
 
2721
 
2699
; redraw status
2722
; redraw status
2700
 
2723
 
2701
sys_redrawstat:
2724
sys_redrawstat:
2702
 
2725
 
2703
    cmp  eax,1
2726
    cmp  eax,1
2704
    jne  no_widgets_away
2727
    jne  no_widgets_away
2705
 
2728
 
2706
    ; buttons away
2729
    ; buttons away
2707
 
2730
 
2708
    mov   ecx,[CURRENT_TASK]
2731
    mov   ecx,[CURRENT_TASK]
2709
 
2732
 
2710
  sys_newba2:
2733
  sys_newba2:
2711
 
2734
 
2712
    mov   edi,[BTN_ADDR]
2735
    mov   edi,[BTN_ADDR]
2713
    cmp   [edi],dword 0  ; empty button list ?
2736
    cmp   [edi],dword 0  ; empty button list ?
2714
    je    end_of_buttons_away
2737
    je    end_of_buttons_away
2715
 
2738
 
2716
    movzx ebx,word [edi]
2739
    movzx ebx,word [edi]
2717
    inc   ebx
2740
    inc   ebx
2718
 
2741
 
2719
    mov   eax,edi
2742
    mov   eax,edi
2720
 
2743
 
2721
  sys_newba:
2744
  sys_newba:
2722
 
2745
 
2723
    dec   ebx
2746
    dec   ebx
2724
    jz    end_of_buttons_away
2747
    jz    end_of_buttons_away
2725
 
2748
 
2726
    add   eax,0x10
2749
    add   eax,0x10
2727
    cmp   cx,[eax]
2750
    cmp   cx,[eax]
2728
    jnz   sys_newba
2751
    jnz   sys_newba
2729
 
2752
 
2730
    push  eax ebx ecx
2753
    push  eax ebx ecx
2731
    mov   ecx,ebx
2754
    mov   ecx,ebx
2732
    inc   ecx
2755
    inc   ecx
2733
    shl   ecx,4
2756
    shl   ecx,4
2734
    mov   ebx,eax
2757
    mov   ebx,eax
2735
    add   eax,0x10
2758
    add   eax,0x10
2736
    call  memmove
2759
    call  memmove
2737
    dec   dword [edi]
2760
    dec   dword [edi]
2738
    pop   ecx ebx eax
2761
    pop   ecx ebx eax
2739
 
2762
 
2740
    jmp   sys_newba2
2763
    jmp   sys_newba2
2741
 
2764
 
2742
  end_of_buttons_away:
2765
  end_of_buttons_away:
2743
 
2766
 
2744
    ret
2767
    ret
2745
 
2768
 
2746
  no_widgets_away:
2769
  no_widgets_away:
2747
 
2770
 
2748
    cmp   eax,2
2771
    cmp   eax,2
2749
    jnz   srl1
2772
    jnz   srl1
2750
 
2773
 
2751
    mov   edx,[TASK_BASE]      ; return whole screen draw area for this app
2774
    mov   edx,[TASK_BASE]      ; return whole screen draw area for this app
2752
    add   edx,draw_data-CURRENT_TASK
2775
    add   edx,draw_data-CURRENT_TASK
2753
    mov   [edx+RECT.left], 0
2776
    mov   [edx+RECT.left], 0
2754
    mov   [edx+RECT.top], 0
2777
    mov   [edx+RECT.top], 0
2755
    mov   eax,[ScreenWidth]
2778
    mov   eax,[ScreenWidth]
2756
    mov   [edx+RECT.right],eax
2779
    mov   [edx+RECT.right],eax
2757
    mov   eax,[ScreenHeight]
2780
    mov   eax,[ScreenHeight]
2758
    mov   [edx+RECT.bottom],eax
2781
    mov   [edx+RECT.bottom],eax
2759
 
2782
 
2760
    mov   edi,[TASK_BASE]
2783
    mov   edi,[TASK_BASE]
2761
    or    [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2784
    or    [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2762
 
2785
 
2763
    call  sys_window_mouse
2786
    call  sys_window_mouse
2764
 
2787
 
2765
    ret
2788
    ret
2766
 
2789
 
2767
  srl1:
2790
  srl1:
2768
 
2791
 
2769
    ret
2792
    ret
2770
 
2793
 
2771
 
2794
 
2772
sys_drawwindow:
2795
sys_drawwindow:
2773
 
2796
 
2774
    mov   edi,ecx
2797
    mov   edi,ecx
2775
    shr   edi,16+8
2798
    shr   edi,16+8
2776
    and   edi,15
2799
    and   edi,15
2777
 
2800
 
2778
    cmp   edi,0   ; type I    - original style
2801
    cmp   edi,0   ; type I    - original style
2779
    jne   nosyswI
2802
    jne   nosyswI
2780
    inc   [mouse_pause]
2803
    inc   [mouse_pause]
2781
    call  [disable_mouse]
2804
    call  [disable_mouse]
2782
    call  sys_set_window
2805
    call  sys_set_window
2783
    call  [disable_mouse]
2806
    call  [disable_mouse]
2784
    call  drawwindow_I
2807
    call  drawwindow_I
2785
    ;dec   [mouse_pause]
2808
    ;dec   [mouse_pause]
2786
    ;call   [draw_pointer]
2809
    ;call   [draw_pointer]
2787
    ;ret
2810
    ;ret
2788
    jmp   draw_window_caption.2
2811
    jmp   draw_window_caption.2
2789
  nosyswI:
2812
  nosyswI:
2790
 
2813
 
2791
    cmp   edi,1   ; type II   - only reserve area, no draw
2814
    cmp   edi,1   ; type II   - only reserve area, no draw
2792
    jne   nosyswII
2815
    jne   nosyswII
2793
    inc   [mouse_pause]
2816
    inc   [mouse_pause]
2794
    call  [disable_mouse]
2817
    call  [disable_mouse]
2795
    call  sys_set_window
2818
    call  sys_set_window
2796
    call  [disable_mouse]
2819
    call  [disable_mouse]
2797
    call  sys_window_mouse
2820
    call  sys_window_mouse
2798
    dec   [mouse_pause]
2821
    dec   [mouse_pause]
2799
    call   [draw_pointer]
2822
    call   [draw_pointer]
2800
    ret
2823
    ret
2801
  nosyswII:
2824
  nosyswII:
2802
 
2825
 
2803
    cmp   edi,2   ; type III  - new style
2826
    cmp   edi,2   ; type III  - new style
2804
    jne   nosyswIII
2827
    jne   nosyswIII
2805
    inc   [mouse_pause]
2828
    inc   [mouse_pause]
2806
    call  [disable_mouse]
2829
    call  [disable_mouse]
2807
    call  sys_set_window
2830
    call  sys_set_window
2808
    call  [disable_mouse]
2831
    call  [disable_mouse]
2809
    call  drawwindow_III
2832
    call  drawwindow_III
2810
    ;dec   [mouse_pause]
2833
    ;dec   [mouse_pause]
2811
    ;call   [draw_pointer]
2834
    ;call   [draw_pointer]
2812
    ;ret
2835
    ;ret
2813
    jmp   draw_window_caption.2
2836
    jmp   draw_window_caption.2
2814
  nosyswIII:
2837
  nosyswIII:
2815
 
2838
 
2816
    cmp   edi,3   ; type IV - skinned window
2839
    cmp   edi,3   ; type IV - skinned window
2817
    jne   nosyswIV
2840
    jne   nosyswIV
2818
 
2841
 
2819
    ; parameter for drawwindow_IV
2842
    ; parameter for drawwindow_IV
2820
    push  0
2843
    push  0
2821
    mov   edi, [TASK_COUNT]
2844
    mov   edi, [TASK_COUNT]
2822
    movzx edi, word [WIN_POS + edi*2]
2845
    movzx edi, word [WIN_POS + edi*2]
2823
    cmp   edi, [CURRENT_TASK]
2846
    cmp   edi, [CURRENT_TASK]
2824
    jne   @f
2847
    jne   @f
2825
    inc   dword [esp]
2848
    inc   dword [esp]
2826
 @@:
2849
 @@:
2827
 
2850
 
2828
    inc   [mouse_pause]
2851
    inc   [mouse_pause]
2829
    call  [disable_mouse]
2852
    call  [disable_mouse]
2830
    call  sys_set_window
2853
    call  sys_set_window
2831
    call  [disable_mouse]
2854
    call  [disable_mouse]
2832
    call  drawwindow_IV
2855
    call  drawwindow_IV
2833
    ;dec   [mouse_pause]
2856
    ;dec   [mouse_pause]
2834
    ;call   [draw_pointer]
2857
    ;call   [draw_pointer]
2835
    ;ret
2858
    ;ret
2836
    jmp   draw_window_caption.2
2859
    jmp   draw_window_caption.2
2837
  nosyswIV:
2860
  nosyswIV:
2838
 
2861
 
2839
    ret
2862
    ret
2840
 
2863
 
2841
 
2864
 
2842
draw_window_caption:
2865
draw_window_caption:
2843
        inc     [mouse_pause]
2866
        inc     [mouse_pause]
2844
        call    [disable_mouse]
2867
        call    [disable_mouse]
2845
 
2868
 
2846
        xor     eax,eax
2869
        xor     eax,eax
2847
        mov     edx,[TASK_COUNT]
2870
        mov     edx,[TASK_COUNT]
2848
        movzx   edx,word[WIN_POS+edx*2]
2871
        movzx   edx,word[WIN_POS+edx*2]
2849
        cmp     edx,[CURRENT_TASK]
2872
        cmp     edx,[CURRENT_TASK]
2850
        jne     @f
2873
        jne     @f
2851
        inc     eax
2874
        inc     eax
2852
    @@: mov     edx,[CURRENT_TASK]
2875
    @@: mov     edx,[CURRENT_TASK]
2853
        shl     edx,5
2876
        shl     edx,5
2854
        add     edx,window_data
2877
        add     edx,window_data
2855
        movzx   ebx,[edx+WDATA.fl_wstyle]
2878
        movzx   ebx,[edx+WDATA.fl_wstyle]
2856
        and     bl,0x0F
2879
        and     bl,0x0F
2857
        cmp     bl,3
2880
        cmp     bl,3
2858
        jne     .not_style_3
2881
        jne     .not_style_3
2859
 
2882
 
2860
        push    edx
2883
        push    edx
2861
        call    drawwindow_IV_caption
2884
        call    drawwindow_IV_caption
2862
        add     esp,4
2885
        add     esp,4
2863
        jmp     .2
2886
        jmp     .2
2864
 
2887
 
2865
  .not_style_3:
2888
  .not_style_3:
2866
        cmp     bl,2
2889
        cmp     bl,2
2867
        jne     .not_style_2
2890
        jne     .not_style_2
2868
 
2891
 
2869
        call    drawwindow_III_caption
2892
        call    drawwindow_III_caption
2870
        jmp     .2
2893
        jmp     .2
2871
 
2894
 
2872
  .not_style_2:
2895
  .not_style_2:
2873
        cmp     bl,0
2896
        cmp     bl,0
2874
        jne     .2
2897
        jne     .2
2875
 
2898
 
2876
        call    drawwindow_I_caption
2899
        call    drawwindow_I_caption
2877
 
2900
 
2878
;--------------------------------------------------------------
2901
;--------------------------------------------------------------
2879
  .2:   ;jmp     @f
2902
  .2:   ;jmp     @f
2880
        mov     edi,[CURRENT_TASK]
2903
        mov     edi,[CURRENT_TASK]
2881
        shl     edi,5
2904
        shl     edi,5
2882
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2905
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2883
        jz      @f
2906
        jz      @f
2884
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2907
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2885
        or      ecx,ecx
2908
        or      ecx,ecx
2886
        jz      @f
2909
        jz      @f
2887
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
2910
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
2888
 
2911
 
2889
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2912
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2890
        and     al,0x0F
2913
        and     al,0x0F
2891
        cmp     al,3
2914
        cmp     al,3
2892
        jne     .not_skinned
2915
        jne     .not_skinned
2893
 
2916
 
2894
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2917
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2895
        mov     bp,word[edi+window_data+WDATA.box.top]
2918
        mov     bp,word[edi+window_data+WDATA.box.top]
2896
        movzx   eax,word[edi+window_data+WDATA.box.width]
2919
        movzx   eax,word[edi+window_data+WDATA.box.width]
2897
        sub     ax,[_skinmargins.left]
2920
        sub     ax,[_skinmargins.left]
2898
        sub     ax,[_skinmargins.right]
2921
        sub     ax,[_skinmargins.right]
2899
        cwde
2922
        cwde
2900
        cdq
2923
        cdq
2901
        mov     ebx,6
2924
        mov     ebx,6
2902
        idiv    ebx
2925
        idiv    ebx
2903
        or      eax,eax
2926
        or      eax,eax
2904
        js      @f
2927
        js      @f
2905
        mov     edx,eax
2928
        mov     edx,eax
2906
        mov     eax,dword[_skinmargins.left-2]
2929
        mov     eax,dword[_skinmargins.left-2]
2907
        mov     ax,word[_skinh]
2930
        mov     ax,word[_skinh]
2908
        sub     ax,[_skinmargins.bottom]
2931
        sub     ax,[_skinmargins.bottom]
2909
        sub     ax,[_skinmargins.top]
2932
        sub     ax,[_skinmargins.top]
2910
        sar     ax,1
2933
        sar     ax,1
2911
        adc     ax,0
2934
        adc     ax,0
2912
        add     ax,[_skinmargins.top]
2935
        add     ax,[_skinmargins.top]
2913
        add     ax,-3
2936
        add     ax,-3
2914
        add     eax,ebp
2937
        add     eax,ebp
2915
        jmp     .dodraw
2938
        jmp     .dodraw
2916
 
2939
 
2917
  .not_skinned:
2940
  .not_skinned:
2918
        cmp     al,1
2941
        cmp     al,1
2919
        je      @f
2942
        je      @f
2920
 
2943
 
2921
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2944
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2922
        mov     bp,word[edi+window_data+WDATA.box.top]
2945
        mov     bp,word[edi+window_data+WDATA.box.top]
2923
        movzx   eax,word[edi+window_data+WDATA.box.width]
2946
        movzx   eax,word[edi+window_data+WDATA.box.width]
2924
        sub     eax,16
2947
        sub     eax,16
2925
        cwde
2948
        cwde
2926
        cdq
2949
        cdq
2927
        mov     ebx,6
2950
        mov     ebx,6
2928
        idiv    ebx
2951
        idiv    ebx
2929
        or      eax,eax
2952
        or      eax,eax
2930
        js      @f
2953
        js      @f
2931
        mov     edx,eax
2954
        mov     edx,eax
2932
        mov     eax,0x00080007
2955
        mov     eax,0x00080007
2933
        add     eax,ebp
2956
        add     eax,ebp
2934
.dodraw:
2957
.dodraw:
2935
        mov     ebx,[common_colours+16];0x00FFFFFF
2958
        mov     ebx,[common_colours+16];0x00FFFFFF
2936
        or      ebx, 0x80000000
2959
        or      ebx, 0x80000000
2937
        xor     edi,edi
2960
        xor     edi,edi
2938
        call    dtext
2961
        call    dtext
2939
 
2962
 
2940
    @@:
2963
    @@:
2941
;--------------------------------------------------------------
2964
;--------------------------------------------------------------
2942
        dec     [mouse_pause]
2965
        dec     [mouse_pause]
2943
        call    [draw_pointer]
2966
        call    [draw_pointer]
2944
        ret
2967
        ret
2945
 
2968
 
2946
iglobal
2969
iglobal
2947
align 4
2970
align 4
2948
window_topleft dd \
2971
window_topleft dd \
2949
  1, 21,\
2972
  1, 21,\
2950
  0,  0,\
2973
  0,  0,\
2951
  5, 20,\
2974
  5, 20,\
2952
  5,  ?
2975
  5,  ?
2953
endg
2976
endg
2954
 
2977
 
2955
set_window_clientbox:
2978
set_window_clientbox:
2956
        push    eax ecx edi
2979
        push    eax ecx edi
2957
 
2980
 
2958
        mov     eax,[_skinh]
2981
        mov     eax,[_skinh]
2959
        mov     [window_topleft+4*7],eax
2982
        mov     [window_topleft+4*7],eax
2960
 
2983
 
2961
        mov     ecx,edi
2984
        mov     ecx,edi
2962
        sub     edi,window_data
2985
        sub     edi,window_data
2963
        shl     edi,3
2986
        shl     edi,3
2964
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
2987
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
2965
        jz      @f
2988
        jz      @f
2966
 
2989
 
2967
        movzx   eax,[ecx+WDATA.fl_wstyle]
2990
        movzx   eax,[ecx+WDATA.fl_wstyle]
2968
        and     eax,0x0F
2991
        and     eax,0x0F
2969
        mov     eax,[eax*8+window_topleft+0]
2992
        mov     eax,[eax*8+window_topleft+0]
2970
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
2993
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
2971
        shl     eax,1
2994
        shl     eax,1
2972
        neg     eax
2995
        neg     eax
2973
        add     eax,[ecx+WDATA.box.width]
2996
        add     eax,[ecx+WDATA.box.width]
2974
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
2997
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
2975
 
2998
 
2976
        movzx   eax,[ecx+WDATA.fl_wstyle]
2999
        movzx   eax,[ecx+WDATA.fl_wstyle]
2977
        and     eax,0x0F
3000
        and     eax,0x0F
2978
        push    [eax*8+window_topleft+0]
3001
        push    [eax*8+window_topleft+0]
2979
        mov     eax,[eax*8+window_topleft+4]
3002
        mov     eax,[eax*8+window_topleft+4]
2980
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3003
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
2981
        neg     eax
3004
        neg     eax
2982
        sub     eax,[esp]
3005
        sub     eax,[esp]
2983
        add     eax,[ecx+WDATA.box.height]
3006
        add     eax,[ecx+WDATA.box.height]
2984
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3007
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
2985
        add     esp,4
3008
        add     esp,4
2986
 
3009
 
2987
        pop     edi ecx eax
3010
        pop     edi ecx eax
2988
        ret
3011
        ret
2989
    @@:
3012
    @@:
2990
        xor     eax,eax
3013
        xor     eax,eax
2991
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3014
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
2992
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3015
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
2993
        mov     eax,[ecx+WDATA.box.width]
3016
        mov     eax,[ecx+WDATA.box.width]
2994
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3017
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
2995
        mov     eax,[ecx+WDATA.box.height]
3018
        mov     eax,[ecx+WDATA.box.height]
2996
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3019
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
2997
 
3020
 
2998
        pop     edi ecx eax
3021
        pop     edi ecx eax
2999
        ret
3022
        ret
3000
 
3023
 
3001
sys_set_window:
3024
sys_set_window:
3002
 
3025
 
3003
    mov   edi,[CURRENT_TASK]
3026
    mov   edi,[CURRENT_TASK]
3004
    shl   edi,5
3027
    shl   edi,5
3005
    add   edi,window_data
3028
    add   edi,window_data
3006
 
3029
 
3007
    ; colors
3030
    ; colors
3008
    mov   [edi+WDATA.cl_workarea],ecx
3031
    mov   [edi+WDATA.cl_workarea],ecx
3009
    mov   [edi+WDATA.cl_titlebar],edx
3032
    mov   [edi+WDATA.cl_titlebar],edx
3010
    mov   [edi+WDATA.cl_frames],esi
3033
    mov   [edi+WDATA.cl_frames],esi
3011
 
3034
 
3012
    ; check flag (?)
3035
    ; check flag (?)
3013
    test  [edi+WDATA.fl_wdrawn],1
3036
    test  [edi+WDATA.fl_wdrawn],1
3014
    jnz   newd
3037
    jnz   newd
3015
 
3038
 
3016
    push  eax
3039
    push  eax
3017
    mov   eax,[timer_ticks] ;[0xfdf0]
3040
    mov   eax,[timer_ticks] ;[0xfdf0]
3018
    add   eax,100
3041
    add   eax,100
3019
    mov   [new_window_starting],eax
3042
    mov   [new_window_starting],eax
3020
    pop   eax
3043
    pop   eax
3021
 
3044
 
3022
    mov   word[edi+WDATA.box.width],ax
3045
    mov   word[edi+WDATA.box.width],ax
3023
    mov   word[edi+WDATA.box.height],bx
3046
    mov   word[edi+WDATA.box.height],bx
3024
    sar   eax,16
3047
    sar   eax,16
3025
    sar   ebx,16
3048
    sar   ebx,16
3026
    mov   word[edi+WDATA.box.left],ax
3049
    mov   word[edi+WDATA.box.left],ax
3027
    mov   word[edi+WDATA.box.top],bx
3050
    mov   word[edi+WDATA.box.top],bx
3028
 
3051
 
3029
    call  check_window_position
3052
    call  check_window_position
3030
 
3053
 
3031
    call  set_window_clientbox
3054
    call  set_window_clientbox
3032
 
3055
 
3033
    push  ecx esi edi               ; save for window fullscreen/resize
3056
    push  ecx esi edi               ; save for window fullscreen/resize
3034
    ;mov   esi,edi
3057
    ;mov   esi,edi
3035
 
3058
 
3036
        mov     cl,[edi+WDATA.fl_wstyle]
3059
        mov     cl,[edi+WDATA.fl_wstyle]
3037
 
3060
 
3038
    sub   edi,window_data
3061
    sub   edi,window_data
3039
    shl   edi,3
3062
    shl   edi,3
3040
    add   edi,SLOT_BASE
3063
    add   edi,SLOT_BASE
3041
 
3064
 
3042
        and     cl,0x0F
3065
        and     cl,0x0F
3043
        mov     [edi+APPDATA.wnd_caption],0
3066
        mov     [edi+APPDATA.wnd_caption],0
3044
        cmp     cl,3
3067
        cmp     cl,3
3045
        jne     @f
3068
        jne     @f
3046
        mov     [edi+APPDATA.wnd_caption],esi
3069
        mov     [edi+APPDATA.wnd_caption],esi
3047
    @@: mov     esi,[esp+0]
3070
    @@: mov     esi,[esp+0]
3048
 
3071
 
3049
    add   edi, APPDATA.saved_box
3072
    add   edi, APPDATA.saved_box
3050
        movsd
3073
        movsd
3051
        movsd
3074
        movsd
3052
        movsd
3075
        movsd
3053
        movsd
3076
        movsd
3054
    pop   edi esi ecx
3077
    pop   edi esi ecx
3055
 
3078
 
3056
    push  eax ebx ecx edx
3079
    push  eax ebx ecx edx
3057
;;;    mov   eax, 1
3080
;;;    mov   eax, 1
3058
;;;    call  delay_hs
3081
;;;    call  delay_hs
3059
    mov   eax, [edi+WDATA.box.left]
3082
    mov   eax, [edi+WDATA.box.left]
3060
    mov   ebx, [edi+WDATA.box.top]
3083
    mov   ebx, [edi+WDATA.box.top]
3061
    mov   ecx, [edi+WDATA.box.width]
3084
    mov   ecx, [edi+WDATA.box.width]
3062
    mov   edx, [edi+WDATA.box.height]
3085
    mov   edx, [edi+WDATA.box.height]
3063
    add   ecx, eax
3086
    add   ecx, eax
3064
    add   edx, ebx
3087
    add   edx, ebx
3065
    call  calculatescreen
3088
    call  calculatescreen
3066
    pop   edx ecx ebx eax
3089
    pop   edx ecx ebx eax
3067
 
3090
 
3068
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3091
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3069
    mov   [BTN_COUNT],byte 0           ; empty button buffer
3092
    mov   [BTN_COUNT],byte 0           ; empty button buffer
3070
 
3093
 
3071
  newd:
3094
  newd:
3072
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
3095
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
3073
    mov   edx,edi
3096
    mov   edx,edi
3074
 
3097
 
3075
    ret
3098
    ret
3076
 
3099
 
3077
syscall_windowsettings:
3100
syscall_windowsettings:
3078
 
3101
 
3079
  .set_window_caption:
3102
  .set_window_caption:
3080
        dec     eax     ; subfunction #1 - set window caption
3103
        dec     eax     ; subfunction #1 - set window caption
3081
        jnz     .get_window_caption
3104
        jnz     .get_window_caption
3082
 
3105
 
3083
        ; NOTE: only window owner thread can set its caption,
3106
        ; NOTE: only window owner thread can set its caption,
3084
        ;       so there's no parameter for PID/TID
3107
        ;       so there's no parameter for PID/TID
3085
 
3108
 
3086
        mov     edi,[CURRENT_TASK]
3109
        mov     edi,[CURRENT_TASK]
3087
        shl     edi,5
3110
        shl     edi,5
3088
 
3111
 
3089
        ; have to check if caption is within application memory limit
3112
        ; have to check if caption is within application memory limit
3090
        ; check is trivial, and if application resizes its memory,
3113
        ; check is trivial, and if application resizes its memory,
3091
        ;   caption still can become over bounds
3114
        ;   caption still can become over bounds
3092
; diamond, 31.10.2006: check removed because with new memory manager
3115
; diamond, 31.10.2006: check removed because with new memory manager
3093
; there can be valid data after APPDATA.mem_size bound
3116
; there can be valid data after APPDATA.mem_size bound
3094
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3117
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
3095
;        add     ecx,255 ; max caption length
3118
;        add     ecx,255 ; max caption length
3096
;        cmp     ebx,ecx
3119
;        cmp     ebx,ecx
3097
;        ja      .exit_fail
3120
;        ja      .exit_fail
3098
 
3121
 
3099
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3122
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3100
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3123
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3101
 
3124
 
3102
        call    draw_window_caption
3125
        call    draw_window_caption
3103
 
3126
 
3104
        xor     eax,eax ; eax = 0 (success)
3127
        xor     eax,eax ; eax = 0 (success)
3105
        ret
3128
        ret
3106
 
3129
 
3107
  .get_window_caption:
3130
  .get_window_caption:
3108
        dec     eax     ; subfunction #2 - get window caption
3131
        dec     eax     ; subfunction #2 - get window caption
3109
        jnz     .exit_fail
3132
        jnz     .exit_fail
3110
 
3133
 
3111
        ; not implemented yet
3134
        ; not implemented yet
3112
 
3135
 
3113
  .exit_fail:
3136
  .exit_fail:
3114
        xor     eax,eax
3137
        xor     eax,eax
3115
        inc     eax     ; eax = 1 (fail)
3138
        inc     eax     ; eax = 1 (fail)
3116
        ret
3139
        ret
3117
 
3140
 
3118
 
3141
 
3119
sys_window_move:
3142
sys_window_move:
3120
 
3143
 
3121
        mov     edi,[CURRENT_TASK]
3144
        mov     edi,[CURRENT_TASK]
3122
        shl     edi,5
3145
        shl     edi,5
3123
        add     edi,window_data
3146
        add     edi,window_data
3124
 
3147
 
3125
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3148
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3126
        jnz     .window_move_return
3149
        jnz     .window_move_return
3127
 
3150
 
3128
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3151
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3129
        push    dword [edi + WDATA.box.top]
3152
        push    dword [edi + WDATA.box.top]
3130
        push    dword [edi + WDATA.box.width]
3153
        push    dword [edi + WDATA.box.width]
3131
        push    dword [edi + WDATA.box.height]
3154
        push    dword [edi + WDATA.box.height]
3132
 
3155
 
3133
        cmp   eax,-1                  ; set new position and size
3156
        cmp   eax,-1                  ; set new position and size
3134
        je    .no_x_reposition
3157
        je    .no_x_reposition
3135
        mov     [edi + WDATA.box.left], eax
3158
        mov     [edi + WDATA.box.left], eax
3136
      .no_x_reposition:
3159
      .no_x_reposition:
3137
        cmp   ebx,-1
3160
        cmp   ebx,-1
3138
        je    .no_y_reposition
3161
        je    .no_y_reposition
3139
        mov     [edi + WDATA.box.top], ebx
3162
        mov     [edi + WDATA.box.top], ebx
3140
      .no_y_reposition:
3163
      .no_y_reposition:
3141
 
3164
 
3142
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3165
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3143
        jnz     .no_y_resizing
3166
        jnz     .no_y_resizing
3144
 
3167
 
3145
        cmp   ecx,-1
3168
        cmp   ecx,-1
3146
        je    .no_x_resizing
3169
        je    .no_x_resizing
3147
        mov     [edi + WDATA.box.width], ecx
3170
        mov     [edi + WDATA.box.width], ecx
3148
      .no_x_resizing:
3171
      .no_x_resizing:
3149
        cmp   edx,-1
3172
        cmp   edx,-1
3150
        je    .no_y_resizing
3173
        je    .no_y_resizing
3151
        mov     [edi + WDATA.box.height], edx
3174
        mov     [edi + WDATA.box.height], edx
3152
      .no_y_resizing:
3175
      .no_y_resizing:
3153
 
3176
 
3154
        call  check_window_position
3177
        call  check_window_position
3155
        call  set_window_clientbox
3178
        call  set_window_clientbox
3156
 
3179
 
3157
        pushad                       ; save for window fullscreen/resize
3180
        pushad                       ; save for window fullscreen/resize
3158
        mov   esi,edi
3181
        mov   esi,edi
3159
        sub   edi,window_data
3182
        sub   edi,window_data
3160
        shr   edi,5
3183
        shr   edi,5
3161
        shl   edi,8
3184
        shl   edi,8
3162
        add   edi, SLOT_BASE + APPDATA.saved_box
3185
        add   edi, SLOT_BASE + APPDATA.saved_box
3163
        mov   ecx,4
3186
        mov   ecx,4
3164
        cld
3187
        cld
3165
        rep   movsd
3188
        rep   movsd
3166
        popad
3189
        popad
3167
 
3190
 
3168
        pushad                       ; calculcate screen at new position
3191
        pushad                       ; calculcate screen at new position
3169
        mov   eax, [edi + WDATA.box.left]
3192
        mov   eax, [edi + WDATA.box.left]
3170
        mov   ebx, [edi + WDATA.box.top]
3193
        mov   ebx, [edi + WDATA.box.top]
3171
        mov   ecx, [edi + WDATA.box.width]
3194
        mov   ecx, [edi + WDATA.box.width]
3172
        mov   edx, [edi + WDATA.box.height]
3195
        mov   edx, [edi + WDATA.box.height]
3173
        add   ecx,eax
3196
        add   ecx,eax
3174
        add   edx,ebx
3197
        add   edx,ebx
3175
 
3198
 
3176
        call  calculatescreen
3199
        call  calculatescreen
3177
        popad
3200
        popad
3178
 
3201
 
3179
        pop   edx                   ; calculcate screen at old position
3202
        pop   edx                   ; calculcate screen at old position
3180
        pop   ecx
3203
        pop   ecx
3181
        pop   ebx
3204
        pop   ebx
3182
        pop   eax
3205
        pop   eax
3183
        add   ecx,eax
3206
        add   ecx,eax
3184
        add   edx,ebx
3207
        add   edx,ebx
3185
        mov   [dlx],eax             ; save for drawlimits
3208
        mov   [dlx],eax             ; save for drawlimits
3186
        mov   [dly],ebx
3209
        mov   [dly],ebx
3187
        mov   [dlxe],ecx
3210
        mov   [dlxe],ecx
3188
        mov   [dlye],edx
3211
        mov   [dlye],edx
3189
        call  calculatescreen
3212
        call  calculatescreen
3190
 
3213
 
3191
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3214
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
3192
 
3215
 
3193
        mov   eax,edi               ; redraw screen at old position
3216
        mov   eax,edi               ; redraw screen at old position
3194
        xor   esi,esi
3217
        xor   esi,esi
3195
        call  redrawscreen
3218
        call  redrawscreen
3196
 
3219
 
3197
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3220
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3198
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3221
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3199
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3222
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3200
 
3223
 
3201
        mov   ecx,10          ; wait 1/10 second
3224
        mov   ecx,10          ; wait 1/10 second
3202
      .wmrl3:
3225
      .wmrl3:
3203
        call  [draw_pointer]
3226
        call  [draw_pointer]
3204
        mov   eax,1
3227
        mov   eax,1
3205
        call  delay_hs
3228
        call  delay_hs
3206
        loop  .wmrl3
3229
        loop  .wmrl3
3207
 
3230
 
3208
        mov   [window_move_pr],0
3231
        mov   [window_move_pr],0
3209
 
3232
 
3210
      .window_move_return:
3233
      .window_move_return:
3211
 
3234
 
3212
        ret
3235
        ret
3213
 
3236
 
3214
;type_background_1:
3237
;type_background_1:
3215
;    cmp   [0xfff0],byte 0               ; background update ?
3238
;    cmp   [0xfff0],byte 0               ; background update ?
3216
;    jz    temp_nobackgr
3239
;    jz    temp_nobackgr
3217
;    mov   [0xfff0],byte 2
3240
;    mov   [0xfff0],byte 2
3218
;    call  change_task
3241
;    call  change_task
3219
;    mov   [draw_data+32+0],dword 0
3242
;    mov   [draw_data+32+0],dword 0
3220
;    mov   [draw_data+32+4],dword 0
3243
;    mov   [draw_data+32+4],dword 0
3221
;    mov   eax,[ScreenWidth
3244
;    mov   eax,[ScreenWidth
3222
;    mov   ebx,[0xfe04]
3245
;    mov   ebx,[0xfe04]
3223
;    mov   [draw_data+32+8],eax
3246
;    mov   [draw_data+32+8],eax
3224
;    mov   [draw_data+32+12],ebx
3247
;    mov   [draw_data+32+12],ebx
3225
;    call  drawbackground
3248
;    call  drawbackground
3226
;    mov   [0xfff0],byte 0
3249
;    mov   [0xfff0],byte 0
3227
;    mov   [MOUSE_BACKGROUND],byte 0
3250
;    mov   [MOUSE_BACKGROUND],byte 0
3228
;temp_nobackgr:
3251
;temp_nobackgr:
3229
;    ret
3252
;    ret
3230
 
3253
 
3231
uglobal
3254
uglobal
3232
  window_move_pr   dd  0x0
3255
  window_move_pr   dd  0x0
3233
  window_move_eax  dd  0x0
3256
  window_move_eax  dd  0x0
3234
  window_move_ebx  dd  0x0
3257
  window_move_ebx  dd  0x0
3235
  window_move_ecx  dd  0x0
3258
  window_move_ecx  dd  0x0
3236
  window_move_edx  dd  0x0
3259
  window_move_edx  dd  0x0
3237
endg
3260
endg
3238
 
3261
 
3239
;ok - 100% work
3262
;ok - 100% work
3240
;nt - not tested
3263
;nt - not tested
3241
;---------------------------------------------------------------------------------------------
3264
;---------------------------------------------------------------------------------------------
3242
;eax
3265
;eax
3243
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3266
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3244
;1 - change task. Ret nothing. Block. ok.
3267
;1 - change task. Ret nothing. Block. ok.
3245
;2 - performance control
3268
;2 - performance control
3246
; ebx
3269
; ebx
3247
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3270
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3248
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3271
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3249
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3272
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3250
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3273
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3251
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3274
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3252
;eax
3275
;eax
3253
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3276
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3254
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3277
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3255
;---------------------------------------------------------------------------------------------
3278
;---------------------------------------------------------------------------------------------
3256
sys_sheduler: ;noname & halyavin
3279
sys_sheduler: ;noname & halyavin
3257
    cmp eax,0
3280
    cmp eax,0
3258
    je shed_counter
3281
    je shed_counter
3259
    cmp eax,2
3282
    cmp eax,2
3260
    je perf_control
3283
    je perf_control
3261
    cmp eax,3
3284
    cmp eax,3
3262
    je rdmsr_instr
3285
    je rdmsr_instr
3263
    cmp eax,4
3286
    cmp eax,4
3264
    je wrmsr_instr
3287
    je wrmsr_instr
3265
    cmp eax,1
3288
    cmp eax,1
3266
    jne not_supported
3289
    jne not_supported
3267
    call change_task ;delay,0
3290
    call change_task ;delay,0
3268
ret
3291
ret
3269
shed_counter:
3292
shed_counter:
3270
    mov eax,[context_counter]
3293
    mov eax,[context_counter]
3271
    mov [esp+36],eax
3294
    mov [esp+36],eax
3272
not_supported:
3295
not_supported:
3273
ret
3296
ret
3274
perf_control:
3297
perf_control:
3275
    inc eax ;now eax=3
3298
    inc eax ;now eax=3
3276
    cmp ebx,eax
3299
    cmp ebx,eax
3277
    je cache_disable
3300
    je cache_disable
3278
    dec eax
3301
    dec eax
3279
    cmp ebx,eax
3302
    cmp ebx,eax
3280
    je cache_enable
3303
    je cache_enable
3281
    dec eax
3304
    dec eax
3282
    cmp ebx,eax
3305
    cmp ebx,eax
3283
    je is_cache_enabled
3306
    je is_cache_enabled
3284
    dec eax
3307
    dec eax
3285
    cmp ebx,eax
3308
    cmp ebx,eax
3286
    je modify_pce
3309
    je modify_pce
3287
ret
3310
ret
3288
 
3311
 
3289
rdmsr_instr:
3312
rdmsr_instr:
3290
;now counter in ecx
3313
;now counter in ecx
3291
;(edx:eax) esi:edi => edx:esi
3314
;(edx:eax) esi:edi => edx:esi
3292
mov eax,esi
3315
mov eax,esi
3293
rdmsr
3316
rdmsr
3294
mov [esp+36],eax
3317
mov [esp+36],eax
3295
mov [esp+24],edx ;ret in ebx?
3318
mov [esp+24],edx ;ret in ebx?
3296
ret
3319
ret
3297
 
3320
 
3298
wrmsr_instr:
3321
wrmsr_instr:
3299
;now counter in ecx
3322
;now counter in ecx
3300
;(edx:eax) esi:edi => edx:esi
3323
;(edx:eax) esi:edi => edx:esi
3301
	; Fast Call MSR can't be destroy
-
 
3302
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
-
 
3303
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
-
 
3304
	cmp	ecx, MSR_SYSENTER_CS
-
 
3305
	je	@f
-
 
3306
	cmp	ecx, MSR_SYSENTER_ESP
-
 
3307
	je	@f
-
 
3308
	cmp	ecx, MSR_SYSENTER_EIP
-
 
3309
	je	@f
-
 
3310
	cmp	ecx, MSR_AMD_STAR
-
 
3311
	je	@f
-
 
3312
 
-
 
3313
	mov	eax, esi
3324
mov eax,esi
3314
	wrmsr
3325
wrmsr
3315
@@:
3326
mov [esp+36],eax
-
 
3327
mov [esp+24],edx ;ret in ebx?
3316
ret
3328
ret
3317
 
-
 
3318
 
3329
 
3319
cache_disable:
3330
cache_disable:
3320
       mov eax,cr0
3331
       mov eax,cr0
3321
       or  eax,01100000000000000000000000000000b
3332
       or  eax,01100000000000000000000000000000b
3322
       mov cr0,eax
3333
       mov cr0,eax
3323
       wbinvd ;set MESI
3334
       wbinvd ;set MESI
3324
ret
3335
ret
3325
 
3336
 
3326
cache_enable:
3337
cache_enable:
3327
       mov eax,cr0
3338
       mov eax,cr0
3328
       and eax,10011111111111111111111111111111b
3339
       and eax,10011111111111111111111111111111b
3329
       mov cr0,eax
3340
       mov cr0,eax
3330
ret
3341
ret
3331
 
3342
 
3332
is_cache_enabled:
3343
is_cache_enabled:
3333
       mov eax,cr0
3344
       mov eax,cr0
3334
       mov ebx,eax
3345
       mov ebx,eax
3335
       and eax,01100000000000000000000000000000b
3346
       and eax,01100000000000000000000000000000b
3336
       jz cache_disabled
3347
       jz cache_disabled
3337
       mov [esp+36],ebx
3348
       mov [esp+36],ebx
3338
cache_disabled:
3349
cache_disabled:
3339
       mov dword [esp+36],eax ;0
3350
       mov dword [esp+36],eax ;0
3340
ret
3351
ret
3341
 
3352
 
3342
modify_pce:
3353
modify_pce:
3343
       mov eax,cr4
3354
       mov eax,cr4
3344
;       mov ebx,0
3355
;       mov ebx,0
3345
;       or  bx,100000000b ;pce
3356
;       or  bx,100000000b ;pce
3346
;       xor eax,ebx ;invert pce
3357
;       xor eax,ebx ;invert pce
3347
       bts eax,8 ;pce=cr4[8]
3358
       bts eax,8 ;pce=cr4[8]
3348
       mov cr4,eax
3359
       mov cr4,eax
3349
       mov [esp+36],eax
3360
       mov [esp+36],eax
3350
ret
3361
ret
3351
;---------------------------------------------------------------------------------------------
3362
;---------------------------------------------------------------------------------------------
3352
 
3363
 
3353
 
3364
 
3354
; check if pixel is allowed to be drawn
3365
; check if pixel is allowed to be drawn
3355
 
3366
 
3356
checkpixel:
3367
checkpixel:
3357
        push eax edx
3368
        push eax edx
3358
 
3369
 
3359
        mov  edx,[ScreenWidth]     ; screen x size
3370
        mov  edx,[ScreenWidth]     ; screen x size
3360
        inc  edx
3371
        inc  edx
3361
        imul edx, ebx
3372
        imul edx, ebx
3362
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3373
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3363
 
3374
 
3364
        xor  ecx, ecx
3375
        xor  ecx, ecx
3365
        mov  eax, [CURRENT_TASK]
3376
        mov  eax, [CURRENT_TASK]
3366
        cmp  al, dl
3377
        cmp  al, dl
3367
        setne cl
3378
        setne cl
3368
 
3379
 
3369
        pop  edx eax
3380
        pop  edx eax
3370
        ret
3381
        ret
3371
 
3382
 
3372
iglobal
3383
iglobal
3373
  cpustring db '/RD/1/CPU',0
3384
  cpustring db '/RD/1/CPU',0
3374
endg
3385
endg
3375
 
3386
 
3376
uglobal
3387
uglobal
3377
background_defined    db    0    ; diamond, 11.04.2006
3388
background_defined    db    0    ; diamond, 11.04.2006
3378
endg
3389
endg
3379
 
3390
 
3380
align 4
3391
align 4
3381
; check misc
3392
; check misc
3382
 
3393
 
3383
checkmisc:
3394
checkmisc:
3384
 
3395
 
3385
    cmp   [ctrl_alt_del], 1
3396
    cmp   [ctrl_alt_del], 1
3386
    jne   nocpustart
3397
    jne   nocpustart
3387
    mov   ebp, cpustring
3398
    mov   ebp, cpustring
3388
    lea   esi,[ebp+6]
3399
    lea   esi,[ebp+6]
3389
    xor   ebx,ebx               ; no parameters
3400
    xor   ebx,ebx               ; no parameters
3390
    xor   edx,edx               ; no flags
3401
    xor   edx,edx               ; no flags
3391
    call  fs_RamdiskExecute.flags
3402
    call  fs_RamdiskExecute.flags
3392
    mov   [ctrl_alt_del], 0
3403
    mov   [ctrl_alt_del], 0
3393
 
3404
 
3394
nocpustart:
3405
nocpustart:
3395
    cmp   [mouse_active], 1
3406
    cmp   [mouse_active], 1
3396
    jne   mouse_not_active
3407
    jne   mouse_not_active
3397
    mov   [mouse_active], 0
3408
    mov   [mouse_active], 0
3398
    xor   edi, edi
3409
    xor   edi, edi
3399
    mov   ecx,  [TASK_COUNT]
3410
    mov   ecx,  [TASK_COUNT]
3400
set_mouse_event:
3411
set_mouse_event:
3401
    add   edi, 256
3412
    add   edi, 256
3402
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3413
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
3403
    loop  set_mouse_event
3414
    loop  set_mouse_event
3404
 
3415
 
3405
mouse_not_active:
3416
mouse_not_active:
3406
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3417
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3407
    jz    nobackgr
3418
    jz    nobackgr
3408
    cmp    [background_defined], 0
3419
    cmp    [background_defined], 0
3409
    jz    nobackgr
3420
    jz    nobackgr
3410
;    mov   [REDRAW_BACKGROUND],byte 2
3421
;    mov   [REDRAW_BACKGROUND],byte 2
3411
;    call  change_task
3422
;    call  change_task
3412
    xor   edi, edi
3423
    xor   edi, edi
3413
    mov   ecx,  [TASK_COUNT]
3424
    mov   ecx,  [TASK_COUNT]
3414
set_bgr_event:
3425
set_bgr_event:
3415
    add   edi, 256
3426
    add   edi, 256
3416
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3427
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3417
    loop  set_bgr_event
3428
    loop  set_bgr_event
3418
    mov   [draw_data+32 + RECT.left],dword 0
3429
    mov   [draw_data+32 + RECT.left],dword 0
3419
    mov   [draw_data+32 + RECT.top],dword 0
3430
    mov   [draw_data+32 + RECT.top],dword 0
3420
    mov   eax,[ScreenWidth]
3431
    mov   eax,[ScreenWidth]
3421
    mov   ebx,[ScreenHeight]
3432
    mov   ebx,[ScreenHeight]
3422
    mov   [draw_data+32 + RECT.right],eax
3433
    mov   [draw_data+32 + RECT.right],eax
3423
    mov   [draw_data+32 + RECT.bottom],ebx
3434
    mov   [draw_data+32 + RECT.bottom],ebx
3424
    call  drawbackground
3435
    call  drawbackground
3425
    mov   [REDRAW_BACKGROUND],byte 0
3436
    mov   [REDRAW_BACKGROUND],byte 0
3426
    mov   [MOUSE_BACKGROUND],byte 0
3437
    mov   [MOUSE_BACKGROUND],byte 0
3427
 
3438
 
3428
nobackgr:
3439
nobackgr:
3429
 
3440
 
3430
    ; system shutdown request
3441
    ; system shutdown request
3431
 
3442
 
3432
    cmp  [SYS_SHUTDOWN],byte 0
3443
    cmp  [SYS_SHUTDOWN],byte 0
3433
    je   noshutdown
3444
    je   noshutdown
3434
 
3445
 
3435
    mov  edx,[shutdown_processes]
3446
    mov  edx,[shutdown_processes]
3436
    sub  dl,2
3447
    sub  dl,2
3437
 
3448
 
3438
    cmp  [SYS_SHUTDOWN],dl
3449
    cmp  [SYS_SHUTDOWN],dl
3439
    jne  no_mark_system_shutdown
3450
    jne  no_mark_system_shutdown
3440
 
3451
 
3441
    mov   edx,OS_BASE+0x3040
3452
    mov   edx,OS_BASE+0x3040
3442
    movzx ecx,byte [SYS_SHUTDOWN]
3453
    movzx ecx,byte [SYS_SHUTDOWN]
3443
    add   ecx,5
3454
    add   ecx,5
3444
markz:
3455
markz:
3445
    mov   [edx+TASKDATA.state],byte 3
3456
    mov   [edx+TASKDATA.state],byte 3
3446
    add   edx,0x20
3457
    add   edx,0x20
3447
    loop  markz
3458
    loop  markz
3448
 
3459
 
3449
  no_mark_system_shutdown:
3460
  no_mark_system_shutdown:
3450
 
3461
 
3451
    call [disable_mouse]
3462
    call [disable_mouse]
3452
 
3463
 
3453
    dec  byte [SYS_SHUTDOWN]
3464
    dec  byte [SYS_SHUTDOWN]
3454
 
3465
 
3455
    cmp  [SYS_SHUTDOWN],byte 0
3466
    cmp  [SYS_SHUTDOWN],byte 0
3456
    je   system_shutdown
3467
    je   system_shutdown
3457
 
3468
 
3458
noshutdown:
3469
noshutdown:
3459
 
3470
 
3460
 
3471
 
3461
    mov   eax,[TASK_COUNT]                  ; termination
3472
    mov   eax,[TASK_COUNT]                  ; termination
3462
    mov   ebx,TASK_DATA+TASKDATA.state
3473
    mov   ebx,TASK_DATA+TASKDATA.state
3463
    mov   esi,1
3474
    mov   esi,1
3464
 
3475
 
3465
newct:
3476
newct:
3466
    mov   cl,[ebx]
3477
    mov   cl,[ebx]
3467
    cmp   cl,byte 3
3478
    cmp   cl,byte 3
3468
    jz    terminate
3479
    jz    terminate
3469
    cmp   cl,byte 4
3480
    cmp   cl,byte 4
3470
    jz    terminate
3481
    jz    terminate
3471
 
3482
 
3472
    add   ebx,0x20
3483
    add   ebx,0x20
3473
    inc   esi
3484
    inc   esi
3474
    dec   eax
3485
    dec   eax
3475
    jnz   newct
3486
    jnz   newct
3476
 
3487
 
3477
    ret
3488
    ret
3478
 
3489
 
3479
 
3490
 
3480
; redraw screen
3491
; redraw screen
3481
 
3492
 
3482
redrawscreen:
3493
redrawscreen:
3483
 
3494
 
3484
; eax , if process window_data base is eax, do not set flag/limits
3495
; eax , if process window_data base is eax, do not set flag/limits
3485
 
3496
 
3486
         pushad
3497
         pushad
3487
         push  eax
3498
         push  eax
3488
 
3499
 
3489
;;;         mov   eax,2
3500
;;;         mov   eax,2
3490
;;;         call  delay_hs
3501
;;;         call  delay_hs
3491
 
3502
 
3492
         ;mov   ecx,0               ; redraw flags for apps
3503
         ;mov   ecx,0               ; redraw flags for apps
3493
         xor   ecx,ecx
3504
         xor   ecx,ecx
3494
       newdw2:
3505
       newdw2:
3495
 
3506
 
3496
         inc   ecx
3507
         inc   ecx
3497
         push  ecx
3508
         push  ecx
3498
 
3509
 
3499
         mov   eax,ecx
3510
         mov   eax,ecx
3500
         shl   eax,5
3511
         shl   eax,5
3501
         add   eax,window_data
3512
         add   eax,window_data
3502
 
3513
 
3503
         cmp   eax,[esp+4]
3514
         cmp   eax,[esp+4]
3504
         je    not_this_task
3515
         je    not_this_task
3505
                                   ; check if window in redraw area
3516
                                   ; check if window in redraw area
3506
         mov   edi,eax
3517
         mov   edi,eax
3507
 
3518
 
3508
         cmp   ecx,1               ; limit for background
3519
         cmp   ecx,1               ; limit for background
3509
         jz    bgli
3520
         jz    bgli
3510
 
3521
 
3511
         mov   eax, [edi + WDATA.box.left]
3522
         mov   eax, [edi + WDATA.box.left]
3512
         mov   ebx, [edi + WDATA.box.top]
3523
         mov   ebx, [edi + WDATA.box.top]
3513
         mov   ecx, [edi + WDATA.box.width]
3524
         mov   ecx, [edi + WDATA.box.width]
3514
         mov   edx, [edi + WDATA.box.height]
3525
         mov   edx, [edi + WDATA.box.height]
3515
         add   ecx,eax
3526
         add   ecx,eax
3516
         add   edx,ebx
3527
         add   edx,ebx
3517
 
3528
 
3518
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3529
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3519
         cmp   ecx,ebx
3530
         cmp   ecx,ebx
3520
         jb    ricino
3531
         jb    ricino
3521
 
3532
 
3522
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3533
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3523
         cmp   ecx,eax
3534
         cmp   ecx,eax
3524
         jb    ricino
3535
         jb    ricino
3525
 
3536
 
3526
         mov   eax, [edi + WDATA.box.left]
3537
         mov   eax, [edi + WDATA.box.left]
3527
         mov   ebx, [edi + WDATA.box.top]
3538
         mov   ebx, [edi + WDATA.box.top]
3528
         mov   ecx, [edi + WDATA.box.width]
3539
         mov   ecx, [edi + WDATA.box.width]
3529
         mov   edx, [edi + WDATA.box.height]
3540
         mov   edx, [edi + WDATA.box.height]
3530
         add   ecx, eax
3541
         add   ecx, eax
3531
         add   edx, ebx
3542
         add   edx, ebx
3532
 
3543
 
3533
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3544
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3534
         cmp   edx,eax
3545
         cmp   edx,eax
3535
         jb    ricino
3546
         jb    ricino
3536
 
3547
 
3537
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3548
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3538
         cmp   ecx,eax
3549
         cmp   ecx,eax
3539
         jb    ricino
3550
         jb    ricino
3540
 
3551
 
3541
        bgli:
3552
        bgli:
3542
 
3553
 
3543
         cmp   edi,esi
3554
         cmp   edi,esi
3544
         jz    ricino
3555
         jz    ricino
3545
 
3556
 
3546
         mov   eax,edi
3557
         mov   eax,edi
3547
         add   eax,draw_data-window_data
3558
         add   eax,draw_data-window_data
3548
 
3559
 
3549
         mov   ebx,[dlx]          ; set limits
3560
         mov   ebx,[dlx]          ; set limits
3550
         mov   [eax + RECT.left], ebx
3561
         mov   [eax + RECT.left], ebx
3551
         mov   ebx,[dly]
3562
         mov   ebx,[dly]
3552
         mov   [eax + RECT.top], ebx
3563
         mov   [eax + RECT.top], ebx
3553
         mov   ebx,[dlxe]
3564
         mov   ebx,[dlxe]
3554
         mov   [eax + RECT.right], ebx
3565
         mov   [eax + RECT.right], ebx
3555
         mov   ebx,[dlye]
3566
         mov   ebx,[dlye]
3556
         mov   [eax + RECT.bottom], ebx
3567
         mov   [eax + RECT.bottom], ebx
3557
 
3568
 
3558
         sub   eax,draw_data-window_data
3569
         sub   eax,draw_data-window_data
3559
 
3570
 
3560
         cmp   ecx,1
3571
         cmp   ecx,1
3561
         jne   nobgrd
3572
         jne   nobgrd
3562
         cmp   esi,1
3573
         cmp   esi,1
3563
         je    newdw8
3574
         je    newdw8
3564
         call  drawbackground
3575
         call  drawbackground
3565
 
3576
 
3566
       newdw8:
3577
       newdw8:
3567
       nobgrd:
3578
       nobgrd:
3568
 
3579
 
3569
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3580
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
3570
 
3581
 
3571
       ricino:
3582
       ricino:
3572
 
3583
 
3573
       not_this_task:
3584
       not_this_task:
3574
 
3585
 
3575
         pop   ecx
3586
         pop   ecx
3576
 
3587
 
3577
         cmp   ecx,[TASK_COUNT]
3588
         cmp   ecx,[TASK_COUNT]
3578
         jle   newdw2
3589
         jle   newdw2
3579
 
3590
 
3580
         pop  eax
3591
         pop  eax
3581
         popad
3592
         popad
3582
 
3593
 
3583
         ret
3594
         ret
3584
 
3595
 
3585
calculatebackground:   ; background
3596
calculatebackground:   ; background
3586
 
3597
 
3587
        ; all black
3598
        ; all black
3588
 
3599
 
3589
        mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3600
        mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3590
        xor   eax, eax
3601
        xor   eax, eax
3591
        mov   ecx, 1023    ;0x0fff00 / 4
3602
        mov   ecx, 1023    ;0x0fff00 / 4
3592
        cld
3603
        cld
3593
        rep   stosd
3604
        rep   stosd
3594
 
3605
 
3595
        mov   edi,display_data              ; set os to use all pixels
3606
        mov   edi,display_data              ; set os to use all pixels
3596
        mov   eax,0x01010101
3607
        mov   eax,0x01010101
3597
        mov   ecx,1280*1024 / 4
3608
        mov   ecx,1280*1024 / 4
3598
        rep   stosd
3609
        rep   stosd
3599
 
3610
 
3600
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3611
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
3601
 
3612
 
3602
        ret
3613
        ret
3603
 
3614
 
3604
uglobal
3615
uglobal
3605
  imax    dd 0x0
3616
  imax    dd 0x0
3606
endg
3617
endg
3607
 
3618
 
3608
 
3619
 
3609
 
3620
 
3610
delay_ms:     ; delay in 1/1000 sec
3621
delay_ms:     ; delay in 1/1000 sec
3611
 
3622
 
3612
 
3623
 
3613
        push  eax
3624
        push  eax
3614
        push  ecx
3625
        push  ecx
3615
 
3626
 
3616
        mov   ecx,esi
3627
        mov   ecx,esi
3617
        ; 
3628
        ; 
3618
        imul  ecx, 33941
3629
        imul  ecx, 33941
3619
        shr   ecx, 9
3630
        shr   ecx, 9
3620
        ; 
3631
        ; 
3621
 
3632
 
3622
        in    al,0x61
3633
        in    al,0x61
3623
        and   al,0x10
3634
        and   al,0x10
3624
        mov   ah,al
3635
        mov   ah,al
3625
        cld
3636
        cld
3626
 
3637
 
3627
 cnt1:  in    al,0x61
3638
 cnt1:  in    al,0x61
3628
        and   al,0x10
3639
        and   al,0x10
3629
        cmp   al,ah
3640
        cmp   al,ah
3630
        jz    cnt1
3641
        jz    cnt1
3631
 
3642
 
3632
        mov   ah,al
3643
        mov   ah,al
3633
        loop  cnt1
3644
        loop  cnt1
3634
 
3645
 
3635
        pop   ecx
3646
        pop   ecx
3636
        pop   eax
3647
        pop   eax
3637
 
3648
 
3638
        ret
3649
        ret
3639
 
3650
 
3640
 
3651
 
3641
set_app_param:
3652
set_app_param:
3642
        push edi
3653
        push edi
3643
 
3654
 
3644
        mov  edi,[TASK_BASE]
3655
        mov  edi,[TASK_BASE]
3645
        mov  [edi+TASKDATA.event_mask],eax
3656
        mov  [edi+TASKDATA.event_mask],eax
3646
 
3657
 
3647
        pop  edi
3658
        pop  edi
3648
        ret
3659
        ret
3649
 
3660
 
3650
 
3661
 
3651
 
3662
 
3652
delay_hs:     ; delay in 1/100 secs
3663
delay_hs:     ; delay in 1/100 secs
3653
        push  eax
3664
        push  eax
3654
        push  ecx
3665
        push  ecx
3655
        push  edx
3666
        push  edx
3656
 
3667
 
3657
        mov   edx,[timer_ticks]
3668
        mov   edx,[timer_ticks]
3658
        add   edx,eax
3669
        add   edx,eax
3659
 
3670
 
3660
      newtic:
3671
      newtic:
3661
        mov   ecx,[timer_ticks]
3672
        mov   ecx,[timer_ticks]
3662
        cmp   edx,ecx
3673
        cmp   edx,ecx
3663
        jbe   zerodelay
3674
        jbe   zerodelay
3664
 
3675
 
3665
        call  change_task
3676
        call  change_task
3666
 
3677
 
3667
        jmp   newtic
3678
        jmp   newtic
3668
 
3679
 
3669
      zerodelay:
3680
      zerodelay:
3670
        pop   edx
3681
        pop   edx
3671
        pop   ecx
3682
        pop   ecx
3672
        pop   eax
3683
        pop   eax
3673
 
3684
 
3674
        ret
3685
        ret
3675
 
3686
 
3676
 
3687
 
3677
memmove:       ; memory move in bytes
3688
memmove:       ; memory move in bytes
3678
 
3689
 
3679
; eax = from
3690
; eax = from
3680
; ebx = to
3691
; ebx = to
3681
; ecx = no of bytes
3692
; ecx = no of bytes
3682
    test ecx, ecx
3693
    test ecx, ecx
3683
    jle  .ret
3694
    jle  .ret
3684
 
3695
 
3685
 
3696
 
3686
    push esi edi ecx
3697
    push esi edi ecx
3687
 
3698
 
3688
    mov  edi, ebx
3699
    mov  edi, ebx
3689
    mov  esi, eax
3700
    mov  esi, eax
3690
 
3701
 
3691
    test ecx, not 11b
3702
    test ecx, not 11b
3692
    jz   @f
3703
    jz   @f
3693
 
3704
 
3694
    push ecx
3705
    push ecx
3695
    shr  ecx, 2
3706
    shr  ecx, 2
3696
    rep  movsd
3707
    rep  movsd
3697
    pop  ecx
3708
    pop  ecx
3698
    and  ecx, 11b
3709
    and  ecx, 11b
3699
    jz   .finish
3710
    jz   .finish
3700
  @@:
3711
  @@:
3701
    rep  movsb
3712
    rep  movsb
3702
 
3713
 
3703
  .finish:
3714
  .finish:
3704
    pop  ecx edi esi
3715
    pop  ecx edi esi
3705
  .ret:
3716
  .ret:
3706
    ret
3717
    ret
3707
 
3718
 
3708
 
3719
 
3709
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3720
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3710
;align 4
3721
;align 4
3711
;
3722
;
3712
;read_floppy_file:
3723
;read_floppy_file:
3713
;
3724
;
3714
;; as input
3725
;; as input
3715
;;
3726
;;
3716
;; eax pointer to file
3727
;; eax pointer to file
3717
;; ebx file lenght
3728
;; ebx file lenght
3718
;; ecx start 512 byte block number
3729
;; ecx start 512 byte block number
3719
;; edx number of blocks to read
3730
;; edx number of blocks to read
3720
;; esi pointer to return/work area (atleast 20 000 bytes)
3731
;; esi pointer to return/work area (atleast 20 000 bytes)
3721
;;
3732
;;
3722
;;
3733
;;
3723
;; on return
3734
;; on return
3724
;;
3735
;;
3725
;; eax = 0 command succesful
3736
;; eax = 0 command succesful
3726
;;       1 no fd base and/or partition defined
3737
;;       1 no fd base and/or partition defined
3727
;;       2 yet unsupported FS
3738
;;       2 yet unsupported FS
3728
;;       3 unknown FS
3739
;;       3 unknown FS
3729
;;       4 partition not defined at hd
3740
;;       4 partition not defined at hd
3730
;;       5 file not found
3741
;;       5 file not found
3731
;; ebx = size of file
3742
;; ebx = size of file
3732
;
3743
;
3733
;     mov   edi,[TASK_BASE]
3744
;     mov   edi,[TASK_BASE]
3734
;     add   edi,0x10
3745
;     add   edi,0x10
3735
;     add   esi,[edi]
3746
;     add   esi,[edi]
3736
;     add   eax,[edi]
3747
;     add   eax,[edi]
3737
;
3748
;
3738
;     pushad
3749
;     pushad
3739
;     mov  edi,esi
3750
;     mov  edi,esi
3740
;     add  edi,1024
3751
;     add  edi,1024
3741
;     mov  esi,0x100000+19*512
3752
;     mov  esi,0x100000+19*512
3742
;     sub  ecx,1
3753
;     sub  ecx,1
3743
;     shl  ecx,9
3754
;     shl  ecx,9
3744
;     add  esi,ecx
3755
;     add  esi,ecx
3745
;     shl  edx,9
3756
;     shl  edx,9
3746
;     mov  ecx,edx
3757
;     mov  ecx,edx
3747
;     cld
3758
;     cld
3748
;     rep  movsb
3759
;     rep  movsb
3749
;     popad
3760
;     popad
3750
;
3761
;
3751
;     mov   [esp+36],eax
3762
;     mov   [esp+36],eax
3752
;     mov   [esp+24],ebx
3763
;     mov   [esp+24],ebx
3753
;     ret
3764
;     ret
3754
 
3765
 
3755
 
3766
 
3756
 
3767
 
3757
align 4
3768
align 4
3758
 
3769
 
3759
sys_programirq:
3770
sys_programirq:
3760
 
3771
 
3761
    mov   edi,[TASK_BASE]
3772
    mov   edi,[TASK_BASE]
3762
    add   eax,[edi+TASKDATA.mem_start]
3773
    add   eax,[edi+TASKDATA.mem_start]
3763
 
3774
 
3764
    cmp   ebx,16
3775
    cmp   ebx,16
3765
    jae   .not_owner
3776
    jae   .not_owner
3766
    mov   edi,[TASK_BASE]
3777
    mov   edi,[TASK_BASE]
3767
    mov   edi,[edi+TASKDATA.pid]
3778
    mov   edi,[edi+TASKDATA.pid]
3768
    cmp   edi,[irq_owner+ebx*4]
3779
    cmp   edi,[irq_owner+ebx*4]
3769
    je    spril1
3780
    je    spril1
3770
.not_owner:
3781
.not_owner:
3771
    mov   [esp+36],dword 1
3782
    mov   [esp+36],dword 1
3772
    ret
3783
    ret
3773
  spril1:
3784
  spril1:
3774
 
3785
 
3775
    mov   esi,eax
3786
    mov   esi,eax
3776
    shl   ebx,6
3787
    shl   ebx,6
3777
    add   ebx,irq00read
3788
    add   ebx,irq00read
3778
    mov   edi,ebx
3789
    mov   edi,ebx
3779
    mov   ecx,16
3790
    mov   ecx,16
3780
    cld
3791
    cld
3781
    rep   movsd
3792
    rep   movsd
3782
    mov   [esp+36],dword 0
3793
    mov   [esp+36],dword 0
3783
    ret
3794
    ret
3784
 
3795
 
3785
 
3796
 
3786
align 4
3797
align 4
3787
 
3798
 
3788
get_irq_data:
3799
get_irq_data:
3789
     cmp   eax,16
3800
     cmp   eax,16
3790
     jae   .not_owner
3801
     jae   .not_owner
3791
     mov   edx,eax           ; check for correct owner
3802
     mov   edx,eax           ; check for correct owner
3792
     shl   edx,2
3803
     shl   edx,2
3793
     add   edx,irq_owner
3804
     add   edx,irq_owner
3794
     mov   edx,[edx]
3805
     mov   edx,[edx]
3795
     mov   edi,[TASK_BASE]
3806
     mov   edi,[TASK_BASE]
3796
     mov   edi,[edi+TASKDATA.pid]
3807
     mov   edi,[edi+TASKDATA.pid]
3797
     cmp   edx,edi
3808
     cmp   edx,edi
3798
     je    gidril1
3809
     je    gidril1
3799
.not_owner:
3810
.not_owner:
3800
     mov   [esp+32],dword 2     ; ecx=2
3811
     mov   [esp+32],dword 2     ; ecx=2
3801
     ret
3812
     ret
3802
 
3813
 
3803
  gidril1:
3814
  gidril1:
3804
 
3815
 
3805
     mov   ebx,eax
3816
     mov   ebx,eax
3806
     shl   ebx,12
3817
     shl   ebx,12
3807
     add   ebx,IRQ_SAVE
3818
     add   ebx,IRQ_SAVE
3808
     mov   eax,[ebx]
3819
     mov   eax,[ebx]
3809
     mov   ecx,1
3820
     mov   ecx,1
3810
     test  eax,eax
3821
     test  eax,eax
3811
     jz    gid1
3822
     jz    gid1
3812
 
3823
 
3813
     dec   eax
3824
     dec   eax
3814
     mov   esi,ebx
3825
     mov   esi,ebx
3815
     mov   [ebx],eax
3826
     mov   [ebx],eax
3816
     movzx ebx,byte [ebx+0x10]
3827
     movzx ebx,byte [ebx+0x10]
3817
     add   esi,0x10
3828
     add   esi,0x10
3818
     mov   edi,esi
3829
     mov   edi,esi
3819
     inc   esi
3830
     inc   esi
3820
     mov   ecx,4000 / 4
3831
     mov   ecx,4000 / 4
3821
     cld
3832
     cld
3822
     rep   movsd
3833
     rep   movsd
3823
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
3834
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
3824
   gid1:
3835
   gid1:
3825
     mov   [esp+36],eax
3836
     mov   [esp+36],eax
3826
     mov   [esp+32],ecx
3837
     mov   [esp+32],ecx
3827
     mov   [esp+24],ebx
3838
     mov   [esp+24],ebx
3828
     ret
3839
     ret
3829
 
3840
 
3830
 
3841
 
3831
set_io_access_rights:
3842
set_io_access_rights:
3832
 
3843
 
3833
     pushad
3844
     pushad
3834
 
3845
 
3835
     mov edi, tss._io_map_0
3846
     mov edi, tss._io_map_0
3836
 
3847
 
3837
;     mov   ecx,eax
3848
;     mov   ecx,eax
3838
;     and   ecx,7    ; offset in byte
3849
;     and   ecx,7    ; offset in byte
3839
 
3850
 
3840
;     shr   eax,3    ; number of byte
3851
;     shr   eax,3    ; number of byte
3841
;     add   edi,eax
3852
;     add   edi,eax
3842
 
3853
 
3843
;     mov   ebx,1
3854
;     mov   ebx,1
3844
;     shl   ebx,cl
3855
;     shl   ebx,cl
3845
 
3856
 
3846
     cmp   ebp,0                ; enable access - ebp = 0
3857
     cmp   ebp,0                ; enable access - ebp = 0
3847
     jne   siar1
3858
     jne   siar1
3848
 
3859
 
3849
;     not   ebx
3860
;     not   ebx
3850
;     and   [edi],byte bl
3861
;     and   [edi],byte bl
3851
     btr [edi], eax
3862
     btr [edi], eax
3852
 
3863
 
3853
     popad
3864
     popad
3854
 
3865
 
3855
     ret
3866
     ret
3856
 
3867
 
3857
siar1:
3868
siar1:
3858
 
3869
 
3859
     bts [edi], eax
3870
     bts [edi], eax
3860
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3871
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3861
 
3872
 
3862
     popad
3873
     popad
3863
 
3874
 
3864
     ret
3875
     ret
3865
 
3876
 
3866
r_f_port_area:
3877
r_f_port_area:
3867
 
3878
 
3868
     test  eax, eax
3879
     test  eax, eax
3869
     jnz   free_port_area
3880
     jnz   free_port_area
3870
;     je    r_port_area
3881
;     je    r_port_area
3871
;     jmp   free_port_area
3882
;     jmp   free_port_area
3872
 
3883
 
3873
;   r_port_area:
3884
;   r_port_area:
3874
 
3885
 
3875
     pushad
3886
     pushad
3876
 
3887
 
3877
     cmp   ebx,ecx            ; beginning > end ?
3888
     cmp   ebx,ecx            ; beginning > end ?
3878
     ja    rpal1
3889
     ja    rpal1
3879
     cmp   ecx,65536
3890
     cmp   ecx,65536
3880
     jae   rpal1
3891
     jae   rpal1
3881
     mov   esi,[RESERVED_PORTS]
3892
     mov   esi,[RESERVED_PORTS]
3882
     test  esi,esi            ; no reserved areas ?
3893
     test  esi,esi            ; no reserved areas ?
3883
     je    rpal2
3894
     je    rpal2
3884
     cmp   esi,255            ; max reserved
3895
     cmp   esi,255            ; max reserved
3885
     jae   rpal1
3896
     jae   rpal1
3886
 rpal3:
3897
 rpal3:
3887
     mov   edi,esi
3898
     mov   edi,esi
3888
     shl   edi,4
3899
     shl   edi,4
3889
     add   edi,RESERVED_PORTS
3900
     add   edi,RESERVED_PORTS
3890
     cmp   ebx,[edi+8]
3901
     cmp   ebx,[edi+8]
3891
     ja    rpal4
3902
     ja    rpal4
3892
     cmp   ecx,[edi+4]
3903
     cmp   ecx,[edi+4]
3893
     jae   rpal1
3904
     jae   rpal1
3894
;     jb    rpal4
3905
;     jb    rpal4
3895
;     jmp   rpal1
3906
;     jmp   rpal1
3896
 rpal4:
3907
 rpal4:
3897
 
3908
 
3898
     dec   esi
3909
     dec   esi
3899
     jnz   rpal3
3910
     jnz   rpal3
3900
     jmp   rpal2
3911
     jmp   rpal2
3901
   rpal1:
3912
   rpal1:
3902
     popad
3913
     popad
3903
     mov   eax,1
3914
     mov   eax,1
3904
     ret
3915
     ret
3905
 
3916
 
3906
   rpal2:
3917
   rpal2:
3907
     popad
3918
     popad
3908
 
3919
 
3909
 
3920
 
3910
     ; enable port access at port IO map
3921
     ; enable port access at port IO map
3911
     cli
3922
     cli
3912
     pushad                        ; start enable io map
3923
     pushad                        ; start enable io map
3913
 
3924
 
3914
     cmp   ecx,65536 ;16384
3925
     cmp   ecx,65536 ;16384
3915
     jae   no_unmask_io ; jge
3926
     jae   no_unmask_io ; jge
3916
 
3927
 
3917
     mov   eax,ebx
3928
     mov   eax,ebx
3918
 
3929
 
3919
   new_port_access:
3930
   new_port_access:
3920
 
3931
 
3921
     pushad
3932
     pushad
3922
 
3933
 
3923
     xor   ebp,ebp                ; enable - eax = port
3934
     xor   ebp,ebp                ; enable - eax = port
3924
     call  set_io_access_rights
3935
     call  set_io_access_rights
3925
 
3936
 
3926
     popad
3937
     popad
3927
 
3938
 
3928
     inc   eax
3939
     inc   eax
3929
     cmp   eax,ecx
3940
     cmp   eax,ecx
3930
     jbe   new_port_access
3941
     jbe   new_port_access
3931
 
3942
 
3932
   no_unmask_io:
3943
   no_unmask_io:
3933
 
3944
 
3934
     popad                         ; end enable io map
3945
     popad                         ; end enable io map
3935
     sti
3946
     sti
3936
 
3947
 
3937
     mov   edi,[RESERVED_PORTS]
3948
     mov   edi,[RESERVED_PORTS]
3938
     add   edi,1
3949
     add   edi,1
3939
     mov   [RESERVED_PORTS],edi
3950
     mov   [RESERVED_PORTS],edi
3940
     shl   edi,4
3951
     shl   edi,4
3941
     add   edi,RESERVED_PORTS
3952
     add   edi,RESERVED_PORTS
3942
     mov   esi,[TASK_BASE]
3953
     mov   esi,[TASK_BASE]
3943
     mov   esi,[esi+TASKDATA.pid]
3954
     mov   esi,[esi+TASKDATA.pid]
3944
     mov   [edi],esi
3955
     mov   [edi],esi
3945
     mov   [edi+4],ebx
3956
     mov   [edi+4],ebx
3946
     mov   [edi+8],ecx
3957
     mov   [edi+8],ecx
3947
 
3958
 
3948
     xor   eax, eax
3959
     xor   eax, eax
3949
     ret
3960
     ret
3950
 
3961
 
3951
free_port_area:
3962
free_port_area:
3952
 
3963
 
3953
     pushad
3964
     pushad
3954
 
3965
 
3955
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
3966
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
3956
     test  esi,esi
3967
     test  esi,esi
3957
     je    frpal2
3968
     je    frpal2
3958
     mov   edx,[TASK_BASE]
3969
     mov   edx,[TASK_BASE]
3959
     mov   edx,[edx+TASKDATA.pid]
3970
     mov   edx,[edx+TASKDATA.pid]
3960
   frpal3:
3971
   frpal3:
3961
     mov   edi,esi
3972
     mov   edi,esi
3962
     shl   edi,4
3973
     shl   edi,4
3963
     add   edi,RESERVED_PORTS
3974
     add   edi,RESERVED_PORTS
3964
     cmp   edx,[edi]
3975
     cmp   edx,[edi]
3965
     jne   frpal4
3976
     jne   frpal4
3966
     cmp   ebx,[edi+4]
3977
     cmp   ebx,[edi+4]
3967
     jne   frpal4
3978
     jne   frpal4
3968
     cmp   ecx,[edi+8]
3979
     cmp   ecx,[edi+8]
3969
     jne   frpal4
3980
     jne   frpal4
3970
     jmp   frpal1
3981
     jmp   frpal1
3971
   frpal4:
3982
   frpal4:
3972
     dec   esi
3983
     dec   esi
3973
     jnz   frpal3
3984
     jnz   frpal3
3974
   frpal2:
3985
   frpal2:
3975
     popad
3986
     popad
3976
     mov   eax,1
3987
     mov   eax,1
3977
     ret
3988
     ret
3978
   frpal1:
3989
   frpal1:
3979
     mov   ecx,256
3990
     mov   ecx,256
3980
     sub   ecx,esi
3991
     sub   ecx,esi
3981
     shl   ecx,4
3992
     shl   ecx,4
3982
     mov   esi,edi
3993
     mov   esi,edi
3983
     add   esi,16
3994
     add   esi,16
3984
     cld
3995
     cld
3985
     rep   movsb
3996
     rep   movsb
3986
 
3997
 
3987
     dec   dword [RESERVED_PORTS]
3998
     dec   dword [RESERVED_PORTS]
3988
 
3999
 
3989
     popad
4000
     popad
3990
 
4001
 
3991
 
4002
 
3992
     ; disable port access at port IO map
4003
     ; disable port access at port IO map
3993
 
4004
 
3994
     pushad                        ; start disable io map
4005
     pushad                        ; start disable io map
3995
 
4006
 
3996
     cmp   ecx,65536 ;16384
4007
     cmp   ecx,65536 ;16384
3997
     jge   no_mask_io
4008
     jge   no_mask_io
3998
 
4009
 
3999
     mov   eax,ebx
4010
     mov   eax,ebx
4000
 
4011
 
4001
   new_port_access_disable:
4012
   new_port_access_disable:
4002
 
4013
 
4003
     pushad
4014
     pushad
4004
 
4015
 
4005
     mov   ebp,1                  ; disable - eax = port
4016
     mov   ebp,1                  ; disable - eax = port
4006
     call  set_io_access_rights
4017
     call  set_io_access_rights
4007
 
4018
 
4008
     popad
4019
     popad
4009
 
4020
 
4010
     inc   eax
4021
     inc   eax
4011
     cmp   eax,ecx
4022
     cmp   eax,ecx
4012
     jbe   new_port_access_disable
4023
     jbe   new_port_access_disable
4013
 
4024
 
4014
   no_mask_io:
4025
   no_mask_io:
4015
 
4026
 
4016
     popad                         ; end disable io map
4027
     popad                         ; end disable io map
4017
 
4028
 
4018
     xor   eax, eax
4029
     xor   eax, eax
4019
     ret
4030
     ret
4020
 
4031
 
4021
 
4032
 
4022
reserve_free_irq:
4033
reserve_free_irq:
4023
 
4034
 
4024
     mov   ecx, 1
4035
     mov   ecx, 1
4025
     cmp   ebx, 16
4036
     cmp   ebx, 16
4026
     jae   fril1
4037
     jae   fril1
4027
     test  eax,eax
4038
     test  eax,eax
4028
     jz    reserve_irq
4039
     jz    reserve_irq
4029
 
4040
 
4030
     lea   edi,[irq_owner+ebx*4]
4041
     lea   edi,[irq_owner+ebx*4]
4031
     mov   edx,[edi]
4042
     mov   edx,[edi]
4032
     mov   eax,[TASK_BASE]
4043
     mov   eax,[TASK_BASE]
4033
     cmp   edx,[eax+TASKDATA.pid]
4044
     cmp   edx,[eax+TASKDATA.pid]
4034
     jne   fril1
4045
     jne   fril1
4035
     dec   ecx
4046
     dec   ecx
4036
     mov   [edi],ecx
4047
     mov   [edi],ecx
4037
   fril1:
4048
   fril1:
4038
     mov   [esp+36],ecx ; return in eax
4049
     mov   [esp+36],ecx ; return in eax
4039
     ret
4050
     ret
4040
 
4051
 
4041
  reserve_irq:
4052
  reserve_irq:
4042
 
4053
 
4043
     lea   edi,[irq_owner+ebx*4]
4054
     lea   edi,[irq_owner+ebx*4]
4044
     cmp   dword [edi], 0
4055
     cmp   dword [edi], 0
4045
     jnz   ril1
4056
     jnz   ril1
4046
 
4057
 
4047
     mov   edx,[TASK_BASE]
4058
     mov   edx,[TASK_BASE]
4048
     mov   edx,[edx+TASKDATA.pid]
4059
     mov   edx,[edx+TASKDATA.pid]
4049
     mov   [edi],edx
4060
     mov   [edi],edx
4050
     dec   ecx
4061
     dec   ecx
4051
   ril1:
4062
   ril1:
4052
     mov   [esp+36],ecx ; return in eax
4063
     mov   [esp+36],ecx ; return in eax
4053
     ret
4064
     ret
4054
 
4065
 
4055
drawbackground:
4066
drawbackground:
4056
       inc   [mouse_pause]
4067
       inc   [mouse_pause]
4057
       cmp   [SCR_MODE],word 0x12
4068
       cmp   [SCR_MODE],word 0x12
4058
       je   dbrv20
4069
       je   dbrv20
4059
     dbrv12:
4070
     dbrv12:
4060
       cmp  [SCR_MODE],word 0100000000000000b
4071
       cmp  [SCR_MODE],word 0100000000000000b
4061
       jge  dbrv20
4072
       jge  dbrv20
4062
       cmp  [SCR_MODE],word 0x13
4073
       cmp  [SCR_MODE],word 0x13
4063
       je   dbrv20
4074
       je   dbrv20
4064
       call  vesa12_drawbackground
4075
       call  vesa12_drawbackground
4065
       dec   [mouse_pause]
4076
       dec   [mouse_pause]
4066
       call   [draw_pointer]
4077
       call   [draw_pointer]
4067
       ret
4078
       ret
4068
     dbrv20:
4079
     dbrv20:
4069
       cmp   [display_data-12],dword 1
4080
       cmp   [display_data-12],dword 1
4070
       jne   bgrstr
4081
       jne   bgrstr
4071
       call  vesa20_drawbackground_tiled
4082
       call  vesa20_drawbackground_tiled
4072
       dec   [mouse_pause]
4083
       dec   [mouse_pause]
4073
       call   [draw_pointer]
4084
       call   [draw_pointer]
4074
       ret
4085
       ret
4075
     bgrstr:
4086
     bgrstr:
4076
       call  vesa20_drawbackground_stretch
4087
       call  vesa20_drawbackground_stretch
4077
       dec   [mouse_pause]
4088
       dec   [mouse_pause]
4078
       call   [draw_pointer]
4089
       call   [draw_pointer]
4079
       ret
4090
       ret
4080
 
4091
 
4081
align 4
4092
align 4
4082
 
4093
 
4083
syscall_putimage:                       ; PutImage
4094
syscall_putimage:                       ; PutImage
4084
 
4095
 
4085
     mov   edx,ecx
4096
     mov   edx,ecx
4086
     mov   ecx,ebx
4097
     mov   ecx,ebx
4087
     mov   ebx, eax
4098
     mov   ebx, eax
4088
 
4099
 
4089
sys_putimage:
4100
sys_putimage:
4090
     test  ecx,0x80008000
4101
     test  ecx,0x80008000
4091
     jnz   .exit
4102
     jnz   .exit
4092
     test  ecx,0x0000FFFF
4103
     test  ecx,0x0000FFFF
4093
     jz    .exit
4104
     jz    .exit
4094
     test  ecx,0xFFFF0000
4105
     test  ecx,0xFFFF0000
4095
     jnz   @f
4106
     jnz   @f
4096
  .exit:
4107
  .exit:
4097
     ret
4108
     ret
4098
 @@:
4109
 @@:
4099
        mov     edi,[current_slot]
4110
        mov     edi,[current_slot]
4100
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4111
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4101
        rol     edx,16
4112
        rol     edx,16
4102
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4113
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4103
        rol     edx,16
4114
        rol     edx,16
4104
  .forced:
4115
  .forced:
4105
        push    ebp esi 0
4116
        push    ebp esi 0
4106
        mov     ebp, putimage_get24bpp
4117
        mov     ebp, putimage_get24bpp
4107
        mov     esi, putimage_init24bpp
4118
        mov     esi, putimage_init24bpp
4108
sys_putimage_bpp:
4119
sys_putimage_bpp:
4109
;        call    [disable_mouse] ; this will be done in xxx_putimage
4120
;        call    [disable_mouse] ; this will be done in xxx_putimage
4110
;        mov     eax, vga_putimage
4121
;        mov     eax, vga_putimage
4111
        cmp     [SCR_MODE], word 0x12
4122
        cmp     [SCR_MODE], word 0x12
4112
        jz      @f   ;.doit
4123
        jz      @f   ;.doit
4113
        mov     eax, vesa12_putimage
4124
        mov     eax, vesa12_putimage
4114
        cmp     [SCR_MODE], word 0100000000000000b
4125
        cmp     [SCR_MODE], word 0100000000000000b
4115
        jae     @f
4126
        jae     @f
4116
        cmp     [SCR_MODE], word 0x13
4127
        cmp     [SCR_MODE], word 0x13
4117
        jnz     .doit
4128
        jnz     .doit
4118
@@:
4129
@@:
4119
        mov     eax, vesa20_putimage
4130
        mov     eax, vesa20_putimage
4120
.doit:
4131
.doit:
4121
        inc     [mouse_pause]
4132
        inc     [mouse_pause]
4122
        call    eax
4133
        call    eax
4123
        dec     [mouse_pause]
4134
        dec     [mouse_pause]
4124
        pop     ebp esi ebp
4135
        pop     ebp esi ebp
4125
        jmp     [draw_pointer]
4136
        jmp     [draw_pointer]
4126
 
4137
 
4127
syscall_putimage_palette:
4138
syscall_putimage_palette:
4128
        mov     edi, esi
4139
        mov     edi, esi
4129
        mov     esi, edx
4140
        mov     esi, edx
4130
        mov     edx, ecx
4141
        mov     edx, ecx
4131
        mov     ecx, ebx
4142
        mov     ecx, ebx
4132
        mov     ebx, eax
4143
        mov     ebx, eax
4133
sys_putimage_palette:
4144
sys_putimage_palette:
4134
; ebx = pointer to image
4145
; ebx = pointer to image
4135
; ecx = [xsize]*65536 + [ysize]
4146
; ecx = [xsize]*65536 + [ysize]
4136
; edx = [xstart]*65536 + [ystart]
4147
; edx = [xstart]*65536 + [ystart]
4137
; esi = number of bits per pixel, must be 8, 24 or 32
4148
; esi = number of bits per pixel, must be 8, 24 or 32
4138
; edi = pointer to palette
4149
; edi = pointer to palette
4139
; ebp = row delta
4150
; ebp = row delta
4140
        mov     eax, [CURRENT_TASK]
4151
        mov     eax, [CURRENT_TASK]
4141
        shl     eax, 8
4152
        shl     eax, 8
4142
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4153
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4143
        rol     edx, 16
4154
        rol     edx, 16
4144
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4155
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4145
        rol     edx, 16
4156
        rol     edx, 16
4146
.forced:
4157
.forced:
4147
        push    ebp esi ebp
4158
        push    ebp esi ebp
4148
        cmp     esi, 8
4159
        cmp     esi, 8
4149
        jnz     @f
4160
        jnz     @f
4150
        mov     ebp, putimage_get8bpp
4161
        mov     ebp, putimage_get8bpp
4151
        mov     esi, putimage_init8bpp
4162
        mov     esi, putimage_init8bpp
4152
        jmp     sys_putimage_bpp
4163
        jmp     sys_putimage_bpp
4153
@@:
4164
@@:
4154
        cmp     esi, 24
4165
        cmp     esi, 24
4155
        jnz     @f
4166
        jnz     @f
4156
        mov     ebp, putimage_get24bpp
4167
        mov     ebp, putimage_get24bpp
4157
        mov     esi, putimage_init24bpp
4168
        mov     esi, putimage_init24bpp
4158
        jmp     sys_putimage_bpp
4169
        jmp     sys_putimage_bpp
4159
@@:
4170
@@:
4160
        cmp     esi, 32
4171
        cmp     esi, 32
4161
        jnz     @f
4172
        jnz     @f
4162
        mov     ebp, putimage_get32bpp
4173
        mov     ebp, putimage_get32bpp
4163
        mov     esi, putimage_init32bpp
4174
        mov     esi, putimage_init32bpp
4164
        jmp     sys_putimage_bpp
4175
        jmp     sys_putimage_bpp
4165
@@:
4176
@@:
4166
        pop     ebp esi
4177
        pop     ebp esi
4167
        ret
4178
        ret
4168
 
4179
 
4169
putimage_init24bpp:
4180
putimage_init24bpp:
4170
        lea     eax, [eax*3]
4181
        lea     eax, [eax*3]
4171
putimage_init8bpp:
4182
putimage_init8bpp:
4172
        ret
4183
        ret
4173
 
4184
 
4174
putimage_get24bpp:
4185
putimage_get24bpp:
4175
        mov     eax, [esi]
4186
        mov     eax, [esi]
4176
        add     esi, 3
4187
        add     esi, 3
4177
        ret     4
4188
        ret     4
4178
putimage_get8bpp:
4189
putimage_get8bpp:
4179
        movzx   eax, byte [esi]
4190
        movzx   eax, byte [esi]
4180
        push    edx
4191
        push    edx
4181
        mov     edx, [esp+8]
4192
        mov     edx, [esp+8]
4182
        mov     eax, [edx+eax*4]
4193
        mov     eax, [edx+eax*4]
4183
        pop     edx
4194
        pop     edx
4184
        inc     esi
4195
        inc     esi
4185
        ret     4
4196
        ret     4
4186
 
4197
 
4187
putimage_init32bpp:
4198
putimage_init32bpp:
4188
        shl     eax, 2
4199
        shl     eax, 2
4189
        ret
4200
        ret
4190
putimage_get32bpp:
4201
putimage_get32bpp:
4191
        lodsd
4202
        lodsd
4192
        ret     4
4203
        ret     4
4193
 
4204
 
4194
; eax x beginning
4205
; eax x beginning
4195
; ebx y beginning
4206
; ebx y beginning
4196
; ecx x end
4207
; ecx x end
4197
	; edx y end
4208
	; edx y end
4198
; edi color
4209
; edi color
4199
 
4210
 
4200
__sys_drawbar:
4211
__sys_drawbar:
4201
        mov     esi,[current_slot]
4212
        mov     esi,[current_slot]
4202
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4213
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4203
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4214
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4204
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4215
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4205
        add     edx,[esi+APPDATA.wnd_clientbox.top]
4216
        add     edx,[esi+APPDATA.wnd_clientbox.top]
4206
  .forced:
4217
  .forced:
4207
    inc   [mouse_pause]
4218
    inc   [mouse_pause]
4208
;        call    [disable_mouse]
4219
;        call    [disable_mouse]
4209
    cmp   [SCR_MODE],word 0x12
4220
    cmp   [SCR_MODE],word 0x12
4210
    je   dbv20
4221
    je   dbv20
4211
   sdbv20:
4222
   sdbv20:
4212
    cmp  [SCR_MODE],word 0100000000000000b
4223
    cmp  [SCR_MODE],word 0100000000000000b
4213
    jge  dbv20
4224
    jge  dbv20
4214
    cmp  [SCR_MODE],word 0x13
4225
    cmp  [SCR_MODE],word 0x13
4215
    je   dbv20
4226
    je   dbv20
4216
    call vesa12_drawbar
4227
    call vesa12_drawbar
4217
    dec   [mouse_pause]
4228
    dec   [mouse_pause]
4218
    call   [draw_pointer]
4229
    call   [draw_pointer]
4219
    ret
4230
    ret
4220
  dbv20:
4231
  dbv20:
4221
    call vesa20_drawbar
4232
    call vesa20_drawbar
4222
    dec   [mouse_pause]
4233
    dec   [mouse_pause]
4223
    call   [draw_pointer]
4234
    call   [draw_pointer]
4224
    ret
4235
    ret
4225
 
4236
 
4226
 
4237
 
4227
 
4238
 
4228
kb_read:
4239
kb_read:
4229
 
4240
 
4230
        push    ecx edx
4241
        push    ecx edx
4231
 
4242
 
4232
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4243
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4233
      kr_loop:
4244
      kr_loop:
4234
        in      al,0x64
4245
        in      al,0x64
4235
        test    al,1
4246
        test    al,1
4236
        jnz     kr_ready
4247
        jnz     kr_ready
4237
        loop    kr_loop
4248
        loop    kr_loop
4238
        mov     ah,1
4249
        mov     ah,1
4239
        jmp     kr_exit
4250
        jmp     kr_exit
4240
      kr_ready:
4251
      kr_ready:
4241
        push    ecx
4252
        push    ecx
4242
        mov     ecx,32
4253
        mov     ecx,32
4243
      kr_delay:
4254
      kr_delay:
4244
        loop    kr_delay
4255
        loop    kr_delay
4245
        pop     ecx
4256
        pop     ecx
4246
        in      al,0x60
4257
        in      al,0x60
4247
        xor     ah,ah
4258
        xor     ah,ah
4248
      kr_exit:
4259
      kr_exit:
4249
 
4260
 
4250
        pop     edx ecx
4261
        pop     edx ecx
4251
 
4262
 
4252
        ret
4263
        ret
4253
 
4264
 
4254
 
4265
 
4255
kb_write:
4266
kb_write:
4256
 
4267
 
4257
        push    ecx edx
4268
        push    ecx edx
4258
 
4269
 
4259
        mov     dl,al
4270
        mov     dl,al
4260
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4271
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4261
;      kw_loop1:
4272
;      kw_loop1:
4262
;        in      al,0x64
4273
;        in      al,0x64
4263
;        test    al,0x20
4274
;        test    al,0x20
4264
;        jz      kw_ok1
4275
;        jz      kw_ok1
4265
;        loop    kw_loop1
4276
;        loop    kw_loop1
4266
;        mov     ah,1
4277
;        mov     ah,1
4267
;        jmp     kw_exit
4278
;        jmp     kw_exit
4268
;      kw_ok1:
4279
;      kw_ok1:
4269
        in      al,0x60
4280
        in      al,0x60
4270
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4281
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4271
      kw_loop:
4282
      kw_loop:
4272
        in      al,0x64
4283
        in      al,0x64
4273
        test    al,2
4284
        test    al,2
4274
        jz      kw_ok
4285
        jz      kw_ok
4275
        loop    kw_loop
4286
        loop    kw_loop
4276
        mov     ah,1
4287
        mov     ah,1
4277
        jmp     kw_exit
4288
        jmp     kw_exit
4278
      kw_ok:
4289
      kw_ok:
4279
        mov     al,dl
4290
        mov     al,dl
4280
        out     0x60,al
4291
        out     0x60,al
4281
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4292
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4282
      kw_loop3:
4293
      kw_loop3:
4283
        in      al,0x64
4294
        in      al,0x64
4284
        test    al,2
4295
        test    al,2
4285
        jz      kw_ok3
4296
        jz      kw_ok3
4286
        loop    kw_loop3
4297
        loop    kw_loop3
4287
        mov     ah,1
4298
        mov     ah,1
4288
        jmp     kw_exit
4299
        jmp     kw_exit
4289
      kw_ok3:
4300
      kw_ok3:
4290
        mov     ah,8
4301
        mov     ah,8
4291
      kw_loop4:
4302
      kw_loop4:
4292
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4303
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4293
      kw_loop5:
4304
      kw_loop5:
4294
        in      al,0x64
4305
        in      al,0x64
4295
        test    al,1
4306
        test    al,1
4296
        jnz     kw_ok4
4307
        jnz     kw_ok4
4297
        loop    kw_loop5
4308
        loop    kw_loop5
4298
        dec     ah
4309
        dec     ah
4299
        jnz     kw_loop4
4310
        jnz     kw_loop4
4300
      kw_ok4:
4311
      kw_ok4:
4301
        xor     ah,ah
4312
        xor     ah,ah
4302
      kw_exit:
4313
      kw_exit:
4303
 
4314
 
4304
        pop     edx ecx
4315
        pop     edx ecx
4305
 
4316
 
4306
        ret
4317
        ret
4307
 
4318
 
4308
 
4319
 
4309
kb_cmd:
4320
kb_cmd:
4310
 
4321
 
4311
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4322
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4312
      c_wait:
4323
      c_wait:
4313
        in      al,0x64
4324
        in      al,0x64
4314
        test    al,2
4325
        test    al,2
4315
        jz      c_send
4326
        jz      c_send
4316
        loop    c_wait
4327
        loop    c_wait
4317
        jmp     c_error
4328
        jmp     c_error
4318
      c_send:
4329
      c_send:
4319
        mov     al,bl
4330
        mov     al,bl
4320
        out     0x64,al
4331
        out     0x64,al
4321
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4332
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4322
      c_accept:
4333
      c_accept:
4323
        in      al,0x64
4334
        in      al,0x64
4324
        test    al,2
4335
        test    al,2
4325
        jz      c_ok
4336
        jz      c_ok
4326
        loop    c_accept
4337
        loop    c_accept
4327
      c_error:
4338
      c_error:
4328
        mov     ah,1
4339
        mov     ah,1
4329
        jmp     c_exit
4340
        jmp     c_exit
4330
      c_ok:
4341
      c_ok:
4331
        xor     ah,ah
4342
        xor     ah,ah
4332
      c_exit:
4343
      c_exit:
4333
        ret
4344
        ret
4334
 
4345
 
4335
 
4346
 
4336
setmouse:  ; set mousepicture -pointer
4347
setmouse:  ; set mousepicture -pointer
4337
           ; ps2 mouse enable
4348
           ; ps2 mouse enable
4338
 
4349
 
4339
     mov     [MOUSE_PICTURE],dword mousepointer
4350
     mov     [MOUSE_PICTURE],dword mousepointer
4340
 
4351
 
4341
     cli
4352
     cli
4342
;     mov     bl,0xa8                 ; enable mouse cmd
4353
;     mov     bl,0xa8                 ; enable mouse cmd
4343
;     call    kb_cmd
4354
;     call    kb_cmd
4344
;     call    kb_read                 ; read status
4355
;     call    kb_read                 ; read status
4345
;     mov     bl,0x20                 ; get command byte
4356
;     mov     bl,0x20                 ; get command byte
4346
;     call    kb_cmd
4357
;     call    kb_cmd
4347
;     call    kb_read
4358
;     call    kb_read
4348
;     or      al,3                    ; enable interrupt
4359
;     or      al,3                    ; enable interrupt
4349
;     mov     bl,0x60                 ; write command
4360
;     mov     bl,0x60                 ; write command
4350
;     push    eax
4361
;     push    eax
4351
;     call    kb_cmd
4362
;     call    kb_cmd
4352
;     pop     eax
4363
;     pop     eax
4353
;     call    kb_write
4364
;     call    kb_write
4354
;     mov     bl,0xd4                 ; for mouse
4365
;     mov     bl,0xd4                 ; for mouse
4355
;     call    kb_cmd
4366
;     call    kb_cmd
4356
;     mov     al,0xf4                 ; enable mouse device
4367
;     mov     al,0xf4                 ; enable mouse device
4357
;     call    kb_write
4368
;     call    kb_write
4358
;     call    kb_read           ; read status return
4369
;     call    kb_read           ; read status return
4359
 
4370
 
4360
     ; com1 mouse enable
4371
     ; com1 mouse enable
4361
 
4372
 
4362
     mov   bx,0x3f8 ; combase
4373
     mov   bx,0x3f8 ; combase
4363
 
4374
 
4364
     mov   dx,bx
4375
     mov   dx,bx
4365
     add   dx,3
4376
     add   dx,3
4366
     mov   al,0x80
4377
     mov   al,0x80
4367
     out   dx,al
4378
     out   dx,al
4368
 
4379
 
4369
     mov   dx,bx
4380
     mov   dx,bx
4370
     add   dx,1
4381
     add   dx,1
4371
     mov   al,0
4382
     mov   al,0
4372
     out   dx,al
4383
     out   dx,al
4373
 
4384
 
4374
     mov   dx,bx
4385
     mov   dx,bx
4375
     add   dx,0
4386
     add   dx,0
4376
     mov   al,0x30*2    ; 0x30 / 4
4387
     mov   al,0x30*2    ; 0x30 / 4
4377
     out   dx,al
4388
     out   dx,al
4378
 
4389
 
4379
     mov   dx,bx
4390
     mov   dx,bx
4380
     add   dx,3
4391
     add   dx,3
4381
     mov   al,2         ; 3
4392
     mov   al,2         ; 3
4382
     out   dx,al
4393
     out   dx,al
4383
 
4394
 
4384
     mov   dx,bx
4395
     mov   dx,bx
4385
     add   dx,4
4396
     add   dx,4
4386
     mov   al,0xb
4397
     mov   al,0xb
4387
     out   dx,al
4398
     out   dx,al
4388
 
4399
 
4389
     mov   dx,bx
4400
     mov   dx,bx
4390
     add   dx,1
4401
     add   dx,1
4391
     mov   al,1
4402
     mov   al,1
4392
     out   dx,al
4403
     out   dx,al
4393
 
4404
 
4394
 
4405
 
4395
     ; com2 mouse enable
4406
     ; com2 mouse enable
4396
 
4407
 
4397
     mov   bx,0x2f8 ; combase
4408
     mov   bx,0x2f8 ; combase
4398
 
4409
 
4399
     mov   dx,bx
4410
     mov   dx,bx
4400
     add   dx,3
4411
     add   dx,3
4401
     mov   al,0x80
4412
     mov   al,0x80
4402
     out   dx,al
4413
     out   dx,al
4403
 
4414
 
4404
     mov   dx,bx
4415
     mov   dx,bx
4405
     add   dx,1
4416
     add   dx,1
4406
     mov   al,0
4417
     mov   al,0
4407
     out   dx,al
4418
     out   dx,al
4408
 
4419
 
4409
     mov   dx,bx
4420
     mov   dx,bx
4410
     add   dx,0
4421
     add   dx,0
4411
     mov   al,0x30*2
4422
     mov   al,0x30*2
4412
     out   dx,al
4423
     out   dx,al
4413
 
4424
 
4414
     mov   dx,bx
4425
     mov   dx,bx
4415
     add   dx,3
4426
     add   dx,3
4416
     mov   al,2
4427
     mov   al,2
4417
     out   dx,al
4428
     out   dx,al
4418
 
4429
 
4419
     mov   dx,bx
4430
     mov   dx,bx
4420
     add   dx,4
4431
     add   dx,4
4421
     mov   al,0xb
4432
     mov   al,0xb
4422
     out   dx,al
4433
     out   dx,al
4423
 
4434
 
4424
     mov   dx,bx
4435
     mov   dx,bx
4425
     add   dx,1
4436
     add   dx,1
4426
     mov   al,1
4437
     mov   al,1
4427
     out   dx,al
4438
     out   dx,al
4428
 
4439
 
4429
     ret
4440
     ret
4430
 
4441
 
4431
 
4442
 
4432
_rdtsc:
4443
_rdtsc:
4433
     bt [cpu_caps], CAPS_TSC
4444
     bt [cpu_caps], CAPS_TSC
4434
     jnc ret_rdtsc
4445
     jnc ret_rdtsc
4435
     rdtsc
4446
     rdtsc
4436
     ret
4447
     ret
4437
   ret_rdtsc:
4448
   ret_rdtsc:
4438
     mov   edx,0xffffffff
4449
     mov   edx,0xffffffff
4439
     mov   eax,0xffffffff
4450
     mov   eax,0xffffffff
4440
     ret
4451
     ret
4441
 
4452
 
4442
rerouteirqs:
4453
rerouteirqs:
4443
 
4454
 
4444
        cli
4455
        cli
4445
 
4456
 
4446
        mov     al,0x11         ;  icw4, edge triggered
4457
        mov     al,0x11         ;  icw4, edge triggered
4447
        out     0x20,al
4458
        out     0x20,al
4448
        call    pic_delay
4459
        call    pic_delay
4449
        out     0xA0,al
4460
        out     0xA0,al
4450
        call    pic_delay
4461
        call    pic_delay
4451
 
4462
 
4452
        mov     al,0x20         ;  generate 0x20 +
4463
        mov     al,0x20         ;  generate 0x20 +
4453
        out     0x21,al
4464
        out     0x21,al
4454
        call    pic_delay
4465
        call    pic_delay
4455
        mov     al,0x28         ;  generate 0x28 +
4466
        mov     al,0x28         ;  generate 0x28 +
4456
        out     0xA1,al
4467
        out     0xA1,al
4457
        call    pic_delay
4468
        call    pic_delay
4458
 
4469
 
4459
        mov     al,0x04         ;  slave at irq2
4470
        mov     al,0x04         ;  slave at irq2
4460
        out     0x21,al
4471
        out     0x21,al
4461
        call    pic_delay
4472
        call    pic_delay
4462
        mov     al,0x02         ;  at irq9
4473
        mov     al,0x02         ;  at irq9
4463
        out     0xA1,al
4474
        out     0xA1,al
4464
        call    pic_delay
4475
        call    pic_delay
4465
 
4476
 
4466
        mov     al,0x01         ;  8086 mode
4477
        mov     al,0x01         ;  8086 mode
4467
        out     0x21,al
4478
        out     0x21,al
4468
        call    pic_delay
4479
        call    pic_delay
4469
        out     0xA1,al
4480
        out     0xA1,al
4470
        call    pic_delay
4481
        call    pic_delay
4471
 
4482
 
4472
        mov     al,255          ; mask all irq's
4483
        mov     al,255          ; mask all irq's
4473
        out     0xA1,al
4484
        out     0xA1,al
4474
        call    pic_delay
4485
        call    pic_delay
4475
        out     0x21,al
4486
        out     0x21,al
4476
        call    pic_delay
4487
        call    pic_delay
4477
 
4488
 
4478
        mov     ecx,0x1000
4489
        mov     ecx,0x1000
4479
        cld
4490
        cld
4480
picl1:  call    pic_delay
4491
picl1:  call    pic_delay
4481
        loop    picl1
4492
        loop    picl1
4482
 
4493
 
4483
        mov     al,255          ; mask all irq's
4494
        mov     al,255          ; mask all irq's
4484
        out     0xA1,al
4495
        out     0xA1,al
4485
        call    pic_delay
4496
        call    pic_delay
4486
        out     0x21,al
4497
        out     0x21,al
4487
        call    pic_delay
4498
        call    pic_delay
4488
 
4499
 
4489
        cli
4500
        cli
4490
 
4501
 
4491
        ret
4502
        ret
4492
 
4503
 
4493
 
4504
 
4494
pic_delay:
4505
pic_delay:
4495
 
4506
 
4496
        jmp     pdl1
4507
        jmp     pdl1
4497
pdl1:   ret
4508
pdl1:   ret
4498
 
4509
 
4499
 
4510
 
4500
sys_msg_board_str:
4511
sys_msg_board_str:
4501
 
4512
 
4502
     pushad
4513
     pushad
4503
   @@:
4514
   @@:
4504
     cmp    [esi],byte 0
4515
     cmp    [esi],byte 0
4505
     je     @f
4516
     je     @f
4506
     mov    eax,1
4517
     mov    eax,1
4507
     movzx  ebx,byte [esi]
4518
     movzx  ebx,byte [esi]
4508
     call   sys_msg_board
4519
     call   sys_msg_board
4509
     inc    esi
4520
     inc    esi
4510
     jmp    @b
4521
     jmp    @b
4511
   @@:
4522
   @@:
4512
     popad
4523
     popad
4513
     ret
4524
     ret
4514
 
4525
 
4515
uglobal
4526
uglobal
4516
  msg_board_data: times 4096 db 0
4527
  msg_board_data: times 4096 db 0
4517
  msg_board_count dd 0x0
4528
  msg_board_count dd 0x0
4518
endg
4529
endg
4519
 
4530
 
4520
sys_msg_board:
4531
sys_msg_board:
4521
 
4532
 
4522
; eax=1 : write :  bl byte to write
4533
; eax=1 : write :  bl byte to write
4523
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4534
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4524
 
4535
 
4525
     mov  ecx,[msg_board_count]
4536
     mov  ecx,[msg_board_count]
4526
     cmp  eax, 1
4537
     cmp  eax, 1
4527
     jne  smbl1
4538
     jne  smbl1
4528
 
4539
 
4529
 
4540
 
4530
     mov  [msg_board_data+ecx],bl
4541
     mov  [msg_board_data+ecx],bl
4531
     inc  ecx
4542
     inc  ecx
4532
     and  ecx, 4095
4543
     and  ecx, 4095
4533
     mov  [msg_board_count], ecx
4544
     mov  [msg_board_count], ecx
4534
     mov  [check_idle_semaphore], 5
4545
     mov  [check_idle_semaphore], 5
4535
     ret
4546
     ret
4536
   smbl1:
4547
   smbl1:
4537
 
4548
 
4538
     cmp   eax, 2
4549
     cmp   eax, 2
4539
     jne   smbl2
4550
     jne   smbl2
4540
     test  ecx, ecx
4551
     test  ecx, ecx
4541
     jz    smbl21
4552
     jz    smbl21
4542
;     mov   edi, msg_board_data
4553
;     mov   edi, msg_board_data
4543
;     mov   esi, msg_board_data+1
4554
;     mov   esi, msg_board_data+1
4544
;     movzx eax, byte [edi]
4555
;     movzx eax, byte [edi]
4545
     mov   eax, msg_board_data+1
4556
     mov   eax, msg_board_data+1
4546
     mov   ebx, msg_board_data
4557
     mov   ebx, msg_board_data
4547
     movzx edx, byte [ebx]
4558
     movzx edx, byte [ebx]
4548
     call  memmove
4559
     call  memmove
4549
;     push  ecx
4560
;     push  ecx
4550
;     shr   ecx, 2
4561
;     shr   ecx, 2
4551
;     cld
4562
;     cld
4552
;     rep   movsd
4563
;     rep   movsd
4553
;     pop   ecx
4564
;     pop   ecx
4554
;     and   ecx, 3
4565
;     and   ecx, 3
4555
;     rep   movsb
4566
;     rep   movsb
4556
     dec   [msg_board_count]
4567
     dec   [msg_board_count]
4557
     mov   [esp+36], edx ;eax
4568
     mov   [esp+36], edx ;eax
4558
     mov   [esp+24], dword 1
4569
     mov   [esp+24], dword 1
4559
     ret
4570
     ret
4560
   smbl21:
4571
   smbl21:
4561
     mov   [esp+36], ecx
4572
     mov   [esp+36], ecx
4562
     mov   [esp+24], ecx
4573
     mov   [esp+24], ecx
4563
 
4574
 
4564
   smbl2:
4575
   smbl2:
4565
     ret
4576
     ret
4566
 
4577
 
4567
 
4578
 
4568
 
4579
 
4569
sys_process_def:
4580
sys_process_def:
4570
        mov     edi, [CURRENT_TASK]
4581
        mov     edi, [CURRENT_TASK]
4571
 
4582
 
4572
        dec     eax             ; 1 = set keyboard mode
4583
        dec     eax             ; 1 = set keyboard mode
4573
     jne   no_set_keyboard_setup
4584
     jne   no_set_keyboard_setup
4574
 
4585
 
4575
     shl   edi,8
4586
     shl   edi,8
4576
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4587
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
4577
 
4588
 
4578
     ret
4589
     ret
4579
 
4590
 
4580
   no_set_keyboard_setup:
4591
   no_set_keyboard_setup:
4581
 
4592
 
4582
        dec     eax             ; 2 = get keyboard mode
4593
        dec     eax             ; 2 = get keyboard mode
4583
     jne   no_get_keyboard_setup
4594
     jne   no_get_keyboard_setup
4584
 
4595
 
4585
     shl   edi,8
4596
     shl   edi,8
4586
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4597
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4587
 
4598
 
4588
     mov   [esp+36],eax
4599
     mov   [esp+36],eax
4589
 
4600
 
4590
     ret
4601
     ret
4591
 
4602
 
4592
   no_get_keyboard_setup:
4603
   no_get_keyboard_setup:
4593
 
4604
 
4594
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4605
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
4595
     jne   no_get_keyboard_cas
4606
     jne   no_get_keyboard_cas
4596
 
4607
 
4597
;     xor   eax,eax
4608
;     xor   eax,eax
4598
;     movzx eax,byte [shift]
4609
;     movzx eax,byte [shift]
4599
;     movzx ebx,byte [ctrl]
4610
;     movzx ebx,byte [ctrl]
4600
;     shl   ebx,2
4611
;     shl   ebx,2
4601
;     add   eax,ebx
4612
;     add   eax,ebx
4602
;     movzx ebx,byte [alt]
4613
;     movzx ebx,byte [alt]
4603
;     shl   ebx,3
4614
;     shl   ebx,3
4604
;     add   eax,ebx
4615
;     add   eax,ebx
4605
 
4616
 
4606
 ;// mike.dld [
4617
 ;// mike.dld [
4607
     mov   eax, [kb_state]
4618
     mov   eax, [kb_state]
4608
 ;// mike.dld ]
4619
 ;// mike.dld ]
4609
 
4620
 
4610
     mov   [esp+36],eax
4621
     mov   [esp+36],eax
4611
 
4622
 
4612
     ret
4623
     ret
4613
 
4624
 
4614
   no_get_keyboard_cas:
4625
   no_get_keyboard_cas:
4615
 
4626
 
4616
        dec     eax
4627
        dec     eax
4617
        jnz     no_add_keyboard_hotkey
4628
        jnz     no_add_keyboard_hotkey
4618
 
4629
 
4619
        mov     eax, hotkey_list
4630
        mov     eax, hotkey_list
4620
@@:
4631
@@:
4621
        cmp     dword [eax+8], 0
4632
        cmp     dword [eax+8], 0
4622
        jz      .found_free
4633
        jz      .found_free
4623
        add     eax, 16
4634
        add     eax, 16
4624
        cmp     eax, hotkey_list+16*256
4635
        cmp     eax, hotkey_list+16*256
4625
        jb      @b
4636
        jb      @b
4626
        mov     dword [esp+36], 1
4637
        mov     dword [esp+36], 1
4627
        ret
4638
        ret
4628
.found_free:
4639
.found_free:
4629
        mov     [eax+8], edi
4640
        mov     [eax+8], edi
4630
        mov     [eax+4], ecx
4641
        mov     [eax+4], ecx
4631
        movzx   ebx, bl
4642
        movzx   ebx, bl
4632
        lea     ebx, [hotkey_scancodes+ebx*4]
4643
        lea     ebx, [hotkey_scancodes+ebx*4]
4633
        mov     ecx, [ebx]
4644
        mov     ecx, [ebx]
4634
        mov     [eax], ecx
4645
        mov     [eax], ecx
4635
        mov     [ebx], eax
4646
        mov     [ebx], eax
4636
        mov     [eax+12], ebx
4647
        mov     [eax+12], ebx
4637
        jecxz   @f
4648
        jecxz   @f
4638
        mov     [ecx+12], eax
4649
        mov     [ecx+12], eax
4639
@@:
4650
@@:
4640
        and     dword [esp+36], 0
4651
        and     dword [esp+36], 0
4641
        ret
4652
        ret
4642
 
4653
 
4643
no_add_keyboard_hotkey:
4654
no_add_keyboard_hotkey:
4644
 
4655
 
4645
        dec     eax
4656
        dec     eax
4646
        jnz     no_del_keyboard_hotkey
4657
        jnz     no_del_keyboard_hotkey
4647
 
4658
 
4648
        movzx   ebx, bl
4659
        movzx   ebx, bl
4649
        lea     ebx, [hotkey_scancodes+ebx*4]
4660
        lea     ebx, [hotkey_scancodes+ebx*4]
4650
        mov     eax, [ebx]
4661
        mov     eax, [ebx]
4651
.scan:
4662
.scan:
4652
        test    eax, eax
4663
        test    eax, eax
4653
        jz      .notfound
4664
        jz      .notfound
4654
        cmp     [eax+8], edi
4665
        cmp     [eax+8], edi
4655
        jnz     .next
4666
        jnz     .next
4656
        cmp     [eax+4], ecx
4667
        cmp     [eax+4], ecx
4657
        jz      .found
4668
        jz      .found
4658
.next:
4669
.next:
4659
        mov     eax, [eax]
4670
        mov     eax, [eax]
4660
        jmp     .scan
4671
        jmp     .scan
4661
.notfound:
4672
.notfound:
4662
        mov     dword [esp+36], 1
4673
        mov     dword [esp+36], 1
4663
        ret
4674
        ret
4664
.found:
4675
.found:
4665
        mov     ecx, [eax]
4676
        mov     ecx, [eax]
4666
        jecxz   @f
4677
        jecxz   @f
4667
        mov     edx, [eax+12]
4678
        mov     edx, [eax+12]
4668
        mov     [ecx+12], edx
4679
        mov     [ecx+12], edx
4669
@@:
4680
@@:
4670
        mov     ecx, [eax+12]
4681
        mov     ecx, [eax+12]
4671
        mov     edx, [eax]
4682
        mov     edx, [eax]
4672
        mov     [ecx], edx
4683
        mov     [ecx], edx
4673
        xor     edx, edx
4684
        xor     edx, edx
4674
        mov     [eax+4], edx
4685
        mov     [eax+4], edx
4675
        mov     [eax+8], edx
4686
        mov     [eax+8], edx
4676
        mov     [eax+12], edx
4687
        mov     [eax+12], edx
4677
        mov     [eax], edx
4688
        mov     [eax], edx
4678
        mov     [esp+36], edx
4689
        mov     [esp+36], edx
4679
        ret
4690
        ret
4680
 
4691
 
4681
no_del_keyboard_hotkey:
4692
no_del_keyboard_hotkey:
4682
     ret
4693
     ret
4683
 
4694
 
4684
 
4695
 
4685
align 4
4696
align 4
4686
 
4697
 
4687
sys_gs:                         ; direct screen access
4698
sys_gs:                         ; direct screen access
4688
 
4699
 
4689
     cmp  eax,1                 ; resolution
4700
     cmp  eax,1                 ; resolution
4690
     jne  no_gs1
4701
     jne  no_gs1
4691
     mov  eax,[ScreenWidth]
4702
     mov  eax,[ScreenWidth]
4692
     shl  eax,16
4703
     shl  eax,16
4693
     mov  ax,[ScreenHeight]
4704
     mov  ax,[ScreenHeight]
4694
     add  eax,0x00010001
4705
     add  eax,0x00010001
4695
     mov  [esp+36],eax
4706
     mov  [esp+36],eax
4696
     ret
4707
     ret
4697
   no_gs1:
4708
   no_gs1:
4698
 
4709
 
4699
     cmp   eax,2                ; bits per pixel
4710
     cmp   eax,2                ; bits per pixel
4700
     jne   no_gs2
4711
     jne   no_gs2
4701
     movzx eax,byte [ScreenBPP]
4712
     movzx eax,byte [ScreenBPP]
4702
     mov   [esp+36],eax
4713
     mov   [esp+36],eax
4703
     ret
4714
     ret
4704
   no_gs2:
4715
   no_gs2:
4705
 
4716
 
4706
     cmp   eax,3                ; bytes per scanline
4717
     cmp   eax,3                ; bytes per scanline
4707
     jne   no_gs3
4718
     jne   no_gs3
4708
     mov   eax,[BytesPerScanLine]
4719
     mov   eax,[BytesPerScanLine]
4709
     mov   [esp+36],eax
4720
     mov   [esp+36],eax
4710
     ret
4721
     ret
4711
   no_gs3:
4722
   no_gs3:
4712
 
4723
 
4713
     mov  [esp+36],dword -1
4724
     mov  [esp+36],dword -1
4714
     ret
4725
     ret
4715
 
4726
 
4716
 
4727
 
4717
align 4 ; PCI functions
4728
align 4 ; PCI functions
4718
 
4729
 
4719
sys_pci:
4730
sys_pci:
4720
 
4731
 
4721
     call  pci_api
4732
     call  pci_api
4722
     mov   [esp+36],eax
4733
     mov   [esp+36],eax
4723
     ret
4734
     ret
4724
 
4735
 
4725
 
4736
 
4726
align 4  ;  system functions
4737
align 4  ;  system functions
4727
 
4738
 
4728
syscall_setpixel:                       ; SetPixel
4739
syscall_setpixel:                       ; SetPixel
4729
 
4740
 
4730
 
4741
 
4731
     mov   edx,[TASK_BASE]
4742
     mov   edx,[TASK_BASE]
4732
     add   eax,[edx-twdw+WDATA.box.left]
4743
     add   eax,[edx-twdw+WDATA.box.left]
4733
     add   ebx,[edx-twdw+WDATA.box.top]
4744
     add   ebx,[edx-twdw+WDATA.box.top]
4734
        mov     edi,[current_slot]
4745
        mov     edi,[current_slot]
4735
        add     eax,[edi+APPDATA.wnd_clientbox.left]
4746
        add     eax,[edi+APPDATA.wnd_clientbox.left]
4736
        add     ebx,[edi+APPDATA.wnd_clientbox.top]
4747
        add     ebx,[edi+APPDATA.wnd_clientbox.top]
4737
     xor   edi,edi ; no force
4748
     xor   edi,edi ; no force
4738
;     mov   edi,1
4749
;     mov   edi,1
4739
     call  [disable_mouse]
4750
     call  [disable_mouse]
4740
     jmp   [putpixel]
4751
     jmp   [putpixel]
4741
 
4752
 
4742
align 4
4753
align 4
4743
 
4754
 
4744
syscall_writetext:                      ; WriteText
4755
syscall_writetext:                      ; WriteText
4745
 
4756
 
4746
        mov   edi,[TASK_BASE]
4757
        mov   edi,[TASK_BASE]
4747
        mov   ebp,[edi-twdw+WDATA.box.left]
4758
        mov   ebp,[edi-twdw+WDATA.box.left]
4748
        push  esi
4759
        push  esi
4749
        mov   esi,[current_slot]
4760
        mov   esi,[current_slot]
4750
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
4761
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
4751
        shl   ebp,16
4762
        shl   ebp,16
4752
        add   ebp,[edi-twdw+WDATA.box.top]
4763
        add   ebp,[edi-twdw+WDATA.box.top]
4753
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
4764
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
4754
        pop   esi
4765
        pop   esi
4755
        add   ecx,[edi+TASKDATA.mem_start]
4766
        add   ecx,[edi+TASKDATA.mem_start]
4756
        add   eax,ebp
4767
        add   eax,ebp
4757
        xor   edi,edi
4768
        xor   edi,edi
4758
        jmp   dtext
4769
        jmp   dtext
4759
 
4770
 
4760
align 4
4771
align 4
4761
 
4772
 
4762
syscall_openramdiskfile:                ; OpenRamdiskFile
4773
syscall_openramdiskfile:                ; OpenRamdiskFile
4763
 
4774
 
4764
 
4775
 
4765
     mov   edi,[TASK_BASE]
4776
     mov   edi,[TASK_BASE]
4766
     add   edi,TASKDATA.mem_start
4777
     add   edi,TASKDATA.mem_start
4767
     add   eax,[edi]
4778
     add   eax,[edi]
4768
     add   edx,[edi]
4779
     add   edx,[edi]
4769
     mov   esi,12
4780
     mov   esi,12
4770
     call  fileread
4781
     call  fileread
4771
     mov   [esp+36],ebx
4782
     mov   [esp+36],ebx
4772
     ret
4783
     ret
4773
 
4784
 
4774
align 4
4785
align 4
4775
 
4786
 
4776
syscall_drawrect:                       ; DrawRect
4787
syscall_drawrect:                       ; DrawRect
4777
 
4788
 
4778
     mov   edi,ecx
4789
     mov   edi,ecx
4779
     and   edi,0x80FFFFFF
4790
     and   edi,0x80FFFFFF
4780
     test  ax,ax
4791
     test  ax,ax
4781
     je    drectr
4792
     je    drectr
4782
     test  bx,bx
4793
     test  bx,bx
4783
     je    drectr
4794
     je    drectr
4784
     movzx ecx,ax
4795
     movzx ecx,ax
4785
     shr   eax,16
4796
     shr   eax,16
4786
     movzx edx,bx
4797
     movzx edx,bx
4787
     shr   ebx,16
4798
     shr   ebx,16
4788
        mov     esi,[current_slot]
4799
        mov     esi,[current_slot]
4789
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4800
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4790
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4801
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4791
     add   ecx,eax
4802
     add   ecx,eax
4792
     add   edx,ebx
4803
     add   edx,ebx
4793
     jmp   [drawbar]
4804
     jmp   [drawbar]
4794
    drectr:
4805
    drectr:
4795
     ret
4806
     ret
4796
 
4807
 
4797
align 4
4808
align 4
4798
 
4809
 
4799
syscall_getscreensize:                  ; GetScreenSize
4810
syscall_getscreensize:                  ; GetScreenSize
4800
 
4811
 
4801
     movzx eax,word[ScreenWidth]
4812
     movzx eax,word[ScreenWidth]
4802
     shl   eax,16
4813
     shl   eax,16
4803
     mov   ax,[ScreenHeight]
4814
     mov   ax,[ScreenHeight]
4804
     mov   [esp+36],eax
4815
     mov   [esp+36],eax
4805
     ret
4816
     ret
4806
 
4817
 
4807
align 4
4818
align 4
4808
 
4819
 
4809
syscall_cdaudio:                        ; CD
4820
syscall_cdaudio:                        ; CD
4810
 
4821
 
4811
     call  sys_cd_audio
4822
     call  sys_cd_audio
4812
     mov   [esp+36],eax
4823
     mov   [esp+36],eax
4813
     ret
4824
     ret
4814
 
4825
 
4815
align 4
4826
align 4
4816
 
4827
 
4817
syscall_delramdiskfile:                 ; DelRamdiskFile
4828
syscall_delramdiskfile:                 ; DelRamdiskFile
4818
 
4829
 
4819
     mov   edi,[TASK_BASE]
4830
     mov   edi,[TASK_BASE]
4820
     add   edi,TASKDATA.mem_start
4831
     add   edi,TASKDATA.mem_start
4821
     add   eax,[edi]
4832
     add   eax,[edi]
4822
     call  filedelete
4833
     call  filedelete
4823
     mov   [esp+36],eax
4834
     mov   [esp+36],eax
4824
     ret
4835
     ret
4825
 
4836
 
4826
align 4
4837
align 4
4827
 
4838
 
4828
syscall_writeramdiskfile:               ; WriteRamdiskFile
4839
syscall_writeramdiskfile:               ; WriteRamdiskFile
4829
 
4840
 
4830
     mov   edi,[TASK_BASE]
4841
     mov   edi,[TASK_BASE]
4831
     add   edi,TASKDATA.mem_start
4842
     add   edi,TASKDATA.mem_start
4832
     add   eax,[edi]
4843
     add   eax,[edi]
4833
     add   ebx,[edi]
4844
     add   ebx,[edi]
4834
     call  filesave
4845
     call  filesave
4835
     mov   [esp+36],eax
4846
     mov   [esp+36],eax
4836
     ret
4847
     ret
4837
 
4848
 
4838
align 4
4849
align 4
4839
 
4850
 
4840
syscall_getpixel:                       ; GetPixel
4851
syscall_getpixel:                       ; GetPixel
4841
     mov   ecx,[ScreenWidth]
4852
     mov   ecx,[ScreenWidth]
4842
     inc   ecx
4853
     inc   ecx
4843
     xor   edx,edx
4854
     xor   edx,edx
4844
     div   ecx
4855
     div   ecx
4845
     mov   ebx,edx
4856
     mov   ebx,edx
4846
     xchg  eax,ebx
4857
     xchg  eax,ebx
4847
     call  dword [GETPIXEL]
4858
     call  dword [GETPIXEL]
4848
     mov   [esp+36],ecx
4859
     mov   [esp+36],ecx
4849
     ret
4860
     ret
4850
 
4861
 
4851
align 4
4862
align 4
4852
 
4863
 
4853
syscall_readstring:                     ; ReadString
4864
syscall_readstring:                     ; ReadString
4854
 
4865
 
4855
     mov   edi,[TASK_BASE]
4866
     mov   edi,[TASK_BASE]
4856
     add   edi,TASKDATA.mem_start
4867
     add   edi,TASKDATA.mem_start
4857
     add   eax,[edi]
4868
     add   eax,[edi]
4858
     call  read_string
4869
     call  read_string
4859
     mov   [esp+36],eax
4870
     mov   [esp+36],eax
4860
     ret
4871
     ret
4861
 
4872
 
4862
align 4
4873
align 4
4863
 
4874
 
4864
syscall_drawline:                       ; DrawLine
4875
syscall_drawline:                       ; DrawLine
4865
 
4876
 
4866
     mov   edi,[TASK_BASE]
4877
     mov   edi,[TASK_BASE]
4867
     movzx edx,word[edi-twdw+WDATA.box.left]
4878
     movzx edx,word[edi-twdw+WDATA.box.left]
4868
     mov   ebp,edx
4879
     mov   ebp,edx
4869
        mov     esi,[current_slot]
4880
        mov     esi,[current_slot]
4870
        add     ebp,[esi+APPDATA.wnd_clientbox.left]
4881
        add     ebp,[esi+APPDATA.wnd_clientbox.left]
4871
        add     dx,word[esi+APPDATA.wnd_clientbox.left]
4882
        add     dx,word[esi+APPDATA.wnd_clientbox.left]
4872
     shl   edx,16
4883
     shl   edx,16
4873
     add   ebp,edx
4884
     add   ebp,edx
4874
     movzx edx,word[edi-twdw+WDATA.box.top]
4885
     movzx edx,word[edi-twdw+WDATA.box.top]
4875
     add   eax,ebp
4886
     add   eax,ebp
4876
     mov   ebp,edx
4887
     mov   ebp,edx
4877
        add     ebp,[esi+APPDATA.wnd_clientbox.top]
4888
        add     ebp,[esi+APPDATA.wnd_clientbox.top]
4878
        add     dx,word[esi+APPDATA.wnd_clientbox.top]
4889
        add     dx,word[esi+APPDATA.wnd_clientbox.top]
4879
     shl   edx,16
4890
     shl   edx,16
4880
     xor   edi,edi
4891
     xor   edi,edi
4881
     add   edx,ebp
4892
     add   edx,ebp
4882
     add   ebx,edx
4893
     add   ebx,edx
4883
     jmp   [draw_line]
4894
     jmp   [draw_line]
4884
 
4895
 
4885
align 4
4896
align 4
4886
 
4897
 
4887
syscall_getirqowner:                    ; GetIrqOwner
4898
syscall_getirqowner:                    ; GetIrqOwner
4888
     cmp   eax,16
4899
     cmp   eax,16
4889
     jae   .err
4900
     jae   .err
4890
     shl   eax,2
4901
     shl   eax,2
4891
     add   eax,irq_owner
4902
     add   eax,irq_owner
4892
     mov   eax,[eax]
4903
     mov   eax,[eax]
4893
     mov   [esp+36],eax
4904
     mov   [esp+36],eax
4894
     ret
4905
     ret
4895
.err:
4906
.err:
4896
     or    dword [esp+36], -1
4907
     or    dword [esp+36], -1
4897
     ret
4908
     ret
4898
 
4909
 
4899
align 4
4910
align 4
4900
 
4911
 
4901
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4912
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4902
 
4913
 
4903
     call  r_f_port_area
4914
     call  r_f_port_area
4904
     mov   [esp+36],eax
4915
     mov   [esp+36],eax
4905
     ret
4916
     ret
4906
 
4917
 
4907
align 4
4918
align 4
4908
 
4919
 
4909
syscall_threads:                        ; CreateThreads
4920
syscall_threads:                        ; CreateThreads
4910
 
4921
 
4911
     call  sys_threads
4922
     call  sys_threads
4912
     mov   [esp+36],eax
4923
     mov   [esp+36],eax
4913
     ret
4924
     ret
4914
 
4925
 
4915
align 4
4926
align 4
4916
 
4927
 
4917
stack_driver_stat:
4928
stack_driver_stat:
4918
 
4929
 
4919
     call  app_stack_handler            ; Stack status
4930
     call  app_stack_handler            ; Stack status
4920
 
4931
 
4921
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4932
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4922
;     call  change_task                 ; between sent packet
4933
;     call  change_task                 ; between sent packet
4923
 
4934
 
4924
     mov   [esp+36],eax
4935
     mov   [esp+36],eax
4925
     ret
4936
     ret
4926
 
4937
 
4927
align 4
4938
align 4
4928
 
4939
 
4929
socket:                                 ; Socket interface
4940
socket:                                 ; Socket interface
4930
     call  app_socket_handler
4941
     call  app_socket_handler
4931
 
4942
 
4932
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4943
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4933
;     call  change_task                 ; between sent packet
4944
;     call  change_task                 ; between sent packet
4934
 
4945
 
4935
     mov   [esp+36],eax
4946
     mov   [esp+36],eax
4936
     mov   [esp+24],ebx
4947
     mov   [esp+24],ebx
4937
     ret
4948
     ret
4938
 
4949
 
4939
align 4
4950
align 4
4940
 
4951
 
4941
user_events:                            ; User event times
4952
user_events:                            ; User event times
4942
 
4953
 
4943
     mov   eax,0x12345678
4954
     mov   eax,0x12345678
4944
     mov   [esp+36],eax
4955
     mov   [esp+36],eax
4945
 
4956
 
4946
     ret
4957
     ret
4947
 
4958
 
4948
align 4
4959
align 4
4949
 
4960
 
4950
read_from_hd:                           ; Read from hd - fn not in use
4961
read_from_hd:                           ; Read from hd - fn not in use
4951
 
4962
 
4952
     mov   edi,[TASK_BASE]
4963
     mov   edi,[TASK_BASE]
4953
     add   edi,TASKDATA.mem_start
4964
     add   edi,TASKDATA.mem_start
4954
     add   eax,[edi]
4965
     add   eax,[edi]
4955
     add   ecx,[edi]
4966
     add   ecx,[edi]
4956
     add   edx,[edi]
4967
     add   edx,[edi]
4957
     call  file_read
4968
     call  file_read
4958
 
4969
 
4959
     mov   [esp+36],eax
4970
     mov   [esp+36],eax
4960
     mov   [esp+24],ebx
4971
     mov   [esp+24],ebx
4961
 
4972
 
4962
     ret
4973
     ret
4963
 
4974
 
4964
align 4
4975
align 4
4965
paleholder:
4976
paleholder:
4966
	ret
4977
	ret
4967
 
4978
 
4968
; --------------- APM ---------------------
4979
; --------------- APM ---------------------
4969
apm_entry    dp    0
4980
apm_entry    dp    0
4970
apm_vf        dd    0
4981
apm_vf        dd    0
4971
align 4
4982
align 4
4972
sys_apm:
4983
sys_apm:
4973
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
4984
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
4974
    jne    @f
4985
    jne    @f
4975
    or    [esp + 56], byte 1    ; error
4986
    or    [esp + 56], byte 1    ; error
4976
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
4987
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
4977
    ret
4988
    ret
4978
 
4989
 
4979
@@:
4990
@@:
4980
    xchg    eax, ecx
4991
    xchg    eax, ecx
4981
    xchg    ebx, ecx
4992
    xchg    ebx, ecx
4982
 
4993
 
4983
    cmp    al, 3
4994
    cmp    al, 3
4984
    ja    @f
4995
    ja    @f
4985
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
4996
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
4986
    mov    eax, [apm_vf]
4997
    mov    eax, [apm_vf]
4987
    mov    [esp + 36], eax
4998
    mov    [esp + 36], eax
4988
    shr    eax, 16
4999
    shr    eax, 16
4989
    mov    [esp + 32], eax
5000
    mov    [esp + 32], eax
4990
    ret
5001
    ret
4991
 
5002
 
4992
@@:
5003
@@:
4993
 
5004
 
4994
    mov esi, [master_tab+(OS_BASE shr 20)]
5005
    mov esi, [master_tab+(OS_BASE shr 20)]
4995
    xchg [master_tab], esi
5006
    xchg [master_tab], esi
4996
    push esi
5007
    push esi
4997
    mov edi, cr3
5008
    mov edi, cr3
4998
    mov cr3, edi                 ;flush TLB
5009
    mov cr3, edi                 ;flush TLB
4999
 
5010
 
5000
    call    pword [apm_entry]    ; call APM BIOS
5011
    call    pword [apm_entry]    ; call APM BIOS
5001
 
5012
 
5002
    xchg eax, [esp]
5013
    xchg eax, [esp]
5003
    mov [master_tab], eax
5014
    mov [master_tab], eax
5004
    mov eax, cr3
5015
    mov eax, cr3
5005
    mov cr3, eax
5016
    mov cr3, eax
5006
    pop eax
5017
    pop eax
5007
 
5018
 
5008
    mov    [esp + 8 ], edi
5019
    mov    [esp + 8 ], edi
5009
    mov    [esp + 12], esi
5020
    mov    [esp + 12], esi
5010
    mov    [esp + 24], ebx
5021
    mov    [esp + 24], ebx
5011
    mov    [esp + 28], edx
5022
    mov    [esp + 28], edx
5012
    mov    [esp + 32], ecx
5023
    mov    [esp + 32], ecx
5013
    mov    [esp + 36], eax
5024
    mov    [esp + 36], eax
5014
    setc    al
5025
    setc    al
5015
    and    [esp + 56], byte 0xfe
5026
    and    [esp + 56], byte 0xfe
5016
    or    [esp + 56], al
5027
    or    [esp + 56], al
5017
 
5028
 
5018
 
5029
 
5019
    ret
5030
    ret
5020
; -----------------------------------------
5031
; -----------------------------------------
5021
 
5032
 
5022
align 4
5033
align 4
5023
 
5034
 
5024
undefined_syscall:                      ; Undefined system call
5035
undefined_syscall:                      ; Undefined system call
5025
 
5036
 
5026
     mov   [esp+36],dword -1
5037
     mov   [esp+36],dword -1
5027
     ret
5038
     ret
5028
 
5039
 
5029
align 4
5040
align 4
5030
system_shutdown:          ; shut down the system
5041
system_shutdown:          ; shut down the system
5031
 
5042
 
5032
           cmp byte [BOOT_VAR+0x9030], 1
5043
           cmp byte [BOOT_VAR+0x9030], 1
5033
           jne @F
5044
           jne @F
5034
           ret
5045
           ret
5035
@@:
5046
@@:
5036
           call stop_all_services
5047
           call stop_all_services
5037
           push 3                ; stop playing cd
5048
           push 3                ; stop playing cd
5038
           pop  eax
5049
           pop  eax
5039
           call sys_cd_audio
5050
           call sys_cd_audio
5040
 
5051
 
5041
yes_shutdown_param:
5052
yes_shutdown_param:
5042
           cli
5053
           cli
5043
 
5054
 
5044
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
5055
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
5045
           push 12
5056
           push 12
5046
           pop  esi
5057
           pop  esi
5047
           xor  ebx,ebx
5058
           xor  ebx,ebx
5048
           or   ecx,-1
5059
           or   ecx,-1
5049
           mov  edx, OS_BASE+0x80000
5060
           mov  edx, OS_BASE+0x80000
5050
           call fileread
5061
           call fileread
5051
 
5062
 
5052
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5063
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5053
           mov  edi,OS_BASE+0x40000
5064
           mov  edi,OS_BASE+0x40000
5054
           mov  ecx,1000
5065
           mov  ecx,1000
5055
           rep  movsb
5066
           rep  movsb
5056
 
5067
 
5057
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5068
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5058
           mov  edi, OS_BASE
5069
           mov  edi, OS_BASE
5059
           mov  ecx,0x10000/4
5070
           mov  ecx,0x10000/4
5060
           cld
5071
           cld
5061
           rep movsd
5072
           rep movsd
5062
 
5073
 
5063
           call restorefatchain
5074
           call restorefatchain
5064
 
5075
 
5065
           mov al, 0xFF
5076
           mov al, 0xFF
5066
           out 0x21, al
5077
           out 0x21, al
5067
           out 0xA1, al
5078
           out 0xA1, al
5068
 
5079
 
5069
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5080
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5070
           mov  word [OS_BASE+0x467+2],0x1000
5081
           mov  word [OS_BASE+0x467+2],0x1000
5071
 
5082
 
5072
           mov  al,0x0F
5083
           mov  al,0x0F
5073
           out  0x70,al
5084
           out  0x70,al
5074
           mov  al,0x05
5085
           mov  al,0x05
5075
           out  0x71,al
5086
           out  0x71,al
5076
 
5087
 
5077
           mov  al,0xFE
5088
           mov  al,0xFE
5078
           out  0x64,al
5089
           out  0x64,al
5079
           hlt
5090
           hlt
5080
 
5091
 
5081
 
5092
 
5082
include "data32.inc"
5093
include "data32.inc"
5083
 
5094
 
5084
__REV__ = __REV
5095
__REV__ = __REV
5085
 
5096
 
5086
uglobals_size = $ - endofcode
5097
uglobals_size = $ - endofcode
5087
diff16 "end of kernel code",0,$
5098
diff16 "end of kernel code",0,$