Subversion Repositories Kolibri OS

Rev

Rev 1369 | 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: 1376 $
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
1376 clevermous 66
debug_com_base  equ 0x3f8  ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
1043 hidnplayr 67
 
164 serge 68
include "proc32.inc"
7 me_root 69
include "kglobals.inc"
1376 clevermous 70
lang fix en
1 ha 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
 
1324 Lrz 122
version db    'Kolibri OS  version 0.7.7.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
; -----------------------------------------
1310 diamond 468
        stdcall alloc_page
469
        stdcall map_page, tss-0xF80, eax, PG_SW
470
        stdcall alloc_page
471
        inc     eax
472
        mov     [SLOT_BASE+256+APPDATA.io_map], eax
473
        stdcall map_page, tss+0x80, eax, PG_SW
474
        stdcall alloc_page
475
        inc     eax
476
        mov     dword [SLOT_BASE+256+APPDATA.io_map+4], eax
477
        stdcall map_page, tss+0x1080, eax, PG_SW
375 Ghost 478
 
465 serge 479
; LOAD IDT
378 serge 480
 
1056 Galkov 481
           call build_interrupt_table ;lidt is executed
482
          ;lidt [idtreg]
378 serge 483
 
1055 Galkov 484
           call init_kernel_heap
485
           stdcall kernel_alloc, RING0_STACK_SIZE+512
486
           mov [os_stack_seg], eax
164 serge 487
 
1055 Galkov 488
           lea esp, [eax+RING0_STACK_SIZE]
164 serge 489
 
1055 Galkov 490
           mov [tss._ss0], os_stack
491
           mov [tss._esp0], esp
492
           mov [tss._esp], esp
493
           mov [tss._cs],os_code
494
           mov [tss._ss],os_stack
495
           mov [tss._ds],app_data
496
           mov [tss._es],app_data
497
           mov [tss._fs],app_data
498
           mov [tss._gs],app_data
499
           mov [tss._io],128
465 serge 500
;Add IO access table - bit array of permitted ports
1055 Galkov 501
           mov edi, tss._io_map_0
502
           xor eax, eax
503
           not eax
504
           mov ecx, 8192/4
505
           rep stosd                 ; access to 4096*8=65536 ports
164 serge 506
 
1055 Galkov 507
           mov  ax,tss0
508
           ltr  ax
378 serge 509
 
1055 Galkov 510
           mov [LFBSize], 0x800000
511
           call init_LFB
512
           call init_fpu
513
           call init_malloc
276 serge 514
 
1055 Galkov 515
           stdcall alloc_kernel_space, 0x51000
516
           mov [default_io_map], eax
465 serge 517
 
1055 Galkov 518
           add eax, 0x2000
519
           mov [ipc_tmp], eax
520
           mov ebx, 0x1000
164 serge 521
 
1055 Galkov 522
           add eax, 0x40000
523
           mov [proc_mem_map], eax
164 serge 524
 
1055 Galkov 525
           add eax, 0x8000
526
           mov [proc_mem_pdir], eax
164 serge 527
 
1055 Galkov 528
           add eax, ebx
529
           mov [proc_mem_tab], eax
164 serge 530
 
1055 Galkov 531
           add eax, ebx
532
           mov [tmp_task_pdir], eax
164 serge 533
 
1055 Galkov 534
           add eax, ebx
535
           mov [tmp_task_ptab], eax
164 serge 536
 
1055 Galkov 537
           add eax, ebx
538
           mov [ipc_pdir], eax
164 serge 539
 
1055 Galkov 540
           add eax, ebx
541
           mov [ipc_ptab], eax
164 serge 542
 
1055 Galkov 543
           stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
544
                                 (unpack.lc+unpack.lp)))*4
712 serge 545
 
1055 Galkov 546
           mov [unpack.p], eax
709 diamond 547
 
1055 Galkov 548
           call init_events
549
           mov eax, srv.fd-SRV_FD_OFFSET
550
           mov [srv.fd], eax
551
           mov [srv.bk], eax
278 serge 552
 
1055 Galkov 553
           mov edi, irq_tab
554
           xor eax, eax
555
           mov ecx, 16
556
           rep stosd
164 serge 557
 
41 mikedld 558
;Set base of graphic segment to linear address of LFB
1055 Galkov 559
        mov     eax,[LFBAddress]          ; set for gs
560
        mov     [graph_data_l+2],ax
561
        shr     eax,16
562
        mov     [graph_data_l+4],al
563
        mov     [graph_data_l+7],ah
1 ha 564
 
1300 serge 565
        stdcall kernel_alloc, [_WinMapSize]
566
        mov [_WinMapAddress], eax
567
 
1267 Lrz 568
        xor  eax,eax
569
        inc  eax
570
        mov [CURRENT_TASK],eax		;dword 1
571
        mov [TASK_COUNT],eax		;dword 1
1055 Galkov 572
        mov [TASK_BASE],dword TASK_DATA
573
        mov [current_slot], SLOT_BASE+256
429 serge 574
 
469 serge 575
; set background
1300 serge 576
 
1055 Galkov 577
        mov   [BgrDrawMode],eax
578
        mov   [BgrDataWidth],eax
579
        mov   [BgrDataHeight],eax
1107 diamond 580
        mov    [mem_BACKGROUND], 4
581
        mov [img_background], static_background_data
469 serge 582
 
1055 Galkov 583
        mov     [SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE
469 serge 584
 
709 diamond 585
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
586
 
1055 Galkov 587
        call  rerouteirqs
709 diamond 588
 
589
; Initialize system V86 machine
1055 Galkov 590
        call    init_sys_v86
709 diamond 591
 
725 diamond 592
; TIMER SET TO 1/100 S
593
 
1055 Galkov 594
        mov   al,0x34              ; set to 100Hz
595
        out   0x43,al
596
        mov   al,0x9b              ; lsb    1193180 / 1193
597
        out   0x40,al
598
        mov   al,0x2e              ; msb
599
        out   0x40,al
725 diamond 600
 
601
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
602
; they are used: when partitions are scanned, hd_read relies on timer
1025 diamond 603
; Also enable IRQ2, because in some configurations
604
; IRQs from slave controller are not delivered until IRQ2 on master is enabled
1055 Galkov 605
        mov     al, 0xFA
606
        out     0x21, al
607
        mov     al, 0x3F
608
        out     0xA1, al
725 diamond 609
 
256 diamond 610
;!!!!!!!!!!!!!!!!!!!!!!!!!!
611
include 'detect/disks.inc'
612
;!!!!!!!!!!!!!!!!!!!!!!!!!!
613
 
521 diamond 614
  call Parser_params
615
 
1 ha 616
; READ RAMDISK IMAGE FROM HD
617
 
618
;!!!!!!!!!!!!!!!!!!!!!!!
619
include 'boot/rdload.inc'
620
;!!!!!!!!!!!!!!!!!!!!!!!
621
;    mov    [dma_hdd],1
622
; CALCULATE FAT CHAIN FOR RAMDISK
623
 
1055 Galkov 624
        call  calculatefatchain
1 ha 625
 
626
; LOAD VMODE DRIVER
627
 
628
;!!!!!!!!!!!!!!!!!!!!!!!
629
include 'vmodeld.inc'
630
;!!!!!!!!!!!!!!!!!!!!!!!
631
 
1289 diamond 632
if 0
509 diamond 633
  mov ax,[OS_BASE+0x10000+bx_from_load]
1055 Galkov 634
  cmp ax,'r1'           ; if using not ram disk, then load librares and parameters {SPraid.simba}
488 spraid 635
  je  no_lib_load
636
; LOADING LIBRARES
1055 Galkov 637
   stdcall dll.Load,@IMPORT                 ; loading librares for kernel (.obj files)
638
   call load_file_parse_table               ; prepare file parse table
639
   call set_kernel_conf                     ; configure devices and gui
488 spraid 640
no_lib_load:
1289 diamond 641
end if
488 spraid 642
 
1 ha 643
; LOAD FONTS I and II
644
 
1055 Galkov 645
        stdcall read_file, char, FONT_I, 0, 2304
646
        stdcall read_file, char2, FONT_II, 0, 2560
490 serge 647
 
1055 Galkov 648
        mov   esi,boot_fonts
649
        call  boot_log
1 ha 650
 
651
; PRINT AMOUNT OF MEMORY
1055 Galkov 652
        mov     esi, boot_memdetect
653
        call    boot_log
1 ha 654
 
1055 Galkov 655
        movzx   ecx, word [boot_y]
656
        or      ecx, (10+29*6) shl 16 ; "Determining amount of memory"
657
        sub     ecx, 10
658
        mov     edx, 0xFFFFFF
659
        mov     ebx, [MEM_AMOUNT]
660
        shr     ebx, 20
1276 Lrz 661
        xor     edi,edi
1055 Galkov 662
        mov     eax, 0x00040000
1276 Lrz 663
		inc		edi
1055 Galkov 664
        call    display_number_force
41 mikedld 665
 
465 serge 666
; BUILD SCHEDULER
667
 
1055 Galkov 668
        call   build_scheduler ; sys32.inc
465 serge 669
 
1055 Galkov 670
        mov    esi,boot_devices
671
        call   boot_log
567 serge 672
 
1055 Galkov 673
        mov  [pci_access_enabled],1
567 serge 674
 
1 ha 675
 
676
; SET PRELIMINARY WINDOW STACK AND POSITIONS
677
 
1055 Galkov 678
        mov   esi,boot_windefs
679
        call  boot_log
1362 mikedld 680
        call  set_window_defaults
1 ha 681
 
682
; SET BACKGROUND DEFAULTS
683
 
1055 Galkov 684
        mov   esi,boot_bgr
685
        call  boot_log
686
        call  init_background
687
        call  calculatebackground
1 ha 688
 
689
; RESERVE SYSTEM IRQ'S JA PORT'S
690
 
1055 Galkov 691
        mov   esi,boot_resirqports
692
        call  boot_log
693
        call  reserve_irqs_ports
1 ha 694
 
695
; SET PORTS FOR IRQ HANDLERS
696
 
1055 Galkov 697
        mov  esi,boot_setrports
698
        call boot_log
699
        ;call setirqreadports
1 ha 700
 
701
; SET UP OS TASK
702
 
1055 Galkov 703
        mov  esi,boot_setostask
704
        call boot_log
214 serge 705
 
1055 Galkov 706
        xor  eax, eax
707
        mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
1074 Galkov 708
        mov  dword [SLOT_BASE+APPDATA.exc_handler], eax
709
        mov  dword [SLOT_BASE+APPDATA.except_mask], eax
164 serge 710
 
1055 Galkov 711
        ; name for OS/IDLE process
281 serge 712
 
1055 Galkov 713
        mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
714
        mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
715
        mov edi, [os_stack_seg]
716
        mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
717
        add edi, 0x2000-512
718
        mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
719
        mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
1310 diamond 720
	; [SLOT_BASE+256+APPDATA.io_map] was set earlier
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
 
1316 serge 747
        call init_display
1055 Galkov 748
        mov eax, [def_cursor]
749
        mov [SLOT_BASE+APPDATA.cursor],eax
750
        mov [SLOT_BASE+APPDATA.cursor+256],eax
281 serge 751
 
465 serge 752
  ; READ TSC / SECOND
281 serge 753
 
1055 Galkov 754
        mov   esi,boot_tsc
755
        call  boot_log
756
        cli
757
        rdtsc ;call  _rdtsc
758
        mov   ecx,eax
759
        mov   esi,250               ; wait 1/4 a second
760
        call  delay_ms
761
        rdtsc ;call  _rdtsc
762
        sti
763
        sub   eax,ecx
764
        shl   eax,2
765
        mov   [CPU_FREQ],eax          ; save tsc / sec
1043 hidnplayr 766
;       mov ebx, 1000000
767
;       div ebx
1038 diamond 768
; ¢®®¡é¥-â® ¯à®¨§¢®¤¨â¥«ì­®áâì ¢ ¤ ­­®¬ ª®­ªà¥â­®¬ ¬¥áâ¥
769
; ᮢ¥à襭­® ­¥ªà¨â¨ç­ , ­® çâ®¡ë § âª­ãâì «î¡¨â¥«¥©
770
; ®¯â¨¬¨§¨àãîé¨å ª®¬¯¨«ïâ®à®¢ Ÿ‚“...
1055 Galkov 771
        mov     edx, 2251799814
772
        mul     edx
773
        shr     edx, 19
774
        mov [stall_mcs], edx
1038 diamond 775
; PRINT CPU FREQUENCY
1055 Galkov 776
        mov     esi, boot_cpufreq
777
        call    boot_log
1 ha 778
 
1055 Galkov 779
        mov     ebx, edx
780
        movzx   ecx, word [boot_y]
781
        add     ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is '
782
        mov     edx, 0xFFFFFF
1276 Lrz 783
        xor     edi,edi
1055 Galkov 784
        mov     eax, 0x00040000
1276 Lrz 785
		inc		edi
1055 Galkov 786
        call    display_number_force
1038 diamond 787
 
1 ha 788
; SET VARIABLES
789
 
1055 Galkov 790
        call  set_variables
1 ha 791
 
774 Rus 792
; SET MOUSE
793
 
1055 Galkov 794
        ;call   detect_devices
795
        stdcall load_driver, szPS2MDriver
1106 diamond 796
;        stdcall load_driver, szCOM_MDriver
774 Rus 797
 
1055 Galkov 798
        mov   esi,boot_setmouse
799
        call  boot_log
800
        call  setmouse
774 Rus 801
 
802
 
1 ha 803
; STACK AND FDC
804
 
1055 Galkov 805
        call  stack_init
806
        call  fdc_init
1 ha 807
 
808
; PALETTE FOR 320x200 and 640x480 16 col
809
 
1055 Galkov 810
        cmp   [SCR_MODE],word 0x12
811
        jne   no_pal_vga
812
        mov   esi,boot_pal_vga
813
        call  boot_log
814
        call  paletteVGA
1 ha 815
      no_pal_vga:
816
 
1055 Galkov 817
        cmp   [SCR_MODE],word 0x13
818
        jne   no_pal_ega
819
        mov   esi,boot_pal_ega
820
        call  boot_log
821
        call  palette320x200
1 ha 822
      no_pal_ega:
823
 
824
; LOAD DEFAULT SKIN
825
 
1055 Galkov 826
        call    load_default_skin
1 ha 827
 
465 serge 828
;protect io permission map
829
 
1055 Galkov 830
           mov esi, [default_io_map]
1310 diamond 831
           stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map], PG_MAP
1055 Galkov 832
           add esi, 0x1000
1310 diamond 833
           stdcall map_page,esi,[SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
465 serge 834
 
1055 Galkov 835
           stdcall map_page,tss._io_map_0,\
1310 diamond 836
                   [SLOT_BASE+256+APPDATA.io_map], PG_MAP
1055 Galkov 837
           stdcall map_page,tss._io_map_1,\
1310 diamond 838
                   [SLOT_BASE+256+APPDATA.io_map+4], PG_MAP
465 serge 839
 
1 ha 840
; LOAD FIRST APPLICATION
1055 Galkov 841
        cli
501 serge 842
 
1055 Galkov 843
        cmp   byte [BOOT_VAR+0x9030],1
844
        jne   no_load_vrr_m
237 serge 845
 
1055 Galkov 846
        mov     ebp, vrr_m
847
        call    fs_execute_from_sysdir
488 spraid 848
 
1260 Lrz 849
;        cmp   eax,2                  ; if vrr_m app found (PID=2)
850
	sub   eax,2
851
        jz    first_app_found
41 mikedld 852
 
237 serge 853
no_load_vrr_m:
488 spraid 854
 
1055 Galkov 855
        mov     ebp, firstapp
856
        call    fs_execute_from_sysdir
488 spraid 857
 
1260 Lrz 858
;        cmp   eax,2                  ; continue if a process has been loaded
859
	sub   eax,2
860
        jz    first_app_found
501 serge 861
 
1055 Galkov 862
        mov     esi, boot_failed
863
        call    boot_log
653 diamond 864
 
1055 Galkov 865
        mov   eax, 0xDEADBEEF        ; otherwise halt
866
        hlt
501 serge 867
 
237 serge 868
first_app_found:
501 serge 869
 
1055 Galkov 870
        cli
1 ha 871
 
1055 Galkov 872
        ;mov   [TASK_COUNT],dword 2
1276 Lrz 873
	push  1
874
        pop   dword [CURRENT_TASK]      ; set OS task fisrt
1 ha 875
 
21 poddubny 876
; SET KEYBOARD PARAMETERS
1055 Galkov 877
        mov   al, 0xf6         ; reset keyboard, scan enabled
878
        call  kb_write
1 ha 879
 
1055 Galkov 880
        ; wait until 8042 is ready
881
        xor ecx,ecx
265 diamond 882
      @@:
1055 Galkov 883
        in     al,64h
884
        and    al,00000010b
885
        loopnz @b
1 ha 886
 
887
       ; mov   al, 0xED       ; svetodiody - only for testing!
888
       ; call  kb_write
889
       ; call  kb_read
890
       ; mov   al, 111b
891
       ; call  kb_write
892
       ; call  kb_read
41 mikedld 893
 
1055 Galkov 894
        mov   al, 0xF3       ; set repeat rate & delay
895
        call  kb_write
265 diamond 896
;        call  kb_read
1055 Galkov 897
        mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
898
        call  kb_write
265 diamond 899
;        call  kb_read
1 ha 900
     ;// mike.dld [
1055 Galkov 901
        call  set_lights
1 ha 902
     ;// mike.dld ]
903
 
1043 hidnplayr 904
 
905
; Setup serial output console (if enabled)
906
 
907
if defined debug_com_base
908
 
1055 Galkov 909
        ; enable Divisor latch
1043 hidnplayr 910
 
1055 Galkov 911
        mov     dx, debug_com_base+3
912
        mov     al, 1 shl 7
913
        out     dx, al
1043 hidnplayr 914
 
1055 Galkov 915
        ; Set speed to 115200 baud (max speed)
1043 hidnplayr 916
 
1055 Galkov 917
        mov     dx, debug_com_base
918
        mov     al, 0x01
919
        out     dx, al
1043 hidnplayr 920
 
1055 Galkov 921
        mov     dx, debug_com_base+1
922
        mov     al, 0x00
923
        out     dx, al
1043 hidnplayr 924
 
1055 Galkov 925
        ; No parity, 8bits words, one stop bit, dlab bit back to 0
1043 hidnplayr 926
 
1055 Galkov 927
        mov     dx, debug_com_base+3
928
        mov     al, 3
929
        out     dx, al
1043 hidnplayr 930
 
1055 Galkov 931
        ; disable interrupts
1043 hidnplayr 932
 
1055 Galkov 933
        mov     dx, debug_com_base+1
934
        mov     al, 0
935
        out     dx, al
1043 hidnplayr 936
 
1055 Galkov 937
        ; clear +  enable fifo (64 bits)
1043 hidnplayr 938
 
1055 Galkov 939
        mov     dx, debug_com_base+2
940
        mov     al, 0x7 + 1 shl 5
941
        out     dx, al
1043 hidnplayr 942
 
943
 
944
end if
945
 
21 poddubny 946
; START MULTITASKING
1 ha 947
 
767 diamond 948
if preboot_blogesc
1055 Galkov 949
        mov     esi, boot_tasking
950
        call    boot_log
951
.bll1:  in      al, 0x60        ; wait for ESC key press
952
        cmp     al, 129
953
        jne     .bll1
767 diamond 954
end if
955
 
465 serge 956
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
21 poddubny 957
 
1 ha 958
; UNMASK ALL IRQ'S
959
 
1055 Galkov 960
        mov   esi,boot_allirqs
961
        call  boot_log
41 mikedld 962
 
1055 Galkov 963
        cli                          ;guarantee forbidance of interrupts.
964
        mov   al,0                   ; unmask all irq's
965
        out   0xA1,al
966
        out   0x21,al
1 ha 967
 
1055 Galkov 968
        mov   ecx,32
1 ha 969
 
970
     ready_for_irqs:
971
 
1055 Galkov 972
        mov   al,0x20                ; ready for irqs
973
        out   0x20,al
974
        out   0xa0,al
1 ha 975
 
1055 Galkov 976
        loop  ready_for_irqs         ; flush the queue
1 ha 977
 
1055 Galkov 978
        stdcall attach_int_handler, dword 1, irq1, dword 0
164 serge 979
 
1 ha 980
;        mov    [dma_hdd],1
1055 Galkov 981
        cmp     [IDEContrRegsBaseAddr], 0
982
        setnz   [dma_hdd]
983
        mov [timer_ticks_enable],1              ; for cd driver
1 ha 984
 
1055 Galkov 985
        sti
986
        call change_task
465 serge 987
 
1055 Galkov 988
        jmp osloop
465 serge 989
 
725 diamond 990
;        jmp   $                      ; wait here for timer to take control
1 ha 991
 
1055 Galkov 992
        ; Fly :)
1 ha 993
 
465 serge 994
include 'unpacker.inc'
995
include 'fdo.inc'
996
 
997
align 4
998
boot_log:
1055 Galkov 999
         pushad
465 serge 1000
 
1276 Lrz 1001
        mov   ebx,10*65536
1002
        mov   bx,word [boot_y]
1003
        add   [boot_y],dword 10
1004
        mov   ecx,0x80ffffff   ; ASCIIZ string with white color
1005
		xor	  edi,edi
1006
        mov   edx,esi
1007
		inc	  edi
1008
        call  dtext
465 serge 1009
 
1276 Lrz 1010
        mov   [novesachecksum],1000
1011
        call  checkVga_N13
465 serge 1012
 
1276 Lrz 1013
        popad
465 serge 1014
 
1276 Lrz 1015
        ret
465 serge 1016
 
1 ha 1017
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1018
;                                                                    ;
33 mario79 1019
;                    MAIN OS LOOP START                              ;
1 ha 1020
;                                                                    ;
1021
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1022
align 32
1023
osloop:
1055 Galkov 1024
        call   [draw_pointer]
1334 mikedld 1025
        call   check_buttons
1055 Galkov 1026
        call   checkwindows
49 mikedld 1027
;       call   check_window_move_request
1055 Galkov 1028
        call   checkmisc
1029
        call   checkVga_N13
1030
        call   stack_handler
1031
        call   checkidle
1032
        call   check_fdd_motor_status
1033
        call   check_ATAPI_device_event
1034
        jmp    osloop
33 mario79 1035
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1036
;                                                                    ;
1037
;                      MAIN OS LOOP END                              ;
1038
;                                                                    ;
1039
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1168 Lrz 1040
align 4
1 ha 1041
checkidle:
1055 Galkov 1042
        pushad
1067 Galkov 1043
        call    change_task
1044
        jmp     idle_loop_entry
1045
  idle_loop:
1046
        cmp     eax,[idlemem]     ; eax == [timer_ticks]
1047
        jne     idle_exit
1048
        rdtsc   ;call _rdtsc
1049
        mov     ecx,eax
1055 Galkov 1050
        hlt
1067 Galkov 1051
        rdtsc   ;call _rdtsc
1052
        sub     eax,ecx
1053
        add     [idleuse],eax
1054
  idle_loop_entry:
1055
        mov     eax,[timer_ticks] ; eax =  [timer_ticks]
1056
        cmp     [check_idle_semaphore],0
1057
        je      idle_loop
1058
        dec     [check_idle_semaphore]
1059
  idle_exit:
1060
        mov     [idlemem],eax     ; eax == [timer_ticks]
1055 Galkov 1061
        popad
1062
        ret
1 ha 1063
 
1064
uglobal
1067 Galkov 1065
  idlemem               dd   0x0
1055 Galkov 1066
  idleuse               dd   0x0
1067
  idleusesec            dd   0x0
1068
  check_idle_semaphore  dd   0x0
1 ha 1069
endg
1070
 
1071
 
1072
 
1073
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1074
;                                                                      ;
1075
;                   INCLUDED SYSTEM FILES                              ;
1076
;                                                                      ;
1077
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1078
 
1079
 
7 me_root 1080
include "kernel32.inc"
1 ha 1081
 
1082
 
1083
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1084
;                                                                      ;
1085
;                       KERNEL FUNCTIONS                               ;
1086
;                                                                      ;
1087
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1088
 
1089
reserve_irqs_ports:
1090
 
1267 Lrz 1091
        push eax
1092
        xor	eax,eax
1276 Lrz 1093
		inc	eax
1267 Lrz 1094
        mov  byte [irq_owner+4*0],al		;1    ; timer
1055 Galkov 1095
        ;mov  [irq_owner+4*1], 1    ; keyboard
1267 Lrz 1096
        mov  byte [irq_owner+4*6],al		;1    ; floppy diskette
1097
        mov  byte [irq_owner+4*13],al	;1   ; math co-pros
1098
        mov  byte [irq_owner+4*14],al	;1   ; ide I
1099
        mov  byte [irq_owner+4*15],al	;1   ; ide II
1100
        pop  eax
1273 Lrz 1101
 
1102
; RESERVE PORTS
1103
	push  4
1267 Lrz 1104
        pop   dword [RESERVED_PORTS]	;,edi
1273 Lrz 1105
 
1106
	push  1
1267 Lrz 1107
        pop   dword [RESERVED_PORTS+16+0]	;,dword 1
1273 Lrz 1108
        and   dword [RESERVED_PORTS+16+4],0	;,dword 0x0
1109
        mov   dword [RESERVED_PORTS+16+8],0x2d	;,dword 0x2d
269 serge 1110
 
1273 Lrz 1111
	push  1
1267 Lrz 1112
        pop   dword [RESERVED_PORTS+32+0]	;,dword 1
1273 Lrz 1113
        push  0x30
1267 Lrz 1114
        pop   dword [RESERVED_PORTS+32+4]	;,dword 0x30
1273 Lrz 1115
	push  0x4d
1267 Lrz 1116
        pop   dword [RESERVED_PORTS+32+8]	;,dword 0x4d
269 serge 1117
 
1273 Lrz 1118
	push  1
1267 Lrz 1119
        pop   dword [RESERVED_PORTS+48+0]	;,dword 1
1273 Lrz 1120
	push  0x50
1267 Lrz 1121
        pop   dword [RESERVED_PORTS+48+4]	;,dword 0x50
1273 Lrz 1122
        mov   dword [RESERVED_PORTS+48+8],0xdf	;,dword 0xdf
233 serge 1123
 
1273 Lrz 1124
	push  1
1267 Lrz 1125
        pop   dword [RESERVED_PORTS+64+0]	;,dword 1
233 serge 1126
 
1273 Lrz 1127
        mov   dword [RESERVED_PORTS+64+4],0xe5	;,dword 0xe5
1128
        mov   dword [RESERVED_PORTS+64+8],0xff	;,dword 0xff
1129
 
1055 Galkov 1130
        ret
1 ha 1131
 
1132
setirqreadports:
1133
 
1055 Galkov 1134
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1276 Lrz 1135
	    and   dword [irq12read+4],0                   ; end of port list
1273 Lrz 1136
;        mov   [irq12read+4],dword 0                  ; end of port list
1055 Galkov 1137
        ;mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1138
        ;mov   [irq04read+4],dword 0                  ; end of port list
1139
        ;mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1140
        ;mov   [irq03read+4],dword 0                  ; end of port list
1 ha 1141
 
1055 Galkov 1142
        ret
1 ha 1143
 
1144
iglobal
1145
  process_number dd 0x1
1146
endg
1147
 
1148
set_variables:
1149
 
1055 Galkov 1150
        mov   ecx,0x100                       ; flush port 0x60
1151
.fl60:  in    al,0x60
1152
        loop  .fl60
1267 Lrz 1153
        push  eax
1 ha 1154
 
1055 Galkov 1155
        mov   ax,[BOOT_VAR+0x900c]
1156
        shr   ax,1
1157
        shl   eax,16
1158
        mov   ax,[BOOT_VAR+0x900A]
1159
        shr   ax,1
1160
        mov   [MOUSE_X],eax
41 mikedld 1161
 
1267 Lrz 1162
        xor   eax,eax
1055 Galkov 1163
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1 ha 1164
 
1267 Lrz 1165
        mov   byte [MOUSE_BUFF_COUNT],al                 ; mouse buffer
1166
        mov   byte [KEY_COUNT],al                 ; keyboard buffer
1167
        mov   byte [BTN_COUNT],al                 ; button buffer
1168
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1169
 
1 ha 1170
     ;!! IP 04.02.2005:
1267 Lrz 1171
        mov   byte [DONT_SWITCH],al ; change task if possible
1172
        pop   eax
1055 Galkov 1173
        ret
1 ha 1174
 
1175
align 4
1304 Lrz 1176
;input  eax=43,bl-byte of output, ecx - number of port
1 ha 1177
sys_outport:
1178
 
1304 Lrz 1179
    mov   edi,ecx          ; separate flag for read / write
1180
    and   ecx,65535
1 ha 1181
 
1304 Lrz 1182
    mov   eax,[RESERVED_PORTS]
1183
    test  eax,eax
1184
    jnz   .sopl8
1185
    inc	  eax
1186
	mov   [esp+32],eax
1 ha 1187
    ret
1188
 
1304 Lrz 1189
  .sopl8:
379 serge 1190
    mov   edx,[TASK_BASE]
1 ha 1191
    mov   edx,[edx+0x4]
1304 Lrz 1192
    ;and   ecx,65535
1193
    ;cld - set on interrupt 0x40
1194
  .sopl1:
1 ha 1195
 
1304 Lrz 1196
    mov   esi,eax
1 ha 1197
    shl   esi,4
381 serge 1198
    add   esi,RESERVED_PORTS
1 ha 1199
    cmp   edx,[esi+0]
1304 Lrz 1200
    jne   .sopl2
1201
    cmp   ecx,[esi+4]
1202
    jb    .sopl2
1203
    cmp   ecx,[esi+8]
1204
    jg    .sopl2
1205
.sopl3:
1 ha 1206
 
1304 Lrz 1207
    test  edi,0x80000000 ; read ?
1208
    jnz   .sopl4
1 ha 1209
 
1304 Lrz 1210
	mov	  eax,ebx
1211
    mov   dx,cx          ; write
1212
    out   dx,al
1213
    and   [esp+32],dword 0
1 ha 1214
    ret
1215
 
1304 Lrz 1216
	.sopl2:
1 ha 1217
 
1304 Lrz 1218
    dec   eax
1219
    jnz   .sopl1
1220
	inc	  eax
1221
    mov   [esp+32],eax
1 ha 1222
    ret
1223
 
1304 Lrz 1224
 
1225
  .sopl4:
1 ha 1226
 
1304 Lrz 1227
    mov   dx,cx          ; read
1055 Galkov 1228
    in    al,dx
1 ha 1229
    and   eax,0xff
1304 Lrz 1230
    and   [esp+32],dword 0
1231
    mov   [esp+20],eax
1 ha 1232
    ret
1233
 
1234
display_number:
1369 Lrz 1235
;It is not optimization
1236
        mov     eax, ebx
1237
        mov     ebx, ecx
1238
        mov     ecx, edx
1239
        mov     edx, esi
1240
        mov     esi, edi
1 ha 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
1329 Lrz 2027
     and  [application_table_status],0
1 ha 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
1329 Lrz 2050
    and    [application_table_status],0
85 halyavin 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:
1319 diamond 2292
  db 0,7,7,0  ; version 0.7.7.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
1312 diamond 2523
        dec     ecx
546 diamond 2524
@@:
1055 Galkov 2525
        and     dword [page_tabs+eax*4], 0
2526
        mov     edx, eax
2527
        shl     edx, 12
2528
        push eax
2529
        invlpg  [edx]
2530
        pop eax
2531
        inc     eax
2532
        loop    @b
2533
        pop     eax
2534
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2535
        stdcall user_free, ebx
2536
        mov     [esp+32], eax
2537
        and     [bgrlockpid], 0
2538
        mov     [bgrlock], 0
2539
        ret
546 diamond 2540
.err:
1055 Galkov 2541
        and     dword [esp+32], 0
2542
        ret
546 diamond 2543
 
2544
nosb7:
1 ha 2545
    ret
2546
 
709 diamond 2547
force_redraw_background:
1276 Lrz 2548
    and   [draw_data+32 + RECT.left],dword 0
2549
    and   [draw_data+32 + RECT.top],dword 0
709 diamond 2550
    push  eax ebx
753 serge 2551
    mov   eax,[Screen_Max_X]
2552
    mov   ebx,[Screen_Max_Y]
709 diamond 2553
    mov   [draw_data+32 + RECT.right],eax
2554
    mov   [draw_data+32 + RECT.bottom],ebx
2555
    pop   ebx eax
2556
    mov   byte [REDRAW_BACKGROUND], 1
2557
    ret
479 kastigar 2558
 
1 ha 2559
align 4
2560
 
2561
sys_getbackground:
1304 Lrz 2562
;    cmp   eax,1                                  ; SIZE
2563
    dec	  ebx
1 ha 2564
    jnz   nogb1
527 diamond 2565
    mov   eax,[BgrDataWidth]
1 ha 2566
    shl   eax,16
531 diamond 2567
    mov   ax,[BgrDataHeight]
1304 Lrz 2568
    mov   [esp+32],eax
1 ha 2569
    ret
2570
 
875 serge 2571
nogb1:
1304 Lrz 2572
;    cmp   eax,2                                  ; PIXEL
2573
    dec	  ebx
1 ha 2574
    jnz   nogb2
875 serge 2575
 
1107 diamond 2576
        mov     eax, [img_background]
1304 Lrz 2577
        test    ecx, ecx
1107 diamond 2578
        jz      @f
2579
        cmp     eax, static_background_data
2580
        jz      .ret
2581
@@:
1304 Lrz 2582
    mov ebx, [mem_BACKGROUND]
2583
    add ebx, 4095
2584
    and ebx, -4096
2585
    sub ebx, 4
2586
    cmp ecx, ebx
1107 diamond 2587
    ja  .ret
875 serge 2588
 
1304 Lrz 2589
    mov   eax,[ecx+eax]
469 serge 2590
 
1 ha 2591
    and   eax, 0xFFFFFF
1304 Lrz 2592
    mov   [esp+32],eax
1107 diamond 2593
.ret:
1 ha 2594
    ret
2595
  nogb2:
2596
 
1304 Lrz 2597
;    cmp   eax,4                                  ; TILED / STRETCHED
2598
    dec   ebx
1314 diamond 2599
    dec   ebx
1 ha 2600
    jnz   nogb4
527 diamond 2601
    mov   eax,[BgrDrawMode]
1 ha 2602
  nogb4:
1304 Lrz 2603
    mov   [esp+32],eax
1 ha 2604
    ret
2605
 
2606
align 4
2607
 
2608
sys_getkey:
1055 Galkov 2609
        mov     [esp + 32],dword 1
2610
        ; test main buffer
2611
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2612
        movzx   ecx, word [WIN_STACK + ebx * 2]
2613
        mov     edx, [TASK_COUNT]
2614
        cmp     ecx, edx
2615
        jne     .finish
2616
        cmp     [KEY_COUNT], byte 0
2617
        je      .finish
2618
        movzx   eax, byte [KEY_BUFF]
2619
        shl     eax, 8
2620
        push    eax
2621
        dec     byte [KEY_COUNT]
2622
        and     byte [KEY_COUNT], 127
2623
        movzx   ecx, byte [KEY_COUNT]
2624
        add     ecx, 2
2625
        mov     eax, KEY_BUFF + 1
2626
        mov     ebx, KEY_BUFF
2627
        call    memmove
2628
        pop     eax
92 diamond 2629
.ret_eax:
1055 Galkov 2630
        mov     [esp + 32], eax
2631
        ret
671 Ghost 2632
.finish:
92 diamond 2633
; test hotkeys buffer
1055 Galkov 2634
        mov     ecx, hotkey_buffer
92 diamond 2635
@@:
1055 Galkov 2636
        cmp     [ecx], ebx
2637
        jz      .found
2638
        add     ecx, 8
2639
        cmp     ecx, hotkey_buffer + 120 * 8
2640
        jb      @b
2641
        ret
92 diamond 2642
.found:
1055 Galkov 2643
        mov     ax, [ecx + 6]
2644
        shl     eax, 16
2645
        mov     ah, [ecx + 4]
2646
        mov     al, 2
2647
        and     dword [ecx + 4], 0
2648
        and     dword [ecx], 0
2649
        jmp     .ret_eax
1 ha 2650
 
2651
align 4
2652
 
2653
sys_getbutton:
2654
 
1055 Galkov 2655
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2656
        mov     [esp + 32], dword 1
2657
        movzx   ecx, word [WIN_STACK + ebx * 2]
2658
        mov     edx, [TASK_COUNT] ; less than 256 processes
2659
        cmp     ecx, edx
2660
        jne     .exit
2661
        movzx   eax, byte [BTN_COUNT]
2662
        test    eax, eax
2663
        jz      .exit
2664
        mov     eax, [BTN_BUFF]
2665
        shl     eax, 8
803 alver 2666
; // Alver 22.06.2008 // {
1055 Galkov 2667
        mov       al, byte [btn_down_determ]
2668
        and       al,0xFE                                       ; delete left button bit
803 alver 2669
; } \\ Alver \\
1055 Galkov 2670
        mov     [BTN_COUNT], byte 0
2671
        mov     [esp + 32], eax
671 Ghost 2672
.exit:
1055 Galkov 2673
        ret
1 ha 2674
 
2675
 
2676
align 4
2677
 
2678
sys_cpuusage:
2679
 
2680
;  RETURN:
2681
;
2682
;  +00 dword     process cpu usage
2683
;  +04  word     position in windowing stack
2684
;  +06  word     windowing stack value at current position (cpu nro)
2685
;  +10 12 bytes  name
2686
;  +22 dword     start in mem
2687
;  +26 dword     used mem
2688
;  +30 dword     PID , process idenfification number
2689
;
2690
 
1055 Galkov 2691
    cmp  ecx,-1         ; who am I ?
684 diamond 2692
    jne  .no_who_am_i
2693
    mov  ecx,[CURRENT_TASK]
2694
  .no_who_am_i:
1055 Galkov 2695
        cmp     ecx, max_processes
2696
        ja      .nofillbuf
1 ha 2697
 
684 diamond 2698
; +4: word: position of the window of thread in the window stack
1055 Galkov 2699
        mov     ax, [WIN_STACK + ecx * 2]
2700
        mov     [ebx+4], ax
684 diamond 2701
; +6: word: number of the thread slot, which window has in the window stack
2702
;           position ecx (has no relation to the specific thread)
1055 Galkov 2703
        mov     ax, [WIN_POS + ecx * 2]
2704
        mov     [ebx+6], ax
1 ha 2705
 
1055 Galkov 2706
        shl     ecx, 5
1 ha 2707
 
684 diamond 2708
; +0: dword: memory usage
1055 Galkov 2709
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2710
        mov     [ebx], eax
684 diamond 2711
; +10: 11 bytes: name of the process
1055 Galkov 2712
        push    ecx
2713
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2714
        add     ebx, 10
2715
        mov     ecx, 11
2716
        call    memmove
2717
        pop     ecx
1 ha 2718
 
684 diamond 2719
; +22: address of the process in memory
2720
; +26: size of used memory - 1
1055 Galkov 2721
        push    edi
2722
        lea     edi, [ebx+12]
2723
        xor     eax, eax
2724
        mov     edx, 0x100000*16
2725
        cmp     ecx, 1 shl 5
2726
        je      .os_mem
2727
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2728
        mov     eax, std_application_base_address
684 diamond 2729
.os_mem:
1055 Galkov 2730
        stosd
2731
        lea     eax, [edx-1]
2732
        stosd
1 ha 2733
 
684 diamond 2734
; +30: PID/TID
1055 Galkov 2735
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2736
        stosd
1 ha 2737
 
2738
    ; window position and size
1055 Galkov 2739
        push    esi
2740
        lea     esi, [ecx + window_data + WDATA.box]
2741
        movsd
2742
        movsd
2743
        movsd
2744
        movsd
1 ha 2745
 
2746
    ; Process state (+50)
1055 Galkov 2747
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2748
        stosd
1 ha 2749
 
138 mikedld 2750
    ; Window client area box
1055 Galkov 2751
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2752
        movsd
2753
        movsd
2754
        movsd
2755
        movsd
1 ha 2756
 
164 serge 2757
    ; Window state
1055 Galkov 2758
        mov     al, [ecx+window_data+WDATA.fl_wstate]
2759
        stosb
164 serge 2760
 
1055 Galkov 2761
        pop     esi
2762
        pop     edi
138 mikedld 2763
 
684 diamond 2764
.nofillbuf:
1 ha 2765
    ; return number of processes
2766
 
379 serge 2767
    mov    eax,[TASK_COUNT]
684 diamond 2768
    mov    [esp+32],eax
1 ha 2769
    ret
2770
 
2771
align 4
2772
sys_clock:
1055 Galkov 2773
        cli
1 ha 2774
  ; Mikhail Lisovin  xx Jan 2005
1055 Galkov 2775
  @@:   mov   al, 10
2776
        out   0x70, al
2777
        in    al, 0x71
2778
        test  al, al
2779
        jns   @f
2780
        mov   esi, 1
2781
        call  delay_ms
2782
        jmp   @b
1 ha 2783
  @@:
2784
  ; end Lisovin's fix
2785
 
1055 Galkov 2786
        xor   al,al           ; seconds
2787
        out   0x70,al
2788
        in    al,0x71
2789
        movzx ecx,al
2790
        mov   al,02           ; minutes
2791
        shl   ecx,16
2792
        out   0x70,al
2793
        in    al,0x71
2794
        movzx edx,al
2795
        mov   al,04           ; hours
2796
        shl   edx,8
2797
        out   0x70,al
2798
        in    al,0x71
2799
        add   ecx,edx
2800
        movzx edx,al
2801
        add   ecx,edx
2802
        sti
2803
        mov     [esp + 32], ecx
2804
        ret
1 ha 2805
 
2806
 
2807
align 4
2808
 
2809
sys_date:
2810
 
1055 Galkov 2811
        cli
2812
  @@:   mov   al, 10
2813
        out   0x70, al
2814
        in    al, 0x71
2815
        test  al, al
2816
        jns   @f
2817
        mov   esi, 1
2818
        call  delay_ms
2819
        jmp   @b
75 diamond 2820
  @@:
2821
 
1055 Galkov 2822
        mov     ch,0
2823
        mov     al,7            ; date
2824
        out     0x70,al
2825
        in      al,0x71
2826
        mov     cl,al
2827
        mov     al,8            ; month
2828
        shl     ecx,16
2829
        out     0x70,al
2830
        in      al,0x71
2831
        mov     ch,al
2832
        mov     al,9            ; year
2833
        out     0x70,al
2834
        in      al,0x71
2835
        mov     cl,al
2836
        sti
2837
        mov     [esp+32], ecx
2838
        ret
1 ha 2839
 
2840
 
2841
; redraw status
2842
 
2843
sys_redrawstat:
1055 Galkov 2844
        cmp     ebx, 1
2845
        jne     no_widgets_away
2846
        ; buttons away
2847
        mov     ecx,[CURRENT_TASK]
1 ha 2848
  sys_newba2:
1055 Galkov 2849
        mov     edi,[BTN_ADDR]
2850
        cmp     [edi], dword 0  ; empty button list ?
2851
        je      end_of_buttons_away
2852
        movzx   ebx, word [edi]
2853
        inc     ebx
2854
        mov     eax,edi
1 ha 2855
  sys_newba:
1055 Galkov 2856
        dec     ebx
2857
        jz      end_of_buttons_away
1 ha 2858
 
1055 Galkov 2859
        add     eax, 0x10
2860
        cmp     cx, [eax]
2861
        jnz     sys_newba
1 ha 2862
 
1055 Galkov 2863
        push    eax ebx ecx
2864
        mov     ecx,ebx
2865
        inc     ecx
2866
        shl     ecx, 4
2867
        mov     ebx, eax
2868
        add     eax, 0x10
2869
        call    memmove
2870
        dec     dword [edi]
2871
        pop     ecx ebx eax
1 ha 2872
 
1055 Galkov 2873
        jmp     sys_newba2
1 ha 2874
 
2875
  end_of_buttons_away:
2876
 
1055 Galkov 2877
        ret
1 ha 2878
 
2879
  no_widgets_away:
2880
 
1055 Galkov 2881
        cmp     ebx, 2
2882
        jnz     srl1
1 ha 2883
 
1055 Galkov 2884
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
2885
        add     edx, draw_data - CURRENT_TASK
2886
        mov     [edx + RECT.left], 0
2887
        mov     [edx + RECT.top], 0
2888
        mov     eax, [Screen_Max_X]
2889
        mov     [edx + RECT.right], eax
2890
        mov     eax, [Screen_Max_Y]
2891
        mov     [edx + RECT.bottom], eax
1 ha 2892
 
1055 Galkov 2893
        mov     edi, [TASK_BASE]
2894
        or      [edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2895
        call    sys_window_mouse
2896
        ret
1 ha 2897
 
2898
  srl1:
1055 Galkov 2899
        ret
1 ha 2900
 
2901
 
2902
sys_drawwindow:
2903
 
684 diamond 2904
    mov   eax,edx
2905
    shr   eax,16+8
2906
    and   eax,15
1 ha 2907
 
684 diamond 2908
;    cmp   eax,0   ; type I    - original style
1 ha 2909
    jne   nosyswI
33 mario79 2910
    inc   [mouse_pause]
1300 serge 2911
    call  [_display.disable_mouse]
1 ha 2912
    call  sys_set_window
1300 serge 2913
    call  [_display.disable_mouse]
1 ha 2914
    call  drawwindow_I
114 mikedld 2915
    ;dec   [mouse_pause]
2916
    ;call   [draw_pointer]
2917
    ;ret
2918
    jmp   draw_window_caption.2
1 ha 2919
  nosyswI:
2920
 
1055 Galkov 2921
    cmp   al,1    ; type II   - only reserve area, no draw
1 ha 2922
    jne   nosyswII
33 mario79 2923
    inc   [mouse_pause]
1300 serge 2924
    call  [_display.disable_mouse]
1 ha 2925
    call  sys_set_window
1300 serge 2926
    call  [_display.disable_mouse]
1 ha 2927
    call  sys_window_mouse
33 mario79 2928
    dec   [mouse_pause]
36 mario79 2929
    call   [draw_pointer]
1 ha 2930
    ret
2931
  nosyswII:
2932
 
1055 Galkov 2933
    cmp   al,2    ; type III  - new style
1 ha 2934
    jne   nosyswIII
33 mario79 2935
    inc   [mouse_pause]
1300 serge 2936
    call  [_display.disable_mouse]
1 ha 2937
    call  sys_set_window
1300 serge 2938
    call  [_display.disable_mouse]
1 ha 2939
    call  drawwindow_III
114 mikedld 2940
    ;dec   [mouse_pause]
2941
    ;call   [draw_pointer]
2942
    ;ret
2943
    jmp   draw_window_caption.2
1 ha 2944
  nosyswIII:
2945
 
1055 Galkov 2946
    cmp   al,3    ; type IV - skinned window
2947
    je    draw_skin_window
2948
    cmp   al,4    ; type V - skinned window not sized! {not_sized_skin_window}
549 spraid 2949
    jne   nosyswV
2950
  draw_skin_window:
567 serge 2951
 
569 diamond 2952
    inc   [mouse_pause]
1300 serge 2953
    call  [_display.disable_mouse]
569 diamond 2954
    call  sys_set_window
1300 serge 2955
    call  [_display.disable_mouse]
684 diamond 2956
    mov   eax, [TASK_COUNT]
2957
    movzx eax, word [WIN_POS + eax*2]
2958
    cmp   eax, [CURRENT_TASK]
2959
    setz  al
2960
    movzx eax, al
2961
    push  eax
36 mario79 2962
    call  drawwindow_IV
114 mikedld 2963
    ;dec   [mouse_pause]
2964
    ;call   [draw_pointer]
2965
    ;ret
2966
    jmp   draw_window_caption.2
549 spraid 2967
  nosyswV:
1 ha 2968
 
2969
    ret
2970
 
2971
 
114 mikedld 2972
draw_window_caption:
1055 Galkov 2973
        inc     [mouse_pause]
1300 serge 2974
        call    [_display.disable_mouse]
114 mikedld 2975
 
1055 Galkov 2976
        xor     eax,eax
2977
        mov     edx,[TASK_COUNT]
2978
        movzx   edx,word[WIN_POS+edx*2]
2979
        cmp     edx,[CURRENT_TASK]
2980
        jne     @f
2981
        inc     eax
2982
    @@: mov     edx,[CURRENT_TASK]
2983
        shl     edx,5
2984
        add     edx,window_data
2985
        movzx   ebx,[edx+WDATA.fl_wstyle]
2986
        and     bl,0x0F
2987
        cmp     bl,3
2988
        je      .draw_caption_style_3           ;{for 3 and 4 style write caption}
2989
        cmp     bl,4
2990
        je      .draw_caption_style_3
567 serge 2991
 
1055 Galkov 2992
        jmp     .not_style_3
549 spraid 2993
  .draw_caption_style_3:
114 mikedld 2994
 
1055 Galkov 2995
        push    edx
2996
        call    drawwindow_IV_caption
2997
        add     esp,4
2998
        jmp     .2
114 mikedld 2999
 
3000
  .not_style_3:
1055 Galkov 3001
        cmp     bl,2
3002
        jne     .not_style_2
114 mikedld 3003
 
1055 Galkov 3004
        call    drawwindow_III_caption
3005
        jmp     .2
114 mikedld 3006
 
3007
  .not_style_2:
1055 Galkov 3008
        cmp     bl,0
3009
        jne     .2
114 mikedld 3010
 
1055 Galkov 3011
        call    drawwindow_I_caption
114 mikedld 3012
 
3013
;--------------------------------------------------------------
1055 Galkov 3014
  .2:   ;jmp     @f
3015
        mov     edi,[CURRENT_TASK]
3016
        shl     edi,5
3017
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3018
        jz      @f
3019
        mov     edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
3020
        or      edx,edx
3021
        jz      @f
114 mikedld 3022
 
1055 Galkov 3023
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
3024
        and     al,0x0F
3025
        cmp     al,3
3026
        je      .skinned
3027
        cmp     al,4
3028
        je      .skinned
567 serge 3029
 
1055 Galkov 3030
        jmp     .not_skinned
567 serge 3031
  .skinned:
1055 Galkov 3032
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3033
        mov     bp,word[edi+window_data+WDATA.box.top]
3034
        movzx   eax,word[edi+window_data+WDATA.box.width]
3035
        sub     ax,[_skinmargins.left]
3036
        sub     ax,[_skinmargins.right]
3037
        push    edx
3038
        cwde
3039
        cdq
3040
        mov     ebx,6
3041
        idiv    ebx
3042
        pop     edx
3043
        or      eax,eax
3044
        js      @f
3045
        mov     esi,eax
3046
        mov     ebx,dword[_skinmargins.left-2]
3047
        mov     bx,word[_skinh]
3048
        sub     bx,[_skinmargins.bottom]
3049
        sub     bx,[_skinmargins.top]
3050
        sar     bx,1
3051
        adc     bx,0
3052
        add     bx,[_skinmargins.top]
3053
        add     bx,-3
3054
        add     ebx,ebp
3055
        jmp     .dodraw
114 mikedld 3056
 
3057
  .not_skinned:
1055 Galkov 3058
        cmp     al,1
3059
        je      @f
114 mikedld 3060
 
1055 Galkov 3061
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3062
        mov     bp,word[edi+window_data+WDATA.box.top]
3063
        movzx   eax,word[edi+window_data+WDATA.box.width]
3064
        sub     eax,16
3065
        push    edx
3066
        cwde
3067
        cdq
3068
        mov     ebx,6
3069
        idiv    ebx
3070
        pop     edx
3071
        or      eax,eax
3072
        js      @f
3073
        mov     esi,eax
3074
        mov     ebx,0x00080007
3075
        add     ebx,ebp
139 diamond 3076
.dodraw:
1055 Galkov 3077
        mov     ecx,[common_colours+16];0x00FFFFFF
3078
        or      ecx, 0x80000000
3079
        xor     edi,edi
803 alver 3080
; // Alver 22.06.2008 // {
1043 hidnplayr 3081
;       call    dtext
1055 Galkov 3082
        call dtext_asciiz_esi
803 alver 3083
; } \\ Alver \\
114 mikedld 3084
 
3085
    @@:
3086
;--------------------------------------------------------------
1055 Galkov 3087
        dec     [mouse_pause]
3088
        call    [draw_pointer]
3089
        ret
114 mikedld 3090
 
3091
iglobal
3092
align 4
3093
window_topleft dd \
1055 Galkov 3094
  1, 21,\               ;type 0
3095
  0,  0,\       ;type 1
3096
  5, 20,\       ;type 2
3097
  5,  ?,\       ;type 3 {set by skin}
3098
  5,  ?         ;type 4 {set by skin}
114 mikedld 3099
endg
3100
 
3101
set_window_clientbox:
1055 Galkov 3102
        push    eax ecx edi
114 mikedld 3103
 
1055 Galkov 3104
        mov     eax,[_skinh]
3105
        mov     [window_topleft+4*7],eax
3106
        mov     [window_topleft+4*9],eax
114 mikedld 3107
 
1055 Galkov 3108
        mov     ecx,edi
3109
        sub     edi,window_data
3110
        shl     edi,3
3111
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3112
        jz      @f
114 mikedld 3113
 
1055 Galkov 3114
        movzx   eax,[ecx+WDATA.fl_wstyle]
3115
        and     eax,0x0F
3116
        mov     eax,[eax*8+window_topleft+0]
3117
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3118
        shl     eax,1
3119
        neg     eax
3120
        add     eax,[ecx+WDATA.box.width]
3121
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
114 mikedld 3122
 
1055 Galkov 3123
        movzx   eax,[ecx+WDATA.fl_wstyle]
3124
        and     eax,0x0F
3125
        push    [eax*8+window_topleft+0]
3126
        mov     eax,[eax*8+window_topleft+4]
3127
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3128
        neg     eax
3129
        sub     eax,[esp]
3130
        add     eax,[ecx+WDATA.box.height]
3131
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3132
        add     esp,4
114 mikedld 3133
 
1055 Galkov 3134
        pop     edi ecx eax
3135
        ret
114 mikedld 3136
    @@:
1055 Galkov 3137
        xor     eax,eax
3138
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3139
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3140
        mov     eax,[ecx+WDATA.box.width]
3141
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3142
        mov     eax,[ecx+WDATA.box.height]
3143
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
114 mikedld 3144
 
1055 Galkov 3145
        pop     edi ecx eax
3146
        ret
114 mikedld 3147
 
1 ha 3148
sys_set_window:
3149
 
684 diamond 3150
    mov   eax,[CURRENT_TASK]
3151
    shl   eax,5
3152
    add   eax,window_data
1 ha 3153
 
3154
    ; colors
684 diamond 3155
    mov   [eax+WDATA.cl_workarea],edx
3156
    mov   [eax+WDATA.cl_titlebar],esi
3157
    mov   [eax+WDATA.cl_frames],edi
1 ha 3158
 
684 diamond 3159
    mov   edi, eax
3160
 
1 ha 3161
    ; check flag (?)
186 diamond 3162
    test  [edi+WDATA.fl_wdrawn],1
3163
    jnz   newd
1 ha 3164
 
3165
    mov   eax,[timer_ticks] ;[0xfdf0]
3166
    add   eax,100
3167
    mov   [new_window_starting],eax
3168
 
856 diamond 3169
    movsx eax,bx
3170
    mov   [edi+WDATA.box.width],eax
3171
    movsx eax,cx
3172
    mov   [edi+WDATA.box.height],eax
114 mikedld 3173
    sar   ebx,16
684 diamond 3174
    sar   ecx,16
856 diamond 3175
    mov   [edi+WDATA.box.left],ebx
3176
    mov   [edi+WDATA.box.top],ecx
1 ha 3177
 
3178
    call  check_window_position
3179
 
1055 Galkov 3180
    push  ecx esi edi               ; save for window fullscreen/resize
114 mikedld 3181
    ;mov   esi,edi
3182
 
1055 Galkov 3183
        mov     cl, [edi+WDATA.fl_wstyle]
3184
        mov     eax, [edi+WDATA.cl_frames]
114 mikedld 3185
 
1 ha 3186
    sub   edi,window_data
114 mikedld 3187
    shl   edi,3
380 serge 3188
    add   edi,SLOT_BASE
114 mikedld 3189
 
1055 Galkov 3190
        and     cl,0x0F
3191
        mov     [edi+APPDATA.wnd_caption],0
3192
        cmp     cl,3
3193
        je      set_APPDATA_wnd_caption
3194
        cmp     cl,4                                                            ; {SPraid.simba}
3195
        je      set_APPDATA_wnd_caption
567 serge 3196
 
1055 Galkov 3197
        jmp     @f
549 spraid 3198
    set_APPDATA_wnd_caption:
1055 Galkov 3199
        mov     [edi+APPDATA.wnd_caption],eax
3200
    @@: mov     esi,[esp+0]
114 mikedld 3201
 
115 poddubny 3202
    add   edi, APPDATA.saved_box
1055 Galkov 3203
        movsd
3204
        movsd
3205
        movsd
3206
        movsd
1 ha 3207
    pop   edi esi ecx
3208
 
1055 Galkov 3209
        mov     esi, [CURRENT_TASK]
3210
        movzx   esi, word [WIN_STACK+esi*2]
3211
        lea     esi, [WIN_POS+esi*2]
3212
        call    waredraw
569 diamond 3213
 
684 diamond 3214
;;;    mov   ebx, 1
1 ha 3215
;;;    call  delay_hs
115 poddubny 3216
    mov   eax, [edi+WDATA.box.left]
3217
    mov   ebx, [edi+WDATA.box.top]
3218
    mov   ecx, [edi+WDATA.box.width]
3219
    mov   edx, [edi+WDATA.box.height]
1 ha 3220
    add   ecx, eax
3221
    add   edx, ebx
3222
    call  calculatescreen
3223
 
1055 Galkov 3224
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3225
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 3226
 
3227
  newd:
1116 diamond 3228
    call  set_window_clientbox
3229
 
1055 Galkov 3230
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
1 ha 3231
    mov   edx,edi
3232
 
3233
    ret
3234
 
114 mikedld 3235
syscall_windowsettings:
1 ha 3236
 
114 mikedld 3237
  .set_window_caption:
1329 Lrz 3238
        dec     ebx     ; subfunction #1 - set window caption
3239
        jnz     .exit_fail
114 mikedld 3240
 
1055 Galkov 3241
        ; NOTE: only window owner thread can set its caption,
3242
        ;       so there's no parameter for PID/TID
114 mikedld 3243
 
1055 Galkov 3244
        mov     edi,[CURRENT_TASK]
3245
        shl     edi,5
114 mikedld 3246
 
1055 Galkov 3247
        ; have to check if caption is within application memory limit
3248
        ; check is trivial, and if application resizes its memory,
3249
        ;   caption still can become over bounds
202 diamond 3250
; diamond, 31.10.2006: check removed because with new memory manager
3251
; there can be valid data after APPDATA.mem_size bound
380 serge 3252
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
202 diamond 3253
;        add     ecx,255 ; max caption length
3254
;        cmp     ebx,ecx
3255
;        ja      .exit_fail
114 mikedld 3256
 
1329 Lrz 3257
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ecx
1055 Galkov 3258
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
114 mikedld 3259
 
1055 Galkov 3260
        call    draw_window_caption
114 mikedld 3261
 
1055 Galkov 3262
        xor     eax,eax ; eax = 0 (success)
3263
        ret
114 mikedld 3264
 
1329 Lrz 3265
;  .get_window_caption:
3266
;        dec     eax     ; subfunction #2 - get window caption
3267
;        jnz     .exit_fail
114 mikedld 3268
 
1055 Galkov 3269
        ; not implemented yet
114 mikedld 3270
 
3271
  .exit_fail:
1055 Galkov 3272
        xor     eax,eax
3273
        inc     eax     ; eax = 1 (fail)
3274
        ret
114 mikedld 3275
 
3276
 
1 ha 3277
sys_window_move:
3278
 
1055 Galkov 3279
        mov     edi,[CURRENT_TASK]
3280
        shl     edi,5
3281
        add     edi,window_data
1 ha 3282
 
1055 Galkov 3283
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3284
        jnz     .window_move_return
1 ha 3285
 
1055 Galkov 3286
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3287
        push    dword [edi + WDATA.box.top]
3288
        push    dword [edi + WDATA.box.width]
3289
        push    dword [edi + WDATA.box.height]
1 ha 3290
 
1055 Galkov 3291
        cmp   eax,-1                  ; set new position and size
3292
        je    .no_x_reposition
3293
        mov     [edi + WDATA.box.left], eax
49 mikedld 3294
      .no_x_reposition:
1055 Galkov 3295
        cmp   ebx,-1
3296
        je    .no_y_reposition
3297
        mov     [edi + WDATA.box.top], ebx
49 mikedld 3298
      .no_y_reposition:
1 ha 3299
 
1055 Galkov 3300
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3301
        jnz     .no_y_resizing
1 ha 3302
 
1055 Galkov 3303
        cmp   ecx,-1
3304
        je    .no_x_resizing
3305
        mov     [edi + WDATA.box.width], ecx
49 mikedld 3306
      .no_x_resizing:
1055 Galkov 3307
        cmp   edx,-1
3308
        je    .no_y_resizing
3309
        mov     [edi + WDATA.box.height], edx
49 mikedld 3310
      .no_y_resizing:
1 ha 3311
 
1055 Galkov 3312
        call  check_window_position
3313
        call  set_window_clientbox
1 ha 3314
 
1055 Galkov 3315
        pushad                       ; save for window fullscreen/resize
3316
        mov   esi,edi
3317
        sub   edi,window_data
3318
        shr   edi,5
3319
        shl   edi,8
3320
        add   edi, SLOT_BASE + APPDATA.saved_box
3321
        mov   ecx,4
3322
        cld
3323
        rep   movsd
3324
        popad
49 mikedld 3325
 
1055 Galkov 3326
        pushad                       ; calculcate screen at new position
3327
        mov   eax, [edi + WDATA.box.left]
3328
        mov   ebx, [edi + WDATA.box.top]
3329
        mov   ecx, [edi + WDATA.box.width]
3330
        mov   edx, [edi + WDATA.box.height]
3331
        add   ecx,eax
3332
        add   edx,ebx
221 serge 3333
 
1055 Galkov 3334
        call  calculatescreen
3335
        popad
49 mikedld 3336
 
1055 Galkov 3337
        pop   edx                   ; calculcate screen at old position
3338
        pop   ecx
3339
        pop   ebx
3340
        pop   eax
3341
        add   ecx,eax
3342
        add   edx,ebx
1362 mikedld 3343
        mov   [draw_limits.left],eax             ; save for drawlimits
3344
        mov   [draw_limits.top],ebx
3345
        mov   [draw_limits.right],ecx
3346
        mov   [draw_limits.bottom],edx
1055 Galkov 3347
        call  calculatescreen
49 mikedld 3348
 
1055 Galkov 3349
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3350
 
1055 Galkov 3351
        mov   eax,edi               ; redraw screen at old position
3352
        xor   esi,esi
3353
        call  redrawscreen
49 mikedld 3354
 
1055 Galkov 3355
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3356
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3357
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
49 mikedld 3358
 
1055 Galkov 3359
        call  [draw_pointer]
49 mikedld 3360
 
1055 Galkov 3361
        mov   [window_move_pr],0
49 mikedld 3362
 
3363
      .window_move_return:
3364
 
1055 Galkov 3365
        ret
1 ha 3366
 
3367
uglobal
3368
  window_move_pr   dd  0x0
3369
  window_move_eax  dd  0x0
3370
  window_move_ebx  dd  0x0
3371
  window_move_ecx  dd  0x0
3372
  window_move_edx  dd  0x0
3373
endg
3374
 
3375
;ok - 100% work
3376
;nt - not tested
3377
;---------------------------------------------------------------------------------------------
3378
;eax
3379
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3380
;1 - change task. Ret nothing. Block. ok.
3381
;2 - performance control
3382
; ebx
3383
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3384
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3385
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3386
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3387
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3388
;eax
3389
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3390
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3391
;---------------------------------------------------------------------------------------------
1344 Lrz 3392
iglobal
3393
align 4
3394
sheduler:
3395
	dd	sys_sheduler.00
3396
	dd	change_task
3397
	dd	sys_sheduler.02
3398
	dd	sys_sheduler.03
3399
	dd	sys_sheduler.04
3400
endg
1273 Lrz 3401
sys_sheduler:
1344 Lrz 3402
;rewritten by   29.12.2009
1345 Lrz 3403
	jmp	dword [sheduler+ebx*4]
1344 Lrz 3404
;.shed_counter:
3405
.00:
3406
	mov eax,[context_counter]
1345 Lrz 3407
	mov [esp+32],eax
1344 Lrz 3408
	ret
1273 Lrz 3409
 
1344 Lrz 3410
.02:
3411
;.perf_control:
1365 Lrz 3412
	inc	ebx			;before ebx=2, ebx=3
3413
        cmp	ebx,ecx			;if ecx=3, ebx=3
3414
        jz 	cache_disable
3415
 
3416
	dec	ebx                     ;ebx=2
3417
	cmp	ebx,ecx                 ;
3418
	jz	cache_enable		;if ecx=2 and ebx=2
3419
 
3420
	dec	ebx                     ;ebx=1
3421
	cmp	ebx,ecx
3422
	jz      is_cache_enabled	;if ecx=1 and ebx=1
3423
 
3424
	dec	ebx
3425
	test	ebx,ecx                 ;ebx=0 and ecx=0
1344 Lrz 3426
	jz 	modify_pce		;if ecx=0
1365 Lrz 3427
 
1344 Lrz 3428
	ret
1345 Lrz 3429
 
1344 Lrz 3430
.03:
3431
;.rdmsr_instr:
3432
;now counter in ecx
3433
;(edx:eax) esi:edi => edx:esi
3434
	mov 	eax,esi
1345 Lrz 3435
	mov	ecx,edx
1344 Lrz 3436
	rdmsr
1345 Lrz 3437
	mov 	[esp+32],eax
3438
	mov 	[esp+20],edx 		;ret in ebx?
1344 Lrz 3439
	ret
3440
 
3441
.04:
1273 Lrz 3442
;.wrmsr_instr:
3443
;now counter in ecx
3444
;(edx:eax) esi:edi => edx:esi
3445
        ; Fast Call MSR can't be destroy
3446
        ; ® MSR_AMD_EFER ¬®¦­® ¨§¬¥­ïâì, â.ª. ¢ í⮬ ॣ¨áâॠ«¨è
3447
        ; ¢ª«îç îâáï/¢ëª«îç îâáï à áè¨à¥­­ë¥ ¢®§¬®¦­®áâ¨
1345 Lrz 3448
        cmp     edx,MSR_SYSENTER_CS
1273 Lrz 3449
        je      @f
1345 Lrz 3450
        cmp     edx,MSR_SYSENTER_ESP
1273 Lrz 3451
        je      @f
1345 Lrz 3452
        cmp     edx,MSR_SYSENTER_EIP
1273 Lrz 3453
        je      @f
1345 Lrz 3454
        cmp     edx,MSR_AMD_STAR
1273 Lrz 3455
        je      @f
3456
 
1344 Lrz 3457
        mov     eax,esi
1345 Lrz 3458
	mov	ecx,edx
1273 Lrz 3459
        wrmsr
1344 Lrz 3460
        ; mov   [esp + 32], eax
3461
        ; mov   [esp + 20], edx ;ret in ebx?
1273 Lrz 3462
@@:
1344 Lrz 3463
	ret
1273 Lrz 3464
 
1 ha 3465
cache_disable:
3466
       mov eax,cr0
3467
       or  eax,01100000000000000000000000000000b
3468
       mov cr0,eax
3469
       wbinvd ;set MESI
3470
ret
3471
 
3472
cache_enable:
3473
       mov eax,cr0
3474
       and eax,10011111111111111111111111111111b
3475
       mov cr0,eax
3476
ret
3477
 
3478
is_cache_enabled:
3479
       mov eax,cr0
3480
       mov ebx,eax
3481
       and eax,01100000000000000000000000000000b
3482
       jz cache_disabled
1345 Lrz 3483
       mov [esp+32],ebx
1 ha 3484
cache_disabled:
1345 Lrz 3485
       mov dword [esp+32],eax ;0
1 ha 3486
ret
3487
 
3488
modify_pce:
3489
       mov eax,cr4
3490
;       mov ebx,0
3491
;       or  bx,100000000b ;pce
3492
;       xor eax,ebx ;invert pce
17 me_root 3493
       bts eax,8 ;pce=cr4[8]
1 ha 3494
       mov cr4,eax
1345 Lrz 3495
       mov [esp+32],eax
1 ha 3496
ret
3497
;---------------------------------------------------------------------------------------------
3498
 
3499
 
3500
; check if pixel is allowed to be drawn
3501
 
3502
checkpixel:
1055 Galkov 3503
        push eax edx
1 ha 3504
 
1055 Galkov 3505
        mov  edx,[Screen_Max_X]     ; screen x size
3506
        inc  edx
3507
        imul edx, ebx
1300 serge 3508
        add  eax, [_WinMapAddress]
3509
        mov  dl, [eax+edx] ; lea eax, [...]
1 ha 3510
 
1055 Galkov 3511
        xor  ecx, ecx
3512
        mov  eax, [CURRENT_TASK]
3513
        cmp  al, dl
3514
        setne cl
1 ha 3515
 
1055 Galkov 3516
        pop  edx eax
3517
        ret
1 ha 3518
 
3519
iglobal
521 diamond 3520
  cpustring db 'CPU',0
1 ha 3521
endg
3522
 
67 diamond 3523
uglobal
1055 Galkov 3524
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3525
endg
1 ha 3526
 
3527
align 4
3528
; check misc
3529
 
3530
checkmisc:
3531
 
3532
    cmp   [ctrl_alt_del], 1
3533
    jne   nocpustart
501 serge 3534
 
1055 Galkov 3535
        mov     ebp, cpustring
3536
        call    fs_execute_from_sysdir
501 serge 3537
 
1 ha 3538
    mov   [ctrl_alt_del], 0
465 serge 3539
 
3540
nocpustart:
1 ha 3541
    cmp   [mouse_active], 1
3542
    jne   mouse_not_active
3543
    mov   [mouse_active], 0
3544
    xor   edi, edi
1055 Galkov 3545
    mov   ecx,  [TASK_COUNT]
465 serge 3546
set_mouse_event:
1 ha 3547
    add   edi, 256
1055 Galkov 3548
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
1 ha 3549
    loop  set_mouse_event
3550
 
465 serge 3551
mouse_not_active:
1055 Galkov 3552
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3553
    jz    nobackgr
76 mario79 3554
    cmp    [background_defined], 0
1055 Galkov 3555
    jz    nobackgr
709 diamond 3556
    cmp   [REDRAW_BACKGROUND], byte 2
3557
    jnz   no_set_bgr_event
473 diamond 3558
    xor   edi, edi
1055 Galkov 3559
    mov   ecx,  [TASK_COUNT]
473 diamond 3560
set_bgr_event:
3561
    add   edi, 256
1055 Galkov 3562
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
473 diamond 3563
    loop  set_bgr_event
709 diamond 3564
no_set_bgr_event:
3565
;    mov   [draw_data+32 + RECT.left],dword 0
3566
;    mov   [draw_data+32 + RECT.top],dword 0
753 serge 3567
;    mov   eax,[Screen_Max_X]
3568
;    mov   ebx,[Screen_Max_Y]
709 diamond 3569
;    mov   [draw_data+32 + RECT.right],eax
3570
;    mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3571
    call  drawbackground
381 serge 3572
    mov   [REDRAW_BACKGROUND],byte 0
3573
    mov   [MOUSE_BACKGROUND],byte 0
1 ha 3574
 
465 serge 3575
nobackgr:
1 ha 3576
 
3577
    ; system shutdown request
3578
 
381 serge 3579
    cmp  [SYS_SHUTDOWN],byte 0
1055 Galkov 3580
    je   noshutdown
1 ha 3581
 
3582
    mov  edx,[shutdown_processes]
3583
 
381 serge 3584
    cmp  [SYS_SHUTDOWN],dl
1 ha 3585
    jne  no_mark_system_shutdown
3586
 
709 diamond 3587
    lea   ecx,[edx-1]
465 serge 3588
    mov   edx,OS_BASE+0x3040
709 diamond 3589
    jecxz @f
465 serge 3590
markz:
115 poddubny 3591
    mov   [edx+TASKDATA.state],byte 3
1 ha 3592
    add   edx,0x20
3593
    loop  markz
709 diamond 3594
@@:
1 ha 3595
 
3596
  no_mark_system_shutdown:
3597
 
1300 serge 3598
    call [_display.disable_mouse]
1 ha 3599
 
381 serge 3600
    dec  byte [SYS_SHUTDOWN]
1055 Galkov 3601
    je   system_shutdown
1 ha 3602
 
465 serge 3603
noshutdown:
1 ha 3604
 
3605
 
1055 Galkov 3606
    mov   eax,[TASK_COUNT]                  ; termination
379 serge 3607
    mov   ebx,TASK_DATA+TASKDATA.state
1 ha 3608
    mov   esi,1
3609
 
465 serge 3610
newct:
1 ha 3611
    mov   cl,[ebx]
3612
    cmp   cl,byte 3
1055 Galkov 3613
    jz    terminate
1 ha 3614
    cmp   cl,byte 4
1055 Galkov 3615
    jz    terminate
1 ha 3616
 
3617
    add   ebx,0x20
3618
    inc   esi
3619
    dec   eax
3620
    jnz   newct
3621
    ret
3622
 
3623
; redraw screen
3624
 
3625
redrawscreen:
3626
 
3627
; eax , if process window_data base is eax, do not set flag/limits
3628
 
1055 Galkov 3629
         pushad
3630
         push  eax
1 ha 3631
 
684 diamond 3632
;;;         mov   ebx,2
1 ha 3633
;;;         call  delay_hs
3634
 
1055 Galkov 3635
         ;mov   ecx,0               ; redraw flags for apps
3636
         xor   ecx,ecx
1 ha 3637
       newdw2:
3638
 
1055 Galkov 3639
         inc   ecx
3640
         push  ecx
1 ha 3641
 
1055 Galkov 3642
         mov   eax,ecx
3643
         shl   eax,5
3644
         add   eax,window_data
1 ha 3645
 
1055 Galkov 3646
         cmp   eax,[esp+4]
3647
         je    not_this_task
3648
                                   ; check if window in redraw area
3649
         mov   edi,eax
1 ha 3650
 
1055 Galkov 3651
         cmp   ecx,1               ; limit for background
3652
         jz    bgli
1 ha 3653
 
1055 Galkov 3654
         mov   eax, [edi + WDATA.box.left]
3655
         mov   ebx, [edi + WDATA.box.top]
3656
         mov   ecx, [edi + WDATA.box.width]
3657
         mov   edx, [edi + WDATA.box.height]
3658
         add   ecx,eax
3659
         add   edx,ebx
1 ha 3660
 
1362 mikedld 3661
         mov   ecx,[draw_limits.bottom]   ; ecx = area y end     ebx = window y start
1055 Galkov 3662
         cmp   ecx,ebx
3663
         jb    ricino
1 ha 3664
 
1362 mikedld 3665
         mov   ecx,[draw_limits.right]   ; ecx = area x end     eax = window x start
1055 Galkov 3666
         cmp   ecx,eax
3667
         jb    ricino
1 ha 3668
 
1055 Galkov 3669
         mov   eax, [edi + WDATA.box.left]
3670
         mov   ebx, [edi + WDATA.box.top]
3671
         mov   ecx, [edi + WDATA.box.width]
3672
         mov   edx, [edi + WDATA.box.height]
3673
         add   ecx, eax
3674
         add   edx, ebx
164 serge 3675
 
1362 mikedld 3676
         mov   eax,[draw_limits.top]    ; eax = area y start     edx = window y end
1055 Galkov 3677
         cmp   edx,eax
3678
         jb    ricino
1 ha 3679
 
1362 mikedld 3680
         mov   eax,[draw_limits.left]    ; eax = area x start     ecx = window x end
1055 Galkov 3681
         cmp   ecx,eax
3682
         jb    ricino
1 ha 3683
 
1055 Galkov 3684
        bgli:
1 ha 3685
 
1055 Galkov 3686
         cmp   ecx,1
3687
         jnz   .az
3688
         mov   al,[REDRAW_BACKGROUND]
3689
         cmp   al,2
3690
         jz    newdw8
3691
         test  al,al
3692
         jz    .az
3693
         lea   eax,[edi+draw_data-window_data]
1362 mikedld 3694
         mov   ebx,[draw_limits.left]
1055 Galkov 3695
         cmp   ebx,[eax+RECT.left]
3696
         jae   @f
3697
         mov   [eax+RECT.left],ebx
3698
        @@:
1362 mikedld 3699
         mov   ebx,[draw_limits.top]
1055 Galkov 3700
         cmp   ebx,[eax+RECT.top]
3701
         jae   @f
3702
         mov   [eax+RECT.top],ebx
3703
        @@:
1362 mikedld 3704
         mov   ebx,[draw_limits.right]
1055 Galkov 3705
         cmp   ebx,[eax+RECT.right]
3706
         jbe   @f
3707
         mov   [eax+RECT.right],ebx
3708
        @@:
1362 mikedld 3709
         mov   ebx,[draw_limits.bottom]
1055 Galkov 3710
         cmp   ebx,[eax+RECT.bottom]
3711
         jbe   @f
3712
         mov   [eax+RECT.bottom],ebx
3713
        @@:
3714
         jmp   newdw8
3715
        .az:
1 ha 3716
 
1055 Galkov 3717
         mov   eax,edi
3718
         add   eax,draw_data-window_data
1 ha 3719
 
1362 mikedld 3720
         mov   ebx,[draw_limits.left]          ; set limits
1055 Galkov 3721
         mov   [eax + RECT.left], ebx
1362 mikedld 3722
         mov   ebx,[draw_limits.top]
1055 Galkov 3723
         mov   [eax + RECT.top], ebx
1362 mikedld 3724
         mov   ebx,[draw_limits.right]
1055 Galkov 3725
         mov   [eax + RECT.right], ebx
1362 mikedld 3726
         mov   ebx,[draw_limits.bottom]
1055 Galkov 3727
         mov   [eax + RECT.bottom], ebx
1 ha 3728
 
1055 Galkov 3729
         sub   eax,draw_data-window_data
1 ha 3730
 
1055 Galkov 3731
         cmp   dword [esp],1
3732
         jne   nobgrd
3733
         mov   byte [REDRAW_BACKGROUND], 1
1 ha 3734
 
3735
       newdw8:
3736
       nobgrd:
3737
 
1055 Galkov 3738
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3739
 
3740
       ricino:
3741
 
3742
       not_this_task:
3743
 
1055 Galkov 3744
         pop   ecx
1 ha 3745
 
1055 Galkov 3746
         cmp   ecx,[TASK_COUNT]
3747
         jle   newdw2
1 ha 3748
 
1055 Galkov 3749
         pop  eax
3750
         popad
1 ha 3751
 
1055 Galkov 3752
         ret
1 ha 3753
 
3754
calculatebackground:   ; background
3755
 
1300 serge 3756
        mov   edi, [_WinMapAddress]                ; set os to use all pixels
1055 Galkov 3757
        mov   eax,0x01010101
1300 serge 3758
        mov   ecx, [_WinMapSize]
3759
        shr   ecx, 2
1055 Galkov 3760
        rep   stosd
1 ha 3761
 
1055 Galkov 3762
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
1 ha 3763
 
1055 Galkov 3764
        ret
1 ha 3765
 
3766
uglobal
1055 Galkov 3767
  imax    dd 0x0
1 ha 3768
endg
3769
 
3770
 
3771
 
3772
delay_ms:     ; delay in 1/1000 sec
3773
 
3774
 
1055 Galkov 3775
        push  eax
3776
        push  ecx
1 ha 3777
 
1055 Galkov 3778
        mov   ecx,esi
3779
        ; 
3780
        imul  ecx, 33941
3781
        shr   ecx, 9
3782
        ; 
1 ha 3783
 
1055 Galkov 3784
        in    al,0x61
3785
        and   al,0x10
3786
        mov   ah,al
3787
        cld
1 ha 3788
 
1055 Galkov 3789
 cnt1:  in    al,0x61
3790
        and   al,0x10
3791
        cmp   al,ah
3792
        jz    cnt1
1 ha 3793
 
1055 Galkov 3794
        mov   ah,al
3795
        loop  cnt1
1 ha 3796
 
1055 Galkov 3797
        pop   ecx
3798
        pop   eax
1 ha 3799
 
1055 Galkov 3800
        ret
1 ha 3801
 
3802
 
3803
set_app_param:
1055 Galkov 3804
        mov     edi, [TASK_BASE]
1153 clevermous 3805
        mov     eax, [edi + TASKDATA.event_mask]
1055 Galkov 3806
        mov     [edi + TASKDATA.event_mask], ebx
1153 clevermous 3807
        mov     [esp+32], eax
1055 Galkov 3808
        ret
1 ha 3809
 
3810
 
3811
 
3812
delay_hs:     ; delay in 1/100 secs
684 diamond 3813
; ebx = delay time
1055 Galkov 3814
        push  ecx
3815
        push  edx
1 ha 3816
 
1055 Galkov 3817
        mov   edx,[timer_ticks]
1 ha 3818
 
3819
      newtic:
1055 Galkov 3820
        mov   ecx,[timer_ticks]
3821
        sub   ecx,edx
3822
        cmp   ecx,ebx
3823
        jae   zerodelay
1 ha 3824
 
1055 Galkov 3825
        call  change_task
1 ha 3826
 
1055 Galkov 3827
        jmp   newtic
1 ha 3828
 
3829
      zerodelay:
1055 Galkov 3830
        pop   edx
3831
        pop   ecx
1 ha 3832
 
1055 Galkov 3833
        ret
1 ha 3834
 
1276 Lrz 3835
align 16	;very often call this subrutine
1 ha 3836
memmove:       ; memory move in bytes
3837
 
3838
; eax = from
3839
; ebx = to
3840
; ecx = no of bytes
3841
    test ecx, ecx
3842
    jle  .ret
3843
 
3844
    push esi edi ecx
3845
 
3846
    mov  edi, ebx
3847
    mov  esi, eax
3848
 
3849
    test ecx, not 11b
1055 Galkov 3850
    jz   @f
1 ha 3851
 
3852
    push ecx
3853
    shr  ecx, 2
3854
    rep  movsd
3855
    pop  ecx
3856
    and  ecx, 11b
1055 Galkov 3857
    jz   .finish
1 ha 3858
  @@:
3859
    rep  movsb
3860
 
3861
  .finish:
3862
    pop  ecx edi esi
3863
  .ret:
3864
    ret
3865
 
3866
 
75 diamond 3867
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3868
;align 4
1 ha 3869
;
75 diamond 3870
;read_floppy_file:
1 ha 3871
;
75 diamond 3872
;; as input
3873
;;
3874
;; eax pointer to file
3875
;; ebx file lenght
3876
;; ecx start 512 byte block number
3877
;; edx number of blocks to read
3878
;; esi pointer to return/work area (atleast 20 000 bytes)
3879
;;
3880
;;
3881
;; on return
3882
;;
3883
;; eax = 0 command succesful
3884
;;       1 no fd base and/or partition defined
3885
;;       2 yet unsupported FS
3886
;;       3 unknown FS
3887
;;       4 partition not defined at hd
3888
;;       5 file not found
3889
;; ebx = size of file
1 ha 3890
;
379 serge 3891
;     mov   edi,[TASK_BASE]
75 diamond 3892
;     add   edi,0x10
3893
;     add   esi,[edi]
3894
;     add   eax,[edi]
1 ha 3895
;
75 diamond 3896
;     pushad
3897
;     mov  edi,esi
3898
;     add  edi,1024
3899
;     mov  esi,0x100000+19*512
3900
;     sub  ecx,1
3901
;     shl  ecx,9
3902
;     add  esi,ecx
3903
;     shl  edx,9
3904
;     mov  ecx,edx
3905
;     cld
3906
;     rep  movsb
3907
;     popad
3908
;
3909
;     mov   [esp+36],eax
3910
;     mov   [esp+24],ebx
3911
;     ret
1 ha 3912
 
3913
 
3914
 
3915
align 4
3916
 
3917
sys_programirq:
3918
 
765 Rus 3919
    mov   eax, [TASK_BASE]
3920
    add   ebx, [eax + TASKDATA.mem_start]
1 ha 3921
 
765 Rus 3922
    cmp   ecx, 16
75 diamond 3923
    jae   .not_owner
765 Rus 3924
    mov   edi, [eax + TASKDATA.pid]
3925
    cmp   edi, [irq_owner + 4 * ecx]
1055 Galkov 3926
    je    .spril1
75 diamond 3927
.not_owner:
765 Rus 3928
    xor   ecx, ecx
973 diamond 3929
    inc   ecx
765 Rus 3930
    jmp   .end
3931
  .spril1:
1 ha 3932
 
765 Rus 3933
    shl   ecx, 6
3934
    mov   esi, ebx
3935
    lea   edi, [irq00read + ecx]
3936
    push  16
3937
    pop   ecx
3938
 
1 ha 3939
    cld
3940
    rep   movsd
765 Rus 3941
  .end:
3942
    mov   [esp+32], ecx
1 ha 3943
    ret
3944
 
3945
 
3946
align 4
3947
 
3948
get_irq_data:
1055 Galkov 3949
     movzx esi, bh                       ; save number of subfunction, if bh = 1, return data size, otherwise, read data
760 Rus 3950
     xor   bh, bh
3951
     cmp   ebx, 16
75 diamond 3952
     jae   .not_owner
1055 Galkov 3953
     mov   edx, [4 * ebx + irq_owner]    ; check for irq owner
742 Rus 3954
 
760 Rus 3955
     mov   eax,[TASK_BASE]
742 Rus 3956
 
760 Rus 3957
     cmp   edx,[eax+TASKDATA.pid]
1 ha 3958
     je    gidril1
75 diamond 3959
.not_owner:
760 Rus 3960
     xor   edx, edx
3961
     dec   edx
3962
     jmp   gid1
1 ha 3963
 
3964
  gidril1:
3965
 
760 Rus 3966
     shl   ebx, 12
1055 Galkov 3967
     lea   eax, [ebx + IRQ_SAVE]         ; calculate address of the beginning of buffer + 0x0 - data size
3968
     mov   edx, [eax]                    ;                                              + 0x4 - data offset
760 Rus 3969
     dec   esi
1 ha 3970
     jz    gid1
1055 Galkov 3971
     test  edx, edx                      ; check if buffer is empty
760 Rus 3972
     jz    gid1
1 ha 3973
 
760 Rus 3974
     mov   ebx, [eax + 0x4]
3975
     mov   edi, ecx
742 Rus 3976
 
1055 Galkov 3977
     mov   ecx, 4000                     ; buffer size, used frequently
742 Rus 3978
 
1055 Galkov 3979
     cmp   ebx, ecx                      ; check for the end of buffer, if end of buffer, begin cycle again
759 Rus 3980
     jb    @f
742 Rus 3981
 
760 Rus 3982
     xor   ebx, ebx
759 Rus 3983
 
3984
   @@:
3985
 
1055 Galkov 3986
     lea   esi, [ebx + edx]              ; calculate data size and offset
760 Rus 3987
     cld
1055 Galkov 3988
     cmp   esi, ecx                      ; if greater than the buffer size, begin cycle again
760 Rus 3989
     jbe   @f
759 Rus 3990
 
760 Rus 3991
     sub   ecx, ebx
3992
     sub   edx, ecx
759 Rus 3993
 
760 Rus 3994
     lea   esi, [eax + ebx + 0x10]
3995
     rep   movsb
3996
 
3997
     xor   ebx, ebx
3998
   @@:
3999
     lea   esi, [eax + ebx + 0x10]
4000
     mov   ecx, edx
4001
     add   ebx, edx
4002
 
4003
     rep   movsb
4004
     mov   edx, [eax]
1055 Galkov 4005
     mov   [eax], ecx                    ; set data size to zero
4006
     mov   [eax + 0x4], ebx              ; set data offset
760 Rus 4007
 
1 ha 4008
   gid1:
1055 Galkov 4009
     mov   [esp+32], edx                 ; eax
1 ha 4010
     ret
4011
 
4012
 
4013
set_io_access_rights:
1306 Lrz 4014
      push edi eax
4015
      mov edi, tss._io_map_0
465 serge 4016
;     mov   ecx,eax
4017
;     and   ecx,7    ; offset in byte
4018
;     shr   eax,3    ; number of byte
4019
;     add   edi,eax
4020
;     mov   ebx,1
4021
;     shl   ebx,cl
1232 Lrz 4022
     test  ebp,ebp
4023
;     cmp   ebp,0                ; enable access - ebp = 0
4024
     jnz   siar1
465 serge 4025
;     not   ebx
4026
;     and   [edi],byte bl
4027
     btr [edi], eax
1306 Lrz 4028
     pop eax edi
1 ha 4029
     ret
465 serge 4030
siar1:
4031
     bts [edi], eax
4032
  ;  or    [edi],byte bl        ; disable access - ebp = 1
1306 Lrz 4033
     pop eax edi
1 ha 4034
     ret
1306 Lrz 4035
;reserve/free group of ports
4036
;  * eax = 46 - number function
4037
;  * ebx = 0 - reserve, 1 - free
4038
;  * ecx = number start arrea of ports
4039
;  * edx = number end arrea of ports (include last number of port)
4040
;Return value:
4041
;  * eax = 0 - succesful
4042
;  * eax = 1 - error
4043
;  * The system has reserve this ports:
4044
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
4045
;destroys eax,ebx, ebp
1 ha 4046
r_f_port_area:
4047
 
1306 Lrz 4048
     test  ebx, ebx
1 ha 4049
     jnz   free_port_area
4050
;     je    r_port_area
4051
;     jmp   free_port_area
4052
 
4053
;   r_port_area:
4054
 
1306 Lrz 4055
;     pushad
1 ha 4056
 
1306 Lrz 4057
     cmp   ecx,edx            ; beginning > end ?
75 diamond 4058
     ja    rpal1
1306 Lrz 4059
     cmp   edx,65536
75 diamond 4060
     jae   rpal1
1306 Lrz 4061
     mov   eax,[RESERVED_PORTS]
4062
     test  eax,eax            ; no reserved areas ?
1 ha 4063
     je    rpal2
1306 Lrz 4064
     cmp   eax,255            ; max reserved
75 diamond 4065
     jae   rpal1
465 serge 4066
 rpal3:
1306 Lrz 4067
     mov   ebx,eax
4068
     shl   ebx,4
4069
     add   ebx,RESERVED_PORTS
4070
     cmp   ecx,[ebx+8]
75 diamond 4071
     ja    rpal4
1306 Lrz 4072
     cmp   edx,[ebx+4]
1 ha 4073
     jae   rpal1
4074
;     jb    rpal4
4075
;     jmp   rpal1
465 serge 4076
 rpal4:
1306 Lrz 4077
     dec   eax
1 ha 4078
     jnz   rpal3
4079
     jmp   rpal2
4080
   rpal1:
1306 Lrz 4081
;     popad
4082
;     mov   eax,1
4083
     xor    eax,eax
4084
     inc    eax
1 ha 4085
     ret
4086
   rpal2:
1306 Lrz 4087
;     popad
1 ha 4088
     ; enable port access at port IO map
1306 Lrz 4089
	cli
4090
	pushad                        ; start enable io map
1 ha 4091
 
1306 Lrz 4092
	cmp   edx,65536 ;16384
4093
	jae   no_unmask_io ; jge
4094
	mov   eax,ecx
4095
;	push	ebp
4096
	xor	ebp,ebp                ; enable - eax = port
4097
new_port_access:
4098
;     pushad
4099
	call	set_io_access_rights
4100
;     popad
1 ha 4101
     inc   eax
1306 Lrz 4102
     cmp   eax,edx
1 ha 4103
     jbe   new_port_access
1306 Lrz 4104
;	pop	ebp
4105
no_unmask_io:
4106
	popad                         ; end enable io map
1 ha 4107
     sti
4108
 
1306 Lrz 4109
     mov   eax,[RESERVED_PORTS]
4110
     add   eax,1
4111
     mov   [RESERVED_PORTS],eax
4112
     shl   eax,4
4113
     add   eax,RESERVED_PORTS
4114
     mov   ebx,[TASK_BASE]
4115
     mov   ebx,[ebx+TASKDATA.pid]
4116
     mov   [eax],ebx
4117
     mov   [eax+4],ecx
4118
     mov   [eax+8],edx
1 ha 4119
 
4120
     xor   eax, eax
4121
     ret
4122
 
4123
free_port_area:
4124
 
1306 Lrz 4125
;     pushad
4126
     mov   eax,[RESERVED_PORTS]     ; no reserved areas ?
4127
     test  eax,eax
4128
     jz    frpal2
4129
     mov   ebx,[TASK_BASE]
4130
     mov   ebx,[ebx+TASKDATA.pid]
1 ha 4131
   frpal3:
1306 Lrz 4132
     mov   edi,eax
1 ha 4133
     shl   edi,4
381 serge 4134
     add   edi,RESERVED_PORTS
1306 Lrz 4135
     cmp   ebx,[edi]
1 ha 4136
     jne   frpal4
1306 Lrz 4137
     cmp   ecx,[edi+4]
1 ha 4138
     jne   frpal4
1306 Lrz 4139
     cmp   edx,[edi+8]
1 ha 4140
     jne   frpal4
4141
     jmp   frpal1
4142
   frpal4:
1306 Lrz 4143
     dec   eax
1 ha 4144
     jnz   frpal3
4145
   frpal2:
1306 Lrz 4146
;     popad
4147
     inc   eax
1 ha 4148
     ret
4149
   frpal1:
1306 Lrz 4150
	push	ecx
4151
	mov   ecx,256
4152
	sub   ecx,eax
4153
	shl   ecx,4
4154
	mov   esi,edi
4155
	add   esi,16
4156
	cld
4157
	rep   movsb
1 ha 4158
 
1306 Lrz 4159
	dec   dword [RESERVED_PORTS]
4160
;popad
4161
;disable port access at port IO map
1 ha 4162
 
1306 Lrz 4163
;     pushad                        ; start disable io map
4164
     pop	eax	;start port
4165
     cmp   edx,65536 ;16384
1 ha 4166
     jge   no_mask_io
4167
 
1306 Lrz 4168
;     mov   eax,ecx
4169
	xor	ebp,ebp
4170
	inc	ebp
4171
new_port_access_disable:
4172
;     pushad
4173
;     mov   ebp,1                  ; disable - eax = port
1 ha 4174
     call  set_io_access_rights
1306 Lrz 4175
;     popad
1 ha 4176
     inc   eax
1306 Lrz 4177
     cmp   eax,edx
1 ha 4178
     jbe   new_port_access_disable
1306 Lrz 4179
no_mask_io:
4180
;     popad                         ; end disable io map
1 ha 4181
     xor   eax, eax
4182
     ret
4183
 
4184
 
4185
reserve_free_irq:
4186
 
765 Rus 4187
     xor   esi, esi
4188
     inc   esi
4189
     cmp   ecx, 16
4190
     jae   ril1
1 ha 4191
 
769 Rus 4192
     push  ecx
765 Rus 4193
     lea   ecx, [irq_owner + 4 * ecx]
4194
     mov   edx, [ecx]
4195
     mov   eax, [TASK_BASE]
4196
     mov   edi, [eax + TASKDATA.pid]
769 Rus 4197
     pop   eax
765 Rus 4198
     dec   ebx
4199
     jnz   reserve_irq
1 ha 4200
 
765 Rus 4201
     cmp   edx, edi
4202
     jne   ril1
4203
     dec   esi
4204
     mov   [ecx], esi
4205
 
4206
     jmp   ril1
4207
 
1 ha 4208
  reserve_irq:
4209
 
765 Rus 4210
     cmp   dword [ecx], 0
4211
     jne   ril1
1 ha 4212
 
769 Rus 4213
     mov   ebx, [f_irqs + 4 * eax]
4214
 
774 Rus 4215
     stdcall attach_int_handler, eax, ebx, dword 0
769 Rus 4216
 
765 Rus 4217
     mov   [ecx], edi
769 Rus 4218
 
765 Rus 4219
     dec   esi
1 ha 4220
   ril1:
765 Rus 4221
     mov   [esp+32], esi ; return in eax
1 ha 4222
     ret
4223
 
769 Rus 4224
iglobal
4225
f_irqs:
4226
     dd 0x0
4227
     dd 0x0
4228
     dd p_irq2
4229
     dd p_irq3
4230
     dd p_irq4
4231
     dd p_irq5
4232
     dd p_irq6
4233
     dd p_irq7
4234
     dd p_irq8
4235
     dd p_irq9
4236
     dd p_irq10
4237
     dd p_irq11
4238
     dd 0x0
4239
     dd 0x0
4240
     dd p_irq14
4241
     dd p_irq15
4242
 
4243
endg
4244
 
1 ha 4245
drawbackground:
33 mario79 4246
       inc   [mouse_pause]
381 serge 4247
       cmp   [SCR_MODE],word 0x12
117 mario79 4248
       je   dbrv20
1 ha 4249
     dbrv12:
381 serge 4250
       cmp  [SCR_MODE],word 0100000000000000b
1 ha 4251
       jge  dbrv20
381 serge 4252
       cmp  [SCR_MODE],word 0x13
1 ha 4253
       je   dbrv20
4254
       call  vesa12_drawbackground
33 mario79 4255
       dec   [mouse_pause]
36 mario79 4256
       call   [draw_pointer]
1 ha 4257
       ret
4258
     dbrv20:
527 diamond 4259
       cmp   [BgrDrawMode],dword 1
1 ha 4260
       jne   bgrstr
4261
       call  vesa20_drawbackground_tiled
33 mario79 4262
       dec   [mouse_pause]
36 mario79 4263
       call   [draw_pointer]
1 ha 4264
       ret
4265
     bgrstr:
4266
       call  vesa20_drawbackground_stretch
33 mario79 4267
       dec   [mouse_pause]
36 mario79 4268
       call   [draw_pointer]
1 ha 4269
       ret
4270
 
75 diamond 4271
align 4
1 ha 4272
 
1055 Galkov 4273
syscall_putimage:                       ; PutImage
1 ha 4274
sys_putimage:
53 mikedld 4275
     test  ecx,0x80008000
4276
     jnz   .exit
4277
     test  ecx,0x0000FFFF
4278
     jz    .exit
4279
     test  ecx,0xFFFF0000
4280
     jnz   @f
4281
  .exit:
4282
     ret
4283
 @@:
1055 Galkov 4284
        mov     edi,[current_slot]
4285
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4286
        rol     edx,16
4287
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4288
        rol     edx,16
114 mikedld 4289
  .forced:
1055 Galkov 4290
        push    ebp esi 0
4291
        mov     ebp, putimage_get24bpp
4292
        mov     esi, putimage_init24bpp
283 diamond 4293
sys_putimage_bpp:
4294
;        call    [disable_mouse] ; this will be done in xxx_putimage
117 mario79 4295
;        mov     eax, vga_putimage
1055 Galkov 4296
        cmp     [SCR_MODE], word 0x12
4297
        jz      @f   ;.doit
4298
        mov     eax, vesa12_putimage
4299
        cmp     [SCR_MODE], word 0100000000000000b
4300
        jae     @f
4301
        cmp     [SCR_MODE], word 0x13
4302
        jnz     .doit
75 diamond 4303
@@:
1055 Galkov 4304
        mov     eax, vesa20_putimage
75 diamond 4305
.doit:
1055 Galkov 4306
        inc     [mouse_pause]
4307
        call    eax
4308
        dec     [mouse_pause]
4309
        pop     ebp esi ebp
4310
        jmp     [draw_pointer]
1 ha 4311
 
283 diamond 4312
syscall_putimage_palette:
1055 Galkov 4313
        mov     edi, esi
4314
        mov     esi, edx
4315
        mov     edx, ecx
4316
        mov     ecx, ebx
4317
        mov     ebx, eax
283 diamond 4318
sys_putimage_palette:
4319
; ebx = pointer to image
4320
; ecx = [xsize]*65536 + [ysize]
4321
; edx = [xstart]*65536 + [ystart]
314 diamond 4322
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4323
; edi = pointer to palette
314 diamond 4324
; ebp = row delta
1055 Galkov 4325
        mov     eax, [CURRENT_TASK]
4326
        shl     eax, 8
4327
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4328
        rol     edx, 16
4329
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4330
        rol     edx, 16
283 diamond 4331
.forced:
1055 Galkov 4332
        cmp     esi, 1
4333
        jnz     @f
4334
        push    edi
4335
        mov     eax, [edi+4]
4336
        sub     eax, [edi]
4337
        push    eax
4338
        push    dword [edi]
4339
        push    0ffffff80h
4340
        mov     edi, esp
4341
        call    put_mono_image
4342
        add     esp, 12
4343
        pop     edi
4344
        ret
911 diamond 4345
@@:
1055 Galkov 4346
        cmp     esi, 2
4347
        jnz     @f
4348
        push    edi
4349
        push    0ffffff80h
4350
        mov     edi, esp
4351
        call    put_2bit_image
4352
        pop     eax
4353
        pop     edi
4354
        ret
911 diamond 4355
@@:
1055 Galkov 4356
        cmp     esi, 4
4357
        jnz     @f
4358
        push    edi
4359
        push    0ffffff80h
4360
        mov     edi, esp
4361
        call    put_4bit_image
4362
        pop     eax
4363
        pop     edi
4364
        ret
314 diamond 4365
@@:
1055 Galkov 4366
        push    ebp esi ebp
4367
        cmp     esi, 8
4368
        jnz     @f
4369
        mov     ebp, putimage_get8bpp
4370
        mov     esi, putimage_init8bpp
4371
        jmp     sys_putimage_bpp
918 diamond 4372
@@:
1055 Galkov 4373
        cmp     esi, 15
4374
        jnz     @f
4375
        mov     ebp, putimage_get15bpp
4376
        mov     esi, putimage_init15bpp
4377
        jmp     sys_putimage_bpp
906 diamond 4378
@@:
1055 Galkov 4379
        cmp     esi, 16
4380
        jnz     @f
4381
        mov     ebp, putimage_get16bpp
4382
        mov     esi, putimage_init16bpp
4383
        jmp     sys_putimage_bpp
842 diamond 4384
@@:
1055 Galkov 4385
        cmp     esi, 24
4386
        jnz     @f
4387
        mov     ebp, putimage_get24bpp
4388
        mov     esi, putimage_init24bpp
4389
        jmp     sys_putimage_bpp
314 diamond 4390
@@:
1055 Galkov 4391
        cmp     esi, 32
4392
        jnz     @f
4393
        mov     ebp, putimage_get32bpp
4394
        mov     esi, putimage_init32bpp
4395
        jmp     sys_putimage_bpp
314 diamond 4396
@@:
1055 Galkov 4397
        pop     ebp esi ebp
4398
        ret
283 diamond 4399
 
911 diamond 4400
put_mono_image:
1055 Galkov 4401
        push    ebp esi ebp
4402
        mov     ebp, putimage_get1bpp
4403
        mov     esi, putimage_init1bpp
4404
        jmp     sys_putimage_bpp
918 diamond 4405
put_2bit_image:
1055 Galkov 4406
        push    ebp esi ebp
4407
        mov     ebp, putimage_get2bpp
4408
        mov     esi, putimage_init2bpp
4409
        jmp     sys_putimage_bpp
911 diamond 4410
put_4bit_image:
1055 Galkov 4411
        push    ebp esi ebp
4412
        mov     ebp, putimage_get4bpp
4413
        mov     esi, putimage_init4bpp
4414
        jmp     sys_putimage_bpp
911 diamond 4415
 
283 diamond 4416
putimage_init24bpp:
1055 Galkov 4417
        lea     eax, [eax*3]
283 diamond 4418
putimage_init8bpp:
1055 Galkov 4419
        ret
283 diamond 4420
 
911 diamond 4421
align 16
283 diamond 4422
putimage_get24bpp:
1055 Galkov 4423
        movzx   eax, byte [esi+2]
4424
        shl     eax, 16
4425
        mov     ax, [esi]
4426
        add     esi, 3
4427
        ret     4
911 diamond 4428
align 16
283 diamond 4429
putimage_get8bpp:
1055 Galkov 4430
        movzx   eax, byte [esi]
4431
        push    edx
4432
        mov     edx, [esp+8]
4433
        mov     eax, [edx+eax*4]
4434
        pop     edx
4435
        inc     esi
4436
        ret     4
283 diamond 4437
 
911 diamond 4438
putimage_init1bpp:
1055 Galkov 4439
        add     eax, ecx
4440
        push    ecx
4441
        add     eax, 7
4442
        add     ecx, 7
4443
        shr     eax, 3
4444
        shr     ecx, 3
4445
        sub     eax, ecx
4446
        pop     ecx
4447
        ret
911 diamond 4448
align 16
4449
putimage_get1bpp:
1055 Galkov 4450
        push    edx
4451
        mov     edx, [esp+8]
4452
        mov     al, [edx]
4453
        add     al, al
4454
        jnz     @f
4455
        lodsb
4456
        adc     al, al
911 diamond 4457
@@:
1055 Galkov 4458
        mov     [edx], al
4459
        sbb     eax, eax
4460
        and     eax, [edx+8]
4461
        add     eax, [edx+4]
4462
        pop     edx
4463
        ret     4
911 diamond 4464
 
918 diamond 4465
putimage_init2bpp:
1055 Galkov 4466
        add     eax, ecx
4467
        push    ecx
4468
        add     ecx, 3
4469
        add     eax, 3
4470
        shr     ecx, 2
4471
        shr     eax, 2
4472
        sub     eax, ecx
4473
        pop     ecx
4474
        ret
918 diamond 4475
align 16
4476
putimage_get2bpp:
1055 Galkov 4477
        push    edx
4478
        mov     edx, [esp+8]
4479
        mov     al, [edx]
4480
        mov     ah, al
4481
        shr     al, 6
4482
        shl     ah, 2
4483
        jnz     .nonewbyte
4484
        lodsb
4485
        mov     ah, al
4486
        shr     al, 6
4487
        shl     ah, 2
4488
        add     ah, 1
918 diamond 4489
.nonewbyte:
1055 Galkov 4490
        mov     [edx], ah
4491
        mov     edx, [edx+4]
4492
        movzx   eax, al
4493
        mov     eax, [edx+eax*4]
4494
        pop     edx
4495
        ret     4
918 diamond 4496
 
911 diamond 4497
putimage_init4bpp:
1055 Galkov 4498
        add     eax, ecx
4499
        push    ecx
4500
        add     ecx, 1
4501
        add     eax, 1
4502
        shr     ecx, 1
4503
        shr     eax, 1
4504
        sub     eax, ecx
4505
        pop     ecx
4506
        ret
911 diamond 4507
align 16
4508
putimage_get4bpp:
1055 Galkov 4509
        push    edx
4510
        mov     edx, [esp+8]
4511
        add     byte [edx], 80h
4512
        jc      @f
4513
        movzx   eax, byte [edx+1]
4514
        mov     edx, [edx+4]
4515
        and     eax, 0x0F
4516
        mov     eax, [edx+eax*4]
4517
        pop     edx
4518
        ret     4
911 diamond 4519
@@:
1055 Galkov 4520
        movzx   eax, byte [esi]
4521
        add     esi, 1
4522
        mov     [edx+1], al
4523
        shr     eax, 4
4524
        mov     edx, [edx+4]
4525
        mov     eax, [edx+eax*4]
4526
        pop     edx
4527
        ret     4
911 diamond 4528
 
314 diamond 4529
putimage_init32bpp:
1055 Galkov 4530
        shl     eax, 2
4531
        ret
911 diamond 4532
align 16
314 diamond 4533
putimage_get32bpp:
1055 Galkov 4534
        lodsd
4535
        ret     4
314 diamond 4536
 
906 diamond 4537
putimage_init15bpp:
911 diamond 4538
putimage_init16bpp:
1055 Galkov 4539
        add     eax, eax
4540
        ret
911 diamond 4541
align 16
906 diamond 4542
putimage_get15bpp:
842 diamond 4543
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
1055 Galkov 4544
        push    ecx edx
4545
        movzx   eax, word [esi]
4546
        add     esi, 2
4547
        mov     ecx, eax
4548
        mov     edx, eax
4549
        and     eax, 0x1F
4550
        and     ecx, 0x1F shl 5
4551
        and     edx, 0x1F shl 10
4552
        shl     eax, 3
4553
        shl     ecx, 6
4554
        shl     edx, 9
4555
        or      eax, ecx
4556
        or      eax, edx
4557
        pop     edx ecx
4558
        ret     4
906 diamond 4559
 
911 diamond 4560
align 16
906 diamond 4561
putimage_get16bpp:
4562
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
1055 Galkov 4563
        push    ecx edx
4564
        movzx   eax, word [esi]
4565
        add     esi, 2
4566
        mov     ecx, eax
4567
        mov     edx, eax
4568
        and     eax, 0x1F
4569
        and     ecx, 0x3F shl 5
4570
        and     edx, 0x1F shl 11
4571
        shl     eax, 3
4572
        shl     ecx, 5
4573
        shl     edx, 8
4574
        or      eax, ecx
4575
        or      eax, edx
4576
        pop     edx ecx
4577
        ret     4
842 diamond 4578
 
1 ha 4579
; eax x beginning
4580
; ebx y beginning
4581
; ecx x end
1055 Galkov 4582
        ; edx y end
1 ha 4583
; edi color
4584
 
4585
__sys_drawbar:
1055 Galkov 4586
        mov     esi,[current_slot]
4587
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4588
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4589
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4590
        add     edx,[esi+APPDATA.wnd_clientbox.top]
114 mikedld 4591
  .forced:
33 mario79 4592
    inc   [mouse_pause]
283 diamond 4593
;        call    [disable_mouse]
381 serge 4594
    cmp   [SCR_MODE],word 0x12
1055 Galkov 4595
    je   dbv20
1 ha 4596
   sdbv20:
381 serge 4597
    cmp  [SCR_MODE],word 0100000000000000b
1 ha 4598
    jge  dbv20
381 serge 4599
    cmp  [SCR_MODE],word 0x13
1055 Galkov 4600
    je   dbv20
1 ha 4601
    call vesa12_drawbar
33 mario79 4602
    dec   [mouse_pause]
36 mario79 4603
    call   [draw_pointer]
1 ha 4604
    ret
4605
  dbv20:
4606
    call vesa20_drawbar
33 mario79 4607
    dec   [mouse_pause]
36 mario79 4608
    call   [draw_pointer]
1 ha 4609
    ret
4610
 
4611
 
4612
 
4613
kb_read:
4614
 
1055 Galkov 4615
        push    ecx edx
1 ha 4616
 
1055 Galkov 4617
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4618
      kr_loop:
1055 Galkov 4619
        in      al,0x64
4620
        test    al,1
4621
        jnz     kr_ready
4622
        loop    kr_loop
4623
        mov     ah,1
4624
        jmp     kr_exit
1 ha 4625
      kr_ready:
1055 Galkov 4626
        push    ecx
4627
        mov     ecx,32
1 ha 4628
      kr_delay:
1055 Galkov 4629
        loop    kr_delay
4630
        pop     ecx
4631
        in      al,0x60
4632
        xor     ah,ah
1 ha 4633
      kr_exit:
4634
 
1055 Galkov 4635
        pop     edx ecx
1 ha 4636
 
1055 Galkov 4637
        ret
1 ha 4638
 
4639
 
4640
kb_write:
4641
 
1055 Galkov 4642
        push    ecx edx
1 ha 4643
 
1055 Galkov 4644
        mov     dl,al
265 diamond 4645
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4646
;      kw_loop1:
4647
;        in      al,0x64
4648
;        test    al,0x20
4649
;        jz      kw_ok1
4650
;        loop    kw_loop1
4651
;        mov     ah,1
4652
;        jmp     kw_exit
4653
;      kw_ok1:
1055 Galkov 4654
        in      al,0x60
4655
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4656
      kw_loop:
1055 Galkov 4657
        in      al,0x64
4658
        test    al,2
4659
        jz      kw_ok
4660
        loop    kw_loop
4661
        mov     ah,1
4662
        jmp     kw_exit
1 ha 4663
      kw_ok:
1055 Galkov 4664
        mov     al,dl
4665
        out     0x60,al
4666
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4667
      kw_loop3:
1055 Galkov 4668
        in      al,0x64
4669
        test    al,2
4670
        jz      kw_ok3
4671
        loop    kw_loop3
4672
        mov     ah,1
4673
        jmp     kw_exit
1 ha 4674
      kw_ok3:
1055 Galkov 4675
        mov     ah,8
1 ha 4676
      kw_loop4:
1055 Galkov 4677
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4678
      kw_loop5:
1055 Galkov 4679
        in      al,0x64
4680
        test    al,1
4681
        jnz     kw_ok4
4682
        loop    kw_loop5
4683
        dec     ah
4684
        jnz     kw_loop4
1 ha 4685
      kw_ok4:
1055 Galkov 4686
        xor     ah,ah
1 ha 4687
      kw_exit:
4688
 
1055 Galkov 4689
        pop     edx ecx
1 ha 4690
 
1055 Galkov 4691
        ret
1 ha 4692
 
4693
 
4694
kb_cmd:
4695
 
1055 Galkov 4696
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4697
      c_wait:
1055 Galkov 4698
        in      al,0x64
4699
        test    al,2
4700
        jz      c_send
4701
        loop    c_wait
4702
        jmp     c_error
1 ha 4703
      c_send:
1055 Galkov 4704
        mov     al,bl
4705
        out     0x64,al
4706
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4707
      c_accept:
1055 Galkov 4708
        in      al,0x64
4709
        test    al,2
4710
        jz      c_ok
4711
        loop    c_accept
1 ha 4712
      c_error:
1055 Galkov 4713
        mov     ah,1
4714
        jmp     c_exit
1 ha 4715
      c_ok:
1055 Galkov 4716
        xor     ah,ah
1 ha 4717
      c_exit:
1055 Galkov 4718
        ret
1 ha 4719
 
4720
 
4721
setmouse:  ; set mousepicture -pointer
1055 Galkov 4722
           ; ps2 mouse enable
1 ha 4723
 
381 serge 4724
     mov     [MOUSE_PICTURE],dword mousepointer
1 ha 4725
 
4726
     cli
4727
 
4728
     ret
4729
 
1055 Galkov 4730
if used _rdtsc
1 ha 4731
_rdtsc:
164 serge 4732
     bt [cpu_caps], CAPS_TSC
4733
     jnc ret_rdtsc
1 ha 4734
     rdtsc
4735
     ret
4736
   ret_rdtsc:
4737
     mov   edx,0xffffffff
4738
     mov   eax,0xffffffff
4739
     ret
1055 Galkov 4740
end if
1 ha 4741
 
4742
rerouteirqs:
4743
 
1055 Galkov 4744
        cli
1 ha 4745
 
1055 Galkov 4746
        mov     al,0x11         ;  icw4, edge triggered
4747
        out     0x20,al
4748
        call    pic_delay
4749
        out     0xA0,al
4750
        call    pic_delay
1 ha 4751
 
1055 Galkov 4752
        mov     al,0x20         ;  generate 0x20 +
4753
        out     0x21,al
4754
        call    pic_delay
4755
        mov     al,0x28         ;  generate 0x28 +
4756
        out     0xA1,al
4757
        call    pic_delay
1 ha 4758
 
1055 Galkov 4759
        mov     al,0x04         ;  slave at irq2
4760
        out     0x21,al
4761
        call    pic_delay
4762
        mov     al,0x02         ;  at irq9
4763
        out     0xA1,al
4764
        call    pic_delay
1 ha 4765
 
1055 Galkov 4766
        mov     al,0x01         ;  8086 mode
4767
        out     0x21,al
4768
        call    pic_delay
4769
        out     0xA1,al
4770
        call    pic_delay
1 ha 4771
 
1055 Galkov 4772
        mov     al,255          ; mask all irq's
4773
        out     0xA1,al
4774
        call    pic_delay
4775
        out     0x21,al
4776
        call    pic_delay
1 ha 4777
 
1055 Galkov 4778
        mov     ecx,0x1000
4779
        cld
4780
picl1:  call    pic_delay
4781
        loop    picl1
1 ha 4782
 
1055 Galkov 4783
        mov     al,255          ; mask all irq's
4784
        out     0xA1,al
4785
        call    pic_delay
4786
        out     0x21,al
4787
        call    pic_delay
1 ha 4788
 
1055 Galkov 4789
        cli
1 ha 4790
 
1055 Galkov 4791
        ret
1 ha 4792
 
4793
 
4794
pic_delay:
4795
 
1055 Galkov 4796
        jmp     pdl1
4797
pdl1:   ret
1 ha 4798
 
4799
 
4800
sys_msg_board_str:
4801
 
4802
     pushad
4803
   @@:
4804
     cmp    [esi],byte 0
4805
     je     @f
4806
     mov    eax,1
4807
     movzx  ebx,byte [esi]
4808
     call   sys_msg_board
4809
     inc    esi
4810
     jmp    @b
4811
   @@:
4812
     popad
4813
     ret
4814
 
709 diamond 4815
sys_msg_board_byte:
4816
; in: al = byte to display
4817
; out: nothing
4818
; destroys: nothing
1055 Galkov 4819
        pushad
4820
        mov     ecx, 2
4821
        shl     eax, 24
4822
        jmp     @f
709 diamond 4823
 
4824
sys_msg_board_word:
4825
; in: ax = word to display
4826
; out: nothing
4827
; destroys: nothing
1055 Galkov 4828
        pushad
4829
        mov     ecx, 4
4830
        shl     eax, 16
4831
        jmp     @f
709 diamond 4832
 
4833
sys_msg_board_dword:
4834
; in: eax = dword to display
4835
; out: nothing
4836
; destroys: nothing
1055 Galkov 4837
        pushad
4838
        mov     ecx, 8
709 diamond 4839
@@:
1055 Galkov 4840
        push    ecx
4841
        rol     eax, 4
4842
        push    eax
4843
        and     al, 0xF
4844
        cmp     al, 10
4845
        sbb     al, 69h
4846
        das
4847
        mov     bl, al
4848
        xor     eax, eax
4849
        inc     eax
4850
        call    sys_msg_board
4851
        pop     eax
4852
        pop     ecx
4853
        loop    @b
4854
        popad
4855
        ret
709 diamond 4856
 
1 ha 4857
uglobal
373 mikedld 4858
  msg_board_data: times 4096 db 0
1 ha 4859
  msg_board_count dd 0x0
4860
endg
4861
 
4862
sys_msg_board:
4863
 
4864
; eax=1 : write :  bl byte to write
4865
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4866
 
1055 Galkov 4867
        mov     ecx, [msg_board_count]
4868
        cmp     eax, 1
4869
        jne     .smbl1
1 ha 4870
 
1043 hidnplayr 4871
if defined debug_com_base
1 ha 4872
 
1055 Galkov 4873
        push    dx ax
1043 hidnplayr 4874
 
1055 Galkov 4875
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4876
        mov     dx, debug_com_base+5
4877
        in      al, dx
4878
        test    al, 1 shl 5
4879
        jz      @r
1043 hidnplayr 4880
 
1055 Galkov 4881
        mov     dx, debug_com_base      ; Output the byte
4882
        mov     al, bl
4883
        out     dx, al
1043 hidnplayr 4884
 
1055 Galkov 4885
        pop     ax dx
1043 hidnplayr 4886
 
4887
end if
4888
 
1055 Galkov 4889
        mov     [msg_board_data+ecx],bl
4890
        inc     ecx
4891
        and     ecx, 4095
4892
        mov     [msg_board_count], ecx
4893
        mov     [check_idle_semaphore], 5
4894
        ret
671 Ghost 4895
.smbl1:
1055 Galkov 4896
        cmp     eax, 2
4897
        jne     .smbl2
4898
        test    ecx, ecx
4899
        jz      .smbl21
4900
        mov     eax, msg_board_data+1
4901
        mov     ebx, msg_board_data
4902
        movzx   edx, byte [ebx]
4903
        call    memmove
4904
        dec     [msg_board_count]
4905
        mov     [esp + 36], edx ;eax
4906
        mov     [esp + 24], dword 1
4907
        ret
671 Ghost 4908
.smbl21:
1055 Galkov 4909
        mov     [esp+36], ecx
4910
        mov     [esp+24], ecx
671 Ghost 4911
.smbl2:
1055 Galkov 4912
        ret
1 ha 4913
 
4914
 
4915
 
4916
sys_process_def:
1055 Galkov 4917
        mov     edi, [CURRENT_TASK]
1 ha 4918
 
1055 Galkov 4919
        dec     eax             ; 1 = set keyboard mode
1 ha 4920
     jne   no_set_keyboard_setup
4921
 
4922
     shl   edi,8
380 serge 4923
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
1 ha 4924
 
4925
     ret
4926
 
4927
   no_set_keyboard_setup:
4928
 
1055 Galkov 4929
        dec     eax             ; 2 = get keyboard mode
1 ha 4930
     jne   no_get_keyboard_setup
4931
 
4932
     shl   edi,8
380 serge 4933
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
1 ha 4934
 
4935
     mov   [esp+36],eax
4936
 
4937
     ret
4938
 
4939
   no_get_keyboard_setup:
4940
 
1055 Galkov 4941
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4942
     jne   no_get_keyboard_cas
4943
 
4944
;     xor   eax,eax
4945
;     movzx eax,byte [shift]
4946
;     movzx ebx,byte [ctrl]
4947
;     shl   ebx,2
4948
;     add   eax,ebx
4949
;     movzx ebx,byte [alt]
4950
;     shl   ebx,3
4951
;     add   eax,ebx
4952
 
4953
 ;// mike.dld [
4954
     mov   eax, [kb_state]
4955
 ;// mike.dld ]
4956
 
4957
     mov   [esp+36],eax
4958
 
4959
     ret
4960
 
4961
   no_get_keyboard_cas:
4962
 
1055 Galkov 4963
        dec     eax
4964
        jnz     no_add_keyboard_hotkey
1 ha 4965
 
1055 Galkov 4966
        mov     eax, hotkey_list
92 diamond 4967
@@:
1055 Galkov 4968
        cmp     dword [eax+8], 0
4969
        jz      .found_free
4970
        add     eax, 16
4971
        cmp     eax, hotkey_list+16*256
4972
        jb      @b
4973
        mov     dword [esp+36], 1
4974
        ret
92 diamond 4975
.found_free:
1055 Galkov 4976
        mov     [eax+8], edi
4977
        mov     [eax+4], ecx
4978
        movzx   ebx, bl
4979
        lea     ebx, [hotkey_scancodes+ebx*4]
4980
        mov     ecx, [ebx]
4981
        mov     [eax], ecx
4982
        mov     [ebx], eax
4983
        mov     [eax+12], ebx
4984
        jecxz   @f
4985
        mov     [ecx+12], eax
92 diamond 4986
@@:
1055 Galkov 4987
        and     dword [esp+36], 0
4988
        ret
92 diamond 4989
 
4990
no_add_keyboard_hotkey:
4991
 
1055 Galkov 4992
        dec     eax
4993
        jnz     no_del_keyboard_hotkey
92 diamond 4994
 
1055 Galkov 4995
        movzx   ebx, bl
4996
        lea     ebx, [hotkey_scancodes+ebx*4]
4997
        mov     eax, [ebx]
92 diamond 4998
.scan:
1055 Galkov 4999
        test    eax, eax
5000
        jz      .notfound
5001
        cmp     [eax+8], edi
5002
        jnz     .next
5003
        cmp     [eax+4], ecx
5004
        jz      .found
92 diamond 5005
.next:
1055 Galkov 5006
        mov     eax, [eax]
5007
        jmp     .scan
92 diamond 5008
.notfound:
1055 Galkov 5009
        mov     dword [esp+36], 1
5010
        ret
92 diamond 5011
.found:
1055 Galkov 5012
        mov     ecx, [eax]
5013
        jecxz   @f
5014
        mov     edx, [eax+12]
5015
        mov     [ecx+12], edx
92 diamond 5016
@@:
1055 Galkov 5017
        mov     ecx, [eax+12]
5018
        mov     edx, [eax]
5019
        mov     [ecx], edx
5020
        xor     edx, edx
5021
        mov     [eax+4], edx
5022
        mov     [eax+8], edx
5023
        mov     [eax+12], edx
5024
        mov     [eax], edx
5025
        mov     [esp+36], edx
5026
        ret
92 diamond 5027
 
5028
no_del_keyboard_hotkey:
1 ha 5029
     ret
5030
 
5031
 
5032
align 4
5033
 
1055 Galkov 5034
sys_gs:                         ; direct screen access
1 ha 5035
 
1055 Galkov 5036
     cmp  eax,1                 ; resolution
1 ha 5037
     jne  no_gs1
753 serge 5038
     mov  eax,[Screen_Max_X]
1 ha 5039
     shl  eax,16
753 serge 5040
     mov  ax,[Screen_Max_Y]
1 ha 5041
     add  eax,0x00010001
5042
     mov  [esp+36],eax
5043
     ret
5044
   no_gs1:
5045
 
1055 Galkov 5046
     cmp   eax,2                ; bits per pixel
1 ha 5047
     jne   no_gs2
381 serge 5048
     movzx eax,byte [ScreenBPP]
1 ha 5049
     mov   [esp+36],eax
5050
     ret
5051
   no_gs2:
5052
 
1055 Galkov 5053
     cmp   eax,3                ; bytes per scanline
1 ha 5054
     jne   no_gs3
381 serge 5055
     mov   eax,[BytesPerScanLine]
1 ha 5056
     mov   [esp+36],eax
5057
     ret
5058
   no_gs3:
5059
 
1276 Lrz 5060
     or  [esp+36],dword -1
1 ha 5061
     ret
5062
 
5063
 
5064
align 4 ; PCI functions
5065
 
5066
sys_pci:
5067
 
5068
     call  pci_api
5069
     mov   [esp+36],eax
5070
     ret
5071
 
5072
 
5073
align 4  ;  system functions
5074
 
1055 Galkov 5075
syscall_setpixel:                       ; SetPixel
1 ha 5076
 
1055 Galkov 5077
        mov     eax, ebx
5078
        mov     ebx, ecx
5079
        mov     ecx, edx
5080
        mov     edx, [TASK_BASE]
5081
        add     eax, [edx-twdw+WDATA.box.left]
5082
        add     ebx, [edx-twdw+WDATA.box.top]
5083
        mov     edi, [current_slot]
5084
        add     eax, [edi+APPDATA.wnd_clientbox.left]
5085
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
5086
        xor     edi, edi ; no force
684 diamond 5087
;       mov     edi, 1
1300 serge 5088
        call    [_display.disable_mouse]
1055 Galkov 5089
        jmp     [putpixel]
1 ha 5090
 
5091
align 4
5092
 
1055 Galkov 5093
syscall_writetext:                      ; WriteText
1 ha 5094
 
1055 Galkov 5095
        mov   eax,[TASK_BASE]
5096
        mov   ebp,[eax-twdw+WDATA.box.left]
5097
        push  esi
5098
        mov   esi,[current_slot]
5099
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
5100
        shl   ebp,16
5101
        add   ebp,[eax-twdw+WDATA.box.top]
5102
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
5103
        pop   esi
5104
        add   ebx,ebp
5105
        mov   eax,edi
5106
        xor   edi,edi
5107
        jmp   dtext
1 ha 5108
 
5109
align 4
5110
 
1055 Galkov 5111
syscall_openramdiskfile:                ; OpenRamdiskFile
1 ha 5112
 
1055 Galkov 5113
        mov     eax, ebx
5114
        mov     ebx, ecx
5115
        mov     ecx, edx
5116
        mov     edx, esi
5117
        mov     esi, 12
5118
        call    fileread
5119
        mov     [esp+32], eax
5120
        ret
1 ha 5121
 
5122
align 4
5123
 
1055 Galkov 5124
syscall_drawrect:                       ; DrawRect
1 ha 5125
 
1055 Galkov 5126
        mov     edi, edx ; color + gradient
5127
        and     edi, 0x80FFFFFF
5128
        test    bx, bx  ; x.size
5129
        je      .drectr
5130
        test    cx, cx ; y.size
5131
        je      .drectr
1 ha 5132
 
1055 Galkov 5133
        mov     eax, ebx ; bad idea
5134
        mov     ebx, ecx
1 ha 5135
 
1055 Galkov 5136
        movzx   ecx, ax ; ecx - x.size
5137
        shr     eax, 16 ; eax - x.coord
5138
        movzx   edx, bx ; edx - y.size
5139
        shr     ebx, 16 ; ebx - y.coord
5140
        mov     esi, [current_slot]
1 ha 5141
 
1055 Galkov 5142
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5143
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5144
        add     ecx, eax
5145
        add     edx, ebx
5146
        jmp     [drawbar]
671 Ghost 5147
.drectr:
1055 Galkov 5148
        ret
1 ha 5149
 
5150
align 4
1055 Galkov 5151
syscall_getscreensize:                  ; GetScreenSize
5152
        mov     ax, [Screen_Max_X]
5153
        shl     eax, 16
5154
        mov     ax, [Screen_Max_Y]
5155
        mov     [esp + 32], eax
5156
        ret
1 ha 5157
 
671 Ghost 5158
align 4
5159
 
1055 Galkov 5160
syscall_cdaudio:                        ; CD
1 ha 5161
 
1290 Lrz 5162
        cmp     ebx, 4
1055 Galkov 5163
        jb      .audio
5164
        jz      .eject
1290 Lrz 5165
        cmp     ebx, 5
1055 Galkov 5166
        jnz     .ret
588 diamond 5167
.load:
1055 Galkov 5168
        call    .reserve
5169
        call    LoadMedium
1290 Lrz 5170
        ;call    .free
5171
		jmp		.free
5172
;        ret
588 diamond 5173
.eject:
1055 Galkov 5174
        call    .reserve
5175
        call    clear_CD_cache
5176
        call    allow_medium_removal
5177
        call    EjectMedium
1290 Lrz 5178
;        call    .free
5179
		jmp		.free
5180
;        ret
588 diamond 5181
.audio:
1 ha 5182
     call  sys_cd_audio
1290 Lrz 5183
     mov   [esp+36-4],eax
588 diamond 5184
.ret:
1 ha 5185
     ret
5186
 
588 diamond 5187
.reserve:
1055 Galkov 5188
        call    reserve_cd
1290 Lrz 5189
        mov     eax, ecx
1055 Galkov 5190
        shr     eax, 1
5191
        and     eax, 1
5192
        inc     eax
5193
        mov     [ChannelNumber], ax
1290 Lrz 5194
        mov     eax, ecx
1055 Galkov 5195
        and     eax, 1
5196
        mov     [DiskNumber], al
5197
        call    reserve_cd_channel
5198
        and     ebx, 3
5199
        inc     ebx
5200
        mov     [cdpos], ebx
5201
        add     ebx, ebx
5202
        mov     cl, 8
5203
        sub     cl, bl
5204
        mov     al, [DRIVE_DATA+1]
5205
        shr     al, cl
5206
        test    al, 2
1290 Lrz 5207
        jz      .free;.err
1055 Galkov 5208
        ret
588 diamond 5209
.free:
1055 Galkov 5210
        call    free_cd_channel
5211
        and     [cd_status], 0
5212
        ret
590 diamond 5213
.err:
1055 Galkov 5214
        call    .free
1290 Lrz 5215
;        pop     eax
1055 Galkov 5216
        ret
588 diamond 5217
 
1 ha 5218
align 4
5219
 
1055 Galkov 5220
syscall_getpixel:                       ; GetPixel
753 serge 5221
     mov   ecx, [Screen_Max_X]
1 ha 5222
     inc   ecx
671 Ghost 5223
     xor   edx, edx
5224
     mov   eax, ebx
1 ha 5225
     div   ecx
671 Ghost 5226
     mov   ebx, edx
5227
     xchg  eax, ebx
5228
     call  dword [GETPIXEL] ; eax - x, ebx - y
5229
     mov   [esp + 32], ecx
1 ha 5230
     ret
5231
 
921 mario79 5232
align 4
1 ha 5233
 
921 mario79 5234
syscall_getarea:
5235
;eax = 36
1055 Galkov 5236
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5237
;ecx = [size x]*65536 + [size y]
5238
;edx = [start x]*65536 + [start y]
921 mario79 5239
     pushad
1055 Galkov 5240
         inc   [mouse_pause]
927 mario79 5241
; Check of use of the hardware cursor.
1300 serge 5242
      cmp  [_display.disable_mouse],__sys_disable_mouse
1055 Galkov 5243
          jne  @f
927 mario79 5244
; Since the test for the coordinates of the mouse should not be used,
5245
; then use the call [disable_mouse] is not possible!
5246
      cmp  dword [MOUSE_VISIBLE],dword 0
5247
      jne  @f
5248
      pushf
5249
      cli
5250
      call draw_mouse_under
5251
      popf
5252
      mov  [MOUSE_VISIBLE],dword 1
5253
@@:
921 mario79 5254
     mov   edi,ebx
5255
     mov   eax,edx
5256
     shr   eax,16
5257
     mov   ebx,edx
5258
     and   ebx,0xffff
939 mario79 5259
     dec   eax
1055 Galkov 5260
           dec   ebx
921 mario79 5261
     ; eax - x, ebx - y
5262
     mov   edx,ecx
5263
 
5264
     shr   ecx,16
5265
     and   edx,0xffff
5266
     mov   esi,ecx
5267
     ; ecx - size x, edx - size y
1055 Galkov 5268
 
5269
         mov   ebp,edx
5270
         dec   ebp
927 mario79 5271
     lea   ebp,[ebp*3]
1055 Galkov 5272
 
5273
         imul  ebp,esi
5274
 
5275
         mov   esi,ecx
5276
         dec   esi
5277
         lea   esi,[esi*3]
5278
 
927 mario79 5279
     add   ebp,esi
5280
     add   ebp,edi
5281
 
5282
     add   ebx,edx
1055 Galkov 5283
 
921 mario79 5284
.start_y:
927 mario79 5285
     push  ecx edx
921 mario79 5286
.start_x:
927 mario79 5287
     push  eax ebx ecx
921 mario79 5288
     add   eax,ecx
927 mario79 5289
 
921 mario79 5290
     call  dword [GETPIXEL] ; eax - x, ebx - y
5291
 
927 mario79 5292
     mov   [ebp],cx
5293
     shr   ecx,16
5294
     mov   [ebp+2],cl
921 mario79 5295
 
1055 Galkov 5296
     pop   ecx ebx eax
927 mario79 5297
     sub   ebp,3
921 mario79 5298
     dec   ecx
5299
     jnz   .start_x
1055 Galkov 5300
         pop   edx ecx
5301
         dec   ebx
921 mario79 5302
     dec   edx
5303
     jnz   .start_y
1055 Galkov 5304
     dec        [mouse_pause]
927 mario79 5305
; Check of use of the hardware cursor.
1300 serge 5306
      cmp  [_display.disable_mouse],__sys_disable_mouse
1055 Galkov 5307
          jne  @f
5308
         call  [draw_pointer]
927 mario79 5309
@@:
921 mario79 5310
     popad
5311
     ret
5312
 
1 ha 5313
align 4
5314
 
1055 Galkov 5315
syscall_drawline:                       ; DrawLine
1 ha 5316
 
1055 Galkov 5317
        mov     edi, [TASK_BASE]
5318
        movzx   eax, word[edi-twdw+WDATA.box.left]
5319
        mov     ebp, eax
5320
        mov     esi, [current_slot]
5321
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5322
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
5323
        add     ebp,ebx
5324
        shl     eax, 16
5325
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5326
        add     eax, ebp
5327
        mov     ebp, ebx
5328
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5329
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5330
        add     ebp, ecx
5331
        shl     ebx, 16
5332
        xor     edi, edi
5333
        add     ebx, ebp
5334
        mov     ecx, edx
5335
        jmp     [draw_line]
1 ha 5336
 
5337
align 4
5338
 
1055 Galkov 5339
syscall_getirqowner:                    ; GetIrqOwner
742 Rus 5340
 
5341
     cmp   ebx,16
75 diamond 5342
     jae   .err
742 Rus 5343
 
774 Rus 5344
     cmp   [irq_rights + 4 * ebx], dword 2
5345
     je    .err
5346
 
742 Rus 5347
     mov   eax,[4 * ebx + irq_owner]
5348
     mov   [esp+32],eax
5349
 
1 ha 5350
     ret
75 diamond 5351
.err:
742 Rus 5352
     or    dword [esp+32], -1
75 diamond 5353
     ret
1 ha 5354
 
5355
align 4
5356
 
1055 Galkov 5357
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 5358
 
5359
     call  r_f_port_area
1306 Lrz 5360
     mov   [esp+32],eax
1 ha 5361
     ret
5362
 
5363
align 4
5364
 
1055 Galkov 5365
syscall_threads:                        ; CreateThreads
1369 Lrz 5366
; eax=1 create thread
5367
;
5368
;   ebx=thread start
5369
;   ecx=thread stack value
5370
;
5371
; on return : eax = pid
1 ha 5372
 
1369 Lrz 5373
     call  new_sys_threads
5374
 
5375
     mov   [esp+32],eax
1 ha 5376
     ret
5377
 
5378
align 4
5379
 
1055 Galkov 5380
read_from_hd:                           ; Read from hd - fn not in use
1 ha 5381
 
379 serge 5382
     mov   edi,[TASK_BASE]
115 poddubny 5383
     add   edi,TASKDATA.mem_start
1 ha 5384
     add   eax,[edi]
5385
     add   ecx,[edi]
5386
     add   edx,[edi]
5387
     call  file_read
5388
 
5389
     mov   [esp+36],eax
5390
     mov   [esp+24],ebx
5391
 
5392
     ret
5393
 
375 Ghost 5394
paleholder:
1055 Galkov 5395
        ret
378 serge 5396
 
757 serge 5397
align 4
5398
set_screen:
1055 Galkov 5399
        cmp eax, [Screen_Max_X]
5400
        jne .set
709 diamond 5401
 
1055 Galkov 5402
        cmp edx, [Screen_Max_Y]
5403
        jne .set
5404
        ret
757 serge 5405
.set:
1055 Galkov 5406
        pushfd
5407
        cli
757 serge 5408
 
1055 Galkov 5409
        mov [Screen_Max_X], eax
5410
        mov [Screen_Max_Y], edx
1300 serge 5411
        mov [BytesPerScanLine], ecx
757 serge 5412
 
1055 Galkov 5413
        mov [screen_workarea.right],eax
5414
        mov [screen_workarea.bottom], edx
1300 serge 5415
 
1055 Galkov 5416
        push ebx
5417
        push esi
5418
        push edi
1300 serge 5419
 
5420
        pushad
5421
 
5422
        stdcall kernel_free, [_WinMapAddress]
5423
 
5424
        mov eax, [_display.width]
5425
        mul [_display.height]
5426
        mov [_WinMapSize], eax
5427
 
5428
        stdcall kernel_alloc, eax
5429
        mov [_WinMapAddress], eax
5430
        test eax, eax
5431
        jz .epic_fail
5432
 
5433
        popad
5434
 
1055 Galkov 5435
        call    repos_windows
1300 serge 5436
        xor eax, eax
5437
        xor ebx, ebx
1055 Galkov 5438
        mov     ecx, [Screen_Max_X]
5439
        mov     edx, [Screen_Max_Y]
5440
        call    calculatescreen
5441
        pop edi
5442
        pop esi
5443
        pop ebx
757 serge 5444
 
1055 Galkov 5445
        popfd
5446
        ret
757 serge 5447
 
1300 serge 5448
.epic_fail:
5449
        hlt                     ; Houston, we've had a problem
5450
 
76 mario79 5451
; --------------- APM ---------------------
1330 Lrz 5452
uglobal
5453
apm_entry	dp	0
5454
apm_vf		dd	0
5455
endg
5456
 
1 ha 5457
align 4
76 mario79 5458
sys_apm:
1330 Lrz 5459
	xor	eax,eax
5460
	cmp	word [apm_vf], ax	; Check APM BIOS enable
5461
	jne	@f
5462
	inc	eax
5463
	or	dword [esp + 44], eax	; error
5464
	add	eax,7
5465
	mov	dword [esp + 32], eax   ; 32-bit protected-mode interface not supported
5466
	ret
164 serge 5467
 
465 serge 5468
@@:
1330 Lrz 5469
;	xchg    eax, ecx
5470
;	xchg    ebx, ecx
164 serge 5471
 
1330 Lrz 5472
	cmp	dx, 3
5473
	ja	@f
5474
	and	[esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
5475
	mov	eax,[apm_vf]
5476
	mov	[esp + 32], eax
5477
	shr	eax, 16
5478
	mov	[esp + 28], eax
5479
	ret
78 diamond 5480
 
465 serge 5481
@@:
5482
 
1330 Lrz 5483
	mov	esi,[master_tab+(OS_BASE shr 20)]
5484
	xchg	[master_tab], esi
5485
	push	esi
5486
	mov 	edi, cr3
5487
	mov 	cr3, edi		;flush TLB
465 serge 5488
 
1330 Lrz 5489
	call    pword [apm_entry]	;call APM BIOS
465 serge 5490
 
1330 Lrz 5491
	xchg 	eax, [esp]
5492
	mov 	[master_tab], eax
5493
	mov 	eax, cr3
5494
	mov 	cr3, eax
5495
	pop eax
465 serge 5496
 
1330 Lrz 5497
	mov	[esp + 4 ], edi
5498
	mov	[esp + 8], esi
5499
	mov	[esp + 20], ebx
5500
	mov	[esp + 24], edx
5501
	mov	[esp + 28], ecx
5502
	mov	[esp + 32], eax
5503
	setc	al
5504
	and	[esp + 44], byte 0xfe
5505
	or	[esp + 44], al
5506
	ret
76 mario79 5507
; -----------------------------------------
1 ha 5508
 
76 mario79 5509
align 4
5510
 
1055 Galkov 5511
undefined_syscall:                      ; Undefined system call
671 Ghost 5512
     mov   [esp + 32], dword -1
1 ha 5513
     ret
5514
 
465 serge 5515
align 4
1055 Galkov 5516
system_shutdown:          ; shut down the system
1 ha 5517
 
1055 Galkov 5518
           cmp byte [BOOT_VAR+0x9030], 1
5519
           jne @F
5520
           ret
465 serge 5521
@@:
1055 Galkov 5522
           call stop_all_services
5523
           push 3                ; stop playing cd
5524
           pop  eax
5525
           call sys_cd_audio
1 ha 5526
 
465 serge 5527
yes_shutdown_param:
1055 Galkov 5528
           cli
1 ha 5529
 
1055 Galkov 5530
           mov  eax, kernel_file ; load kernel.mnt to 0x7000:0
5531
           push 12
5532
           pop  esi
5533
           xor  ebx,ebx
5534
           or   ecx,-1
5535
           mov  edx, OS_BASE+0x70000
5536
           call fileread
1 ha 5537
 
1055 Galkov 5538
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5539
           mov  edi,OS_BASE+0x40000
5540
           mov  ecx,1000
5541
           rep  movsb
1 ha 5542
 
1055 Galkov 5543
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5544
           mov  edi, OS_BASE
5545
           mov  ecx,0x10000/4
5546
           cld
5547
           rep movsd
1 ha 5548
 
1055 Galkov 5549
           call restorefatchain
1 ha 5550
 
1055 Galkov 5551
           mov al, 0xFF
5552
           out 0x21, al
5553
           out 0xA1, al
1 ha 5554
 
1085 diamond 5555
if 0
1055 Galkov 5556
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5557
           mov  word [OS_BASE+0x467+2],0x1000
1 ha 5558
 
1055 Galkov 5559
           mov  al,0x0F
5560
           out  0x70,al
5561
           mov  al,0x05
5562
           out  0x71,al
1 ha 5563
 
1055 Galkov 5564
           mov  al,0xFE
5565
           out  0x64,al
709 diamond 5566
 
1055 Galkov 5567
           hlt
1085 diamond 5568
           jmp $-1
1 ha 5569
 
709 diamond 5570
else
1055 Galkov 5571
        cmp     byte [OS_BASE + 0x9030], 2
5572
        jnz     no_acpi_power_off
1 ha 5573
 
709 diamond 5574
; scan for RSDP
5575
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
1055 Galkov 5576
        movzx   eax, word [OS_BASE + 0x40E]
5577
        shl     eax, 4
5578
        jz      @f
5579
        mov     ecx, 1024/16
5580
        call    scan_rsdp
5581
        jnc     .rsdp_found
709 diamond 5582
@@:
5583
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
1055 Galkov 5584
        mov     eax, 0xE0000
5585
        mov     ecx, 0x2000
5586
        call    scan_rsdp
5587
        jc      no_acpi_power_off
709 diamond 5588
.rsdp_found:
1055 Galkov 5589
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
5590
        mov     ebp, [ipc_tmp]
5591
        stdcall map_page, ebp, esi, PG_MAP
5592
        lea     eax, [esi+1000h]
5593
        lea     edx, [ebp+1000h]
5594
        stdcall map_page, edx, eax, PG_MAP
5595
        and     esi, 0xFFF
5596
        add     esi, ebp
5597
        cmp     dword [esi], 'RSDT'
5598
        jnz     no_acpi_power_off
5599
        mov     ecx, [esi+4]
5600
        sub     ecx, 24h
5601
        jbe     no_acpi_power_off
5602
        shr     ecx, 2
5603
        add     esi, 24h
709 diamond 5604
.scan_fadt:
1055 Galkov 5605
        lodsd
5606
        mov     ebx, eax
5607
        lea     eax, [ebp+2000h]
5608
        stdcall map_page, eax, ebx, PG_MAP
5609
        lea     eax, [ebp+3000h]
5610
        add     ebx, 0x1000
5611
        stdcall map_page, eax, ebx, PG_MAP
5612
        and     ebx, 0xFFF
5613
        lea     ebx, [ebx+ebp+2000h]
5614
        cmp     dword [ebx], 'FACP'
5615
        jz      .fadt_found
5616
        loop    .scan_fadt
5617
        jmp     no_acpi_power_off
709 diamond 5618
.fadt_found:
5619
; ebx is linear address of FADT
1085 diamond 5620
        mov     edi, [ebx+40] ; physical address of the DSDT
5621
        lea     eax, [ebp+4000h]
5622
        stdcall map_page, eax, edi, PG_MAP
5623
        lea     eax, [ebp+5000h]
5624
        lea     esi, [edi+0x1000]
5625
        stdcall map_page, eax, esi, PG_MAP
5626
        and     esi, 0xFFF
5627
        sub     edi, esi
5628
        cmp     dword [esi+ebp+4000h], 'DSDT'
5629
        jnz     no_acpi_power_off
5630
        mov     eax, [esi+ebp+4004h] ; DSDT length
5631
        sub     eax, 36+4
5632
        jbe     no_acpi_power_off
5633
        add     esi, 36
5634
.scan_dsdt:
5635
        cmp     dword [esi+ebp+4000h], '_S5_'
5636
        jnz     .scan_dsdt_cont
5637
        cmp     byte [esi+ebp+4000h+4], 12h ; DefPackage opcode
5638
        jnz     .scan_dsdt_cont
5639
        mov     dl, [esi+ebp+4000h+6]
5640
        cmp     dl, 4 ; _S5_ package must contain 4 bytes
5641
                      ; ...in theory; in practice, VirtualBox has 2 bytes
5642
        ja      .scan_dsdt_cont
5643
        cmp     dl, 1
5644
        jb      .scan_dsdt_cont
5645
        lea     esi, [esi+ebp+4000h+7]
5646
        xor     ecx, ecx
5647
        cmp     byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx
5648
        jz      @f
5649
        cmp     byte [esi], 0xA
5650
        jnz     no_acpi_power_off
5651
        inc     esi
5652
        mov     cl, [esi]
5653
@@:
5654
        inc     esi
5655
        cmp     dl, 2
5656
        jb      @f
5657
        cmp     byte [esi], 0
5658
        jz      @f
5659
        cmp     byte [esi], 0xA
5660
        jnz     no_acpi_power_off
5661
        inc     esi
5662
        mov     ch, [esi]
5663
@@:
5664
        jmp     do_acpi_power_off
5665
.scan_dsdt_cont:
5666
        inc     esi
5667
        cmp     esi, 0x1000
5668
        jb      @f
5669
        sub     esi, 0x1000
5670
        add     edi, 0x1000
5671
        push    eax
5672
        lea     eax, [ebp+4000h]
5673
        stdcall map_page, eax, edi, PG_MAP
5674
        push    PG_MAP
5675
        lea     eax, [edi+1000h]
5676
        push    eax
5677
        lea     eax, [ebp+5000h]
5678
        push    eax
5679
        stdcall map_page
5680
        pop     eax
5681
@@:
5682
        dec     eax
5683
        jnz     .scan_dsdt
5684
        jmp     no_acpi_power_off
5685
do_acpi_power_off:
1055 Galkov 5686
        mov     edx, [ebx+48]
5687
        test    edx, edx
5688
        jz      .nosmi
5689
        mov     al, [ebx+52]
5690
        out     dx, al
5691
        mov     edx, [ebx+64]
709 diamond 5692
@@:
1055 Galkov 5693
        in      ax, dx
5694
        test    al, 1
5695
        jz      @b
709 diamond 5696
.nosmi:
1085 diamond 5697
        and     cx, 0x0707
5698
        shl     cx, 2
5699
        or      cx, 0x2020
1055 Galkov 5700
        mov     edx, [ebx+64]
5701
        in      ax, dx
5702
        and     ax, 203h
1085 diamond 5703
        or      ah, cl
1055 Galkov 5704
        out     dx, ax
5705
        mov     edx, [ebx+68]
5706
        test    edx, edx
5707
        jz      @f
5708
        in      ax, dx
5709
        and     ax, 203h
1085 diamond 5710
        or      ah, ch
1055 Galkov 5711
        out     dx, ax
709 diamond 5712
@@:
1055 Galkov 5713
        jmp     $
709 diamond 5714
 
5715
 
5716
no_acpi_power_off:
1055 Galkov 5717
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5718
           mov  word [OS_BASE+0x467+2],0x1000
709 diamond 5719
 
1055 Galkov 5720
           mov  al,0x0F
5721
           out  0x70,al
5722
           mov  al,0x05
5723
           out  0x71,al
709 diamond 5724
 
1055 Galkov 5725
           mov  al,0xFE
5726
           out  0x64,al
709 diamond 5727
 
1055 Galkov 5728
           hlt
1085 diamond 5729
           jmp $-1
709 diamond 5730
 
5731
scan_rsdp:
1055 Galkov 5732
        add     eax, OS_BASE
709 diamond 5733
.s:
1055 Galkov 5734
        cmp     dword [eax], 'RSD '
5735
        jnz     .n
5736
        cmp     dword [eax+4], 'PTR '
5737
        jnz     .n
5738
        xor     edx, edx
5739
        xor     esi, esi
709 diamond 5740
@@:
1055 Galkov 5741
        add     dl, [eax+esi]
5742
        inc     esi
5743
        cmp     esi, 20
5744
        jnz     @b
5745
        test    dl, dl
5746
        jz      .ok
709 diamond 5747
.n:
1055 Galkov 5748
        add     eax, 10h
5749
        loop    .s
5750
        stc
709 diamond 5751
.ok:
1055 Galkov 5752
        ret
709 diamond 5753
end if
5754
 
465 serge 5755
include "data32.inc"
1 ha 5756
 
465 serge 5757
__REV__ = __REV
1 ha 5758
 
5759
uglobals_size = $ - endofcode
41 mikedld 5760
diff16 "end of kernel code",0,$