Subversion Repositories Kolibri OS

Rev

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

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