Subversion Repositories Kolibri OS

Rev

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

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