Subversion Repositories Kolibri OS

Rev

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