Subversion Repositories Kolibri OS

Rev

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