Subversion Repositories Kolibri OS

Rev

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