Subversion Repositories Kolibri OS

Rev

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