Subversion Repositories Kolibri OS

Rev

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

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