Subversion Repositories Kolibri OS

Rev

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