Subversion Repositories Kolibri OS

Rev

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