Subversion Repositories Kolibri OS

Rev

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