Subversion Repositories Kolibri OS

Rev

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