Subversion Repositories Kolibri OS

Rev

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