Subversion Repositories Kolibri OS

Rev

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

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