Subversion Repositories Kolibri OS

Rev

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

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