Subversion Repositories Kolibri OS

Rev

Rev 160 | Rev 164 | 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
163 diamond 2752
    mov   [edi-twdw+WDATA.fl_redraw], 0
1 ha 2753
 
2754
    call  sys_window_mouse
2755
 
2756
    ret
2757
 
2758
  srl1:
2759
 
2760
    ret
2761
 
2762
 
2763
sys_drawwindow:
2764
 
2765
    mov   edi,ecx
2766
    shr   edi,16+8
2767
    and   edi,15
2768
 
2769
    cmp   edi,0   ; type I    - original style
2770
    jne   nosyswI
33 mario79 2771
    inc   [mouse_pause]
36 mario79 2772
    call  [disable_mouse]
1 ha 2773
    call  sys_set_window
36 mario79 2774
    call  [disable_mouse]
1 ha 2775
    call  drawwindow_I
114 mikedld 2776
    ;dec   [mouse_pause]
2777
    ;call   [draw_pointer]
2778
    ;ret
2779
    jmp   draw_window_caption.2
1 ha 2780
  nosyswI:
2781
 
2782
    cmp   edi,1   ; type II   - only reserve area, no draw
2783
    jne   nosyswII
33 mario79 2784
    inc   [mouse_pause]
36 mario79 2785
    call  [disable_mouse]
1 ha 2786
    call  sys_set_window
36 mario79 2787
    call  [disable_mouse]
1 ha 2788
    call  sys_window_mouse
33 mario79 2789
    dec   [mouse_pause]
36 mario79 2790
    call   [draw_pointer]
1 ha 2791
    ret
2792
  nosyswII:
2793
 
2794
    cmp   edi,2   ; type III  - new style
2795
    jne   nosyswIII
33 mario79 2796
    inc   [mouse_pause]
36 mario79 2797
    call  [disable_mouse]
1 ha 2798
    call  sys_set_window
36 mario79 2799
    call  [disable_mouse]
1 ha 2800
    call  drawwindow_III
114 mikedld 2801
    ;dec   [mouse_pause]
2802
    ;call   [draw_pointer]
2803
    ;ret
2804
    jmp   draw_window_caption.2
1 ha 2805
  nosyswIII:
2806
 
2807
    cmp   edi,3   ; type IV - skinned window
2808
    jne   nosyswIV
33 mario79 2809
 
102 poddubny 2810
    ; parameter for drawwindow_IV
35 halyavin 2811
    push  0
102 poddubny 2812
    mov   edi, [0x3004]
2813
    movzx edi, word [0xC400 + edi*2]
2814
    cmp   edi, [0x3000]
33 mario79 2815
    jne   @f
102 poddubny 2816
    inc   dword [esp]
2817
 @@:
33 mario79 2818
 
2819
    inc   [mouse_pause]
36 mario79 2820
    call  [disable_mouse]
1 ha 2821
    call  sys_set_window
36 mario79 2822
    call  [disable_mouse]
2823
    call  drawwindow_IV
114 mikedld 2824
    ;dec   [mouse_pause]
2825
    ;call   [draw_pointer]
2826
    ;ret
2827
    jmp   draw_window_caption.2
1 ha 2828
  nosyswIV:
2829
 
2830
    ret
2831
 
2832
 
114 mikedld 2833
draw_window_caption:
2834
        inc     [mouse_pause]
2835
        call    [disable_mouse]
2836
 
2837
        xor     eax,eax
2838
        mov     edx,[0x3004]
2839
        movzx   edx,word[0xC400+edx*2]
2840
        cmp     edx,[0x3000]
2841
        jne     @f
2842
        inc     eax
2843
    @@: mov     edx,[0x3000]
2844
        shl     edx,5
2845
        add     edx,window_data
2846
        movzx   ebx,[edx+WDATA.fl_wstyle]
2847
        and     bl,0x0F
2848
        cmp     bl,3
2849
        jne     .not_style_3
2850
 
2851
        push    edx
2852
        call    drawwindow_IV_caption
2853
        add     esp,4
2854
        jmp     .2
2855
 
2856
  .not_style_3:
2857
        cmp     bl,2
2858
        jne     .not_style_2
2859
 
2860
        call    drawwindow_III_caption
2861
        jmp     .2
2862
 
2863
  .not_style_2:
2864
        cmp     bl,0
2865
        jne     .2
2866
 
2867
        call    drawwindow_I_caption
2868
 
2869
;--------------------------------------------------------------
2870
  .2:   ;jmp     @f
2871
        mov     edi,[0x3000]
2872
        shl     edi,5
2873
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2874
        jz      @f
2875
        mov     ecx,[edi*8+0x80000+APPDATA.wnd_caption]
2876
        or      ecx,ecx
2877
        jz      @f
115 poddubny 2878
        add     ecx,[edi+twdw+TASKDATA.mem_start]
114 mikedld 2879
 
2880
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2881
        and     al,0x0F
2882
        cmp     al,3
2883
        jne     .not_skinned
2884
 
2885
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2886
        mov     bp,word[edi+window_data+WDATA.box.top]
2887
        movzx   eax,word[edi+window_data+WDATA.box.width]
2888
        sub     ax,[_skinmargins.left]
2889
        sub     ax,[_skinmargins.right]
2890
        cwde
2891
        cdq
2892
        mov     ebx,6
2893
        idiv    ebx
2894
        or      eax,eax
2895
        js      @f
2896
        mov     edx,eax
2897
        mov     eax,dword[_skinmargins.left-2]
2898
        mov     ax,word[_skinh]
2899
        sub     ax,[_skinmargins.bottom]
2900
        sub     ax,[_skinmargins.top]
2901
        sar     ax,1
2902
        adc     ax,0
2903
        add     ax,[_skinmargins.top]
2904
        add     ax,-3
2905
        add     eax,ebp
139 diamond 2906
        jmp     .dodraw
114 mikedld 2907
 
2908
  .not_skinned:
2909
        cmp     al,1
2910
        je      @f
2911
 
2912
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2913
        mov     bp,word[edi+window_data+WDATA.box.top]
2914
        movzx   eax,word[edi+window_data+WDATA.box.width]
2915
        sub     eax,16
2916
        cwde
2917
        cdq
2918
        mov     ebx,6
2919
        idiv    ebx
2920
        or      eax,eax
2921
        js      @f
2922
        mov     edx,eax
2923
        mov     eax,0x00080007
2924
        add     eax,ebp
139 diamond 2925
.dodraw:
114 mikedld 2926
        mov     ebx,[common_colours+16];0x00FFFFFF
139 diamond 2927
        or      ebx, 0x80000000
114 mikedld 2928
        xor     edi,edi
2929
        call    dtext
2930
 
2931
    @@:
2932
;--------------------------------------------------------------
2933
        dec     [mouse_pause]
2934
        call    [draw_pointer]
2935
        ret
2936
 
2937
iglobal
2938
align 4
2939
window_topleft dd \
2940
  1, 21,\
2941
  0,  0,\
2942
  5, 20,\
2943
  5,  ?
2944
endg
2945
 
2946
set_window_clientbox:
2947
        push    eax ecx edi
2948
 
2949
        mov     eax,[_skinh]
2950
        mov     [window_topleft+4*7],eax
2951
 
2952
        mov     ecx,edi
2953
        sub     edi,window_data
2954
        shl     edi,3
2955
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
2956
        jz      @f
2957
 
2958
        movzx   eax,[ecx+WDATA.fl_wstyle]
2959
        and     eax,0x0F
2960
        mov     eax,[eax*8+window_topleft+0]
2961
        mov     [edi+0x80000+APPDATA.wnd_clientbox.left],eax
2962
        shl     eax,1
2963
        neg     eax
2964
        add     eax,[ecx+WDATA.box.width]
2965
        mov     [edi+0x80000+APPDATA.wnd_clientbox.width],eax
2966
 
2967
        movzx   eax,[ecx+WDATA.fl_wstyle]
2968
        and     eax,0x0F
2969
        push    [eax*8+window_topleft+0]
2970
        mov     eax,[eax*8+window_topleft+4]
2971
        mov     [edi+0x80000+APPDATA.wnd_clientbox.top],eax
2972
        neg     eax
2973
        sub     eax,[esp]
2974
        add     eax,[ecx+WDATA.box.height]
2975
        mov     [edi+0x80000+APPDATA.wnd_clientbox.height],eax
2976
        add     esp,4
2977
 
2978
        pop     edi ecx eax
2979
        ret
2980
    @@:
2981
        xor     eax,eax
2982
        mov     [edi+0x80000+APPDATA.wnd_clientbox.left],eax
2983
        mov     [edi+0x80000+APPDATA.wnd_clientbox.top],eax
2984
        mov     eax,[ecx+WDATA.box.width]
2985
        mov     [edi+0x80000+APPDATA.wnd_clientbox.width],eax
2986
        mov     eax,[ecx+WDATA.box.height]
2987
        mov     [edi+0x80000+APPDATA.wnd_clientbox.height],eax
2988
 
2989
        pop     edi ecx eax
2990
        ret
2991
 
1 ha 2992
sys_set_window:
2993
 
2994
    mov   edi,[0x3000]
2995
    shl   edi,5
2996
    add   edi,window_data
2997
 
2998
    ; colors
114 mikedld 2999
    mov   [edi+WDATA.cl_workarea],ecx
3000
    mov   [edi+WDATA.cl_titlebar],edx
3001
    mov   [edi+WDATA.cl_frames],esi
1 ha 3002
 
3003
    ; check flag (?)
114 mikedld 3004
    cmp   [edi+WDATA.fl_wdrawn],1
1 ha 3005
    jz    newd
3006
 
3007
    push  eax
3008
    mov   eax,[timer_ticks] ;[0xfdf0]
3009
    add   eax,100
3010
    mov   [new_window_starting],eax
3011
    pop   eax
3012
 
114 mikedld 3013
    mov   word[edi+WDATA.box.width],ax
3014
    mov   word[edi+WDATA.box.height],bx
3015
    sar   eax,16
3016
    sar   ebx,16
3017
    mov   word[edi+WDATA.box.left],ax
3018
    mov   word[edi+WDATA.box.top],bx
1 ha 3019
 
3020
    call  check_window_position
3021
 
150 diamond 3022
        call    set_window_clientbox
1 ha 3023
 
3024
    push  ecx esi edi               ; save for window fullscreen/resize
114 mikedld 3025
    ;mov   esi,edi
3026
 
3027
        mov     cl,[edi+WDATA.fl_wstyle]
3028
 
1 ha 3029
    sub   edi,window_data
114 mikedld 3030
    shl   edi,3
115 poddubny 3031
    add   edi,0x80000
114 mikedld 3032
 
3033
        and     cl,0x0F
115 poddubny 3034
        mov     [edi+APPDATA.wnd_caption],0
114 mikedld 3035
        cmp     cl,3
3036
        jne     @f
115 poddubny 3037
        mov     [edi+APPDATA.wnd_caption],esi
114 mikedld 3038
    @@: mov     esi,[esp+0]
3039
 
115 poddubny 3040
    add   edi, APPDATA.saved_box
1 ha 3041
    mov   ecx,4
3042
    cld
3043
    rep   movsd
3044
    pop   edi esi ecx
3045
 
3046
    push  eax ebx ecx edx
3047
;;;    mov   eax, 1
3048
;;;    call  delay_hs
115 poddubny 3049
    mov   eax, [edi+WDATA.box.left]
3050
    mov   ebx, [edi+WDATA.box.top]
3051
    mov   ecx, [edi+WDATA.box.width]
3052
    mov   edx, [edi+WDATA.box.height]
1 ha 3053
    add   ecx, eax
3054
    add   edx, ebx
3055
    call  calculatescreen
3056
    pop   edx ecx ebx eax
3057
 
3058
    mov   [0xf400],byte 0           ; empty keyboard buffer
3059
    mov   [0xf500],byte 0           ; empty button buffer
3060
 
3061
  newd:
163 diamond 3062
;    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
1 ha 3063
    mov   edx,edi
3064
 
3065
    ret
3066
 
114 mikedld 3067
syscall_windowsettings:
1 ha 3068
 
114 mikedld 3069
  .set_window_caption:
3070
        dec     eax     ; subfunction #1 - set window caption
3071
        jnz     .get_window_caption
3072
 
3073
        ; NOTE: only window owner thread can set its caption,
3074
        ;       so there's no parameter for PID/TID
3075
 
3076
        mov     edi,[0x3000]
3077
        shl     edi,5
3078
 
3079
        ; have to check if caption is within application memory limit
3080
        ; check is trivial, and if application resizes its memory,
3081
        ;   caption still can become over bounds
3082
        mov     ecx,[edi*8+0x80000+APPDATA.mem_size]
3083
        add     ecx,255 ; max caption length
3084
        cmp     ebx,ecx
3085
        ja      .exit_fail
3086
 
3087
        mov     [edi*8+0x80000+APPDATA.wnd_caption],ebx
3088
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3089
 
3090
        call    draw_window_caption
3091
 
3092
        xor     eax,eax ; eax = 0 (success)
3093
        ret
3094
 
3095
  .get_window_caption:
3096
        dec     eax     ; subfunction #2 - get window caption
3097
        jnz     .exit_fail
3098
 
3099
        ; not implemented yet
3100
 
3101
  .exit_fail:
3102
        xor     eax,eax
3103
        inc     eax     ; eax = 1 (fail)
3104
        ret
3105
 
3106
 
1 ha 3107
sys_window_move:
3108
 
115 poddubny 3109
        mov     edi,[0x3000]
49 mikedld 3110
        shl     edi,5
3111
        add     edi,window_data
1 ha 3112
 
49 mikedld 3113
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3114
        jnz     .window_move_return
1 ha 3115
 
115 poddubny 3116
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3117
        push    dword [edi + WDATA.box.top]
3118
        push    dword [edi + WDATA.box.width]
3119
        push    dword [edi + WDATA.box.height]
1 ha 3120
 
49 mikedld 3121
        cmp   eax,-1                  ; set new position and size
3122
        je    .no_x_reposition
115 poddubny 3123
        mov     [edi + WDATA.box.left], eax
49 mikedld 3124
      .no_x_reposition:
3125
        cmp   ebx,-1
3126
        je    .no_y_reposition
115 poddubny 3127
        mov     [edi + WDATA.box.top], ebx
49 mikedld 3128
      .no_y_reposition:
1 ha 3129
 
49 mikedld 3130
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3131
        jnz     .no_y_resizing
1 ha 3132
 
49 mikedld 3133
        cmp   ecx,-1
3134
        je    .no_x_resizing
115 poddubny 3135
        mov     [edi + WDATA.box.width], ecx
49 mikedld 3136
      .no_x_resizing:
3137
        cmp   edx,-1
3138
        je    .no_y_resizing
115 poddubny 3139
        mov     [edi + WDATA.box.height], edx
49 mikedld 3140
      .no_y_resizing:
1 ha 3141
 
49 mikedld 3142
        call  check_window_position
150 diamond 3143
        call  set_window_clientbox
1 ha 3144
 
49 mikedld 3145
        pushad                       ; save for window fullscreen/resize
3146
        mov   esi,edi
3147
        sub   edi,window_data
3148
        shr   edi,5
3149
        shl   edi,8
115 poddubny 3150
        add   edi, 0x80000 + APPDATA.saved_box
49 mikedld 3151
        mov   ecx,4
3152
        cld
3153
        rep   movsd
3154
        popad
3155
 
3156
        pushad                       ; calculcate screen at new position
115 poddubny 3157
        mov   eax, [edi + WDATA.box.left]
3158
        mov   ebx, [edi + WDATA.box.top]
3159
        mov   ecx, [edi + WDATA.box.width]
3160
        mov   edx, [edi + WDATA.box.height]
3161
        add   ecx, eax
3162
        add   edx, ebx
49 mikedld 3163
        call  calculatescreen
3164
        popad
3165
 
3166
        pop   edx                   ; calculcate screen at old position
3167
        pop   ecx
3168
        pop   ebx
3169
        pop   eax
3170
        add   ecx,eax
3171
        add   edx,ebx
3172
        mov   [dlx],eax             ; save for drawlimits
3173
        mov   [dly],ebx
3174
        mov   [dlxe],ecx
3175
        mov   [dlye],edx
3176
        call  calculatescreen
3177
 
115 poddubny 3178
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3179
 
3180
        mov   eax,edi               ; redraw screen at old position
3181
        xor   esi,esi
3182
        call  redrawscreen
3183
 
3184
        mov   [0xfff5],byte 0 ; mouse pointer
3185
        mov   [0xfff4],byte 0 ; no mouse under
3186
        mov   [0xfb44],byte 0 ; react to mouse up/down
3187
 
3188
        mov   ecx,10          ; wait 1/10 second
3189
      .wmrl3:
3190
        call  [draw_pointer]
3191
        mov   eax,1
3192
        call  delay_hs
3193
        loop  .wmrl3
3194
 
3195
        mov   [window_move_pr],0
3196
 
3197
      .window_move_return:
3198
 
1 ha 3199
        ret
3200
 
67 diamond 3201
;type_background_1:
3202
;    cmp   [0xfff0],byte 0               ; background update ?
3203
;    jz    temp_nobackgr
3204
;    mov   [0xfff0],byte 2
3205
;    call  change_task
3206
;    mov   [draw_data+32+0],dword 0
3207
;    mov   [draw_data+32+4],dword 0
3208
;    mov   eax,[0xfe00]
3209
;    mov   ebx,[0xfe04]
3210
;    mov   [draw_data+32+8],eax
3211
;    mov   [draw_data+32+12],ebx
3212
;    call  drawbackground
3213
;    mov   [0xfff0],byte 0
3214
;    mov   [0xfff4],byte 0
3215
;temp_nobackgr:
3216
;    ret
41 mikedld 3217
 
1 ha 3218
uglobal
3219
  window_move_pr   dd  0x0
3220
  window_move_eax  dd  0x0
3221
  window_move_ebx  dd  0x0
3222
  window_move_ecx  dd  0x0
3223
  window_move_edx  dd  0x0
3224
endg
3225
 
3226
;ok - 100% work
3227
;nt - not tested
3228
;---------------------------------------------------------------------------------------------
3229
;eax
3230
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3231
;1 - change task. Ret nothing. Block. ok.
3232
;2 - performance control
3233
; ebx
3234
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3235
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3236
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3237
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3238
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3239
;eax
3240
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3241
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3242
;---------------------------------------------------------------------------------------------
3243
sys_sheduler: ;noname & halyavin
3244
    cmp eax,0
3245
    je shed_counter
3246
    cmp eax,2
3247
    je perf_control
3248
    cmp eax,3
3249
    je rdmsr_instr
3250
    cmp eax,4
3251
    je wrmsr_instr
3252
    cmp eax,1
3253
    jne not_supported
3254
    call change_task ;delay,0
3255
ret
3256
shed_counter:
3257
    mov eax,[context_counter]
3258
    mov [esp+36],eax
3259
not_supported:
3260
ret
3261
perf_control:
3262
    inc eax ;now eax=3
3263
    cmp ebx,eax
3264
    je cache_disable
3265
    dec eax
3266
    cmp ebx,eax
3267
    je cache_enable
3268
    dec eax
3269
    cmp ebx,eax
3270
    je is_cache_enabled
3271
    dec eax
3272
    cmp ebx,eax
3273
    je modify_pce
3274
ret
3275
 
3276
rdmsr_instr:
3277
;now counter in ecx
3278
;(edx:eax) esi:edi => edx:esi
3279
mov eax,esi
3280
rdmsr
3281
mov [esp+36],eax
3282
mov [esp+24],edx ;ret in ebx?
3283
ret
3284
 
3285
wrmsr_instr:
3286
;now counter in ecx
3287
;(edx:eax) esi:edi => edx:esi
3288
mov eax,esi
3289
wrmsr
3290
mov [esp+36],eax
3291
mov [esp+24],edx ;ret in ebx?
3292
ret
3293
 
3294
cache_disable:
3295
       mov eax,cr0
3296
       or  eax,01100000000000000000000000000000b
3297
       mov cr0,eax
3298
       wbinvd ;set MESI
3299
ret
3300
 
3301
cache_enable:
3302
       mov eax,cr0
3303
       and eax,10011111111111111111111111111111b
3304
       mov cr0,eax
3305
ret
3306
 
3307
is_cache_enabled:
3308
       mov eax,cr0
3309
       mov ebx,eax
3310
       and eax,01100000000000000000000000000000b
3311
       jz cache_disabled
3312
       mov [esp+36],ebx
3313
cache_disabled:
3314
       mov dword [esp+36],eax ;0
3315
ret
3316
 
3317
modify_pce:
3318
       mov eax,cr4
3319
;       mov ebx,0
3320
;       or  bx,100000000b ;pce
3321
;       xor eax,ebx ;invert pce
17 me_root 3322
       bts eax,8 ;pce=cr4[8]
1 ha 3323
       mov cr4,eax
3324
       mov [esp+36],eax
3325
ret
3326
;---------------------------------------------------------------------------------------------
3327
 
3328
 
3329
; check if pixel is allowed to be drawn
3330
 
3331
checkpixel:
21 poddubny 3332
        push eax edx
1 ha 3333
 
3334
        mov  edx,[0xfe00]     ; screen x size
3335
        inc  edx
21 poddubny 3336
        imul edx, ebx
1 ha 3337
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3338
 
21 poddubny 3339
        xor  ecx, ecx
105 poddubny 3340
        mov  eax, [0x3000]
3341
        cmp  al, dl
21 poddubny 3342
        setne cl
1 ha 3343
 
21 poddubny 3344
        pop  edx eax
1 ha 3345
        ret
3346
 
3347
uglobal
3348
  mouse_active  db  0
3349
endg
3350
iglobal
143 diamond 3351
  cpustring db '/RD/1/CPU',0
1 ha 3352
endg
3353
 
67 diamond 3354
uglobal
76 mario79 3355
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3356
endg
1 ha 3357
 
3358
align 4
3359
; check misc
3360
 
3361
checkmisc:
3362
 
3363
    cmp   [ctrl_alt_del], 1
3364
    jne   nocpustart
143 diamond 3365
    mov   ebp, cpustring
3366
    lea   esi,[ebp+6]
41 mikedld 3367
    xor   ebx,ebx               ; no parameters
40 halyavin 3368
    xor   edx,edx               ; no flags
143 diamond 3369
    call  fs_RamdiskExecute.flags
1 ha 3370
    mov   [ctrl_alt_del], 0
3371
  nocpustart:
3372
    cmp   [mouse_active], 1
3373
    jne   mouse_not_active
3374
    mov   [mouse_active], 0
3375
    xor   edi, edi
3376
    mov   ecx, [0x3004]
3377
   set_mouse_event:
3378
    add   edi, 256
115 poddubny 3379
    or    [edi+0x80000+APPDATA.event_mask], dword 00100000b
1 ha 3380
    loop  set_mouse_event
3381
  mouse_not_active:
3382
 
3383
 
3384
    cmp   [0xfff0],byte 0               ; background update ?
3385
    jz    nobackgr
76 mario79 3386
    cmp    [background_defined], 0
3387
    jz    nobackgr
1 ha 3388
    mov   [0xfff0],byte 2
3389
    call  change_task
117 mario79 3390
    mov   [draw_data+32 + RECT.left],dword 0
3391
    mov   [draw_data+32 + RECT.top],dword 0
1 ha 3392
    mov   eax,[0xfe00]
3393
    mov   ebx,[0xfe04]
117 mario79 3394
    mov   [draw_data+32 + RECT.right],eax
3395
    mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3396
    call  drawbackground
3397
    mov   [0xfff0],byte 0
3398
    mov   [0xfff4],byte 0
3399
 
3400
  nobackgr:
3401
 
3402
 
3403
    ; system shutdown request
3404
 
3405
    cmp  [0xFF00],byte 0
3406
    je   noshutdown
3407
 
3408
    mov  edx,[shutdown_processes]
3409
    sub  dl,2
3410
 
3411
    cmp  [0xff00],dl
3412
    jne  no_mark_system_shutdown
3413
 
3414
    mov   edx,0x3040
3415
    movzx ecx,byte [0xff00]
3416
    add   ecx,5
3417
  markz:
115 poddubny 3418
    mov   [edx+TASKDATA.state],byte 3
1 ha 3419
    add   edx,0x20
3420
    loop  markz
3421
 
3422
  no_mark_system_shutdown:
3423
 
3424
    call [disable_mouse]
3425
 
3426
    dec  byte [0xff00]
3427
 
3428
    cmp  [0xff00],byte 0
3429
    je   system_shutdown
3430
 
3431
  noshutdown:
3432
 
3433
 
3434
    mov   eax,[0x3004]                  ; termination
115 poddubny 3435
    mov   ebx,0x3020+TASKDATA.state
1 ha 3436
    mov   esi,1
3437
 
3438
  newct:
3439
    mov   cl,[ebx]
3440
    cmp   cl,byte 3
3441
    jz    terminate
3442
    cmp   cl,byte 4
3443
    jz    terminate
3444
 
3445
    add   ebx,0x20
3446
    inc   esi
3447
    dec   eax
3448
    jnz   newct
3449
 
3450
    ret
3451
 
3452
 
3453
 
3454
 
3455
; redraw screen
3456
 
3457
redrawscreen:
3458
 
3459
; eax , if process window_data base is eax, do not set flag/limits
3460
 
3461
         pushad
3462
         push  eax
3463
 
3464
;;;         mov   eax,2
3465
;;;         call  delay_hs
3466
 
3467
         ;mov   ecx,0               ; redraw flags for apps
3468
         xor   ecx,ecx
3469
       newdw2:
3470
 
3471
         inc   ecx
3472
         push  ecx
3473
 
3474
         mov   eax,ecx
3475
         shl   eax,5
3476
         add   eax,window_data
3477
 
3478
         cmp   eax,[esp+4]
3479
         je    not_this_task
3480
                                   ; check if window in redraw area
3481
         mov   edi,eax
3482
 
3483
         cmp   ecx,1               ; limit for background
3484
         jz    bgli
3485
 
115 poddubny 3486
         mov   eax, [edi + WDATA.box.left]
3487
         mov   ebx, [edi + WDATA.box.top]
3488
         mov   ecx, [edi + WDATA.box.width]
3489
         mov   edx, [edi + WDATA.box.height]
3490
         add   ecx, eax
3491
         add   edx, ebx
1 ha 3492
 
3493
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3494
         cmp   ecx,ebx
3495
         jb    ricino
3496
 
3497
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3498
         cmp   ecx,eax
3499
         jb    ricino
3500
 
115 poddubny 3501
         mov   eax, [edi + WDATA.box.left]
3502
         mov   ebx, [edi + WDATA.box.top]
3503
         mov   ecx, [edi + WDATA.box.width]
3504
         mov   edx, [edi + WDATA.box.height]
3505
         add   ecx, eax
3506
         add   edx, ebx
117 mario79 3507
 
1 ha 3508
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3509
         cmp   edx,eax
3510
         jb    ricino
3511
 
3512
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3513
         cmp   ecx,eax
3514
         jb    ricino
3515
 
3516
        bgli:
3517
 
3518
         cmp   edi,esi
3519
         jz    ricino
3520
 
3521
         mov   eax,edi
3522
         add   eax,draw_data-window_data
3523
 
3524
         mov   ebx,[dlx]          ; set limits
115 poddubny 3525
         mov   [eax + RECT.left], ebx
1 ha 3526
         mov   ebx,[dly]
115 poddubny 3527
         mov   [eax + RECT.top], ebx
1 ha 3528
         mov   ebx,[dlxe]
115 poddubny 3529
         mov   [eax + RECT.right], ebx
1 ha 3530
         mov   ebx,[dlye]
115 poddubny 3531
         mov   [eax + RECT.bottom], ebx
1 ha 3532
 
3533
         sub   eax,draw_data-window_data
3534
 
3535
         cmp   ecx,1
3536
         jne   nobgrd
3537
         cmp   esi,1
3538
         je    newdw8
3539
         call  drawbackground
3540
 
3541
       newdw8:
3542
       nobgrd:
3543
 
115 poddubny 3544
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3545
 
3546
       ricino:
3547
 
3548
       not_this_task:
3549
 
3550
         pop   ecx
3551
 
3552
         cmp   ecx,[0x3004]
3553
         jle   newdw2
3554
 
3555
         pop  eax
3556
         popad
3557
 
3558
         ret
3559
 
3560
calculatebackground:   ; background
3561
 
3562
        ; all black
3563
 
3564
        mov   [display_data-8],dword 4      ; size x
3565
        mov   [display_data-4],dword 2      ; size y
3566
 
3567
        mov   edi, 0x300000                 ; set background to black
3568
        xor   eax, eax
3569
        mov   ecx, 0x0fff00 / 4
3570
        cld
3571
        rep   stosd
3572
 
3573
        mov   edi,display_data              ; set os to use all pixels
3574
        mov   eax,0x01010101
3575
        mov   ecx,0x1fff00 / 4
3576
        rep   stosd
3577
 
3578
        mov   byte [0xFFF0], 0              ; do not draw background!
3579
 
3580
        ret
3581
 
3582
uglobal
3583
  imax    dd 0x0
3584
endg
3585
 
3586
 
3587
 
3588
delay_ms:     ; delay in 1/1000 sec
3589
 
3590
 
3591
        push  eax
3592
        push  ecx
3593
 
3594
        mov   ecx,esi
3595
        ; 
3596
        imul  ecx, 33941
3597
        shr   ecx, 9
3598
        ; 
3599
 
3600
        in    al,0x61
3601
        and   al,0x10
3602
        mov   ah,al
3603
        cld
3604
 
3605
 cnt1:  in    al,0x61
3606
        and   al,0x10
3607
        cmp   al,ah
3608
        jz    cnt1
3609
 
3610
        mov   ah,al
3611
        loop  cnt1
3612
 
3613
        pop   ecx
3614
        pop   eax
3615
 
3616
        ret
3617
 
3618
 
3619
set_app_param:
3620
        push edi
3621
 
3622
        mov  edi,[0x3010]
115 poddubny 3623
        mov  [edi+TASKDATA.event_mask],eax
1 ha 3624
 
3625
        pop  edi
3626
        ret
3627
 
3628
 
3629
 
3630
delay_hs:     ; delay in 1/100 secs
3631
        push  eax
3632
        push  ecx
3633
        push  edx
3634
 
115 poddubny 3635
        mov   edx,[timer_ticks]
1 ha 3636
        add   edx,eax
3637
 
3638
      newtic:
115 poddubny 3639
        mov   ecx,[timer_ticks]
1 ha 3640
        cmp   edx,ecx
3641
        jbe   zerodelay
3642
 
3643
        call  change_task
3644
 
3645
        jmp   newtic
3646
 
3647
      zerodelay:
3648
        pop   edx
3649
        pop   ecx
3650
        pop   eax
3651
 
3652
        ret
3653
 
3654
 
3655
memmove:       ; memory move in bytes
3656
 
3657
; eax = from
3658
; ebx = to
3659
; ecx = no of bytes
3660
    test ecx, ecx
3661
    jle  .ret
3662
 
3663
 
3664
    push esi edi ecx
3665
 
3666
    mov  edi, ebx
3667
    mov  esi, eax
3668
 
3669
    test ecx, not 11b
3670
    jz   @f
3671
 
3672
    push ecx
3673
    shr  ecx, 2
3674
    rep  movsd
3675
    pop  ecx
3676
    and  ecx, 11b
3677
    jz   .finish
3678
  @@:
3679
    rep  movsb
3680
 
3681
  .finish:
3682
    pop  ecx edi esi
3683
  .ret:
3684
    ret
3685
 
3686
 
75 diamond 3687
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3688
;align 4
1 ha 3689
;
75 diamond 3690
;read_floppy_file:
1 ha 3691
;
75 diamond 3692
;; as input
3693
;;
3694
;; eax pointer to file
3695
;; ebx file lenght
3696
;; ecx start 512 byte block number
3697
;; edx number of blocks to read
3698
;; esi pointer to return/work area (atleast 20 000 bytes)
3699
;;
3700
;;
3701
;; on return
3702
;;
3703
;; eax = 0 command succesful
3704
;;       1 no fd base and/or partition defined
3705
;;       2 yet unsupported FS
3706
;;       3 unknown FS
3707
;;       4 partition not defined at hd
3708
;;       5 file not found
3709
;; ebx = size of file
1 ha 3710
;
75 diamond 3711
;     mov   edi,[0x3010]
3712
;     add   edi,0x10
3713
;     add   esi,[edi]
3714
;     add   eax,[edi]
1 ha 3715
;
75 diamond 3716
;     pushad
3717
;     mov  edi,esi
3718
;     add  edi,1024
3719
;     mov  esi,0x100000+19*512
3720
;     sub  ecx,1
3721
;     shl  ecx,9
3722
;     add  esi,ecx
3723
;     shl  edx,9
3724
;     mov  ecx,edx
3725
;     cld
3726
;     rep  movsb
3727
;     popad
3728
;
3729
;     mov   [esp+36],eax
3730
;     mov   [esp+24],ebx
3731
;     ret
1 ha 3732
 
3733
 
3734
 
3735
align 4
3736
 
3737
sys_programirq:
3738
 
3739
    mov   edi,[0x3010]
115 poddubny 3740
    add   eax,[edi+TASKDATA.mem_start]
1 ha 3741
 
75 diamond 3742
    cmp   ebx,16
3743
    jae   .not_owner
1 ha 3744
    mov   edi,[0x3010]
115 poddubny 3745
    mov   edi,[edi+TASKDATA.pid]
75 diamond 3746
    cmp   edi,[irq_owner+ebx*4]
1 ha 3747
    je    spril1
75 diamond 3748
.not_owner:
1 ha 3749
    mov   [esp+36],dword 1
3750
    ret
3751
  spril1:
3752
 
3753
    mov   esi,eax
3754
    shl   ebx,6
3755
    add   ebx,irq00read
3756
    mov   edi,ebx
3757
    mov   ecx,16
3758
    cld
3759
    rep   movsd
3760
    mov   [esp+36],dword 0
3761
    ret
3762
 
3763
 
3764
align 4
3765
 
3766
get_irq_data:
75 diamond 3767
     cmp   eax,16
3768
     jae   .not_owner
1 ha 3769
     mov   edx,eax           ; check for correct owner
3770
     shl   edx,2
3771
     add   edx,irq_owner
3772
     mov   edx,[edx]
3773
     mov   edi,[0x3010]
115 poddubny 3774
     mov   edi,[edi+TASKDATA.pid]
1 ha 3775
     cmp   edx,edi
3776
     je    gidril1
75 diamond 3777
.not_owner:
3778
     mov   [esp+32],dword 2     ; ecx=2
1 ha 3779
     ret
3780
 
3781
  gidril1:
3782
 
3783
     mov   ebx,eax
3784
     shl   ebx,12
3785
     add   ebx,0x2e0000
3786
     mov   eax,[ebx]
3787
     mov   ecx,1
3788
     test  eax,eax
3789
     jz    gid1
3790
 
3791
     dec   eax
3792
     mov   esi,ebx
3793
     mov   [ebx],eax
3794
     movzx ebx,byte [ebx+0x10]
3795
     add   esi,0x10
3796
     mov   edi,esi
3797
     inc   esi
3798
     mov   ecx,4000 / 4
3799
     cld
3800
     rep   movsd
75 diamond 3801
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
1 ha 3802
   gid1:
3803
     mov   [esp+36],eax
3804
     mov   [esp+32],ecx
3805
     mov   [esp+24],ebx
3806
     ret
3807
 
3808
 
3809
set_io_access_rights:
3810
 
3811
     pushad
3812
 
3813
     mov   edi,[0x3000]
3814
     imul  edi,tss_step
3815
     add   edi,tss_data+128
3816
;     add   edi,128
3817
 
3818
     mov   ecx,eax
3819
     and   ecx,7    ; offset in byte
3820
 
3821
     shr   eax,3    ; number of byte
3822
     add   edi,eax
3823
 
3824
     mov   ebx,1
3825
     shl   ebx,cl
3826
 
3827
     cmp   ebp,0                ; enable access - ebp = 0
3828
     jne   siar1
3829
 
3830
     not   ebx
3831
     and   [edi],byte bl
3832
 
3833
     popad
3834
 
3835
     ret
3836
 
3837
   siar1:
3838
 
3839
     or    [edi],byte bl        ; disable access - ebp = 1
3840
 
3841
     popad
3842
 
3843
     ret
3844
 
3845
 
3846
 
3847
 
3848
 
3849
r_f_port_area:
3850
 
3851
     test  eax, eax
3852
     jnz   free_port_area
3853
;     je    r_port_area
3854
;     jmp   free_port_area
3855
 
3856
;   r_port_area:
3857
 
3858
     pushad
3859
 
3860
     cmp   ebx,ecx            ; beginning > end ?
75 diamond 3861
     ja    rpal1
3862
     cmp   ecx,65536
3863
     jae   rpal1
1 ha 3864
     mov   esi,[0x2d0000]
75 diamond 3865
     test  esi,esi            ; no reserved areas ?
1 ha 3866
     je    rpal2
3867
     cmp   esi,255            ; max reserved
75 diamond 3868
     jae   rpal1
1 ha 3869
   rpal3:
3870
     mov   edi,esi
3871
     shl   edi,4
3872
     add   edi,0x2d0000
3873
     cmp   ebx,[edi+8]
75 diamond 3874
     ja    rpal4
1 ha 3875
     cmp   ecx,[edi+4]
3876
     jae   rpal1
3877
;     jb    rpal4
3878
;     jmp   rpal1
3879
   rpal4:
3880
 
3881
     dec   esi
3882
     jnz   rpal3
3883
     jmp   rpal2
3884
   rpal1:
3885
     popad
3886
     mov   eax,1
3887
     ret
3888
 
3889
   rpal2:
3890
     popad
3891
 
3892
 
3893
     ; enable port access at port IO map
3894
     cli
3895
     pushad                        ; start enable io map
3896
 
3897
     cmp   ecx,65536 ;16384
3898
     jae   no_unmask_io ; jge
3899
 
3900
     mov   eax,ebx
3901
 
3902
   new_port_access:
3903
 
3904
     pushad
3905
 
75 diamond 3906
     xor   ebp,ebp                ; enable - eax = port
1 ha 3907
     call  set_io_access_rights
3908
 
3909
     popad
3910
 
3911
     inc   eax
3912
     cmp   eax,ecx
3913
     jbe   new_port_access
3914
 
3915
   no_unmask_io:
3916
 
3917
     popad                         ; end enable io map
3918
     sti
3919
 
3920
     mov   edi,[0x2d0000]
3921
     add   edi,1
3922
     mov   [0x2d0000],edi
3923
     shl   edi,4
3924
     add   edi,0x2d0000
3925
     mov   esi,[0x3010]
115 poddubny 3926
     mov   esi,[esi+TASKDATA.pid]
1 ha 3927
     mov   [edi],esi
3928
     mov   [edi+4],ebx
3929
     mov   [edi+8],ecx
3930
 
3931
     xor   eax, eax
3932
     ret
3933
 
3934
 
3935
 
3936
 
3937
free_port_area:
3938
 
3939
     pushad
3940
 
3941
     mov   esi,[0x2d0000]     ; no reserved areas ?
75 diamond 3942
     test  esi,esi
1 ha 3943
     je    frpal2
3944
     mov   edx,[0x3010]
115 poddubny 3945
     mov   edx,[edx+TASKDATA.pid]
1 ha 3946
   frpal3:
3947
     mov   edi,esi
3948
     shl   edi,4
3949
     add   edi,0x2d0000
3950
     cmp   edx,[edi]
3951
     jne   frpal4
3952
     cmp   ebx,[edi+4]
3953
     jne   frpal4
3954
     cmp   ecx,[edi+8]
3955
     jne   frpal4
3956
     jmp   frpal1
3957
   frpal4:
3958
     dec   esi
3959
     jnz   frpal3
3960
   frpal2:
3961
     popad
3962
     mov   eax,1
3963
     ret
3964
   frpal1:
3965
     mov   ecx,256
3966
     sub   ecx,esi
3967
     shl   ecx,4
3968
     mov   esi,edi
3969
     add   esi,16
3970
     cld
3971
     rep   movsb
3972
 
3973
     dec   dword [0x2d0000]
3974
 
3975
     popad
3976
 
3977
 
3978
     ; disable port access at port IO map
3979
 
3980
     pushad                        ; start disable io map
3981
 
3982
     cmp   ecx,65536 ;16384
3983
     jge   no_mask_io
3984
 
3985
     mov   eax,ebx
3986
 
3987
   new_port_access_disable:
3988
 
3989
     pushad
3990
 
3991
     mov   ebp,1                  ; disable - eax = port
3992
     call  set_io_access_rights
3993
 
3994
     popad
3995
 
3996
     inc   eax
3997
     cmp   eax,ecx
3998
     jbe   new_port_access_disable
3999
 
4000
   no_mask_io:
4001
 
4002
     popad                         ; end disable io map
4003
 
4004
     xor   eax, eax
4005
     ret
4006
 
4007
 
4008
reserve_free_irq:
4009
 
75 diamond 4010
     mov   ecx, 1
4011
     cmp   ebx, 16
4012
     jae   fril1
4013
     test  eax,eax
1 ha 4014
     jz    reserve_irq
4015
 
75 diamond 4016
     lea   edi,[irq_owner+ebx*4]
1 ha 4017
     mov   edx,[edi]
4018
     mov   eax,[0x3010]
115 poddubny 4019
     cmp   edx,[eax+TASKDATA.pid]
1 ha 4020
     jne   fril1
75 diamond 4021
     dec   ecx
4022
     mov   [edi],ecx
1 ha 4023
   fril1:
4024
     mov   [esp+36],ecx ; return in eax
4025
     ret
4026
 
4027
  reserve_irq:
4028
 
75 diamond 4029
     lea   edi,[irq_owner+ebx*4]
4030
     cmp   dword [edi], 0
4031
     jnz   ril1
1 ha 4032
 
4033
     mov   edx,[0x3010]
115 poddubny 4034
     mov   edx,[edx+TASKDATA.pid]
1 ha 4035
     mov   [edi],edx
75 diamond 4036
     dec   ecx
1 ha 4037
   ril1:
4038
     mov   [esp+36],ecx ; return in eax
4039
     ret
4040
 
4041
 
4042
 
4043
drawbackground:
33 mario79 4044
       inc   [mouse_pause]
1 ha 4045
       cmp   [0xfe0c],word 0x12
117 mario79 4046
       je   dbrv20
1 ha 4047
     dbrv12:
4048
       cmp  [0xfe0c],word 0100000000000000b
4049
       jge  dbrv20
4050
       cmp  [0xfe0c],word 0x13
4051
       je   dbrv20
4052
       call  vesa12_drawbackground
33 mario79 4053
       dec   [mouse_pause]
36 mario79 4054
       call   [draw_pointer]
1 ha 4055
       ret
4056
     dbrv20:
4057
       cmp   [display_data-12],dword 1
4058
       jne   bgrstr
4059
       call  vesa20_drawbackground_tiled
33 mario79 4060
       dec   [mouse_pause]
36 mario79 4061
       call   [draw_pointer]
1 ha 4062
       ret
4063
     bgrstr:
4064
       call  vesa20_drawbackground_stretch
33 mario79 4065
       dec   [mouse_pause]
36 mario79 4066
       call   [draw_pointer]
1 ha 4067
       ret
4068
 
75 diamond 4069
align 4
1 ha 4070
 
75 diamond 4071
syscall_putimage:                       ; PutImage
33 mario79 4072
 
75 diamond 4073
     mov   edx,ecx
4074
     mov   ecx,ebx
4075
        lea     ebx, [eax+std_application_base_address]
4076
 
1 ha 4077
sys_putimage:
53 mikedld 4078
     test  ecx,0x80008000
4079
     jnz   .exit
4080
     test  ecx,0x0000FFFF
4081
     jz    .exit
4082
     test  ecx,0xFFFF0000
4083
     jnz   @f
4084
  .exit:
4085
     ret
4086
 @@:
114 mikedld 4087
        mov     edi,[0x3000]
4088
        shl     edi,8
4089
        add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.top]
4090
        rol     edx,16
4091
        add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.left]
4092
        rol     edx,16
4093
  .forced:
117 mario79 4094
;        mov     eax, vga_putimage
75 diamond 4095
        cmp     [0xfe0c], word 0x12
117 mario79 4096
        jz      @f   ;.doit
75 diamond 4097
        mov     eax, vesa12_putimage
4098
        cmp     [0xfe0c], word 0100000000000000b
4099
        jae     @f
4100
        cmp     [0xfe0c], word 0x13
4101
        jnz     .doit
4102
@@:
4103
        mov     eax, vesa20_putimage
4104
.doit:
119 mario79 4105
        inc     [mouse_pause]
75 diamond 4106
        call    eax
119 mario79 4107
        dec     [mouse_pause]
75 diamond 4108
        jmp     [draw_pointer]
1 ha 4109
 
4110
; eax x beginning
4111
; ebx y beginning
4112
; ecx x end
4113
; edx y end
4114
; edi color
4115
 
4116
__sys_drawbar:
114 mikedld 4117
        mov     esi,[0x3000]
4118
        shl     esi,8
4119
        add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
4120
        add     ecx,[esi+0x80000+APPDATA.wnd_clientbox.left]
4121
        add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
4122
        add     edx,[esi+0x80000+APPDATA.wnd_clientbox.top]
4123
  .forced:
33 mario79 4124
    inc   [mouse_pause]
4125
    cmp   [0xfe0c],word 0x12
117 mario79 4126
    je   dbv20
1 ha 4127
   sdbv20:
4128
    cmp  [0xfe0c],word 0100000000000000b
4129
    jge  dbv20
4130
    cmp  [0xfe0c],word 0x13
4131
    je   dbv20
4132
    call vesa12_drawbar
33 mario79 4133
    dec   [mouse_pause]
36 mario79 4134
    call   [draw_pointer]
1 ha 4135
    ret
4136
  dbv20:
4137
    call vesa20_drawbar
33 mario79 4138
    dec   [mouse_pause]
36 mario79 4139
    call   [draw_pointer]
1 ha 4140
    ret
4141
 
4142
 
4143
 
4144
kb_read:
4145
 
4146
        push    ecx edx
4147
 
98 mario79 4148
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4149
      kr_loop:
4150
        in      al,0x64
4151
        test    al,1
4152
        jnz     kr_ready
4153
        loop    kr_loop
4154
        mov     ah,1
4155
        jmp     kr_exit
4156
      kr_ready:
4157
        push    ecx
4158
        mov     ecx,32
4159
      kr_delay:
4160
        loop    kr_delay
4161
        pop     ecx
4162
        in      al,0x60
4163
        xor     ah,ah
4164
      kr_exit:
4165
 
4166
        pop     edx ecx
4167
 
4168
        ret
4169
 
4170
 
4171
kb_write:
4172
 
4173
        push    ecx edx
4174
 
4175
        mov     dl,al
98 mario79 4176
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4177
      kw_loop1:
4178
        in      al,0x64
4179
        test    al,0x20
4180
        jz      kw_ok1
4181
        loop    kw_loop1
4182
        mov     ah,1
4183
        jmp     kw_exit
4184
      kw_ok1:
4185
        in      al,0x60
98 mario79 4186
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4187
      kw_loop:
4188
        in      al,0x64
4189
        test    al,2
4190
        jz      kw_ok
4191
        loop    kw_loop
4192
        mov     ah,1
4193
        jmp     kw_exit
4194
      kw_ok:
4195
        mov     al,dl
4196
        out     0x60,al
98 mario79 4197
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4198
      kw_loop3:
4199
        in      al,0x64
4200
        test    al,2
4201
        jz      kw_ok3
4202
        loop    kw_loop3
4203
        mov     ah,1
4204
        jmp     kw_exit
4205
      kw_ok3:
4206
        mov     ah,8
4207
      kw_loop4:
98 mario79 4208
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4209
      kw_loop5:
4210
        in      al,0x64
4211
        test    al,1
4212
        jnz     kw_ok4
4213
        loop    kw_loop5
4214
        dec     ah
4215
        jnz     kw_loop4
4216
      kw_ok4:
4217
        xor     ah,ah
4218
      kw_exit:
4219
 
4220
        pop     edx ecx
4221
 
4222
        ret
4223
 
4224
 
4225
kb_cmd:
4226
 
98 mario79 4227
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4228
      c_wait:
4229
        in      al,0x64
4230
        test    al,2
4231
        jz      c_send
4232
        loop    c_wait
4233
        jmp     c_error
4234
      c_send:
4235
        mov     al,bl
4236
        out     0x64,al
98 mario79 4237
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4238
      c_accept:
4239
        in      al,0x64
4240
        test    al,2
4241
        jz      c_ok
4242
        loop    c_accept
4243
      c_error:
4244
        mov     ah,1
4245
        jmp     c_exit
4246
      c_ok:
4247
        xor     ah,ah
4248
      c_exit:
4249
        ret
4250
 
4251
 
4252
setmouse:  ; set mousepicture -pointer
4253
           ; ps2 mouse enable
4254
 
4255
     mov     [0xf200],dword mousepointer
4256
 
4257
     cli
33 mario79 4258
;     mov     bl,0xa8                 ; enable mouse cmd
4259
;     call    kb_cmd
4260
;     call    kb_read                 ; read status
4261
;     mov     bl,0x20                 ; get command byte
4262
;     call    kb_cmd
4263
;     call    kb_read
4264
;     or      al,3                    ; enable interrupt
4265
;     mov     bl,0x60                 ; write command
4266
;     push    eax
4267
;     call    kb_cmd
4268
;     pop     eax
4269
;     call    kb_write
4270
;     mov     bl,0xd4                 ; for mouse
4271
;     call    kb_cmd
4272
;     mov     al,0xf4                 ; enable mouse device
4273
;     call    kb_write
4274
;     call    kb_read           ; read status return
1 ha 4275
 
4276
     ; com1 mouse enable
4277
 
4278
     mov   bx,0x3f8 ; combase
4279
 
4280
     mov   dx,bx
4281
     add   dx,3
4282
     mov   al,0x80
4283
     out   dx,al
4284
 
4285
     mov   dx,bx
4286
     add   dx,1
4287
     mov   al,0
4288
     out   dx,al
4289
 
4290
     mov   dx,bx
4291
     add   dx,0
4292
     mov   al,0x30*2    ; 0x30 / 4
4293
     out   dx,al
4294
 
4295
     mov   dx,bx
4296
     add   dx,3
4297
     mov   al,2         ; 3
4298
     out   dx,al
4299
 
4300
     mov   dx,bx
4301
     add   dx,4
4302
     mov   al,0xb
4303
     out   dx,al
4304
 
4305
     mov   dx,bx
4306
     add   dx,1
4307
     mov   al,1
4308
     out   dx,al
4309
 
4310
 
4311
     ; com2 mouse enable
4312
 
4313
     mov   bx,0x2f8 ; combase
4314
 
4315
     mov   dx,bx
4316
     add   dx,3
4317
     mov   al,0x80
4318
     out   dx,al
4319
 
4320
     mov   dx,bx
4321
     add   dx,1
4322
     mov   al,0
4323
     out   dx,al
4324
 
4325
     mov   dx,bx
4326
     add   dx,0
4327
     mov   al,0x30*2
4328
     out   dx,al
4329
 
4330
     mov   dx,bx
4331
     add   dx,3
4332
     mov   al,2
4333
     out   dx,al
4334
 
4335
     mov   dx,bx
4336
     add   dx,4
4337
     mov   al,0xb
4338
     out   dx,al
4339
 
4340
     mov   dx,bx
4341
     add   dx,1
4342
     mov   al,1
4343
     out   dx,al
4344
 
4345
     ret
4346
 
4347
 
4348
_rdtsc:
4349
 
4350
     mov   edx,[cpuid_1+3*4]
4351
     test  edx,00010000b
4352
     jz    ret_rdtsc
4353
     rdtsc
4354
     ret
4355
   ret_rdtsc:
4356
     mov   edx,0xffffffff
4357
     mov   eax,0xffffffff
4358
     ret
4359
 
4360
 
4361
 
4362
rerouteirqs:
4363
 
4364
        cli
4365
 
4366
        mov     al,0x11         ;  icw4, edge triggered
4367
        out     0x20,al
4368
        call    pic_delay
4369
        out     0xA0,al
4370
        call    pic_delay
4371
 
4372
        mov     al,0x20         ;  generate 0x20 +
4373
        out     0x21,al
4374
        call    pic_delay
4375
        mov     al,0x28         ;  generate 0x28 +
4376
        out     0xA1,al
4377
        call    pic_delay
4378
 
4379
        mov     al,0x04         ;  slave at irq2
4380
        out     0x21,al
4381
        call    pic_delay
4382
        mov     al,0x02         ;  at irq9
4383
        out     0xA1,al
4384
        call    pic_delay
4385
 
4386
        mov     al,0x01         ;  8086 mode
4387
        out     0x21,al
4388
        call    pic_delay
4389
        out     0xA1,al
4390
        call    pic_delay
4391
 
4392
        mov     al,255          ; mask all irq's
4393
        out     0xA1,al
4394
        call    pic_delay
4395
        out     0x21,al
4396
        call    pic_delay
4397
 
4398
        mov     ecx,0x1000
4399
        cld
4400
picl1:  call    pic_delay
4401
        loop    picl1
4402
 
4403
        mov     al,255          ; mask all irq's
4404
        out     0xA1,al
4405
        call    pic_delay
4406
        out     0x21,al
4407
        call    pic_delay
4408
 
4409
        cli
4410
 
4411
        ret
4412
 
4413
 
4414
pic_delay:
4415
 
4416
        jmp     pdl1
4417
pdl1:   ret
4418
 
4419
 
4420
sys_msg_board_str:
4421
 
4422
     pushad
4423
   @@:
4424
     cmp    [esi],byte 0
4425
     je     @f
4426
     mov    eax,1
4427
     movzx  ebx,byte [esi]
4428
     call   sys_msg_board
4429
     inc    esi
4430
     jmp    @b
4431
   @@:
4432
     popad
4433
     ret
4434
 
4435
uglobal
4436
  msg_board_data: times 512 db 0
4437
  msg_board_count dd 0x0
4438
endg
4439
 
4440
sys_msg_board:
4441
 
4442
; eax=1 : write :  bl byte to write
4443
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4444
 
4445
     mov  ecx,[msg_board_count]
4446
     cmp  eax, 1
4447
     jne  smbl1
4448
 
4449
 
4450
     mov  [msg_board_data+ecx],bl
4451
     inc  ecx
4452
     and  ecx, 511
4453
     mov  [msg_board_count], ecx
4454
     mov  [check_idle_semaphore], 5
4455
     ret
4456
   smbl1:
4457
 
4458
     cmp   eax, 2
4459
     jne   smbl2
4460
     test  ecx, ecx
4461
     jz    smbl21
4462
;     mov   edi, msg_board_data
4463
;     mov   esi, msg_board_data+1
4464
;     movzx eax, byte [edi]
4465
     mov   eax, msg_board_data+1
4466
     mov   ebx, msg_board_data
4467
     movzx edx, byte [ebx]
4468
     call  memmove
4469
;     push  ecx
4470
;     shr   ecx, 2
4471
;     cld
4472
;     rep   movsd
4473
;     pop   ecx
4474
;     and   ecx, 3
4475
;     rep   movsb
4476
     dec   [msg_board_count]
4477
     mov   [esp+36], edx ;eax
4478
     mov   [esp+24], dword 1
4479
     ret
4480
   smbl21:
4481
     mov   [esp+36], ecx
4482
     mov   [esp+24], ecx
4483
 
4484
   smbl2:
4485
     ret
4486
 
4487
 
4488
 
4489
sys_trace:
4490
 
4491
     test eax, eax                  ; get event data
4492
     jnz  no_get_sys_events
4493
 
4494
     mov  esi,save_syscall_data     ; data
4495
     mov  edi,[0x3010]
115 poddubny 4496
     mov  edi,[edi+TASKDATA.mem_start]
1 ha 4497
     add  edi,ebx
4498
     cld
4499
     rep  movsb
4500
 
4501
     mov  [esp+24],dword 0
4502
     mov  eax,[save_syscall_count]  ; count
4503
     mov  [esp+36],eax
4504
     ret
4505
 
4506
   no_get_sys_events:
4507
 
4508
     ret
4509
 
4510
 
4511
sys_process_def:
92 diamond 4512
        mov     edi, [0x3000]
1 ha 4513
 
92 diamond 4514
        dec     eax             ; 1 = set keyboard mode
1 ha 4515
     jne   no_set_keyboard_setup
4516
 
4517
     shl   edi,8
115 poddubny 4518
     mov   [edi+0x80000 + APPDATA.keyboard_mode],bl
1 ha 4519
 
4520
     ret
4521
 
4522
   no_set_keyboard_setup:
4523
 
92 diamond 4524
        dec     eax             ; 2 = get keyboard mode
1 ha 4525
     jne   no_get_keyboard_setup
4526
 
4527
     shl   edi,8
115 poddubny 4528
     movzx eax, byte [0x80000+edi + APPDATA.keyboard_mode]
1 ha 4529
 
4530
     mov   [esp+36],eax
4531
 
4532
     ret
4533
 
4534
   no_get_keyboard_setup:
4535
 
92 diamond 4536
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4537
     jne   no_get_keyboard_cas
4538
 
4539
;     xor   eax,eax
4540
;     movzx eax,byte [shift]
4541
;     movzx ebx,byte [ctrl]
4542
;     shl   ebx,2
4543
;     add   eax,ebx
4544
;     movzx ebx,byte [alt]
4545
;     shl   ebx,3
4546
;     add   eax,ebx
4547
 
4548
 ;// mike.dld [
4549
     mov   eax, [kb_state]
4550
 ;// mike.dld ]
4551
 
4552
     mov   [esp+36],eax
4553
 
4554
     ret
4555
 
4556
   no_get_keyboard_cas:
4557
 
92 diamond 4558
        dec     eax
4559
        jnz     no_add_keyboard_hotkey
1 ha 4560
 
92 diamond 4561
        mov     eax, hotkey_list
4562
@@:
4563
        cmp     dword [eax+8], 0
4564
        jz      .found_free
4565
        add     eax, 16
4566
        cmp     eax, hotkey_list+16*256
4567
        jb      @b
4568
        mov     dword [esp+36], 1
4569
        ret
4570
.found_free:
4571
        mov     [eax+8], edi
4572
        mov     [eax+4], ecx
4573
        movzx   ebx, bl
4574
        lea     ebx, [hotkey_scancodes+ebx*4]
4575
        mov     ecx, [ebx]
4576
        mov     [eax], ecx
4577
        mov     [ebx], eax
4578
        mov     [eax+12], ebx
4579
        jecxz   @f
4580
        mov     [ecx+12], eax
4581
@@:
4582
        and     dword [esp+36], 0
4583
        ret
4584
 
4585
no_add_keyboard_hotkey:
4586
 
4587
        dec     eax
4588
        jnz     no_del_keyboard_hotkey
4589
 
4590
        movzx   ebx, bl
4591
        lea     ebx, [hotkey_scancodes+ebx*4]
4592
        mov     eax, [ebx]
4593
.scan:
4594
        test    eax, eax
4595
        jz      .notfound
4596
        cmp     [eax+8], edi
4597
        jnz     .next
4598
        cmp     [eax+4], ecx
4599
        jz      .found
4600
.next:
4601
        mov     eax, [eax]
4602
        jmp     .scan
4603
.notfound:
4604
        mov     dword [esp+36], 1
4605
        ret
4606
.found:
4607
        mov     ecx, [eax]
4608
        jecxz   @f
4609
        mov     edx, [eax+12]
4610
        mov     [ecx+12], edx
4611
@@:
4612
        mov     ecx, [eax+12]
4613
        mov     edx, [eax]
4614
        mov     [ecx], edx
4615
        xor     edx, edx
4616
        mov     [eax+4], edx
4617
        mov     [eax+8], edx
4618
        mov     [eax+12], edx
4619
        mov     [eax], edx
4620
        mov     [esp+36], edx
4621
        ret
4622
 
4623
no_del_keyboard_hotkey:
1 ha 4624
     ret
4625
 
4626
 
4627
sys_ipc:
4628
     cmp  eax,1                      ; DEFINE IPC MEMORY
4629
     jne  no_ipc_def
4630
     mov  edi,[0x3000]
4631
     shl  edi,8
4632
     add  edi,0x80000
115 poddubny 4633
     mov  [edi + APPDATA.ipc_start], ebx
4634
     mov  [edi + APPDATA.ipc_size], ecx
1 ha 4635
     mov  [esp+36],dword 0
4636
     ret
4637
   no_ipc_def:
4638
 
4639
     cmp  eax,2                      ; SEND IPC MESSAGE
4640
     jne  no_ipc_send
4641
     mov  esi,1
4642
     mov  edi,0x3020
4643
    ipcs1:
115 poddubny 4644
     cmp  [edi+TASKDATA.pid], ebx
1 ha 4645
     je   ipcs2
4646
     add  edi,0x20
4647
     inc  esi
4648
     cmp  esi,[0x3004]
4649
     jbe  ipcs1
4650
     mov  [esp+36],dword 4
4651
     ret
4652
    ipcs2:
4653
 
4654
     cli
4655
 
4656
     push esi
4657
     mov  eax,esi
4658
     shl  eax,8
115 poddubny 4659
     mov  ebx,[eax+0x80000 + APPDATA.ipc_start]
1 ha 4660
     test ebx,ebx                  ; ipc area not defined ?
4661
     je   ipc_err1
4662
 
115 poddubny 4663
     add  ebx,[eax+0x80000 + APPDATA.ipc_size]
1 ha 4664
     mov  eax,esi
4665
     shl  eax,5
115 poddubny 4666
     add  ebx,[eax+0x3000 + TASKDATA.mem_start]    ; ebx <- max data position
1 ha 4667
 
4668
     mov  eax,esi                  ; to
4669
     shl  esi,8
4670
     add  esi,0x80000
115 poddubny 4671
     mov  edi,[esi+APPDATA.ipc_start]
1 ha 4672
     shl  eax,5
4673
     add  eax,0x3000
115 poddubny 4674
     add  edi,[eax+TASKDATA.mem_start]
1 ha 4675
 
4676
     cmp  [edi],byte 0             ; overrun ?
4677
     jne  ipc_err2
4678
 
4679
     mov  ebp,edi
4680
     add  edi,[edi+4]
4681
     add  edi,8
4682
 
4683
     mov  esi,ecx                  ; from
4684
     mov  eax,[0x3010]
115 poddubny 4685
     mov  eax,[eax+TASKDATA.mem_start]
1 ha 4686
     add  esi,eax
4687
 
4688
     mov  ecx,edx                  ; size
4689
 
4690
     mov  eax,edi
4691
     add  eax,ecx
4692
     cmp  eax,ebx
75 diamond 4693
     jg   ipc_err3                 ; not enough room ?
1 ha 4694
 
4695
     push ecx
4696
 
4697
     mov  eax,[0x3010]
115 poddubny 4698
     mov  eax,[eax+TASKDATA.pid]
1 ha 4699
     mov  [edi-8],eax
4700
     mov  [edi-4],ecx
4701
     cld
4702
     rep  movsb
4703
 
4704
     pop  ecx
4705
     add  ecx,8
4706
 
4707
     mov  edi,ebp                  ; increase memory position
4708
     add  dword [edi+4],ecx
4709
 
4710
     mov  edi,[esp]
4711
     shl  edi,8
115 poddubny 4712
     or   dword [edi+0x80000+APPDATA.event_mask],dword 01000000b ; ipc message
1 ha 4713
 
4714
     cmp  [check_idle_semaphore],dword 20
4715
     jge  ipc_no_cis
4716
     mov  [check_idle_semaphore],5
4717
   ipc_no_cis:
4718
 
4719
     xor  eax, eax
4720
 
4721
    ipc_err:
4722
     add  esp,4
4723
     mov  [esp+36],eax
4724
     sti
4725
     ret
4726
 
4727
    ipc_err1:
4728
     add  esp,4
4729
     mov  [esp+36],dword 1
4730
     sti
4731
     ret
4732
    ipc_err2:
4733
     add  esp,4
4734
     mov  [esp+36],dword 2
4735
     sti
4736
     ret
4737
    ipc_err3:
4738
     add  esp,4
4739
     mov  [esp+36],dword 3
4740
     sti
4741
     ret
4742
 
4743
   no_ipc_send:
4744
 
4745
     mov  [esp+36],dword -1
4746
     ret
4747
 
4748
 
4749
align 4
4750
 
4751
sys_gs:                         ; direct screen access
4752
 
4753
     cmp  eax,1                 ; resolution
4754
     jne  no_gs1
4755
     mov  eax,[0xfe00]
4756
     shl  eax,16
4757
     mov  ax,[0xfe04]
4758
     add  eax,0x00010001
4759
     mov  [esp+36],eax
4760
     ret
4761
   no_gs1:
4762
 
4763
     cmp   eax,2                ; bits per pixel
4764
     jne   no_gs2
4765
     movzx eax,byte [0xfbf1]
4766
     mov   [esp+36],eax
4767
     ret
4768
   no_gs2:
4769
 
4770
     cmp   eax,3                ; bytes per scanline
4771
     jne   no_gs3
4772
     mov   eax,[0xfe08]
4773
     mov   [esp+36],eax
4774
     ret
4775
   no_gs3:
4776
 
4777
     mov  [esp+36],dword -1
4778
     ret
4779
 
4780
 
4781
align 4 ; PCI functions
4782
 
4783
sys_pci:
4784
 
4785
     call  pci_api
4786
     mov   [esp+36],eax
4787
     ret
4788
 
4789
 
4790
align 4  ;  system functions
4791
 
4792
syscall_setpixel:                       ; SetPixel
4793
 
4794
 
4795
     mov   edx,[0x3010]
115 poddubny 4796
     add   eax,[edx-twdw+WDATA.box.left]
4797
     add   ebx,[edx-twdw+WDATA.box.top]
114 mikedld 4798
        mov     edi,[0x3000]
4799
        shl     edi,8
4800
        add     eax,[edi+0x80000+APPDATA.wnd_clientbox.left]
4801
        add     ebx,[edi+0x80000+APPDATA.wnd_clientbox.top]
112 poddubny 4802
     xor   edi,edi ; no force
114 mikedld 4803
;     mov   edi,1
112 poddubny 4804
     call  [disable_mouse]
1 ha 4805
     jmp   [putpixel]
4806
 
4807
align 4
4808
 
4809
syscall_writetext:                      ; WriteText
4810
 
4811
     mov   edi,[0x3010]
115 poddubny 4812
     mov   ebp,[edi-twdw+WDATA.box.left]
139 diamond 4813
        push    esi
114 mikedld 4814
        mov     esi,[0x3000]
4815
        shl     esi,8
4816
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
1 ha 4817
     shl   ebp,16
115 poddubny 4818
     add   ebp,[edi-twdw+WDATA.box.top]
114 mikedld 4819
        add     bp,word[esi+0x80000+APPDATA.wnd_clientbox.top]
139 diamond 4820
        pop     esi
117 mario79 4821
     add   ecx,[edi+TASKDATA.mem_start]
1 ha 4822
     add   eax,ebp
4823
     xor   edi,edi
4824
     jmp   dtext
4825
 
4826
align 4
4827
 
4828
syscall_openramdiskfile:                ; OpenRamdiskFile
4829
 
4830
 
4831
     mov   edi,[0x3010]
115 poddubny 4832
     add   edi, TASKDATA.mem_start
1 ha 4833
     add   eax,[edi]
4834
     add   edx,[edi]
4835
     mov   esi,12
4836
     call  fileread
4837
     mov   [esp+36],ebx
4838
     ret
4839
 
4840
align 4
4841
 
4842
syscall_drawrect:                       ; DrawRect
4843
 
4844
     mov   edi,ecx
52 mikedld 4845
     and   edi,0x80FFFFFF
1 ha 4846
     test  ax,ax
4847
     je    drectr
4848
     test  bx,bx
4849
     je    drectr
4850
     movzx ecx,ax
4851
     shr   eax,16
4852
     movzx edx,bx
4853
     shr   ebx,16
114 mikedld 4854
        mov     esi,[0x3000]
4855
        shl     esi,8
4856
        add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
4857
        add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
1 ha 4858
     add   ecx,eax
4859
     add   edx,ebx
4860
     jmp   [drawbar]
4861
    drectr:
4862
     ret
4863
 
4864
align 4
4865
 
4866
syscall_getscreensize:                  ; GetScreenSize
4867
 
4868
     movzx eax,word[0xfe00]
4869
     shl   eax,16
4870
     mov   ax,[0xfe04]
4871
     mov   [esp+36],eax
4872
     ret
4873
 
4874
align 4
4875
 
4876
syscall_cdaudio:                        ; CD
4877
 
4878
     call  sys_cd_audio
4879
     mov   [esp+36],eax
4880
     ret
4881
 
4882
align 4
4883
 
4884
syscall_delramdiskfile:                 ; DelRamdiskFile
4885
 
4886
     mov   edi,[0x3010]
115 poddubny 4887
     add   edi, TASKDATA.mem_start
1 ha 4888
     add   eax,[edi]
4889
     call  filedelete
4890
     mov   [esp+36],eax
4891
     ret
4892
 
4893
align 4
4894
 
4895
syscall_writeramdiskfile:               ; WriteRamdiskFile
4896
 
4897
     mov   edi,[0x3010]
115 poddubny 4898
     add   edi, TASKDATA.mem_start
1 ha 4899
     add   eax,[edi]
4900
     add   ebx,[edi]
4901
     call  filesave
4902
     mov   [esp+36],eax
4903
     ret
4904
 
4905
align 4
4906
 
4907
syscall_getpixel:                       ; GetPixel
4908
     mov   ecx,[0xfe00]
4909
     inc   ecx
4910
     xor   edx,edx
4911
     div   ecx
4912
     mov   ebx,edx
4913
     xchg  eax,ebx
4914
     call  dword [0xe024]
4915
     mov   [esp+36],ecx
4916
     ret
4917
 
4918
align 4
4919
 
4920
syscall_readstring:                     ; ReadString
4921
 
4922
     mov   edi,[0x3010]
115 poddubny 4923
     add   edi, TASKDATA.mem_start
1 ha 4924
     add   eax,[edi]
4925
     call  read_string
4926
     mov   [esp+36],eax
4927
     ret
4928
 
4929
align 4
4930
 
4931
syscall_drawline:                       ; DrawLine
4932
 
4933
     mov   edi,[0x3010]
115 poddubny 4934
     movzx edx,word[edi-twdw+WDATA.box.left]
1 ha 4935
     mov   ebp,edx
114 mikedld 4936
        mov     esi,[0x3000]
4937
        shl     esi,8
4938
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
4939
        add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.left]
1 ha 4940
     shl   edx,16
4941
     add   ebp,edx
115 poddubny 4942
     movzx edx,word[edi-twdw+WDATA.box.top]
1 ha 4943
     add   eax,ebp
4944
     mov   ebp,edx
114 mikedld 4945
        add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.top]
4946
        add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.top]
1 ha 4947
     shl   edx,16
4948
     xor   edi,edi
4949
     add   edx,ebp
4950
     add   ebx,edx
4951
     jmp   [draw_line]
4952
 
4953
align 4
4954
 
4955
syscall_getirqowner:                    ; GetIrqOwner
75 diamond 4956
     cmp   eax,16
4957
     jae   .err
1 ha 4958
     shl   eax,2
4959
     add   eax,irq_owner
4960
     mov   eax,[eax]
4961
     mov   [esp+36],eax
4962
     ret
75 diamond 4963
.err:
4964
     or    dword [esp+36], -1
4965
     ret
1 ha 4966
 
4967
align 4
4968
 
4969
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4970
 
4971
     call  r_f_port_area
4972
     mov   [esp+36],eax
4973
     ret
4974
 
4975
align 4
4976
 
4977
syscall_threads:                        ; CreateThreads
4978
 
4979
     call  sys_threads
4980
     mov   [esp+36],eax
4981
     ret
4982
 
4983
align 4
4984
 
4985
stack_driver_stat:
4986
 
4987
     call  app_stack_handler            ; Stack status
4988
 
4989
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4990
;     call  change_task                 ; between sent packet
4991
 
4992
     mov   [esp+36],eax
4993
     ret
4994
 
4995
align 4
4996
 
4997
socket:                                 ; Socket interface
4998
     call  app_socket_handler
4999
 
5000
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5001
;     call  change_task                 ; between sent packet
5002
 
5003
     mov   [esp+36],eax
5004
     mov   [esp+24],ebx
5005
     ret
5006
 
5007
align 4
5008
 
5009
user_events:                            ; User event times
5010
 
5011
     mov   eax,0x12345678
5012
     mov   [esp+36],eax
5013
 
5014
     ret
5015
 
5016
align 4
5017
 
5018
read_from_hd:                           ; Read from hd - fn not in use
5019
 
5020
     mov   edi,[0x3010]
115 poddubny 5021
     add   edi,TASKDATA.mem_start
1 ha 5022
     add   eax,[edi]
5023
     add   ecx,[edi]
5024
     add   edx,[edi]
5025
     call  file_read
5026
 
5027
     mov   [esp+36],eax
5028
     mov   [esp+24],ebx
5029
 
5030
     ret
5031
 
5032
 
5033
align 4
5034
 
5035
write_to_hd:                            ; Write a file to hd
5036
 
5037
     mov   edi,[0x3010]
115 poddubny 5038
     add   edi,TASKDATA.mem_start
1 ha 5039
     add   eax,[edi]
5040
     add   ecx,[edi]
5041
     add   edx,[edi]
5042
     call  file_write
5043
     ret
5044
 
75 diamond 5045
;  Sysfunction 57, delete_from_hd, is obsolete. Use 58 or 70 functions instead.
5046
;align 4
5047
;
5048
;delete_from_hd:                         ; Delete a file from hd
5049
;
5050
;     mov   edi,[0x3010]
5051
;     add   edi,0x10
5052
;     add   eax,[edi]
5053
;     add   ecx,[edi]
5054
;     call  file_delete
5055
;     ret
5056
;
1 ha 5057
 
76 mario79 5058
; --------------- APM ---------------------
5059
apm_entry    dp    0
5060
apm_vf        dd    0
1 ha 5061
align 4
76 mario79 5062
sys_apm:
5063
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5064
    jne    @f
78 diamond 5065
    or    [esp + 56], byte 1    ; error
76 mario79 5066
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
5067
    ret
5068
 
5069
@@:    xchg    eax, ecx
5070
    xchg    ebx, ecx
5071
 
5072
    cmp    al, 3
5073
    ja    @f
78 diamond 5074
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 5075
    mov    eax, [apm_vf]
5076
    mov    [esp + 36], eax
5077
    shr    eax, 16
5078
    mov    [esp + 32], eax
5079
    ret
78 diamond 5080
 
76 mario79 5081
@@:    call    pword [apm_entry]    ; call APM BIOS
5082
    mov    [esp + 8 ], edi
5083
    mov    [esp + 12], esi
5084
    mov    [esp + 24], ebx
5085
    mov    [esp + 28], edx
5086
    mov    [esp + 32], ecx
5087
    mov    [esp + 36], eax
5088
    setc    al
78 diamond 5089
    and    [esp + 56], byte 0xfe
5090
    or    [esp + 56], al
76 mario79 5091
    ret
5092
; -----------------------------------------
1 ha 5093
 
76 mario79 5094
align 4
5095
 
1 ha 5096
undefined_syscall:                      ; Undefined system call
5097
 
5098
     mov   [esp+36],dword -1
5099
     ret
5100
 
5101
 
5102
;clear_busy_flag_at_caller:
5103
 
5104
;      push  edi
5105
 
5106
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
5107
;      imul  edi,8
5108
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
5109
 
5110
;      pop   edi
5111
 
5112
;      ret
5113
 
5114
 
5115
 
5116
 
5117
keymap:
5118
 
5119
     db   '6',27
5120
     db   '1234567890-=',8,9
5121
     db   'qwertyuiop[]',13
5122
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
5123
     db   '@234567890123',180,178,184,'6',176,'7'
5124
     db   179,'8',181,177,183,185,182
5125
     db   'AB
5126
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5127
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5128
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5129
 
5130
 
5131
keymap_shift:
5132
 
5133
     db   '6',27
5134
     db   '!@#$%^&*()_+',8,9
5135
     db   'QWERTYUIOP{}',13
5136
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
5137
     db   '@234567890123',180,178,184,'6',176,'7'
5138
     db   179,'8',181,177,183,185,182
5139
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
5140
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5141
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5142
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5143
 
5144
 
5145
keymap_alt:
5146
 
5147
     db   ' ',27
5148
     db   ' @ $  {[]}\ ',8,9
5149
     db   '            ',13
5150
     db   '             ',0,'           ',0,'4',0,' '
5151
     db   '             ',180,178,184,'6',176,'7'
5152
     db   179,'8',181,177,183,185,182
5153
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
5154
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5155
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5156
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5157
 
5158
 
5159
; device irq owners
5160
uglobal
5161
irq_owner:       ; process id
5162
 
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
     dd   0x0
5179
endg
5180
 
5181
 
5182
; on irq read ports
5183
uglobal
5184
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5185
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5186
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5187
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5188
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5189
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5190
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5191
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5192
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5193
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5194
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5195
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5196
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5197
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5198
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5199
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5200
endg
5201
 
5202
; status
5203
uglobal
5204
  hd1_status                  dd 0x0  ; 0 - free : other - pid
5205
  application_table_status    dd 0x0  ; 0 - free : other - pid
5206
endg
5207
 
5208
; device addresses
5209
uglobal
5210
  mididp     dd 0x0
5211
  midisp     dd 0x0
5212
 
5213
  cdbase     dd 0x0
5214
  cdid       dd 0x0
5215
 
5216
  hdbase              dd   0x0  ; for boot 0x1f0
5217
  hdid                dd   0x0
5218
  hdpos               dd   0x0  ; for boot 0x1
5219
  fat32part           dd   0x0  ; for boot 0x1
5220
 
5221
  ;part2_ld            dd   0x0
5222
 
102 poddubny 5223
;* start code - Mario79
33 mario79 5224
mouse_pause         dd   0
36 mario79 5225
MouseTickCounter    dd   0
33 mario79 5226
ps2_mouse_detected  db   0
5227
com1_mouse_detected db   0
5228
com2_mouse_detected db   0
102 poddubny 5229
;* end code - Mario79
1 ha 5230
 
5231
wraw_bacground_select db 0
5232
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
5233
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
5234
 
5235
  sb16       dd 0x0
5236
  wss        dd 0x0
5237
 
5238
  buttontype         dd 0x0
5239
  windowtypechanged  dd 0x0
5240
endg
5241
 
5242
iglobal
5243
  keyboard   dd 0x1
5244
  sound_dma  dd 0x1
5245
  syslang    dd 0x1
5246
endg
5247
 
5248
IncludeIGlobals
5249
endofcode:
5250
IncludeUGlobals
5251
uglobals_size = $ - endofcode
41 mikedld 5252
diff16 "end of kernel code",0,$
1 ha 5253