Subversion Repositories Kolibri OS

Rev

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

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