Subversion Repositories Kolibri OS

Rev

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