Subversion Repositories Kolibri OS

Rev

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

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