Subversion Repositories Kolibri OS

Rev

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