Subversion Repositories Kolibri OS

Rev

Rev 115 | Rev 119 | 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   edx,eax
  1411.      mov   ecx,65
  1412.      sub   ecx,eax
  1413.      add   ecx,esp
  1414.      add   ecx,4
  1415.      mov   eax,[esp+64+32-8+4]
  1416.      mov   ebx,[esp+64+32-12+4]
  1417.      push  edx                       ; add window start x & y
  1418.      push  ebx
  1419.      mov   edx,[0x3010]
  1420.      mov   ebx,[edx-twdw+WDATA.box.left]
  1421.      shl   ebx,16
  1422.      add   ebx,[edx-twdw+WDATA.box.top]
  1423.      add   eax,ebx
  1424.      pop   ebx
  1425.      pop   edx
  1426.      mov   edi,0
  1427.      call  dtext
  1428.  
  1429.      ret
  1430.  
  1431.  
  1432. read_string:
  1433.  
  1434.     ; eax  read_area
  1435.     ; ebx  color of letter
  1436.     ; ecx  color of background
  1437.     ; edx  number of letters to read
  1438.     ; esi  [x start]*65536 + [y_start]
  1439.  
  1440.     ret
  1441.  
  1442.  
  1443. align 4
  1444.  
  1445. sys_setup:
  1446.  
  1447. ; 1=roland mpu midi base , base io address
  1448. ; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
  1449. ; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  1450. ; 4=sb16 base , base io address
  1451. ; 5=system language, 1eng 2fi 3ger 4rus
  1452. ; 6=wss base , base io address
  1453. ; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  1454. ; 8=fat32 partition in hd
  1455. ; 9
  1456. ; 10 = sound dma channel
  1457. ; 11 = enable lba read
  1458. ; 12 = enable pci access
  1459.  
  1460.  
  1461.      mov  [esp+36],dword 0
  1462.      cmp  eax,1                      ; MIDI
  1463.      jnz  nsyse1
  1464.      cmp  ebx,0x100
  1465.      jb   nsyse1
  1466.      mov  edx,65535
  1467.      cmp  edx,ebx
  1468.      jb   nsyse1
  1469.      mov  [midi_base],bx
  1470.      mov  word [mididp],bx
  1471.      inc  bx
  1472.      mov  word [midisp],bx
  1473.      ret
  1474.  
  1475. midi_base dw 0
  1476.  
  1477.    nsyse1:
  1478.  
  1479.      cmp  eax,2                      ; KEYBOARD
  1480.      jnz  nsyse2
  1481.      cmp  ebx,1
  1482.      jnz  kbnobase
  1483.      mov  edi,[0x3010]
  1484.      add  ecx,[edi+TASKDATA.mem_start]
  1485.      mov  eax,ecx
  1486.      mov  ebx,keymap
  1487.      mov  ecx,128
  1488.      call memmove
  1489.      ret
  1490.    kbnobase:
  1491.      cmp  ebx,2
  1492.      jnz  kbnoshift
  1493.      mov  edi,[0x3010]
  1494.      add  ecx,[edi+TASKDATA.mem_start]
  1495.      mov  eax,ecx
  1496.      mov  ebx,keymap_shift
  1497.      mov  ecx,128
  1498.      call memmove
  1499.      ret
  1500.    kbnoshift:
  1501.      cmp  ebx,3
  1502.      jne  kbnoalt
  1503.      mov  edi,[0x3010]
  1504.      add  ecx,[edi+TASKDATA.mem_start]
  1505.      mov  eax,ecx
  1506.      mov  ebx,keymap_alt
  1507.      mov  ecx,128
  1508.      call memmove
  1509.      ret
  1510.    kbnoalt:
  1511.      cmp  ebx,9
  1512.      jnz  kbnocountry
  1513.      mov  word [keyboard],cx
  1514.      ret
  1515.    kbnocountry:
  1516.      mov  [esp+36],dword 1
  1517.      ret
  1518.    nsyse2:
  1519.      cmp  eax,3                      ; CD
  1520.      jnz  nsyse3
  1521.      test ebx,ebx
  1522.      jz   nosesl
  1523.      cmp  ebx, 4
  1524.      ja   nosesl
  1525.      mov  [cd_base],bl
  1526.      cmp  ebx,1
  1527.      jnz  noprma
  1528.      mov  [cdbase],0x1f0
  1529.      mov  [cdid],0xa0
  1530.    noprma:
  1531.      cmp  ebx,2
  1532.      jnz  noprsl
  1533.      mov  [cdbase],0x1f0
  1534.      mov  [cdid],0xb0
  1535.    noprsl:
  1536.      cmp  ebx,3
  1537.      jnz  nosema
  1538.      mov  [cdbase],0x170
  1539.      mov  [cdid],0xa0
  1540.    nosema:
  1541.      cmp  ebx,4
  1542.      jnz  nosesl
  1543.      mov  [cdbase],0x170
  1544.      mov  [cdid],0xb0
  1545.    nosesl:
  1546.      ret
  1547.  
  1548. cd_base db 0
  1549.  
  1550.    nsyse3:
  1551.  
  1552.      cmp  eax,4                      ; SB
  1553.      jnz  nsyse4
  1554.      cmp  ebx,0x100
  1555.      jb   nsyse4
  1556.      mov  edx,65535
  1557.      cmp  edx,ebx
  1558.      jb   nsyse4
  1559.      mov  word [sb16],bx
  1560.      ret
  1561.    nsyse4:
  1562.  
  1563.      cmp  eax,5                      ; SYSTEM LANGUAGE
  1564.      jnz  nsyse5
  1565.      mov  [syslang],ebx
  1566.      ret
  1567.    nsyse5:
  1568.  
  1569.      cmp  eax,6                      ; WSS
  1570.      jnz  nsyse6
  1571.      cmp  ebx,0x100
  1572.      jb   nsyse6
  1573.      mov  [wss],ebx
  1574.      ret
  1575.  
  1576. wss_temp dd 0
  1577.  
  1578.    nsyse6:
  1579.  
  1580.      cmp  eax,7                      ; HD BASE
  1581.      jne  nsyse7
  1582.      test ebx,ebx
  1583.      jz   nosethd
  1584.      cmp  ebx,4
  1585.      ja   nosethd
  1586.      mov  [hd_base],bl
  1587.      cmp  ebx,1
  1588.      jnz  noprmahd
  1589.      mov  [hdbase],0x1f0
  1590.      mov  [hdid],0x0
  1591.      mov  [hdpos],1
  1592. ;     call set_FAT32_variables
  1593.    noprmahd:
  1594.      cmp  ebx,2
  1595.      jnz  noprslhd
  1596.      mov  [hdbase],0x1f0
  1597.      mov  [hdid],0x10
  1598.      mov  [hdpos],2
  1599. ;     call set_FAT32_variables
  1600.    noprslhd:
  1601.      cmp  ebx,3
  1602.      jnz  nosemahd
  1603.      mov  [hdbase],0x170
  1604.      mov  [hdid],0x0
  1605.      mov  [hdpos],3
  1606. ;     call set_FAT32_variables
  1607.    nosemahd:
  1608.      cmp  ebx,4
  1609.      jnz  noseslhd
  1610.      mov  [hdbase],0x170
  1611.      mov  [hdid],0x10
  1612.      mov  [hdpos],4
  1613. ;     call set_FAT32_variables
  1614.    noseslhd:
  1615.      mov   [0xfe10],dword 0
  1616.     call  reserve_hd1
  1617.     call  clear_hd_cache
  1618.     mov   [hd1_status],0        ; free
  1619.    nosethd:
  1620.      ret
  1621.  
  1622. hd_base db 0
  1623.  
  1624.    nsyse7:
  1625.  
  1626.      cmp  eax,8                      ; HD PARTITION
  1627.      jne  nsyse8
  1628.      mov  [fat32part],ebx
  1629. ;     call set_FAT32_variables
  1630.     call  reserve_hd1
  1631.     call  clear_hd_cache
  1632.      pusha
  1633.      call  choice_necessity_partition_1
  1634.      popa
  1635.     mov   [hd1_status],0        ; free
  1636.      ret
  1637.    nsyse8:
  1638.  
  1639.      cmp  eax,10                     ; SOUND DMA CHANNEL
  1640.      jne  no_set_sound_dma
  1641.      cmp  ebx,3
  1642.      ja   sys_setup_err
  1643.      mov  [sound_dma],ebx
  1644.      ret
  1645.    no_set_sound_dma:
  1646.  
  1647.      cmp  eax,11                     ; ENABLE LBA READ
  1648.      jne  no_set_lba_read
  1649.      and  ebx,1
  1650.      mov  [lba_read_enabled],ebx
  1651.      ret
  1652.    no_set_lba_read:
  1653.  
  1654.      cmp  eax,12                     ; ENABLE PCI ACCESS
  1655.      jne  no_set_pci_access
  1656.      and  ebx,1
  1657.      mov  [pci_access_enabled],ebx
  1658.      ret
  1659.    no_set_pci_access:
  1660.  
  1661. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1662. include 'vmodeint.inc'
  1663. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1664.  
  1665. sys_setup_err:
  1666.      mov  [esp+36],dword -1
  1667.      ret
  1668.  
  1669.  
  1670. align 4
  1671.  
  1672. sys_getsetup:
  1673.  
  1674. ; 1=roland mpu midi base , base io address
  1675. ; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
  1676. ; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  1677. ; 4=sb16 base , base io address
  1678. ; 5=system language, 1eng 2fi 3ger 4rus
  1679. ; 6=wss base
  1680. ; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  1681. ; 8=fat32 partition in hd
  1682. ; 9=get hs timer tic
  1683.  
  1684.      cmp  eax,1
  1685.      jne  ngsyse1
  1686.      movzx eax,[midi_base]
  1687.      mov  [esp+36],eax
  1688.      ret
  1689.    ngsyse1:
  1690.  
  1691.      cmp  eax,2
  1692.      jne  ngsyse2
  1693.      cmp  ebx,1
  1694.      jnz  kbnobaseret
  1695.      mov  edi,[0x3010]
  1696.      add  ecx,[edi+TASKDATA.mem_start]
  1697.      mov  ebx,ecx
  1698.      mov  eax,keymap
  1699.      mov  ecx,128
  1700.      call memmove
  1701.      ret
  1702.    kbnobaseret:
  1703.      cmp  ebx,2
  1704.      jnz  kbnoshiftret
  1705.      mov  edi,[0x3010]
  1706.      add  ecx,[edi+TASKDATA.mem_start]
  1707.      mov  ebx,ecx
  1708.      mov  eax,keymap_shift
  1709.      mov  ecx,128
  1710.      call memmove
  1711.      ret
  1712.    kbnoshiftret:
  1713.      cmp  ebx,3
  1714.      jne  kbnoaltret
  1715.      mov  edi,[0x3010]
  1716.      add  ecx,[edi+TASKDATA.mem_start]
  1717.      mov  ebx,ecx
  1718.      mov  eax,keymap_alt
  1719.      mov  ecx,128
  1720.      call memmove
  1721.      ret
  1722.    kbnoaltret:
  1723.      cmp  ebx,9
  1724.      jnz  ngsyse2
  1725.      movzx eax,word [keyboard]
  1726.      mov  [esp+36],eax
  1727.      ret
  1728.    ngsyse2:
  1729.  
  1730.      cmp  eax,3
  1731.      jnz  ngsyse3
  1732.      movzx eax,[cd_base]
  1733.      mov  [esp+36],eax
  1734.      ret
  1735.    ngsyse3:
  1736.  
  1737.      cmp  eax,4
  1738.      jne  ngsyse4
  1739.      mov  eax,[sb16]
  1740.      mov  [esp+36],eax
  1741.      ret
  1742.    ngsyse4:
  1743.  
  1744.      cmp  eax,5
  1745.      jnz  ngsyse5
  1746.      mov  eax,[syslang]
  1747.      mov  [esp+36],eax
  1748.      ret
  1749.    ngsyse5:
  1750.      cmp  eax,6
  1751.      jnz  ngsyse6
  1752.      mov  eax,[wss]
  1753.      mov  [esp+36],eax
  1754.      ret
  1755.    ngsyse6:
  1756.      cmp  eax,7
  1757.      jnz  ngsyse7
  1758.      movzx eax,[hd_base]
  1759.      mov  [esp+36],eax
  1760.      ret
  1761.    ngsyse7:
  1762.      cmp  eax,8
  1763.      jnz  ngsyse8
  1764.      mov eax,[fat32part]
  1765.      mov  [esp+36],eax
  1766.      ret
  1767.    ngsyse8:
  1768.      cmp  eax,9
  1769.      jne  ngsyse9
  1770.      mov  eax,[timer_ticks] ;[0xfdf0]
  1771.      mov  [esp+36],eax
  1772.      ret
  1773.    ngsyse9:
  1774.      cmp  eax,10
  1775.      jnz  ngsyse10
  1776.      mov eax,[sound_dma]
  1777.      mov  [esp+36],eax
  1778.      ret
  1779.    ngsyse10:
  1780.      cmp  eax,11
  1781.      jnz  ngsyse11
  1782.      mov eax,[lba_read_enabled]
  1783.      mov  [esp+36],eax
  1784.      ret
  1785.    ngsyse11:
  1786.      cmp  eax,12
  1787.      jnz  ngsyse12
  1788.      mov eax,[pci_access_enabled]
  1789.      mov  [esp+36],eax
  1790.      ret
  1791.    ngsyse12:
  1792.      mov  [esp+36],dword 1
  1793.      ret
  1794.  
  1795.  
  1796. align 4
  1797.  
  1798. readmousepos:
  1799.  
  1800. ; eax=0 screen relative
  1801. ; eax=1 window relative
  1802. ; eax=2 buttons pressed
  1803.  
  1804.     test eax,eax
  1805.     jnz  nosr
  1806.     mov  eax,[0xfb0a]
  1807.     shl  eax,16
  1808.     mov  ax,[0xfb0c]
  1809.     mov  [esp+36],eax
  1810.     ret
  1811.   nosr:
  1812.  
  1813.     cmp  eax,1
  1814.     jnz  nowr
  1815.     mov  eax,[0xfb0a]
  1816.     shl  eax,16
  1817.     mov  ax,[0xfb0c]
  1818.     mov  esi,[0x3010]
  1819.     mov  bx, word [esi-twdw+WDATA.box.left]
  1820.     shl  ebx,16
  1821.     mov  bx, word [esi-twdw+WDATA.box.top]
  1822.     sub  eax,ebx
  1823.     mov  [esp+36],eax
  1824.     ret
  1825.   nowr:
  1826.  
  1827.     cmp   eax,2
  1828.     jnz   nomb
  1829.     movzx eax,byte [0xfb40]
  1830.   nomb:
  1831.     mov   [esp+36],eax
  1832.  
  1833.     ret
  1834.  
  1835. is_input:
  1836.  
  1837.    push edx
  1838.    mov  dx,word [midisp]
  1839.    in   al,dx
  1840.    and  al,0x80
  1841.    pop  edx
  1842.    ret
  1843.  
  1844.  
  1845. is_output:
  1846.  
  1847.    push edx
  1848.    mov  dx,word [midisp]
  1849.    in   al,dx
  1850.    and  al,0x40
  1851.    pop  edx
  1852.    ret
  1853.  
  1854.  
  1855. get_mpu_in:
  1856.  
  1857.    push edx
  1858.    mov  dx,word [mididp]
  1859.    in   al,dx
  1860.    pop  edx
  1861.    ret
  1862.  
  1863.  
  1864. put_mpu_out:
  1865.  
  1866.    push edx
  1867.    mov  dx,word [mididp]
  1868.    out  dx,al
  1869.    pop  edx
  1870.    ret
  1871.  
  1872.  
  1873. setuart:
  1874.  
  1875.  su1:
  1876.    call is_output
  1877.    cmp  al,0
  1878.    jnz  su1
  1879.    mov  dx,word [midisp]
  1880.    mov  al,0xff
  1881.    out  dx,al
  1882.  su2:
  1883.    mov  dx,word [midisp]
  1884.    mov  al,0xff
  1885.    out  dx,al
  1886.    call is_input
  1887.    cmp  al,0
  1888.    jnz  su2
  1889.    call get_mpu_in
  1890.    cmp  al,0xfe
  1891.    jnz  su2
  1892.  su3:
  1893.    call is_output
  1894.    cmp  al,0
  1895.    jnz  su3
  1896.    mov  dx,word [midisp]
  1897.    mov  al,0x3f
  1898.    out  dx,al
  1899.  
  1900.    ret
  1901.  
  1902.  
  1903. align 4
  1904.  
  1905. sys_midi:
  1906.  
  1907.      cmp  [mididp],0
  1908.      jnz  sm0
  1909.      mov  [esp+36],dword 1
  1910.      ret
  1911.    sm0:
  1912.  
  1913.      cmp  eax,1
  1914.      mov  [esp+36],dword 0
  1915.      jnz  smn1
  1916.      call setuart
  1917.      ret
  1918.    smn1:
  1919.  
  1920.      cmp  eax,2
  1921.      jnz  smn2
  1922.    sm10:
  1923.      call get_mpu_in
  1924.      call is_output
  1925.      test al,al
  1926.      jnz  sm10
  1927.      mov  al,bl
  1928.      call put_mpu_out
  1929.      ret
  1930.    smn2:
  1931.  
  1932.      ret
  1933.  
  1934.  
  1935. detect_devices:
  1936. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1937. include 'detect/commouse.inc'
  1938. include 'detect/ps2mouse.inc'
  1939. ;include 'detect/dev_fd.inc'
  1940. ;include 'detect/dev_hdcd.inc'
  1941. ;include 'detect/sear_par.inc'
  1942. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1943.     ret
  1944.  
  1945.  
  1946. sys_end:
  1947.  
  1948.      mov   eax,[0x3010]
  1949.      mov   [eax+TASKDATA.state], 3  ; terminate this program
  1950.  
  1951.     waitterm:            ; wait here for termination
  1952.      mov   eax,5
  1953.      call  delay_hs
  1954.      jmp   waitterm
  1955.  
  1956. iglobal
  1957. sys_system_table:
  1958.         dd      sysfn_shutdown          ; 1 = system shutdown
  1959.         dd      sysfn_terminate         ; 2 = terminate thread
  1960.         dd      sysfn_activate          ; 3 = activate window
  1961.         dd      sysfn_getidletime       ; 4 = get idle time
  1962.         dd      sysfn_getcpuclock       ; 5 = get cpu clock
  1963.         dd      sysfn_saveramdisk       ; 6 = save ramdisk
  1964.         dd      sysfn_getactive         ; 7 = get active window
  1965.         dd      sysfn_sound_flag        ; 8 = get/set sound_flag
  1966.         dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
  1967.         dd      sysfn_minimize          ; 10 = minimize window
  1968.         dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
  1969.         dd      sysfn_lastkey           ; 12 = get last pressed key
  1970.         dd      sysfn_getversion        ; 13 = get kernel version
  1971.         dd      sysfn_waitretrace       ; 14 = wait retrace
  1972.         dd      sysfn_centermouse       ; 15 = center mouse cursor
  1973.         dd      sysfn_getfreemem        ; 16 = get free memory size
  1974.         dd      sysfn_getallmem         ; 17 = get total memory size
  1975.         dd      sysfn_terminate2        ; 18 = terminate thread using PID instead of slot
  1976. sysfn_num = ($ - sys_system_table)/4
  1977. endg
  1978.  
  1979. sys_system:
  1980.         dec     eax
  1981.         cmp     eax, sysfn_num
  1982.         jae     @f
  1983.         jmp     dword [sys_system_table + eax*4]
  1984. @@:
  1985.         ret
  1986.  
  1987. sysfn_shutdown:         ; 18.1 = BOOT
  1988.      mov  [0x2f0000+0x9030],byte 0
  1989.   for_shutdown_parameter:
  1990.      mov  eax,[0x3004]
  1991.      add  eax,2
  1992.      mov  [shutdown_processes],eax
  1993.      mov  [0xFF00],al
  1994.      and  dword [esp+36], 0
  1995.      ret
  1996.   uglobal
  1997.    shutdown_processes: dd 0x0
  1998.   endg
  1999.  
  2000. sysfn_terminate:        ; 18.2 = TERMINATE
  2001.      cmp  ebx,2
  2002.      jb   noprocessterminate
  2003.      mov  edx,[0x3004]
  2004.      cmp  ebx,edx
  2005.      ja   noprocessterminate
  2006.      mov  eax,[0x3004]
  2007.      shl  ebx,5
  2008.      mov  edx,[ebx+0x3000+TASKDATA.pid]
  2009.      add  ebx,0x3000+TASKDATA.state
  2010.      cmp  byte [ebx], 9
  2011.      jz   noprocessterminate
  2012.  
  2013.      ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
  2014.      mov  [ebx],byte 3       ; clear possible i40's
  2015.      ;call MEM_Heap_UnLock
  2016.  
  2017.      cmp  edx,[application_table_status]    ; clear app table stat
  2018.      jne  noatsc
  2019.      mov  [application_table_status],0
  2020.    noatsc:
  2021.    noprocessterminate:
  2022.      ret
  2023.  
  2024. sysfn_terminate2:
  2025. ;lock application_table_status mutex
  2026. .table_status:    
  2027.     cli
  2028.     cmp    [application_table_status],0
  2029.     je     .stf
  2030.     sti
  2031.     call   change_task
  2032.     jmp    .table_status
  2033. .stf:
  2034.     call   set_application_table_status
  2035.     mov    eax,ebx
  2036.     call   pid_to_slot
  2037.     test   eax,eax
  2038.     jz     .not_found
  2039.     mov    ebx,eax
  2040.     cli
  2041.     call   sysfn_terminate
  2042.     mov    [application_table_status],0
  2043.     sti
  2044.     and    dword [esp+36],0
  2045.     ret
  2046. .not_found:
  2047.     mov    [application_table_status],0
  2048.     or     dword [esp+36],-1
  2049.     ret
  2050.  
  2051. sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
  2052.      cmp  ebx,2
  2053.      jb   .nowindowactivate
  2054.      cmp  ebx,[0x3004]
  2055.      ja   .nowindowactivate
  2056.  
  2057.      mov   [window_minimize], 2   ; restore window if minimized
  2058.  
  2059.      movzx esi, word [0xC000 + ebx*2]
  2060.      cmp   esi, [0x3004]
  2061.      je    .nowindowactivate ; already active
  2062.  
  2063.      mov   edi, ebx
  2064.      shl   edi, 5
  2065.      add   edi, window_data
  2066.      movzx esi, word [0xC000 + ebx * 2]
  2067.      lea   esi, [0xC400 + esi * 2]
  2068.      call  waredraw
  2069. .nowindowactivate:
  2070.      ret
  2071.  
  2072. sysfn_getidletime:              ; 18.4 = GET IDLETIME
  2073.      mov  eax,[idleusesec]
  2074.      mov  [esp+36], eax
  2075.      ret
  2076.  
  2077. sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
  2078.      mov  eax,[0xf600]
  2079.      mov  [esp+36], eax
  2080.      ret
  2081.  
  2082. ;  SAVE ramdisk to /hd/1/menuet.img
  2083. ;!!!!!!!!!!!!!!!!!!!!!!!!
  2084.    include 'blkdev/rdsave.inc'
  2085. ;!!!!!!!!!!!!!!!!!!!!!!!!
  2086.  
  2087. sysfn_getactive:        ; 18.7 = get active window
  2088.      mov  eax, [0x3004]
  2089.    movzx  eax, word [0xC400 + eax*2]
  2090.      mov  [esp+36],eax
  2091.      ret
  2092.  
  2093. sysfn_sound_flag:       ; 18.8 = get/set sound_flag
  2094.      cmp  ebx,1
  2095.      jne  nogetsoundflag
  2096.      movzx  eax,byte [sound_flag] ; get sound_flag
  2097.      mov  [esp+36],eax
  2098.      ret
  2099.  nogetsoundflag:
  2100.      cmp  ebx,2
  2101.      jnz  nosoundflag
  2102.      xor  byte [sound_flag], 1
  2103.  nosoundflag:
  2104.      ret
  2105.  
  2106. sysfn_shutdown_param:   ; 18.9 = system shutdown with param
  2107.      cmp  ebx,1
  2108.      jl   exit_for_anyone
  2109.      cmp  ebx,4
  2110.      jg   exit_for_anyone
  2111.      mov  [0x2f0000+0x9030],bl
  2112.      jmp  for_shutdown_parameter
  2113.  
  2114. sysfn_minimize:         ; 18.10 = minimize window
  2115.      mov   [window_minimize],1
  2116.  exit_for_anyone:
  2117.      ret
  2118.  
  2119. sysfn_getdiskinfo:      ; 18.11 = get disk info table
  2120.      cmp  ebx,1
  2121.      jnz  full_table
  2122.   small_table:
  2123.      call for_all_tables
  2124.      mov ecx,10
  2125.      cld
  2126.      rep movsb
  2127.      ret
  2128.    for_all_tables:
  2129.      mov edi,[0x3010]
  2130.      mov edi,[edi+TASKDATA.mem_start]
  2131.      add edi,ecx
  2132.      mov esi,0x40000
  2133.      ret
  2134.   full_table:
  2135.      cmp  ebx,2
  2136.      jnz  exit_for_anyone
  2137.      call for_all_tables
  2138.      mov ecx,16384
  2139.      cld
  2140.      rep movsd
  2141.      ret
  2142.  
  2143. sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
  2144.         and     dword [esp+36], 0
  2145.         ret
  2146.  
  2147. sysfn_getversion:       ; 18.13 = get kernel ID and version
  2148.      mov edi,[0x3010]
  2149.      mov edi,[edi+TASKDATA.mem_start]
  2150.      add edi,ebx
  2151.      mov esi,version_inf
  2152.      mov ecx,version_end-version_inf
  2153.      cld
  2154.      rep movsb
  2155.      ret
  2156.  
  2157. sysfn_waitretrace:     ; 18.14 = sys wait retrace
  2158.      ;wait retrace functions
  2159.  sys_wait_retrace:
  2160.      mov edx,0x3da
  2161.  WaitRetrace_loop:
  2162.      in al,dx
  2163.      test al,1000b
  2164.      jz WaitRetrace_loop
  2165.      mov [esp+36],dword 0
  2166.      ret
  2167.  
  2168. sysfn_centermouse:      ; 18.15 = mouse centered
  2169.      call  mouse_centered
  2170.      mov [esp+36],dword 0
  2171.      ret
  2172.  
  2173. sysfn_getfreemem:
  2174.      mov  eax,[MEM_FreeSpace]
  2175.      shl  eax,2
  2176.      mov  [esp+36],eax
  2177.      ret
  2178.  
  2179. sysfn_getallmem:
  2180.      mov  eax,[0xFE8C]
  2181.      shr  eax,10
  2182. ;     mov  eax,[MEM_AllSpace]
  2183. ;     shl  eax,2
  2184.      mov  [esp+36],eax
  2185.      ret
  2186.  
  2187. uglobal
  2188. ;// mike.dld, 2006-29-01 [
  2189. screen_workarea RECT
  2190. ;// mike.dld, 2006-29-01 ]
  2191. window_minimize db 0
  2192. sound_flag      db 0
  2193. endg
  2194.  
  2195. iglobal
  2196. version_inf:
  2197.   db 0,5,8,1  ; version 0.5.8.1
  2198.   db UID_KOLIBRI
  2199.   db 'Kolibri',0
  2200. version_end:
  2201. endg
  2202.  
  2203. UID_NONE=0
  2204. UID_MENUETOS=1   ;official
  2205. UID_KOLIBRI=2    ;russian
  2206.  
  2207. sys_cachetodiskette:
  2208. ;    pushad
  2209. ;    cmp  eax,1
  2210. ;    jne  no_write_all_of_ramdisk
  2211. ;    call fdc_writeramdisk
  2212. ;    popad
  2213. ;    ret
  2214. ;  no_write_all_of_ramdisk:
  2215. ;    cmp eax,2
  2216. ;    jne no_write_part_of_ramdisk
  2217. ;    call fdc_commitflush
  2218. ;    popad
  2219. ;    ret
  2220. ;  no_write_part_of_ramdisk:
  2221. ;    cmp  eax,3
  2222. ;    jne  no_set_fdc
  2223. ;    call fdc_set
  2224. ;    popad
  2225. ;    ret
  2226. ;  no_set_fdc:
  2227. ;    cmp  eax,4
  2228. ;    jne  no_get_fdc
  2229. ;    popad
  2230. ;    call fdc_get
  2231. ;    mov    [esp+36],ecx
  2232. ;    ret
  2233. ;  no_get_fdc:
  2234. ;    popad
  2235. ;    ret
  2236.     cmp eax,1
  2237.     jne no_floppy_a_save
  2238.     mov   [flp_number],1
  2239.     jmp save_image_on_floppy
  2240.   no_floppy_a_save:
  2241.     cmp eax,2
  2242.     jne no_floppy_b_save
  2243.     mov   [flp_number],2
  2244.   save_image_on_floppy:
  2245.     call save_image
  2246.     mov  [esp+36],dword 0
  2247.     cmp  [FDC_Status],0
  2248.     je   yes_floppy_save
  2249.   no_floppy_b_save:
  2250.     mov [esp+36],dword 1
  2251.   yes_floppy_save:
  2252.     ret
  2253.  
  2254. uglobal
  2255. ;  bgrchanged  dd  0x0
  2256. endg
  2257.  
  2258. sys_background:
  2259.  
  2260.     cmp   eax,1                            ; BACKGROUND SIZE
  2261.     jnz   nosb1
  2262.     cmp   ebx,0
  2263.     je    sbgrr
  2264.     cmp   ecx,0
  2265.     je    sbgrr
  2266.     mov   [display_data-8],ebx
  2267.     mov   [display_data-4],ecx
  2268. ;    mov   [bgrchanged],1
  2269.   sbgrr:
  2270.     ret
  2271.   nosb1:
  2272.  
  2273.     cmp   eax,2                            ; SET PIXEL
  2274.     jnz   nosb2
  2275.     mov   edx,0x160000-16
  2276.     cmp   edx,ebx
  2277.     jbe   nosb2
  2278.     mov   edx,[ebx]
  2279.     and   edx,0xFF000000 ;255*256*256*256
  2280.     and   ecx,0x00FFFFFF ;255*256*256+255*256+255
  2281.     add   edx,ecx
  2282.     mov   [ebx+0x300000],edx
  2283. ;    mov   [bgrchanged],1
  2284.     ret
  2285.   nosb2:
  2286.  
  2287.     cmp   eax,3                            ; DRAW BACKGROUND
  2288.     jnz   nosb3
  2289. draw_background_temp:
  2290. ;    cmp   [bgrchanged],1 ;0
  2291. ;    je    nosb31
  2292. ;draw_background_temp:
  2293. ;    mov   [bgrchanged],1 ;0
  2294.     mov   [0xfff0],byte 1
  2295.     mov    [background_defined], 1
  2296.    nosb31:
  2297.     ret
  2298.   nosb3:
  2299.  
  2300.     cmp   eax,4                            ; TILED / STRETCHED
  2301.     jnz   nosb4
  2302.     cmp   ebx,[display_data-12]
  2303.     je    nosb41
  2304.     mov   [display_data-12],ebx
  2305. ;    mov   [bgrchanged],1
  2306.    nosb41:
  2307.     ret
  2308.   nosb4:
  2309.  
  2310.     cmp   eax,5                            ; BLOCK MOVE TO BGR
  2311.     jnz   nosb5
  2312.   ; bughere
  2313.     mov   edi, [0x3010]
  2314.     add   ebx, [edi+TASKDATA.mem_start]
  2315.  ;   mov   esi, ebx
  2316.  ;   mov   edi, ecx
  2317.     mov   eax, ebx
  2318.     mov   ebx, ecx
  2319.     add   ecx, edx
  2320.     cmp   ecx, 0x160000-16
  2321.     ja    .fin
  2322.  ;   add   edi, 0x300000
  2323.     add   ebx, 0x300000
  2324.     mov   ecx, edx
  2325.     cmp   ecx, 0x160000-16
  2326.     ja    .fin
  2327. ;    mov   [bgrchanged],1
  2328.   ;  cld
  2329.   ;  rep   movsb
  2330.     call  memmove
  2331.   .fin:
  2332.     ret
  2333.   nosb5:
  2334.  
  2335.     ret
  2336.  
  2337.  
  2338. align 4
  2339.  
  2340. sys_getbackground:
  2341.  
  2342.     cmp   eax,1                                  ; SIZE
  2343.     jnz   nogb1
  2344.     mov   eax,[display_data-8]
  2345.     shl   eax,16
  2346.     mov   ax,[display_data-4]
  2347.     mov   [esp+36],eax
  2348.     ret
  2349.   nogb1:
  2350.  
  2351.     cmp   eax,2                                  ; PIXEL
  2352.     jnz   nogb2
  2353.     mov   edx,0x160000-16
  2354.     cmp   edx,ebx
  2355.     jbe   nogb2
  2356.     mov   eax, [ebx+0x300000]
  2357.     and   eax, 0xFFFFFF
  2358.     mov   [esp+36],eax
  2359.     ret
  2360.   nogb2:
  2361.  
  2362.     cmp   eax,4                                  ; TILED / STRETCHED
  2363.     jnz   nogb4
  2364.     mov   eax,[display_data-12]
  2365.   nogb4:
  2366.     mov   [esp+36],eax
  2367.     ret
  2368.  
  2369.  
  2370. align 4
  2371.  
  2372. sys_getkey:
  2373.     mov   [esp+36],dword 1
  2374. ; test main buffer
  2375.     mov   ebx, [0x3000]                          ; TOP OF WINDOW STACK
  2376.     movzx ecx,word [0xC000 + ebx * 2]
  2377.     mov   edx,[0x3004]
  2378.     cmp   ecx,edx
  2379.     jne   .finish
  2380.     cmp   [0xf400],byte 0
  2381.     je    .finish
  2382.     movzx eax,byte [0xf401]
  2383.     shl   eax,8
  2384.     push  eax
  2385.     dec   byte [0xf400]
  2386.     and   byte [0xf400],127
  2387.     movzx ecx,byte [0xf400]
  2388.     add   ecx,2
  2389.  ;   mov   esi,0xf402
  2390.  ;   mov   edi,0xf401
  2391.  ;   cld
  2392.  ;  rep   movsb
  2393.     mov   eax, 0xF402
  2394.     mov   ebx, 0xF401
  2395.     call  memmove
  2396.     pop   eax
  2397. .ret_eax:
  2398.     mov   [esp+36],eax
  2399.     ret
  2400.  .finish:
  2401. ; test hotkeys buffer
  2402.         mov     ecx, hotkey_buffer
  2403. @@:
  2404.         cmp     [ecx], ebx
  2405.         jz      .found
  2406.         add     ecx, 8
  2407.         cmp     ecx, hotkey_buffer+120*8
  2408.         jb      @b
  2409.         ret
  2410. .found:
  2411.         mov     ax, [ecx+6]
  2412.         shl     eax, 16
  2413.         mov     ah, [ecx+4]
  2414.         mov     al, 2
  2415.         and     dword [ecx+4], 0
  2416.         and     dword [ecx], 0
  2417.         jmp     .ret_eax
  2418.  
  2419. align 4
  2420.  
  2421. sys_getbutton:
  2422.  
  2423.     mov   ebx, [0x3000]                         ; TOP OF WINDOW STACK
  2424.     mov   [esp+36],dword 1
  2425.     movzx ecx, word [0xC000 + ebx * 2]
  2426.     mov   edx, [0x3004] ; less than 256 processes
  2427.     cmp   ecx,edx
  2428.     jne   .exit
  2429.     movzx eax,byte [0xf500]
  2430.     test  eax,eax
  2431.     jz    .exit
  2432.     mov   eax,[0xf501]
  2433.     shl   eax,8
  2434.     mov   [0xf500],byte 0
  2435.     mov   [esp+36],eax
  2436.  .exit:
  2437.     ret
  2438.  
  2439.  
  2440. align 4
  2441.  
  2442. sys_cpuusage:
  2443.  
  2444. ;  RETURN:
  2445. ;
  2446. ;  +00 dword     process cpu usage
  2447. ;  +04  word     position in windowing stack
  2448. ;  +06  word     windowing stack value at current position (cpu nro)
  2449. ;  +10 12 bytes  name
  2450. ;  +22 dword     start in mem
  2451. ;  +26 dword     used mem
  2452. ;  +30 dword     PID , process idenfification number
  2453. ;
  2454.  
  2455.     mov  edi,[0x3010]   ; eax = return area
  2456.     add  eax,[edi + TASKDATA.mem_start]
  2457.  
  2458.     cmp  ebx,-1         ; who am I ?
  2459.     jne  no_who_am_i
  2460.     mov  ebx,[0x3000]
  2461.   no_who_am_i:
  2462.  
  2463.     push eax            ; return area
  2464.     push ebx            ; process number
  2465.  
  2466.     push ebx
  2467.     push ebx
  2468.     push eax
  2469.  
  2470.     ; return memory usage
  2471.  
  2472.     xor  edx,edx
  2473.     mov  eax,0x20
  2474.     mul  ebx
  2475.     add  eax,0x3000+TASKDATA.cpu_usage
  2476.     mov  ebx,eax
  2477.     pop  eax
  2478.     mov  ecx,[ebx]
  2479.     mov  [eax],ecx
  2480.     pop  ebx
  2481.     mov  cx, [0xC000 + ebx * 2]
  2482.     mov  [eax+4],cx
  2483.     mov  cx, [0xC400 + ebx * 2]
  2484.     mov  [eax+6],cx
  2485.     push eax
  2486.     mov  eax,ebx
  2487.     shl  eax,8
  2488.     add  eax,0x80000+APPDATA.app_name
  2489.     pop  ebx
  2490.     add  ebx,10
  2491.     mov  ecx,11
  2492.     call memmove
  2493.  
  2494.     ; memory usage
  2495.  
  2496.     xor    eax,eax
  2497.     mov    edx,0x100000*16
  2498.     pop    ecx                                   ; get gdt of tss
  2499.     cmp    ecx,1
  2500.     je     os_mem
  2501.     shl    ecx,8
  2502.     mov    edx,[0x80000+ecx+APPDATA.mem_size] ;0x8c
  2503.     mov    eax,std_application_base_address
  2504.     ; eax run base -> edx used memory
  2505.   os_mem:
  2506.     dec    edx
  2507.     mov    [ebx+12],eax
  2508.     mov    [ebx+16],edx
  2509.  
  2510.     ; PID (+30)
  2511.  
  2512.     mov    eax,[esp]
  2513.     shl    eax,5
  2514.     add    eax,0x3000+TASKDATA.pid
  2515.     mov    eax,[eax]
  2516.     mov    [ebx+20],eax
  2517.  
  2518.     ; window position and size
  2519.  
  2520.     mov    esi,[esp]
  2521.     shl    esi,5
  2522.     add    esi,window_data + WDATA.box
  2523.     mov    edi,[esp+4]
  2524.     add    edi,34
  2525.     mov    ecx,4
  2526.     cld
  2527.     rep    movsd
  2528.  
  2529.     ; Process state (+50)
  2530.  
  2531.     mov    eax,[esp]
  2532.     shl    eax,5
  2533.     add    eax,0x3000+TASKDATA.state
  2534.     mov    eax,[eax]
  2535.     mov    [ebx+40],ax
  2536.  
  2537.  
  2538.     pop    ebx
  2539.     pop    eax
  2540.  
  2541.     ; return number of processes
  2542.  
  2543.     mov    eax,[0x3004]
  2544.     mov    [esp+36],eax
  2545.     ret
  2546.  
  2547.  
  2548.  
  2549.  
  2550. align 4
  2551. sys_clock:
  2552.         cli
  2553.   ; Mikhail Lisovin  xx Jan 2005
  2554.   @@:   mov   al, 10
  2555.         out   0x70, al
  2556.         in    al, 0x71
  2557.         test  al, al
  2558.         jns   @f
  2559.         mov   esi, 1
  2560.         call  delay_ms
  2561.         jmp   @b
  2562.   @@:
  2563.   ; end Lisovin's fix
  2564.  
  2565.         xor   al,al           ; seconds
  2566.         out   0x70,al
  2567.         in    al,0x71
  2568.         movzx ecx,al
  2569.         mov   al,02           ; minutes
  2570.         shl   ecx,16
  2571.         out   0x70,al
  2572.         in    al,0x71
  2573.         movzx edx,al
  2574.         mov   al,04           ; hours
  2575.         shl   edx,8
  2576.         out   0x70,al
  2577.         in    al,0x71
  2578.         add   ecx,edx
  2579.         movzx edx,al
  2580.         add   ecx,edx
  2581.         sti
  2582.         mov   [esp+36],ecx
  2583.         ret
  2584.  
  2585.  
  2586. align 4
  2587.  
  2588. sys_date:
  2589.  
  2590.         cli
  2591.  
  2592.   @@:   mov   al, 10
  2593.         out   0x70, al
  2594.         in    al, 0x71
  2595.         test  al, al
  2596.         jns   @f
  2597.         mov   esi, 1
  2598.         call  delay_ms
  2599.         jmp   @b
  2600.   @@:
  2601.  
  2602.         mov     ch,0
  2603.         mov     al,7            ; date
  2604.         out     0x70,al
  2605.         in      al,0x71
  2606.         mov     cl,al
  2607.         mov     al,8            ; month
  2608.         shl     ecx,16
  2609.         out     0x70,al
  2610.         in      al,0x71
  2611.         mov     ch,al
  2612.         mov     al,9            ; year
  2613.         out     0x70,al
  2614.         in      al,0x71
  2615.         mov     cl,al
  2616.         sti
  2617.         mov     [esp+36],ecx
  2618.         ret
  2619.  
  2620.  
  2621. ; redraw status
  2622.  
  2623. sys_redrawstat:
  2624.  
  2625.     cmp  eax,1
  2626.     jne  no_widgets_away
  2627.  
  2628.     ; buttons away
  2629.  
  2630.     mov   ecx,[0x3000]
  2631.  
  2632.   sys_newba2:
  2633.  
  2634.     mov   edi,[0xfe88]
  2635.     cmp   [edi],dword 0  ; empty button list ?
  2636.     je    end_of_buttons_away
  2637.  
  2638.     movzx ebx,word [edi]
  2639.     inc   ebx
  2640.  
  2641.     mov   eax,edi
  2642.  
  2643.   sys_newba:
  2644.  
  2645.     dec   ebx
  2646.     jz    end_of_buttons_away
  2647.  
  2648.     add   eax,0x10
  2649.     cmp   cx,[eax]
  2650.     jnz   sys_newba
  2651.  
  2652.     push  eax ebx ecx
  2653.     mov   ecx,ebx
  2654.     inc   ecx
  2655.     shl   ecx,4
  2656.     mov   ebx,eax
  2657.     add   eax,0x10
  2658.     call  memmove
  2659.     dec   dword [edi]
  2660.     pop   ecx ebx eax
  2661.  
  2662.     jmp   sys_newba2
  2663.  
  2664.   end_of_buttons_away:
  2665.  
  2666.     ret
  2667.  
  2668.   no_widgets_away:
  2669.  
  2670.     cmp   eax,2
  2671.     jnz   srl1
  2672.  
  2673.     mov   edx,[0x3010]      ; return whole screen draw area for this app
  2674.     add   edx,draw_data-0x3000
  2675.     mov   [edx+RECT.left], 0
  2676.     mov   [edx+RECT.top], 0
  2677.     mov   eax,[0xfe00]
  2678.     mov   [edx+RECT.right],eax
  2679.     mov   eax,[0xfe04]
  2680.     mov   [edx+RECT.bottom],eax
  2681.  
  2682.     mov   edi,[0x3010]
  2683.     mov   [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
  2684.  
  2685.     call  sys_window_mouse
  2686.  
  2687.     ret
  2688.  
  2689.   srl1:
  2690.  
  2691.     ret
  2692.  
  2693.  
  2694. sys_drawwindow:
  2695.  
  2696.     mov   edi,ecx
  2697.     shr   edi,16+8
  2698.     and   edi,15
  2699.  
  2700.     cmp   edi,0   ; type I    - original style
  2701.     jne   nosyswI
  2702.     inc   [mouse_pause]
  2703.     call  [disable_mouse]
  2704.     call  sys_set_window
  2705.     call  [disable_mouse]
  2706.     call  drawwindow_I
  2707.     ;dec   [mouse_pause]
  2708.     ;call   [draw_pointer]
  2709.     ;ret
  2710.     jmp   draw_window_caption.2
  2711.   nosyswI:
  2712.  
  2713.     cmp   edi,1   ; type II   - only reserve area, no draw
  2714.     jne   nosyswII
  2715.     inc   [mouse_pause]
  2716.     call  [disable_mouse]
  2717.     call  sys_set_window
  2718.     call  [disable_mouse]
  2719.     call  sys_window_mouse
  2720.     dec   [mouse_pause]
  2721.     call   [draw_pointer]
  2722.     ret
  2723.   nosyswII:
  2724.  
  2725.     cmp   edi,2   ; type III  - new style
  2726.     jne   nosyswIII
  2727.     inc   [mouse_pause]
  2728.     call  [disable_mouse]
  2729.     call  sys_set_window
  2730.     call  [disable_mouse]
  2731.     call  drawwindow_III
  2732.     ;dec   [mouse_pause]
  2733.     ;call   [draw_pointer]
  2734.     ;ret
  2735.     jmp   draw_window_caption.2
  2736.   nosyswIII:
  2737.  
  2738.     cmp   edi,3   ; type IV - skinned window
  2739.     jne   nosyswIV
  2740.  
  2741.     ; parameter for drawwindow_IV
  2742.     push  0
  2743.     mov   edi, [0x3004]
  2744.     movzx edi, word [0xC400 + edi*2]
  2745.     cmp   edi, [0x3000]
  2746.     jne   @f
  2747.     inc   dword [esp]
  2748.  @@:
  2749.  
  2750.     inc   [mouse_pause]
  2751.     call  [disable_mouse]
  2752.     call  sys_set_window
  2753.     call  [disable_mouse]
  2754.     call  drawwindow_IV
  2755.     ;dec   [mouse_pause]
  2756.     ;call   [draw_pointer]
  2757.     ;ret
  2758.     jmp   draw_window_caption.2
  2759.   nosyswIV:
  2760.  
  2761.     ret
  2762.  
  2763.  
  2764. draw_window_caption:
  2765.         inc     [mouse_pause]
  2766.         call    [disable_mouse]
  2767.  
  2768.         xor     eax,eax
  2769.         mov     edx,[0x3004]
  2770.         movzx   edx,word[0xC400+edx*2]
  2771.         cmp     edx,[0x3000]
  2772.         jne     @f
  2773.         inc     eax
  2774.     @@: mov     edx,[0x3000]
  2775.         shl     edx,5
  2776.         add     edx,window_data
  2777.         movzx   ebx,[edx+WDATA.fl_wstyle]
  2778.         and     bl,0x0F
  2779.         cmp     bl,3
  2780.         jne     .not_style_3
  2781.  
  2782.         push    edx
  2783.         call    drawwindow_IV_caption
  2784.         add     esp,4
  2785.         jmp     .2
  2786.  
  2787.   .not_style_3:
  2788.         cmp     bl,2
  2789.         jne     .not_style_2
  2790.  
  2791.         call    drawwindow_III_caption
  2792.         jmp     .2
  2793.  
  2794.   .not_style_2:
  2795.         cmp     bl,0
  2796.         jne     .2
  2797.  
  2798.         call    drawwindow_I_caption
  2799.  
  2800. ;--------------------------------------------------------------
  2801.   .2:   ;jmp     @f
  2802.         mov     edi,[0x3000]
  2803.         shl     edi,5
  2804.         test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
  2805.         jz      @f
  2806.         mov     ecx,[edi*8+0x80000+APPDATA.wnd_caption]
  2807.         or      ecx,ecx
  2808.         jz      @f
  2809.         add     ecx,[edi+twdw+TASKDATA.mem_start]
  2810.  
  2811.         movzx   eax,[edi+window_data+WDATA.fl_wstyle]
  2812.         and     al,0x0F
  2813.         cmp     al,3
  2814.         jne     .not_skinned
  2815.  
  2816.         mov     ebp,[edi+window_data+WDATA.box.left-2]
  2817.         mov     bp,word[edi+window_data+WDATA.box.top]
  2818.         movzx   eax,word[edi+window_data+WDATA.box.width]
  2819.         sub     ax,[_skinmargins.left]
  2820.         sub     ax,[_skinmargins.right]
  2821.         cwde
  2822.         cdq
  2823.         mov     ebx,6
  2824.         idiv    ebx
  2825.         or      eax,eax
  2826.         js      @f
  2827.         mov     edx,eax
  2828.         mov     eax,dword[_skinmargins.left-2]
  2829.         mov     ax,word[_skinh]
  2830.         sub     ax,[_skinmargins.bottom]
  2831.         sub     ax,[_skinmargins.top]
  2832.         sar     ax,1
  2833.         adc     ax,0
  2834.         add     ax,[_skinmargins.top]
  2835.         add     ax,-3
  2836.         add     eax,ebp
  2837.         mov     ebx,[common_colours+16];0x00FFFFFF
  2838.         xor     edi,edi
  2839.         call    dtext
  2840.         jmp     @f
  2841.  
  2842.   .not_skinned:
  2843.         cmp     al,1
  2844.         je      @f
  2845.  
  2846.         mov     ebp,[edi+window_data+WDATA.box.left-2]
  2847.         mov     bp,word[edi+window_data+WDATA.box.top]
  2848.         movzx   eax,word[edi+window_data+WDATA.box.width]
  2849.         sub     eax,16
  2850.         cwde
  2851.         cdq
  2852.         mov     ebx,6
  2853.         idiv    ebx
  2854.         or      eax,eax
  2855.         js      @f
  2856.         mov     edx,eax
  2857.         mov     eax,0x00080007
  2858.         add     eax,ebp
  2859.         mov     ebx,[common_colours+16];0x00FFFFFF
  2860.         xor     edi,edi
  2861.         call    dtext
  2862.         jmp     @f
  2863.  
  2864.     @@:
  2865. ;--------------------------------------------------------------
  2866.         dec     [mouse_pause]
  2867.         call    [draw_pointer]
  2868.         ret
  2869.  
  2870. iglobal
  2871. align 4
  2872. window_topleft dd \
  2873.   1, 21,\
  2874.   0,  0,\
  2875.   5, 20,\
  2876.   5,  ?
  2877. endg
  2878.  
  2879. set_window_clientbox:
  2880.         push    eax ecx edi
  2881.  
  2882.         mov     eax,[_skinh]
  2883.         mov     [window_topleft+4*7],eax
  2884.  
  2885.         mov     ecx,edi
  2886.         sub     edi,window_data
  2887.         shl     edi,3
  2888.         test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
  2889.         jz      @f
  2890.  
  2891.         movzx   eax,[ecx+WDATA.fl_wstyle]
  2892.         and     eax,0x0F
  2893.         mov     eax,[eax*8+window_topleft+0]
  2894.         mov     [edi+0x80000+APPDATA.wnd_clientbox.left],eax
  2895.         shl     eax,1
  2896.         neg     eax
  2897.         add     eax,[ecx+WDATA.box.width]
  2898.         mov     [edi+0x80000+APPDATA.wnd_clientbox.width],eax
  2899.  
  2900.         movzx   eax,[ecx+WDATA.fl_wstyle]
  2901.         and     eax,0x0F
  2902.         push    [eax*8+window_topleft+0]
  2903.         mov     eax,[eax*8+window_topleft+4]
  2904.         mov     [edi+0x80000+APPDATA.wnd_clientbox.top],eax
  2905.         neg     eax
  2906.         sub     eax,[esp]
  2907.         add     eax,[ecx+WDATA.box.height]
  2908.         mov     [edi+0x80000+APPDATA.wnd_clientbox.height],eax
  2909.         add     esp,4
  2910.  
  2911.         pop     edi ecx eax
  2912.         ret
  2913.     @@:
  2914.         xor     eax,eax
  2915.         mov     [edi+0x80000+APPDATA.wnd_clientbox.left],eax
  2916.         mov     [edi+0x80000+APPDATA.wnd_clientbox.top],eax
  2917.         mov     eax,[ecx+WDATA.box.width]
  2918.         mov     [edi+0x80000+APPDATA.wnd_clientbox.width],eax
  2919.         mov     eax,[ecx+WDATA.box.height]
  2920.         mov     [edi+0x80000+APPDATA.wnd_clientbox.height],eax
  2921.  
  2922.         pop     edi ecx eax
  2923.         ret
  2924.  
  2925. sys_set_window:
  2926.  
  2927.     mov   edi,[0x3000]
  2928.     shl   edi,5
  2929.     add   edi,window_data
  2930.  
  2931.     ; colors
  2932.     mov   [edi+WDATA.cl_workarea],ecx
  2933.     mov   [edi+WDATA.cl_titlebar],edx
  2934.     mov   [edi+WDATA.cl_frames],esi
  2935.  
  2936.         call    set_window_clientbox
  2937.  
  2938.     ; check flag (?)
  2939.     cmp   [edi+WDATA.fl_wdrawn],1
  2940.     jz    newd
  2941.  
  2942.     push  eax
  2943.     mov   eax,[timer_ticks] ;[0xfdf0]
  2944.     add   eax,100
  2945.     mov   [new_window_starting],eax
  2946.     pop   eax
  2947.  
  2948.     mov   word[edi+WDATA.box.width],ax
  2949.     mov   word[edi+WDATA.box.height],bx
  2950.     sar   eax,16
  2951.     sar   ebx,16
  2952.     mov   word[edi+WDATA.box.left],ax
  2953.     mov   word[edi+WDATA.box.top],bx
  2954.  
  2955.  
  2956.     call  check_window_position
  2957.  
  2958.  
  2959.     push  ecx esi edi               ; save for window fullscreen/resize
  2960.     ;mov   esi,edi
  2961.  
  2962.         mov     cl,[edi+WDATA.fl_wstyle]
  2963.  
  2964.     sub   edi,window_data
  2965.     shl   edi,3
  2966.     add   edi,0x80000
  2967.  
  2968.         and     cl,0x0F
  2969.         mov     [edi+APPDATA.wnd_caption],0
  2970.         cmp     cl,3
  2971.         jne     @f
  2972.         mov     [edi+APPDATA.wnd_caption],esi
  2973.     @@: mov     esi,[esp+0]
  2974.  
  2975.     add   edi, APPDATA.saved_box
  2976.     mov   ecx,4
  2977.     cld
  2978.     rep   movsd
  2979.     pop   edi esi ecx
  2980.  
  2981.     push  eax ebx ecx edx
  2982. ;;;    mov   eax, 1
  2983. ;;;    call  delay_hs
  2984.     mov   eax, [edi+WDATA.box.left]
  2985.     mov   ebx, [edi+WDATA.box.top]
  2986.     mov   ecx, [edi+WDATA.box.width]
  2987.     mov   edx, [edi+WDATA.box.height]
  2988.     add   ecx, eax
  2989.     add   edx, ebx
  2990.     call  calculatescreen
  2991.     pop   edx ecx ebx eax
  2992.  
  2993.     mov   [0xf400],byte 0           ; empty keyboard buffer
  2994.     mov   [0xf500],byte 0           ; empty button buffer
  2995.  
  2996.   newd:
  2997.     mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
  2998.     mov   edx,edi
  2999.  
  3000.     ret
  3001.  
  3002. syscall_windowsettings:
  3003.  
  3004.   .set_window_caption:
  3005.         dec     eax     ; subfunction #1 - set window caption
  3006.         jnz     .get_window_caption
  3007.  
  3008.         ; NOTE: only window owner thread can set its caption,
  3009.         ;       so there's no parameter for PID/TID
  3010.  
  3011.         mov     edi,[0x3000]
  3012.         shl     edi,5
  3013.  
  3014.         ; have to check if caption is within application memory limit
  3015.         ; check is trivial, and if application resizes its memory,
  3016.         ;   caption still can become over bounds
  3017.         mov     ecx,[edi*8+0x80000+APPDATA.mem_size]
  3018.         add     ecx,255 ; max caption length
  3019.         cmp     ebx,ecx
  3020.         ja      .exit_fail
  3021.  
  3022.         mov     [edi*8+0x80000+APPDATA.wnd_caption],ebx
  3023.         or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
  3024.  
  3025.         call    draw_window_caption
  3026.  
  3027.         xor     eax,eax ; eax = 0 (success)
  3028.         ret
  3029.  
  3030.   .get_window_caption:
  3031.         dec     eax     ; subfunction #2 - get window caption
  3032.         jnz     .exit_fail
  3033.  
  3034.         ; not implemented yet
  3035.  
  3036.   .exit_fail:
  3037.         xor     eax,eax
  3038.         inc     eax     ; eax = 1 (fail)
  3039.         ret
  3040.  
  3041.  
  3042. sys_window_move:
  3043.  
  3044.         mov     edi,[0x3000]
  3045.         shl     edi,5
  3046.         add     edi,window_data
  3047.  
  3048.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  3049.         jnz     .window_move_return
  3050.  
  3051.         push    dword [edi + WDATA.box.left]  ; save old coordinates
  3052.         push    dword [edi + WDATA.box.top]
  3053.         push    dword [edi + WDATA.box.width]
  3054.         push    dword [edi + WDATA.box.height]
  3055.  
  3056.         cmp   eax,-1                  ; set new position and size
  3057.         je    .no_x_reposition
  3058.         mov     [edi + WDATA.box.left], eax
  3059.       .no_x_reposition:
  3060.         cmp   ebx,-1
  3061.         je    .no_y_reposition
  3062.         mov     [edi + WDATA.box.top], ebx
  3063.       .no_y_reposition:
  3064.  
  3065.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  3066.         jnz     .no_y_resizing
  3067.  
  3068.         cmp   ecx,-1
  3069.         je    .no_x_resizing
  3070.         mov     [edi + WDATA.box.width], ecx
  3071.       .no_x_resizing:
  3072.         cmp   edx,-1
  3073.         je    .no_y_resizing
  3074.         mov     [edi + WDATA.box.height], edx
  3075.       .no_y_resizing:
  3076.  
  3077.         call  check_window_position
  3078.  
  3079.         pushad                       ; save for window fullscreen/resize
  3080.         mov   esi,edi
  3081.         sub   edi,window_data
  3082.         shr   edi,5
  3083.         shl   edi,8
  3084.         add   edi, 0x80000 + APPDATA.saved_box
  3085.         mov   ecx,4
  3086.         cld
  3087.         rep   movsd
  3088.         popad
  3089.  
  3090.         pushad                       ; calculcate screen at new position
  3091.         mov   eax, [edi + WDATA.box.left]
  3092.         mov   ebx, [edi + WDATA.box.top]
  3093.         mov   ecx, [edi + WDATA.box.width]
  3094.         mov   edx, [edi + WDATA.box.height]
  3095.         add   ecx, eax
  3096.         add   edx, ebx
  3097.         call  calculatescreen
  3098.         popad
  3099.  
  3100.         pop   edx                   ; calculcate screen at old position
  3101.         pop   ecx
  3102.         pop   ebx
  3103.         pop   eax
  3104.         add   ecx,eax
  3105.         add   edx,ebx
  3106.         mov   [dlx],eax             ; save for drawlimits
  3107.         mov   [dly],ebx
  3108.         mov   [dlxe],ecx
  3109.         mov   [dlye],edx
  3110.         call  calculatescreen
  3111.  
  3112.         mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
  3113.  
  3114.         mov   eax,edi               ; redraw screen at old position
  3115.         xor   esi,esi
  3116.         call  redrawscreen
  3117.  
  3118.         mov   [0xfff5],byte 0 ; mouse pointer
  3119.         mov   [0xfff4],byte 0 ; no mouse under
  3120.         mov   [0xfb44],byte 0 ; react to mouse up/down
  3121.  
  3122.         mov   ecx,10          ; wait 1/10 second
  3123.       .wmrl3:
  3124.         call  [draw_pointer]
  3125.         mov   eax,1
  3126.         call  delay_hs
  3127.         loop  .wmrl3
  3128.  
  3129.         mov   [window_move_pr],0
  3130.  
  3131.       .window_move_return:
  3132.  
  3133.         ret
  3134.  
  3135. ;type_background_1:
  3136. ;    cmp   [0xfff0],byte 0               ; background update ?
  3137. ;    jz    temp_nobackgr
  3138. ;    mov   [0xfff0],byte 2
  3139. ;    call  change_task
  3140. ;    mov   [draw_data+32+0],dword 0
  3141. ;    mov   [draw_data+32+4],dword 0
  3142. ;    mov   eax,[0xfe00]
  3143. ;    mov   ebx,[0xfe04]
  3144. ;    mov   [draw_data+32+8],eax
  3145. ;    mov   [draw_data+32+12],ebx
  3146. ;    call  drawbackground
  3147. ;    mov   [0xfff0],byte 0
  3148. ;    mov   [0xfff4],byte 0
  3149. ;temp_nobackgr:
  3150. ;    ret
  3151.  
  3152. uglobal
  3153.   window_move_pr   dd  0x0
  3154.   window_move_eax  dd  0x0
  3155.   window_move_ebx  dd  0x0
  3156.   window_move_ecx  dd  0x0
  3157.   window_move_edx  dd  0x0
  3158. endg
  3159.  
  3160. ;ok - 100% work
  3161. ;nt - not tested
  3162. ;---------------------------------------------------------------------------------------------
  3163. ;eax
  3164. ;0 - task switch counter. Ret switch counter in eax. Block. ok.
  3165. ;1 - change task. Ret nothing. Block. ok.
  3166. ;2 - performance control
  3167. ; ebx
  3168. ; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
  3169. ; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
  3170. ; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
  3171. ; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
  3172. ; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
  3173. ;eax
  3174. ;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  3175. ;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  3176. ;---------------------------------------------------------------------------------------------
  3177. sys_sheduler: ;noname & halyavin
  3178.     cmp eax,0
  3179.     je shed_counter
  3180.     cmp eax,2
  3181.     je perf_control
  3182.     cmp eax,3
  3183.     je rdmsr_instr
  3184.     cmp eax,4
  3185.     je wrmsr_instr
  3186.     cmp eax,1
  3187.     jne not_supported
  3188.     call change_task ;delay,0
  3189. ret
  3190. shed_counter:
  3191.     mov eax,[context_counter]
  3192.     mov [esp+36],eax
  3193. not_supported:
  3194. ret
  3195. perf_control:
  3196.     inc eax ;now eax=3
  3197.     cmp ebx,eax
  3198.     je cache_disable
  3199.     dec eax
  3200.     cmp ebx,eax
  3201.     je cache_enable
  3202.     dec eax
  3203.     cmp ebx,eax
  3204.     je is_cache_enabled
  3205.     dec eax
  3206.     cmp ebx,eax
  3207.     je modify_pce
  3208. ret
  3209.  
  3210. rdmsr_instr:
  3211. ;now counter in ecx
  3212. ;(edx:eax) esi:edi => edx:esi
  3213. mov eax,esi
  3214. rdmsr
  3215. mov [esp+36],eax
  3216. mov [esp+24],edx ;ret in ebx?
  3217. ret
  3218.  
  3219. wrmsr_instr:
  3220. ;now counter in ecx
  3221. ;(edx:eax) esi:edi => edx:esi
  3222. mov eax,esi
  3223. wrmsr
  3224. mov [esp+36],eax
  3225. mov [esp+24],edx ;ret in ebx?
  3226. ret
  3227.  
  3228. cache_disable:
  3229.        mov eax,cr0
  3230.        or  eax,01100000000000000000000000000000b
  3231.        mov cr0,eax
  3232.        wbinvd ;set MESI
  3233. ret
  3234.  
  3235. cache_enable:
  3236.        mov eax,cr0
  3237.        and eax,10011111111111111111111111111111b
  3238.        mov cr0,eax
  3239. ret
  3240.  
  3241. is_cache_enabled:
  3242.        mov eax,cr0
  3243.        mov ebx,eax
  3244.        and eax,01100000000000000000000000000000b
  3245.        jz cache_disabled
  3246.        mov [esp+36],ebx
  3247. cache_disabled:
  3248.        mov dword [esp+36],eax ;0
  3249. ret
  3250.  
  3251. modify_pce:
  3252.        mov eax,cr4
  3253. ;       mov ebx,0
  3254. ;       or  bx,100000000b ;pce
  3255. ;       xor eax,ebx ;invert pce
  3256.        bts eax,8 ;pce=cr4[8]
  3257.        mov cr4,eax
  3258.        mov [esp+36],eax
  3259. ret
  3260. ;---------------------------------------------------------------------------------------------
  3261.  
  3262.  
  3263. ; check if pixel is allowed to be drawn
  3264.  
  3265. checkpixel:
  3266.         push eax edx
  3267.  
  3268.         mov  edx,[0xfe00]     ; screen x size
  3269.         inc  edx
  3270.         imul edx, ebx
  3271.         mov  dl, [eax+edx+display_data] ; lea eax, [...]
  3272.  
  3273.         xor  ecx, ecx
  3274.         mov  eax, [0x3000]
  3275.         cmp  al, dl
  3276.         setne cl
  3277.  
  3278.         pop  edx eax
  3279.         ret
  3280.  
  3281. uglobal
  3282.   mouse_active  db  0
  3283. endg
  3284. iglobal
  3285.   cpustring db 'CPU        '
  3286. endg
  3287.  
  3288. uglobal
  3289. background_defined    db    0    ; diamond, 11.04.2006
  3290. endg
  3291.  
  3292. align 4
  3293. ; check misc
  3294.  
  3295. checkmisc:
  3296.  
  3297.     cmp   [ctrl_alt_del], 1
  3298.     jne   nocpustart
  3299.     mov   eax, cpustring
  3300.     xor   ebx,ebx               ; no parameters
  3301.     xor   edx,edx               ; no flags
  3302.     call  start_application_fl
  3303.     mov   [ctrl_alt_del], 0
  3304.   nocpustart:
  3305.     cmp   [mouse_active], 1
  3306.     jne   mouse_not_active
  3307.     mov   [mouse_active], 0
  3308.     xor   edi, edi
  3309.     mov   ecx, [0x3004]
  3310.    set_mouse_event:
  3311.     add   edi, 256
  3312.     or    [edi+0x80000+APPDATA.event_mask], dword 00100000b
  3313.     loop  set_mouse_event
  3314.   mouse_not_active:
  3315.  
  3316.  
  3317.     cmp   [0xfff0],byte 0               ; background update ?
  3318.     jz    nobackgr
  3319.     cmp    [background_defined], 0
  3320.     jz    nobackgr
  3321.     mov   [0xfff0],byte 2
  3322.     call  change_task
  3323.     mov   [draw_data+32 + RECT.left],dword 0
  3324.     mov   [draw_data+32 + RECT.top],dword 0
  3325.     mov   eax,[0xfe00]
  3326.     mov   ebx,[0xfe04]
  3327.     mov   [draw_data+32 + RECT.right],eax
  3328.     mov   [draw_data+32 + RECT.bottom],ebx
  3329.     call  drawbackground
  3330.     mov   [0xfff0],byte 0
  3331.     mov   [0xfff4],byte 0
  3332.  
  3333.   nobackgr:
  3334.  
  3335.  
  3336.     ; system shutdown request
  3337.  
  3338.     cmp  [0xFF00],byte 0
  3339.     je   noshutdown
  3340.  
  3341.     mov  edx,[shutdown_processes]
  3342.     sub  dl,2
  3343.  
  3344.     cmp  [0xff00],dl
  3345.     jne  no_mark_system_shutdown
  3346.  
  3347.     mov   edx,0x3040
  3348.     movzx ecx,byte [0xff00]
  3349.     add   ecx,5
  3350.   markz:
  3351.     mov   [edx+TASKDATA.state],byte 3
  3352.     add   edx,0x20
  3353.     loop  markz
  3354.  
  3355.   no_mark_system_shutdown:
  3356.  
  3357.     call [disable_mouse]
  3358.  
  3359.     dec  byte [0xff00]
  3360.  
  3361.     cmp  [0xff00],byte 0
  3362.     je   system_shutdown
  3363.  
  3364.   noshutdown:
  3365.  
  3366.  
  3367.     mov   eax,[0x3004]                  ; termination
  3368.     mov   ebx,0x3020+TASKDATA.state
  3369.     mov   esi,1
  3370.  
  3371.   newct:
  3372.     mov   cl,[ebx]
  3373.     cmp   cl,byte 3
  3374.     jz    terminate
  3375.     cmp   cl,byte 4
  3376.     jz    terminate
  3377.  
  3378.     add   ebx,0x20
  3379.     inc   esi
  3380.     dec   eax
  3381.     jnz   newct
  3382.  
  3383.     ret
  3384.  
  3385.  
  3386.  
  3387.  
  3388. ; redraw screen
  3389.  
  3390. redrawscreen:
  3391.  
  3392. ; eax , if process window_data base is eax, do not set flag/limits
  3393.  
  3394.          pushad
  3395.          push  eax
  3396.  
  3397. ;;;         mov   eax,2
  3398. ;;;         call  delay_hs
  3399.  
  3400.          ;mov   ecx,0               ; redraw flags for apps
  3401.          xor   ecx,ecx
  3402.        newdw2:
  3403.  
  3404.          inc   ecx
  3405.          push  ecx
  3406.  
  3407.          mov   eax,ecx
  3408.          shl   eax,5
  3409.          add   eax,window_data
  3410.  
  3411.          cmp   eax,[esp+4]
  3412.          je    not_this_task
  3413.                                    ; check if window in redraw area
  3414.          mov   edi,eax
  3415.  
  3416.          cmp   ecx,1               ; limit for background
  3417.          jz    bgli
  3418.  
  3419.          mov   eax, [edi + WDATA.box.left]
  3420.          mov   ebx, [edi + WDATA.box.top]
  3421.          mov   ecx, [edi + WDATA.box.width]
  3422.          mov   edx, [edi + WDATA.box.height]
  3423.          add   ecx, eax
  3424.          add   edx, ebx
  3425.  
  3426.          mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
  3427.          cmp   ecx,ebx
  3428.          jb    ricino
  3429.  
  3430.          mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
  3431.          cmp   ecx,eax
  3432.          jb    ricino
  3433.  
  3434.          mov   eax, [edi + WDATA.box.left]
  3435.          mov   ebx, [edi + WDATA.box.top]
  3436.          mov   ecx, [edi + WDATA.box.width]
  3437.          mov   edx, [edi + WDATA.box.height]
  3438.          add   ecx, eax
  3439.          add   edx, ebx
  3440.          
  3441.          mov   eax,[dly]    ; eax = area y start     edx = window y end
  3442.          cmp   edx,eax
  3443.          jb    ricino
  3444.  
  3445.          mov   eax,[dlx]    ; eax = area x start     ecx = window x end
  3446.          cmp   ecx,eax
  3447.          jb    ricino
  3448.  
  3449.         bgli:
  3450.  
  3451.          cmp   edi,esi
  3452.          jz    ricino
  3453.  
  3454.          mov   eax,edi
  3455.          add   eax,draw_data-window_data
  3456.  
  3457.          mov   ebx,[dlx]          ; set limits
  3458.          mov   [eax + RECT.left], ebx
  3459.          mov   ebx,[dly]
  3460.          mov   [eax + RECT.top], ebx
  3461.          mov   ebx,[dlxe]
  3462.          mov   [eax + RECT.right], ebx
  3463.          mov   ebx,[dlye]
  3464.          mov   [eax + RECT.bottom], ebx
  3465.  
  3466.          sub   eax,draw_data-window_data
  3467.  
  3468.          cmp   ecx,1
  3469.          jne   nobgrd
  3470.          cmp   esi,1
  3471.          je    newdw8
  3472.          call  drawbackground
  3473.  
  3474.        newdw8:
  3475.        nobgrd:
  3476.  
  3477.          mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
  3478.  
  3479.        ricino:
  3480.  
  3481.        not_this_task:
  3482.  
  3483.          pop   ecx
  3484.  
  3485.          cmp   ecx,[0x3004]
  3486.          jle   newdw2
  3487.  
  3488.          pop  eax
  3489.          popad
  3490.  
  3491.          ret
  3492.  
  3493. calculatebackground:   ; background
  3494.  
  3495.         ; all black
  3496.  
  3497.         mov   [display_data-8],dword 4      ; size x
  3498.         mov   [display_data-4],dword 2      ; size y
  3499.  
  3500.         mov   edi, 0x300000                 ; set background to black
  3501.         xor   eax, eax
  3502.         mov   ecx, 0x0fff00 / 4
  3503.         cld
  3504.         rep   stosd
  3505.  
  3506.         mov   edi,display_data              ; set os to use all pixels
  3507.         mov   eax,0x01010101
  3508.         mov   ecx,0x1fff00 / 4
  3509.         rep   stosd
  3510.  
  3511.         mov   byte [0xFFF0], 0              ; do not draw background!
  3512.  
  3513.         ret
  3514.  
  3515. uglobal
  3516.   imax    dd 0x0
  3517. endg
  3518.  
  3519.  
  3520.  
  3521. delay_ms:     ; delay in 1/1000 sec
  3522.  
  3523.  
  3524.         push  eax
  3525.         push  ecx
  3526.  
  3527.         mov   ecx,esi
  3528.         ; <CPU clock fix by Sergey Kuzmin aka Wildwest>
  3529.         imul  ecx, 33941
  3530.         shr   ecx, 9
  3531.         ; </CPU clock fix>
  3532.  
  3533.         in    al,0x61
  3534.         and   al,0x10
  3535.         mov   ah,al
  3536.         cld
  3537.  
  3538.  cnt1:  in    al,0x61
  3539.         and   al,0x10
  3540.         cmp   al,ah
  3541.         jz    cnt1
  3542.  
  3543.         mov   ah,al
  3544.         loop  cnt1
  3545.  
  3546.         pop   ecx
  3547.         pop   eax
  3548.  
  3549.         ret
  3550.  
  3551.  
  3552. set_app_param:
  3553.         push edi
  3554.  
  3555.         mov  edi,[0x3010]
  3556.         mov  [edi+TASKDATA.event_mask],eax
  3557.  
  3558.         pop  edi
  3559.         ret
  3560.  
  3561.  
  3562.  
  3563. delay_hs:     ; delay in 1/100 secs
  3564.         push  eax
  3565.         push  ecx
  3566.         push  edx
  3567.  
  3568.         mov   edx,[timer_ticks]
  3569.         add   edx,eax
  3570.  
  3571.       newtic:
  3572.         mov   ecx,[timer_ticks]
  3573.         cmp   edx,ecx
  3574.         jbe   zerodelay
  3575.  
  3576.         call  change_task
  3577.  
  3578.         jmp   newtic
  3579.  
  3580.       zerodelay:
  3581.         pop   edx
  3582.         pop   ecx
  3583.         pop   eax
  3584.  
  3585.         ret
  3586.  
  3587.  
  3588. memmove:       ; memory move in bytes
  3589.  
  3590. ; eax = from
  3591. ; ebx = to
  3592. ; ecx = no of bytes
  3593.     test ecx, ecx
  3594.     jle  .ret
  3595.  
  3596.  
  3597.     push esi edi ecx
  3598.  
  3599.     mov  edi, ebx
  3600.     mov  esi, eax
  3601.  
  3602.     test ecx, not 11b
  3603.     jz   @f
  3604.  
  3605.     push ecx
  3606.     shr  ecx, 2
  3607.     rep  movsd
  3608.     pop  ecx
  3609.     and  ecx, 11b
  3610.     jz   .finish
  3611.   @@:
  3612.     rep  movsb
  3613.  
  3614.   .finish:
  3615.     pop  ecx edi esi
  3616.   .ret:
  3617.     ret
  3618.  
  3619.  
  3620. ; <diamond> Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
  3621. ;align 4
  3622. ;
  3623. ;read_floppy_file:
  3624. ;
  3625. ;; as input
  3626. ;;
  3627. ;; eax pointer to file
  3628. ;; ebx file lenght
  3629. ;; ecx start 512 byte block number
  3630. ;; edx number of blocks to read
  3631. ;; esi pointer to return/work area (atleast 20 000 bytes)
  3632. ;;
  3633. ;;
  3634. ;; on return
  3635. ;;
  3636. ;; eax = 0 command succesful
  3637. ;;       1 no fd base and/or partition defined
  3638. ;;       2 yet unsupported FS
  3639. ;;       3 unknown FS
  3640. ;;       4 partition not defined at hd
  3641. ;;       5 file not found
  3642. ;; ebx = size of file
  3643. ;
  3644. ;     mov   edi,[0x3010]
  3645. ;     add   edi,0x10
  3646. ;     add   esi,[edi]
  3647. ;     add   eax,[edi]
  3648. ;
  3649. ;     pushad
  3650. ;     mov  edi,esi
  3651. ;     add  edi,1024
  3652. ;     mov  esi,0x100000+19*512
  3653. ;     sub  ecx,1
  3654. ;     shl  ecx,9
  3655. ;     add  esi,ecx
  3656. ;     shl  edx,9
  3657. ;     mov  ecx,edx
  3658. ;     cld
  3659. ;     rep  movsb
  3660. ;     popad
  3661. ;
  3662. ;     mov   [esp+36],eax
  3663. ;     mov   [esp+24],ebx
  3664. ;     ret
  3665.  
  3666.  
  3667.  
  3668. align 4
  3669.  
  3670. sys_programirq:
  3671.  
  3672.     mov   edi,[0x3010]
  3673.     add   eax,[edi+TASKDATA.mem_start]
  3674.  
  3675.     cmp   ebx,16
  3676.     jae   .not_owner
  3677.     mov   edi,[0x3010]
  3678.     mov   edi,[edi+TASKDATA.pid]
  3679.     cmp   edi,[irq_owner+ebx*4]
  3680.     je    spril1
  3681. .not_owner:
  3682.     mov   [esp+36],dword 1
  3683.     ret
  3684.   spril1:
  3685.  
  3686.     mov   esi,eax
  3687.     shl   ebx,6
  3688.     add   ebx,irq00read
  3689.     mov   edi,ebx
  3690.     mov   ecx,16
  3691.     cld
  3692.     rep   movsd
  3693.     mov   [esp+36],dword 0
  3694.     ret
  3695.  
  3696.  
  3697. align 4
  3698.  
  3699. get_irq_data:
  3700.      cmp   eax,16
  3701.      jae   .not_owner
  3702.      mov   edx,eax           ; check for correct owner
  3703.      shl   edx,2
  3704.      add   edx,irq_owner
  3705.      mov   edx,[edx]
  3706.      mov   edi,[0x3010]
  3707.      mov   edi,[edi+TASKDATA.pid]
  3708.      cmp   edx,edi
  3709.      je    gidril1
  3710. .not_owner:
  3711.      mov   [esp+32],dword 2     ; ecx=2
  3712.      ret
  3713.  
  3714.   gidril1:
  3715.  
  3716.      mov   ebx,eax
  3717.      shl   ebx,12
  3718.      add   ebx,0x2e0000
  3719.      mov   eax,[ebx]
  3720.      mov   ecx,1
  3721.      test  eax,eax
  3722.      jz    gid1
  3723.  
  3724.      dec   eax
  3725.      mov   esi,ebx
  3726.      mov   [ebx],eax
  3727.      movzx ebx,byte [ebx+0x10]
  3728.      add   esi,0x10
  3729.      mov   edi,esi
  3730.      inc   esi
  3731.      mov   ecx,4000 / 4
  3732.      cld
  3733.      rep   movsd
  3734. ;     xor   ecx,ecx     ; as result of 'rep' ecx=0
  3735.    gid1:
  3736.      mov   [esp+36],eax
  3737.      mov   [esp+32],ecx
  3738.      mov   [esp+24],ebx
  3739.      ret
  3740.  
  3741.  
  3742. set_io_access_rights:
  3743.  
  3744.      pushad
  3745.  
  3746.      mov   edi,[0x3000]
  3747.      imul  edi,tss_step
  3748.      add   edi,tss_data+128
  3749. ;     add   edi,128
  3750.  
  3751.      mov   ecx,eax
  3752.      and   ecx,7    ; offset in byte
  3753.  
  3754.      shr   eax,3    ; number of byte
  3755.      add   edi,eax
  3756.  
  3757.      mov   ebx,1
  3758.      shl   ebx,cl
  3759.  
  3760.      cmp   ebp,0                ; enable access - ebp = 0
  3761.      jne   siar1
  3762.  
  3763.      not   ebx
  3764.      and   [edi],byte bl
  3765.  
  3766.      popad
  3767.  
  3768.      ret
  3769.  
  3770.    siar1:
  3771.  
  3772.      or    [edi],byte bl        ; disable access - ebp = 1
  3773.  
  3774.      popad
  3775.  
  3776.      ret
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782. r_f_port_area:
  3783.  
  3784.      test  eax, eax
  3785.      jnz   free_port_area
  3786. ;     je    r_port_area
  3787. ;     jmp   free_port_area
  3788.  
  3789. ;   r_port_area:
  3790.  
  3791.      pushad
  3792.  
  3793.      cmp   ebx,ecx            ; beginning > end ?
  3794.      ja    rpal1
  3795.      cmp   ecx,65536
  3796.      jae   rpal1
  3797.      mov   esi,[0x2d0000]
  3798.      test  esi,esi            ; no reserved areas ?
  3799.      je    rpal2
  3800.      cmp   esi,255            ; max reserved
  3801.      jae   rpal1
  3802.    rpal3:
  3803.      mov   edi,esi
  3804.      shl   edi,4
  3805.      add   edi,0x2d0000
  3806.      cmp   ebx,[edi+8]
  3807.      ja    rpal4
  3808.      cmp   ecx,[edi+4]
  3809.      jae   rpal1
  3810. ;     jb    rpal4
  3811. ;     jmp   rpal1
  3812.    rpal4:
  3813.  
  3814.      dec   esi
  3815.      jnz   rpal3
  3816.      jmp   rpal2
  3817.    rpal1:
  3818.      popad
  3819.      mov   eax,1
  3820.      ret
  3821.  
  3822.    rpal2:
  3823.      popad
  3824.  
  3825.  
  3826.      ; enable port access at port IO map
  3827.      cli
  3828.      pushad                        ; start enable io map
  3829.  
  3830.      cmp   ecx,65536 ;16384
  3831.      jae   no_unmask_io ; jge
  3832.  
  3833.      mov   eax,ebx
  3834.  
  3835.    new_port_access:
  3836.  
  3837.      pushad
  3838.  
  3839.      xor   ebp,ebp                ; enable - eax = port
  3840.      call  set_io_access_rights
  3841.  
  3842.      popad
  3843.  
  3844.      inc   eax
  3845.      cmp   eax,ecx
  3846.      jbe   new_port_access
  3847.  
  3848.    no_unmask_io:
  3849.  
  3850.      popad                         ; end enable io map
  3851.      sti
  3852.  
  3853.      mov   edi,[0x2d0000]
  3854.      add   edi,1
  3855.      mov   [0x2d0000],edi
  3856.      shl   edi,4
  3857.      add   edi,0x2d0000
  3858.      mov   esi,[0x3010]
  3859.      mov   esi,[esi+TASKDATA.pid]
  3860.      mov   [edi],esi
  3861.      mov   [edi+4],ebx
  3862.      mov   [edi+8],ecx
  3863.  
  3864.      xor   eax, eax
  3865.      ret
  3866.  
  3867.  
  3868.  
  3869.  
  3870. free_port_area:
  3871.  
  3872.      pushad
  3873.  
  3874.      mov   esi,[0x2d0000]     ; no reserved areas ?
  3875.      test  esi,esi
  3876.      je    frpal2
  3877.      mov   edx,[0x3010]
  3878.      mov   edx,[edx+TASKDATA.pid]
  3879.    frpal3:
  3880.      mov   edi,esi
  3881.      shl   edi,4
  3882.      add   edi,0x2d0000
  3883.      cmp   edx,[edi]
  3884.      jne   frpal4
  3885.      cmp   ebx,[edi+4]
  3886.      jne   frpal4
  3887.      cmp   ecx,[edi+8]
  3888.      jne   frpal4
  3889.      jmp   frpal1
  3890.    frpal4:
  3891.      dec   esi
  3892.      jnz   frpal3
  3893.    frpal2:
  3894.      popad
  3895.      mov   eax,1
  3896.      ret
  3897.    frpal1:
  3898.      mov   ecx,256
  3899.      sub   ecx,esi
  3900.      shl   ecx,4
  3901.      mov   esi,edi
  3902.      add   esi,16
  3903.      cld
  3904.      rep   movsb
  3905.  
  3906.      dec   dword [0x2d0000]
  3907.  
  3908.      popad
  3909.  
  3910.  
  3911.      ; disable port access at port IO map
  3912.  
  3913.      pushad                        ; start disable io map
  3914.  
  3915.      cmp   ecx,65536 ;16384
  3916.      jge   no_mask_io
  3917.  
  3918.      mov   eax,ebx
  3919.  
  3920.    new_port_access_disable:
  3921.  
  3922.      pushad
  3923.  
  3924.      mov   ebp,1                  ; disable - eax = port
  3925.      call  set_io_access_rights
  3926.  
  3927.      popad
  3928.  
  3929.      inc   eax
  3930.      cmp   eax,ecx
  3931.      jbe   new_port_access_disable
  3932.  
  3933.    no_mask_io:
  3934.  
  3935.      popad                         ; end disable io map
  3936.  
  3937.      xor   eax, eax
  3938.      ret
  3939.  
  3940.  
  3941. reserve_free_irq:
  3942.  
  3943.      mov   ecx, 1
  3944.      cmp   ebx, 16
  3945.      jae   fril1
  3946.      test  eax,eax
  3947.      jz    reserve_irq
  3948.  
  3949.      lea   edi,[irq_owner+ebx*4]
  3950.      mov   edx,[edi]
  3951.      mov   eax,[0x3010]
  3952.      cmp   edx,[eax+TASKDATA.pid]
  3953.      jne   fril1
  3954.      dec   ecx
  3955.      mov   [edi],ecx
  3956.    fril1:
  3957.      mov   [esp+36],ecx ; return in eax
  3958.      ret
  3959.  
  3960.   reserve_irq:
  3961.  
  3962.      lea   edi,[irq_owner+ebx*4]
  3963.      cmp   dword [edi], 0
  3964.      jnz   ril1
  3965.  
  3966.      mov   edx,[0x3010]
  3967.      mov   edx,[edx+TASKDATA.pid]
  3968.      mov   [edi],edx
  3969.      dec   ecx
  3970.    ril1:
  3971.      mov   [esp+36],ecx ; return in eax
  3972.      ret
  3973.  
  3974.  
  3975.  
  3976. drawbackground:
  3977.        inc   [mouse_pause]
  3978.        cmp   [0xfe0c],word 0x12
  3979.        je   dbrv20
  3980.      dbrv12:
  3981.        cmp  [0xfe0c],word 0100000000000000b
  3982.        jge  dbrv20
  3983.        cmp  [0xfe0c],word 0x13
  3984.        je   dbrv20
  3985.        call  vesa12_drawbackground
  3986.        dec   [mouse_pause]
  3987.        call   [draw_pointer]
  3988.        ret
  3989.      dbrv20:
  3990.        cmp   [display_data-12],dword 1
  3991.        jne   bgrstr
  3992.        call  vesa20_drawbackground_tiled
  3993.        dec   [mouse_pause]
  3994.        call   [draw_pointer]
  3995.        ret
  3996.      bgrstr:
  3997.        call  vesa20_drawbackground_stretch
  3998.        dec   [mouse_pause]
  3999.        call   [draw_pointer]
  4000.        ret
  4001.  
  4002. align 4
  4003.  
  4004. syscall_putimage:                       ; PutImage
  4005.  
  4006.      mov   edx,ecx
  4007.      mov   ecx,ebx
  4008.         lea     ebx, [eax+std_application_base_address]
  4009.  
  4010. sys_putimage:
  4011.      test  ecx,0x80008000
  4012.      jnz   .exit
  4013.      test  ecx,0x0000FFFF
  4014.      jz    .exit
  4015.      test  ecx,0xFFFF0000
  4016.      jnz   @f
  4017.   .exit:
  4018.      ret
  4019.  @@:
  4020.         mov     edi,[0x3000]
  4021.         shl     edi,8
  4022.         add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.top]
  4023.         rol     edx,16
  4024.         add     dx,word[edi+0x80000+APPDATA.wnd_clientbox.left]
  4025.         rol     edx,16
  4026.   .forced:
  4027. ;        mov     eax, vga_putimage
  4028.         cmp     [0xfe0c], word 0x12
  4029.         jz      @f   ;.doit
  4030.         mov     eax, vesa12_putimage
  4031.         cmp     [0xfe0c], word 0100000000000000b
  4032.         jae     @f
  4033.         cmp     [0xfe0c], word 0x13
  4034.         jnz     .doit
  4035. @@:
  4036.         mov     eax, vesa20_putimage
  4037. .doit:
  4038. ;       inc     [mouse_pause]
  4039.         call    eax
  4040. ;       dec     [mouse_pause]
  4041.         jmp     [draw_pointer]
  4042.  
  4043. ; eax x beginning
  4044. ; ebx y beginning
  4045. ; ecx x end
  4046. ; edx y end
  4047. ; edi color
  4048.  
  4049. __sys_drawbar:
  4050.         mov     esi,[0x3000]
  4051.         shl     esi,8
  4052.         add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4053.         add     ecx,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4054.         add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4055.         add     edx,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4056.   .forced:
  4057.     inc   [mouse_pause]
  4058.     cmp   [0xfe0c],word 0x12
  4059.     je   dbv20
  4060.    sdbv20:
  4061.     cmp  [0xfe0c],word 0100000000000000b
  4062.     jge  dbv20
  4063.     cmp  [0xfe0c],word 0x13
  4064.     je   dbv20
  4065.     call vesa12_drawbar
  4066.     dec   [mouse_pause]
  4067.     call   [draw_pointer]
  4068.     ret
  4069.   dbv20:
  4070.     call vesa20_drawbar
  4071.     dec   [mouse_pause]
  4072.     call   [draw_pointer]
  4073.     ret
  4074.  
  4075.  
  4076.  
  4077. kb_read:
  4078.  
  4079.         push    ecx edx
  4080.  
  4081.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4082.       kr_loop:
  4083.         in      al,0x64
  4084.         test    al,1
  4085.         jnz     kr_ready
  4086.         loop    kr_loop
  4087.         mov     ah,1
  4088.         jmp     kr_exit
  4089.       kr_ready:
  4090.         push    ecx
  4091.         mov     ecx,32
  4092.       kr_delay:
  4093.         loop    kr_delay
  4094.         pop     ecx
  4095.         in      al,0x60
  4096.         xor     ah,ah
  4097.       kr_exit:
  4098.  
  4099.         pop     edx ecx
  4100.  
  4101.         ret
  4102.  
  4103.  
  4104. kb_write:
  4105.  
  4106.         push    ecx edx
  4107.  
  4108.         mov     dl,al
  4109.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4110.       kw_loop1:
  4111.         in      al,0x64
  4112.         test    al,0x20
  4113.         jz      kw_ok1
  4114.         loop    kw_loop1
  4115.         mov     ah,1
  4116.         jmp     kw_exit
  4117.       kw_ok1:
  4118.         in      al,0x60
  4119.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4120.       kw_loop:
  4121.         in      al,0x64
  4122.         test    al,2
  4123.         jz      kw_ok
  4124.         loop    kw_loop
  4125.         mov     ah,1
  4126.         jmp     kw_exit
  4127.       kw_ok:
  4128.         mov     al,dl
  4129.         out     0x60,al
  4130.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4131.       kw_loop3:
  4132.         in      al,0x64
  4133.         test    al,2
  4134.         jz      kw_ok3
  4135.         loop    kw_loop3
  4136.         mov     ah,1
  4137.         jmp     kw_exit
  4138.       kw_ok3:
  4139.         mov     ah,8
  4140.       kw_loop4:
  4141.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4142.       kw_loop5:
  4143.         in      al,0x64
  4144.         test    al,1
  4145.         jnz     kw_ok4
  4146.         loop    kw_loop5
  4147.         dec     ah
  4148.         jnz     kw_loop4
  4149.       kw_ok4:
  4150.         xor     ah,ah
  4151.       kw_exit:
  4152.  
  4153.         pop     edx ecx
  4154.  
  4155.         ret
  4156.  
  4157.  
  4158. kb_cmd:
  4159.  
  4160.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4161.       c_wait:
  4162.         in      al,0x64
  4163.         test    al,2
  4164.         jz      c_send
  4165.         loop    c_wait
  4166.         jmp     c_error
  4167.       c_send:
  4168.         mov     al,bl
  4169.         out     0x64,al
  4170.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  4171.       c_accept:
  4172.         in      al,0x64
  4173.         test    al,2
  4174.         jz      c_ok
  4175.         loop    c_accept
  4176.       c_error:
  4177.         mov     ah,1
  4178.         jmp     c_exit
  4179.       c_ok:
  4180.         xor     ah,ah
  4181.       c_exit:
  4182.         ret
  4183.  
  4184.  
  4185. setmouse:  ; set mousepicture -pointer
  4186.            ; ps2 mouse enable
  4187.  
  4188.      mov     [0xf200],dword mousepointer
  4189.  
  4190.      cli
  4191. ;     mov     bl,0xa8                 ; enable mouse cmd
  4192. ;     call    kb_cmd
  4193. ;     call    kb_read                 ; read status
  4194. ;     mov     bl,0x20                 ; get command byte
  4195. ;     call    kb_cmd
  4196. ;     call    kb_read
  4197. ;     or      al,3                    ; enable interrupt
  4198. ;     mov     bl,0x60                 ; write command
  4199. ;     push    eax
  4200. ;     call    kb_cmd
  4201. ;     pop     eax
  4202. ;     call    kb_write
  4203. ;     mov     bl,0xd4                 ; for mouse
  4204. ;     call    kb_cmd
  4205. ;     mov     al,0xf4                 ; enable mouse device
  4206. ;     call    kb_write
  4207. ;     call    kb_read           ; read status return
  4208.  
  4209.      ; com1 mouse enable
  4210.  
  4211.      mov   bx,0x3f8 ; combase
  4212.  
  4213.      mov   dx,bx
  4214.      add   dx,3
  4215.      mov   al,0x80
  4216.      out   dx,al
  4217.  
  4218.      mov   dx,bx
  4219.      add   dx,1
  4220.      mov   al,0
  4221.      out   dx,al
  4222.  
  4223.      mov   dx,bx
  4224.      add   dx,0
  4225.      mov   al,0x30*2    ; 0x30 / 4
  4226.      out   dx,al
  4227.  
  4228.      mov   dx,bx
  4229.      add   dx,3
  4230.      mov   al,2         ; 3
  4231.      out   dx,al
  4232.  
  4233.      mov   dx,bx
  4234.      add   dx,4
  4235.      mov   al,0xb
  4236.      out   dx,al
  4237.  
  4238.      mov   dx,bx
  4239.      add   dx,1
  4240.      mov   al,1
  4241.      out   dx,al
  4242.  
  4243.  
  4244.      ; com2 mouse enable
  4245.  
  4246.      mov   bx,0x2f8 ; combase
  4247.  
  4248.      mov   dx,bx
  4249.      add   dx,3
  4250.      mov   al,0x80
  4251.      out   dx,al
  4252.  
  4253.      mov   dx,bx
  4254.      add   dx,1
  4255.      mov   al,0
  4256.      out   dx,al
  4257.  
  4258.      mov   dx,bx
  4259.      add   dx,0
  4260.      mov   al,0x30*2
  4261.      out   dx,al
  4262.  
  4263.      mov   dx,bx
  4264.      add   dx,3
  4265.      mov   al,2
  4266.      out   dx,al
  4267.  
  4268.      mov   dx,bx
  4269.      add   dx,4
  4270.      mov   al,0xb
  4271.      out   dx,al
  4272.  
  4273.      mov   dx,bx
  4274.      add   dx,1
  4275.      mov   al,1
  4276.      out   dx,al
  4277.  
  4278.      ret
  4279.  
  4280.  
  4281. _rdtsc:
  4282.  
  4283.      mov   edx,[cpuid_1+3*4]
  4284.      test  edx,00010000b
  4285.      jz    ret_rdtsc
  4286.      rdtsc
  4287.      ret
  4288.    ret_rdtsc:
  4289.      mov   edx,0xffffffff
  4290.      mov   eax,0xffffffff
  4291.      ret
  4292.  
  4293.  
  4294.  
  4295. rerouteirqs:
  4296.  
  4297.         cli
  4298.  
  4299.         mov     al,0x11         ;  icw4, edge triggered
  4300.         out     0x20,al
  4301.         call    pic_delay
  4302.         out     0xA0,al
  4303.         call    pic_delay
  4304.  
  4305.         mov     al,0x20         ;  generate 0x20 +
  4306.         out     0x21,al
  4307.         call    pic_delay
  4308.         mov     al,0x28         ;  generate 0x28 +
  4309.         out     0xA1,al
  4310.         call    pic_delay
  4311.  
  4312.         mov     al,0x04         ;  slave at irq2
  4313.         out     0x21,al
  4314.         call    pic_delay
  4315.         mov     al,0x02         ;  at irq9
  4316.         out     0xA1,al
  4317.         call    pic_delay
  4318.  
  4319.         mov     al,0x01         ;  8086 mode
  4320.         out     0x21,al
  4321.         call    pic_delay
  4322.         out     0xA1,al
  4323.         call    pic_delay
  4324.  
  4325.         mov     al,255          ; mask all irq's
  4326.         out     0xA1,al
  4327.         call    pic_delay
  4328.         out     0x21,al
  4329.         call    pic_delay
  4330.  
  4331.         mov     ecx,0x1000
  4332.         cld
  4333. picl1:  call    pic_delay
  4334.         loop    picl1
  4335.  
  4336.         mov     al,255          ; mask all irq's
  4337.         out     0xA1,al
  4338.         call    pic_delay
  4339.         out     0x21,al
  4340.         call    pic_delay
  4341.  
  4342.         cli
  4343.  
  4344.         ret
  4345.  
  4346.  
  4347. pic_delay:
  4348.  
  4349.         jmp     pdl1
  4350. pdl1:   ret
  4351.  
  4352.  
  4353. sys_msg_board_str:
  4354.  
  4355.      pushad
  4356.    @@:
  4357.      cmp    [esi],byte 0
  4358.      je     @f
  4359.      mov    eax,1
  4360.      movzx  ebx,byte [esi]
  4361.      call   sys_msg_board
  4362.      inc    esi
  4363.      jmp    @b
  4364.    @@:
  4365.      popad
  4366.      ret
  4367.  
  4368. uglobal
  4369.   msg_board_data: times 512 db 0
  4370.   msg_board_count dd 0x0
  4371. endg
  4372.  
  4373. sys_msg_board:
  4374.  
  4375. ; eax=1 : write :  bl byte to write
  4376. ; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
  4377.  
  4378.      mov  ecx,[msg_board_count]
  4379.      cmp  eax, 1
  4380.      jne  smbl1
  4381.  
  4382.  
  4383.      mov  [msg_board_data+ecx],bl
  4384.      inc  ecx
  4385.      and  ecx, 511
  4386.      mov  [msg_board_count], ecx
  4387.      mov  [check_idle_semaphore], 5
  4388.      ret
  4389.    smbl1:
  4390.  
  4391.      cmp   eax, 2
  4392.      jne   smbl2
  4393.      test  ecx, ecx
  4394.      jz    smbl21
  4395. ;     mov   edi, msg_board_data
  4396. ;     mov   esi, msg_board_data+1
  4397. ;     movzx eax, byte [edi]
  4398.      mov   eax, msg_board_data+1
  4399.      mov   ebx, msg_board_data
  4400.      movzx edx, byte [ebx]
  4401.      call  memmove
  4402. ;     push  ecx
  4403. ;     shr   ecx, 2
  4404. ;     cld
  4405. ;     rep   movsd
  4406. ;     pop   ecx
  4407. ;     and   ecx, 3
  4408. ;     rep   movsb
  4409.      dec   [msg_board_count]
  4410.      mov   [esp+36], edx ;eax
  4411.      mov   [esp+24], dword 1
  4412.      ret
  4413.    smbl21:
  4414.      mov   [esp+36], ecx
  4415.      mov   [esp+24], ecx
  4416.  
  4417.    smbl2:
  4418.      ret
  4419.  
  4420.  
  4421.  
  4422. sys_trace:
  4423.  
  4424.      test eax, eax                  ; get event data
  4425.      jnz  no_get_sys_events
  4426.  
  4427.      mov  esi,save_syscall_data     ; data
  4428.      mov  edi,[0x3010]
  4429.      mov  edi,[edi+TASKDATA.mem_start]
  4430.      add  edi,ebx
  4431.      cld
  4432.      rep  movsb
  4433.  
  4434.      mov  [esp+24],dword 0
  4435.      mov  eax,[save_syscall_count]  ; count
  4436.      mov  [esp+36],eax
  4437.      ret
  4438.  
  4439.    no_get_sys_events:
  4440.  
  4441.      ret
  4442.  
  4443.  
  4444. sys_process_def:
  4445.         mov     edi, [0x3000]
  4446.  
  4447.         dec     eax             ; 1 = set keyboard mode
  4448.      jne   no_set_keyboard_setup
  4449.  
  4450.      shl   edi,8
  4451.      mov   [edi+0x80000 + APPDATA.keyboard_mode],bl
  4452.  
  4453.      ret
  4454.  
  4455.    no_set_keyboard_setup:
  4456.  
  4457.         dec     eax             ; 2 = get keyboard mode
  4458.      jne   no_get_keyboard_setup
  4459.  
  4460.      shl   edi,8
  4461.      movzx eax, byte [0x80000+edi + APPDATA.keyboard_mode]
  4462.  
  4463.      mov   [esp+36],eax
  4464.  
  4465.      ret
  4466.  
  4467.    no_get_keyboard_setup:
  4468.  
  4469.         dec     eax             ; 3 = get keyboard ctrl, alt, shift
  4470.      jne   no_get_keyboard_cas
  4471.  
  4472. ;     xor   eax,eax
  4473. ;     movzx eax,byte [shift]
  4474. ;     movzx ebx,byte [ctrl]
  4475. ;     shl   ebx,2
  4476. ;     add   eax,ebx
  4477. ;     movzx ebx,byte [alt]
  4478. ;     shl   ebx,3
  4479. ;     add   eax,ebx
  4480.  
  4481.  ;// mike.dld [
  4482.      mov   eax, [kb_state]
  4483.  ;// mike.dld ]
  4484.  
  4485.      mov   [esp+36],eax
  4486.  
  4487.      ret
  4488.  
  4489.    no_get_keyboard_cas:
  4490.  
  4491.         dec     eax
  4492.         jnz     no_add_keyboard_hotkey
  4493.  
  4494.         mov     eax, hotkey_list
  4495. @@:
  4496.         cmp     dword [eax+8], 0
  4497.         jz      .found_free
  4498.         add     eax, 16
  4499.         cmp     eax, hotkey_list+16*256
  4500.         jb      @b
  4501.         mov     dword [esp+36], 1
  4502.         ret
  4503. .found_free:
  4504.         mov     [eax+8], edi
  4505.         mov     [eax+4], ecx
  4506.         movzx   ebx, bl
  4507.         lea     ebx, [hotkey_scancodes+ebx*4]
  4508.         mov     ecx, [ebx]
  4509.         mov     [eax], ecx
  4510.         mov     [ebx], eax
  4511.         mov     [eax+12], ebx
  4512.         jecxz   @f
  4513.         mov     [ecx+12], eax
  4514. @@:
  4515.         and     dword [esp+36], 0
  4516.         ret
  4517.  
  4518. no_add_keyboard_hotkey:
  4519.  
  4520.         dec     eax
  4521.         jnz     no_del_keyboard_hotkey
  4522.  
  4523.         movzx   ebx, bl
  4524.         lea     ebx, [hotkey_scancodes+ebx*4]
  4525.         mov     eax, [ebx]
  4526. .scan:
  4527.         test    eax, eax
  4528.         jz      .notfound
  4529.         cmp     [eax+8], edi
  4530.         jnz     .next
  4531.         cmp     [eax+4], ecx
  4532.         jz      .found
  4533. .next:
  4534.         mov     eax, [eax]
  4535.         jmp     .scan
  4536. .notfound:
  4537.         mov     dword [esp+36], 1
  4538.         ret
  4539. .found:
  4540.         mov     ecx, [eax]
  4541.         jecxz   @f
  4542.         mov     edx, [eax+12]
  4543.         mov     [ecx+12], edx
  4544. @@:
  4545.         mov     ecx, [eax+12]
  4546.         mov     edx, [eax]
  4547.         mov     [ecx], edx
  4548.         xor     edx, edx
  4549.         mov     [eax+4], edx
  4550.         mov     [eax+8], edx
  4551.         mov     [eax+12], edx
  4552.         mov     [eax], edx
  4553.         mov     [esp+36], edx
  4554.         ret
  4555.  
  4556. no_del_keyboard_hotkey:
  4557.      ret
  4558.  
  4559.  
  4560. sys_ipc:
  4561.      cmp  eax,1                      ; DEFINE IPC MEMORY
  4562.      jne  no_ipc_def
  4563.      mov  edi,[0x3000]
  4564.      shl  edi,8
  4565.      add  edi,0x80000
  4566.      mov  [edi + APPDATA.ipc_start], ebx
  4567.      mov  [edi + APPDATA.ipc_size], ecx
  4568.      mov  [esp+36],dword 0
  4569.      ret
  4570.    no_ipc_def:
  4571.  
  4572.      cmp  eax,2                      ; SEND IPC MESSAGE
  4573.      jne  no_ipc_send
  4574.      mov  esi,1
  4575.      mov  edi,0x3020
  4576.     ipcs1:
  4577.      cmp  [edi+TASKDATA.pid], ebx
  4578.      je   ipcs2
  4579.      add  edi,0x20
  4580.      inc  esi
  4581.      cmp  esi,[0x3004]
  4582.      jbe  ipcs1
  4583.      mov  [esp+36],dword 4
  4584.      ret
  4585.     ipcs2:
  4586.  
  4587.      cli
  4588.  
  4589.      push esi
  4590.      mov  eax,esi
  4591.      shl  eax,8
  4592.      mov  ebx,[eax+0x80000 + APPDATA.ipc_start]
  4593.      test ebx,ebx                  ; ipc area not defined ?
  4594.      je   ipc_err1
  4595.  
  4596.      add  ebx,[eax+0x80000 + APPDATA.ipc_size]
  4597.      mov  eax,esi
  4598.      shl  eax,5
  4599.      add  ebx,[eax+0x3000 + TASKDATA.mem_start]    ; ebx <- max data position
  4600.  
  4601.      mov  eax,esi                  ; to
  4602.      shl  esi,8
  4603.      add  esi,0x80000
  4604.      mov  edi,[esi+APPDATA.ipc_start]
  4605.      shl  eax,5
  4606.      add  eax,0x3000
  4607.      add  edi,[eax+TASKDATA.mem_start]
  4608.  
  4609.      cmp  [edi],byte 0             ; overrun ?
  4610.      jne  ipc_err2
  4611.  
  4612.      mov  ebp,edi
  4613.      add  edi,[edi+4]
  4614.      add  edi,8
  4615.  
  4616.      mov  esi,ecx                  ; from
  4617.      mov  eax,[0x3010]
  4618.      mov  eax,[eax+TASKDATA.mem_start]
  4619.      add  esi,eax
  4620.  
  4621.      mov  ecx,edx                  ; size
  4622.  
  4623.      mov  eax,edi
  4624.      add  eax,ecx
  4625.      cmp  eax,ebx
  4626.      jg   ipc_err3                 ; not enough room ?
  4627.  
  4628.      push ecx
  4629.  
  4630.      mov  eax,[0x3010]
  4631.      mov  eax,[eax+TASKDATA.pid]
  4632.      mov  [edi-8],eax
  4633.      mov  [edi-4],ecx
  4634.      cld
  4635.      rep  movsb
  4636.  
  4637.      pop  ecx
  4638.      add  ecx,8
  4639.  
  4640.      mov  edi,ebp                  ; increase memory position
  4641.      add  dword [edi+4],ecx
  4642.  
  4643.      mov  edi,[esp]
  4644.      shl  edi,8
  4645.      or   dword [edi+0x80000+APPDATA.event_mask],dword 01000000b ; ipc message
  4646.  
  4647.      cmp  [check_idle_semaphore],dword 20
  4648.      jge  ipc_no_cis
  4649.      mov  [check_idle_semaphore],5
  4650.    ipc_no_cis:
  4651.  
  4652.      xor  eax, eax
  4653.  
  4654.     ipc_err:
  4655.      add  esp,4
  4656.      mov  [esp+36],eax
  4657.      sti
  4658.      ret
  4659.  
  4660.     ipc_err1:
  4661.      add  esp,4
  4662.      mov  [esp+36],dword 1
  4663.      sti
  4664.      ret
  4665.     ipc_err2:
  4666.      add  esp,4
  4667.      mov  [esp+36],dword 2
  4668.      sti
  4669.      ret
  4670.     ipc_err3:
  4671.      add  esp,4
  4672.      mov  [esp+36],dword 3
  4673.      sti
  4674.      ret
  4675.  
  4676.    no_ipc_send:
  4677.  
  4678.      mov  [esp+36],dword -1
  4679.      ret
  4680.  
  4681.  
  4682. align 4
  4683.  
  4684. sys_gs:                         ; direct screen access
  4685.  
  4686.      cmp  eax,1                 ; resolution
  4687.      jne  no_gs1
  4688.      mov  eax,[0xfe00]
  4689.      shl  eax,16
  4690.      mov  ax,[0xfe04]
  4691.      add  eax,0x00010001
  4692.      mov  [esp+36],eax
  4693.      ret
  4694.    no_gs1:
  4695.  
  4696.      cmp   eax,2                ; bits per pixel
  4697.      jne   no_gs2
  4698.      movzx eax,byte [0xfbf1]
  4699.      mov   [esp+36],eax
  4700.      ret
  4701.    no_gs2:
  4702.  
  4703.      cmp   eax,3                ; bytes per scanline
  4704.      jne   no_gs3
  4705.      mov   eax,[0xfe08]
  4706.      mov   [esp+36],eax
  4707.      ret
  4708.    no_gs3:
  4709.  
  4710.      mov  [esp+36],dword -1
  4711.      ret
  4712.  
  4713.  
  4714. align 4 ; PCI functions
  4715.  
  4716. sys_pci:
  4717.  
  4718.      call  pci_api
  4719.      mov   [esp+36],eax
  4720.      ret
  4721.  
  4722.  
  4723. align 4  ;  system functions
  4724.  
  4725. syscall_setpixel:                       ; SetPixel
  4726.  
  4727.  
  4728.      mov   edx,[0x3010]
  4729.      add   eax,[edx-twdw+WDATA.box.left]
  4730.      add   ebx,[edx-twdw+WDATA.box.top]
  4731.         mov     edi,[0x3000]
  4732.         shl     edi,8
  4733.         add     eax,[edi+0x80000+APPDATA.wnd_clientbox.left]
  4734.         add     ebx,[edi+0x80000+APPDATA.wnd_clientbox.top]
  4735.      xor   edi,edi ; no force
  4736. ;     mov   edi,1
  4737.      call  [disable_mouse]
  4738.      jmp   [putpixel]
  4739.  
  4740. align 4
  4741.  
  4742. syscall_writetext:                      ; WriteText
  4743.  
  4744.      mov   edi,[0x3010]
  4745.      mov   ebp,[edi-twdw+WDATA.box.left]
  4746.         mov     esi,[0x3000]
  4747.         shl     esi,8
  4748.         add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4749.      shl   ebp,16
  4750.      add   ebp,[edi-twdw+WDATA.box.top]
  4751.         add     bp,word[esi+0x80000+APPDATA.wnd_clientbox.top]
  4752.      add   ecx,[edi+TASKDATA.mem_start]
  4753.      add   eax,ebp
  4754.      xor   edi,edi
  4755.      jmp   dtext
  4756.  
  4757. align 4
  4758.  
  4759. syscall_openramdiskfile:                ; OpenRamdiskFile
  4760.  
  4761.  
  4762.      mov   edi,[0x3010]
  4763.      add   edi, TASKDATA.mem_start
  4764.      add   eax,[edi]
  4765.      add   edx,[edi]
  4766.      mov   esi,12
  4767.      call  fileread
  4768.      mov   [esp+36],ebx
  4769.      ret
  4770.  
  4771. align 4
  4772.  
  4773. syscall_drawrect:                       ; DrawRect
  4774.  
  4775.      mov   edi,ecx
  4776.      and   edi,0x80FFFFFF
  4777.      test  ax,ax
  4778.      je    drectr
  4779.      test  bx,bx
  4780.      je    drectr
  4781.      movzx ecx,ax
  4782.      shr   eax,16
  4783.      movzx edx,bx
  4784.      shr   ebx,16
  4785.         mov     esi,[0x3000]
  4786.         shl     esi,8
  4787.         add     eax,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4788.         add     ebx,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4789.      add   ecx,eax
  4790.      add   edx,ebx
  4791.      jmp   [drawbar]
  4792.     drectr:
  4793.      ret
  4794.  
  4795. align 4
  4796.  
  4797. syscall_getscreensize:                  ; GetScreenSize
  4798.  
  4799.      movzx eax,word[0xfe00]
  4800.      shl   eax,16
  4801.      mov   ax,[0xfe04]
  4802.      mov   [esp+36],eax
  4803.      ret
  4804.  
  4805. align 4
  4806.  
  4807. syscall_startapp:                       ; StartApp
  4808.      mov   edi,[0x3010]
  4809.      add   edi, TASKDATA.mem_start
  4810.      add   eax,[edi]
  4811.      test  ebx,ebx
  4812.      jz    noapppar
  4813.      add   ebx,[edi]
  4814.    noapppar:
  4815. ;     call  start_application_fl
  4816.      xor   edx,edx      ; compatibility - flags=0
  4817.      call   new_start_application_fl
  4818.      mov   [esp+36],eax
  4819.      ret
  4820.  
  4821.  
  4822. align 4
  4823.  
  4824. syscall_cdaudio:                        ; CD
  4825.  
  4826.      call  sys_cd_audio
  4827.      mov   [esp+36],eax
  4828.      ret
  4829.  
  4830. ; <diamond> ReadHd and StartHdApp functions are obsolete. Use 58 or 70 functions instead.
  4831. ;align 4
  4832. ;
  4833. ;syscall_readhd:                         ; ReadHd
  4834. ;
  4835. ;     mov   edi,[0x3010]
  4836. ;     add   edi,0x10
  4837. ;     add   esi,[edi]
  4838. ;     add   eax,[edi]
  4839. ;     call  read_hd_file
  4840. ;     mov   [esp+36],eax
  4841. ;     mov   [esp+24],ebx
  4842. ;     ret
  4843.  
  4844. ;align 4
  4845. ;
  4846. ;syscall_starthdapp:                     ; StartHdApp
  4847. ;
  4848. ;     mov   edi,[0x3010]
  4849. ;     add   edi,0x10
  4850. ;     add   eax,[edi]
  4851. ;     add   ecx,[edi]
  4852. ;     xor   ebp,ebp
  4853. ;     xor   edx,edx      ; compatibility - flags=0
  4854. ;     call  start_application_hd
  4855. ;     mov   [esp+36],eax
  4856. ;     ret
  4857.  
  4858. align 4
  4859.  
  4860. syscall_delramdiskfile:                 ; DelRamdiskFile
  4861.  
  4862.      mov   edi,[0x3010]
  4863.      add   edi, TASKDATA.mem_start
  4864.      add   eax,[edi]
  4865.      call  filedelete
  4866.      mov   [esp+36],eax
  4867.      ret
  4868.  
  4869. align 4
  4870.  
  4871. syscall_writeramdiskfile:               ; WriteRamdiskFile
  4872.  
  4873.      mov   edi,[0x3010]
  4874.      add   edi, TASKDATA.mem_start
  4875.      add   eax,[edi]
  4876.      add   ebx,[edi]
  4877.      call  filesave
  4878.      mov   [esp+36],eax
  4879.      ret
  4880.  
  4881. align 4
  4882.  
  4883. syscall_getpixel:                       ; GetPixel
  4884.  
  4885.      mov   ecx,[0xfe00]
  4886.      inc   ecx
  4887.      xor   edx,edx
  4888.      div   ecx
  4889.      mov   ebx,edx
  4890.      xchg  eax,ebx
  4891.      call  dword [0xe024]
  4892.      mov   [esp+36],ecx
  4893.      ret
  4894.  
  4895. align 4
  4896.  
  4897. syscall_readstring:                     ; ReadString
  4898.  
  4899.      mov   edi,[0x3010]
  4900.      add   edi, TASKDATA.mem_start
  4901.      add   eax,[edi]
  4902.      call  read_string
  4903.      mov   [esp+36],eax
  4904.      ret
  4905.  
  4906. align 4
  4907.  
  4908. syscall_drawline:                       ; DrawLine
  4909.  
  4910.      mov   edi,[0x3010]
  4911.      movzx edx,word[edi-twdw+WDATA.box.left]
  4912.      mov   ebp,edx
  4913.         mov     esi,[0x3000]
  4914.         shl     esi,8
  4915.         add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.left]
  4916.         add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.left]
  4917.      shl   edx,16
  4918.      add   ebp,edx
  4919.      movzx edx,word[edi-twdw+WDATA.box.top]
  4920.      add   eax,ebp
  4921.      mov   ebp,edx
  4922.         add     ebp,[esi+0x80000+APPDATA.wnd_clientbox.top]
  4923.         add     dx,word[esi+0x80000+APPDATA.wnd_clientbox.top]
  4924.      shl   edx,16
  4925.      xor   edi,edi
  4926.      add   edx,ebp
  4927.      add   ebx,edx
  4928.      jmp   [draw_line]
  4929.  
  4930. align 4
  4931.  
  4932. syscall_getirqowner:                    ; GetIrqOwner
  4933.      cmp   eax,16
  4934.      jae   .err
  4935.      shl   eax,2
  4936.      add   eax,irq_owner
  4937.      mov   eax,[eax]
  4938.      mov   [esp+36],eax
  4939.      ret
  4940. .err:
  4941.      or    dword [esp+36], -1
  4942.      ret
  4943.  
  4944. align 4
  4945.  
  4946. syscall_reserveportarea:                ; ReservePortArea and FreePortArea
  4947.  
  4948.      call  r_f_port_area
  4949.      mov   [esp+36],eax
  4950.      ret
  4951.  
  4952. align 4
  4953.  
  4954. syscall_threads:                        ; CreateThreads
  4955.  
  4956.      call  sys_threads
  4957.      mov   [esp+36],eax
  4958.      ret
  4959.  
  4960. align 4
  4961.  
  4962. stack_driver_stat:
  4963.  
  4964.      call  app_stack_handler            ; Stack status
  4965.  
  4966. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  4967. ;     call  change_task                 ; between sent packet
  4968.  
  4969.      mov   [esp+36],eax
  4970.      ret
  4971.  
  4972. align 4
  4973.  
  4974. socket:                                 ; Socket interface
  4975.      call  app_socket_handler
  4976.  
  4977. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  4978. ;     call  change_task                 ; between sent packet
  4979.  
  4980.      mov   [esp+36],eax
  4981.      mov   [esp+24],ebx
  4982.      ret
  4983.  
  4984. align 4
  4985.  
  4986. user_events:                            ; User event times
  4987.  
  4988.      mov   eax,0x12345678
  4989.      mov   [esp+36],eax
  4990.  
  4991.      ret
  4992.  
  4993. align 4
  4994.  
  4995. read_from_hd:                           ; Read from hd - fn not in use
  4996.  
  4997.      mov   edi,[0x3010]
  4998.      add   edi,TASKDATA.mem_start
  4999.      add   eax,[edi]
  5000.      add   ecx,[edi]
  5001.      add   edx,[edi]
  5002.      call  file_read
  5003.  
  5004.      mov   [esp+36],eax
  5005.      mov   [esp+24],ebx
  5006.  
  5007.      ret
  5008.  
  5009.  
  5010. align 4
  5011.  
  5012. write_to_hd:                            ; Write a file to hd
  5013.  
  5014.      mov   edi,[0x3010]
  5015.      add   edi,TASKDATA.mem_start
  5016.      add   eax,[edi]
  5017.      add   ecx,[edi]
  5018.      add   edx,[edi]
  5019.      call  file_write
  5020.      ret
  5021.  
  5022. ; <diamond> Sysfunction 57, delete_from_hd, is obsolete. Use 58 or 70 functions instead.
  5023. ;align 4
  5024. ;
  5025. ;delete_from_hd:                         ; Delete a file from hd
  5026. ;
  5027. ;     mov   edi,[0x3010]
  5028. ;     add   edi,0x10
  5029. ;     add   eax,[edi]
  5030. ;     add   ecx,[edi]
  5031. ;     call  file_delete
  5032. ;     ret
  5033. ;
  5034.  
  5035. ; --------------- APM ---------------------
  5036. apm_entry    dp    0
  5037. apm_vf        dd    0
  5038. align 4
  5039. sys_apm:
  5040.     cmp    word [apm_vf], 0    ; Check APM BIOS enable
  5041.     jne    @f
  5042.     or    [esp + 56], byte 1    ; error
  5043.     mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
  5044.     ret
  5045.    
  5046. @@:    xchg    eax, ecx
  5047.     xchg    ebx, ecx
  5048.    
  5049.     cmp    al, 3
  5050.     ja    @f
  5051.     and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
  5052.     mov    eax, [apm_vf]
  5053.     mov    [esp + 36], eax
  5054.     shr    eax, 16
  5055.     mov    [esp + 32], eax
  5056.     ret
  5057.  
  5058. @@:    call    pword [apm_entry]    ; call APM BIOS
  5059.     mov    [esp + 8 ], edi
  5060.     mov    [esp + 12], esi
  5061.     mov    [esp + 24], ebx
  5062.     mov    [esp + 28], edx
  5063.     mov    [esp + 32], ecx
  5064.     mov    [esp + 36], eax
  5065.     setc    al
  5066.     and    [esp + 56], byte 0xfe
  5067.     or    [esp + 56], al
  5068.     ret
  5069. ; -----------------------------------------
  5070.  
  5071. align 4
  5072.  
  5073. undefined_syscall:                      ; Undefined system call
  5074.  
  5075.      mov   [esp+36],dword -1
  5076.      ret
  5077.  
  5078.  
  5079. ;clear_busy_flag_at_caller:
  5080.  
  5081. ;      push  edi
  5082.  
  5083. ;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
  5084. ;      imul  edi,8
  5085. ;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  5086.  
  5087. ;      pop   edi
  5088.  
  5089. ;      ret
  5090.  
  5091.  
  5092.  
  5093.  
  5094. keymap:
  5095.  
  5096.      db   '6',27
  5097.      db   '1234567890-=',8,9
  5098.      db   'qwertyuiop[]',13
  5099.      db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
  5100.      db   '@234567890123',180,178,184,'6',176,'7'
  5101.      db   179,'8',181,177,183,185,182
  5102.      db   'AB<D',255,'FGHIJKLMNOPQRSTUVWXYZ'
  5103.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5104.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5105.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5106.  
  5107.  
  5108. keymap_shift:
  5109.  
  5110.      db   '6',27
  5111.      db   '!@#$%^&*()_+',8,9
  5112.      db   'QWERTYUIOP{}',13
  5113.      db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
  5114.      db   '@234567890123',180,178,184,'6',176,'7'
  5115.      db   179,'8',181,177,183,185,182
  5116.      db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
  5117.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5118.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5119.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5120.  
  5121.  
  5122. keymap_alt:
  5123.  
  5124.      db   ' ',27
  5125.      db   ' @ $  {[]}\ ',8,9
  5126.      db   '            ',13
  5127.      db   '             ',0,'           ',0,'4',0,' '
  5128.      db   '             ',180,178,184,'6',176,'7'
  5129.      db   179,'8',181,177,183,185,182
  5130.      db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
  5131.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5132.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5133.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5134.  
  5135.  
  5136. ; device irq owners
  5137. uglobal
  5138. irq_owner:       ; process id
  5139.  
  5140.      dd   0x0
  5141.      dd   0x0
  5142.      dd   0x0
  5143.      dd   0x0
  5144.      dd   0x0
  5145.      dd   0x0
  5146.      dd   0x0
  5147.      dd   0x0
  5148.      dd   0x0
  5149.      dd   0x0
  5150.      dd   0x0
  5151.      dd   0x0
  5152.      dd   0x0
  5153.      dd   0x0
  5154.      dd   0x0
  5155.      dd   0x0
  5156. endg
  5157.  
  5158.  
  5159. ; on irq read ports
  5160. uglobal
  5161.   irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5162.   irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5163.   irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5164.   irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5165.   irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5166.   irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5167.   irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5168.   irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5169.   irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5170.   irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5171.   irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5172.   irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5173.   irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5174.   irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5175.   irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5176.   irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5177. endg
  5178.  
  5179. ; status
  5180. uglobal
  5181.   hd1_status                  dd 0x0  ; 0 - free : other - pid
  5182.   application_table_status    dd 0x0  ; 0 - free : other - pid
  5183. endg
  5184.  
  5185. ; device addresses
  5186. uglobal
  5187.   mididp     dd 0x0
  5188.   midisp     dd 0x0
  5189.  
  5190.   cdbase     dd 0x0
  5191.   cdid       dd 0x0
  5192.  
  5193.   hdbase              dd   0x0  ; for boot 0x1f0
  5194.   hdid                dd   0x0
  5195.   hdpos               dd   0x0  ; for boot 0x1
  5196.   fat32part           dd   0x0  ; for boot 0x1
  5197.  
  5198.   ;part2_ld            dd   0x0
  5199.  
  5200. ;* start code - Mario79
  5201. mouse_pause         dd   0
  5202. MouseTickCounter    dd   0
  5203. ps2_mouse_detected  db   0
  5204. com1_mouse_detected db   0
  5205. com2_mouse_detected db   0
  5206. ;* end code - Mario79
  5207.  
  5208. wraw_bacground_select db 0
  5209.   lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
  5210.   pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
  5211.  
  5212.   sb16       dd 0x0
  5213.   wss        dd 0x0
  5214.  
  5215.   buttontype         dd 0x0
  5216.   windowtypechanged  dd 0x0
  5217. endg
  5218.  
  5219. iglobal
  5220.   keyboard   dd 0x1
  5221.   sound_dma  dd 0x1
  5222.   syslang    dd 0x1
  5223. endg
  5224.  
  5225. IncludeIGlobals
  5226. endofcode:
  5227. IncludeUGlobals
  5228. uglobals_size = $ - endofcode
  5229. diff16 "end of kernel code",0,$
  5230.  
  5231.