Subversion Repositories Kolibri OS

Rev

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