Subversion Repositories Kolibri OS

Rev

Rev 395 | Blame | Last modification | View Log | Download | RSS feed

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