Subversion Repositories Kolibri OS

Rev

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