Subversion Repositories Kolibri OS

Rev

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