Subversion Repositories Kolibri OS

Rev

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