Subversion Repositories Kolibri OS

Rev

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