Subversion Repositories Kolibri OS

Rev

Rev 1276 | Rev 1289 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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