Subversion Repositories Kolibri OS

Rev

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