Subversion Repositories Kolibri OS

Rev

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