Subversion Repositories Kolibri OS

Rev

Rev 39 | Rev 41 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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