Subversion Repositories Kolibri OS

Rev

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

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