Subversion Repositories Kolibri OS

Rev

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