Subversion Repositories Kolibri OS

Rev

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