Subversion Repositories Kolibri OS

Rev

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

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