Subversion Repositories Kolibri OS

Rev

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

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