Subversion Repositories Kolibri OS

Rev

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