Subversion Repositories Kolibri OS

Rev

Rev 36 | Rev 40 | 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
39 halyavin 2261
     mov  eax,[0xFE8C]
2262
     shr  eax,10
2263
;     mov  eax,[MEM_AllSpace]
2264
;     shl  eax,2
32 halyavin 2265
     ret
2266
no_get_all_space:
2267
 
2268
     ret
1 ha 2269
window_minimize db 0
2270
sound_flag      db 0
2271
last_key_press  dd 0
2272
keyboard_mode_sys db 0
2273
 
2274
iglobal
2275
version_inf:
33 mario79 2276
  db 0,5,2,9  ; version 0.5.2.9
1 ha 2277
  db UID_KOLIBRI
2278
  db 'Kolibri',0
2279
version_end:
2280
endg
2281
 
2282
UID_NONE=0
2283
UID_MENUETOS=1   ;official
2284
UID_KOLIBRI=2    ;russian
2285
 
2286
main_loop_sys_getkey:
2287
    cmp   [0xf400],byte 0
2288
    je    .finish
2289
    movzx eax,byte [0xf401]
2290
    shl   eax,8
2291
    mov   [last_key_press],eax
2292
 .finish:
2293
    ret
2294
 
2295
sys_cachetodiskette:
19 mario79 2296
;    pushad
2297
;    cmp  eax,1
2298
;    jne  no_write_all_of_ramdisk
2299
;    call fdc_writeramdisk
2300
;    popad
2301
;    ret
2302
;  no_write_all_of_ramdisk:
2303
;    cmp eax,2
2304
;    jne no_write_part_of_ramdisk
2305
;    call fdc_commitflush
2306
;    popad
2307
;    ret
2308
;  no_write_part_of_ramdisk:
2309
;    cmp  eax,3
2310
;    jne  no_set_fdc
2311
;    call fdc_set
2312
;    popad
2313
;    ret
2314
;  no_set_fdc:
2315
;    cmp  eax,4
2316
;    jne  no_get_fdc
2317
;    popad
2318
;    call fdc_get
2319
;    mov    [esp+36],ecx
2320
;    ret
2321
;  no_get_fdc:
2322
;    popad
2323
;    ret
2324
    cmp eax,1
2325
    jne no_floppy_a_save
2326
    mov   [flp_number],1
2327
    jmp save_image_on_floppy
2328
  no_floppy_a_save:
1 ha 2329
    cmp eax,2
19 mario79 2330
    jne no_floppy_b_save
2331
    mov   [flp_number],2
2332
  save_image_on_floppy:
2333
    call save_image
2334
    mov  [esp+36],dword 0
2335
    cmp  [FDC_Status],0
2336
    je   yes_floppy_save
2337
  no_floppy_b_save:
2338
    mov [esp+36],dword 1
2339
  yes_floppy_save:
1 ha 2340
    ret
2341
 
2342
uglobal
2343
;  bgrchanged  dd  0x0
2344
endg
2345
 
2346
sys_background:
2347
 
2348
    cmp   eax,1                            ; BACKGROUND SIZE
2349
    jnz   nosb1
2350
    cmp   ebx,0
2351
    je    sbgrr
2352
    cmp   ecx,0
2353
    je    sbgrr
2354
    mov   [display_data-8],ebx
2355
    mov   [display_data-4],ecx
2356
;    mov   [bgrchanged],1
2357
  sbgrr:
2358
    ret
2359
  nosb1:
2360
 
2361
    cmp   eax,2                            ; SET PIXEL
2362
    jnz   nosb2
2363
    mov   edx,0x160000-16
2364
    cmp   edx,ebx
2365
    jbe   nosb2
2366
    mov   edx,[ebx]
2367
    and   edx,0xFF000000 ;255*256*256*256
2368
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2369
    add   edx,ecx
2370
    mov   [ebx+0x300000],edx
2371
;    mov   [bgrchanged],1
2372
    ret
2373
  nosb2:
2374
 
2375
    cmp   eax,3                            ; DRAW BACKGROUND
2376
    jnz   nosb3
2377
draw_background_temp:
2378
;    cmp   [bgrchanged],1 ;0
2379
;    je    nosb31
2380
;draw_background_temp:
2381
;    mov   [bgrchanged],1 ;0
2382
    mov   [0xfff0],byte 1
2383
   nosb31:
2384
    ret
2385
  nosb3:
2386
 
2387
    cmp   eax,4                            ; TILED / STRETCHED
2388
    jnz   nosb4
2389
    cmp   ebx,[display_data-12]
2390
    je    nosb41
2391
    mov   [display_data-12],ebx
2392
;    mov   [bgrchanged],1
2393
   nosb41:
2394
    ret
2395
  nosb4:
2396
 
2397
    cmp   eax,5                            ; BLOCK MOVE TO BGR
2398
    jnz   nosb5
2399
  ; bughere
2400
    mov   edi, [0x3010]
2401
    add   ebx, [edi+0x10]
2402
 ;   mov   esi, ebx
2403
 ;   mov   edi, ecx
2404
    mov   eax, ebx
2405
    mov   ebx, ecx
2406
    add   ecx, edx
2407
    cmp   ecx, 0x160000-16
2408
    ja    .fin
2409
 ;   add   edi, 0x300000
2410
    add   ebx, 0x300000
2411
    mov   ecx, edx
2412
    cmp   ecx, 0x160000-16
2413
    ja    .fin
2414
;    mov   [bgrchanged],1
2415
  ;  cld
2416
  ;  rep   movsb
2417
    call  memmove
2418
  .fin:
2419
    ret
2420
  nosb5:
2421
 
2422
    ret
2423
 
2424
 
2425
align 4
2426
 
2427
sys_getbackground:
2428
 
2429
    cmp   eax,1                                  ; SIZE
2430
    jnz   nogb1
2431
    mov   eax,[display_data-8]
2432
    shl   eax,16
2433
    mov   ax,[display_data-4]
2434
    mov   [esp+36],eax
2435
    ret
2436
  nogb1:
2437
 
2438
    cmp   eax,2                                  ; PIXEL
2439
    jnz   nogb2
2440
    mov   edx,0x160000-16
2441
    cmp   edx,ebx
2442
    jbe   nogb2
2443
    mov   eax, [ebx+0x300000]
2444
    and   eax, 0xFFFFFF
2445
    mov   [esp+36],eax
2446
    ret
2447
  nogb2:
2448
 
2449
    cmp   eax,4                                  ; TILED / STRETCHED
2450
    jnz   nogb4
2451
    mov   eax,[display_data-12]
2452
  nogb4:
2453
    mov   [esp+36],eax
2454
    ret
2455
 
2456
 
2457
align 4
2458
 
2459
sys_getkey:
2460
    mov   [esp+36],dword 1
2461
    mov   ebx, [0x3000]                          ; TOP OF WINDOW STACK
2462
    movzx ecx,word [0xC000 + ebx * 2]
2463
    mov   edx,[0x3004]
2464
    cmp   ecx,edx
2465
    jne   .finish
2466
    cmp   [0xf400],byte 0
2467
    je    .finish
2468
    movzx eax,byte [0xf401]
2469
    shl   eax,8
2470
    push  eax
2471
    dec   byte [0xf400]
2472
    and   byte [0xf400],127
2473
    movzx ecx,byte [0xf400]
2474
    add   ecx,2
2475
 ;   mov   esi,0xf402
2476
 ;   mov   edi,0xf401
2477
 ;   cld
2478
 ;  rep   movsb
2479
    mov   eax, 0xF402
2480
    mov   ebx, 0xF401
2481
    call  memmove
2482
    pop   eax
2483
    mov   [last_key_press],eax
2484
 
2485
    mov   eax,[kb_state]
2486
    and   al,110000b
2487
    cmp   al,100000b
2488
    je    .yes_win_key
2489
    cmp   al,10000b
2490
    je    .yes_win_key
2491
    mov   eax,[last_key_press]
2492
    jmp   .no_win_key
2493
;    cmp   ah,232
2494
;    je    .yes_win_key
2495
;    cmp   ah,233
2496
;    jne   .no_win_key
2497
 .yes_win_key:
2498
    mov   eax,1
2499
 .no_win_key:
2500
    mov   [esp+36],eax
2501
 .finish:
2502
    ret
2503
 
2504
 
2505
align 4
2506
 
2507
sys_getbutton:
2508
 
2509
    mov   ebx, [0x3000]                         ; TOP OF WINDOW STACK
2510
    mov   [esp+36],dword 1
2511
    movzx ecx, word [0xC000 + ebx * 2]
2512
    mov   edx, [0x3004] ; less than 256 processes
2513
    cmp   ecx,edx
2514
    jne   .exit
2515
    movzx eax,byte [0xf500]
2516
    test  eax,eax
2517
    jz    .exit
2518
    mov   eax,[0xf501]
2519
    shl   eax,8
2520
    mov   [0xf500],byte 0
2521
    mov   [esp+36],eax
2522
 .exit:
2523
    ret
2524
 
2525
 
2526
align 4
2527
 
2528
sys_cpuusage:
2529
 
2530
;  RETURN:
2531
;
2532
;  +00 dword     process cpu usage
2533
;  +04  word     position in windowing stack
2534
;  +06  word     windowing stack value at current position (cpu nro)
2535
;  +10 12 bytes  name
2536
;  +22 dword     start in mem
2537
;  +26 dword     used mem
2538
;  +30 dword     PID , process idenfification number
2539
;
2540
 
2541
    mov  edi,[0x3010]   ; eax = return area
2542
    add  edi,0x10
2543
    add  eax,[edi]
2544
 
2545
    cmp  ebx,-1         ; who am I ?
2546
    jne  no_who_am_i
2547
    mov  ebx,[0x3000]
2548
  no_who_am_i:
2549
 
2550
    push eax            ; return area
2551
    push ebx            ; process number
2552
 
2553
    push ebx
2554
    push ebx
2555
    push eax
2556
 
2557
    ; return memory usage
2558
 
2559
    xor  edx,edx
2560
    mov  eax,0x20
2561
    mul  ebx
2562
    add  eax,0x3000+0x1c
2563
    mov  ebx,eax
2564
    pop  eax
2565
    mov  ecx,[ebx]
2566
    mov  [eax],ecx
2567
    pop  ebx
2568
;    mov  ebx,[esp]
2569
;    shl  ebx,1
2570
;    add  ebx,0xc000
2571
    mov  cx, [0xC000 + ebx * 2]
2572
    mov  [eax+4],cx
2573
;    mov  ebx,[esp]
2574
;    shl  ebx,1
2575
;    add  ebx,0xc400
2576
    mov  cx, [0xC400 + ebx * 2]
2577
    mov  [eax+6],cx
2578
;    pop  ebx
2579
    push eax
2580
    mov  eax,ebx
2581
    shl  eax,8
2582
    add  eax,0x80000
2583
    pop  ebx
2584
    add  ebx,10
2585
    mov  ecx,11
2586
    call memmove
2587
 
2588
    ; memory usage
2589
 
2590
    xor    eax,eax
2591
    mov    edx,0x100000*16
2592
    pop    ecx                                   ; get gdt of tss
2593
    cmp    ecx,1
2594
    je     os_mem
2595
    shl    ecx,8
2596
    mov    edx,[0x80000+ecx+0x8c]
2597
    mov    eax,std_application_base_address
2598
    ;add    ecx,0x80000+0x88
2599
    ;mov    ecx,[ecx]
2600
;    shl    ecx,3
2601
    ; eax run base -> edx used memory
2602
;    mov    al,[ecx+gdts+ app_code-3 +4]        ;  base  23:16
2603
;    mov    ah,[ecx+gdts+ app_code-3 +7]        ;  base  31:24
2604
;    shl    eax,16
2605
;    mov    ax,[ecx+gdts+ app_code-3 +2]        ;  base  0:15
2606
;    movzx  edx,word [ecx+gdts+ app_code-3 +0]
2607
;    shl    edx,12
2608
 
2609
  os_mem:
2610
    dec    edx
2611
    mov    [ebx+12],eax
2612
    mov    [ebx+16],edx
2613
 
2614
    ; PID (+30)
2615
 
2616
    mov    eax,[esp]
2617
    shl    eax,5
2618
    add    eax,0x3000+0x4
2619
    mov    eax,[eax]
2620
    mov    [ebx+20],eax
2621
 
2622
    ; window position and size
2623
 
2624
    mov    esi,[esp]
2625
    shl    esi,5
2626
    add    esi,window_data
2627
    mov    edi,[esp+4]
2628
    add    edi,34
2629
    mov    ecx,4*4
2630
    cld
2631
    rep    movsb
2632
 
2633
    ; Process state (+50)
2634
 
2635
    mov    eax,[esp]
2636
    shl    eax,5
2637
    add    eax,0x3000+0xa
2638
    mov    eax,[eax]
2639
    mov    [ebx+40],ax
2640
 
2641
 
2642
    pop    ebx
2643
    pop    eax
2644
 
2645
    ; return number of processes
2646
 
2647
    mov    eax,[0x3004]
2648
    mov    [esp+36],eax
2649
    ret
2650
 
2651
 
2652
 
2653
 
2654
align 4
2655
sys_clock:
2656
        cli
2657
  ; Mikhail Lisovin  xx Jan 2005
2658
  @@:   mov   al, 10
2659
        out   0x70, al
2660
        in    al, 0x71
2661
        test  al, al
2662
        jns   @f
2663
        mov   esi, 1
2664
        call  delay_ms
2665
        jmp   @b
2666
  @@:
2667
  ; end Lisovin's fix
2668
 
2669
        xor   al,al           ; seconds
2670
        out   0x70,al
2671
        in    al,0x71
2672
        movzx ecx,al
2673
        mov   al,02           ; minutes
2674
        shl   ecx,16
2675
        out   0x70,al
2676
        in    al,0x71
2677
        movzx edx,al
2678
        mov   al,04           ; hours
2679
        shl   edx,8
2680
        out   0x70,al
2681
        in    al,0x71
2682
        add   ecx,edx
2683
        movzx edx,al
2684
        add   ecx,edx
2685
        sti
2686
        mov   [esp+36],ecx
2687
        ret
2688
 
2689
 
2690
align 4
2691
 
2692
sys_date:
2693
 
2694
        cli
2695
        mov     al,6            ; day of week
2696
        out     0x70,al
2697
        in      al,0x71
2698
        mov     ch,al
2699
        mov     al,7            ; date
2700
        out     0x70,al
2701
        in      al,0x71
2702
        mov     cl,al
2703
        mov     al,8            ; month
2704
        shl     ecx,16
2705
        out     0x70,al
2706
        in      al,0x71
2707
        mov     ch,al
2708
        mov     al,9            ; year
2709
        out     0x70,al
2710
        in      al,0x71
2711
        mov     cl,al
2712
        sti
2713
        mov     [esp+36],ecx
2714
        ret
2715
 
2716
 
2717
; redraw status
2718
 
2719
sys_redrawstat:
2720
 
2721
    cmp  eax,1
2722
    jne  no_widgets_away
2723
 
2724
    ; buttons away
2725
 
2726
    mov   ecx,[0x3000]
2727
 
2728
  sys_newba2:
2729
 
2730
    mov   edi,[0xfe88]
2731
    cmp   [edi],dword 0  ; empty button list ?
2732
    je    end_of_buttons_away
2733
 
2734
    movzx ebx,word [edi]
2735
    inc   ebx
2736
 
2737
    mov   eax,edi
2738
 
2739
  sys_newba:
2740
 
2741
    dec   ebx
2742
    jz    end_of_buttons_away
2743
 
2744
    add   eax,0x10
2745
    cmp   cx,[eax]
2746
    jnz   sys_newba
2747
 
2748
    push  eax ebx ecx
2749
    mov   ecx,ebx
2750
    inc   ecx
2751
    shl   ecx,4
2752
    mov   ebx,eax
2753
    add   eax,0x10
2754
    call  memmove
2755
    dec   dword [edi]
2756
    pop   ecx ebx eax
2757
 
2758
    jmp   sys_newba2
2759
 
2760
  end_of_buttons_away:
2761
 
2762
    ret
2763
 
2764
  no_widgets_away:
2765
 
2766
    cmp   eax,2
2767
    jnz   srl1
2768
 
2769
    mov   edx,[0x3010]      ; return whole screen draw area for this app
2770
    add   edx,draw_data-0x3000
2771
    mov   [edx+0],dword 0
2772
    mov   [edx+4],dword 0
2773
    mov   eax,[0xfe00]
2774
    mov   [edx+8],eax
2775
    mov   eax,[0xfe04]
2776
    mov   [edx+12],eax
2777
 
2778
    mov   edi,[0x3010]
2779
    sub   edi,twdw
2780
    mov   [edi+30],byte 1   ; no new position & buttons from app
2781
 
2782
    call  sys_window_mouse
2783
 
2784
    ret
2785
 
2786
  srl1:
2787
 
2788
    ret
2789
 
2790
 
2791
sys_drawwindow:
2792
 
2793
    mov   edi,ecx
2794
    shr   edi,16+8
2795
    and   edi,15
2796
 
2797
    cmp   edi,0   ; type I    - original style
2798
    jne   nosyswI
33 mario79 2799
    inc   [mouse_pause]
36 mario79 2800
    call  [disable_mouse]
1 ha 2801
    call  sys_set_window
36 mario79 2802
    call  [disable_mouse]
1 ha 2803
    call  drawwindow_I
33 mario79 2804
    dec   [mouse_pause]
36 mario79 2805
    call   [draw_pointer]
1 ha 2806
    ret
2807
  nosyswI:
2808
 
2809
    cmp   edi,1   ; type II   - only reserve area, no draw
2810
    jne   nosyswII
33 mario79 2811
    inc   [mouse_pause]
36 mario79 2812
    call  [disable_mouse]
1 ha 2813
    call  sys_set_window
36 mario79 2814
    call  [disable_mouse]
1 ha 2815
    call  sys_window_mouse
33 mario79 2816
    dec   [mouse_pause]
36 mario79 2817
    call   [draw_pointer]
1 ha 2818
    ret
2819
  nosyswII:
2820
 
2821
    cmp   edi,2   ; type III  - new style
2822
    jne   nosyswIII
33 mario79 2823
    inc   [mouse_pause]
36 mario79 2824
    call  [disable_mouse]
1 ha 2825
    call  sys_set_window
36 mario79 2826
    call  [disable_mouse]
1 ha 2827
    call  drawwindow_III
33 mario79 2828
    dec   [mouse_pause]
36 mario79 2829
    call   [draw_pointer]
1 ha 2830
    ret
2831
  nosyswIII:
2832
 
2833
    cmp   edi,3   ; type IV - skinned window
2834
    jne   nosyswIV
33 mario79 2835
 
2836
    cli
2837
    mov   edi,[0x3010]
2838
    sub   edi,0x3000
2839
    shr   edi,5
2840
    cmp   edi,[active_process]
35 halyavin 2841
    push  0
33 mario79 2842
    jne   @f
35 halyavin 2843
    mov   byte [esp],1
2844
  @@:             ; parameter for drawwindow_IV
33 mario79 2845
    sti
2846
 
2847
    inc   [mouse_pause]
36 mario79 2848
    call  [disable_mouse]
1 ha 2849
    call  sys_set_window
36 mario79 2850
    call  [disable_mouse]
2851
    call  drawwindow_IV
33 mario79 2852
    dec   [mouse_pause]
36 mario79 2853
    call   [draw_pointer]
1 ha 2854
    ret
2855
  nosyswIV:
2856
 
2857
    ret
2858
 
2859
 
2860
sys_set_window:
2861
 
2862
    mov   edi,[0x3000]
2863
    shl   edi,5
2864
    add   edi,window_data
2865
 
2866
    ; colors
2867
    mov   [edi+16],ecx
2868
    mov   [edi+20],edx
2869
    mov   [edi+24],esi
2870
 
2871
    ; check flag (?)
2872
    cmp   [edi+30],byte 1
2873
    jz    newd
2874
 
2875
    push  eax
2876
    mov   eax,[timer_ticks] ;[0xfdf0]
2877
    add   eax,100
2878
    mov   [new_window_starting],eax
2879
    pop   eax
2880
 
2881
    mov   [edi+8],ax
2882
    mov   [edi+12],bx
2883
    shr   eax,16
2884
    shr   ebx,16
2885
    mov   [edi+00],ax
2886
    mov   [edi+04],bx
2887
 
2888
 
2889
    call  check_window_position
2890
 
2891
 
2892
    push  ecx esi edi               ; save for window fullscreen/resize
2893
    mov   esi,edi
2894
    sub   edi,window_data
2895
    shr   edi,5
2896
    shl   edi,8
2897
    add   edi,0x80000+0x90
2898
    mov   ecx,4
2899
    cld
2900
    rep   movsd
2901
    pop   edi esi ecx
2902
 
2903
    push  eax ebx ecx edx
2904
;;;    mov   eax, 1
2905
;;;    call  delay_hs
2906
    movzx eax, word [edi+00]
2907
    movzx ebx, word [edi+04]
2908
    movzx ecx, word [edi+8]
2909
    movzx edx, word [edi+12]
2910
    add   ecx, eax
2911
    add   edx, ebx
2912
    call  calculatescreen
2913
    pop   edx ecx ebx eax
2914
 
2915
    mov   [0xf400],byte 0           ; empty keyboard buffer
2916
    mov   [0xf500],byte 0           ; empty button buffer
2917
 
2918
  newd:
2919
    mov   [edi+31],byte 0   ; no redraw
2920
    mov   edx,edi
2921
 
2922
    ret
2923
 
2924
 
2925
sys_window_move:
2926
 
2927
        cmp  [window_move_pr],0
2928
        je   mwrl1
2929
 
2930
        mov  [esp+36],dword 1         ; return queue error
2931
 
2932
        ret
2933
 
2934
     mwrl1:
2935
 
2936
        mov   edi,[0x3000]            ; requestor process base
2937
        mov   [window_move_pr],edi
2938
 
2939
        mov   [window_move_eax],eax
2940
        mov   [window_move_ebx],ebx
2941
        mov   [window_move_ecx],ecx
2942
        mov   [window_move_edx],edx
2943
 
2944
        mov   [esp+36],dword 0        ; return success
2945
 
2946
        ret
2947
 
2948
type_background_1:
2949
    cmp   [0xfff0],byte 0               ; background update ?
2950
    jz    temp_nobackgr
2951
    mov   [0xfff0],byte 2
2952
    call  change_task
2953
    mov   [draw_data+32+0],dword 0
2954
    mov   [draw_data+32+4],dword 0
2955
    mov   eax,[0xfe00]
2956
    mov   ebx,[0xfe04]
2957
    mov   [draw_data+32+8],eax
2958
    mov   [draw_data+32+12],ebx
2959
    call  drawbackground
2960
    mov   [0xfff0],byte 0
2961
    mov   [0xfff4],byte 0
2962
temp_nobackgr:
2963
    ret
2964
 
2965
uglobal
2966
  window_move_pr   dd  0x0
2967
  window_move_eax  dd  0x0
2968
  window_move_ebx  dd  0x0
2969
  window_move_ecx  dd  0x0
2970
  window_move_edx  dd  0x0
2971
endg
2972
 
2973
;ok - 100% work
2974
;nt - not tested
2975
;---------------------------------------------------------------------------------------------
2976
;eax
2977
;0 - task switch counter. Ret switch counter in eax. Block. ok.
2978
;1 - change task. Ret nothing. Block. ok.
2979
;2 - performance control
2980
; ebx
2981
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
2982
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
2983
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
2984
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
2985
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
2986
;eax
2987
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2988
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
2989
;---------------------------------------------------------------------------------------------
2990
sys_sheduler: ;noname & halyavin
2991
    cmp eax,0
2992
    je shed_counter
2993
    cmp eax,2
2994
    je perf_control
2995
    cmp eax,3
2996
    je rdmsr_instr
2997
    cmp eax,4
2998
    je wrmsr_instr
2999
    cmp eax,1
3000
    jne not_supported
3001
    call change_task ;delay,0
3002
ret
3003
shed_counter:
3004
    mov eax,[context_counter]
3005
    mov [esp+36],eax
3006
not_supported:
3007
ret
3008
perf_control:
3009
    inc eax ;now eax=3
3010
    cmp ebx,eax
3011
    je cache_disable
3012
    dec eax
3013
    cmp ebx,eax
3014
    je cache_enable
3015
    dec eax
3016
    cmp ebx,eax
3017
    je is_cache_enabled
3018
    dec eax
3019
    cmp ebx,eax
3020
    je modify_pce
3021
ret
3022
 
3023
rdmsr_instr:
3024
;now counter in ecx
3025
;(edx:eax) esi:edi => edx:esi
3026
mov eax,esi
3027
rdmsr
3028
mov [esp+36],eax
3029
mov [esp+24],edx ;ret in ebx?
3030
ret
3031
 
3032
wrmsr_instr:
3033
;now counter in ecx
3034
;(edx:eax) esi:edi => edx:esi
3035
mov eax,esi
3036
wrmsr
3037
mov [esp+36],eax
3038
mov [esp+24],edx ;ret in ebx?
3039
ret
3040
 
3041
cache_disable:
3042
       mov eax,cr0
3043
       or  eax,01100000000000000000000000000000b
3044
       mov cr0,eax
3045
       wbinvd ;set MESI
3046
ret
3047
 
3048
cache_enable:
3049
       mov eax,cr0
3050
       and eax,10011111111111111111111111111111b
3051
       mov cr0,eax
3052
ret
3053
 
3054
is_cache_enabled:
3055
       mov eax,cr0
3056
       mov ebx,eax
3057
       and eax,01100000000000000000000000000000b
3058
       jz cache_disabled
3059
       mov [esp+36],ebx
3060
cache_disabled:
3061
       mov dword [esp+36],eax ;0
3062
ret
3063
 
3064
modify_pce:
3065
       mov eax,cr4
3066
;       mov ebx,0
3067
;       or  bx,100000000b ;pce
3068
;       xor eax,ebx ;invert pce
17 me_root 3069
       bts eax,8 ;pce=cr4[8]
1 ha 3070
       mov cr4,eax
3071
       mov [esp+36],eax
3072
ret
3073
;---------------------------------------------------------------------------------------------
3074
 
3075
 
3076
; check if pixel is allowed to be drawn
3077
 
3078
checkpixel:
21 poddubny 3079
        push eax edx
1 ha 3080
 
3081
        mov  edx,[0xfe00]     ; screen x size
3082
        inc  edx
21 poddubny 3083
        imul edx, ebx
1 ha 3084
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
3085
 
21 poddubny 3086
        mov  eax, [0x3010]
1 ha 3087
 
21 poddubny 3088
        xor  ecx, ecx
3089
        cmp  byte [eax+0xe], dl
3090
        setne cl
1 ha 3091
 
21 poddubny 3092
        pop  edx eax
1 ha 3093
        ret
3094
 
3095
uglobal
3096
  mouse_active  db  0
3097
endg
3098
iglobal
3099
  cpustring db 'CPU        '
3100
endg
3101
 
3102
 
3103
align 4
3104
; check misc
3105
 
3106
checkmisc:
3107
 
3108
    cmp   [ctrl_alt_del], 1
3109
    jne   nocpustart
3110
    mov   eax, cpustring
3111
    call  start_application_fl
3112
    mov   [ctrl_alt_del], 0
3113
  nocpustart:
3114
    cmp   [mouse_active], 1
3115
    jne   mouse_not_active
3116
    mov   [mouse_active], 0
3117
    xor   edi, edi
3118
    mov   ecx, [0x3004]
3119
   set_mouse_event:
3120
    add   edi, 256
3121
    or    [edi+0x80000+0xA8], dword 00100000b
3122
    loop  set_mouse_event
3123
  mouse_not_active:
3124
 
3125
 
3126
    cmp   [0xfff0],byte 0               ; background update ?
3127
    jz    nobackgr
3128
    mov   [0xfff0],byte 2
3129
    call  change_task
3130
    mov   [draw_data+32+0],dword 0
3131
    mov   [draw_data+32+4],dword 0
3132
    mov   eax,[0xfe00]
3133
    mov   ebx,[0xfe04]
3134
    mov   [draw_data+32+8],eax
3135
    mov   [draw_data+32+12],ebx
3136
    call  drawbackground
3137
    mov   [0xfff0],byte 0
3138
    mov   [0xfff4],byte 0
3139
 
3140
  nobackgr:
3141
 
3142
 
3143
    ; system shutdown request
3144
 
3145
    cmp  [0xFF00],byte 0
3146
    je   noshutdown
3147
 
3148
    mov  edx,[shutdown_processes]
3149
    sub  dl,2
3150
 
3151
    cmp  [0xff00],dl
3152
    jne  no_mark_system_shutdown
3153
 
3154
    mov   edx,0x3040
3155
    movzx ecx,byte [0xff00]
3156
    add   ecx,5
3157
  markz:
3158
    mov   [edx+0xa],byte 3
3159
    add   edx,0x20
3160
    loop  markz
3161
 
3162
  no_mark_system_shutdown:
3163
 
3164
    call [disable_mouse]
3165
 
3166
    dec  byte [0xff00]
3167
 
3168
    cmp  [0xff00],byte 0
3169
    je   system_shutdown
3170
 
3171
  noshutdown:
3172
 
3173
 
3174
    mov   eax,[0x3004]                  ; termination
3175
    mov   ebx,0x3020+0xa
3176
    mov   esi,1
3177
 
3178
  newct:
3179
    mov   cl,[ebx]
3180
    cmp   cl,byte 3
3181
    jz    terminate
3182
    cmp   cl,byte 4
3183
    jz    terminate
3184
 
3185
    add   ebx,0x20
3186
    inc   esi
3187
    dec   eax
3188
    jnz   newct
3189
 
3190
    ret
3191
 
3192
 
3193
 
3194
 
3195
; redraw screen
3196
 
3197
redrawscreen:
3198
 
3199
; eax , if process window_data base is eax, do not set flag/limits
3200
 
3201
         pushad
3202
         push  eax
3203
 
3204
;;;         mov   eax,2
3205
;;;         call  delay_hs
3206
 
3207
         ;mov   ecx,0               ; redraw flags for apps
3208
         xor   ecx,ecx
3209
       newdw2:
3210
 
3211
         inc   ecx
3212
         push  ecx
3213
 
3214
         mov   eax,ecx
3215
         shl   eax,5
3216
         add   eax,window_data
3217
 
3218
         cmp   eax,[esp+4]
3219
         je    not_this_task
3220
                                   ; check if window in redraw area
3221
         mov   edi,eax
3222
 
3223
         cmp   ecx,1               ; limit for background
3224
         jz    bgli
3225
 
3226
         mov   eax,[edi+0]
3227
         mov   ebx,[edi+4]
3228
         mov   ecx,[edi+8]
3229
         mov   edx,[edi+12]
3230
         add   ecx,eax
3231
         add   edx,ebx
3232
 
3233
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3234
         cmp   ecx,ebx
3235
         jb    ricino
3236
 
3237
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3238
         cmp   ecx,eax
3239
         jb    ricino
3240
 
3241
         mov   eax,[edi+0]
3242
         mov   ebx,[edi+4]
3243
         mov   ecx,[edi+8]
3244
         mov   edx,[edi+12]
3245
         add   ecx,eax
3246
         add   edx,ebx
3247
 
3248
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3249
         cmp   edx,eax
3250
         jb    ricino
3251
 
3252
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3253
         cmp   ecx,eax
3254
         jb    ricino
3255
 
3256
        bgli:
3257
 
3258
         cmp   edi,esi
3259
         jz    ricino
3260
 
3261
         mov   eax,edi
3262
         add   eax,draw_data-window_data
3263
 
3264
         mov   ebx,[dlx]          ; set limits
3265
         mov   [eax+0],ebx
3266
         mov   ebx,[dly]
3267
         mov   [eax+4],ebx
3268
         mov   ebx,[dlxe]
3269
         mov   [eax+8],ebx
3270
         mov   ebx,[dlye]
3271
         mov   [eax+12],ebx
3272
 
3273
         sub   eax,draw_data-window_data
3274
 
3275
         cmp   ecx,1
3276
         jne   nobgrd
3277
         cmp   esi,1
3278
         je    newdw8
3279
         call  drawbackground
3280
 
3281
       newdw8:
3282
       nobgrd:
3283
 
3284
         mov   [eax+31],byte 1    ; mark as redraw
3285
 
3286
       ricino:
3287
 
3288
       not_this_task:
3289
 
3290
         pop   ecx
3291
 
3292
         cmp   ecx,[0x3004]
3293
         jle   newdw2
3294
 
3295
         pop  eax
3296
         popad
3297
 
3298
         ret
3299
 
3300
calculatebackground:   ; background
3301
 
3302
        ; all black
3303
 
3304
        mov   [display_data-8],dword 4      ; size x
3305
        mov   [display_data-4],dword 2      ; size y
3306
 
3307
        mov   edi, 0x300000                 ; set background to black
3308
        xor   eax, eax
3309
        mov   ecx, 0x0fff00 / 4
3310
        cld
3311
        rep   stosd
3312
 
3313
        mov   edi,display_data              ; set os to use all pixels
3314
        mov   eax,0x01010101
3315
        mov   ecx,0x1fff00 / 4
3316
        rep   stosd
3317
 
3318
        mov   byte [0xFFF0], 0              ; do not draw background!
3319
 
3320
        ret
3321
 
3322
uglobal
3323
  imax    dd 0x0
3324
endg
3325
 
3326
 
3327
 
3328
delay_ms:     ; delay in 1/1000 sec
3329
 
3330
 
3331
        push  eax
3332
        push  ecx
3333
 
3334
        mov   ecx,esi
3335
        ; 
3336
        imul  ecx, 33941
3337
        shr   ecx, 9
3338
        ; 
3339
 
3340
        in    al,0x61
3341
        and   al,0x10
3342
        mov   ah,al
3343
        cld
3344
 
3345
 cnt1:  in    al,0x61
3346
        and   al,0x10
3347
        cmp   al,ah
3348
        jz    cnt1
3349
 
3350
        mov   ah,al
3351
        loop  cnt1
3352
 
3353
        pop   ecx
3354
        pop   eax
3355
 
3356
        ret
3357
 
3358
 
3359
set_app_param:
3360
        push edi
3361
 
3362
        mov  edi,[0x3010]
3363
        mov  [edi],eax
3364
 
3365
        pop  edi
3366
        ret
3367
 
3368
 
3369
 
3370
delay_hs:     ; delay in 1/100 secs
3371
        push  eax
3372
        push  ecx
3373
        push  edx
3374
 
3375
        mov   edx,[timer_ticks];[0xfdf0]
3376
        add   edx,eax
3377
 
3378
      newtic:
3379
        mov   ecx,[timer_ticks];[0xfdf0]
3380
        cmp   edx,ecx
3381
        jbe   zerodelay
3382
 
3383
        call  change_task
3384
 
3385
        jmp   newtic
3386
 
3387
      zerodelay:
3388
        pop   edx
3389
        pop   ecx
3390
        pop   eax
3391
 
3392
        ret
3393
 
3394
 
3395
memmove:       ; memory move in bytes
3396
 
3397
; eax = from
3398
; ebx = to
3399
; ecx = no of bytes
3400
    test ecx, ecx
3401
    jle  .ret
3402
 
3403
 
3404
    push esi edi ecx
3405
 
3406
    mov  edi, ebx
3407
    mov  esi, eax
3408
 
3409
    test ecx, not 11b
3410
    jz   @f
3411
 
3412
    push ecx
3413
    shr  ecx, 2
3414
    rep  movsd
3415
    pop  ecx
3416
    and  ecx, 11b
3417
    jz   .finish
3418
  @@:
3419
    rep  movsb
3420
 
3421
  .finish:
3422
    pop  ecx edi esi
3423
  .ret:
3424
    ret
3425
 
3426
 
3427
align 4
3428
 
3429
read_floppy_file:
3430
 
3431
; as input
3432
;
3433
; eax pointer to file
3434
; ebx file lenght
3435
; ecx start 512 byte block number
3436
; edx number of blocks to read
3437
; esi pointer to return/work area (atleast 20 000 bytes)
3438
;
3439
;
3440
; on return
3441
;
3442
; eax = 0 command succesful
3443
;       1 no fd base and/or partition defined
3444
;       2 yet unsupported FS
3445
;       3 unknown FS
3446
;       4 partition not defined at hd
3447
;       5 file not found
3448
; ebx = size of file
3449
 
3450
     mov   edi,[0x3010]
3451
     add   edi,0x10
3452
     add   esi,[edi]
3453
     add   eax,[edi]
3454
 
3455
     pushad
3456
     mov  edi,esi
3457
     add  edi,1024
3458
     mov  esi,0x100000+19*512
3459
     sub  ecx,1
3460
     shl  ecx,9
3461
     add  esi,ecx
3462
     shl  edx,9
3463
     mov  ecx,edx
3464
     cld
3465
     rep  movsb
3466
     popad
3467
 
3468
     mov   [esp+36],eax
3469
     mov   [esp+24],ebx
3470
     ret
3471
 
3472
 
3473
 
3474
align 4
3475
 
3476
sys_programirq:
3477
 
3478
    mov   edi,[0x3010]
3479
    add   edi,0x10
3480
    add   eax,[edi]
3481
 
3482
    mov   edx,ebx
3483
    shl   edx,2
3484
    add   edx,irq_owner
3485
    mov   edx,[edx]
3486
    mov   edi,[0x3010]
3487
    mov   edi,[edi+0x4]
3488
    cmp   edx,edi
3489
    je    spril1
3490
    mov   [esp+36],dword 1
3491
    ret
3492
  spril1:
3493
 
3494
    mov   esi,eax
3495
    shl   ebx,6
3496
    add   ebx,irq00read
3497
    mov   edi,ebx
3498
    mov   ecx,16
3499
    cld
3500
    rep   movsd
3501
    mov   [esp+36],dword 0
3502
    ret
3503
 
3504
 
3505
align 4
3506
 
3507
get_irq_data:
3508
 
3509
     mov   edx,eax           ; check for correct owner
3510
     shl   edx,2
3511
     add   edx,irq_owner
3512
     mov   edx,[edx]
3513
     mov   edi,[0x3010]
3514
     mov   edi,[edi+0x4]
3515
     cmp   edx,edi
3516
     je    gidril1
3517
     mov   [esp+36],eax
3518
     mov   [esp+32],dword 2
3519
     mov   [esp+24],ebx
3520
     ret
3521
 
3522
  gidril1:
3523
 
3524
     mov   ebx,eax
3525
     shl   ebx,12
3526
     add   ebx,0x2e0000
3527
     mov   eax,[ebx]
3528
     mov   ecx,1
3529
     test  eax,eax
3530
     jz    gid1
3531
 
3532
     dec   eax
3533
     mov   esi,ebx
3534
     mov   [ebx],eax
3535
     movzx ebx,byte [ebx+0x10]
3536
     add   esi,0x10
3537
     mov   edi,esi
3538
     inc   esi
3539
     mov   ecx,4000 / 4
3540
     cld
3541
     rep   movsd
3542
     xor   ecx,ecx
3543
   gid1:
3544
     mov   [esp+36],eax
3545
     mov   [esp+32],ecx
3546
     mov   [esp+24],ebx
3547
     ret
3548
 
3549
 
3550
set_io_access_rights:
3551
 
3552
     pushad
3553
 
3554
     mov   edi,[0x3000]
3555
     imul  edi,tss_step
3556
     add   edi,tss_data+128
3557
;     add   edi,128
3558
 
3559
     mov   ecx,eax
3560
     and   ecx,7    ; offset in byte
3561
 
3562
     shr   eax,3    ; number of byte
3563
     add   edi,eax
3564
 
3565
     mov   ebx,1
3566
     shl   ebx,cl
3567
 
3568
     cmp   ebp,0                ; enable access - ebp = 0
3569
     jne   siar1
3570
 
3571
     not   ebx
3572
     and   [edi],byte bl
3573
 
3574
     popad
3575
 
3576
     ret
3577
 
3578
   siar1:
3579
 
3580
     or    [edi],byte bl        ; disable access - ebp = 1
3581
 
3582
     popad
3583
 
3584
     ret
3585
 
3586
 
3587
 
3588
 
3589
 
3590
r_f_port_area:
3591
 
3592
     test  eax, eax
3593
     jnz   free_port_area
3594
;     je    r_port_area
3595
;     jmp   free_port_area
3596
 
3597
;   r_port_area:
3598
 
3599
     pushad
3600
 
3601
     cmp   ebx,ecx            ; beginning > end ?
3602
     jg    rpal1
3603
     mov   esi,[0x2d0000]
3604
     cmp   esi,0              ; no reserved areas ?
3605
     je    rpal2
3606
     cmp   esi,255            ; max reserved
3607
     jge   rpal1
3608
   rpal3:
3609
     mov   edi,esi
3610
     shl   edi,4
3611
     add   edi,0x2d0000
3612
     cmp   ebx,[edi+8]
3613
     jg    rpal4
3614
     cmp   ecx,[edi+4]
3615
     jae   rpal1
3616
;     jb    rpal4
3617
;     jmp   rpal1
3618
   rpal4:
3619
 
3620
     dec   esi
3621
     jnz   rpal3
3622
     jmp   rpal2
3623
   rpal1:
3624
     popad
3625
     mov   eax,1
3626
     ret
3627
 
3628
   rpal2:
3629
     popad
3630
 
3631
 
3632
     ; enable port access at port IO map
3633
     cli
3634
     pushad                        ; start enable io map
3635
 
3636
     cmp   ecx,65536 ;16384
3637
     jae   no_unmask_io ; jge
3638
 
3639
     mov   eax,ebx
3640
 
3641
   new_port_access:
3642
 
3643
     pushad
3644
 
3645
     mov   ebp,0                  ; enable - eax = port
3646
     call  set_io_access_rights
3647
 
3648
     popad
3649
 
3650
     inc   eax
3651
     cmp   eax,ecx
3652
     jbe   new_port_access
3653
 
3654
   no_unmask_io:
3655
 
3656
     popad                         ; end enable io map
3657
     sti
3658
 
3659
     mov   edi,[0x2d0000]
3660
     add   edi,1
3661
     mov   [0x2d0000],edi
3662
     shl   edi,4
3663
     add   edi,0x2d0000
3664
     mov   esi,[0x3010]
3665
     mov   esi,[esi+0x4]
3666
     mov   [edi],esi
3667
     mov   [edi+4],ebx
3668
     mov   [edi+8],ecx
3669
 
3670
     xor   eax, eax
3671
     ret
3672
 
3673
 
3674
 
3675
 
3676
free_port_area:
3677
 
3678
     pushad
3679
 
3680
     mov   esi,[0x2d0000]     ; no reserved areas ?
3681
     cmp   esi,0
3682
     je    frpal2
3683
     mov   edx,[0x3010]
3684
     mov   edx,[edx+4]
3685
   frpal3:
3686
     mov   edi,esi
3687
     shl   edi,4
3688
     add   edi,0x2d0000
3689
     cmp   edx,[edi]
3690
     jne   frpal4
3691
     cmp   ebx,[edi+4]
3692
     jne   frpal4
3693
     cmp   ecx,[edi+8]
3694
     jne   frpal4
3695
     jmp   frpal1
3696
   frpal4:
3697
     dec   esi
3698
     jnz   frpal3
3699
   frpal2:
3700
     popad
3701
     mov   eax,1
3702
     ret
3703
   frpal1:
3704
     mov   ecx,256
3705
     sub   ecx,esi
3706
     shl   ecx,4
3707
     mov   esi,edi
3708
     add   esi,16
3709
     cld
3710
     rep   movsb
3711
 
3712
     dec   dword [0x2d0000]
3713
 
3714
     popad
3715
 
3716
 
3717
     ; disable port access at port IO map
3718
 
3719
     pushad                        ; start disable io map
3720
 
3721
     cmp   ecx,65536 ;16384
3722
     jge   no_mask_io
3723
 
3724
     mov   eax,ebx
3725
 
3726
   new_port_access_disable:
3727
 
3728
     pushad
3729
 
3730
     mov   ebp,1                  ; disable - eax = port
3731
     call  set_io_access_rights
3732
 
3733
     popad
3734
 
3735
     inc   eax
3736
     cmp   eax,ecx
3737
     jbe   new_port_access_disable
3738
 
3739
   no_mask_io:
3740
 
3741
     popad                         ; end disable io map
3742
 
3743
     xor   eax, eax
3744
     ret
3745
 
3746
 
3747
reserve_free_irq:
3748
 
3749
     cmp   eax,0
3750
     jz    reserve_irq
3751
 
3752
     mov   edi,ebx
3753
     shl   edi,2
3754
     add   edi,irq_owner
3755
     mov   edx,[edi]
3756
     mov   eax,[0x3010]
3757
     mov   eax,[eax+0x4]
3758
     mov   ecx,1
3759
     cmp   edx,eax
3760
     jne   fril1
3761
     mov   [edi],dword 0
3762
     mov   ecx,0
3763
   fril1:
3764
     mov   [esp+36],ecx ; return in eax
3765
     ret
3766
 
3767
  reserve_irq:
3768
 
3769
     mov   edi,ebx
3770
     shl   edi,2
3771
     add   edi,irq_owner
3772
     mov   edx,[edi]
3773
     mov   ecx,1
3774
     cmp   edx,0
3775
     jne   ril1
3776
 
3777
     mov   edx,[0x3010]
3778
     mov   edx,[edx+0x4]
3779
     mov   [edi],edx
3780
     mov   ecx,0
3781
 
3782
   ril1:
3783
 
3784
     mov   [esp+36],ecx ; return in eax
3785
 
3786
     ret
3787
 
3788
 
3789
 
3790
drawbackground:
33 mario79 3791
       inc   [mouse_pause]
1 ha 3792
       cmp   [0xfe0c],word 0x12
3793
       jne   dbrv12
3794
       cmp   [display_data-12],dword 1
3795
       jne   bgrstr12
3796
       call  vga_drawbackground_tiled
33 mario79 3797
       dec   [mouse_pause]
36 mario79 3798
       call   [draw_pointer]
1 ha 3799
       ret
3800
     bgrstr12:
3801
       call  vga_drawbackground_stretch
33 mario79 3802
       dec   [mouse_pause]
36 mario79 3803
       call   [draw_pointer]
1 ha 3804
       ret
3805
     dbrv12:
3806
 
3807
       cmp  [0xfe0c],word 0100000000000000b
3808
       jge  dbrv20
3809
       cmp  [0xfe0c],word 0x13
3810
       je   dbrv20
3811
       call  vesa12_drawbackground
33 mario79 3812
       dec   [mouse_pause]
36 mario79 3813
       call   [draw_pointer]
1 ha 3814
       ret
3815
     dbrv20:
3816
       cmp   [display_data-12],dword 1
3817
       jne   bgrstr
3818
       call  vesa20_drawbackground_tiled
33 mario79 3819
       dec   [mouse_pause]
36 mario79 3820
       call   [draw_pointer]
1 ha 3821
       ret
3822
     bgrstr:
3823
       call  vesa20_drawbackground_stretch
33 mario79 3824
       dec   [mouse_pause]
36 mario79 3825
       call   [draw_pointer]
1 ha 3826
       ret
3827
 
3828
 
33 mario79 3829
 
1 ha 3830
sys_putimage:
36 mario79 3831
;     inc   [mouse_pause]
1 ha 3832
     cmp   [0xfe0c],word 0x12
3833
     jne   spiv20
3834
     call  vga_putimage
36 mario79 3835
;     dec   [mouse_pause]
3836
     call   [draw_pointer]
1 ha 3837
     ret
3838
   spiv20:
3839
     cmp   [0xfe0c],word 0100000000000000b
3840
     jge   piv20
3841
     cmp   [0xfe0c],word 0x13
3842
     je    piv20
3843
     call  vesa12_putimage
36 mario79 3844
;     dec   [mouse_pause]
3845
     call   [draw_pointer]
1 ha 3846
     ret
3847
   piv20:
3848
     call  vesa20_putimage
36 mario79 3849
;     dec   [mouse_pause]
3850
     call   [draw_pointer]
1 ha 3851
     ret
3852
 
3853
 
3854
 
3855
; eax x beginning
3856
; ebx y beginning
3857
; ecx x end
3858
; edx y end
3859
; edi color
3860
 
3861
__sys_drawbar:
33 mario79 3862
    inc   [mouse_pause]
3863
    cmp   [0xfe0c],word 0x12
3864
    jne   sdbv20
3865
    call  vga_drawbar
3866
    dec   [mouse_pause]
36 mario79 3867
    call   [draw_pointer]
33 mario79 3868
    ret
1 ha 3869
   sdbv20:
3870
    cmp  [0xfe0c],word 0100000000000000b
3871
    jge  dbv20
3872
    cmp  [0xfe0c],word 0x13
3873
    je   dbv20
3874
    call vesa12_drawbar
33 mario79 3875
    dec   [mouse_pause]
36 mario79 3876
    call   [draw_pointer]
1 ha 3877
    ret
3878
  dbv20:
3879
    call vesa20_drawbar
33 mario79 3880
    dec   [mouse_pause]
36 mario79 3881
    call   [draw_pointer]
1 ha 3882
    ret
3883
 
3884
 
3885
 
3886
kb_read:
3887
 
3888
        push    ecx edx
3889
 
3890
        mov     ecx,0xffff
3891
      kr_loop:
3892
        in      al,0x64
3893
        test    al,1
3894
        jnz     kr_ready
3895
        loop    kr_loop
3896
        mov     ah,1
3897
        jmp     kr_exit
3898
      kr_ready:
3899
        push    ecx
3900
        mov     ecx,32
3901
      kr_delay:
3902
        loop    kr_delay
3903
        pop     ecx
3904
        in      al,0x60
3905
        xor     ah,ah
3906
      kr_exit:
3907
 
3908
        pop     edx ecx
3909
 
3910
        ret
3911
 
3912
 
3913
kb_write:
3914
 
3915
        push    ecx edx
3916
 
3917
        mov     dl,al
3918
        mov     ecx,0xffff
3919
      kw_loop1:
3920
        in      al,0x64
3921
        test    al,0x20
3922
        jz      kw_ok1
3923
        loop    kw_loop1
3924
        mov     ah,1
3925
        jmp     kw_exit
3926
      kw_ok1:
3927
        in      al,0x60
3928
        mov     ecx,0xffff
3929
      kw_loop:
3930
        in      al,0x64
3931
        test    al,2
3932
        jz      kw_ok
3933
        loop    kw_loop
3934
        mov     ah,1
3935
        jmp     kw_exit
3936
      kw_ok:
3937
        mov     al,dl
3938
        out     0x60,al
3939
        mov     ecx,0xffff
3940
      kw_loop3:
3941
        in      al,0x64
3942
        test    al,2
3943
        jz      kw_ok3
3944
        loop    kw_loop3
3945
        mov     ah,1
3946
        jmp     kw_exit
3947
      kw_ok3:
3948
        mov     ah,8
3949
      kw_loop4:
3950
        mov     ecx,0xffff
3951
      kw_loop5:
3952
        in      al,0x64
3953
        test    al,1
3954
        jnz     kw_ok4
3955
        loop    kw_loop5
3956
        dec     ah
3957
        jnz     kw_loop4
3958
      kw_ok4:
3959
        xor     ah,ah
3960
      kw_exit:
3961
 
3962
        pop     edx ecx
3963
 
3964
        ret
3965
 
3966
 
3967
kb_cmd:
3968
 
3969
        mov     ecx,0xffff
3970
      c_wait:
3971
        in      al,0x64
3972
        test    al,2
3973
        jz      c_send
3974
        loop    c_wait
3975
        jmp     c_error
3976
      c_send:
3977
        mov     al,bl
3978
        out     0x64,al
3979
        mov     ecx,0xffff
3980
      c_accept:
3981
        in      al,0x64
3982
        test    al,2
3983
        jz      c_ok
3984
        loop    c_accept
3985
      c_error:
3986
        mov     ah,1
3987
        jmp     c_exit
3988
      c_ok:
3989
        xor     ah,ah
3990
      c_exit:
3991
        ret
3992
 
3993
 
3994
setmouse:  ; set mousepicture -pointer
3995
           ; ps2 mouse enable
3996
 
3997
     mov     [0xf200],dword mousepointer
3998
 
3999
     cli
33 mario79 4000
;     mov     bl,0xa8                 ; enable mouse cmd
4001
;     call    kb_cmd
4002
;     call    kb_read                 ; read status
4003
;     mov     bl,0x20                 ; get command byte
4004
;     call    kb_cmd
4005
;     call    kb_read
4006
;     or      al,3                    ; enable interrupt
4007
;     mov     bl,0x60                 ; write command
4008
;     push    eax
4009
;     call    kb_cmd
4010
;     pop     eax
4011
;     call    kb_write
4012
;     mov     bl,0xd4                 ; for mouse
4013
;     call    kb_cmd
4014
;     mov     al,0xf4                 ; enable mouse device
4015
;     call    kb_write
4016
;     call    kb_read           ; read status return
1 ha 4017
 
4018
     ; com1 mouse enable
4019
 
4020
     mov   bx,0x3f8 ; combase
4021
 
4022
     mov   dx,bx
4023
     add   dx,3
4024
     mov   al,0x80
4025
     out   dx,al
4026
 
4027
     mov   dx,bx
4028
     add   dx,1
4029
     mov   al,0
4030
     out   dx,al
4031
 
4032
     mov   dx,bx
4033
     add   dx,0
4034
     mov   al,0x30*2    ; 0x30 / 4
4035
     out   dx,al
4036
 
4037
     mov   dx,bx
4038
     add   dx,3
4039
     mov   al,2         ; 3
4040
     out   dx,al
4041
 
4042
     mov   dx,bx
4043
     add   dx,4
4044
     mov   al,0xb
4045
     out   dx,al
4046
 
4047
     mov   dx,bx
4048
     add   dx,1
4049
     mov   al,1
4050
     out   dx,al
4051
 
4052
 
4053
     ; com2 mouse enable
4054
 
4055
     mov   bx,0x2f8 ; combase
4056
 
4057
     mov   dx,bx
4058
     add   dx,3
4059
     mov   al,0x80
4060
     out   dx,al
4061
 
4062
     mov   dx,bx
4063
     add   dx,1
4064
     mov   al,0
4065
     out   dx,al
4066
 
4067
     mov   dx,bx
4068
     add   dx,0
4069
     mov   al,0x30*2
4070
     out   dx,al
4071
 
4072
     mov   dx,bx
4073
     add   dx,3
4074
     mov   al,2
4075
     out   dx,al
4076
 
4077
     mov   dx,bx
4078
     add   dx,4
4079
     mov   al,0xb
4080
     out   dx,al
4081
 
4082
     mov   dx,bx
4083
     add   dx,1
4084
     mov   al,1
4085
     out   dx,al
4086
 
4087
     ret
4088
 
4089
 
4090
_rdtsc:
4091
 
4092
     mov   edx,[cpuid_1+3*4]
4093
     test  edx,00010000b
4094
     jz    ret_rdtsc
4095
     rdtsc
4096
     ret
4097
   ret_rdtsc:
4098
     mov   edx,0xffffffff
4099
     mov   eax,0xffffffff
4100
     ret
4101
 
4102
 
4103
 
4104
rerouteirqs:
4105
 
4106
        cli
4107
 
4108
        mov     al,0x11         ;  icw4, edge triggered
4109
        out     0x20,al
4110
        call    pic_delay
4111
        out     0xA0,al
4112
        call    pic_delay
4113
 
4114
        mov     al,0x20         ;  generate 0x20 +
4115
        out     0x21,al
4116
        call    pic_delay
4117
        mov     al,0x28         ;  generate 0x28 +
4118
        out     0xA1,al
4119
        call    pic_delay
4120
 
4121
        mov     al,0x04         ;  slave at irq2
4122
        out     0x21,al
4123
        call    pic_delay
4124
        mov     al,0x02         ;  at irq9
4125
        out     0xA1,al
4126
        call    pic_delay
4127
 
4128
        mov     al,0x01         ;  8086 mode
4129
        out     0x21,al
4130
        call    pic_delay
4131
        out     0xA1,al
4132
        call    pic_delay
4133
 
4134
        mov     al,255          ; mask all irq's
4135
        out     0xA1,al
4136
        call    pic_delay
4137
        out     0x21,al
4138
        call    pic_delay
4139
 
4140
        mov     ecx,0x1000
4141
        cld
4142
picl1:  call    pic_delay
4143
        loop    picl1
4144
 
4145
        mov     al,255          ; mask all irq's
4146
        out     0xA1,al
4147
        call    pic_delay
4148
        out     0x21,al
4149
        call    pic_delay
4150
 
4151
        cli
4152
 
4153
        ret
4154
 
4155
 
4156
pic_delay:
4157
 
4158
        jmp     pdl1
4159
pdl1:   ret
4160
 
4161
 
4162
sys_msg_board_str:
4163
 
4164
     pushad
4165
   @@:
4166
     cmp    [esi],byte 0
4167
     je     @f
4168
     mov    eax,1
4169
     movzx  ebx,byte [esi]
4170
     call   sys_msg_board
4171
     inc    esi
4172
     jmp    @b
4173
   @@:
4174
     popad
4175
     ret
4176
 
4177
uglobal
4178
  msg_board_data: times 512 db 0
4179
  msg_board_count dd 0x0
4180
endg
4181
 
4182
sys_msg_board:
4183
 
4184
; eax=1 : write :  bl byte to write
4185
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4186
 
4187
     mov  ecx,[msg_board_count]
4188
     cmp  eax, 1
4189
     jne  smbl1
4190
 
4191
 
4192
     mov  [msg_board_data+ecx],bl
4193
     inc  ecx
4194
     and  ecx, 511
4195
     mov  [msg_board_count], ecx
4196
     mov  [check_idle_semaphore], 5
4197
     ret
4198
   smbl1:
4199
 
4200
     cmp   eax, 2
4201
     jne   smbl2
4202
     test  ecx, ecx
4203
     jz    smbl21
4204
;     mov   edi, msg_board_data
4205
;     mov   esi, msg_board_data+1
4206
;     movzx eax, byte [edi]
4207
     mov   eax, msg_board_data+1
4208
     mov   ebx, msg_board_data
4209
     movzx edx, byte [ebx]
4210
     call  memmove
4211
;     push  ecx
4212
;     shr   ecx, 2
4213
;     cld
4214
;     rep   movsd
4215
;     pop   ecx
4216
;     and   ecx, 3
4217
;     rep   movsb
4218
     dec   [msg_board_count]
4219
     mov   [esp+36], edx ;eax
4220
     mov   [esp+24], dword 1
4221
     ret
4222
   smbl21:
4223
     mov   [esp+36], ecx
4224
     mov   [esp+24], ecx
4225
 
4226
   smbl2:
4227
     ret
4228
 
4229
 
4230
 
4231
sys_trace:
4232
 
4233
     test eax, eax                  ; get event data
4234
     jnz  no_get_sys_events
4235
 
4236
     mov  esi,save_syscall_data     ; data
4237
     mov  edi,[0x3010]
4238
     mov  edi,[edi+0x10]
4239
     add  edi,ebx
4240
     cld
4241
     rep  movsb
4242
 
4243
     mov  [esp+24],dword 0
4244
     mov  eax,[save_syscall_count]  ; count
4245
     mov  [esp+36],eax
4246
     ret
4247
 
4248
   no_get_sys_events:
4249
 
4250
     ret
4251
 
4252
 
4253
sys_process_def:
4254
 
4255
     cmp   eax,1                   ; set keyboard mode
4256
     jne   no_set_keyboard_setup
4257
 
4258
     mov   edi,[0x3000]
4259
     shl   edi,8
4260
     add   edi,0x80000+0xB4
4261
     mov   [edi],bl
4262
 
4263
     ret
4264
 
4265
   no_set_keyboard_setup:
4266
 
4267
     cmp   eax,2                   ; get keyboard mode
4268
     jne   no_get_keyboard_setup
4269
 
4270
     mov   edi,[0x3000]
4271
     shl   edi,8
4272
     add   edi,0x80000+0xB4
4273
     movzx eax, byte [edi]
4274
 
4275
     mov   [esp+36],eax
4276
 
4277
     ret
4278
 
4279
   no_get_keyboard_setup:
4280
 
4281
     cmp   eax,3                   ; get keyboard ctrl, alt, shift
4282
     jne   no_get_keyboard_cas
4283
 
4284
;     xor   eax,eax
4285
;     movzx eax,byte [shift]
4286
;     movzx ebx,byte [ctrl]
4287
;     shl   ebx,2
4288
;     add   eax,ebx
4289
;     movzx ebx,byte [alt]
4290
;     shl   ebx,3
4291
;     add   eax,ebx
4292
 
4293
 ;// mike.dld [
4294
     mov   eax, [kb_state]
4295
 ;// mike.dld ]
4296
 
4297
     mov   [esp+36],eax
4298
 
4299
     ret
4300
 
4301
   no_get_keyboard_cas:
4302
 
4303
 
4304
     ret
4305
 
4306
 
4307
sys_ipc:
4308
     cmp  eax,1                      ; DEFINE IPC MEMORY
4309
     jne  no_ipc_def
4310
     mov  edi,[0x3000]
4311
     shl  edi,8
4312
     add  edi,0x80000
4313
     mov  [edi+0xA0],ebx
4314
     mov  [edi+0xA4],ecx
4315
     mov  [esp+36],dword 0
4316
     ret
4317
   no_ipc_def:
4318
 
4319
     cmp  eax,2                      ; SEND IPC MESSAGE
4320
     jne  no_ipc_send
4321
     mov  esi,1
4322
     mov  edi,0x3020
4323
    ipcs1:
4324
     cmp  [edi+4],ebx
4325
     je   ipcs2
4326
     add  edi,0x20
4327
     inc  esi
4328
     cmp  esi,[0x3004]
4329
     jbe  ipcs1
4330
     mov  [esp+36],dword 4
4331
     ret
4332
    ipcs2:
4333
 
4334
     cli
4335
 
4336
     push esi
4337
     mov  eax,esi
4338
     shl  eax,8
4339
     mov  ebx,[eax+0x80000+0xa0]
4340
     test ebx,ebx                  ; ipc area not defined ?
4341
     je   ipc_err1
4342
 
4343
     add  ebx,[eax+0x80000+0xa4]
4344
     mov  eax,esi
4345
     shl  eax,5
4346
     add  ebx,[eax+0x3000+0x10]    ; ebx <- max data position
4347
 
4348
     mov  eax,esi                  ; to
4349
     shl  esi,8
4350
     add  esi,0x80000
4351
     mov  edi,[esi+0xa0]
4352
     shl  eax,5
4353
     add  eax,0x3000
4354
     add  edi,[eax+0x10]
4355
 
4356
     cmp  [edi],byte 0             ; overrun ?
4357
     jne  ipc_err2
4358
 
4359
     mov  ebp,edi
4360
     add  edi,[edi+4]
4361
     add  edi,8
4362
 
4363
     mov  esi,ecx                  ; from
4364
     mov  eax,[0x3010]
4365
     mov  eax,[eax+0x10]
4366
     add  esi,eax
4367
 
4368
     mov  ecx,edx                  ; size
4369
 
4370
     mov  eax,edi
4371
     add  eax,ecx
4372
     cmp  eax,ebx
4373
     jge  ipc_err3                 ; not enough room ?
4374
 
4375
     push ecx
4376
 
4377
     mov  eax,[0x3010]
4378
     mov  eax,[eax+4]
4379
     mov  [edi-8],eax
4380
     mov  [edi-4],ecx
4381
     cld
4382
     rep  movsb
4383
 
4384
     pop  ecx
4385
     add  ecx,8
4386
 
4387
     mov  edi,ebp                  ; increase memory position
4388
     add  dword [edi+4],ecx
4389
 
4390
     mov  edi,[esp]
4391
     shl  edi,8
4392
     or   dword [edi+0x80000+0xA8],dword 01000000b ; ipc message
4393
 
4394
     cmp  [check_idle_semaphore],dword 20
4395
     jge  ipc_no_cis
4396
     mov  [check_idle_semaphore],5
4397
   ipc_no_cis:
4398
 
4399
     xor  eax, eax
4400
 
4401
    ipc_err:
4402
     add  esp,4
4403
     mov  [esp+36],eax
4404
     sti
4405
     ret
4406
 
4407
    ipc_err1:
4408
     add  esp,4
4409
     mov  [esp+36],dword 1
4410
     sti
4411
     ret
4412
    ipc_err2:
4413
     add  esp,4
4414
     mov  [esp+36],dword 2
4415
     sti
4416
     ret
4417
    ipc_err3:
4418
     add  esp,4
4419
     mov  [esp+36],dword 3
4420
     sti
4421
     ret
4422
 
4423
   no_ipc_send:
4424
 
4425
     mov  [esp+36],dword -1
4426
     ret
4427
 
4428
 
4429
align 4
4430
 
4431
sys_gs:                         ; direct screen access
4432
 
4433
     cmp  eax,1                 ; resolution
4434
     jne  no_gs1
4435
     mov  eax,[0xfe00]
4436
     shl  eax,16
4437
     mov  ax,[0xfe04]
4438
     add  eax,0x00010001
4439
     mov  [esp+36],eax
4440
     ret
4441
   no_gs1:
4442
 
4443
     cmp   eax,2                ; bits per pixel
4444
     jne   no_gs2
4445
     movzx eax,byte [0xfbf1]
4446
     mov   [esp+36],eax
4447
     ret
4448
   no_gs2:
4449
 
4450
     cmp   eax,3                ; bytes per scanline
4451
     jne   no_gs3
4452
     mov   eax,[0xfe08]
4453
     mov   [esp+36],eax
4454
     ret
4455
   no_gs3:
4456
 
4457
     mov  [esp+36],dword -1
4458
     ret
4459
 
4460
 
4461
align 4 ; PCI functions
4462
 
4463
sys_pci:
4464
 
4465
     call  pci_api
4466
     mov   [esp+36],eax
4467
     ret
4468
 
4469
 
4470
align 4  ;  system functions
4471
 
4472
syscall_setpixel:                       ; SetPixel
4473
 
4474
 
4475
     mov   edx,[0x3010]
4476
     add   eax,[edx-twdw]
4477
     add   ebx,[edx-twdw+4]
33 mario79 4478
;     xor   edi,edi ; no force
4479
     mov   edi,1
4480
;     call  [disable_mouse]
1 ha 4481
     jmp   [putpixel]
4482
 
4483
align 4
4484
 
4485
syscall_writetext:                      ; WriteText
4486
 
4487
     mov   edi,[0x3010]
4488
     mov   ebp,[edi-twdw]
4489
     shl   ebp,16
4490
     add   ebp,[edi-twdw+4]
4491
     add   edi,0x10
4492
     add   ecx,[edi]
4493
     add   eax,ebp
4494
     xor   edi,edi
4495
     jmp   dtext
4496
 
4497
align 4
4498
 
4499
syscall_openramdiskfile:                ; OpenRamdiskFile
4500
 
4501
 
4502
     mov   edi,[0x3010]
4503
     add   edi,0x10
4504
     add   eax,[edi]
4505
     add   edx,[edi]
4506
     mov   esi,12
4507
     call  fileread
4508
     mov   [esp+36],ebx
4509
     ret
4510
 
4511
align 4
4512
 
4513
syscall_putimage:                       ; PutImage
4514
 
4515
     mov   edi,[0x3010]
4516
     add   edi,0x10
4517
     add   eax,[edi]
4518
     mov   edx,ecx
4519
     mov   ecx,ebx
4520
     mov   ebx,eax
4521
     call  sys_putimage
4522
     mov   [esp+36],eax
4523
     ret
4524
 
4525
align 4
4526
 
4527
syscall_drawrect:                       ; DrawRect
4528
 
4529
     mov   edi,ecx
4530
     test  ax,ax
4531
     je    drectr
4532
     test  bx,bx
4533
     je    drectr
4534
     movzx ecx,ax
4535
     shr   eax,16
4536
     movzx edx,bx
4537
     shr   ebx,16
4538
     add   ecx,eax
4539
     add   edx,ebx
4540
     jmp   [drawbar]
4541
    drectr:
4542
     ret
4543
 
4544
align 4
4545
 
4546
syscall_getscreensize:                  ; GetScreenSize
4547
 
4548
     movzx eax,word[0xfe00]
4549
     shl   eax,16
4550
     mov   ax,[0xfe04]
4551
     mov   [esp+36],eax
4552
     ret
4553
 
4554
align 4
4555
 
4556
syscall_system:                         ; System
4557
 
4558
     call  sys_system
4559
     mov   [esp+36],eax
4560
     ret
4561
 
4562
align 4
4563
 
4564
syscall_startapp:                       ; StartApp
4565
     mov   edi,[0x3010]
4566
     add   edi,0x10
4567
     add   eax,[edi]
4568
     test  ebx,ebx
4569
     jz    noapppar
4570
     add   ebx,[edi]
4571
   noapppar:
4572
;     call  start_application_fl
4573
     call   new_start_application_fl
4574
     mov   [esp+36],eax
4575
     ret
4576
 
4577
 
4578
align 4
4579
 
4580
syscall_cdaudio:                        ; CD
4581
 
4582
     call  sys_cd_audio
4583
     mov   [esp+36],eax
4584
     ret
4585
 
4586
align 4
4587
 
4588
syscall_readhd:                         ; ReadHd
4589
 
4590
     mov   edi,[0x3010]
4591
     add   edi,0x10
4592
     add   esi,[edi]
4593
     add   eax,[edi]
4594
     call  read_hd_file
4595
     mov   [esp+36],eax
4596
     mov   [esp+24],ebx
4597
     ret
4598
 
4599
align 4
4600
 
4601
syscall_starthdapp:                     ; StartHdApp
4602
 
4603
     mov   edi,[0x3010]
4604
     add   edi,0x10
4605
     add   eax,[edi]
4606
     add   ecx,[edi]
4607
     mov   ebp,0
4608
     call  start_application_hd
4609
     mov   [esp+36],eax
4610
     ret
4611
 
4612
align 4
4613
 
4614
syscall_delramdiskfile:                 ; DelRamdiskFile
4615
 
4616
     mov   edi,[0x3010]
4617
     add   edi,0x10
4618
     add   eax,[edi]
4619
     call  filedelete
4620
     mov   [esp+36],eax
4621
     ret
4622
 
4623
align 4
4624
 
4625
syscall_writeramdiskfile:               ; WriteRamdiskFile
4626
 
4627
     mov   edi,[0x3010]
4628
     add   edi,0x10
4629
     add   eax,[edi]
4630
     add   ebx,[edi]
4631
     call  filesave
4632
     mov   [esp+36],eax
4633
     ret
4634
 
4635
align 4
4636
 
4637
syscall_getpixel:                       ; GetPixel
4638
 
4639
     mov   ecx,[0xfe00]
4640
     inc   ecx
4641
     xor   edx,edx
4642
     div   ecx
4643
     mov   ebx,edx
4644
     xchg  eax,ebx
4645
     call  dword [0xe024]
4646
     mov   [esp+36],ecx
4647
     ret
4648
 
4649
align 4
4650
 
4651
syscall_readstring:                     ; ReadString
4652
 
4653
     mov   edi,[0x3010]
4654
     add   edi,0x10
4655
     add   eax,[edi]
4656
     call  read_string
4657
     mov   [esp+36],eax
4658
     ret
4659
 
4660
align 4
4661
 
4662
syscall_drawline:                       ; DrawLine
4663
 
4664
     mov   edi,[0x3010]
4665
     movzx edx,word[edi-twdw]
4666
     mov   ebp,edx
4667
     shl   edx,16
4668
     add   ebp,edx
4669
     movzx edx,word[edi-twdw+4]
4670
     add   eax,ebp
4671
     mov   ebp,edx
4672
     shl   edx,16
4673
     xor   edi,edi
4674
     add   edx,ebp
4675
     add   ebx,edx
4676
     jmp   [draw_line]
4677
 
4678
align 4
4679
 
4680
syscall_getirqowner:                    ; GetIrqOwner
4681
 
4682
     shl   eax,2
4683
     add   eax,irq_owner
4684
     mov   eax,[eax]
4685
     mov   [esp+36],eax
4686
     ret
4687
 
4688
align 4
4689
 
4690
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
4691
 
4692
     call  r_f_port_area
4693
     mov   [esp+36],eax
4694
     ret
4695
 
14 poddubny 4696
;align 4
1 ha 4697
 
4698
syscall_appints:                        ; AppInts
14 poddubny 4699
;    mov   [esp+36],dword -1
1 ha 4700
     ret
4701
 
4702
align 4
4703
 
4704
syscall_threads:                        ; CreateThreads
4705
 
4706
     call  sys_threads
4707
     mov   [esp+36],eax
4708
     ret
4709
 
4710
align 4
4711
 
4712
stack_driver_stat:
4713
 
4714
     call  app_stack_handler            ; Stack status
4715
 
4716
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4717
;     call  change_task                 ; between sent packet
4718
 
4719
     mov   [esp+36],eax
4720
     ret
4721
 
4722
align 4
4723
 
4724
socket:                                 ; Socket interface
4725
     call  app_socket_handler
4726
 
4727
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4728
;     call  change_task                 ; between sent packet
4729
 
4730
     mov   [esp+36],eax
4731
     mov   [esp+24],ebx
4732
     ret
4733
 
4734
align 4
4735
 
4736
user_events:                            ; User event times
4737
 
4738
     mov   eax,0x12345678
4739
     mov   [esp+36],eax
4740
 
4741
     ret
4742
 
4743
align 4
4744
 
4745
read_from_hd:                           ; Read from hd - fn not in use
4746
 
4747
     mov   edi,[0x3010]
4748
     add   edi,0x10
4749
     add   eax,[edi]
4750
     add   ecx,[edi]
4751
     add   edx,[edi]
4752
     call  file_read
4753
 
4754
     mov   [esp+36],eax
4755
     mov   [esp+24],ebx
4756
 
4757
     ret
4758
 
4759
 
4760
align 4
4761
 
4762
write_to_hd:                            ; Write a file to hd
4763
 
4764
     mov   edi,[0x3010]
4765
     add   edi,0x10
4766
     add   eax,[edi]
4767
     add   ecx,[edi]
4768
     add   edx,[edi]
4769
     call  file_write
4770
     ret
4771
 
4772
align 4
4773
 
4774
delete_from_hd:                         ; Delete a file from hd
4775
 
4776
     mov   edi,[0x3010]
4777
     add   edi,0x10
4778
     add   eax,[edi]
4779
     add   ecx,[edi]
4780
     call  file_delete
4781
     ret
4782
 
4783
 
4784
align 4
4785
 
4786
undefined_syscall:                      ; Undefined system call
4787
 
4788
     mov   [esp+36],dword -1
4789
     ret
4790
 
4791
 
4792
;clear_busy_flag_at_caller:
4793
 
4794
;      push  edi
4795
 
4796
;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
4797
;      imul  edi,8
4798
;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
4799
 
4800
;      pop   edi
4801
 
4802
;      ret
4803
 
4804
 
4805
 
4806
 
4807
keymap:
4808
 
4809
     db   '6',27
4810
     db   '1234567890-=',8,9
4811
     db   'qwertyuiop[]',13
4812
     db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
4813
     db   '@234567890123',180,178,184,'6',176,'7'
4814
     db   179,'8',181,177,183,185,182
4815
     db   'AB
4816
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4817
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4818
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4819
 
4820
 
4821
keymap_shift:
4822
 
4823
     db   '6',27
4824
     db   '!@#$%^&*()_+',8,9
4825
     db   'QWERTYUIOP{}',13
4826
     db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
4827
     db   '@234567890123',180,178,184,'6',176,'7'
4828
     db   179,'8',181,177,183,185,182
4829
     db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
4830
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4831
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4832
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4833
 
4834
 
4835
keymap_alt:
4836
 
4837
     db   ' ',27
4838
     db   ' @ $  {[]}\ ',8,9
4839
     db   '            ',13
4840
     db   '             ',0,'           ',0,'4',0,' '
4841
     db   '             ',180,178,184,'6',176,'7'
4842
     db   179,'8',181,177,183,185,182
4843
     db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
4844
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4845
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4846
     db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
4847
 
4848
 
4849
; device irq owners
4850
uglobal
4851
irq_owner:       ; process id
4852
 
4853
     dd   0x0
4854
     dd   0x0
4855
     dd   0x0
4856
     dd   0x0
4857
     dd   0x0
4858
     dd   0x0
4859
     dd   0x0
4860
     dd   0x0
4861
     dd   0x0
4862
     dd   0x0
4863
     dd   0x0
4864
     dd   0x0
4865
     dd   0x0
4866
     dd   0x0
4867
     dd   0x0
4868
     dd   0x0
4869
endg
4870
 
4871
 
4872
; on irq read ports
4873
uglobal
4874
  irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4875
  irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4876
  irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4877
  irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4878
  irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4879
  irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4880
  irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4881
  irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4882
  irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4883
  irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4884
  irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4885
  irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4886
  irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4887
  irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4888
  irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4889
  irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
4890
endg
4891
 
4892
; status
4893
uglobal
4894
  hd1_status                  dd 0x0  ; 0 - free : other - pid
4895
  application_table_status    dd 0x0  ; 0 - free : other - pid
4896
endg
4897
 
4898
; device addresses
4899
uglobal
4900
  mididp     dd 0x0
4901
  midisp     dd 0x0
4902
 
4903
  cdbase     dd 0x0
4904
  cdid       dd 0x0
4905
 
4906
  hdbase              dd   0x0  ; for boot 0x1f0
4907
  hdid                dd   0x0
4908
  hdpos               dd   0x0  ; for boot 0x1
4909
  fat32part           dd   0x0  ; for boot 0x1
4910
 
4911
  ;part2_ld            dd   0x0
4912
 
4913
;* start code - get  process (3) - Mario79
4914
active_process      dd   0
33 mario79 4915
active_process_flag db   0
4916
deleted_process     dd   0
4917
mouse_pause         dd   0
36 mario79 4918
MouseTickCounter    dd   0
33 mario79 4919
ps2_mouse_detected  db   0
4920
com1_mouse_detected db   0
4921
com2_mouse_detected db   0
1 ha 4922
;* end code - get active process (3) - Mario79
4923
 
4924
wraw_bacground_select db 0
4925
  lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
4926
  pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
4927
 
4928
  sb16       dd 0x0
4929
  wss        dd 0x0
4930
 
4931
  buttontype         dd 0x0
4932
  windowtypechanged  dd 0x0
4933
endg
4934
 
4935
iglobal
4936
  keyboard   dd 0x1
4937
  sound_dma  dd 0x1
4938
  syslang    dd 0x1
33 mario79 4939
  active_proc_stack_coun dd 0xa400-4
1 ha 4940
endg
4941
 
4942
IncludeIGlobals
4943
endofcode:
4944
IncludeUGlobals
4945
uglobals_size = $ - endofcode
4946
diff16 "end of kernel code",$
4947