Subversion Repositories Kolibri OS

Rev

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