Subversion Repositories Kolibri OS

Rev

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

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