Subversion Repositories Kolibri OS

Rev

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

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