Subversion Repositories Kolibri OS

Rev

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