Subversion Repositories Kolibri OS

Rev

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