Subversion Repositories Kolibri OS

Rev

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