Subversion Repositories Kolibri OS

Rev

Rev 358 | Rev 373 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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