Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                                                      ;
  3. ;                       KERNEL FUNCTIONS                               ;
  4. ;                                                                      ;
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6.  
  7. reserve_irqs_ports:
  8.  
  9.         pushad
  10.  
  11.         mov  [irq_owner+4*0],byte 1    ; timer
  12.         mov  [irq_owner+4*1],byte 1    ; keyboard
  13.         mov  [irq_owner+4*5],byte 1    ; sound blaster
  14.         mov  [irq_owner+4*6],byte 1    ; floppy diskette
  15.         mov  [irq_owner+4*13],byte 1   ; math co-pros
  16.         mov  [irq_owner+4*14],byte 1   ; ide I
  17.         mov  [irq_owner+4*15],byte 1   ; ide II
  18. ;        movzx eax,byte [0xf604]        ; mouse irq
  19. ;        dec   eax
  20. ;        add   eax,mouseirqtable
  21. ;        movzx eax,byte [eax]
  22. ;        shl   eax,2
  23. ;        mov   [irq_owner+eax],byte 1
  24.  
  25.  
  26.                                        ; RESERVE PORTS
  27.         mov   edi,1                    ; 0x00-0x2d
  28.         mov   [RESERVED_PORTS],edi
  29.         shl   edi,4
  30.         mov   [RESERVED_PORTS+edi+0],dword 1
  31.         mov   [RESERVED_PORTS+edi+4],dword 0x0
  32.         mov   [RESERVED_PORTS+edi+8],dword 0x2d
  33.  
  34.         inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
  35.         mov   edi,[RESERVED_PORTS]
  36.         shl   edi,4
  37.         mov   [RESERVED_PORTS+edi+0],dword 1
  38.         mov   [RESERVED_PORTS+edi+4],dword 0x30
  39.         mov   [RESERVED_PORTS+edi+8],dword 0x4d
  40.  
  41.         inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
  42.         mov   edi,[RESERVED_PORTS]
  43.         shl   edi,4
  44.         mov   [RESERVED_PORTS+edi+0],dword 1
  45.         mov   [RESERVED_PORTS+edi+4],dword 0x50
  46.         mov   [RESERVED_PORTS+edi+8],dword 0xdf
  47.  
  48.         inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
  49.         mov   edi,[RESERVED_PORTS]
  50.         shl   edi,4
  51.         mov   [RESERVED_PORTS+edi+0],dword 1
  52.         mov   [RESERVED_PORTS+edi+4],dword 0xe5
  53.         mov   [RESERVED_PORTS+edi+8],dword 0xff
  54.  
  55.  
  56. ;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
  57. ;        jne   ripl1
  58. ;        inc   dword [0x2d0000]
  59. ;        mov   edi,[0x2d0000]
  60. ;        shl   edi,4
  61. ;        mov   [0x2d0000+edi+0],dword 1
  62. ;        mov   [0x2d0000+edi+4],dword 0x3f0
  63. ;        mov   [0x2d0000+edi+8],dword 0x3ff
  64. ;      ripl1:
  65. ;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
  66. ;        jne   ripl2
  67. ;        inc   dword [0x2d0000]
  68. ;        mov   edi,[0x2d0000]
  69. ;        shl   edi,4
  70. ;        mov   [0x2d0000+edi+0],dword 1
  71. ;        mov   [0x2d0000+edi+4],dword 0x2f0
  72. ;        mov   [0x2d0000+edi+8],dword 0x2ff
  73. ;      ripl2:
  74.  
  75.         popad
  76.         ret
  77.  
  78. iglobal
  79. mouseirqtable   db  12    ; ps2
  80.                 db  4     ; com1
  81.                 db  3     ; com2
  82. endg
  83.  
  84. setirqreadports:
  85.  
  86.         mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
  87.         mov   [irq12read+4],dword 0                  ; end of port list
  88.         mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
  89.         mov   [irq04read+4],dword 0                  ; end of port list
  90.         mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
  91.         mov   [irq03read+4],dword 0                  ; end of port list
  92.  
  93.         ret
  94.  
  95. iglobal
  96.   process_number dd 0x1
  97. endg
  98.  
  99. set_variables:
  100.  
  101.         mov   ecx,0x100                       ; flush port 0x60
  102. .fl60:  in    al,0x60
  103.         loop  .fl60
  104.         mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
  105.         mov   [KEY_COUNT],byte 0                 ; keyboard buffer
  106.         mov   [BTN_COUNT],byte 0                 ; button buffer
  107. ;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
  108.  
  109.         push  eax
  110.         mov   ax,[0x2f0000+0x900c]
  111.         shr   ax,1
  112.         shl   eax,16
  113.         mov   ax,[0x2f0000+0x900A]
  114.         shr   ax,1
  115.         mov   [MOUSE_X],eax
  116.         pop   eax
  117.  
  118.         mov   byte [SB16_Status],0            ; Minazzi Paolo
  119.         mov   [display_data-12],dword 1       ; tiled background
  120.         mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
  121.  
  122.      ;!! IP 04.02.2005:
  123.         mov   [next_usage_update], 100
  124.         mov   byte [0xFFFF], 0 ; change task if possible
  125.  
  126.         ret
  127.  
  128. ;* mouse centered - start code- Mario79
  129. mouse_centered:
  130.         push  eax
  131.         mov   eax,[ScreenWidth]
  132.         shr   eax,1
  133.         mov   [MOUSE_X],ax
  134.         mov   eax,[ScreenHeight]
  135.         shr   eax,1
  136.         mov   [MOUSE_Y],ax
  137.         pop   eax
  138.         ret
  139. ;* mouse centered - end code- Mario79
  140.  
  141. align 4
  142.  
  143. sys_outport:
  144.  
  145.     mov   edi,ebx          ; separate flag for read / write
  146.     and   ebx,65535
  147.  
  148.     mov   ecx,[RESERVED_PORTS]
  149.     test  ecx,ecx
  150.     jne   sopl8
  151.     mov   [esp+36],dword 1
  152.     ret
  153.  
  154.   sopl8:
  155.     mov   edx,[TASK_BASE]
  156.     mov   edx,[edx+0x4]
  157.     and   ebx,65535
  158.     cld
  159.   sopl1:
  160.  
  161.     mov   esi,ecx
  162.     shl   esi,4
  163.     add   esi,RESERVED_PORTS
  164.     cmp   edx,[esi+0]
  165.     jne   sopl2
  166.     cmp   ebx,[esi+4]
  167.     jb    sopl2
  168.     cmp   ebx,[esi+8]
  169.     jg    sopl2
  170.     jmp   sopl3
  171.  
  172.   sopl2:
  173.  
  174.     dec   ecx
  175.     jnz   sopl1
  176.     mov   [esp+36],dword 1
  177.     ret
  178.  
  179.   sopl3:
  180.  
  181.     test  edi,0x80000000 ; read ?
  182.     jnz   sopl4
  183.  
  184.     mov   dx,bx          ; write
  185.     out   dx,al
  186.     mov   [esp+36],dword 0
  187.     ret
  188.  
  189.   sopl4:
  190.  
  191.     mov   dx,bx          ; read
  192.     in    al,dx
  193.     and   eax,0xff
  194.     mov   [esp+36],dword 0
  195.     mov   [esp+24],eax
  196.     ret
  197.  
  198.  
  199.  
  200. align 4
  201. sys_sb16:
  202.  
  203.      cmp  word [sb16],word 0
  204.      jnz  sb16l1
  205.      mov  [esp+36],dword 1
  206.      ret
  207.    sb16l1:
  208.      mov  [esp+36],dword 0
  209.      cmp  eax,1    ; set volume - main
  210.      jnz  sb16l2
  211.      mov  dx,word [sb16]
  212.      add  dx,4
  213.      mov  al,0x22
  214.      out  dx,al
  215.      mov  esi,1
  216.      call delay_ms
  217.      mov  eax,ebx
  218.      inc  edx
  219.      out  dx,al
  220.      ret
  221.    sb16l2:
  222.  
  223.      cmp  eax,2    ; set volume - cd
  224.      jnz  sb16l3
  225.      mov  dx,word [sb16]
  226.      add  dx,4
  227.      mov  al,0x28
  228.      out  dx,al
  229.      mov  esi,1
  230.      call delay_ms
  231.      mov  eax,ebx
  232.      add  edx,1
  233.      out  dx,al
  234.      ret
  235.    sb16l3:
  236.       mov  [esp+36],dword 2
  237.       ret
  238.  
  239.  
  240. align 4
  241.  
  242. sys_sb16II:
  243.  
  244.      cmp  word [sb16],word 0
  245.      jnz  IIsb16l1
  246.      mov  [esp+36],dword 1
  247.      ret
  248.    IIsb16l1:
  249.  
  250.      cmp  eax,1    ; set volume - main
  251.      jnz  IIsb16l2
  252.      ; L
  253.      mov  dx,word [sb16]
  254.      add  dx,4
  255.      mov  al,0x30
  256.      out  dx,al
  257.      mov  eax,ebx
  258.      inc  edx
  259.      out  dx,al
  260.      ; R
  261.      mov  dx,word [sb16]
  262.      add  dx,4
  263.      mov  al,0x31
  264.      out  dx,al
  265.      mov  eax,ebx
  266.      inc  edx
  267.      out  dx,al
  268.      mov  [esp+36],dword 0
  269.      ret
  270.    IIsb16l2:
  271.  
  272.      cmp  eax,2    ; set volume - cd
  273.      jnz  IIsb16l3
  274.      ; L
  275.      mov  dx,word [sb16]
  276.      add  dx,4
  277.      mov  al,0x36
  278.      out  dx,al
  279.      mov  eax,ebx
  280.      inc  edx
  281.      out  dx,al
  282.      ; R
  283.      mov  dx,word [sb16]
  284.      add  dx,4
  285.      mov  al,0x37
  286.      out  dx,al
  287.      mov  eax,ebx
  288.      inc  edx
  289.      out  dx,al
  290.      mov  [esp+36],dword 0
  291.      ret
  292.    IIsb16l3:
  293.  
  294.      mov  [esp+36],dword 2
  295.      ret
  296.  
  297.  
  298. display_number:
  299.  
  300. ; eax = print type, al=0 -> ebx is number
  301. ;                   al=1 -> ebx is pointer
  302. ;                   ah=0 -> display decimal
  303. ;                   ah=1 -> display hexadecimal
  304. ;                   ah=2 -> display binary
  305. ;                   eax bits 16-21 = number of digits to display (0-32)
  306. ;                   eax bits 22-31 = reserved
  307. ;
  308. ; ebx = number or pointer
  309. ; ecx = x shl 16 + y
  310. ; edx = color
  311.         xor     edi, edi
  312. display_number_force:
  313.  
  314.      cmp   eax,0xffff            ; length > 0 ?
  315.      jge   cont_displ
  316.      ret
  317.    cont_displ:
  318.  
  319.      cmp   eax,61*0x10000        ; length <= 60 ?
  320.      jb    cont_displ2
  321.      ret
  322.    cont_displ2:
  323.  
  324.      pushad
  325.  
  326.      cmp   al,1                  ; ecx is a pointer ?
  327.      jne   displnl1
  328.      mov   ebx,[ebx+std_application_base_address]
  329.    displnl1:
  330.      sub   esp,64
  331.  
  332.      cmp   ah,0                  ; DECIMAL
  333.      jne   no_display_desnum
  334.      shr   eax,16
  335.      and   eax,0x3f
  336.      push  eax
  337.      mov   edi,esp
  338.      add   edi,4+64-1
  339.      mov   ecx,eax
  340.      mov   eax,ebx
  341.      mov   ebx,10
  342.    d_desnum:
  343.      xor   edx,edx
  344.      div   ebx
  345.      add   dl,48
  346.      mov   [edi],dl
  347.      dec   edi
  348.      loop  d_desnum
  349.      pop   eax
  350.      call  draw_num_text
  351.      add   esp,64
  352.      popad
  353.      ret
  354.    no_display_desnum:
  355.  
  356.      cmp   ah,0x01               ; HEXADECIMAL
  357.      jne   no_display_hexnum
  358.      shr   eax,16
  359.      and   eax,0x3f
  360.      push  eax
  361.      mov   edi,esp
  362.      add   edi,4+64-1
  363.      mov   ecx,eax
  364.      mov   eax,ebx
  365.      mov   ebx,16
  366.    d_hexnum:
  367.      xor   edx,edx
  368.      div   ebx
  369.      add   edx,hexletters
  370.      mov   dl,[edx]
  371.      mov   [edi],dl
  372.      dec   edi
  373.      loop  d_hexnum
  374.      pop   eax
  375.      call  draw_num_text
  376.      add   esp,64
  377.      popad
  378.      ret
  379.    no_display_hexnum:
  380.  
  381.      cmp   ah,0x02               ; BINARY
  382.      jne   no_display_binnum
  383.      shr   eax,16
  384.      and   eax,0x3f
  385.      push  eax
  386.      mov   edi,esp
  387.      add   edi,4+64-1
  388.      mov   ecx,eax
  389.      mov   eax,ebx
  390.      mov   ebx,2
  391.    d_binnum:
  392.      xor   edx,edx
  393.      div   ebx
  394.      add   dl,48
  395.      mov   [edi],dl
  396.      dec   edi
  397.      loop  d_binnum
  398.      pop   eax
  399.      call  draw_num_text
  400.      add   esp,64
  401.      popad
  402.      ret
  403.    no_display_binnum:
  404.  
  405.      add   esp,64
  406.      popad
  407.      ret
  408.  
  409.  
  410. draw_num_text:
  411.  
  412.      ; dtext
  413.      ;
  414.      ; eax x & y
  415.      ; ebx color
  416.      ; ecx start of text
  417.      ; edx length
  418.      ; edi 1 force
  419.  
  420. ;        mov     edi,[CURRENT_TASK]
  421. ;        shl     edi,8
  422. ;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  423. ;        rol     eax,16
  424. ;        add     ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  425. ;        rol     eax,16
  426.  
  427.      mov   edx,eax
  428.      mov   ecx,64+4
  429.      sub   ecx,eax
  430.      add   ecx,esp
  431.      mov   eax,[esp+64+32-8+4]
  432.      push  edx                       ; add window start x & y
  433.      mov   edx,[TASK_BASE]
  434.      mov   ebx,[edx-twdw+WDATA.box.left]
  435.      add   ebx, [(edx-CURRENT_TASK)*8+SLOT_BASE+APPDATA.wnd_clientbox.left]
  436.      shl   ebx,16
  437.      add   ebx,[edx-twdw+WDATA.box.top]
  438.      add   ebx, [(edx-CURRENT_TASK)*8+SLOT_BASE+APPDATA.wnd_clientbox.top]
  439.      add   eax,ebx
  440.      pop   edx
  441.      mov   ebx,[esp+64+32-12+4]
  442.         and     ebx, not 0x80000000     ; force counted string
  443.         mov     esi, [esp+64+4+4]
  444.         mov     edi, [esp+64+4]
  445.      jmp   dtext
  446.  
  447. read_string:
  448.  
  449.     ; eax  read_area
  450.     ; ebx  color of letter
  451.     ; ecx  color of background
  452.     ; edx  number of letters to read
  453.     ; esi  [x start]*65536 + [y_start]
  454.  
  455.     ret
  456.  
  457.  
  458. align 4
  459.  
  460. sys_setup:
  461.  
  462. ; 1=roland mpu midi base , base io address
  463. ; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
  464. ; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  465. ; 4=sb16 base , base io address
  466. ; 5=system language, 1eng 2fi 3ger 4rus
  467. ; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  468. ; 8=fat32 partition in hd
  469. ; 9
  470. ; 10 = sound dma channel
  471. ; 11 = enable lba read
  472. ; 12 = enable pci access
  473.  
  474.  
  475.      mov  [esp+36],dword 0
  476.      cmp  eax,1                      ; MIDI
  477.      jnz  nsyse1
  478.      cmp  ebx,0x100
  479.      jb   nsyse1
  480.      mov  edx,65535
  481.      cmp  edx,ebx
  482.      jb   nsyse1
  483.      mov  [midi_base],bx
  484.      mov  word [mididp],bx
  485.      inc  bx
  486.      mov  word [midisp],bx
  487.      ret
  488.  
  489. iglobal
  490. midi_base dw 0
  491. endg
  492.  
  493.    nsyse1:
  494.  
  495.      cmp  eax,2                      ; KEYBOARD
  496.      jnz  nsyse2
  497.      cmp  ebx,1
  498.      jnz  kbnobase
  499.      mov  edi,[TASK_BASE]
  500.      add  ecx,[edi+TASKDATA.mem_start]
  501.      mov  eax,ecx
  502.      mov  ebx,keymap
  503.      mov  ecx,128
  504.      call memmove
  505.      ret
  506.    kbnobase:
  507.      cmp  ebx,2
  508.      jnz  kbnoshift
  509.      mov  edi,[TASK_BASE]
  510.      add  ecx,[edi+TASKDATA.mem_start]
  511.      mov  eax,ecx
  512.      mov  ebx,keymap_shift
  513.      mov  ecx,128
  514.      call memmove
  515.      ret
  516.    kbnoshift:
  517.      cmp  ebx,3
  518.      jne  kbnoalt
  519.      mov  edi,[TASK_BASE]
  520.      add  ecx,[edi+TASKDATA.mem_start]
  521.      mov  eax,ecx
  522.      mov  ebx,keymap_alt
  523.      mov  ecx,128
  524.      call memmove
  525.      ret
  526.    kbnoalt:
  527.      cmp  ebx,9
  528.      jnz  kbnocountry
  529.      mov  word [keyboard],cx
  530.      ret
  531.    kbnocountry:
  532.      mov  [esp+36],dword 1
  533.      ret
  534.    nsyse2:
  535.      cmp  eax,3                      ; CD
  536.      jnz  nsyse3
  537.      test ebx,ebx
  538.      jz   nosesl
  539.      cmp  ebx, 4
  540.      ja   nosesl
  541.      mov  [cd_base],bl
  542.      cmp  ebx,1
  543.      jnz  noprma
  544.      mov  [cdbase],0x1f0
  545.      mov  [cdid],0xa0
  546.    noprma:
  547.      cmp  ebx,2
  548.      jnz  noprsl
  549.      mov  [cdbase],0x1f0
  550.      mov  [cdid],0xb0
  551.    noprsl:
  552.      cmp  ebx,3
  553.      jnz  nosema
  554.      mov  [cdbase],0x170
  555.      mov  [cdid],0xa0
  556.    nosema:
  557.      cmp  ebx,4
  558.      jnz  nosesl
  559.      mov  [cdbase],0x170
  560.      mov  [cdid],0xb0
  561.    nosesl:
  562.      ret
  563.  
  564. cd_base db 0
  565.  
  566.    nsyse3:
  567.  
  568.      cmp  eax,4                      ; SB
  569.      jnz  nsyse4
  570.      cmp  ebx,0x100
  571.      jb   nsyse4
  572.      mov  edx,65535
  573.      cmp  edx,ebx
  574.      jb   nsyse4
  575.      mov  word [sb16],bx
  576.      ret
  577.    nsyse4:
  578.  
  579.      cmp  eax,5                      ; SYSTEM LANGUAGE
  580.      jnz  nsyse5
  581.      mov  [syslang],ebx
  582.      ret
  583.    nsyse5:
  584.  
  585.      cmp  eax,7                      ; HD BASE
  586.      jne  nsyse7
  587.      test ebx,ebx
  588.      jz   nosethd
  589.      cmp  ebx,4
  590.      ja   nosethd
  591.      mov  [hd_base],bl
  592.      cmp  ebx,1
  593.      jnz  noprmahd
  594.      mov  [hdbase],0x1f0
  595.      mov  [hdid],0x0
  596.      mov  [hdpos],1
  597. ;     call set_FAT32_variables
  598.    noprmahd:
  599.      cmp  ebx,2
  600.      jnz  noprslhd
  601.      mov  [hdbase],0x1f0
  602.      mov  [hdid],0x10
  603.      mov  [hdpos],2
  604. ;     call set_FAT32_variables
  605.    noprslhd:
  606.      cmp  ebx,3
  607.      jnz  nosemahd
  608.      mov  [hdbase],0x170
  609.      mov  [hdid],0x0
  610.      mov  [hdpos],3
  611. ;     call set_FAT32_variables
  612.    nosemahd:
  613.      cmp  ebx,4
  614.      jnz  noseslhd
  615.      mov  [hdbase],0x170
  616.      mov  [hdid],0x10
  617.      mov  [hdpos],4
  618. ;     call set_FAT32_variables
  619.    noseslhd:
  620.     call  reserve_hd1
  621.     call  reserve_hd_channel
  622.     call  free_hd_channel
  623.     mov   [hd1_status],0        ; free
  624.    nosethd:
  625.      ret
  626.  
  627. iglobal
  628. hd_base db 0
  629. endg
  630.  
  631.    nsyse7:
  632.  
  633.      cmp  eax,8                      ; HD PARTITION
  634.      jne  nsyse8
  635.      mov  [fat32part],ebx
  636. ;     call set_FAT32_variables
  637.     call  reserve_hd1
  638.     call  reserve_hd_channel
  639.     call  free_hd_channel
  640.      pusha
  641.      call  choice_necessity_partition_1
  642.      popa
  643.     mov   [hd1_status],0        ; free
  644.      ret
  645.    nsyse8:
  646.  
  647.      cmp  eax,10                     ; SOUND DMA CHANNEL
  648.      jne  no_set_sound_dma
  649.      cmp  ebx,3
  650.      ja   sys_setup_err
  651.      mov  [sound_dma],ebx
  652.      ret
  653.    no_set_sound_dma:
  654.  
  655.      cmp  eax,11                     ; ENABLE LBA READ
  656.      jne  no_set_lba_read
  657.      and  ebx,1
  658.      mov  [lba_read_enabled],ebx
  659.      ret
  660.    no_set_lba_read:
  661.  
  662.      cmp  eax,12                     ; ENABLE PCI ACCESS
  663.      jne  no_set_pci_access
  664.      and  ebx,1
  665.      mov  [pci_access_enabled],ebx
  666.      ret
  667.    no_set_pci_access:
  668.  
  669. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  670. include 'vmodeint.inc'
  671. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  672.  
  673. sys_setup_err:
  674.      mov  [esp+36],dword -1
  675.      ret
  676.  
  677.  
  678. align 4
  679.  
  680. sys_getsetup:
  681.  
  682. ; 1=roland mpu midi base , base io address
  683. ; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
  684. ; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  685. ; 4=sb16 base , base io address
  686. ; 5=system language, 1eng 2fi 3ger 4rus
  687. ; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
  688. ; 8=fat32 partition in hd
  689. ; 9=get hs timer tic
  690.  
  691.      cmp  eax,1
  692.      jne  ngsyse1
  693.      movzx eax,[midi_base]
  694.      mov  [esp+36],eax
  695.      ret
  696.    ngsyse1:
  697.  
  698.      cmp  eax,2
  699.      jne  ngsyse2
  700.      cmp  ebx,1
  701.      jnz  kbnobaseret
  702.      mov  edi,[TASK_BASE]
  703.      add  ecx,[edi+TASKDATA.mem_start]
  704.      mov  ebx,ecx
  705.      mov  eax,keymap
  706.      mov  ecx,128
  707.      call memmove
  708.      ret
  709.    kbnobaseret:
  710.      cmp  ebx,2
  711.      jnz  kbnoshiftret
  712.      mov  edi,[TASK_BASE]
  713.      add  ecx,[edi+TASKDATA.mem_start]
  714.      mov  ebx,ecx
  715.      mov  eax,keymap_shift
  716.      mov  ecx,128
  717.      call memmove
  718.      ret
  719.    kbnoshiftret:
  720.      cmp  ebx,3
  721.      jne  kbnoaltret
  722.      mov  edi,[TASK_BASE]
  723.      add  ecx,[edi+TASKDATA.mem_start]
  724.      mov  ebx,ecx
  725.      mov  eax,keymap_alt
  726.      mov  ecx,128
  727.      call memmove
  728.      ret
  729.    kbnoaltret:
  730.      cmp  ebx,9
  731.      jnz  ngsyse2
  732.      movzx eax,word [keyboard]
  733.      mov  [esp+36],eax
  734.      ret
  735.    ngsyse2:
  736.  
  737.      cmp  eax,3
  738.      jnz  ngsyse3
  739.      movzx eax,[cd_base]
  740.      mov  [esp+36],eax
  741.      ret
  742.    ngsyse3:
  743.  
  744.      cmp  eax,4
  745.      jne  ngsyse4
  746.      mov  eax,[sb16]
  747.      mov  [esp+36],eax
  748.      ret
  749.    ngsyse4:
  750.  
  751.      cmp  eax,5
  752.      jnz  ngsyse5
  753.      mov  eax,[syslang]
  754.      mov  [esp+36],eax
  755.      ret
  756.    ngsyse5:
  757.      cmp  eax,7
  758.      jnz  ngsyse7
  759.      movzx eax,[hd_base]
  760.      mov  [esp+36],eax
  761.      ret
  762.    ngsyse7:
  763.      cmp  eax,8
  764.      jnz  ngsyse8
  765.      mov eax,[fat32part]
  766.      mov  [esp+36],eax
  767.      ret
  768.    ngsyse8:
  769.      cmp  eax,9
  770.      jne  ngsyse9
  771.      mov  eax,[timer_ticks] ;[0xfdf0]
  772.      mov  [esp+36],eax
  773.      ret
  774.    ngsyse9:
  775.      cmp  eax,10
  776.      jnz  ngsyse10
  777.      mov eax,[sound_dma]
  778.      mov  [esp+36],eax
  779.      ret
  780.    ngsyse10:
  781.      cmp  eax,11
  782.      jnz  ngsyse11
  783.      mov eax,[lba_read_enabled]
  784.      mov  [esp+36],eax
  785.      ret
  786.    ngsyse11:
  787.      cmp  eax,12
  788.      jnz  ngsyse12
  789.      mov eax,[pci_access_enabled]
  790.      mov  [esp+36],eax
  791.      ret
  792.    ngsyse12:
  793.      mov  [esp+36],dword 1
  794.      ret
  795.  
  796. iglobal
  797. align 4
  798. mousefn dd msscreen, mswin, msbutton, msset
  799.         dd app_load_cursor
  800.         dd app_set_cursor
  801.         dd app_delete_cursor
  802. endg
  803.  
  804. readmousepos:
  805.  
  806. ; eax=0 screen relative
  807. ; eax=1 window relative
  808. ; eax=2 buttons pressed
  809. ; eax=3 set mouse pos   ; reserved
  810. ; eax=4 load cursor
  811. ; eax=5 set cursor
  812. ; eax=6 delete cursor   ; reserved
  813.  
  814.            cmp eax, 6
  815.            ja msset
  816.            jmp [mousefn+eax*4]
  817. msscreen:
  818.            mov  eax,[MOUSE_X]
  819.            shl  eax,16
  820.            mov  ax,[MOUSE_Y]
  821.            mov  [esp+36],eax
  822.            ret
  823. mswin:
  824.            mov  eax,[MOUSE_X]
  825.            shl  eax,16
  826.            mov  ax,[MOUSE_Y]
  827.            mov  esi,[TASK_BASE]
  828.            mov  bx, word [esi-twdw+WDATA.box.left]
  829.            shl  ebx,16
  830.            mov  bx, word [esi-twdw+WDATA.box.top]
  831.            sub  eax,ebx
  832.  
  833.            mov  edi,[CURRENT_TASK]
  834.            shl  edi,8
  835.            sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  836.            rol  eax,16
  837.            sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  838.            rol  eax,16
  839.            mov  [esp+36],eax
  840.            ret
  841. msbutton:
  842.            movzx eax,byte [BTN_DOWN]
  843.            mov  [esp+36],eax
  844.            ret
  845. msset:
  846.            ret
  847.  
  848. app_load_cursor:
  849.            add ebx, new_app_base
  850.            cmp ebx, new_app_base
  851.            jb msset
  852.            stdcall load_cursor, ebx, ecx
  853.            mov [esp+36], eax
  854.            ret
  855.  
  856. app_set_cursor:
  857.            stdcall set_cursor, ebx
  858.            mov [esp+36], eax
  859.            ret
  860.  
  861. app_delete_cursor:
  862.            stdcall delete_cursor, ebx
  863.            mov [esp+36], eax
  864.            ret
  865.  
  866. is_input:
  867.  
  868.    push edx
  869.    mov  dx,word [midisp]
  870.    in   al,dx
  871.    and  al,0x80
  872.    pop  edx
  873.    ret
  874.  
  875. is_output:
  876.  
  877.    push edx
  878.    mov  dx,word [midisp]
  879.    in   al,dx
  880.    and  al,0x40
  881.    pop  edx
  882.    ret
  883.  
  884.  
  885. get_mpu_in:
  886.  
  887.    push edx
  888.    mov  dx,word [mididp]
  889.    in   al,dx
  890.    pop  edx
  891.    ret
  892.  
  893.  
  894. put_mpu_out:
  895.  
  896.    push edx
  897.    mov  dx,word [mididp]
  898.    out  dx,al
  899.    pop  edx
  900.    ret
  901.  
  902.  
  903. setuart:
  904.  
  905.  su1:
  906.    call is_output
  907.    cmp  al,0
  908.    jnz  su1
  909.    mov  dx,word [midisp]
  910.    mov  al,0xff
  911.    out  dx,al
  912.  su2:
  913.    mov  dx,word [midisp]
  914.    mov  al,0xff
  915.    out  dx,al
  916.    call is_input
  917.    cmp  al,0
  918.    jnz  su2
  919.    call get_mpu_in
  920.    cmp  al,0xfe
  921.    jnz  su2
  922.  su3:
  923.    call is_output
  924.    cmp  al,0
  925.    jnz  su3
  926.    mov  dx,word [midisp]
  927.    mov  al,0x3f
  928.    out  dx,al
  929.  
  930.    ret
  931.  
  932.  
  933. align 4
  934.  
  935. sys_midi:
  936.  
  937.      cmp  [mididp],0
  938.      jnz  sm0
  939.      mov  [esp+36],dword 1
  940.      ret
  941.    sm0:
  942.  
  943.      cmp  eax,1
  944.      mov  [esp+36],dword 0
  945.      jnz  smn1
  946.      call setuart
  947.      ret
  948.    smn1:
  949.  
  950.      cmp  eax,2
  951.      jnz  smn2
  952.    sm10:
  953.      call get_mpu_in
  954.      call is_output
  955.      test al,al
  956.      jnz  sm10
  957.      mov  al,bl
  958.      call put_mpu_out
  959.      ret
  960.    smn2:
  961.  
  962.      ret
  963.  
  964.  
  965. detect_devices:
  966. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  967. include 'detect/commouse.inc'
  968. include 'detect/ps2mouse.inc'
  969. ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  970. ret
  971.  
  972.  
  973. sys_end:
  974.  
  975.      mov   eax,[TASK_BASE]
  976.      mov   [eax+TASKDATA.state], 3  ; terminate this program
  977.  
  978.     waitterm:            ; wait here for termination
  979.      mov   eax,5
  980.      call  delay_hs
  981.      jmp   waitterm
  982.  
  983. iglobal
  984. align 4
  985. sys_system_table:
  986.         dd      sysfn_shutdown          ; 1 = system shutdown
  987.         dd      sysfn_terminate         ; 2 = terminate thread
  988.         dd      sysfn_activate          ; 3 = activate window
  989.         dd      sysfn_getidletime       ; 4 = get idle time
  990.         dd      sysfn_getcpuclock       ; 5 = get cpu clock
  991.         dd      sysfn_saveramdisk       ; 6 = save ramdisk
  992.         dd      sysfn_getactive         ; 7 = get active window
  993.         dd      sysfn_sound_flag        ; 8 = get/set sound_flag
  994.         dd      sysfn_shutdown_param    ; 9 = shutdown with parameter
  995.         dd      sysfn_minimize          ; 10 = minimize window
  996.         dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
  997.         dd      sysfn_lastkey           ; 12 = get last pressed key
  998.         dd      sysfn_getversion        ; 13 = get kernel version
  999.         dd      sysfn_waitretrace       ; 14 = wait retrace
  1000.         dd      sysfn_centermouse       ; 15 = center mouse cursor
  1001.         dd      sysfn_getfreemem        ; 16 = get free memory size
  1002.         dd      sysfn_getallmem         ; 17 = get total memory size
  1003.         dd      sysfn_terminate2        ; 18 = terminate thread using PID
  1004.                                         ;                 instead of slot
  1005.         dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
  1006.         dd      sysfn_meminfo           ; 20 = get extended memory info
  1007. sysfn_num = ($ - sys_system_table)/4
  1008. endg
  1009.  
  1010. sys_system:
  1011.         dec     eax
  1012.         cmp     eax, sysfn_num
  1013.         jae     @f
  1014.         jmp     dword [sys_system_table + eax*4]
  1015. @@:
  1016.         ret
  1017.  
  1018. sysfn_shutdown:         ; 18.1 = BOOT
  1019.      mov  [0x2f0000+0x9030],byte 0
  1020.   for_shutdown_parameter:
  1021.  
  1022.      mov  eax,[TASK_COUNT]
  1023.      add  eax,2
  1024.      mov  [shutdown_processes],eax
  1025.      mov  [SYS_SHUTDOWN],al
  1026.      and  dword [esp+36], 0
  1027.      ret
  1028.   uglobal
  1029.    shutdown_processes: dd 0x0
  1030.   endg
  1031.  
  1032. sysfn_terminate:        ; 18.2 = TERMINATE
  1033.      cmp  ebx,2
  1034.      jb   noprocessterminate
  1035.      mov  edx,[TASK_COUNT]
  1036.      cmp  ebx,edx
  1037.      ja   noprocessterminate
  1038.      mov  eax,[TASK_COUNT]
  1039.      shl  ebx,5
  1040.      mov  edx,[ebx+CURRENT_TASK+TASKDATA.pid]
  1041.      add  ebx,CURRENT_TASK+TASKDATA.state
  1042.      cmp  byte [ebx], 9
  1043.      jz   noprocessterminate
  1044.  
  1045.      ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
  1046.      mov  [ebx],byte 3       ; clear possible i40's
  1047.      ;call MEM_Heap_UnLock
  1048.  
  1049.      cmp  edx,[application_table_status]    ; clear app table stat
  1050.      jne  noatsc
  1051.      mov  [application_table_status],0
  1052.    noatsc:
  1053.    noprocessterminate:
  1054.      ret
  1055.  
  1056. sysfn_terminate2:
  1057. ;lock application_table_status mutex
  1058. .table_status:
  1059.     cli
  1060.     cmp    [application_table_status],0
  1061.     je     .stf
  1062.     sti
  1063.     call   change_task
  1064.     jmp    .table_status
  1065. .stf:
  1066.     call   set_application_table_status
  1067.     mov    eax,ebx
  1068.     call   pid_to_slot
  1069.     test   eax,eax
  1070.     jz     .not_found
  1071.     mov    ebx,eax
  1072.     cli
  1073.     call   sysfn_terminate
  1074.     mov    [application_table_status],0
  1075.     sti
  1076.     and    dword [esp+36],0
  1077.     ret
  1078. .not_found:
  1079.     mov    [application_table_status],0
  1080.     or     dword [esp+36],-1
  1081.     ret
  1082.  
  1083. sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
  1084.      cmp  ebx,2
  1085.      jb   .nowindowactivate
  1086.      cmp  ebx,[TASK_COUNT]
  1087.      ja   .nowindowactivate
  1088.  
  1089.      mov   [window_minimize], 2   ; restore window if minimized
  1090.  
  1091.      movzx esi, word [WIN_STACK + ebx*2]
  1092.      cmp   esi, [TASK_COUNT]
  1093.      je    .nowindowactivate ; already active
  1094.  
  1095.      mov   edi, ebx
  1096.      shl   edi, 5
  1097.      add   edi, window_data
  1098.      movzx esi, word [WIN_STACK + ebx * 2]
  1099.      lea   esi, [WIN_POS + esi * 2]
  1100.      call  waredraw
  1101. .nowindowactivate:
  1102.      ret
  1103.  
  1104. sysfn_getidletime:              ; 18.4 = GET IDLETIME
  1105.      mov  eax,[idleusesec]
  1106.      mov  [esp+36], eax
  1107.      ret
  1108.  
  1109. sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
  1110.      mov  eax,[CPU_FREQ]
  1111.      mov  [esp+36], eax
  1112.      ret
  1113.  
  1114. ;  SAVE ramdisk to /hd/1/menuet.img
  1115. ;!!!!!!!!!!!!!!!!!!!!!!!!
  1116.    include 'blkdev/rdsave.inc'
  1117. ;!!!!!!!!!!!!!!!!!!!!!!!!
  1118.  
  1119. sysfn_getactive:        ; 18.7 = get active window
  1120.      mov  eax, [TASK_COUNT]
  1121.    movzx  eax, word [WIN_POS + eax*2]
  1122.      mov  [esp+36],eax
  1123.      ret
  1124.  
  1125. sysfn_sound_flag:       ; 18.8 = get/set sound_flag
  1126.      cmp  ebx,1
  1127.      jne  nogetsoundflag
  1128.      movzx  eax,byte [sound_flag] ; get sound_flag
  1129.      mov  [esp+36],eax
  1130.      ret
  1131.  nogetsoundflag:
  1132.      cmp  ebx,2
  1133.      jnz  nosoundflag
  1134.      xor  byte [sound_flag], 1
  1135.  nosoundflag:
  1136.      ret
  1137.  
  1138. sysfn_shutdown_param:   ; 18.9 = system shutdown with param
  1139.      cmp  ebx,1
  1140.      jl   exit_for_anyone
  1141.      cmp  ebx,4
  1142.      jg   exit_for_anyone
  1143.      mov  [0x2f0000+0x9030],bl
  1144.      jmp  for_shutdown_parameter
  1145.  
  1146. sysfn_minimize:         ; 18.10 = minimize window
  1147.      mov   [window_minimize],1
  1148.  exit_for_anyone:
  1149.      ret
  1150.  
  1151. sysfn_getdiskinfo:      ; 18.11 = get disk info table
  1152.      cmp  ebx,1
  1153.      jnz  full_table
  1154.   small_table:
  1155.      call for_all_tables
  1156.      mov ecx,10
  1157.      cld
  1158.      rep movsb
  1159.      ret
  1160.    for_all_tables:
  1161.      mov edi,[TASK_BASE]
  1162.      mov edi,[edi+TASKDATA.mem_start]
  1163.      add edi,ecx
  1164.      mov esi,DRIVE_DATA
  1165.      ret
  1166.   full_table:
  1167.      cmp  ebx,2
  1168.      jnz  exit_for_anyone
  1169.      call for_all_tables
  1170.      mov ecx,16384
  1171.      cld
  1172.      rep movsd
  1173.      ret
  1174.  
  1175. sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
  1176.         and     dword [esp+36], 0
  1177.         ret
  1178.  
  1179. sysfn_getversion:       ; 18.13 = get kernel ID and version
  1180.      mov edi,[TASK_BASE]
  1181.      mov edi,[edi+TASKDATA.mem_start]
  1182.      add edi,ebx
  1183.      mov esi,version_inf
  1184.      mov ecx,version_end-version_inf
  1185.      cld
  1186.      rep movsb
  1187.      ret
  1188.  
  1189. sysfn_waitretrace:     ; 18.14 = sys wait retrace
  1190.      ;wait retrace functions
  1191.  sys_wait_retrace:
  1192.      mov edx,0x3da
  1193.  WaitRetrace_loop:
  1194.      in al,dx
  1195.      test al,1000b
  1196.      jz WaitRetrace_loop
  1197.      mov [esp+36],dword 0
  1198.      ret
  1199.  
  1200. sysfn_centermouse:      ; 18.15 = mouse centered
  1201.      call  mouse_centered
  1202.      mov [esp+36],dword 0
  1203.      ret
  1204.  
  1205. sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
  1206.      cmp  ebx,0  ; get mouse speed factor
  1207.      jnz  .set_mouse_acceleration
  1208.      xor  eax,eax
  1209.      mov  ax,[mouse_speed_factor]
  1210.      mov  [esp+36],eax
  1211.      ret
  1212.  .set_mouse_acceleration:
  1213.      cmp  ebx,1  ; set mouse speed factor
  1214.      jnz  .get_mouse_delay
  1215.      mov  [mouse_speed_factor],cx
  1216.      ret
  1217.  .get_mouse_delay:
  1218.      cmp  ebx,2  ; get mouse delay
  1219.      jnz  .set_mouse_delay
  1220.      mov  eax,[mouse_delay]
  1221.      mov  [esp+36],eax
  1222.      ret
  1223.  .set_mouse_delay:
  1224.      cmp  ebx,3  ; set mouse delay
  1225.      jnz  .set_pointer_position
  1226.      mov  [mouse_delay],ecx
  1227.      ret
  1228.  .set_pointer_position:
  1229.      cmp  ebx,4  ; set mouse pointer position
  1230.      jnz  .end
  1231.      mov   [MOUSE_Y],cx    ;y
  1232.      ror   ecx,16
  1233.      mov   [MOUSE_X],cx    ;x
  1234.      rol   ecx,16
  1235.  .end:
  1236.      ret
  1237.  
  1238. sysfn_getfreemem:
  1239.      mov eax, [pg_data.pages_free]
  1240.      shl eax, 2
  1241.      mov [esp+36],eax
  1242.      ret
  1243.  
  1244. sysfn_getallmem:
  1245.      mov  eax,[MEM_AMOUNT]
  1246.      shr eax, 10
  1247.      mov  [esp+36],eax
  1248.      ret
  1249.  
  1250. uglobal
  1251. ;// mike.dld, 2006-29-01 [
  1252. screen_workarea RECT
  1253. ;// mike.dld, 2006-29-01 ]
  1254. window_minimize db 0
  1255. sound_flag      db 0
  1256. endg
  1257.  
  1258. iglobal
  1259. version_inf:
  1260.   db 0,6,5,0  ; version 0.6.5.0
  1261.   db UID_KOLIBRI
  1262.   db 'Kolibri',0
  1263. version_end:
  1264. endg
  1265.  
  1266. UID_NONE=0
  1267. UID_MENUETOS=1   ;official
  1268. UID_KOLIBRI=2    ;russian
  1269.  
  1270. sys_cachetodiskette:
  1271. ;    pushad
  1272. ;    cmp  eax,1
  1273. ;    jne  no_write_all_of_ramdisk
  1274. ;    call fdc_writeramdisk
  1275. ;    popad
  1276. ;    ret
  1277. ;  no_write_all_of_ramdisk:
  1278. ;    cmp eax,2
  1279. ;    jne no_write_part_of_ramdisk
  1280. ;    call fdc_commitflush
  1281. ;    popad
  1282. ;    ret
  1283. ;  no_write_part_of_ramdisk:
  1284. ;    cmp  eax,3
  1285. ;    jne  no_set_fdc
  1286. ;    call fdc_set
  1287. ;    popad
  1288. ;    ret
  1289. ;  no_set_fdc:
  1290. ;    cmp  eax,4
  1291. ;    jne  no_get_fdc
  1292. ;    popad
  1293. ;    call fdc_get
  1294. ;    mov    [esp+36],ecx
  1295. ;    ret
  1296. ;  no_get_fdc:
  1297. ;    popad
  1298. ;    ret
  1299.     cmp eax,1
  1300.     jne no_floppy_a_save
  1301.     mov   [flp_number],1
  1302.     jmp save_image_on_floppy
  1303.   no_floppy_a_save:
  1304.     cmp eax,2
  1305.     jne no_floppy_b_save
  1306.     mov   [flp_number],2
  1307.   save_image_on_floppy:
  1308.     call save_image
  1309.     mov  [esp+36],dword 0
  1310.     cmp  [FDC_Status],0
  1311.     je   yes_floppy_save
  1312.   no_floppy_b_save:
  1313.     mov [esp+36],dword 1
  1314.   yes_floppy_save:
  1315.     ret
  1316.  
  1317. uglobal
  1318. ;  bgrchanged  dd  0x0
  1319. endg
  1320.  
  1321. sys_background:
  1322.  
  1323.     cmp   eax,1                            ; BACKGROUND SIZE
  1324.     jnz   nosb1
  1325.     cmp   ebx,0
  1326.     je    sbgrr
  1327.     cmp   ecx,0
  1328.     je    sbgrr
  1329.     mov   [display_data-8],ebx
  1330.     mov   [display_data-4],ecx
  1331. ;    mov   [bgrchanged],1
  1332.   sbgrr:
  1333.     ret
  1334.   nosb1:
  1335.  
  1336.     cmp   eax,2                            ; SET PIXEL
  1337.     jnz   nosb2
  1338.     mov   edx,0x160000-16
  1339.     cmp   edx,ebx
  1340.     jbe   nosb2
  1341.     mov   edx,[ebx]
  1342.     and   edx,0xFF000000 ;255*256*256*256
  1343.     and   ecx,0x00FFFFFF ;255*256*256+255*256+255
  1344.     add   edx,ecx
  1345.     mov   [ebx+IMG_BACKGROUND],edx
  1346. ;    mov   [bgrchanged],1
  1347.     ret
  1348.   nosb2:
  1349.  
  1350.     cmp   eax,3                            ; DRAW BACKGROUND
  1351.     jnz   nosb3
  1352. draw_background_temp:
  1353. ;    cmp   [bgrchanged],1 ;0
  1354. ;    je    nosb31
  1355. ;draw_background_temp:
  1356. ;    mov   [bgrchanged],1 ;0
  1357.     mov   [REDRAW_BACKGROUND],byte 1
  1358.     mov    [background_defined], 1
  1359.    nosb31:
  1360.     ret
  1361.   nosb3:
  1362.  
  1363.     cmp   eax,4                            ; TILED / STRETCHED
  1364.     jnz   nosb4
  1365.     cmp   ebx,[display_data-12]
  1366.     je    nosb41
  1367.     mov   [display_data-12],ebx
  1368. ;    mov   [bgrchanged],1
  1369.    nosb41:
  1370.     ret
  1371.   nosb4:
  1372.  
  1373.     cmp   eax,5                            ; BLOCK MOVE TO BGR
  1374.     jnz   nosb5
  1375.   ; bughere
  1376.     mov   edi, [TASK_BASE]
  1377.     add   ebx, [edi+TASKDATA.mem_start]
  1378.  ;   mov   esi, ebx
  1379.  ;   mov   edi, ecx
  1380.     mov   eax, ebx
  1381.     mov   ebx, ecx
  1382.     add   ecx, edx
  1383.     cmp   ecx, 0x160000-16
  1384.     ja    .fin
  1385.  ;   add   edi, 0x300000
  1386.     add   ebx, IMG_BACKGROUND
  1387.     mov   ecx, edx
  1388.     cmp   ecx, 0x160000-16
  1389.     ja    .fin
  1390. ;    mov   [bgrchanged],1
  1391.   ;  cld
  1392.   ;  rep   movsb
  1393.     call  memmove
  1394.   .fin:
  1395.     ret
  1396.   nosb5:
  1397.  
  1398.     ret
  1399.  
  1400.  
  1401. align 4
  1402.  
  1403. sys_getbackground:
  1404.  
  1405.     cmp   eax,1                                  ; SIZE
  1406.     jnz   nogb1
  1407.     mov   eax,[display_data-8]
  1408.     shl   eax,16
  1409.     mov   ax,[display_data-4]
  1410.     mov   [esp+36],eax
  1411.     ret
  1412.   nogb1:
  1413.  
  1414.     cmp   eax,2                                  ; PIXEL
  1415.     jnz   nogb2
  1416.     mov   edx,0x160000-16
  1417.     cmp   edx,ebx
  1418.     jbe   nogb2
  1419.     mov   eax, [ebx+IMG_BACKGROUND]
  1420.     and   eax, 0xFFFFFF
  1421.     mov   [esp+36],eax
  1422.     ret
  1423.   nogb2:
  1424.  
  1425.     cmp   eax,4                                  ; TILED / STRETCHED
  1426.     jnz   nogb4
  1427.     mov   eax,[display_data-12]
  1428.   nogb4:
  1429.     mov   [esp+36],eax
  1430.     ret
  1431.  
  1432.  
  1433. align 4
  1434.  
  1435. sys_getkey:
  1436.     mov   [esp+36],dword 1
  1437. ; test main buffer
  1438.     mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
  1439.     movzx ecx,word [WIN_STACK + ebx * 2]
  1440.     mov   edx,[TASK_COUNT]
  1441.     cmp   ecx,edx
  1442.     jne   .finish
  1443.     cmp   [KEY_COUNT],byte 0
  1444.     je    .finish
  1445.     movzx eax,byte [KEY_BUFF]
  1446.     shl   eax,8
  1447.     push  eax
  1448.     dec   byte [KEY_COUNT]
  1449.     and   byte [KEY_COUNT],127
  1450.     movzx ecx,byte [KEY_COUNT]
  1451.     add   ecx,2
  1452.  ;   mov   esi,0xf402
  1453.  ;   mov   edi,0xf401
  1454.  ;   cld
  1455.  ;  rep   movsb
  1456.     mov   eax, KEY_BUFF+1
  1457.     mov   ebx, KEY_BUFF
  1458.     call  memmove
  1459.     pop   eax
  1460. .ret_eax:
  1461.     mov   [esp+36],eax
  1462.     ret
  1463.  .finish:
  1464. ; test hotkeys buffer
  1465.         mov     ecx, hotkey_buffer
  1466. @@:
  1467.         cmp     [ecx], ebx
  1468.         jz      .found
  1469.         add     ecx, 8
  1470.         cmp     ecx, hotkey_buffer+120*8
  1471.         jb      @b
  1472.         ret
  1473. .found:
  1474.         mov     ax, [ecx+6]
  1475.         shl     eax, 16
  1476.         mov     ah, [ecx+4]
  1477.         mov     al, 2
  1478.         and     dword [ecx+4], 0
  1479.         and     dword [ecx], 0
  1480.         jmp     .ret_eax
  1481.  
  1482. align 4
  1483.  
  1484. sys_getbutton:
  1485.  
  1486.     mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
  1487.     mov   [esp+36],dword 1
  1488.     movzx ecx, word [WIN_STACK + ebx * 2]
  1489.     mov   edx, [TASK_COUNT] ; less than 256 processes
  1490.     cmp   ecx,edx
  1491.     jne   .exit
  1492.     movzx eax,byte [BTN_COUNT]
  1493.     test  eax,eax
  1494.     jz    .exit
  1495.     mov   eax,[BTN_BUFF]
  1496.     shl   eax,8
  1497.     mov   [BTN_COUNT],byte 0
  1498.     mov   [esp+36],eax
  1499.  .exit:
  1500.     ret
  1501.  
  1502.  
  1503. align 4
  1504.  
  1505. sys_cpuusage:
  1506.  
  1507. ;  RETURN:
  1508. ;
  1509. ;  +00 dword     process cpu usage
  1510. ;  +04  word     position in windowing stack
  1511. ;  +06  word     windowing stack value at current position (cpu nro)
  1512. ;  +10 12 bytes  name
  1513. ;  +22 dword     start in mem
  1514. ;  +26 dword     used mem
  1515. ;  +30 dword     PID , process idenfification number
  1516. ;
  1517.  
  1518.     mov  edi,[TASK_BASE]   ; eax = return area
  1519.     add  eax,[edi + TASKDATA.mem_start]
  1520.  
  1521.     cmp  ebx,-1         ; who am I ?
  1522.     jne  no_who_am_i
  1523.     mov  ebx,[CURRENT_TASK]
  1524.   no_who_am_i:
  1525.  
  1526.     push eax            ; return area
  1527.     push ebx            ; process number
  1528.  
  1529.     push ebx
  1530.     push ebx
  1531.     push eax
  1532.  
  1533.     ; return memory usage
  1534.  
  1535.     xor  edx,edx
  1536.     mov  eax,0x20
  1537.     mul  ebx
  1538.     add  eax,CURRENT_TASK+TASKDATA.cpu_usage
  1539.     mov  ebx,eax
  1540.     pop  eax
  1541.     mov  ecx,[ebx]
  1542.     mov  [eax],ecx
  1543.     pop  ebx
  1544.     mov  cx, [WIN_STACK + ebx * 2]
  1545.     mov  [eax+4],cx
  1546.     mov  cx, [WIN_POS + ebx * 2]
  1547.     mov  [eax+6],cx
  1548.     push eax
  1549.     mov  eax,ebx
  1550.     shl  eax,8
  1551.     add  eax,SLOT_BASE+APPDATA.app_name
  1552.     pop  ebx
  1553.     add  ebx,10
  1554.     mov  ecx,11
  1555.     call memmove
  1556.  
  1557.     ; memory usage
  1558.  
  1559.     xor    eax,eax
  1560.     mov    edx,0x100000*16
  1561.     pop    ecx                                   ; get gdt of tss
  1562.     cmp    ecx,1
  1563.     je     os_mem
  1564.     shl    ecx,8
  1565.     mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
  1566.     mov    eax,std_application_base_address
  1567.     ; eax run base -> edx used memory
  1568.   os_mem:
  1569.     dec    edx
  1570.     mov    [ebx+12],eax
  1571.     mov    [ebx+16],edx
  1572.  
  1573.     ; PID (+30)
  1574.  
  1575.     mov    eax,[esp]
  1576.     shl    eax,5
  1577.     add    eax,CURRENT_TASK+TASKDATA.pid
  1578.     mov    eax,[eax]
  1579.     mov    [ebx+20],eax
  1580.  
  1581.     ; window position and size
  1582.  
  1583.     mov    esi,[esp]
  1584.     shl    esi,5
  1585.     add    esi,window_data + WDATA.box
  1586.     mov    edi,[esp+4]
  1587.     add    edi,34
  1588.     mov    ecx,4
  1589.     cld
  1590.     rep    movsd
  1591.  
  1592.     ; Process state (+50)
  1593.  
  1594.     mov    eax,[esp]
  1595.     shl    eax,5
  1596.     add    eax,CURRENT_TASK+TASKDATA.state
  1597.     mov    eax,[eax]
  1598.     mov    [ebx+40],ax
  1599.  
  1600.     ; Window client area box
  1601.  
  1602.     mov    esi,[esp]
  1603.     shl    esi,8
  1604.     add    esi,SLOT_BASE+APPDATA.wnd_clientbox
  1605.     lea    edi,[ebx+44]
  1606.     mov    ecx,4
  1607.     rep    movsd
  1608.  
  1609.     ; Window state
  1610.  
  1611.     mov    esi,[esp]
  1612.     shl    esi,5
  1613.     add    esi,window_data + WDATA.box
  1614.     mov    al,[esi+window_data+WDATA.fl_wstate]
  1615.     mov    [edi],al
  1616.  
  1617.     pop    ebx
  1618.     pop    eax
  1619.  
  1620.     ; return number of processes
  1621.  
  1622.     mov    eax,[TASK_COUNT]
  1623.     mov    [esp+36],eax
  1624.     ret
  1625.  
  1626.  
  1627.  
  1628.  
  1629. align 4
  1630. sys_clock:
  1631.         cli
  1632.   ; Mikhail Lisovin  xx Jan 2005
  1633.   @@:   mov   al, 10
  1634.         out   0x70, al
  1635.         in    al, 0x71
  1636.         test  al, al
  1637.         jns   @f
  1638.         mov   esi, 1
  1639.         call  delay_ms
  1640.         jmp   @b
  1641.   @@:
  1642.   ; end Lisovin's fix
  1643.  
  1644.         xor   al,al           ; seconds
  1645.         out   0x70,al
  1646.         in    al,0x71
  1647.         movzx ecx,al
  1648.         mov   al,02           ; minutes
  1649.         shl   ecx,16
  1650.         out   0x70,al
  1651.         in    al,0x71
  1652.         movzx edx,al
  1653.         mov   al,04           ; hours
  1654.         shl   edx,8
  1655.         out   0x70,al
  1656.         in    al,0x71
  1657.         add   ecx,edx
  1658.         movzx edx,al
  1659.         add   ecx,edx
  1660.         sti
  1661.         mov   [esp+36],ecx
  1662.         ret
  1663.  
  1664.  
  1665. align 4
  1666.  
  1667. sys_date:
  1668.  
  1669.         cli
  1670.  
  1671.   @@:   mov   al, 10
  1672.         out   0x70, al
  1673.         in    al, 0x71
  1674.         test  al, al
  1675.         jns   @f
  1676.         mov   esi, 1
  1677.         call  delay_ms
  1678.         jmp   @b
  1679.   @@:
  1680.  
  1681.         mov     ch,0
  1682.         mov     al,7            ; date
  1683.         out     0x70,al
  1684.         in      al,0x71
  1685.         mov     cl,al
  1686.         mov     al,8            ; month
  1687.         shl     ecx,16
  1688.         out     0x70,al
  1689.         in      al,0x71
  1690.         mov     ch,al
  1691.         mov     al,9            ; year
  1692.         out     0x70,al
  1693.         in      al,0x71
  1694.         mov     cl,al
  1695.         sti
  1696.         mov     [esp+36],ecx
  1697.         ret
  1698.  
  1699.  
  1700. ; redraw status
  1701.  
  1702. sys_redrawstat:
  1703.  
  1704.     cmp  eax,1
  1705.     jne  no_widgets_away
  1706.  
  1707.     ; buttons away
  1708.  
  1709.     mov   ecx,[CURRENT_TASK]
  1710.  
  1711.   sys_newba2:
  1712.  
  1713.     mov   edi,[BTN_ADDR]
  1714.     cmp   [edi],dword 0  ; empty button list ?
  1715.     je    end_of_buttons_away
  1716.  
  1717.     movzx ebx,word [edi]
  1718.     inc   ebx
  1719.  
  1720.     mov   eax,edi
  1721.  
  1722.   sys_newba:
  1723.  
  1724.     dec   ebx
  1725.     jz    end_of_buttons_away
  1726.  
  1727.     add   eax,0x10
  1728.     cmp   cx,[eax]
  1729.     jnz   sys_newba
  1730.  
  1731.     push  eax ebx ecx
  1732.     mov   ecx,ebx
  1733.     inc   ecx
  1734.     shl   ecx,4
  1735.     mov   ebx,eax
  1736.     add   eax,0x10
  1737.     call  memmove
  1738.     dec   dword [edi]
  1739.     pop   ecx ebx eax
  1740.  
  1741.     jmp   sys_newba2
  1742.  
  1743.   end_of_buttons_away:
  1744.  
  1745.     ret
  1746.  
  1747.   no_widgets_away:
  1748.  
  1749.     cmp   eax,2
  1750.     jnz   srl1
  1751.  
  1752.     mov   edx,[TASK_BASE]      ; return whole screen draw area for this app
  1753.     add   edx,draw_data-CURRENT_TASK
  1754.     mov   [edx+RECT.left], 0
  1755.     mov   [edx+RECT.top], 0
  1756.     mov   eax,[ScreenWidth]
  1757.     mov   [edx+RECT.right],eax
  1758.     mov   eax,[ScreenHeight]
  1759.     mov   [edx+RECT.bottom],eax
  1760.  
  1761.     mov   edi,[TASK_BASE]
  1762.     or    [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
  1763.  
  1764.     call  sys_window_mouse
  1765.  
  1766.     ret
  1767.  
  1768.   srl1:
  1769.  
  1770.     ret
  1771.  
  1772.  
  1773. sys_drawwindow:
  1774.  
  1775.     mov   edi,ecx
  1776.     shr   edi,16+8
  1777.     and   edi,15
  1778.  
  1779.     cmp   edi,0   ; type I    - original style
  1780.     jne   nosyswI
  1781.     inc   [mouse_pause]
  1782.     call  [disable_mouse]
  1783.     call  sys_set_window
  1784.     call  [disable_mouse]
  1785.     call  drawwindow_I
  1786.     ;dec   [mouse_pause]
  1787.     ;call   [draw_pointer]
  1788.     ;ret
  1789.     jmp   draw_window_caption.2
  1790.   nosyswI:
  1791.  
  1792.     cmp   edi,1   ; type II   - only reserve area, no draw
  1793.     jne   nosyswII
  1794.     inc   [mouse_pause]
  1795.     call  [disable_mouse]
  1796.     call  sys_set_window
  1797.     call  [disable_mouse]
  1798.     call  sys_window_mouse
  1799.     dec   [mouse_pause]
  1800.     call   [draw_pointer]
  1801.     ret
  1802.   nosyswII:
  1803.  
  1804.     cmp   edi,2   ; type III  - new style
  1805.     jne   nosyswIII
  1806.     inc   [mouse_pause]
  1807.     call  [disable_mouse]
  1808.     call  sys_set_window
  1809.     call  [disable_mouse]
  1810.     call  drawwindow_III
  1811.     ;dec   [mouse_pause]
  1812.     ;call   [draw_pointer]
  1813.     ;ret
  1814.     jmp   draw_window_caption.2
  1815.   nosyswIII:
  1816.  
  1817.     cmp   edi,3   ; type IV - skinned window
  1818.     jne   nosyswIV
  1819.  
  1820.     ; parameter for drawwindow_IV
  1821.     push  0
  1822.     mov   edi, [TASK_COUNT]
  1823.     movzx edi, word [WIN_POS + edi*2]
  1824.     cmp   edi, [CURRENT_TASK]
  1825.     jne   @f
  1826.     inc   dword [esp]
  1827.  @@:
  1828.  
  1829.     inc   [mouse_pause]
  1830.     call  [disable_mouse]
  1831.     call  sys_set_window
  1832.     call  [disable_mouse]
  1833.     call  drawwindow_IV
  1834.     ;dec   [mouse_pause]
  1835.     ;call   [draw_pointer]
  1836.     ;ret
  1837.     jmp   draw_window_caption.2
  1838.   nosyswIV:
  1839.  
  1840.     ret
  1841.  
  1842.  
  1843. draw_window_caption:
  1844.         inc     [mouse_pause]
  1845.         call    [disable_mouse]
  1846.  
  1847.         xor     eax,eax
  1848.         mov     edx,[TASK_COUNT]
  1849.         movzx   edx,word[WIN_POS+edx*2]
  1850.         cmp     edx,[CURRENT_TASK]
  1851.         jne     @f
  1852.         inc     eax
  1853.     @@: mov     edx,[CURRENT_TASK]
  1854.         shl     edx,5
  1855.         add     edx,window_data
  1856.         movzx   ebx,[edx+WDATA.fl_wstyle]
  1857.         and     bl,0x0F
  1858.         cmp     bl,3
  1859.         jne     .not_style_3
  1860.  
  1861.         push    edx
  1862.         call    drawwindow_IV_caption
  1863.         add     esp,4
  1864.         jmp     .2
  1865.  
  1866.   .not_style_3:
  1867.         cmp     bl,2
  1868.         jne     .not_style_2
  1869.  
  1870.         call    drawwindow_III_caption
  1871.         jmp     .2
  1872.  
  1873.   .not_style_2:
  1874.         cmp     bl,0
  1875.         jne     .2
  1876.  
  1877.         call    drawwindow_I_caption
  1878.  
  1879. ;--------------------------------------------------------------
  1880.   .2:   ;jmp     @f
  1881.         mov     edi,[CURRENT_TASK]
  1882.         shl     edi,5
  1883.         test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
  1884.         jz      @f
  1885.         mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
  1886.         or      ecx,ecx
  1887.         jz      @f
  1888.         add     ecx,[edi+twdw+TASKDATA.mem_start]
  1889.  
  1890.         movzx   eax,[edi+window_data+WDATA.fl_wstyle]
  1891.         and     al,0x0F
  1892.         cmp     al,3
  1893.         jne     .not_skinned
  1894.  
  1895.         mov     ebp,[edi+window_data+WDATA.box.left-2]
  1896.         mov     bp,word[edi+window_data+WDATA.box.top]
  1897.         movzx   eax,word[edi+window_data+WDATA.box.width]
  1898.         sub     ax,[_skinmargins.left]
  1899.         sub     ax,[_skinmargins.right]
  1900.         cwde
  1901.         cdq
  1902.         mov     ebx,6
  1903.         idiv    ebx
  1904.         or      eax,eax
  1905.         js      @f
  1906.         mov     edx,eax
  1907.         mov     eax,dword[_skinmargins.left-2]
  1908.         mov     ax,word[_skinh]
  1909.         sub     ax,[_skinmargins.bottom]
  1910.         sub     ax,[_skinmargins.top]
  1911.         sar     ax,1
  1912.         adc     ax,0
  1913.         add     ax,[_skinmargins.top]
  1914.         add     ax,-3
  1915.         add     eax,ebp
  1916.         jmp     .dodraw
  1917.  
  1918.   .not_skinned:
  1919.         cmp     al,1
  1920.         je      @f
  1921.  
  1922.         mov     ebp,[edi+window_data+WDATA.box.left-2]
  1923.         mov     bp,word[edi+window_data+WDATA.box.top]
  1924.         movzx   eax,word[edi+window_data+WDATA.box.width]
  1925.         sub     eax,16
  1926.         cwde
  1927.         cdq
  1928.         mov     ebx,6
  1929.         idiv    ebx
  1930.         or      eax,eax
  1931.         js      @f
  1932.         mov     edx,eax
  1933.         mov     eax,0x00080007
  1934.         add     eax,ebp
  1935. .dodraw:
  1936.         mov     ebx,[common_colours+16];0x00FFFFFF
  1937.         or      ebx, 0x80000000
  1938.         xor     edi,edi
  1939.         call    dtext
  1940.  
  1941.     @@:
  1942. ;--------------------------------------------------------------
  1943.         dec     [mouse_pause]
  1944.         call    [draw_pointer]
  1945.         ret
  1946.  
  1947. iglobal
  1948. align 4
  1949. window_topleft dd \
  1950.   1, 21,\
  1951.   0,  0,\
  1952.   5, 20,\
  1953.   5,  ?
  1954. endg
  1955.  
  1956. set_window_clientbox:
  1957.         push    eax ecx edi
  1958.  
  1959.         mov     eax,[_skinh]
  1960.         mov     [window_topleft+4*7],eax
  1961.  
  1962.         mov     ecx,edi
  1963.         sub     edi,window_data
  1964.         shl     edi,3
  1965.         test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
  1966.         jz      @f
  1967.  
  1968.         movzx   eax,[ecx+WDATA.fl_wstyle]
  1969.         and     eax,0x0F
  1970.         mov     eax,[eax*8+window_topleft+0]
  1971.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
  1972.         shl     eax,1
  1973.         neg     eax
  1974.         add     eax,[ecx+WDATA.box.width]
  1975.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
  1976.  
  1977.         movzx   eax,[ecx+WDATA.fl_wstyle]
  1978.         and     eax,0x0F
  1979.         push    [eax*8+window_topleft+0]
  1980.         mov     eax,[eax*8+window_topleft+4]
  1981.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
  1982.         neg     eax
  1983.         sub     eax,[esp]
  1984.         add     eax,[ecx+WDATA.box.height]
  1985.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
  1986.         add     esp,4
  1987.  
  1988.         pop     edi ecx eax
  1989.         ret
  1990.     @@:
  1991.         xor     eax,eax
  1992.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
  1993.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
  1994.         mov     eax,[ecx+WDATA.box.width]
  1995.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
  1996.         mov     eax,[ecx+WDATA.box.height]
  1997.         mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
  1998.  
  1999.         pop     edi ecx eax
  2000.         ret
  2001.  
  2002. sys_set_window:
  2003.  
  2004.     mov   edi,[CURRENT_TASK]
  2005.     shl   edi,5
  2006.     add   edi,window_data
  2007.  
  2008.     ; colors
  2009.     mov   [edi+WDATA.cl_workarea],ecx
  2010.     mov   [edi+WDATA.cl_titlebar],edx
  2011.     mov   [edi+WDATA.cl_frames],esi
  2012.  
  2013.     ; check flag (?)
  2014.     test  [edi+WDATA.fl_wdrawn],1
  2015.     jnz   newd
  2016.  
  2017.     push  eax
  2018.     mov   eax,[timer_ticks] ;[0xfdf0]
  2019.     add   eax,100
  2020.     mov   [new_window_starting],eax
  2021.     pop   eax
  2022.  
  2023.     mov   word[edi+WDATA.box.width],ax
  2024.     mov   word[edi+WDATA.box.height],bx
  2025.     sar   eax,16
  2026.     sar   ebx,16
  2027.     mov   word[edi+WDATA.box.left],ax
  2028.     mov   word[edi+WDATA.box.top],bx
  2029.  
  2030.     call  check_window_position
  2031.  
  2032.     call  set_window_clientbox
  2033.  
  2034.     push  ecx esi edi               ; save for window fullscreen/resize
  2035.     ;mov   esi,edi
  2036.  
  2037.         mov     cl,[edi+WDATA.fl_wstyle]
  2038.  
  2039.     sub   edi,window_data
  2040.     shl   edi,3
  2041.     add   edi,SLOT_BASE
  2042.  
  2043.         and     cl,0x0F
  2044.         mov     [edi+APPDATA.wnd_caption],0
  2045.         cmp     cl,3
  2046.         jne     @f
  2047.         mov     [edi+APPDATA.wnd_caption],esi
  2048.     @@: mov     esi,[esp+0]
  2049.  
  2050.     add   edi, APPDATA.saved_box
  2051.         movsd
  2052.         movsd
  2053.         movsd
  2054.         movsd
  2055.     pop   edi esi ecx
  2056.  
  2057.     push  eax ebx ecx edx
  2058. ;;;    mov   eax, 1
  2059. ;;;    call  delay_hs
  2060.     mov   eax, [edi+WDATA.box.left]
  2061.     mov   ebx, [edi+WDATA.box.top]
  2062.     mov   ecx, [edi+WDATA.box.width]
  2063.     mov   edx, [edi+WDATA.box.height]
  2064.     add   ecx, eax
  2065.     add   edx, ebx
  2066.     call  calculatescreen
  2067.     pop   edx ecx ebx eax
  2068.  
  2069.     mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
  2070.     mov   [BTN_COUNT],byte 0           ; empty button buffer
  2071.  
  2072.   newd:
  2073.     mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
  2074.     mov   edx,edi
  2075.  
  2076.     ret
  2077.  
  2078. syscall_windowsettings:
  2079.  
  2080.   .set_window_caption:
  2081.         dec     eax     ; subfunction #1 - set window caption
  2082.         jnz     .get_window_caption
  2083.  
  2084.         ; NOTE: only window owner thread can set its caption,
  2085.         ;       so there's no parameter for PID/TID
  2086.  
  2087.         mov     edi,[CURRENT_TASK]
  2088.         shl     edi,5
  2089.  
  2090.         ; have to check if caption is within application memory limit
  2091.         ; check is trivial, and if application resizes its memory,
  2092.         ;   caption still can become over bounds
  2093. ; diamond, 31.10.2006: check removed because with new memory manager
  2094. ; there can be valid data after APPDATA.mem_size bound
  2095. ;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
  2096. ;        add     ecx,255 ; max caption length
  2097. ;        cmp     ebx,ecx
  2098. ;        ja      .exit_fail
  2099.  
  2100.         mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
  2101.         or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
  2102.  
  2103.         call    draw_window_caption
  2104.  
  2105.         xor     eax,eax ; eax = 0 (success)
  2106.         ret
  2107.  
  2108.   .get_window_caption:
  2109.         dec     eax     ; subfunction #2 - get window caption
  2110.         jnz     .exit_fail
  2111.  
  2112.         ; not implemented yet
  2113.  
  2114.   .exit_fail:
  2115.         xor     eax,eax
  2116.         inc     eax     ; eax = 1 (fail)
  2117.         ret
  2118.  
  2119.  
  2120. sys_window_move:
  2121.  
  2122.         mov     edi,[CURRENT_TASK]
  2123.         shl     edi,5
  2124.         add     edi,window_data
  2125.  
  2126.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  2127.         jnz     .window_move_return
  2128.  
  2129.         push    dword [edi + WDATA.box.left]  ; save old coordinates
  2130.         push    dword [edi + WDATA.box.top]
  2131.         push    dword [edi + WDATA.box.width]
  2132.         push    dword [edi + WDATA.box.height]
  2133.  
  2134.         cmp   eax,-1                  ; set new position and size
  2135.         je    .no_x_reposition
  2136.         mov     [edi + WDATA.box.left], eax
  2137.       .no_x_reposition:
  2138.         cmp   ebx,-1
  2139.         je    .no_y_reposition
  2140.         mov     [edi + WDATA.box.top], ebx
  2141.       .no_y_reposition:
  2142.  
  2143.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  2144.         jnz     .no_y_resizing
  2145.  
  2146.         cmp   ecx,-1
  2147.         je    .no_x_resizing
  2148.         mov     [edi + WDATA.box.width], ecx
  2149.       .no_x_resizing:
  2150.         cmp   edx,-1
  2151.         je    .no_y_resizing
  2152.         mov     [edi + WDATA.box.height], edx
  2153.       .no_y_resizing:
  2154.  
  2155.         call  check_window_position
  2156.         call  set_window_clientbox
  2157.  
  2158.         pushad                       ; save for window fullscreen/resize
  2159.         mov   esi,edi
  2160.         sub   edi,window_data
  2161.         shr   edi,5
  2162.         shl   edi,8
  2163.         add   edi, SLOT_BASE + APPDATA.saved_box
  2164.         mov   ecx,4
  2165.         cld
  2166.         rep   movsd
  2167.         popad
  2168.  
  2169.         pushad                       ; calculcate screen at new position
  2170.         mov   eax, [edi + WDATA.box.left]
  2171.         mov   ebx, [edi + WDATA.box.top]
  2172.         mov   ecx, [edi + WDATA.box.width]
  2173.         mov   edx, [edi + WDATA.box.height]
  2174.         add   ecx,eax
  2175.         add   edx,ebx
  2176.  
  2177.         call  calculatescreen
  2178.         popad
  2179.  
  2180.         pop   edx                   ; calculcate screen at old position
  2181.         pop   ecx
  2182.         pop   ebx
  2183.         pop   eax
  2184.         add   ecx,eax
  2185.         add   edx,ebx
  2186.         mov   [dlx],eax             ; save for drawlimits
  2187.         mov   [dly],ebx
  2188.         mov   [dlxe],ecx
  2189.         mov   [dlye],edx
  2190.         call  calculatescreen
  2191.  
  2192.         mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
  2193.  
  2194.         mov   eax,edi               ; redraw screen at old position
  2195.         xor   esi,esi
  2196.         call  redrawscreen
  2197.  
  2198.         mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
  2199.         mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
  2200.         mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
  2201.  
  2202.         mov   ecx,10          ; wait 1/10 second
  2203.       .wmrl3:
  2204.         call  [draw_pointer]
  2205.         mov   eax,1
  2206.         call  delay_hs
  2207.         loop  .wmrl3
  2208.  
  2209.         mov   [window_move_pr],0
  2210.  
  2211.       .window_move_return:
  2212.  
  2213.         ret
  2214.  
  2215. ;type_background_1:
  2216. ;    cmp   [0xfff0],byte 0               ; background update ?
  2217. ;    jz    temp_nobackgr
  2218. ;    mov   [0xfff0],byte 2
  2219. ;    call  change_task
  2220. ;    mov   [draw_data+32+0],dword 0
  2221. ;    mov   [draw_data+32+4],dword 0
  2222. ;    mov   eax,[ScreenWidth
  2223. ;    mov   ebx,[0xfe04]
  2224. ;    mov   [draw_data+32+8],eax
  2225. ;    mov   [draw_data+32+12],ebx
  2226. ;    call  drawbackground
  2227. ;    mov   [0xfff0],byte 0
  2228. ;    mov   [MOUSE_BACKGROUND],byte 0
  2229. ;temp_nobackgr:
  2230. ;    ret
  2231.  
  2232. uglobal
  2233.   window_move_pr   dd  0x0
  2234.   window_move_eax  dd  0x0
  2235.   window_move_ebx  dd  0x0
  2236.   window_move_ecx  dd  0x0
  2237.   window_move_edx  dd  0x0
  2238. endg
  2239.  
  2240. ;ok - 100% work
  2241. ;nt - not tested
  2242. ;---------------------------------------------------------------------------------------------
  2243. ;eax
  2244. ;0 - task switch counter. Ret switch counter in eax. Block. ok.
  2245. ;1 - change task. Ret nothing. Block. ok.
  2246. ;2 - performance control
  2247. ; ebx
  2248. ; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
  2249. ; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
  2250. ; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
  2251. ; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
  2252. ; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
  2253. ;eax
  2254. ;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  2255. ;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
  2256. ;---------------------------------------------------------------------------------------------
  2257. sys_sheduler: ;noname & halyavin
  2258.     cmp eax,0
  2259.     je shed_counter
  2260.     cmp eax,2
  2261.     je perf_control
  2262.     cmp eax,3
  2263.     je rdmsr_instr
  2264.     cmp eax,4
  2265.     je wrmsr_instr
  2266.     cmp eax,1
  2267.     jne not_supported
  2268.     call change_task ;delay,0
  2269. ret
  2270. shed_counter:
  2271.     mov eax,[context_counter]
  2272.     mov [esp+36],eax
  2273. not_supported:
  2274. ret
  2275. perf_control:
  2276.     inc eax ;now eax=3
  2277.     cmp ebx,eax
  2278.     je cache_disable
  2279.     dec eax
  2280.     cmp ebx,eax
  2281.     je cache_enable
  2282.     dec eax
  2283.     cmp ebx,eax
  2284.     je is_cache_enabled
  2285.     dec eax
  2286.     cmp ebx,eax
  2287.     je modify_pce
  2288. ret
  2289.  
  2290. rdmsr_instr:
  2291. ;now counter in ecx
  2292. ;(edx:eax) esi:edi => edx:esi
  2293. mov eax,esi
  2294. rdmsr
  2295. mov [esp+36],eax
  2296. mov [esp+24],edx ;ret in ebx?
  2297. ret
  2298.  
  2299. wrmsr_instr:
  2300. ;now counter in ecx
  2301. ;(edx:eax) esi:edi => edx:esi
  2302. mov eax,esi
  2303. wrmsr
  2304. mov [esp+36],eax
  2305. mov [esp+24],edx ;ret in ebx?
  2306. ret
  2307.  
  2308. cache_disable:
  2309.        mov eax,cr0
  2310.        or  eax,01100000000000000000000000000000b
  2311.        mov cr0,eax
  2312.        wbinvd ;set MESI
  2313. ret
  2314.  
  2315. cache_enable:
  2316.        mov eax,cr0
  2317.        and eax,10011111111111111111111111111111b
  2318.        mov cr0,eax
  2319. ret
  2320.  
  2321. is_cache_enabled:
  2322.        mov eax,cr0
  2323.        mov ebx,eax
  2324.        and eax,01100000000000000000000000000000b
  2325.        jz cache_disabled
  2326.        mov [esp+36],ebx
  2327. cache_disabled:
  2328.        mov dword [esp+36],eax ;0
  2329. ret
  2330.  
  2331. modify_pce:
  2332.        mov eax,cr4
  2333. ;       mov ebx,0
  2334. ;       or  bx,100000000b ;pce
  2335. ;       xor eax,ebx ;invert pce
  2336.        bts eax,8 ;pce=cr4[8]
  2337.        mov cr4,eax
  2338.        mov [esp+36],eax
  2339. ret
  2340. ;---------------------------------------------------------------------------------------------
  2341.  
  2342.  
  2343. ; check if pixel is allowed to be drawn
  2344.  
  2345. checkpixel:
  2346.         push eax edx
  2347.  
  2348.         mov  edx,[ScreenWidth]     ; screen x size
  2349.         inc  edx
  2350.         imul edx, ebx
  2351.         mov  dl, [eax+edx+display_data] ; lea eax, [...]
  2352.  
  2353.         xor  ecx, ecx
  2354.         mov  eax, [CURRENT_TASK]
  2355.         cmp  al, dl
  2356.         setne cl
  2357.  
  2358.         pop  edx eax
  2359.         ret
  2360.  
  2361. uglobal
  2362.   mouse_active  db  0
  2363. endg
  2364. iglobal
  2365.   cpustring db '/hd0/1/kolibri/bin/CPU',0
  2366. endg
  2367.  
  2368. uglobal
  2369. background_defined    db    0    ; diamond, 11.04.2006
  2370. endg
  2371.  
  2372. align 4
  2373. ; check misc
  2374.  
  2375. checkmisc:
  2376.  
  2377.     cmp   [ctrl_alt_del], 1
  2378.     jne   nocpustart
  2379.     mov   ebp, cpustring
  2380.     call   fs_execute               ; SPraid 8.03.2007
  2381.     ;lea   esi,[ebp+6]
  2382.     ;xor   ebx,ebx               ; no parameters
  2383.     ;xor   edx,edx               ; no flags
  2384.     ;call  fs_RamdiskExecute.flags
  2385.     mov   [ctrl_alt_del], 0
  2386.   nocpustart:
  2387.     cmp   [mouse_active], 1
  2388.     jne   mouse_not_active
  2389.     mov   [mouse_active], 0
  2390.     xor   edi, edi
  2391.     mov   ecx, [TASK_COUNT]
  2392.    set_mouse_event:
  2393.     add   edi, 256
  2394.     or    [edi+SLOT_BASE+APPDATA.event_mask], dword 00100000b
  2395.     loop  set_mouse_event
  2396.   mouse_not_active:
  2397.  
  2398.  
  2399.     cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
  2400.     jz    nobackgr
  2401.     cmp    [background_defined], 0
  2402.     jz    nobackgr
  2403.     mov   [REDRAW_BACKGROUND],byte 2
  2404.     call  change_task
  2405.         mov   [draw_data+32 + RECT.left],dword 0
  2406.         mov   [draw_data+32 + RECT.top],dword 0
  2407.     mov   eax,[ScreenWidth]
  2408.     mov   ebx,[ScreenHeight]
  2409.         mov   [draw_data+32 + RECT.right],eax
  2410.         mov   [draw_data+32 + RECT.bottom],ebx
  2411.     call  drawbackground
  2412.     mov   [REDRAW_BACKGROUND],byte 0
  2413.     mov   [MOUSE_BACKGROUND],byte 0
  2414.  
  2415.   nobackgr:
  2416.  
  2417.  
  2418.     ; system shutdown request
  2419.  
  2420.     cmp  [SYS_SHUTDOWN],byte 0
  2421.     je   noshutdown
  2422.  
  2423.     mov  edx,[shutdown_processes]
  2424.     sub  dl,2
  2425.  
  2426.     cmp  [SYS_SHUTDOWN],dl
  2427.     jne  no_mark_system_shutdown
  2428.  
  2429.     mov   edx,0x3040
  2430.     movzx ecx,byte [SYS_SHUTDOWN]
  2431.     add   ecx,5
  2432.   markz:
  2433.     mov   [edx+TASKDATA.state],byte 3
  2434.     add   edx,0x20
  2435.     loop  markz
  2436.  
  2437.   no_mark_system_shutdown:
  2438.  
  2439.     call [disable_mouse]
  2440.  
  2441.     dec  byte [SYS_SHUTDOWN]
  2442.  
  2443.     cmp  [SYS_SHUTDOWN],byte 0
  2444.     je   system_shutdown
  2445.  
  2446.   noshutdown:
  2447.  
  2448.  
  2449.     mov   eax,[TASK_COUNT]                  ; termination
  2450.     mov   ebx,TASK_DATA+TASKDATA.state
  2451.     mov   esi,1
  2452.  
  2453.   newct:
  2454.     mov   cl,[ebx]
  2455.     cmp   cl,byte 3
  2456.     jz    terminate
  2457.     cmp   cl,byte 4
  2458.     jz    terminate
  2459.  
  2460.     add   ebx,0x20
  2461.     inc   esi
  2462.     dec   eax
  2463.     jnz   newct
  2464.  
  2465.     ret
  2466.  
  2467.  
  2468.  
  2469.  
  2470. ; redraw screen
  2471.  
  2472. redrawscreen:
  2473.  
  2474. ; eax , if process window_data base is eax, do not set flag/limits
  2475.  
  2476.          pushad
  2477.          push  eax
  2478.  
  2479. ;;;         mov   eax,2
  2480. ;;;         call  delay_hs
  2481.  
  2482.          ;mov   ecx,0               ; redraw flags for apps
  2483.          xor   ecx,ecx
  2484.        newdw2:
  2485.  
  2486.          inc   ecx
  2487.          push  ecx
  2488.  
  2489.          mov   eax,ecx
  2490.          shl   eax,5
  2491.          add   eax,window_data
  2492.  
  2493.          cmp   eax,[esp+4]
  2494.          je    not_this_task
  2495.                                    ; check if window in redraw area
  2496.          mov   edi,eax
  2497.  
  2498.          cmp   ecx,1               ; limit for background
  2499.          jz    bgli
  2500.  
  2501.          mov   eax, [edi + WDATA.box.left]
  2502.          mov   ebx, [edi + WDATA.box.top]
  2503.          mov   ecx, [edi + WDATA.box.width]
  2504.          mov   edx, [edi + WDATA.box.height]
  2505.          add   ecx,eax
  2506.          add   edx,ebx
  2507.  
  2508.          mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
  2509.          cmp   ecx,ebx
  2510.          jb    ricino
  2511.  
  2512.          mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
  2513.          cmp   ecx,eax
  2514.          jb    ricino
  2515.  
  2516.          mov   eax, [edi + WDATA.box.left]
  2517.          mov   ebx, [edi + WDATA.box.top]
  2518.          mov   ecx, [edi + WDATA.box.width]
  2519.          mov   edx, [edi + WDATA.box.height]
  2520.          add   ecx, eax
  2521.          add   edx, ebx
  2522.  
  2523.          mov   eax,[dly]    ; eax = area y start     edx = window y end
  2524.          cmp   edx,eax
  2525.          jb    ricino
  2526.  
  2527.          mov   eax,[dlx]    ; eax = area x start     ecx = window x end
  2528.          cmp   ecx,eax
  2529.          jb    ricino
  2530.  
  2531.         bgli:
  2532.  
  2533.          cmp   edi,esi
  2534.          jz    ricino
  2535.  
  2536.          mov   eax,edi
  2537.          add   eax,draw_data-window_data
  2538.  
  2539.          mov   ebx,[dlx]          ; set limits
  2540.          mov   [eax + RECT.left], ebx
  2541.          mov   ebx,[dly]
  2542.          mov   [eax + RECT.top], ebx
  2543.          mov   ebx,[dlxe]
  2544.          mov   [eax + RECT.right], ebx
  2545.          mov   ebx,[dlye]
  2546.          mov   [eax + RECT.bottom], ebx
  2547.  
  2548.          sub   eax,draw_data-window_data
  2549.  
  2550.          cmp   ecx,1
  2551.          jne   nobgrd
  2552.          cmp   esi,1
  2553.          je    newdw8
  2554.          call  drawbackground
  2555.  
  2556.        newdw8:
  2557.        nobgrd:
  2558.  
  2559.          mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
  2560.  
  2561.        ricino:
  2562.  
  2563.        not_this_task:
  2564.  
  2565.          pop   ecx
  2566.  
  2567.          cmp   ecx,[TASK_COUNT]
  2568.          jle   newdw2
  2569.  
  2570.          pop  eax
  2571.          popad
  2572.  
  2573.          ret
  2574.  
  2575. calculatebackground:   ; background
  2576.  
  2577.         ; all black
  2578.  
  2579.         mov   [display_data-8],dword 4      ; size x
  2580.         mov   [display_data-4],dword 2      ; size y
  2581.  
  2582.         mov   edi, IMG_BACKGROUND                 ; set background to black
  2583.         xor   eax, eax
  2584.         mov   ecx, 0x0fff00 / 4
  2585.         cld
  2586.         rep   stosd
  2587.  
  2588.         mov   edi,display_data              ; set os to use all pixels
  2589.         mov   eax,0x01010101
  2590.         mov   ecx,0x15ff00 / 4
  2591.         rep   stosd
  2592.  
  2593.         mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
  2594.  
  2595.         ret
  2596.  
  2597. uglobal
  2598.   imax    dd 0x0
  2599. endg
  2600.  
  2601.  
  2602.  
  2603. delay_ms:     ; delay in 1/1000 sec
  2604.  
  2605.  
  2606.         push  eax
  2607.         push  ecx
  2608.  
  2609.         mov   ecx,esi
  2610.         ; <CPU clock fix by Sergey Kuzmin aka Wildwest>
  2611.         imul  ecx, 33941
  2612.         shr   ecx, 9
  2613.         ; </CPU clock fix>
  2614.  
  2615.         in    al,0x61
  2616.         and   al,0x10
  2617.         mov   ah,al
  2618.         cld
  2619.  
  2620.  cnt1:  in    al,0x61
  2621.         and   al,0x10
  2622.         cmp   al,ah
  2623.         jz    cnt1
  2624.  
  2625.         mov   ah,al
  2626.         loop  cnt1
  2627.  
  2628.         pop   ecx
  2629.         pop   eax
  2630.  
  2631.         ret
  2632.  
  2633.  
  2634. set_app_param:
  2635.         push edi
  2636.  
  2637.         mov  edi,[TASK_BASE]
  2638.         mov  [edi+TASKDATA.event_mask],eax
  2639.  
  2640.         pop  edi
  2641.         ret
  2642.  
  2643.  
  2644.  
  2645. delay_hs:     ; delay in 1/100 secs
  2646.         push  eax
  2647.         push  ecx
  2648.         push  edx
  2649.  
  2650.         mov   edx,[timer_ticks]
  2651.         add   edx,eax
  2652.  
  2653.       newtic:
  2654.         mov   ecx,[timer_ticks]
  2655.         cmp   edx,ecx
  2656.         jbe   zerodelay
  2657.  
  2658.         call  change_task
  2659.  
  2660.         jmp   newtic
  2661.  
  2662.       zerodelay:
  2663.         pop   edx
  2664.         pop   ecx
  2665.         pop   eax
  2666.  
  2667.         ret
  2668.  
  2669.  
  2670. memmove:       ; memory move in bytes
  2671.  
  2672. ; eax = from
  2673. ; ebx = to
  2674. ; ecx = no of bytes
  2675.     test ecx, ecx
  2676.     jle  .ret
  2677.  
  2678.  
  2679.     push esi edi ecx
  2680.  
  2681.     mov  edi, ebx
  2682.     mov  esi, eax
  2683.  
  2684.     test ecx, not 11b
  2685.     jz   @f
  2686.  
  2687.     push ecx
  2688.     shr  ecx, 2
  2689.     rep  movsd
  2690.     pop  ecx
  2691.     and  ecx, 11b
  2692.     jz   .finish
  2693.   @@:
  2694.     rep  movsb
  2695.  
  2696.   .finish:
  2697.     pop  ecx edi esi
  2698.   .ret:
  2699.     ret
  2700.  
  2701.  
  2702. ; <diamond> Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
  2703. ;align 4
  2704. ;
  2705. ;read_floppy_file:
  2706. ;
  2707. ;; as input
  2708. ;;
  2709. ;; eax pointer to file
  2710. ;; ebx file lenght
  2711. ;; ecx start 512 byte block number
  2712. ;; edx number of blocks to read
  2713. ;; esi pointer to return/work area (atleast 20 000 bytes)
  2714. ;;
  2715. ;;
  2716. ;; on return
  2717. ;;
  2718. ;; eax = 0 command succesful
  2719. ;;       1 no fd base and/or partition defined
  2720. ;;       2 yet unsupported FS
  2721. ;;       3 unknown FS
  2722. ;;       4 partition not defined at hd
  2723. ;;       5 file not found
  2724. ;; ebx = size of file
  2725. ;
  2726. ;     mov   edi,[TASK_BASE]
  2727. ;     add   edi,0x10
  2728. ;     add   esi,[edi]
  2729. ;     add   eax,[edi]
  2730. ;
  2731. ;     pushad
  2732. ;     mov  edi,esi
  2733. ;     add  edi,1024
  2734. ;     mov  esi,0x100000+19*512
  2735. ;     sub  ecx,1
  2736. ;     shl  ecx,9
  2737. ;     add  esi,ecx
  2738. ;     shl  edx,9
  2739. ;     mov  ecx,edx
  2740. ;     cld
  2741. ;     rep  movsb
  2742. ;     popad
  2743. ;
  2744. ;     mov   [esp+36],eax
  2745. ;     mov   [esp+24],ebx
  2746. ;     ret
  2747.  
  2748.  
  2749.  
  2750. align 4
  2751.  
  2752. sys_programirq:
  2753.  
  2754.     mov   edi,[TASK_BASE]
  2755.     add   eax,[edi+TASKDATA.mem_start]
  2756.  
  2757.     cmp   ebx,16
  2758.     jae   .not_owner
  2759.     mov   edi,[TASK_BASE]
  2760.     mov   edi,[edi+TASKDATA.pid]
  2761.     cmp   edi,[irq_owner+ebx*4]
  2762.     je    spril1
  2763. .not_owner:
  2764.     mov   [esp+36],dword 1
  2765.     ret
  2766.   spril1:
  2767.  
  2768.     mov   esi,eax
  2769.     shl   ebx,6
  2770.     add   ebx,irq00read
  2771.     mov   edi,ebx
  2772.     mov   ecx,16
  2773.     cld
  2774.     rep   movsd
  2775.     mov   [esp+36],dword 0
  2776.     ret
  2777.  
  2778.  
  2779. align 4
  2780.  
  2781. get_irq_data:
  2782.      cmp   eax,16
  2783.      jae   .not_owner
  2784.      mov   edx,eax           ; check for correct owner
  2785.      shl   edx,2
  2786.      add   edx,irq_owner
  2787.      mov   edx,[edx]
  2788.      mov   edi,[TASK_BASE]
  2789.      mov   edi,[edi+TASKDATA.pid]
  2790.      cmp   edx,edi
  2791.      je    gidril1
  2792. .not_owner:
  2793.      mov   [esp+32],dword 2     ; ecx=2
  2794.      ret
  2795.  
  2796.   gidril1:
  2797.  
  2798.      mov   ebx,eax
  2799.      shl   ebx,12
  2800.      add   ebx,IRQ_SAVE
  2801.      mov   eax,[ebx]
  2802.      mov   ecx,1
  2803.      test  eax,eax
  2804.      jz    gid1
  2805.  
  2806.      dec   eax
  2807.      mov   esi,ebx
  2808.      mov   [ebx],eax
  2809.      movzx ebx,byte [ebx+0x10]
  2810.      add   esi,0x10
  2811.      mov   edi,esi
  2812.      inc   esi
  2813.      mov   ecx,4000 / 4
  2814.      cld
  2815.      rep   movsd
  2816. ;     xor   ecx,ecx     ; as result of 'rep' ecx=0
  2817.    gid1:
  2818.      mov   [esp+36],eax
  2819.      mov   [esp+32],ecx
  2820.      mov   [esp+24],ebx
  2821.      ret
  2822.  
  2823.  
  2824. set_io_access_rights:
  2825.  
  2826.      pushad
  2827.  
  2828.      mov   edi,[CURRENT_TASK]
  2829.      imul  edi,tss_step
  2830.      add   edi,tss_data+128
  2831. ;     add   edi,128
  2832.  
  2833.      mov   ecx,eax
  2834.      and   ecx,7    ; offset in byte
  2835.  
  2836.      shr   eax,3    ; number of byte
  2837.      add   edi,eax
  2838.  
  2839.      mov   ebx,1
  2840.      shl   ebx,cl
  2841.  
  2842.      cmp   ebp,0                ; enable access - ebp = 0
  2843.      jne   siar1
  2844.  
  2845.      not   ebx
  2846.      and   [edi],byte bl
  2847.  
  2848.      popad
  2849.  
  2850.      ret
  2851.  
  2852.    siar1:
  2853.  
  2854.      or    [edi],byte bl        ; disable access - ebp = 1
  2855.  
  2856.      popad
  2857.  
  2858.      ret
  2859.  
  2860. r_f_port_area:
  2861.  
  2862.      test  eax, eax
  2863.      jnz   free_port_area
  2864. ;     je    r_port_area
  2865. ;     jmp   free_port_area
  2866.  
  2867. ;   r_port_area:
  2868.  
  2869.      pushad
  2870.  
  2871.      cmp   ebx,ecx            ; beginning > end ?
  2872.      ja    rpal1
  2873.      cmp   ecx,65536
  2874.      jae   rpal1
  2875.      mov   esi,[RESERVED_PORTS]
  2876.      test  esi,esi            ; no reserved areas ?
  2877.      je    rpal2
  2878.      cmp   esi,255            ; max reserved
  2879.      jae   rpal1
  2880.    rpal3:
  2881.      mov   edi,esi
  2882.      shl   edi,4
  2883.      add   edi,RESERVED_PORTS
  2884.      cmp   ebx,[edi+8]
  2885.      ja    rpal4
  2886.      cmp   ecx,[edi+4]
  2887.      jae   rpal1
  2888. ;     jb    rpal4
  2889. ;     jmp   rpal1
  2890.    rpal4:
  2891.  
  2892.      dec   esi
  2893.      jnz   rpal3
  2894.      jmp   rpal2
  2895.    rpal1:
  2896.      popad
  2897.      mov   eax,1
  2898.      ret
  2899.  
  2900.    rpal2:
  2901.      popad
  2902.  
  2903.  
  2904.      ; enable port access at port IO map
  2905.      cli
  2906.      pushad                        ; start enable io map
  2907.  
  2908.      cmp   ecx,65536 ;16384
  2909.      jae   no_unmask_io ; jge
  2910.  
  2911.      mov   eax,ebx
  2912.  
  2913.    new_port_access:
  2914.  
  2915.      pushad
  2916.  
  2917.      xor   ebp,ebp                ; enable - eax = port
  2918.      call  set_io_access_rights
  2919.  
  2920.      popad
  2921.  
  2922.      inc   eax
  2923.      cmp   eax,ecx
  2924.      jbe   new_port_access
  2925.  
  2926.    no_unmask_io:
  2927.  
  2928.      popad                         ; end enable io map
  2929.      sti
  2930.  
  2931.      mov   edi,[RESERVED_PORTS]
  2932.      add   edi,1
  2933.      mov   [RESERVED_PORTS],edi
  2934.      shl   edi,4
  2935.      add   edi,RESERVED_PORTS
  2936.      mov   esi,[TASK_BASE]
  2937.      mov   esi,[esi+TASKDATA.pid]
  2938.      mov   [edi],esi
  2939.      mov   [edi+4],ebx
  2940.      mov   [edi+8],ecx
  2941.  
  2942.      xor   eax, eax
  2943.      ret
  2944.  
  2945. free_port_area:
  2946.  
  2947.      pushad
  2948.  
  2949.      mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
  2950.      test  esi,esi
  2951.      je    frpal2
  2952.      mov   edx,[TASK_BASE]
  2953.      mov   edx,[edx+TASKDATA.pid]
  2954.    frpal3:
  2955.      mov   edi,esi
  2956.      shl   edi,4
  2957.      add   edi,RESERVED_PORTS
  2958.      cmp   edx,[edi]
  2959.      jne   frpal4
  2960.      cmp   ebx,[edi+4]
  2961.      jne   frpal4
  2962.      cmp   ecx,[edi+8]
  2963.      jne   frpal4
  2964.      jmp   frpal1
  2965.    frpal4:
  2966.      dec   esi
  2967.      jnz   frpal3
  2968.    frpal2:
  2969.      popad
  2970.      mov   eax,1
  2971.      ret
  2972.    frpal1:
  2973.      mov   ecx,256
  2974.      sub   ecx,esi
  2975.      shl   ecx,4
  2976.      mov   esi,edi
  2977.      add   esi,16
  2978.      cld
  2979.      rep   movsb
  2980.  
  2981.      dec   dword [RESERVED_PORTS]
  2982.  
  2983.      popad
  2984.  
  2985.  
  2986.      ; disable port access at port IO map
  2987.  
  2988.      pushad                        ; start disable io map
  2989.  
  2990.      cmp   ecx,65536 ;16384
  2991.      jge   no_mask_io
  2992.  
  2993.      mov   eax,ebx
  2994.  
  2995.    new_port_access_disable:
  2996.  
  2997.      pushad
  2998.  
  2999.      mov   ebp,1                  ; disable - eax = port
  3000.      call  set_io_access_rights
  3001.  
  3002.      popad
  3003.  
  3004.      inc   eax
  3005.      cmp   eax,ecx
  3006.      jbe   new_port_access_disable
  3007.  
  3008.    no_mask_io:
  3009.  
  3010.      popad                         ; end disable io map
  3011.  
  3012.      xor   eax, eax
  3013.      ret
  3014.  
  3015.  
  3016. reserve_free_irq:
  3017.  
  3018.      mov   ecx, 1
  3019.      cmp   ebx, 16
  3020.      jae   fril1
  3021.      test  eax,eax
  3022.      jz    reserve_irq
  3023.  
  3024.      lea   edi,[irq_owner+ebx*4]
  3025.      mov   edx,[edi]
  3026.      mov   eax,[TASK_BASE]
  3027.      cmp   edx,[eax+TASKDATA.pid]
  3028.      jne   fril1
  3029.      dec   ecx
  3030.      mov   [edi],ecx
  3031.    fril1:
  3032.      mov   [esp+36],ecx ; return in eax
  3033.      ret
  3034.  
  3035.   reserve_irq:
  3036.  
  3037.      lea   edi,[irq_owner+ebx*4]
  3038.      cmp   dword [edi], 0
  3039.      jnz   ril1
  3040.  
  3041.      mov   edx,[TASK_BASE]
  3042.      mov   edx,[edx+TASKDATA.pid]
  3043.      mov   [edi],edx
  3044.      dec   ecx
  3045.    ril1:
  3046.      mov   [esp+36],ecx ; return in eax
  3047.      ret
  3048.  
  3049. drawbackground:
  3050.        inc   [mouse_pause]
  3051.        cmp   [SCR_MODE],word 0x12
  3052.        je   dbrv20
  3053.      dbrv12:
  3054.        cmp  [SCR_MODE],word 0100000000000000b
  3055.        jge  dbrv20
  3056.        cmp  [SCR_MODE],word 0x13
  3057.        je   dbrv20
  3058.        call  vesa12_drawbackground
  3059.        dec   [mouse_pause]
  3060.        call   [draw_pointer]
  3061.        ret
  3062.      dbrv20:
  3063.        cmp   [display_data-12],dword 1
  3064.        jne   bgrstr
  3065.        call  vesa20_drawbackground_tiled
  3066.        dec   [mouse_pause]
  3067.        call   [draw_pointer]
  3068.        ret
  3069.      bgrstr:
  3070.        call  vesa20_drawbackground_stretch
  3071.        dec   [mouse_pause]
  3072.        call   [draw_pointer]
  3073.        ret
  3074.  
  3075. align 4
  3076.  
  3077. syscall_putimage:                       ; PutImage
  3078.  
  3079.      mov   edx,ecx
  3080.      mov   ecx,ebx
  3081.         lea     ebx, [eax+std_application_base_address]
  3082.  
  3083. sys_putimage:
  3084.      test  ecx,0x80008000
  3085.      jnz   .exit
  3086.      test  ecx,0x0000FFFF
  3087.      jz    .exit
  3088.      test  ecx,0xFFFF0000
  3089.      jnz   @f
  3090.   .exit:
  3091.      ret
  3092.  @@:
  3093.         mov     edi,[CURRENT_TASK]
  3094.         shl     edi,8
  3095.         add     dx,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3096.         rol     edx,16
  3097.         add     dx,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3098.         rol     edx,16
  3099.   .forced:
  3100.         push    ebp esi 0
  3101.         mov     ebp, putimage_get24bpp
  3102.         mov     esi, putimage_init24bpp
  3103. sys_putimage_bpp:
  3104. ;        call    [disable_mouse] ; this will be done in xxx_putimage
  3105. ;        mov     eax, vga_putimage
  3106.         cmp     [SCR_MODE], word 0x12
  3107.         jz      @f   ;.doit
  3108.         mov     eax, vesa12_putimage
  3109.         cmp     [SCR_MODE], word 0100000000000000b
  3110.         jae     @f
  3111.         cmp     [SCR_MODE], word 0x13
  3112.         jnz     .doit
  3113. @@:
  3114.         mov     eax, vesa20_putimage
  3115. .doit:
  3116.         inc     [mouse_pause]
  3117.         call    eax
  3118.         dec     [mouse_pause]
  3119.         pop     ebp esi ebp
  3120.         jmp     [draw_pointer]
  3121.  
  3122. syscall_putimage_palette:
  3123.         lea     edi, [esi+std_application_base_address]
  3124.         mov     esi, edx
  3125.         mov     edx, ecx
  3126.         mov     ecx, ebx
  3127.         lea     ebx, [eax+std_application_base_address]
  3128. sys_putimage_palette:
  3129. ; ebx = pointer to image
  3130. ; ecx = [xsize]*65536 + [ysize]
  3131. ; edx = [xstart]*65536 + [ystart]
  3132. ; esi = number of bits per pixel, must be 8, 24 or 32
  3133. ; edi = pointer to palette
  3134. ; ebp = row delta
  3135.         mov     eax, [CURRENT_TASK]
  3136.         shl     eax, 8
  3137.         add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3138.         rol     edx, 16
  3139.         add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3140.         rol     edx, 16
  3141. .forced:
  3142.         push    ebp esi ebp
  3143.         cmp     esi, 8
  3144.         jnz     @f
  3145.         mov     ebp, putimage_get8bpp
  3146.         mov     esi, putimage_init8bpp
  3147.         jmp     sys_putimage_bpp
  3148. @@:
  3149.         cmp     esi, 24
  3150.         jnz     @f
  3151.         mov     ebp, putimage_get24bpp
  3152.         mov     esi, putimage_init24bpp
  3153.         jmp     sys_putimage_bpp
  3154. @@:
  3155.         cmp     esi, 32
  3156.         jnz     @f
  3157.         mov     ebp, putimage_get32bpp
  3158.         mov     esi, putimage_init32bpp
  3159.         jmp     sys_putimage_bpp
  3160. @@:
  3161.         pop     ebp esi
  3162.         ret
  3163.  
  3164. putimage_init24bpp:
  3165.         lea     eax, [eax*3]
  3166. putimage_init8bpp:
  3167.         ret
  3168.  
  3169. putimage_get24bpp:
  3170.         mov     eax, [esi]
  3171.         add     esi, 3
  3172.         ret     4
  3173. putimage_get8bpp:
  3174.         movzx   eax, byte [esi]
  3175.         push    edx
  3176.         mov     edx, [esp+8]
  3177.         mov     eax, [edx+eax*4]
  3178.         pop     edx
  3179.         inc     esi
  3180.         ret     4
  3181.  
  3182. putimage_init32bpp:
  3183.         shl     eax, 2
  3184.         ret
  3185. putimage_get32bpp:
  3186.         lodsd
  3187.         ret     4
  3188.  
  3189. ; eax x beginning
  3190. ; ebx y beginning
  3191. ; ecx x end
  3192.         ; edx y end
  3193. ; edi color
  3194.  
  3195. __sys_drawbar:
  3196.         mov     esi,[CURRENT_TASK]
  3197.         shl     esi,8
  3198.         add     eax,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3199.         add     ecx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3200.         add     ebx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3201.         add     edx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3202.   .forced:
  3203.     inc   [mouse_pause]
  3204. ;        call    [disable_mouse]
  3205.     cmp   [SCR_MODE],word 0x12
  3206.     je   dbv20
  3207.    sdbv20:
  3208.     cmp  [SCR_MODE],word 0100000000000000b
  3209.     jge  dbv20
  3210.     cmp  [SCR_MODE],word 0x13
  3211.     je   dbv20
  3212.     call vesa12_drawbar
  3213.     dec   [mouse_pause]
  3214.     call   [draw_pointer]
  3215.     ret
  3216.   dbv20:
  3217.     call vesa20_drawbar
  3218.     dec   [mouse_pause]
  3219.     call   [draw_pointer]
  3220.     ret
  3221.  
  3222.  
  3223.  
  3224. kb_read:
  3225.  
  3226.         push    ecx edx
  3227.  
  3228.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  3229.       kr_loop:
  3230.         in      al,0x64
  3231.         test    al,1
  3232.         jnz     kr_ready
  3233.         loop    kr_loop
  3234.         mov     ah,1
  3235.         jmp     kr_exit
  3236.       kr_ready:
  3237.         push    ecx
  3238.         mov     ecx,32
  3239.       kr_delay:
  3240.         loop    kr_delay
  3241.         pop     ecx
  3242.         in      al,0x60
  3243.         xor     ah,ah
  3244.       kr_exit:
  3245.  
  3246.         pop     edx ecx
  3247.  
  3248.         ret
  3249.  
  3250.  
  3251. kb_write:
  3252.  
  3253.         push    ecx edx
  3254.  
  3255.         mov     dl,al
  3256. ;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  3257. ;      kw_loop1:
  3258. ;        in      al,0x64
  3259. ;        test    al,0x20
  3260. ;        jz      kw_ok1
  3261. ;        loop    kw_loop1
  3262. ;        mov     ah,1
  3263. ;        jmp     kw_exit
  3264. ;      kw_ok1:
  3265.         in      al,0x60
  3266.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  3267.       kw_loop:
  3268.         in      al,0x64
  3269.         test    al,2
  3270.         jz      kw_ok
  3271.         loop    kw_loop
  3272.         mov     ah,1
  3273.         jmp     kw_exit
  3274.       kw_ok:
  3275.         mov     al,dl
  3276.         out     0x60,al
  3277.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  3278.       kw_loop3:
  3279.         in      al,0x64
  3280.         test    al,2
  3281.         jz      kw_ok3
  3282.         loop    kw_loop3
  3283.         mov     ah,1
  3284.         jmp     kw_exit
  3285.       kw_ok3:
  3286.         mov     ah,8
  3287.       kw_loop4:
  3288.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  3289.       kw_loop5:
  3290.         in      al,0x64
  3291.         test    al,1
  3292.         jnz     kw_ok4
  3293.         loop    kw_loop5
  3294.         dec     ah
  3295.         jnz     kw_loop4
  3296.       kw_ok4:
  3297.         xor     ah,ah
  3298.       kw_exit:
  3299.  
  3300.         pop     edx ecx
  3301.  
  3302.         ret
  3303.  
  3304.  
  3305. kb_cmd:
  3306.  
  3307.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  3308.       c_wait:
  3309.         in      al,0x64
  3310.         test    al,2
  3311.         jz      c_send
  3312.         loop    c_wait
  3313.         jmp     c_error
  3314.       c_send:
  3315.         mov     al,bl
  3316.         out     0x64,al
  3317.         mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
  3318.       c_accept:
  3319.         in      al,0x64
  3320.         test    al,2
  3321.         jz      c_ok
  3322.         loop    c_accept
  3323.       c_error:
  3324.         mov     ah,1
  3325.         jmp     c_exit
  3326.       c_ok:
  3327.         xor     ah,ah
  3328.       c_exit:
  3329.         ret
  3330.  
  3331.  
  3332. setmouse:  ; set mousepicture -pointer
  3333.            ; ps2 mouse enable
  3334.  
  3335.      mov     [MOUSE_PICTURE],dword mousepointer
  3336.  
  3337.      cli
  3338. ;     mov     bl,0xa8                 ; enable mouse cmd
  3339. ;     call    kb_cmd
  3340. ;     call    kb_read                 ; read status
  3341. ;     mov     bl,0x20                 ; get command byte
  3342. ;     call    kb_cmd
  3343. ;     call    kb_read
  3344. ;     or      al,3                    ; enable interrupt
  3345. ;     mov     bl,0x60                 ; write command
  3346. ;     push    eax
  3347. ;     call    kb_cmd
  3348. ;     pop     eax
  3349. ;     call    kb_write
  3350. ;     mov     bl,0xd4                 ; for mouse
  3351. ;     call    kb_cmd
  3352. ;     mov     al,0xf4                 ; enable mouse device
  3353. ;     call    kb_write
  3354. ;     call    kb_read           ; read status return
  3355.  
  3356.      ; com1 mouse enable
  3357.  
  3358.      mov   bx,0x3f8 ; combase
  3359.  
  3360.      mov   dx,bx
  3361.      add   dx,3
  3362.      mov   al,0x80
  3363.      out   dx,al
  3364.  
  3365.      mov   dx,bx
  3366.      add   dx,1
  3367.      mov   al,0
  3368.      out   dx,al
  3369.  
  3370.      mov   dx,bx
  3371.      add   dx,0
  3372.      mov   al,0x30*2    ; 0x30 / 4
  3373.      out   dx,al
  3374.  
  3375.      mov   dx,bx
  3376.      add   dx,3
  3377.      mov   al,2         ; 3
  3378.      out   dx,al
  3379.  
  3380.      mov   dx,bx
  3381.      add   dx,4
  3382.      mov   al,0xb
  3383.      out   dx,al
  3384.  
  3385.      mov   dx,bx
  3386.      add   dx,1
  3387.      mov   al,1
  3388.      out   dx,al
  3389.  
  3390.  
  3391.      ; com2 mouse enable
  3392.  
  3393.      mov   bx,0x2f8 ; combase
  3394.  
  3395.      mov   dx,bx
  3396.      add   dx,3
  3397.      mov   al,0x80
  3398.      out   dx,al
  3399.  
  3400.      mov   dx,bx
  3401.      add   dx,1
  3402.      mov   al,0
  3403.      out   dx,al
  3404.  
  3405.      mov   dx,bx
  3406.      add   dx,0
  3407.      mov   al,0x30*2
  3408.      out   dx,al
  3409.  
  3410.      mov   dx,bx
  3411.      add   dx,3
  3412.      mov   al,2
  3413.      out   dx,al
  3414.  
  3415.      mov   dx,bx
  3416.      add   dx,4
  3417.      mov   al,0xb
  3418.      out   dx,al
  3419.  
  3420.      mov   dx,bx
  3421.      add   dx,1
  3422.      mov   al,1
  3423.      out   dx,al
  3424.  
  3425.      ret
  3426.  
  3427.  
  3428. _rdtsc:
  3429.      bt [cpu_caps], CAPS_TSC
  3430.      jnc ret_rdtsc
  3431.      rdtsc
  3432.      ret
  3433.    ret_rdtsc:
  3434.      mov   edx,0xffffffff
  3435.      mov   eax,0xffffffff
  3436.      ret
  3437.  
  3438. rerouteirqs:
  3439.  
  3440.         cli
  3441.  
  3442.         mov     al,0x11         ;  icw4, edge triggered
  3443.         out     0x20,al
  3444.         call    pic_delay
  3445.         out     0xA0,al
  3446.         call    pic_delay
  3447.  
  3448.         mov     al,0x20         ;  generate 0x20 +
  3449.         out     0x21,al
  3450.         call    pic_delay
  3451.         mov     al,0x28         ;  generate 0x28 +
  3452.         out     0xA1,al
  3453.         call    pic_delay
  3454.  
  3455.         mov     al,0x04         ;  slave at irq2
  3456.         out     0x21,al
  3457.         call    pic_delay
  3458.         mov     al,0x02         ;  at irq9
  3459.         out     0xA1,al
  3460.         call    pic_delay
  3461.  
  3462.         mov     al,0x01         ;  8086 mode
  3463.         out     0x21,al
  3464.         call    pic_delay
  3465.         out     0xA1,al
  3466.         call    pic_delay
  3467.  
  3468.         mov     al,255          ; mask all irq's
  3469.         out     0xA1,al
  3470.         call    pic_delay
  3471.         out     0x21,al
  3472.         call    pic_delay
  3473.  
  3474.         mov     ecx,0x1000
  3475.         cld
  3476. picl1:  call    pic_delay
  3477.         loop    picl1
  3478.  
  3479.         mov     al,255          ; mask all irq's
  3480.         out     0xA1,al
  3481.         call    pic_delay
  3482.         out     0x21,al
  3483.         call    pic_delay
  3484.  
  3485.         cli
  3486.  
  3487.         ret
  3488.  
  3489.  
  3490. pic_delay:
  3491.  
  3492.         jmp     pdl1
  3493. pdl1:   ret
  3494.  
  3495.  
  3496. sys_msg_board_str:
  3497.  
  3498.      pushad
  3499.    @@:
  3500.      cmp    [esi],byte 0
  3501.      je     @f
  3502.      mov    eax,1
  3503.      movzx  ebx,byte [esi]
  3504.      call   sys_msg_board
  3505.      inc    esi
  3506.      jmp    @b
  3507.    @@:
  3508.      popad
  3509.      ret
  3510.  
  3511. uglobal
  3512.   msg_board_data: times 4096 db 0
  3513.   msg_board_count dd 0x0
  3514. endg
  3515.  
  3516. sys_msg_board:
  3517.  
  3518. ; eax=1 : write :  bl byte to write
  3519. ; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
  3520.  
  3521.      mov  ecx,[msg_board_count]
  3522.      cmp  eax, 1
  3523.      jne  smbl1
  3524.  
  3525.  
  3526.      mov  [msg_board_data+ecx],bl
  3527.      inc  ecx
  3528.      and  ecx, 4095
  3529.      mov  [msg_board_count], ecx
  3530.      mov  [check_idle_semaphore], 5
  3531.      ret
  3532.    smbl1:
  3533.  
  3534.      cmp   eax, 2
  3535.      jne   smbl2
  3536.      test  ecx, ecx
  3537.      jz    smbl21
  3538. ;     mov   edi, msg_board_data
  3539. ;     mov   esi, msg_board_data+1
  3540. ;     movzx eax, byte [edi]
  3541.      mov   eax, msg_board_data+1
  3542.      mov   ebx, msg_board_data
  3543.      movzx edx, byte [ebx]
  3544.      call  memmove
  3545. ;     push  ecx
  3546. ;     shr   ecx, 2
  3547. ;     cld
  3548. ;     rep   movsd
  3549. ;     pop   ecx
  3550. ;     and   ecx, 3
  3551. ;     rep   movsb
  3552.      dec   [msg_board_count]
  3553.      mov   [esp+36], edx ;eax
  3554.      mov   [esp+24], dword 1
  3555.      ret
  3556.    smbl21:
  3557.      mov   [esp+36], ecx
  3558.      mov   [esp+24], ecx
  3559.  
  3560.    smbl2:
  3561.      ret
  3562.  
  3563.  
  3564.  
  3565. sys_process_def:
  3566.         mov     edi, [CURRENT_TASK]
  3567.  
  3568.         dec     eax             ; 1 = set keyboard mode
  3569.      jne   no_set_keyboard_setup
  3570.  
  3571.      shl   edi,8
  3572.      mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
  3573.  
  3574.      ret
  3575.  
  3576.    no_set_keyboard_setup:
  3577.  
  3578.         dec     eax             ; 2 = get keyboard mode
  3579.      jne   no_get_keyboard_setup
  3580.  
  3581.      shl   edi,8
  3582.      movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
  3583.  
  3584.      mov   [esp+36],eax
  3585.  
  3586.      ret
  3587.  
  3588.    no_get_keyboard_setup:
  3589.  
  3590.         dec     eax             ; 3 = get keyboard ctrl, alt, shift
  3591.      jne   no_get_keyboard_cas
  3592.  
  3593. ;     xor   eax,eax
  3594. ;     movzx eax,byte [shift]
  3595. ;     movzx ebx,byte [ctrl]
  3596. ;     shl   ebx,2
  3597. ;     add   eax,ebx
  3598. ;     movzx ebx,byte [alt]
  3599. ;     shl   ebx,3
  3600. ;     add   eax,ebx
  3601.  
  3602.  ;// mike.dld [
  3603.      mov   eax, [kb_state]
  3604.  ;// mike.dld ]
  3605.  
  3606.      mov   [esp+36],eax
  3607.  
  3608.      ret
  3609.  
  3610.    no_get_keyboard_cas:
  3611.  
  3612.         dec     eax
  3613.         jnz     no_add_keyboard_hotkey
  3614.  
  3615.         mov     eax, hotkey_list
  3616. @@:
  3617.         cmp     dword [eax+8], 0
  3618.         jz      .found_free
  3619.         add     eax, 16
  3620.         cmp     eax, hotkey_list+16*256
  3621.         jb      @b
  3622.         mov     dword [esp+36], 1
  3623.         ret
  3624. .found_free:
  3625.         mov     [eax+8], edi
  3626.         mov     [eax+4], ecx
  3627.         movzx   ebx, bl
  3628.         lea     ebx, [hotkey_scancodes+ebx*4]
  3629.         mov     ecx, [ebx]
  3630.         mov     [eax], ecx
  3631.         mov     [ebx], eax
  3632.         mov     [eax+12], ebx
  3633.         jecxz   @f
  3634.         mov     [ecx+12], eax
  3635. @@:
  3636.         and     dword [esp+36], 0
  3637.         ret
  3638.  
  3639. no_add_keyboard_hotkey:
  3640.  
  3641.         dec     eax
  3642.         jnz     no_del_keyboard_hotkey
  3643.  
  3644.         movzx   ebx, bl
  3645.         lea     ebx, [hotkey_scancodes+ebx*4]
  3646.         mov     eax, [ebx]
  3647. .scan:
  3648.         test    eax, eax
  3649.         jz      .notfound
  3650.         cmp     [eax+8], edi
  3651.         jnz     .next
  3652.         cmp     [eax+4], ecx
  3653.         jz      .found
  3654. .next:
  3655.         mov     eax, [eax]
  3656.         jmp     .scan
  3657. .notfound:
  3658.         mov     dword [esp+36], 1
  3659.         ret
  3660. .found:
  3661.         mov     ecx, [eax]
  3662.         jecxz   @f
  3663.         mov     edx, [eax+12]
  3664.         mov     [ecx+12], edx
  3665. @@:
  3666.         mov     ecx, [eax+12]
  3667.         mov     edx, [eax]
  3668.         mov     [ecx], edx
  3669.         xor     edx, edx
  3670.         mov     [eax+4], edx
  3671.         mov     [eax+8], edx
  3672.         mov     [eax+12], edx
  3673.         mov     [eax], edx
  3674.         mov     [esp+36], edx
  3675.         ret
  3676.  
  3677. no_del_keyboard_hotkey:
  3678.      ret
  3679.  
  3680.  
  3681. align 4
  3682.  
  3683. sys_gs:                         ; direct screen access
  3684.  
  3685.      cmp  eax,1                 ; resolution
  3686.      jne  no_gs1
  3687.      mov  eax,[ScreenWidth]
  3688.      shl  eax,16
  3689.      mov  ax,[ScreenHeight]
  3690.      add  eax,0x00010001
  3691.      mov  [esp+36],eax
  3692.      ret
  3693.    no_gs1:
  3694.  
  3695.      cmp   eax,2                ; bits per pixel
  3696.      jne   no_gs2
  3697.      movzx eax,byte [ScreenBPP]
  3698.      mov   [esp+36],eax
  3699.      ret
  3700.    no_gs2:
  3701.  
  3702.      cmp   eax,3                ; bytes per scanline
  3703.      jne   no_gs3
  3704.      mov   eax,[BytesPerScanLine]
  3705.      mov   [esp+36],eax
  3706.      ret
  3707.    no_gs3:
  3708.  
  3709.      mov  [esp+36],dword -1
  3710.      ret
  3711.  
  3712.  
  3713. align 4 ; PCI functions
  3714.  
  3715. sys_pci:
  3716.  
  3717.      call  pci_api
  3718.      mov   [esp+36],eax
  3719.      ret
  3720.  
  3721.  
  3722. align 4  ;  system functions
  3723.  
  3724. syscall_setpixel:                       ; SetPixel
  3725.  
  3726.  
  3727.      mov   edx,[TASK_BASE]
  3728.      add   eax,[edx-twdw+WDATA.box.left]
  3729.      add   ebx,[edx-twdw+WDATA.box.top]
  3730.         mov     edi,[CURRENT_TASK]
  3731.         shl     edi,8
  3732.         add     eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3733.         add     ebx,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3734.      xor   edi,edi ; no force
  3735. ;     mov   edi,1
  3736.      call  [disable_mouse]
  3737.      jmp   [putpixel]
  3738.  
  3739. align 4
  3740.  
  3741. syscall_writetext:                      ; WriteText
  3742.  
  3743.      mov   edi,[TASK_BASE]
  3744.      mov   ebp,[edi-twdw+WDATA.box.left]
  3745.         push    esi
  3746.         mov     esi,[CURRENT_TASK]
  3747.         shl     esi,8
  3748.         add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3749.      shl   ebp,16
  3750.      add   ebp,[edi-twdw+WDATA.box.top]
  3751.         add     bp,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3752.         pop     esi
  3753.      add   ecx,[edi+TASKDATA.mem_start]
  3754.      add   eax,ebp
  3755.      xor   edi,edi
  3756.      jmp   dtext
  3757.  
  3758. align 4
  3759.  
  3760. syscall_openramdiskfile:                ; OpenRamdiskFile
  3761.  
  3762.  
  3763.      mov   edi,[TASK_BASE]
  3764.      add   edi,TASKDATA.mem_start
  3765.      add   eax,[edi]
  3766.      add   edx,[edi]
  3767.      mov   esi,12
  3768.      call  fileread
  3769.      mov   [esp+36],ebx
  3770.      ret
  3771.  
  3772. align 4
  3773.  
  3774. syscall_drawrect:                       ; DrawRect
  3775.  
  3776.      mov   edi,ecx
  3777.      and   edi,0x80FFFFFF
  3778.      test  ax,ax
  3779.      je    drectr
  3780.      test  bx,bx
  3781.      je    drectr
  3782.      movzx ecx,ax
  3783.      shr   eax,16
  3784.      movzx edx,bx
  3785.      shr   ebx,16
  3786.         mov     esi,[CURRENT_TASK]
  3787.         shl     esi,8
  3788.         add     eax,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3789.         add     ebx,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3790.      add   ecx,eax
  3791.      add   edx,ebx
  3792.      jmp   [drawbar]
  3793.     drectr:
  3794.      ret
  3795.  
  3796. align 4
  3797.  
  3798. syscall_getscreensize:                  ; GetScreenSize
  3799.  
  3800.      movzx eax,word[ScreenWidth]
  3801.      shl   eax,16
  3802.      mov   ax,[ScreenHeight]
  3803.      mov   [esp+36],eax
  3804.      ret
  3805.  
  3806. align 4
  3807.  
  3808. syscall_cdaudio:                        ; CD
  3809.  
  3810.      call  sys_cd_audio
  3811.      mov   [esp+36],eax
  3812.      ret
  3813.  
  3814. align 4
  3815.  
  3816. syscall_delramdiskfile:                 ; DelRamdiskFile
  3817.  
  3818.      mov   edi,[TASK_BASE]
  3819.      add   edi,TASKDATA.mem_start
  3820.      add   eax,[edi]
  3821.      call  filedelete
  3822.      mov   [esp+36],eax
  3823.      ret
  3824.  
  3825. align 4
  3826.  
  3827. syscall_writeramdiskfile:               ; WriteRamdiskFile
  3828.  
  3829.      mov   edi,[TASK_BASE]
  3830.      add   edi,TASKDATA.mem_start
  3831.      add   eax,[edi]
  3832.      add   ebx,[edi]
  3833.      call  filesave
  3834.      mov   [esp+36],eax
  3835.      ret
  3836.  
  3837. align 4
  3838.  
  3839. syscall_getpixel:                       ; GetPixel
  3840.      mov   ecx,[ScreenWidth]
  3841.      inc   ecx
  3842.      xor   edx,edx
  3843.      div   ecx
  3844.      mov   ebx,edx
  3845.      xchg  eax,ebx
  3846.      call  dword [0xe024]
  3847.      mov   [esp+36],ecx
  3848.      ret
  3849.  
  3850. align 4
  3851.  
  3852. syscall_readstring:                     ; ReadString
  3853.  
  3854.      mov   edi,[TASK_BASE]
  3855.      add   edi,TASKDATA.mem_start
  3856.      add   eax,[edi]
  3857.      call  read_string
  3858.      mov   [esp+36],eax
  3859.      ret
  3860.  
  3861. align 4
  3862.  
  3863. syscall_drawline:                       ; DrawLine
  3864.  
  3865.      mov   edi,[TASK_BASE]
  3866.      movzx edx,word[edi-twdw+WDATA.box.left]
  3867.      mov   ebp,edx
  3868.         mov     esi,[CURRENT_TASK]
  3869.         shl     esi,8
  3870.         add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3871.         add     dx,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.left]
  3872.      shl   edx,16
  3873.      add   ebp,edx
  3874.      movzx edx,word[edi-twdw+WDATA.box.top]
  3875.      add   eax,ebp
  3876.      mov   ebp,edx
  3877.         add     ebp,[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3878.         add     dx,word[esi+SLOT_BASE+APPDATA.wnd_clientbox.top]
  3879.      shl   edx,16
  3880.      xor   edi,edi
  3881.      add   edx,ebp
  3882.      add   ebx,edx
  3883.      jmp   [draw_line]
  3884.  
  3885. align 4
  3886.  
  3887. syscall_getirqowner:                    ; GetIrqOwner
  3888.      cmp   eax,16
  3889.      jae   .err
  3890.      shl   eax,2
  3891.      add   eax,irq_owner
  3892.      mov   eax,[eax]
  3893.      mov   [esp+36],eax
  3894.      ret
  3895. .err:
  3896.      or    dword [esp+36], -1
  3897.      ret
  3898.  
  3899. align 4
  3900.  
  3901. syscall_reserveportarea:                ; ReservePortArea and FreePortArea
  3902.  
  3903.      call  r_f_port_area
  3904.      mov   [esp+36],eax
  3905.      ret
  3906.  
  3907. align 4
  3908.  
  3909. syscall_threads:                        ; CreateThreads
  3910.  
  3911.      call  sys_threads
  3912.      mov   [esp+36],eax
  3913.      ret
  3914.  
  3915. align 4
  3916.  
  3917. stack_driver_stat:
  3918.  
  3919.      call  app_stack_handler            ; Stack status
  3920.  
  3921. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  3922. ;     call  change_task                 ; between sent packet
  3923.  
  3924.      mov   [esp+36],eax
  3925.      ret
  3926.  
  3927. align 4
  3928.  
  3929. socket:                                 ; Socket interface
  3930.      call  app_socket_handler
  3931.  
  3932. ;     mov   [check_idle_semaphore],5    ; enable these for zero delay
  3933. ;     call  change_task                 ; between sent packet
  3934.  
  3935.      mov   [esp+36],eax
  3936.      mov   [esp+24],ebx
  3937.      ret
  3938.  
  3939. align 4
  3940.  
  3941. user_events:                            ; User event times
  3942.  
  3943.      mov   eax,0x12345678
  3944.      mov   [esp+36],eax
  3945.  
  3946.      ret
  3947.  
  3948. align 4
  3949.  
  3950. read_from_hd:                           ; Read from hd - fn not in use
  3951.  
  3952.      mov   edi,[TASK_BASE]
  3953.      add   edi,TASKDATA.mem_start
  3954.      add   eax,[edi]
  3955.      add   ecx,[edi]
  3956.      add   edx,[edi]
  3957.      call  file_read
  3958.  
  3959.      mov   [esp+36],eax
  3960.      mov   [esp+24],ebx
  3961.  
  3962.      ret
  3963.  
  3964. align 4
  3965. paleholder:
  3966.         ret
  3967.  
  3968. ; --------------- APM ---------------------
  3969. apm_entry    dp    0
  3970. apm_vf        dd    0
  3971. align 4
  3972. sys_apm:
  3973.     cmp    word [apm_vf], 0    ; Check APM BIOS enable
  3974.     jne    @f
  3975.     or    [esp + 56], byte 1    ; error
  3976.     mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
  3977.     ret
  3978.  
  3979. @@:    xchg    eax, ecx
  3980.     xchg    ebx, ecx
  3981.  
  3982.     cmp    al, 3
  3983.     ja    @f
  3984.     and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
  3985.     mov    eax, [apm_vf]
  3986.     mov    [esp + 36], eax
  3987.     shr    eax, 16
  3988.     mov    [esp + 32], eax
  3989.     ret
  3990.  
  3991. @@:    call    pword [apm_entry]    ; call APM BIOS
  3992.     mov    [esp + 8 ], edi
  3993.     mov    [esp + 12], esi
  3994.     mov    [esp + 24], ebx
  3995.     mov    [esp + 28], edx
  3996.     mov    [esp + 32], ecx
  3997.     mov    [esp + 36], eax
  3998.     setc    al
  3999.     and    [esp + 56], byte 0xfe
  4000.     or    [esp + 56], al
  4001.     ret
  4002. ; -----------------------------------------
  4003.  
  4004. align 4
  4005.  
  4006. undefined_syscall:                      ; Undefined system call
  4007.  
  4008.      mov   [esp+36],dword -1
  4009.      ret
  4010.  
  4011.  
  4012.  
  4013.