Subversion Repositories Kolibri OS

Rev

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