Subversion Repositories Kolibri OS

Rev

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

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