Subversion Repositories Kolibri OS

Rev

Rev 21 | Rev 32 | 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.      ret
  2249. window_minimize db 0
  2250. sound_flag      db 0
  2251. last_key_press  dd 0
  2252. keyboard_mode_sys db 0
  2253.  
  2254. iglobal
  2255. version_inf:
  2256.   db 0,5,2,1  ; version 0.5.2.1
  2257.   db UID_KOLIBRI
  2258.   db 'Kolibri',0
  2259. version_end:
  2260. endg
  2261.  
  2262. UID_NONE=0
  2263. UID_MENUETOS=1   ;official
  2264. UID_KOLIBRI=2    ;russian
  2265.  
  2266. main_loop_sys_getkey:
  2267.     cmp   [0xf400],byte 0
  2268.     je    .finish
  2269.     movzx eax,byte [0xf401]
  2270.     shl   eax,8
  2271.     mov   [last_key_press],eax
  2272.  .finish:
  2273.     ret
  2274.  
  2275. sys_cachetodiskette:
  2276. ;    pushad
  2277. ;    cmp  eax,1
  2278. ;    jne  no_write_all_of_ramdisk
  2279. ;    call fdc_writeramdisk
  2280. ;    popad
  2281. ;    ret
  2282. ;  no_write_all_of_ramdisk:
  2283. ;    cmp eax,2
  2284. ;    jne no_write_part_of_ramdisk
  2285. ;    call fdc_commitflush
  2286. ;    popad
  2287. ;    ret
  2288. ;  no_write_part_of_ramdisk:
  2289. ;    cmp  eax,3
  2290. ;    jne  no_set_fdc
  2291. ;    call fdc_set
  2292. ;    popad
  2293. ;    ret
  2294. ;  no_set_fdc:
  2295. ;    cmp  eax,4
  2296. ;    jne  no_get_fdc
  2297. ;    popad
  2298. ;    call fdc_get
  2299. ;    mov    [esp+36],ecx
  2300. ;    ret
  2301. ;  no_get_fdc:
  2302. ;    popad
  2303. ;    ret
  2304.     cmp eax,1
  2305.     jne no_floppy_a_save
  2306.     mov   [flp_number],1
  2307.     jmp save_image_on_floppy
  2308.   no_floppy_a_save:
  2309.     cmp eax,2
  2310.     jne no_floppy_b_save
  2311.     mov   [flp_number],2
  2312.   save_image_on_floppy:
  2313.     call save_image
  2314.     mov  [esp+36],dword 0
  2315.     cmp  [FDC_Status],0
  2316.     je   yes_floppy_save            
  2317.   no_floppy_b_save:
  2318.     mov [esp+36],dword 1
  2319.   yes_floppy_save:
  2320.     ret
  2321.  
  2322. uglobal
  2323. ;  bgrchanged  dd  0x0
  2324. endg
  2325.  
  2326. sys_background:
  2327.  
  2328.     cmp   eax,1                            ; BACKGROUND SIZE
  2329.     jnz   nosb1
  2330.     cmp   ebx,0
  2331.     je    sbgrr
  2332.     cmp   ecx,0
  2333.     je    sbgrr
  2334.     mov   [display_data-8],ebx
  2335.     mov   [display_data-4],ecx
  2336. ;    mov   [bgrchanged],1
  2337.   sbgrr:
  2338.     ret
  2339.   nosb1:
  2340.  
  2341.     cmp   eax,2                            ; SET PIXEL
  2342.     jnz   nosb2
  2343.     mov   edx,0x160000-16
  2344.     cmp   edx,ebx
  2345.     jbe   nosb2
  2346.     mov   edx,[ebx]
  2347.     and   edx,0xFF000000 ;255*256*256*256
  2348.     and   ecx,0x00FFFFFF ;255*256*256+255*256+255
  2349.     add   edx,ecx
  2350.     mov   [ebx+0x300000],edx
  2351. ;    mov   [bgrchanged],1
  2352.     ret
  2353.   nosb2:
  2354.  
  2355.     cmp   eax,3                            ; DRAW BACKGROUND
  2356.     jnz   nosb3
  2357. draw_background_temp:
  2358. ;    cmp   [bgrchanged],1 ;0
  2359. ;    je    nosb31
  2360. ;draw_background_temp:
  2361. ;    mov   [bgrchanged],1 ;0
  2362.     mov   [0xfff0],byte 1
  2363.    nosb31:
  2364.     ret
  2365.   nosb3:
  2366.  
  2367.     cmp   eax,4                            ; TILED / STRETCHED
  2368.     jnz   nosb4
  2369.     cmp   ebx,[display_data-12]
  2370.     je    nosb41
  2371.     mov   [display_data-12],ebx
  2372. ;    mov   [bgrchanged],1
  2373.    nosb41:
  2374.     ret
  2375.   nosb4:
  2376.  
  2377.     cmp   eax,5                            ; BLOCK MOVE TO BGR
  2378.     jnz   nosb5
  2379.   ; bughere
  2380.     mov   edi, [0x3010]
  2381.     add   ebx, [edi+0x10]
  2382.  ;   mov   esi, ebx
  2383.  ;   mov   edi, ecx
  2384.     mov   eax, ebx
  2385.     mov   ebx, ecx
  2386.     add   ecx, edx
  2387.     cmp   ecx, 0x160000-16
  2388.     ja    .fin
  2389.  ;   add   edi, 0x300000
  2390.     add   ebx, 0x300000
  2391.     mov   ecx, edx
  2392.     cmp   ecx, 0x160000-16
  2393.     ja    .fin
  2394. ;    mov   [bgrchanged],1
  2395.   ;  cld
  2396.   ;  rep   movsb
  2397.     call  memmove
  2398.   .fin:
  2399.     ret
  2400.   nosb5:
  2401.  
  2402.     ret
  2403.  
  2404.  
  2405. align 4
  2406.  
  2407. sys_getbackground:
  2408.  
  2409.     cmp   eax,1                                  ; SIZE
  2410.     jnz   nogb1
  2411.     mov   eax,[display_data-8]
  2412.     shl   eax,16
  2413.     mov   ax,[display_data-4]
  2414.     mov   [esp+36],eax
  2415.     ret
  2416.   nogb1:
  2417.  
  2418.     cmp   eax,2                                  ; PIXEL
  2419.     jnz   nogb2
  2420.     mov   edx,0x160000-16
  2421.     cmp   edx,ebx
  2422.     jbe   nogb2
  2423.     mov   eax, [ebx+0x300000]
  2424.     and   eax, 0xFFFFFF
  2425.     mov   [esp+36],eax
  2426.     ret
  2427.   nogb2:
  2428.  
  2429.     cmp   eax,4                                  ; TILED / STRETCHED
  2430.     jnz   nogb4
  2431.     mov   eax,[display_data-12]
  2432.   nogb4:
  2433.     mov   [esp+36],eax
  2434.     ret
  2435.  
  2436.  
  2437. align 4
  2438.  
  2439. sys_getkey:
  2440.     mov   [esp+36],dword 1
  2441.     mov   ebx, [0x3000]                          ; TOP OF WINDOW STACK
  2442.     movzx ecx,word [0xC000 + ebx * 2]
  2443.     mov   edx,[0x3004]
  2444.     cmp   ecx,edx
  2445.     jne   .finish
  2446.     cmp   [0xf400],byte 0
  2447.     je    .finish
  2448.     movzx eax,byte [0xf401]
  2449.     shl   eax,8
  2450.     push  eax
  2451.     dec   byte [0xf400]
  2452.     and   byte [0xf400],127
  2453.     movzx ecx,byte [0xf400]
  2454.     add   ecx,2
  2455.  ;   mov   esi,0xf402
  2456.  ;   mov   edi,0xf401
  2457.  ;   cld
  2458.  ;  rep   movsb
  2459.     mov   eax, 0xF402
  2460.     mov   ebx, 0xF401
  2461.     call  memmove
  2462.     pop   eax
  2463.     mov   [last_key_press],eax
  2464.  
  2465.     mov   eax,[kb_state]
  2466.     and   al,110000b
  2467.     cmp   al,100000b
  2468.     je    .yes_win_key
  2469.     cmp   al,10000b
  2470.     je    .yes_win_key
  2471.     mov   eax,[last_key_press]
  2472.     jmp   .no_win_key
  2473. ;    cmp   ah,232
  2474. ;    je    .yes_win_key
  2475. ;    cmp   ah,233
  2476. ;    jne   .no_win_key
  2477.  .yes_win_key:
  2478.     mov   eax,1
  2479.  .no_win_key:
  2480.     mov   [esp+36],eax
  2481.  .finish:
  2482.     ret
  2483.  
  2484.  
  2485. align 4
  2486.  
  2487. sys_getbutton:
  2488.  
  2489.     mov   ebx, [0x3000]                         ; TOP OF WINDOW STACK
  2490.     mov   [esp+36],dword 1
  2491.     movzx ecx, word [0xC000 + ebx * 2]
  2492.     mov   edx, [0x3004] ; less than 256 processes
  2493.     cmp   ecx,edx
  2494.     jne   .exit
  2495.     movzx eax,byte [0xf500]
  2496.     test  eax,eax
  2497.     jz    .exit
  2498.     mov   eax,[0xf501]
  2499.     shl   eax,8
  2500.     mov   [0xf500],byte 0
  2501.     mov   [esp+36],eax
  2502.  .exit:
  2503.     ret
  2504.  
  2505.  
  2506. align 4
  2507.  
  2508. sys_cpuusage:
  2509.  
  2510. ;  RETURN:
  2511. ;
  2512. ;  +00 dword     process cpu usage
  2513. ;  +04  word     position in windowing stack
  2514. ;  +06  word     windowing stack value at current position (cpu nro)
  2515. ;  +10 12 bytes  name
  2516. ;  +22 dword     start in mem
  2517. ;  +26 dword     used mem
  2518. ;  +30 dword     PID , process idenfification number
  2519. ;
  2520.  
  2521.     mov  edi,[0x3010]   ; eax = return area
  2522.     add  edi,0x10
  2523.     add  eax,[edi]
  2524.  
  2525.     cmp  ebx,-1         ; who am I ?
  2526.     jne  no_who_am_i
  2527.     mov  ebx,[0x3000]
  2528.   no_who_am_i:
  2529.  
  2530.     push eax            ; return area
  2531.     push ebx            ; process number
  2532.  
  2533.     push ebx
  2534.     push ebx
  2535.     push eax
  2536.  
  2537.     ; return memory usage
  2538.  
  2539.     xor  edx,edx
  2540.     mov  eax,0x20
  2541.     mul  ebx
  2542.     add  eax,0x3000+0x1c
  2543.     mov  ebx,eax
  2544.     pop  eax
  2545.     mov  ecx,[ebx]
  2546.     mov  [eax],ecx
  2547.     pop  ebx
  2548. ;    mov  ebx,[esp]
  2549. ;    shl  ebx,1
  2550. ;    add  ebx,0xc000
  2551.     mov  cx, [0xC000 + ebx * 2]
  2552.     mov  [eax+4],cx
  2553. ;    mov  ebx,[esp]
  2554. ;    shl  ebx,1
  2555. ;    add  ebx,0xc400
  2556.     mov  cx, [0xC400 + ebx * 2]
  2557.     mov  [eax+6],cx
  2558. ;    pop  ebx
  2559.     push eax
  2560.     mov  eax,ebx
  2561.     shl  eax,8
  2562.     add  eax,0x80000
  2563.     pop  ebx
  2564.     add  ebx,10
  2565.     mov  ecx,11
  2566.     call memmove
  2567.  
  2568.     ; memory usage
  2569.  
  2570.     xor    eax,eax
  2571.     mov    edx,0x100000*16
  2572.     pop    ecx                                   ; get gdt of tss
  2573.     cmp    ecx,1
  2574.     je     os_mem
  2575.     shl    ecx,8
  2576.     mov    edx,[0x80000+ecx+0x8c]
  2577.     mov    eax,std_application_base_address
  2578.     ;add    ecx,0x80000+0x88
  2579.     ;mov    ecx,[ecx]
  2580. ;    shl    ecx,3
  2581.     ; eax run base -> edx used memory
  2582. ;    mov    al,[ecx+gdts+ app_code-3 +4]        ;  base  23:16
  2583. ;    mov    ah,[ecx+gdts+ app_code-3 +7]        ;  base  31:24
  2584. ;    shl    eax,16
  2585. ;    mov    ax,[ecx+gdts+ app_code-3 +2]        ;  base  0:15
  2586. ;    movzx  edx,word [ecx+gdts+ app_code-3 +0]
  2587. ;    shl    edx,12
  2588.  
  2589.   os_mem:
  2590.     dec    edx
  2591.     mov    [ebx+12],eax
  2592.     mov    [ebx+16],edx
  2593.  
  2594.     ; PID (+30)
  2595.  
  2596.     mov    eax,[esp]
  2597.     shl    eax,5
  2598.     add    eax,0x3000+0x4
  2599.     mov    eax,[eax]
  2600.     mov    [ebx+20],eax
  2601.  
  2602.     ; window position and size
  2603.  
  2604.     mov    esi,[esp]
  2605.     shl    esi,5
  2606.     add    esi,window_data
  2607.     mov    edi,[esp+4]
  2608.     add    edi,34
  2609.     mov    ecx,4*4
  2610.     cld
  2611.     rep    movsb
  2612.  
  2613.     ; Process state (+50)
  2614.  
  2615.     mov    eax,[esp]
  2616.     shl    eax,5
  2617.     add    eax,0x3000+0xa
  2618.     mov    eax,[eax]
  2619.     mov    [ebx+40],ax
  2620.  
  2621.  
  2622.     pop    ebx
  2623.     pop    eax
  2624.  
  2625.     ; return number of processes
  2626.  
  2627.     mov    eax,[0x3004]
  2628.     mov    [esp+36],eax
  2629.     ret
  2630.  
  2631.  
  2632.  
  2633.  
  2634. align 4
  2635. sys_clock:
  2636.         cli
  2637.   ; Mikhail Lisovin  xx Jan 2005
  2638.   @@:   mov   al, 10
  2639.         out   0x70, al
  2640.         in    al, 0x71
  2641.         test  al, al
  2642.         jns   @f
  2643.         mov   esi, 1
  2644.         call  delay_ms
  2645.         jmp   @b
  2646.   @@:
  2647.   ; end Lisovin's fix
  2648.  
  2649.         xor   al,al           ; seconds
  2650.         out   0x70,al
  2651.         in    al,0x71
  2652.         movzx ecx,al
  2653.         mov   al,02           ; minutes
  2654.         shl   ecx,16
  2655.         out   0x70,al
  2656.         in    al,0x71
  2657.         movzx edx,al
  2658.         mov   al,04           ; hours
  2659.         shl   edx,8
  2660.         out   0x70,al
  2661.         in    al,0x71
  2662.         add   ecx,edx
  2663.         movzx edx,al
  2664.         add   ecx,edx
  2665.         sti
  2666.         mov   [esp+36],ecx
  2667.         ret
  2668.  
  2669.  
  2670. align 4
  2671.  
  2672. sys_date:
  2673.  
  2674.         cli
  2675.         mov     al,6            ; day of week
  2676.         out     0x70,al
  2677.         in      al,0x71
  2678.         mov     ch,al
  2679.         mov     al,7            ; date
  2680.         out     0x70,al
  2681.         in      al,0x71
  2682.         mov     cl,al
  2683.         mov     al,8            ; month
  2684.         shl     ecx,16
  2685.         out     0x70,al
  2686.         in      al,0x71
  2687.         mov     ch,al
  2688.         mov     al,9            ; year
  2689.         out     0x70,al
  2690.         in      al,0x71
  2691.         mov     cl,al
  2692.         sti
  2693.         mov     [esp+36],ecx
  2694.         ret
  2695.  
  2696.  
  2697. ; redraw status
  2698.  
  2699. sys_redrawstat:
  2700.  
  2701.     cmp  eax,1
  2702.     jne  no_widgets_away
  2703.  
  2704.     ; buttons away
  2705.  
  2706.     mov   ecx,[0x3000]
  2707.  
  2708.   sys_newba2:
  2709.  
  2710.     mov   edi,[0xfe88]
  2711.     cmp   [edi],dword 0  ; empty button list ?
  2712.     je    end_of_buttons_away
  2713.  
  2714.     movzx ebx,word [edi]
  2715.     inc   ebx
  2716.  
  2717.     mov   eax,edi
  2718.  
  2719.   sys_newba:
  2720.  
  2721.     dec   ebx
  2722.     jz    end_of_buttons_away
  2723.  
  2724.     add   eax,0x10
  2725.     cmp   cx,[eax]
  2726.     jnz   sys_newba
  2727.  
  2728.     push  eax ebx ecx
  2729.     mov   ecx,ebx
  2730.     inc   ecx
  2731.     shl   ecx,4
  2732.     mov   ebx,eax
  2733.     add   eax,0x10
  2734.     call  memmove
  2735.     dec   dword [edi]
  2736.     pop   ecx ebx eax
  2737.  
  2738.     jmp   sys_newba2
  2739.  
  2740.   end_of_buttons_away:
  2741.  
  2742.     ret
  2743.  
  2744.   no_widgets_away:
  2745.  
  2746.     cmp   eax,2
  2747.     jnz   srl1
  2748.  
  2749.     mov   edx,[0x3010]      ; return whole screen draw area for this app
  2750.     add   edx,draw_data-0x3000
  2751.     mov   [edx+0],dword 0
  2752.     mov   [edx+4],dword 0
  2753.     mov   eax,[0xfe00]
  2754.     mov   [edx+8],eax
  2755.     mov   eax,[0xfe04]
  2756.     mov   [edx+12],eax
  2757.  
  2758.     mov   edi,[0x3010]
  2759.     sub   edi,twdw
  2760.     mov   [edi+30],byte 1   ; no new position & buttons from app
  2761.  
  2762.     call  sys_window_mouse
  2763.  
  2764.     ret
  2765.  
  2766.   srl1:
  2767.  
  2768.     ret
  2769.  
  2770.  
  2771. sys_drawwindow:
  2772.  
  2773.     mov   edi,ecx
  2774.     shr   edi,16+8
  2775.     and   edi,15
  2776.  
  2777.     cmp   edi,0   ; type I    - original style
  2778.     jne   nosyswI
  2779.     call  sys_set_window
  2780.     call  drawwindow_I
  2781.     ret
  2782.   nosyswI:
  2783.  
  2784.     cmp   edi,1   ; type II   - only reserve area, no draw
  2785.     jne   nosyswII
  2786.     call  sys_set_window
  2787.     call  sys_window_mouse
  2788.     ret
  2789.   nosyswII:
  2790.  
  2791.     cmp   edi,2   ; type III  - new style
  2792.     jne   nosyswIII
  2793.     call  sys_set_window
  2794.     call  drawwindow_III
  2795.     ret
  2796.   nosyswIII:
  2797.  
  2798.     cmp   edi,3   ; type IV - skinned window
  2799.     jne   nosyswIV
  2800.     call  sys_set_window
  2801.     call  drawwindow_IV
  2802.     ret
  2803.   nosyswIV:
  2804.  
  2805.     ret
  2806.  
  2807.  
  2808. sys_set_window:
  2809.  
  2810.     mov   edi,[0x3000]
  2811.     shl   edi,5
  2812.     add   edi,window_data
  2813.  
  2814.     ; colors
  2815.     mov   [edi+16],ecx
  2816.     mov   [edi+20],edx
  2817.     mov   [edi+24],esi
  2818.  
  2819.     ; check flag (?)
  2820.     cmp   [edi+30],byte 1
  2821.     jz    newd
  2822.  
  2823.     push  eax
  2824.     mov   eax,[timer_ticks] ;[0xfdf0]
  2825.     add   eax,100
  2826.     mov   [new_window_starting],eax
  2827.     pop   eax
  2828.  
  2829.     mov   [edi+8],ax
  2830.     mov   [edi+12],bx
  2831.     shr   eax,16
  2832.     shr   ebx,16
  2833.     mov   [edi+00],ax
  2834.     mov   [edi+04],bx
  2835.  
  2836.  
  2837.     call  check_window_position
  2838.  
  2839.  
  2840.     push  ecx esi edi               ; save for window fullscreen/resize
  2841.     mov   esi,edi
  2842.     sub   edi,window_data
  2843.     shr   edi,5
  2844.     shl   edi,8
  2845.     add   edi,0x80000+0x90
  2846.     mov   ecx,4
  2847.     cld
  2848.     rep   movsd
  2849.     pop   edi esi ecx
  2850.  
  2851.     push  eax ebx ecx edx
  2852. ;;;    mov   eax, 1
  2853. ;;;    call  delay_hs
  2854.     movzx eax, word [edi+00]
  2855.     movzx ebx, word [edi+04]
  2856.     movzx ecx, word [edi+8]
  2857.     movzx edx, word [edi+12]
  2858.     add   ecx, eax
  2859.     add   edx, ebx
  2860.     call  calculatescreen
  2861.     pop   edx ecx ebx eax
  2862.  
  2863.     mov   [0xf400],byte 0           ; empty keyboard buffer
  2864.     mov   [0xf500],byte 0           ; empty button buffer
  2865.  
  2866.   newd:
  2867.     mov   [edi+31],byte 0   ; no redraw
  2868.     mov   edx,edi
  2869.  
  2870.     ret
  2871.  
  2872.  
  2873. sys_window_move:
  2874.  
  2875.         cmp  [window_move_pr],0
  2876.         je   mwrl1
  2877.  
  2878.         mov  [esp+36],dword 1         ; return queue error
  2879.  
  2880.         ret
  2881.  
  2882.      mwrl1:
  2883.  
  2884.         mov   edi,[0x3000]            ; requestor process base
  2885.         mov   [window_move_pr],edi
  2886.  
  2887.         mov   [window_move_eax],eax
  2888.         mov   [window_move_ebx],ebx
  2889.         mov   [window_move_ecx],ecx
  2890.         mov   [window_move_edx],edx
  2891.  
  2892.         mov   [esp+36],dword 0        ; return success
  2893.  
  2894.         ret
  2895.  
  2896. type_background_1:
  2897.     cmp   [0xfff0],byte 0               ; background update ?
  2898.     jz    temp_nobackgr
  2899.     mov   [0xfff0],byte 2
  2900.     call  change_task
  2901.     mov   [draw_data+32+0],dword 0
  2902.     mov   [draw_data+32+4],dword 0
  2903.     mov   eax,[0xfe00]
  2904.     mov   ebx,[0xfe04]
  2905.     mov   [draw_data+32+8],eax
  2906.     mov   [draw_data+32+12],ebx
  2907.     call  drawbackground
  2908.     mov   [0xfff0],byte 0
  2909.     mov   [0xfff4],byte 0
  2910. temp_nobackgr:
  2911.     ret
  2912.    
  2913. uglobal
  2914.   window_move_pr   dd  0x0
  2915.   window_move_eax  dd  0x0
  2916.   window_move_ebx  dd  0x0
  2917.   window_move_ecx  dd  0x0
  2918.   window_move_edx  dd  0x0
  2919. endg
  2920.  
  2921. ;ok - 100% work
  2922. ;nt - not tested
  2923. ;---------------------------------------------------------------------------------------------
  2924. ;eax
  2925. ;0 - task switch counter. Ret switch counter in eax. Block. ok.
  2926. ;1 - change task. Ret nothing. Block. ok.
  2927. ;2 - performance control
  2928. ; ebx
  2929. ; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
  2930. ; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
  2931. ; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
  2932. ; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
  2933. ; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
  2934. ;eax
  2935. ;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  2936. ;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  2937. ;---------------------------------------------------------------------------------------------
  2938. sys_sheduler: ;noname & halyavin
  2939.     cmp eax,0
  2940.     je shed_counter
  2941.     cmp eax,2
  2942.     je perf_control
  2943.     cmp eax,3
  2944.     je rdmsr_instr
  2945.     cmp eax,4
  2946.     je wrmsr_instr
  2947.     cmp eax,1
  2948.     jne not_supported
  2949.     call change_task ;delay,0
  2950. ret
  2951. shed_counter:
  2952.     mov eax,[context_counter]
  2953.     mov [esp+36],eax
  2954. not_supported:
  2955. ret
  2956. perf_control:
  2957.     inc eax ;now eax=3
  2958.     cmp ebx,eax
  2959.     je cache_disable
  2960.     dec eax
  2961.     cmp ebx,eax
  2962.     je cache_enable
  2963.     dec eax
  2964.     cmp ebx,eax
  2965.     je is_cache_enabled
  2966.     dec eax
  2967.     cmp ebx,eax
  2968.     je modify_pce
  2969. ret
  2970.  
  2971. rdmsr_instr:
  2972. ;now counter in ecx
  2973. ;(edx:eax) esi:edi => edx:esi
  2974. mov eax,esi
  2975. rdmsr
  2976. mov [esp+36],eax
  2977. mov [esp+24],edx ;ret in ebx?
  2978. ret
  2979.  
  2980. wrmsr_instr:
  2981. ;now counter in ecx
  2982. ;(edx:eax) esi:edi => edx:esi
  2983. mov eax,esi
  2984. wrmsr
  2985. mov [esp+36],eax
  2986. mov [esp+24],edx ;ret in ebx?
  2987. ret
  2988.  
  2989. cache_disable:
  2990.        mov eax,cr0
  2991.        or  eax,01100000000000000000000000000000b
  2992.        mov cr0,eax
  2993.        wbinvd ;set MESI
  2994. ret
  2995.  
  2996. cache_enable:
  2997.        mov eax,cr0
  2998.        and eax,10011111111111111111111111111111b
  2999.        mov cr0,eax
  3000. ret
  3001.  
  3002. is_cache_enabled:
  3003.        mov eax,cr0
  3004.        mov ebx,eax
  3005.        and eax,01100000000000000000000000000000b
  3006.        jz cache_disabled
  3007.        mov [esp+36],ebx
  3008. cache_disabled:
  3009.        mov dword [esp+36],eax ;0
  3010. ret
  3011.  
  3012. modify_pce:
  3013.        mov eax,cr4
  3014. ;       mov ebx,0
  3015. ;       or  bx,100000000b ;pce
  3016. ;       xor eax,ebx ;invert pce
  3017.        bts eax,8 ;pce=cr4[8]
  3018.        mov cr4,eax
  3019.        mov [esp+36],eax
  3020. ret
  3021. ;---------------------------------------------------------------------------------------------
  3022.  
  3023.  
  3024. ; check if pixel is allowed to be drawn
  3025.  
  3026. checkpixel:
  3027.         push eax edx
  3028.  
  3029.         mov  edx,[0xfe00]     ; screen x size
  3030.         inc  edx
  3031.         imul edx, ebx
  3032.         mov  dl, [eax+edx+display_data] ; lea eax, [...]
  3033.  
  3034.         mov  eax, [0x3010]
  3035.  
  3036.         xor  ecx, ecx
  3037.         cmp  byte [eax+0xe], dl
  3038.         setne cl
  3039.  
  3040.         pop  edx eax
  3041.         ret
  3042.  
  3043. uglobal
  3044.   mouse_active  db  0
  3045. endg
  3046. iglobal
  3047.   cpustring db 'CPU        '
  3048. endg
  3049.  
  3050.  
  3051. align 4
  3052. ; check misc
  3053.  
  3054. checkmisc:
  3055.  
  3056.     cmp   [ctrl_alt_del], 1
  3057.     jne   nocpustart
  3058.     mov   eax, cpustring
  3059.     call  start_application_fl
  3060.     mov   [ctrl_alt_del], 0
  3061.   nocpustart:
  3062.     cmp   [mouse_active], 1
  3063.     jne   mouse_not_active
  3064.     mov   [mouse_active], 0
  3065.     xor   edi, edi
  3066.     mov   ecx, [0x3004]
  3067.    set_mouse_event:
  3068.     add   edi, 256
  3069.     or    [edi+0x80000+0xA8], dword 00100000b
  3070.     loop  set_mouse_event
  3071.   mouse_not_active:
  3072.  
  3073.  
  3074.     cmp   [0xfff0],byte 0               ; background update ?
  3075.     jz    nobackgr
  3076.     mov   [0xfff0],byte 2
  3077.     call  change_task
  3078.     mov   [draw_data+32+0],dword 0
  3079.     mov   [draw_data+32+4],dword 0
  3080.     mov   eax,[0xfe00]
  3081.     mov   ebx,[0xfe04]
  3082.     mov   [draw_data+32+8],eax
  3083.     mov   [draw_data+32+12],ebx
  3084.     call  drawbackground
  3085.     mov   [0xfff0],byte 0
  3086.     mov   [0xfff4],byte 0
  3087.  
  3088.   nobackgr:
  3089.  
  3090.  
  3091.     ; system shutdown request
  3092.  
  3093.     cmp  [0xFF00],byte 0
  3094.     je   noshutdown
  3095.  
  3096.     mov  edx,[shutdown_processes]
  3097.     sub  dl,2
  3098.  
  3099.     cmp  [0xff00],dl
  3100.     jne  no_mark_system_shutdown
  3101.  
  3102.     mov   edx,0x3040
  3103.     movzx ecx,byte [0xff00]
  3104.     add   ecx,5
  3105.   markz:
  3106.     mov   [edx+0xa],byte 3
  3107.     add   edx,0x20
  3108.     loop  markz
  3109.  
  3110.   no_mark_system_shutdown:
  3111.  
  3112.     call [disable_mouse]
  3113.  
  3114.     dec  byte [0xff00]
  3115.  
  3116.     cmp  [0xff00],byte 0
  3117.     je   system_shutdown
  3118.  
  3119.   noshutdown:
  3120.  
  3121.  
  3122.     mov   eax,[0x3004]                  ; termination
  3123.     mov   ebx,0x3020+0xa
  3124.     mov   esi,1
  3125.  
  3126.   newct:
  3127.     mov   cl,[ebx]
  3128.     cmp   cl,byte 3
  3129.     jz    terminate
  3130.     cmp   cl,byte 4
  3131.     jz    terminate
  3132.  
  3133.     add   ebx,0x20
  3134.     inc   esi
  3135.     dec   eax
  3136.     jnz   newct
  3137.  
  3138.     ret
  3139.  
  3140.  
  3141.  
  3142.  
  3143. ; redraw screen
  3144.  
  3145. redrawscreen:
  3146.  
  3147. ; eax , if process window_data base is eax, do not set flag/limits
  3148.  
  3149.          pushad
  3150.          push  eax
  3151.  
  3152. ;;;         mov   eax,2
  3153. ;;;         call  delay_hs
  3154.  
  3155.          ;mov   ecx,0               ; redraw flags for apps
  3156.          xor   ecx,ecx
  3157.        newdw2:
  3158.  
  3159.          inc   ecx
  3160.          push  ecx
  3161.  
  3162.          mov   eax,ecx
  3163.          shl   eax,5
  3164.          add   eax,window_data
  3165.  
  3166.          cmp   eax,[esp+4]
  3167.          je    not_this_task
  3168.                                    ; check if window in redraw area
  3169.          mov   edi,eax
  3170.  
  3171.          cmp   ecx,1               ; limit for background
  3172.          jz    bgli
  3173.  
  3174.          mov   eax,[edi+0]
  3175.          mov   ebx,[edi+4]
  3176.          mov   ecx,[edi+8]
  3177.          mov   edx,[edi+12]
  3178.          add   ecx,eax
  3179.          add   edx,ebx
  3180.  
  3181.          mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
  3182.          cmp   ecx,ebx
  3183.          jb    ricino
  3184.  
  3185.          mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
  3186.          cmp   ecx,eax
  3187.          jb    ricino
  3188.  
  3189.          mov   eax,[edi+0]
  3190.          mov   ebx,[edi+4]
  3191.          mov   ecx,[edi+8]
  3192.          mov   edx,[edi+12]
  3193.          add   ecx,eax
  3194.          add   edx,ebx
  3195.  
  3196.          mov   eax,[dly]    ; eax = area y start     edx = window y end
  3197.          cmp   edx,eax
  3198.          jb    ricino
  3199.  
  3200.          mov   eax,[dlx]    ; eax = area x start     ecx = window x end
  3201.          cmp   ecx,eax
  3202.          jb    ricino
  3203.  
  3204.         bgli:
  3205.  
  3206.          cmp   edi,esi
  3207.          jz    ricino
  3208.  
  3209.          mov   eax,edi
  3210.          add   eax,draw_data-window_data
  3211.  
  3212.          mov   ebx,[dlx]          ; set limits
  3213.          mov   [eax+0],ebx
  3214.          mov   ebx,[dly]
  3215.          mov   [eax+4],ebx
  3216.          mov   ebx,[dlxe]
  3217.          mov   [eax+8],ebx
  3218.          mov   ebx,[dlye]
  3219.          mov   [eax+12],ebx
  3220.  
  3221.          sub   eax,draw_data-window_data
  3222.  
  3223.          cmp   ecx,1
  3224.          jne   nobgrd
  3225.          cmp   esi,1
  3226.          je    newdw8
  3227.          call  drawbackground
  3228.  
  3229.        newdw8:
  3230.        nobgrd:
  3231.  
  3232.          mov   [eax+31],byte 1    ; mark as redraw
  3233.  
  3234.        ricino:
  3235.  
  3236.        not_this_task:
  3237.  
  3238.          pop   ecx
  3239.  
  3240.          cmp   ecx,[0x3004]
  3241.          jle   newdw2
  3242.  
  3243.          pop  eax
  3244.          popad
  3245.  
  3246.          ret
  3247.  
  3248. ;   check mouse
  3249. ;
  3250. ;
  3251. ;   FB00  ->   FB0F   mouse memory 00 chunk count - FB0A-B x - FB0C-D y
  3252. ;   FB10  ->   FB17   mouse color mem
  3253. ;   FB21              x move
  3254. ;   FB22              y move
  3255. ;   FB30              color temp
  3256. ;   FB28              high bits temp
  3257. ;   FB4A  ->   FB4D   FB4A-B x-under - FB4C-D y-under
  3258. ;   FC00  ->   FCFE   com1/ps2 buffer
  3259. ;   FCFF              com1/ps2 buffer count starting from FC00
  3260.  
  3261. uglobal
  3262.   mousecount  dd  0x0
  3263.   mousedata   dd  0x0
  3264. endg
  3265.  
  3266.  
  3267. check_mouse_data:
  3268.  
  3269.         pushad
  3270.  
  3271.         cmp    [0xF604],byte 1
  3272.         jne    no_ps2_mouse
  3273.         mov    [mousecount],dword 0x2e0000+12*4096
  3274.         mov    [mousedata],dword 0x2e0000+12*4096+0x10
  3275.         jmp    uusicheckmouse
  3276. no_ps2_mouse:        
  3277.         cmp    [0xF604],byte 2
  3278.         jne    no_com1_mouse
  3279.         mov    [mousecount],dword 0x2e0000+4*4096
  3280.         mov    [mousedata],dword 0x2e0000+4*4096+0x10
  3281.         jmp    uusicheckmouse
  3282. no_com1_mouse:
  3283.         mov    [mousecount],dword 0x2e0000+3*4096
  3284.         mov    [mousedata],dword 0x2e0000+3*4096+0x10
  3285.  
  3286.       uusicheckmouse:
  3287.  
  3288.         mov    ebx,[mousecount]       ; anything at buffer for mouse
  3289.         cmp    dword [ebx], 0         ; !!!
  3290.         jz     checkmouseret
  3291.  
  3292.         ; first byte of comX or ps2 ?
  3293.  
  3294.         cmp    [0xF604],byte 1
  3295.         je     ps2mousefirst
  3296.  
  3297.         ; ******************************************        
  3298.         ; *********** COMX mouse driver ************
  3299.         ; ******************************************
  3300.  
  3301.        com1mousefirst:
  3302.  
  3303.         mov    edi,[mousedata]
  3304.         mov    dl,byte [edi] ; first com1 ?
  3305.         test   dl,64
  3306.         jz     @f
  3307.         mov    [0xfb00],byte 0  ; zero mouse block count
  3308.        @@:
  3309.         xor    ebx,ebx
  3310.  
  3311.         mov    bl,[0xfb00]
  3312.         inc    bl
  3313.         mov    [0xfb00],bl
  3314.         mov    eax,0xfb00
  3315.         add    eax,ebx
  3316.         mov    edi,[mousedata]
  3317.         mov    dl,byte [edi]
  3318.         mov    [eax],byte dl
  3319.         cmp    bl,3             ; three ?
  3320.         jnz    decm
  3321.  
  3322.         ; buttons
  3323.  
  3324. ;* change right and left button by places - start code - Mario79
  3325.         mov al,[0xfb01]
  3326.         mov ah,al
  3327.         shr al,3
  3328.         and al,2
  3329.         shr ah,5
  3330.         and ah,1
  3331.         add al,ah
  3332. ;* change right and left button by places - end code - Mario79
  3333.  
  3334.         mov    [0xfb40],al
  3335.  
  3336.         ; com1 mouse
  3337.         ; x
  3338.  
  3339.         mov    dl,[0xfb01]        ; x high bits
  3340.         movzx  eax,dl
  3341.         and    al,3
  3342.         shl    al,6
  3343.         mov    dl,byte[0xfb02]    ; x low bits
  3344.         add    al,dl
  3345.         mov    [0xfb21],byte al
  3346.         movzx  ebx,word[0xfb0a]
  3347.  
  3348.         mov    al,byte [0xfb01]   ; + or - ?
  3349.         test   al,2
  3350.         jz     x_add
  3351.  
  3352.        x_sub:                      ; x-
  3353.         sub    bx,255
  3354.         sub    bx,255
  3355.        x_add:                      ; x+
  3356.         movzx  eax,byte [0xfb21]
  3357.         add    bx,ax
  3358.         add    bx,ax
  3359.         push   ebx
  3360.         mov    [0xfb00],byte 0
  3361.  
  3362.         ; y
  3363.  
  3364.  
  3365.       my_event:
  3366.  
  3367.         mov    dl,[0xfb01]       ; y high bits
  3368.         movzx  eax,dl
  3369.         and    al,12
  3370.         shl    al,4
  3371.         mov    dl,byte[0xfb03]   ; y low bits
  3372.         add    al,dl
  3373.         mov    [0xfb22],byte al
  3374.         movzx  ebx,word[0xfb0c]
  3375.  
  3376.         mov    al,byte [0xfb01]  ; + or - ?
  3377.         test   al,8
  3378.         je     y_add
  3379.  
  3380.       y_sub:                      ; y-
  3381.         sub    bx,255
  3382.         sub    bx,255
  3383.       y_add:                      ; y+
  3384.         movzx  eax,byte [0xfb22]
  3385.         add    bx,ax
  3386.         add    bx,ax
  3387.         push   ebx
  3388.         mov    [0xfb00],byte 0
  3389.         jmp    mdraw
  3390.  
  3391.         ; end of com1 mouse
  3392.  
  3393.  
  3394.         ; ******************************************
  3395.         ; ********  PS2 MOUSE DRIVER  **************
  3396.         ; ******************************************
  3397.  
  3398.       ps2mousefirst:
  3399.      
  3400.         movzx  edx,byte [0x2E0000+4096*12+0x10]   ; first ps2 ?
  3401.         cmp    edx,40
  3402.         jne    @f
  3403.         mov    [0xfb00],byte 0  ; zero mouse block count
  3404.       @@:
  3405.  
  3406.         movzx  ebx,byte [0xfb00]
  3407.         add    ebx,1
  3408.         mov    [0xfb00],bl
  3409.         mov    eax,0xfb00
  3410.         add    eax,ebx
  3411.         mov    dl,byte [0x2E0000+4096*12+0x10]
  3412.         mov    [eax],byte dl
  3413.  
  3414.         cmp    bl,3             ; full packet of three bytes ?
  3415.         jnz    decm
  3416.  
  3417.         mov    [0xfb00],byte 0  ; zero mouse block count
  3418.  
  3419.         ; buttons
  3420.  
  3421.         movzx  eax,byte [0xfb01]
  3422.         and    eax,3
  3423.         mov    [0xfb40],al
  3424.  
  3425.         ; x
  3426.  
  3427.         movzx  eax,word [0xfb0a]
  3428.         movzx  edx,byte [0xfb02]
  3429.         cmp    edx,128
  3430.         jb     ps2xp
  3431.         shl    edx,1
  3432.         add    eax,edx
  3433.         cmp    eax,512
  3434.         jge    ps2xsok
  3435.         xor    eax, eax
  3436.         jmp    ps2xready
  3437.        ps2xsok:
  3438.         sub    eax,512
  3439.         jmp    ps2xready
  3440.        ps2xp:
  3441.         shl    edx,1
  3442.         add    eax,edx
  3443.         jmp    ps2xready
  3444.        ps2xready:
  3445.         push   eax
  3446.  
  3447.         ; y
  3448.  
  3449.         movzx  eax,word [0xfb0c]
  3450.         movzx  edx,byte [0xfb03]
  3451.         cmp    edx,128
  3452.         jb     ps2yp
  3453.         add    eax,512
  3454.         shl    edx,1
  3455.         sub    eax,edx
  3456.         jmp    ps2yready
  3457.        ps2yp:
  3458.         shl    edx,1
  3459.         cmp    edx,eax
  3460.         jb     ps201
  3461.         mov    edx,eax
  3462.        ps201:
  3463.         sub    eax,edx
  3464.         jmp    ps2yready
  3465.        ps2yready:
  3466.         push   eax
  3467.  
  3468.         ;jmp    mdraw
  3469.  
  3470.         ; end of ps2 mouse
  3471.  
  3472.  
  3473.         ; ****************************
  3474.         ; ***** CHECK FOR LIMITS *****
  3475.         ; ****************************
  3476.  
  3477.       mdraw:
  3478.  
  3479.         cmp    [0xfb44],byte 0
  3480.         jne    mousedraw4
  3481.         cmp    [0xfb40],byte 0
  3482.         je     mousedraw4
  3483.         mov    [0xfff5],byte 1
  3484.  
  3485.       mousedraw4:
  3486.  
  3487.         pop    ebx
  3488.         pop    eax
  3489.  
  3490.         mov    [mouse_active],1
  3491.  
  3492. ;        mov    dx,0                   ; smaller than zero
  3493.         xor    dx,dx
  3494.         cmp    bx,dx
  3495.         jge    mnb11
  3496. ;        mov    bx,0
  3497.         xor    bx,bx
  3498.       mnb11:
  3499.         mov    [0xfb0c],word bx
  3500.  
  3501. ;        mov    dx,0
  3502.         xor    dx,dx
  3503.         cmp    ax,dx
  3504.         jge    mnb22
  3505. ;        mov    ax,0
  3506.         xor    ax,ax
  3507.       mnb22:
  3508.         mov    [0xfb0a],word ax
  3509.  
  3510.         mov    edx,[0xfe04]           ; bigger than maximum
  3511.         cmp    ebx,edx
  3512.         jb     mnb1
  3513.         mov    bx,[0xfe04]
  3514.       mnb1:
  3515.         mov    [0xfb0c],word bx
  3516.  
  3517.         mov    edx,[0xfe00]
  3518.         cmp    eax,edx
  3519.         jb     mnb2
  3520.         mov    ax,[0xfe00]
  3521.       mnb2:
  3522.         mov    [0xfb0a],word ax
  3523.  
  3524.  
  3525.         ; ****   NEXT DATA BYTE FROM MOUSE BUFFER   ****
  3526.  
  3527.       decm:
  3528.  
  3529.         mov    edi,[mousecount]         ; decrease counter
  3530.         dec    dword [edi]
  3531.  
  3532.         mov    esi,[mousedata]
  3533.         mov    edi,esi
  3534.         inc    esi
  3535. ;        mov    ecx,250
  3536.         mov    ecx,[mousecount]
  3537.         mov    ecx,[ecx]
  3538.         cld
  3539.         rep    movsb
  3540.  
  3541.         jmp    uusicheckmouse
  3542.  
  3543.       checkmouseret:
  3544.  
  3545.         cmp    [0xfb44],byte 0
  3546.         jne    cmret
  3547.        
  3548.         cmp    [0xfb40],byte 0
  3549.         je     cmret
  3550.        
  3551.         mov    [0xfff4],byte 0
  3552.         mov    [0xfff5],byte 0
  3553.        
  3554.       cmret:
  3555.  
  3556.         popad
  3557.  
  3558.         ret
  3559.  
  3560.  
  3561. draw_mouse_under:
  3562.  
  3563.         ; return old picture
  3564. ;        cli
  3565.  
  3566.         pushad
  3567.  
  3568.         xor    ecx,ecx
  3569.         xor    edx,edx
  3570.  
  3571.         ;cli    ; !!!****
  3572.         align  4
  3573.       mres:
  3574.  
  3575.         movzx  eax,word [0xfb4a]
  3576.         movzx  ebx,word [0xfb4c]
  3577.  
  3578.         add    eax,ecx
  3579.         add    ebx,edx
  3580.  
  3581.         push   ecx
  3582.         push   edx
  3583.         push   eax
  3584.         push   ebx
  3585.  
  3586.         mov    eax,edx
  3587.         shl    eax,6
  3588.         shl    ecx,2
  3589.         add    eax,ecx
  3590.         add    eax,mouseunder
  3591.         mov    ecx,[eax]
  3592.  
  3593.         pop    ebx
  3594.         pop    eax
  3595.  
  3596.         ;;;push   edi
  3597.         mov    edi,1 ;force
  3598.         call   [putpixel]
  3599.         ;;;pop    edi
  3600.  
  3601.         pop    edx
  3602.         pop    ecx
  3603.  
  3604.         inc    ecx
  3605.         cmp    ecx, 16
  3606.         jnz    mres
  3607.         xor    ecx, ecx
  3608.         inc    edx
  3609.         cmp    edx, 24
  3610.         jnz    mres
  3611.         ;sti    ; !!!****
  3612.  
  3613.         popad
  3614.        
  3615. ;        sti
  3616.        
  3617.         ret
  3618.  
  3619.  
  3620. save_draw_mouse:
  3621.  
  3622.         ; save & draw
  3623. ;        cli
  3624.  
  3625.         mov    [0xfb4a],ax
  3626.         mov    [0xfb4c],bx
  3627.         push   eax
  3628.         push   ebx
  3629.         mov    ecx,0
  3630.         mov    edx,0
  3631.  
  3632.         ;cli ; !!!****
  3633.  
  3634.       drm:
  3635.  
  3636.         push   eax
  3637.         push   ebx
  3638.         push   ecx
  3639.         push   edx
  3640.  
  3641.         ; helloworld
  3642.         push   eax ebx ecx
  3643.         add    eax,ecx  ; save picture under mouse
  3644.         add    ebx,edx
  3645.         push   ecx
  3646.         call   getpixel
  3647.         mov    [0xfb30],ecx
  3648.         pop    ecx
  3649.         mov    eax,edx
  3650.         shl    eax,6
  3651.         shl    ecx,2
  3652.         add    eax,ecx
  3653.         add    eax,mouseunder
  3654.         mov    ebx,[0xfb30]
  3655.         mov    [eax],ebx
  3656.         pop    ecx ebx eax
  3657.  
  3658.         mov    edi,edx       ; y cycle
  3659.         shl    edi,4       ; *16 bytes per row
  3660.         add    edi,ecx       ; x cycle
  3661.         mov    esi, edi
  3662.         add    edi, esi
  3663.         add    edi, esi       ; *3
  3664.         add    edi,[0xf200]      ; we have our str address
  3665.         mov    esi, edi
  3666.         add    esi, 16*24*3
  3667.         push   ecx
  3668.         mov    ecx, [0xfb30]
  3669.         call   combine_colors
  3670.         mov    [0xfb10], ecx
  3671.         pop    ecx
  3672.  
  3673.  
  3674.         pop    edx
  3675.         pop    ecx
  3676.         pop    ebx
  3677.         pop    eax
  3678.  
  3679.         add    eax,ecx       ; we have x coord+cycle
  3680.         add    ebx,edx       ; and y coord+cycle
  3681.  
  3682.         push   ecx edi
  3683.         mov    ecx, [0xfb10]
  3684.         mov    edi, 1
  3685.         call   [putpixel]
  3686.         pop    edi ecx
  3687.  
  3688.       mnext:
  3689.  
  3690.         mov    ebx,[esp+0]      ; pure y coord again
  3691.         mov    eax,[esp+4]      ; and x
  3692.  
  3693.         inc    ecx          ; +1 cycle
  3694.         cmp    ecx,16       ; if more than 16
  3695.         jnz    drm
  3696.         xor    ecx, ecx
  3697.         inc    edx
  3698.         cmp    edx,24
  3699.         jnz    drm
  3700.  
  3701.         pop    ebx
  3702.         pop    eax
  3703.  
  3704. ;        sti ; !!!****
  3705.  
  3706.         ret
  3707.  
  3708.  
  3709. combine_colors:
  3710.  
  3711.       ; in
  3712.       ; ecx - color ( 00 RR GG BB )
  3713.       ; edi - ref to new color byte
  3714.       ; esi - ref to alpha byte
  3715.       ;
  3716.       ; out
  3717.       ; ecx - new color ( roughly (ecx*[esi]>>8)+([edi]*[esi]>>8) )
  3718.  
  3719.       push eax
  3720.       push ebx
  3721.       push edx
  3722.       push ecx
  3723.       xor ecx, ecx
  3724.          ; byte 2
  3725.       mov eax, 0xff
  3726.       sub al, [esi+0]
  3727.       mov ebx, [esp]
  3728.       shr ebx, 16
  3729.       and ebx, 0xff
  3730.       mul ebx
  3731.       shr eax, 8
  3732.       add ecx, eax
  3733. ;      xor eax, eax
  3734. ;      xor ebx, ebx
  3735. ;      mov al, [edi+0]
  3736. ;      mov bl, [esi+0]
  3737.     movzx eax, byte [edi+0]
  3738.     movzx ebx, byte [esi+0]
  3739.       mul ebx
  3740.       shr eax, 8
  3741.       add ecx, eax
  3742.       shl ecx, 8
  3743.          ; byte 1
  3744.       mov eax, 0xff
  3745.       sub al, [esi+1]
  3746.       mov ebx, [esp]
  3747.       shr ebx, 8
  3748.       and ebx, 0xff
  3749.       mul ebx
  3750.       shr eax, 8
  3751.       add ecx, eax
  3752. ;      xor eax, eax
  3753. ;      xor ebx, ebx
  3754. ;      mov al, [edi+1]
  3755. ;      mov bl, [esi+1]
  3756.     movzx eax, byte [edi+1]
  3757.     movzx ebx, byte [esi+1]
  3758.       mul ebx
  3759.       shr eax, 8
  3760.       add ecx, eax
  3761.       shl ecx, 8
  3762.          ; byte 2
  3763.       mov eax, 0xff
  3764.       sub al, [esi+2]
  3765.       mov ebx, [esp]
  3766.       and ebx, 0xff
  3767.       mul ebx
  3768.       shr eax, 8
  3769.       add ecx, eax
  3770. ;      xor eax, eax
  3771. ;      xor ebx, ebx
  3772. ;      mov al, [edi+2]
  3773. ;      mov bl, [esi+2]
  3774.     movzx eax, byte [edi+2]
  3775.     movzx ebx, byte [esi+2]
  3776.       mul ebx
  3777.       shr eax, 8
  3778.       add ecx, eax
  3779.  
  3780.       pop eax
  3781.       pop edx
  3782.       pop ebx
  3783.       pop eax
  3784.       ret
  3785.  
  3786.  
  3787. __sys_disable_mouse:
  3788.  
  3789.       pushad
  3790.  
  3791.       cmp  [0x3000],dword 1
  3792.       je   disable_m
  3793.  
  3794.       mov  edx,[0x3000]
  3795.       shl  edx,5
  3796.       add  edx,window_data
  3797.  
  3798.       movzx  eax, word [0xfb0a]
  3799.       movzx  ebx, word [0xfb0c]
  3800.  
  3801.       mov  ecx,[0xfe00]
  3802.       inc  ecx
  3803.       imul  ecx,ebx
  3804.       add  ecx,eax
  3805.       add  ecx, display_data
  3806.  
  3807.       movzx eax, byte [edx+twdw+0xe]
  3808.  
  3809.       movzx ebx, byte [ecx]
  3810.       cmp   eax,ebx
  3811.       je    yes_mouse_disable
  3812.       movzx ebx, byte [ecx+16]
  3813.       cmp   eax,ebx
  3814.       je    yes_mouse_disable
  3815.  
  3816.       mov   ebx,[0xfe00]
  3817.       inc   ebx
  3818.       imul  ebx,10
  3819.       add   ecx,ebx
  3820.  
  3821.       movzx ebx, byte [ecx]
  3822.       cmp   eax,ebx
  3823.       je    yes_mouse_disable
  3824.  
  3825.       mov   ebx,[0xfe00]
  3826.       inc   ebx
  3827.       imul  ebx,10
  3828.       add   ecx,ebx
  3829.  
  3830.       movzx ebx, byte [ecx]
  3831.       cmp   eax,ebx
  3832.       je    yes_mouse_disable
  3833.       movzx ebx, byte [ecx+16]
  3834.       cmp   eax,ebx
  3835.       je    yes_mouse_disable
  3836.  
  3837.       jmp   no_mouse_disable
  3838.  
  3839.     yes_mouse_disable:
  3840.  
  3841.       mov  edx,[0x3000]
  3842.       shl  edx,5
  3843.       add  edx,window_data
  3844.  
  3845.       movzx  eax, word [0xfb0a]
  3846.       movzx  ebx, word [0xfb0c]
  3847.  
  3848.       mov  ecx,[edx+0]   ; mouse inside the area ?
  3849.       add  eax,14
  3850.       cmp  eax,ecx
  3851.       jb   no_mouse_disable
  3852.       sub  eax,14
  3853.  
  3854.       add  ecx,[edx+8]
  3855.       cmp  eax,ecx
  3856.       jg   no_mouse_disable
  3857.  
  3858.       mov  ecx,[edx+4]
  3859.       add  ebx,20
  3860.       cmp  ebx,ecx
  3861.       jb   no_mouse_disable
  3862.       sub  ebx,20
  3863.  
  3864.       add  ecx,[edx+12]
  3865.       cmp  ebx,ecx
  3866.       jg   no_mouse_disable
  3867.  
  3868.     disable_m:
  3869.  
  3870.       cmp  dword [0xf204],dword 0
  3871.       jne  @f
  3872.       call draw_mouse_under
  3873.     @@:
  3874.  
  3875.       mov  [0xf204],dword 1
  3876.  
  3877.     no_mouse_disable:
  3878.  
  3879.       popad
  3880.  
  3881.       ret
  3882.  
  3883.  
  3884.  
  3885. __sys_draw_pointer:
  3886.         cli
  3887.  
  3888.         pushad
  3889.  
  3890.         cmp    dword [0xf204],dword 0  ; mouse visible ?
  3891.         je     chms00
  3892.  
  3893.         dec    dword [0xf204]
  3894.  
  3895.         cmp    [0xf204],dword 0
  3896.         jnz    nodmu2
  3897.  
  3898.         movzx  ebx,word [0xfb0c]
  3899.         movzx  eax,word [0xfb0a]
  3900.         call   save_draw_mouse
  3901.  
  3902.         popad
  3903.         sti
  3904.         ret
  3905.  
  3906.       nodmu2:
  3907.  
  3908.         popad
  3909.         sti
  3910.         ret
  3911.  
  3912.       chms00:
  3913.  
  3914. ;        popad
  3915.  
  3916. ;        pushad
  3917.  
  3918. ;        cmp   [0xf204],dword 0
  3919. ;        jne   nodmp
  3920.  
  3921.         movzx  ecx,word [0xfb4a]
  3922.         movzx  edx,word [0xfb4c]
  3923.  
  3924.         movzx  ebx,word [0xfb0c]
  3925.         movzx  eax,word [0xfb0a]
  3926.  
  3927.         cmp    eax,ecx
  3928.         jne    redrawmouse
  3929.  
  3930.         cmp    ebx,edx
  3931.         jne    redrawmouse
  3932.  
  3933.         jmp    nodmp
  3934.  
  3935.       redrawmouse:
  3936.  
  3937.        
  3938.         call   draw_mouse_under
  3939. redrawmouse_1:
  3940.         call   save_draw_mouse
  3941.  
  3942.      nodmp:
  3943.  
  3944.         popad
  3945.         sti
  3946.         ret
  3947.  
  3948.  
  3949.  
  3950. calculatebackground:   ; background
  3951.  
  3952.         ; all black
  3953.  
  3954.         mov   [display_data-8],dword 4      ; size x
  3955.         mov   [display_data-4],dword 2      ; size y
  3956.  
  3957.         mov   edi, 0x300000                 ; set background to black
  3958.         xor   eax, eax
  3959.         mov   ecx, 0x0fff00 / 4
  3960.         cld
  3961.         rep   stosd
  3962.  
  3963.         mov   edi,display_data              ; set os to use all pixels
  3964.         mov   eax,0x01010101
  3965.         mov   ecx,0x1fff00 / 4
  3966.         rep   stosd
  3967.  
  3968.         mov   byte [0xFFF0], 0              ; do not draw background!
  3969.  
  3970.         ret
  3971.  
  3972. uglobal
  3973.   imax    dd 0x0
  3974. endg
  3975.  
  3976.  
  3977.  
  3978. delay_ms:     ; delay in 1/1000 sec
  3979.  
  3980.  
  3981.         push  eax
  3982.         push  ecx
  3983.  
  3984.         mov   ecx,esi
  3985.         ; <CPU clock fix by Sergey Kuzmin aka Wildwest>
  3986.         imul  ecx, 33941
  3987.         shr   ecx, 9
  3988.         ; </CPU clock fix>
  3989.  
  3990.         in    al,0x61
  3991.         and   al,0x10
  3992.         mov   ah,al
  3993.         cld
  3994.  
  3995.  cnt1:  in    al,0x61
  3996.         and   al,0x10
  3997.         cmp   al,ah
  3998.         jz    cnt1
  3999.  
  4000.         mov   ah,al
  4001.         loop  cnt1
  4002.  
  4003.         pop   ecx
  4004.         pop   eax
  4005.  
  4006.         ret
  4007.  
  4008.  
  4009. set_app_param:
  4010.         push edi
  4011.  
  4012.         mov  edi,[0x3010]
  4013.         mov  [edi],eax
  4014.  
  4015.         pop  edi
  4016.         ret
  4017.  
  4018.  
  4019.  
  4020. delay_hs:     ; delay in 1/100 secs
  4021.         push  eax
  4022.         push  ecx
  4023.         push  edx
  4024.  
  4025.         mov   edx,[timer_ticks];[0xfdf0]
  4026.         add   edx,eax
  4027.  
  4028.       newtic:
  4029.         mov   ecx,[timer_ticks];[0xfdf0]
  4030.         cmp   edx,ecx
  4031.         jbe   zerodelay
  4032.  
  4033.         call  change_task
  4034.  
  4035.         jmp   newtic
  4036.  
  4037.       zerodelay:
  4038.         pop   edx
  4039.         pop   ecx
  4040.         pop   eax
  4041.  
  4042.         ret
  4043.  
  4044.  
  4045. memmove:       ; memory move in bytes
  4046.  
  4047. ; eax = from
  4048. ; ebx = to
  4049. ; ecx = no of bytes
  4050.     test ecx, ecx
  4051.     jle  .ret
  4052.  
  4053.  
  4054.     push esi edi ecx
  4055.  
  4056.     mov  edi, ebx
  4057.     mov  esi, eax
  4058.  
  4059.     test ecx, not 11b
  4060.     jz   @f
  4061.  
  4062.     push ecx
  4063.     shr  ecx, 2
  4064.     rep  movsd
  4065.     pop  ecx
  4066.     and  ecx, 11b
  4067.     jz   .finish
  4068.   @@:
  4069.     rep  movsb
  4070.  
  4071.   .finish:
  4072.     pop  ecx edi esi
  4073.   .ret:
  4074.     ret
  4075.  
  4076.  
  4077. align 4
  4078.  
  4079. read_floppy_file:
  4080.  
  4081. ; as input
  4082. ;
  4083. ; eax pointer to file
  4084. ; ebx file lenght
  4085. ; ecx start 512 byte block number
  4086. ; edx number of blocks to read
  4087. ; esi pointer to return/work area (atleast 20 000 bytes)
  4088. ;
  4089. ;
  4090. ; on return
  4091. ;
  4092. ; eax = 0 command succesful
  4093. ;       1 no fd base and/or partition defined
  4094. ;       2 yet unsupported FS
  4095. ;       3 unknown FS
  4096. ;       4 partition not defined at hd
  4097. ;       5 file not found
  4098. ; ebx = size of file
  4099.  
  4100.      mov   edi,[0x3010]
  4101.      add   edi,0x10
  4102.      add   esi,[edi]
  4103.      add   eax,[edi]
  4104.  
  4105.      pushad
  4106.      mov  edi,esi
  4107.      add  edi,1024
  4108.      mov  esi,0x100000+19*512
  4109.      sub  ecx,1
  4110.      shl  ecx,9
  4111.      add  esi,ecx
  4112.      shl  edx,9
  4113.      mov  ecx,edx
  4114.      cld
  4115.      rep  movsb
  4116.      popad
  4117.  
  4118.      mov   [esp+36],eax
  4119.      mov   [esp+24],ebx
  4120.      ret
  4121.  
  4122.  
  4123.  
  4124. align 4
  4125.  
  4126. sys_programirq:
  4127.  
  4128.     mov   edi,[0x3010]
  4129.     add   edi,0x10
  4130.     add   eax,[edi]
  4131.  
  4132.     mov   edx,ebx
  4133.     shl   edx,2
  4134.     add   edx,irq_owner
  4135.     mov   edx,[edx]
  4136.     mov   edi,[0x3010]
  4137.     mov   edi,[edi+0x4]
  4138.     cmp   edx,edi
  4139.     je    spril1
  4140.     mov   [esp+36],dword 1
  4141.     ret
  4142.   spril1:
  4143.  
  4144.     mov   esi,eax
  4145.     shl   ebx,6
  4146.     add   ebx,irq00read
  4147.     mov   edi,ebx
  4148.     mov   ecx,16
  4149.     cld
  4150.     rep   movsd
  4151.     mov   [esp+36],dword 0
  4152.     ret
  4153.  
  4154.  
  4155. align 4
  4156.  
  4157. get_irq_data:
  4158.  
  4159.      mov   edx,eax           ; check for correct owner
  4160.      shl   edx,2
  4161.      add   edx,irq_owner
  4162.      mov   edx,[edx]
  4163.      mov   edi,[0x3010]
  4164.      mov   edi,[edi+0x4]
  4165.      cmp   edx,edi
  4166.      je    gidril1
  4167.      mov   [esp+36],eax
  4168.      mov   [esp+32],dword 2
  4169.      mov   [esp+24],ebx
  4170.      ret
  4171.  
  4172.   gidril1:
  4173.  
  4174.      mov   ebx,eax
  4175.      shl   ebx,12
  4176.      add   ebx,0x2e0000
  4177.      mov   eax,[ebx]
  4178.      mov   ecx,1
  4179.      test  eax,eax
  4180.      jz    gid1
  4181.  
  4182.      dec   eax
  4183.      mov   esi,ebx
  4184.      mov   [ebx],eax
  4185.      movzx ebx,byte [ebx+0x10]
  4186.      add   esi,0x10
  4187.      mov   edi,esi
  4188.      inc   esi
  4189.      mov   ecx,4000 / 4
  4190.      cld
  4191.      rep   movsd
  4192.      xor   ecx,ecx
  4193.    gid1:
  4194.      mov   [esp+36],eax
  4195.      mov   [esp+32],ecx
  4196.      mov   [esp+24],ebx
  4197.      ret
  4198.  
  4199.  
  4200. set_io_access_rights:
  4201.  
  4202.      pushad
  4203.  
  4204.      mov   edi,[0x3000]
  4205.      imul  edi,tss_step
  4206.      add   edi,tss_data+128
  4207. ;     add   edi,128
  4208.  
  4209.      mov   ecx,eax
  4210.      and   ecx,7    ; offset in byte
  4211.  
  4212.      shr   eax,3    ; number of byte
  4213.      add   edi,eax
  4214.  
  4215.      mov   ebx,1
  4216.      shl   ebx,cl
  4217.  
  4218.      cmp   ebp,0                ; enable access - ebp = 0
  4219.      jne   siar1
  4220.  
  4221.      not   ebx
  4222.      and   [edi],byte bl
  4223.  
  4224.      popad
  4225.  
  4226.      ret
  4227.  
  4228.    siar1:
  4229.  
  4230.      or    [edi],byte bl        ; disable access - ebp = 1
  4231.  
  4232.      popad
  4233.  
  4234.      ret
  4235.  
  4236.  
  4237.  
  4238.  
  4239.  
  4240. r_f_port_area:
  4241.  
  4242.      test  eax, eax
  4243.      jnz   free_port_area
  4244. ;     je    r_port_area
  4245. ;     jmp   free_port_area
  4246.  
  4247. ;   r_port_area:
  4248.  
  4249.      pushad
  4250.  
  4251.      cmp   ebx,ecx            ; beginning > end ?
  4252.      jg    rpal1
  4253.      mov   esi,[0x2d0000]
  4254.      cmp   esi,0              ; no reserved areas ?
  4255.      je    rpal2
  4256.      cmp   esi,255            ; max reserved
  4257.      jge   rpal1
  4258.    rpal3:
  4259.      mov   edi,esi
  4260.      shl   edi,4
  4261.      add   edi,0x2d0000
  4262.      cmp   ebx,[edi+8]
  4263.      jg    rpal4
  4264.      cmp   ecx,[edi+4]
  4265.      jae   rpal1
  4266. ;     jb    rpal4
  4267. ;     jmp   rpal1
  4268.    rpal4:
  4269.  
  4270.      dec   esi
  4271.      jnz   rpal3
  4272.      jmp   rpal2
  4273.    rpal1:
  4274.      popad
  4275.      mov   eax,1
  4276.      ret
  4277.  
  4278.    rpal2:
  4279.      popad
  4280.  
  4281.  
  4282.      ; enable port access at port IO map
  4283.      cli
  4284.      pushad                        ; start enable io map
  4285.  
  4286.      cmp   ecx,65536 ;16384
  4287.      jae   no_unmask_io ; jge
  4288.  
  4289.      mov   eax,ebx
  4290.  
  4291.    new_port_access:
  4292.  
  4293.      pushad
  4294.  
  4295.      mov   ebp,0                  ; enable - eax = port
  4296.      call  set_io_access_rights
  4297.  
  4298.      popad
  4299.  
  4300.      inc   eax
  4301.      cmp   eax,ecx
  4302.      jbe   new_port_access
  4303.  
  4304.    no_unmask_io:
  4305.  
  4306.      popad                         ; end enable io map
  4307.      sti
  4308.  
  4309.      mov   edi,[0x2d0000]
  4310.      add   edi,1
  4311.      mov   [0x2d0000],edi
  4312.      shl   edi,4
  4313.      add   edi,0x2d0000
  4314.      mov   esi,[0x3010]
  4315.      mov   esi,[esi+0x4]
  4316.      mov   [edi],esi
  4317.      mov   [edi+4],ebx
  4318.      mov   [edi+8],ecx
  4319.  
  4320.      xor   eax, eax
  4321.      ret
  4322.  
  4323.  
  4324.  
  4325.  
  4326. free_port_area:
  4327.  
  4328.      pushad
  4329.  
  4330.      mov   esi,[0x2d0000]     ; no reserved areas ?
  4331.      cmp   esi,0
  4332.      je    frpal2
  4333.      mov   edx,[0x3010]
  4334.      mov   edx,[edx+4]
  4335.    frpal3:
  4336.      mov   edi,esi
  4337.      shl   edi,4
  4338.      add   edi,0x2d0000
  4339.      cmp   edx,[edi]
  4340.      jne   frpal4
  4341.      cmp   ebx,[edi+4]
  4342.      jne   frpal4
  4343.      cmp   ecx,[edi+8]
  4344.      jne   frpal4
  4345.      jmp   frpal1
  4346.    frpal4:
  4347.      dec   esi
  4348.      jnz   frpal3
  4349.    frpal2:
  4350.      popad
  4351.      mov   eax,1
  4352.      ret
  4353.    frpal1:
  4354.      mov   ecx,256
  4355.      sub   ecx,esi
  4356.      shl   ecx,4
  4357.      mov   esi,edi
  4358.      add   esi,16
  4359.      cld
  4360.      rep   movsb
  4361.  
  4362.      dec   dword [0x2d0000]
  4363.  
  4364.      popad
  4365.  
  4366.  
  4367.      ; disable port access at port IO map
  4368.  
  4369.      pushad                        ; start disable io map
  4370.  
  4371.      cmp   ecx,65536 ;16384
  4372.      jge   no_mask_io
  4373.  
  4374.      mov   eax,ebx
  4375.  
  4376.    new_port_access_disable:
  4377.  
  4378.      pushad
  4379.  
  4380.      mov   ebp,1                  ; disable - eax = port
  4381.      call  set_io_access_rights
  4382.  
  4383.      popad
  4384.  
  4385.      inc   eax
  4386.      cmp   eax,ecx
  4387.      jbe   new_port_access_disable
  4388.  
  4389.    no_mask_io:
  4390.  
  4391.      popad                         ; end disable io map
  4392.  
  4393.      xor   eax, eax
  4394.      ret
  4395.  
  4396.  
  4397. reserve_free_irq:
  4398.  
  4399.      cmp   eax,0
  4400.      jz    reserve_irq
  4401.  
  4402.      mov   edi,ebx
  4403.      shl   edi,2
  4404.      add   edi,irq_owner
  4405.      mov   edx,[edi]
  4406.      mov   eax,[0x3010]
  4407.      mov   eax,[eax+0x4]
  4408.      mov   ecx,1
  4409.      cmp   edx,eax
  4410.      jne   fril1
  4411.      mov   [edi],dword 0
  4412.      mov   ecx,0
  4413.    fril1:
  4414.      mov   [esp+36],ecx ; return in eax
  4415.      ret
  4416.  
  4417.   reserve_irq:
  4418.  
  4419.      mov   edi,ebx
  4420.      shl   edi,2
  4421.      add   edi,irq_owner
  4422.      mov   edx,[edi]
  4423.      mov   ecx,1
  4424.      cmp   edx,0
  4425.      jne   ril1
  4426.  
  4427.      mov   edx,[0x3010]
  4428.      mov   edx,[edx+0x4]
  4429.      mov   [edi],edx
  4430.      mov   ecx,0
  4431.  
  4432.    ril1:
  4433.  
  4434.      mov   [esp+36],ecx ; return in eax
  4435.  
  4436.      ret
  4437.  
  4438.  
  4439.  
  4440. drawbackground:
  4441.  
  4442.        cmp   [0xfe0c],word 0x12
  4443.        jne   dbrv12
  4444.        cmp   [display_data-12],dword 1
  4445.        jne   bgrstr12
  4446.        call  vga_drawbackground_tiled
  4447.        ret
  4448.      bgrstr12:
  4449.        call  vga_drawbackground_stretch
  4450.        ret
  4451.      dbrv12:
  4452.  
  4453.        cmp  [0xfe0c],word 0100000000000000b
  4454.        jge  dbrv20
  4455.        cmp  [0xfe0c],word 0x13
  4456.        je   dbrv20
  4457.        call  vesa12_drawbackground
  4458.        ret
  4459.      dbrv20:
  4460.        cmp   [display_data-12],dword 1
  4461.        jne   bgrstr
  4462.        call  vesa20_drawbackground_tiled
  4463.        ret
  4464.      bgrstr:
  4465.        call  vesa20_drawbackground_stretch
  4466.        ret
  4467.  
  4468.  
  4469. sys_putimage:
  4470.  
  4471.      cmp   [0xfe0c],word 0x12
  4472.      jne   spiv20
  4473.      call  vga_putimage
  4474.      ret
  4475.    spiv20:
  4476.  
  4477.      cmp   [0xfe0c],word 0100000000000000b
  4478.      jge   piv20
  4479.      cmp   [0xfe0c],word 0x13
  4480.      je    piv20
  4481.      call  vesa12_putimage
  4482.      ret
  4483.    piv20:
  4484.      call  vesa20_putimage
  4485.      ret
  4486.  
  4487.  
  4488.  
  4489. ; eax x beginning
  4490. ; ebx y beginning
  4491. ; ecx x end
  4492. ; edx y end
  4493. ; edi color
  4494.  
  4495. __sys_drawbar:
  4496.  
  4497.      cmp   [0xfe0c],word 0x12
  4498.      jne   sdbv20
  4499.      call  vga_drawbar
  4500.      ret
  4501.    sdbv20:
  4502.  
  4503.     cmp  [0xfe0c],word 0100000000000000b
  4504.     jge  dbv20
  4505.     cmp  [0xfe0c],word 0x13
  4506.     je   dbv20
  4507.     call vesa12_drawbar
  4508.     ret
  4509.  
  4510.   dbv20:
  4511.  
  4512.     call vesa20_drawbar
  4513.     ret
  4514.  
  4515.  
  4516.  
  4517. kb_read:
  4518.  
  4519.         push    ecx edx
  4520.  
  4521.         mov     ecx,0xffff
  4522.       kr_loop:
  4523.         in      al,0x64
  4524.         test    al,1
  4525.         jnz     kr_ready
  4526.         loop    kr_loop
  4527.         mov     ah,1
  4528.         jmp     kr_exit
  4529.       kr_ready:
  4530.         push    ecx
  4531.         mov     ecx,32
  4532.       kr_delay:
  4533.         loop    kr_delay
  4534.         pop     ecx
  4535.         in      al,0x60
  4536.         xor     ah,ah
  4537.       kr_exit:
  4538.  
  4539.         pop     edx ecx
  4540.  
  4541.         ret
  4542.  
  4543.  
  4544. kb_write:
  4545.  
  4546.         push    ecx edx
  4547.  
  4548.         mov     dl,al
  4549.         mov     ecx,0xffff
  4550.       kw_loop1:
  4551.         in      al,0x64
  4552.         test    al,0x20
  4553.         jz      kw_ok1
  4554.         loop    kw_loop1
  4555.         mov     ah,1
  4556.         jmp     kw_exit
  4557.       kw_ok1:
  4558.         in      al,0x60
  4559.         mov     ecx,0xffff
  4560.       kw_loop:
  4561.         in      al,0x64
  4562.         test    al,2
  4563.         jz      kw_ok
  4564.         loop    kw_loop
  4565.         mov     ah,1
  4566.         jmp     kw_exit
  4567.       kw_ok:
  4568.         mov     al,dl
  4569.         out     0x60,al
  4570.         mov     ecx,0xffff
  4571.       kw_loop3:
  4572.         in      al,0x64
  4573.         test    al,2
  4574.         jz      kw_ok3
  4575.         loop    kw_loop3
  4576.         mov     ah,1
  4577.         jmp     kw_exit
  4578.       kw_ok3:
  4579.         mov     ah,8
  4580.       kw_loop4:
  4581.         mov     ecx,0xffff
  4582.       kw_loop5:
  4583.         in      al,0x64
  4584.         test    al,1
  4585.         jnz     kw_ok4
  4586.         loop    kw_loop5
  4587.         dec     ah
  4588.         jnz     kw_loop4
  4589.       kw_ok4:
  4590.         xor     ah,ah
  4591.       kw_exit:
  4592.  
  4593.         pop     edx ecx
  4594.  
  4595.         ret
  4596.  
  4597.  
  4598. kb_cmd:
  4599.  
  4600.         mov     ecx,0xffff
  4601.       c_wait:
  4602.         in      al,0x64
  4603.         test    al,2
  4604.         jz      c_send
  4605.         loop    c_wait
  4606.         jmp     c_error
  4607.       c_send:
  4608.         mov     al,bl
  4609.         out     0x64,al
  4610.         mov     ecx,0xffff
  4611.       c_accept:
  4612.         in      al,0x64
  4613.         test    al,2
  4614.         jz      c_ok
  4615.         loop    c_accept
  4616.       c_error:
  4617.         mov     ah,1
  4618.         jmp     c_exit
  4619.       c_ok:
  4620.         xor     ah,ah
  4621.       c_exit:
  4622.         ret
  4623.  
  4624.  
  4625. setmouse:  ; set mousepicture -pointer
  4626.            ; ps2 mouse enable
  4627.  
  4628.      mov     [0xf200],dword mousepointer
  4629.  
  4630.      cli
  4631.      mov     bl,0xa8                 ; enable mouse cmd
  4632.      call    kb_cmd
  4633.      call    kb_read                 ; read status
  4634.  
  4635.      mov     bl,0x20                 ; get command byte
  4636.      call    kb_cmd
  4637.      call    kb_read
  4638.      or      al,3                    ; enable interrupt
  4639.      mov     bl,0x60                 ; write command
  4640.      push    eax
  4641.      call    kb_cmd
  4642.      pop     eax
  4643.      call    kb_write
  4644.  
  4645.      mov     bl,0xd4                 ; for mouse
  4646.      call    kb_cmd
  4647.      mov     al,0xf4                 ; enable mouse device
  4648.      call    kb_write
  4649.      call    kb_read           ; read status return
  4650.  
  4651.      ; com1 mouse enable
  4652.  
  4653.      mov   bx,0x3f8 ; combase
  4654.  
  4655.      mov   dx,bx
  4656.      add   dx,3
  4657.      mov   al,0x80
  4658.      out   dx,al
  4659.  
  4660.      mov   dx,bx
  4661.      add   dx,1
  4662.      mov   al,0
  4663.      out   dx,al
  4664.  
  4665.      mov   dx,bx
  4666.      add   dx,0
  4667.      mov   al,0x30*2    ; 0x30 / 4
  4668.      out   dx,al
  4669.  
  4670.      mov   dx,bx
  4671.      add   dx,3
  4672.      mov   al,2         ; 3
  4673.      out   dx,al
  4674.  
  4675.      mov   dx,bx
  4676.      add   dx,4
  4677.      mov   al,0xb
  4678.      out   dx,al
  4679.  
  4680.      mov   dx,bx
  4681.      add   dx,1
  4682.      mov   al,1
  4683.      out   dx,al
  4684.  
  4685.  
  4686.      ; com2 mouse enable
  4687.  
  4688.      mov   bx,0x2f8 ; combase
  4689.  
  4690.      mov   dx,bx
  4691.      add   dx,3
  4692.      mov   al,0x80
  4693.      out   dx,al
  4694.  
  4695.      mov   dx,bx
  4696.      add   dx,1
  4697.      mov   al,0
  4698.      out   dx,al
  4699.  
  4700.      mov   dx,bx
  4701.      add   dx,0
  4702.      mov   al,0x30*2
  4703.      out   dx,al
  4704.  
  4705.      mov   dx,bx
  4706.      add   dx,3
  4707.      mov   al,2
  4708.      out   dx,al
  4709.  
  4710.      mov   dx,bx
  4711.      add   dx,4
  4712.      mov   al,0xb
  4713.      out   dx,al
  4714.  
  4715.      mov   dx,bx
  4716.      add   dx,1
  4717.      mov   al,1
  4718.      out   dx,al
  4719.  
  4720.      ret
  4721.  
  4722.  
  4723. _rdtsc:
  4724.  
  4725.      mov   edx,[cpuid_1+3*4]
  4726.      test  edx,00010000b
  4727.      jz    ret_rdtsc
  4728.      rdtsc
  4729.      ret
  4730.    ret_rdtsc:
  4731.      mov   edx,0xffffffff
  4732.      mov   eax,0xffffffff
  4733.      ret
  4734.  
  4735.  
  4736.  
  4737. rerouteirqs:
  4738.  
  4739.         cli
  4740.  
  4741.         mov     al,0x11         ;  icw4, edge triggered
  4742.         out     0x20,al
  4743.         call    pic_delay
  4744.         out     0xA0,al
  4745.         call    pic_delay
  4746.  
  4747.         mov     al,0x20         ;  generate 0x20 +
  4748.         out     0x21,al
  4749.         call    pic_delay
  4750.         mov     al,0x28         ;  generate 0x28 +
  4751.         out     0xA1,al
  4752.         call    pic_delay
  4753.  
  4754.         mov     al,0x04         ;  slave at irq2
  4755.         out     0x21,al
  4756.         call    pic_delay
  4757.         mov     al,0x02         ;  at irq9
  4758.         out     0xA1,al
  4759.         call    pic_delay
  4760.  
  4761.         mov     al,0x01         ;  8086 mode
  4762.         out     0x21,al
  4763.         call    pic_delay
  4764.         out     0xA1,al
  4765.         call    pic_delay
  4766.  
  4767.         mov     al,255          ; mask all irq's
  4768.         out     0xA1,al
  4769.         call    pic_delay
  4770.         out     0x21,al
  4771.         call    pic_delay
  4772.  
  4773.         mov     ecx,0x1000
  4774.         cld
  4775. picl1:  call    pic_delay
  4776.         loop    picl1
  4777.  
  4778.         mov     al,255          ; mask all irq's
  4779.         out     0xA1,al
  4780.         call    pic_delay
  4781.         out     0x21,al
  4782.         call    pic_delay
  4783.  
  4784.         cli
  4785.  
  4786.         ret
  4787.  
  4788.  
  4789. pic_delay:
  4790.  
  4791.         jmp     pdl1
  4792. pdl1:   ret
  4793.  
  4794.  
  4795. sys_msg_board_str:
  4796.  
  4797.      pushad
  4798.    @@:
  4799.      cmp    [esi],byte 0
  4800.      je     @f
  4801.      mov    eax,1
  4802.      movzx  ebx,byte [esi]
  4803.      call   sys_msg_board
  4804.      inc    esi
  4805.      jmp    @b
  4806.    @@:
  4807.      popad
  4808.      ret
  4809.  
  4810. uglobal
  4811.   msg_board_data: times 512 db 0
  4812.   msg_board_count dd 0x0
  4813. endg
  4814.  
  4815. sys_msg_board:
  4816.  
  4817. ; eax=1 : write :  bl byte to write
  4818. ; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
  4819.  
  4820.      mov  ecx,[msg_board_count]
  4821.      cmp  eax, 1
  4822.      jne  smbl1
  4823.  
  4824.  
  4825.      mov  [msg_board_data+ecx],bl
  4826.      inc  ecx
  4827.      and  ecx, 511
  4828.      mov  [msg_board_count], ecx
  4829.      mov  [check_idle_semaphore], 5
  4830.      ret
  4831.    smbl1:
  4832.  
  4833.      cmp   eax, 2
  4834.      jne   smbl2
  4835.      test  ecx, ecx
  4836.      jz    smbl21
  4837. ;     mov   edi, msg_board_data
  4838. ;     mov   esi, msg_board_data+1
  4839. ;     movzx eax, byte [edi]
  4840.      mov   eax, msg_board_data+1
  4841.      mov   ebx, msg_board_data
  4842.      movzx edx, byte [ebx]
  4843.      call  memmove
  4844. ;     push  ecx
  4845. ;     shr   ecx, 2
  4846. ;     cld
  4847. ;     rep   movsd
  4848. ;     pop   ecx
  4849. ;     and   ecx, 3
  4850. ;     rep   movsb
  4851.      dec   [msg_board_count]
  4852.      mov   [esp+36], edx ;eax
  4853.      mov   [esp+24], dword 1
  4854.      ret
  4855.    smbl21:
  4856.      mov   [esp+36], ecx
  4857.      mov   [esp+24], ecx
  4858.  
  4859.    smbl2:
  4860.      ret
  4861.  
  4862.  
  4863.  
  4864. sys_trace:
  4865.  
  4866.      test eax, eax                  ; get event data
  4867.      jnz  no_get_sys_events
  4868.  
  4869.      mov  esi,save_syscall_data     ; data
  4870.      mov  edi,[0x3010]
  4871.      mov  edi,[edi+0x10]
  4872.      add  edi,ebx
  4873.      cld
  4874.      rep  movsb
  4875.  
  4876.      mov  [esp+24],dword 0
  4877.      mov  eax,[save_syscall_count]  ; count
  4878.      mov  [esp+36],eax
  4879.      ret
  4880.  
  4881.    no_get_sys_events:
  4882.  
  4883.      ret
  4884.  
  4885.  
  4886. sys_process_def:
  4887.  
  4888.      cmp   eax,1                   ; set keyboard mode
  4889.      jne   no_set_keyboard_setup
  4890.  
  4891.      mov   edi,[0x3000]
  4892.      shl   edi,8
  4893.      add   edi,0x80000+0xB4
  4894.      mov   [edi],bl
  4895.  
  4896.      ret
  4897.  
  4898.    no_set_keyboard_setup:
  4899.  
  4900.      cmp   eax,2                   ; get keyboard mode
  4901.      jne   no_get_keyboard_setup
  4902.  
  4903.      mov   edi,[0x3000]
  4904.      shl   edi,8
  4905.      add   edi,0x80000+0xB4
  4906.      movzx eax, byte [edi]
  4907.  
  4908.      mov   [esp+36],eax
  4909.  
  4910.      ret
  4911.  
  4912.    no_get_keyboard_setup:
  4913.  
  4914.      cmp   eax,3                   ; get keyboard ctrl, alt, shift
  4915.      jne   no_get_keyboard_cas
  4916.  
  4917. ;     xor   eax,eax
  4918. ;     movzx eax,byte [shift]
  4919. ;     movzx ebx,byte [ctrl]
  4920. ;     shl   ebx,2
  4921. ;     add   eax,ebx
  4922. ;     movzx ebx,byte [alt]
  4923. ;     shl   ebx,3
  4924. ;     add   eax,ebx
  4925.  
  4926.  ;// mike.dld [
  4927.      mov   eax, [kb_state]
  4928.  ;// mike.dld ]
  4929.  
  4930.      mov   [esp+36],eax
  4931.  
  4932.      ret
  4933.  
  4934.    no_get_keyboard_cas:
  4935.  
  4936.  
  4937.      ret
  4938.  
  4939.  
  4940. sys_ipc:
  4941.      cmp  eax,1                      ; DEFINE IPC MEMORY
  4942.      jne  no_ipc_def
  4943.      mov  edi,[0x3000]
  4944.      shl  edi,8
  4945.      add  edi,0x80000
  4946.      mov  [edi+0xA0],ebx
  4947.      mov  [edi+0xA4],ecx
  4948.      mov  [esp+36],dword 0
  4949.      ret
  4950.    no_ipc_def:
  4951.  
  4952.      cmp  eax,2                      ; SEND IPC MESSAGE
  4953.      jne  no_ipc_send
  4954.      mov  esi,1
  4955.      mov  edi,0x3020
  4956.     ipcs1:
  4957.      cmp  [edi+4],ebx
  4958.      je   ipcs2
  4959.      add  edi,0x20
  4960.      inc  esi
  4961.      cmp  esi,[0x3004]
  4962.      jbe  ipcs1
  4963.      mov  [esp+36],dword 4
  4964.      ret
  4965.     ipcs2:
  4966.  
  4967.      cli
  4968.  
  4969.      push esi
  4970.      mov  eax,esi
  4971.      shl  eax,8
  4972.      mov  ebx,[eax+0x80000+0xa0]
  4973.      test ebx,ebx                  ; ipc area not defined ?
  4974.      je   ipc_err1
  4975.  
  4976.      add  ebx,[eax+0x80000+0xa4]
  4977.      mov  eax,esi
  4978.      shl  eax,5
  4979.      add  ebx,[eax+0x3000+0x10]    ; ebx <- max data position
  4980.  
  4981.      mov  eax,esi                  ; to
  4982.      shl  esi,8
  4983.      add  esi,0x80000
  4984.      mov  edi,[esi+0xa0]
  4985.      shl  eax,5
  4986.      add  eax,0x3000
  4987.      add  edi,[eax+0x10]
  4988.  
  4989.      cmp  [edi],byte 0             ; overrun ?
  4990.      jne  ipc_err2
  4991.  
  4992.      mov  ebp,edi
  4993.      add  edi,[edi+4]
  4994.      add  edi,8
  4995.  
  4996.      mov  esi,ecx                  ; from
  4997.      mov  eax,[0x3010]
  4998.      mov  eax,[eax+0x10]
  4999.      add  esi,eax
  5000.  
  5001.      mov  ecx,edx                  ; size
  5002.  
  5003.      mov  eax,edi
  5004.      add  eax,ecx
  5005.      cmp  eax,ebx
  5006.      jge  ipc_err3                 ; not enough room ?
  5007.  
  5008.      push ecx
  5009.  
  5010.      mov  eax,[0x3010]
  5011.      mov  eax,[eax+4]
  5012.      mov  [edi-8],eax
  5013.      mov  [edi-4],ecx
  5014.      cld
  5015.      rep  movsb
  5016.  
  5017.      pop  ecx
  5018.      add  ecx,8
  5019.  
  5020.      mov  edi,ebp                  ; increase memory position
  5021.      add  dword [edi+4],ecx
  5022.  
  5023.      mov  edi,[esp]
  5024.      shl  edi,8
  5025.      or   dword [edi+0x80000+0xA8],dword 01000000b ; ipc message
  5026.  
  5027.      cmp  [check_idle_semaphore],dword 20
  5028.      jge  ipc_no_cis
  5029.      mov  [check_idle_semaphore],5
  5030.    ipc_no_cis:
  5031.  
  5032.      xor  eax, eax
  5033.  
  5034.     ipc_err:
  5035.      add  esp,4
  5036.      mov  [esp+36],eax
  5037.      sti
  5038.      ret
  5039.  
  5040.     ipc_err1:
  5041.      add  esp,4
  5042.      mov  [esp+36],dword 1
  5043.      sti
  5044.      ret
  5045.     ipc_err2:
  5046.      add  esp,4
  5047.      mov  [esp+36],dword 2
  5048.      sti
  5049.      ret
  5050.     ipc_err3:
  5051.      add  esp,4
  5052.      mov  [esp+36],dword 3
  5053.      sti
  5054.      ret
  5055.  
  5056.    no_ipc_send:
  5057.  
  5058.      mov  [esp+36],dword -1
  5059.      ret
  5060.  
  5061.  
  5062. align 4
  5063.  
  5064. sys_gs:                         ; direct screen access
  5065.  
  5066.      cmp  eax,1                 ; resolution
  5067.      jne  no_gs1
  5068.      mov  eax,[0xfe00]
  5069.      shl  eax,16
  5070.      mov  ax,[0xfe04]
  5071.      add  eax,0x00010001
  5072.      mov  [esp+36],eax
  5073.      ret
  5074.    no_gs1:
  5075.  
  5076.      cmp   eax,2                ; bits per pixel
  5077.      jne   no_gs2
  5078.      movzx eax,byte [0xfbf1]
  5079.      mov   [esp+36],eax
  5080.      ret
  5081.    no_gs2:
  5082.  
  5083.      cmp   eax,3                ; bytes per scanline
  5084.      jne   no_gs3
  5085.      mov   eax,[0xfe08]
  5086.      mov   [esp+36],eax
  5087.      ret
  5088.    no_gs3:
  5089.  
  5090.      mov  [esp+36],dword -1
  5091.      ret
  5092.  
  5093.  
  5094. align 4 ; PCI functions
  5095.  
  5096. sys_pci:
  5097.  
  5098.      call  pci_api
  5099.      mov   [esp+36],eax
  5100.      ret
  5101.  
  5102.  
  5103. align 4  ;  system functions
  5104.  
  5105. syscall_setpixel:                       ; SetPixel
  5106.  
  5107.  
  5108.      mov   edx,[0x3010]
  5109.      add   eax,[edx-twdw]
  5110.      add   ebx,[edx-twdw+4]
  5111.      xor   edi,edi ; no force
  5112.      call  [disable_mouse]
  5113.      jmp   [putpixel]
  5114.  
  5115. align 4
  5116.  
  5117. syscall_writetext:                      ; WriteText
  5118.  
  5119.      mov   edi,[0x3010]
  5120.      mov   ebp,[edi-twdw]
  5121.      shl   ebp,16
  5122.      add   ebp,[edi-twdw+4]
  5123.      add   edi,0x10
  5124.      add   ecx,[edi]
  5125.      add   eax,ebp
  5126.      xor   edi,edi
  5127.      jmp   dtext
  5128.  
  5129. align 4
  5130.  
  5131. syscall_openramdiskfile:                ; OpenRamdiskFile
  5132.  
  5133.  
  5134.      mov   edi,[0x3010]
  5135.      add   edi,0x10
  5136.      add   eax,[edi]
  5137.      add   edx,[edi]
  5138.      mov   esi,12
  5139.      call  fileread
  5140.      mov   [esp+36],ebx
  5141.      ret
  5142.  
  5143. align 4
  5144.  
  5145. syscall_putimage:                       ; PutImage
  5146.  
  5147.      mov   edi,[0x3010]
  5148.      add   edi,0x10
  5149.      add   eax,[edi]
  5150.      mov   edx,ecx
  5151.      mov   ecx,ebx
  5152.      mov   ebx,eax
  5153.      call  sys_putimage
  5154.      mov   [esp+36],eax
  5155.      ret
  5156.  
  5157. align 4
  5158.  
  5159. syscall_drawrect:                       ; DrawRect
  5160.  
  5161.      mov   edi,ecx
  5162.      test  ax,ax
  5163.      je    drectr
  5164.      test  bx,bx
  5165.      je    drectr
  5166.      movzx ecx,ax
  5167.      shr   eax,16
  5168.      movzx edx,bx
  5169.      shr   ebx,16
  5170.      add   ecx,eax
  5171.      add   edx,ebx
  5172.      jmp   [drawbar]
  5173.     drectr:
  5174.      ret
  5175.  
  5176. align 4
  5177.  
  5178. syscall_getscreensize:                  ; GetScreenSize
  5179.  
  5180.      movzx eax,word[0xfe00]
  5181.      shl   eax,16
  5182.      mov   ax,[0xfe04]
  5183.      mov   [esp+36],eax
  5184.      ret
  5185.  
  5186. align 4
  5187.  
  5188. syscall_system:                         ; System
  5189.  
  5190.      call  sys_system
  5191.      mov   [esp+36],eax
  5192.      ret
  5193.  
  5194. align 4
  5195.  
  5196. syscall_startapp:                       ; StartApp
  5197.      mov   edi,[0x3010]
  5198.      add   edi,0x10
  5199.      add   eax,[edi]
  5200.      test  ebx,ebx
  5201.      jz    noapppar
  5202.      add   ebx,[edi]
  5203.    noapppar:
  5204. ;     call  start_application_fl
  5205.      call   new_start_application_fl
  5206.      mov   [esp+36],eax
  5207.      ret
  5208.      
  5209.  
  5210. align 4
  5211.  
  5212. syscall_cdaudio:                        ; CD
  5213.  
  5214.      call  sys_cd_audio
  5215.      mov   [esp+36],eax
  5216.      ret
  5217.  
  5218. align 4
  5219.  
  5220. syscall_readhd:                         ; ReadHd
  5221.  
  5222.      mov   edi,[0x3010]
  5223.      add   edi,0x10
  5224.      add   esi,[edi]
  5225.      add   eax,[edi]
  5226.      call  read_hd_file
  5227.      mov   [esp+36],eax
  5228.      mov   [esp+24],ebx
  5229.      ret
  5230.  
  5231. align 4
  5232.  
  5233. syscall_starthdapp:                     ; StartHdApp
  5234.  
  5235.      mov   edi,[0x3010]
  5236.      add   edi,0x10
  5237.      add   eax,[edi]
  5238.      add   ecx,[edi]
  5239.      mov   ebp,0
  5240.      call  start_application_hd
  5241.      mov   [esp+36],eax
  5242.      ret
  5243.  
  5244. align 4
  5245.  
  5246. syscall_delramdiskfile:                 ; DelRamdiskFile
  5247.  
  5248.      mov   edi,[0x3010]
  5249.      add   edi,0x10
  5250.      add   eax,[edi]
  5251.      call  filedelete
  5252.      mov   [esp+36],eax
  5253.      ret
  5254.  
  5255. align 4
  5256.  
  5257. syscall_writeramdiskfile:               ; WriteRamdiskFile
  5258.  
  5259.      mov   edi,[0x3010]
  5260.      add   edi,0x10
  5261.      add   eax,[edi]
  5262.      add   ebx,[edi]
  5263.      call  filesave
  5264.      mov   [esp+36],eax
  5265.      ret
  5266.  
  5267. align 4
  5268.  
  5269. syscall_getpixel:                       ; GetPixel
  5270.  
  5271.      mov   ecx,[0xfe00]
  5272.      inc   ecx
  5273.      xor   edx,edx
  5274.      div   ecx
  5275.      mov   ebx,edx
  5276.      xchg  eax,ebx
  5277.      call  dword [0xe024]
  5278.      mov   [esp+36],ecx
  5279.      ret
  5280.  
  5281. align 4
  5282.  
  5283. syscall_readstring:                     ; ReadString
  5284.  
  5285.      mov   edi,[0x3010]
  5286.      add   edi,0x10
  5287.      add   eax,[edi]
  5288.      call  read_string
  5289.      mov   [esp+36],eax
  5290.      ret
  5291.  
  5292. align 4
  5293.  
  5294. syscall_drawline:                       ; DrawLine
  5295.  
  5296.      mov   edi,[0x3010]
  5297.      movzx edx,word[edi-twdw]
  5298.      mov   ebp,edx
  5299.      shl   edx,16
  5300.      add   ebp,edx
  5301.      movzx edx,word[edi-twdw+4]
  5302.      add   eax,ebp
  5303.      mov   ebp,edx
  5304.      shl   edx,16
  5305.      xor   edi,edi
  5306.      add   edx,ebp
  5307.      add   ebx,edx
  5308.      jmp   [draw_line]
  5309.  
  5310. align 4
  5311.  
  5312. syscall_getirqowner:                    ; GetIrqOwner
  5313.  
  5314.      shl   eax,2
  5315.      add   eax,irq_owner
  5316.      mov   eax,[eax]
  5317.      mov   [esp+36],eax
  5318.      ret
  5319.  
  5320. align 4
  5321.  
  5322. syscall_reserveportarea:                ; ReservePortArea and FreePortArea
  5323.  
  5324.      call  r_f_port_area
  5325.      mov   [esp+36],eax
  5326.      ret
  5327.  
  5328. ;align 4
  5329.  
  5330. syscall_appints:                        ; AppInts
  5331. ;    mov   [esp+36],dword -1
  5332.      ret
  5333.  
  5334. align 4
  5335.  
  5336. syscall_threads:                        ; CreateThreads
  5337.  
  5338.      call  sys_threads
  5339.      mov   [esp+36],eax
  5340.      ret
  5341.  
  5342. align 4
  5343.  
  5344. stack_driver_stat:
  5345.  
  5346.      call  app_stack_handler            ; Stack status
  5347.  
  5348. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  5349. ;     call  change_task                 ; between sent packet
  5350.  
  5351.      mov   [esp+36],eax
  5352.      ret
  5353.  
  5354. align 4
  5355.  
  5356. socket:                                 ; Socket interface
  5357.      call  app_socket_handler
  5358.  
  5359. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  5360. ;     call  change_task                 ; between sent packet
  5361.  
  5362.      mov   [esp+36],eax
  5363.      mov   [esp+24],ebx
  5364.      ret
  5365.  
  5366. align 4
  5367.  
  5368. user_events:                            ; User event times
  5369.  
  5370.      mov   eax,0x12345678
  5371.      mov   [esp+36],eax
  5372.  
  5373.      ret
  5374.  
  5375. align 4
  5376.  
  5377. read_from_hd:                           ; Read from hd - fn not in use
  5378.  
  5379.      mov   edi,[0x3010]
  5380.      add   edi,0x10
  5381.      add   eax,[edi]
  5382.      add   ecx,[edi]
  5383.      add   edx,[edi]
  5384.      call  file_read
  5385.  
  5386.      mov   [esp+36],eax
  5387.      mov   [esp+24],ebx
  5388.  
  5389.      ret
  5390.  
  5391.  
  5392. align 4
  5393.  
  5394. write_to_hd:                            ; Write a file to hd
  5395.  
  5396.      mov   edi,[0x3010]
  5397.      add   edi,0x10
  5398.      add   eax,[edi]
  5399.      add   ecx,[edi]
  5400.      add   edx,[edi]
  5401.      call  file_write
  5402.      ret
  5403.  
  5404. align 4
  5405.  
  5406. delete_from_hd:                         ; Delete a file from hd
  5407.  
  5408.      mov   edi,[0x3010]
  5409.      add   edi,0x10
  5410.      add   eax,[edi]
  5411.      add   ecx,[edi]
  5412.      call  file_delete
  5413.      ret
  5414.  
  5415.  
  5416. align 4
  5417.  
  5418. undefined_syscall:                      ; Undefined system call
  5419.  
  5420.      mov   [esp+36],dword -1
  5421.      ret
  5422.  
  5423.  
  5424. ;clear_busy_flag_at_caller:
  5425.  
  5426. ;      push  edi
  5427.  
  5428. ;      mov   edi,[0x3000]    ; restore processes tss pointer in gdt, busyfl?
  5429. ;      imul  edi,8
  5430. ;      mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  5431.  
  5432. ;      pop   edi
  5433.  
  5434. ;      ret
  5435.  
  5436.  
  5437.  
  5438.  
  5439. keymap:
  5440.  
  5441.      db   '6',27
  5442.      db   '1234567890-=',8,9
  5443.      db   'qwertyuiop[]',13
  5444.      db   '~asdfghjkl;',39,96,0,'\zxcvbnm,./',0,'45 '
  5445.      db   '@234567890123',180,178,184,'6',176,'7'
  5446.      db   179,'8',181,177,183,185,182
  5447.      db   'AB<D',255,'FGHIJKLMNOPQRSTUVWXYZ'
  5448.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5449.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5450.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5451.  
  5452.  
  5453. keymap_shift:
  5454.  
  5455.      db   '6',27
  5456.      db   '!@#$%^&*()_+',8,9
  5457.      db   'QWERTYUIOP{}',13
  5458.      db   '~ASDFGHJKL:"~',0,'|ZXCVBNM<>?',0,'45 '
  5459.      db   '@234567890123',180,178,184,'6',176,'7'
  5460.      db   179,'8',181,177,183,185,182
  5461.      db   'AB>D',255,'FGHIJKLMNOPQRSTUVWXYZ'
  5462.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5463.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5464.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5465.  
  5466.  
  5467. keymap_alt:
  5468.  
  5469.      db   ' ',27
  5470.      db   ' @ $  {[]}\ ',8,9
  5471.      db   '            ',13
  5472.      db   '             ',0,'           ',0,'4',0,' '
  5473.      db   '             ',180,178,184,'6',176,'7'
  5474.      db   179,'8',181,177,183,185,182
  5475.      db   'ABCD',255,'FGHIJKLMNOPQRSTUVWXYZ'
  5476.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5477.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5478.      db   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  5479.  
  5480.  
  5481. ; device irq owners
  5482. uglobal
  5483. irq_owner:       ; process id
  5484.  
  5485.      dd   0x0
  5486.      dd   0x0
  5487.      dd   0x0
  5488.      dd   0x0
  5489.      dd   0x0
  5490.      dd   0x0
  5491.      dd   0x0
  5492.      dd   0x0
  5493.      dd   0x0
  5494.      dd   0x0
  5495.      dd   0x0
  5496.      dd   0x0
  5497.      dd   0x0
  5498.      dd   0x0
  5499.      dd   0x0
  5500.      dd   0x0
  5501. endg
  5502.  
  5503.  
  5504. ; on irq read ports
  5505. uglobal
  5506.   irq00read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5507.   irq01read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5508.   irq02read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5509.   irq03read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5510.   irq04read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5511.   irq05read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5512.   irq06read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5513.   irq07read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5514.   irq08read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5515.   irq09read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5516.   irq10read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5517.   irq11read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5518.   irq12read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5519.   irq13read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5520.   irq14read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5521.   irq15read  dd  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  5522. endg
  5523.  
  5524. ; status
  5525. uglobal
  5526.   hd1_status                  dd 0x0  ; 0 - free : other - pid
  5527.   application_table_status    dd 0x0  ; 0 - free : other - pid
  5528. endg
  5529.  
  5530. ; device addresses
  5531. uglobal
  5532.   mididp     dd 0x0
  5533.   midisp     dd 0x0
  5534.  
  5535.   cdbase     dd 0x0
  5536.   cdid       dd 0x0
  5537.  
  5538.   hdbase              dd   0x0  ; for boot 0x1f0
  5539.   hdid                dd   0x0
  5540.   hdpos               dd   0x0  ; for boot 0x1
  5541.   fat32part           dd   0x0  ; for boot 0x1
  5542.  
  5543.   ;part2_ld            dd   0x0
  5544.  
  5545. ;* start code - get  process (3) - Mario79
  5546. active_process      dd   0
  5547. ;* end code - get active process (3) - Mario79
  5548.  
  5549. wraw_bacground_select db 0
  5550.   lba_read_enabled    dd   0x0  ; 0 = disabled , 1 = enabled
  5551.   pci_access_enabled  dd   0x0  ; 0 = disabled , 1 = enabled
  5552.  
  5553.   sb16       dd 0x0
  5554.   wss        dd 0x0
  5555.  
  5556.   buttontype         dd 0x0
  5557.   windowtypechanged  dd 0x0
  5558. endg
  5559.  
  5560. iglobal
  5561.   keyboard   dd 0x1
  5562.   sound_dma  dd 0x1
  5563.   syslang    dd 0x1
  5564. endg
  5565.  
  5566. IncludeIGlobals
  5567. endofcode:
  5568. IncludeUGlobals
  5569. uglobals_size = $ - endofcode
  5570. diff16 "end of kernel code",$
  5571.  
  5572.