Subversion Repositories Kolibri OS

Rev

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

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