Subversion Repositories Kolibri OS

Rev

Rev 1066 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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