Subversion Repositories Kolibri OS

Rev

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