Subversion Repositories Kolibri OS

Rev

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