Subversion Repositories Kolibri OS

Rev

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

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