Subversion Repositories Kolibri OS

Rev

Rev 551 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;    Ok, this is the sceleton that MENUET 0.01 understands.
  3. ;    Do not change the header bits for now. Compile with nasm.
  4. ;
  5.  
  6. include '..\..\..\macros.inc'
  7.  
  8. use32
  9.  org    0x0
  10.  db     'MENUET01'    ; header
  11.  dd     0x01          ; header version
  12.  dd     START         ; entry point
  13.  dd     I_END         ; image size
  14.  dd     0x1000        ; required memory
  15.  dd     0x1000        ; esp
  16.  dd     0x0 , 0x0     ; I_Param , I_Path
  17.  
  18.  
  19. MIDI_PORT = 0x330
  20.  
  21. midisp: dw      MIDI_PORT + 1
  22. mididp: dw      MIDI_PORT
  23.  
  24.  
  25. START:
  26.         mov     dx, word[midisp]
  27.         mov     cx, word[mididp]
  28.         mcall   46, 0
  29.  
  30.         test    eax, eax
  31.         jne     exit
  32.  
  33.  
  34.   red:
  35.     call  draw_window
  36.  
  37. still:
  38.  
  39.         mov     eax, 10          ; redraw ?
  40.         mcall
  41.  
  42.         cmp     eax, 1
  43.         jz      red
  44.         cmp     eax, 3
  45.         jnz     still
  46.  
  47.         ;button:
  48.         mov     eax, 17
  49.         mcall
  50.  
  51.         cmp     al, 0
  52.         jnz  still
  53.  
  54.         cmp     ah, 1
  55.         jz      exit
  56.  
  57.         cmp     ah, 2
  58.         jz      .play_note
  59.  
  60.         ; reset midi device
  61.         call    midi_reset
  62.  
  63.         cmp     eax, 0    ; check error code
  64.         jz      still
  65.  
  66.         call    printerror
  67.  
  68.         jmp     still
  69.  
  70. .play_note:
  71.  
  72.         mov     eax, 50
  73. .nn:
  74.         mov     ebx, 100
  75.         call    noteout
  76.         pusha
  77.  
  78.         mov     eax, 5
  79.         mov     ebx, 8
  80.         mcall
  81.  
  82.         popa
  83.         mov     ebx, 0
  84. ;    call noteout
  85.  
  86.         add     eax, 3
  87.  
  88.         mov     ebx, 100
  89.         call    noteout
  90.         pusha
  91.  
  92.         mov     eax, 5
  93.         mov     ebx, 8
  94.         mcall
  95.  
  96.         popa
  97.         mov     ebx, 0
  98. ;    call noteout
  99.  
  100.         add     eax, 4
  101.  
  102.         inc     eax
  103.         cmp     eax, 90
  104.         jbe     .nn
  105.  
  106.         jmp     still
  107.  
  108. exit:
  109.         mcall   -1
  110.  
  111.  
  112. draw_window:
  113.  
  114.         pusha
  115.  
  116.         mov     eax, 12                    ; tell os about redraw
  117.         mov     ebx, 1
  118.         mcall
  119.  
  120.         mov     eax, 0                     ; define and draw window
  121.         mov     ebx, 20*65536+250
  122.         mov     ecx, 20*65536+120
  123.         mov     edx, 0x14ffffff
  124.         mov     edi, title
  125.         mcall
  126.  
  127.         mov     eax, 8
  128.         mov     ebx, 10*65536+200          ; button start x & size
  129.         mov     ecx, 40 *65536+17          ; button start y & size
  130.         mov     edx, 2                     ; button number
  131.         mov     esi, 0x4060b0              ; button color
  132.         mcall
  133.  
  134.         mov     ecx, 60 *65536+17          ; button start y & size
  135.         mov     edx, 3                     ; button number
  136.         mcall
  137.  
  138.         mov     eax, 4
  139.         mov     ebx, 25*65536+45
  140.         mov     ecx, dword 0xffffff
  141.         mov     edx, buttont
  142.         mov     esi, buttontlen-buttont
  143.         mcall
  144.  
  145.         mov     ebx, 25*65536+65
  146.         mov     edx, buttont2
  147.         mov     esi, buttontlen2-buttont2
  148.         mcall
  149.  
  150.         mov     eax, 12                    ; tell os about redraw end
  151.         mov     ebx, 2
  152.         mcall
  153.  
  154.         popa
  155.         ret
  156.  
  157.  
  158. noteout:
  159.         pusha
  160.  
  161.         push    ebx
  162.         push    eax
  163.  
  164.         mov     ecx, 0x9f
  165.         call    midi_output_byte
  166.  
  167.         pop     ecx
  168.         call    midi_output_byte
  169.  
  170.         pop     ecx
  171.         call    midi_output_byte
  172.  
  173.         cmp     eax, 0
  174.         jz      @f
  175.  
  176.         call    printerror
  177.  
  178. @@:
  179.         popa
  180.         ret
  181.  
  182. printerror:
  183.  
  184.         mov     eax, 4
  185.         mov     ebx, 15*65536+85
  186.         mov     ecx, 0x000000
  187.         mov     edx, error1
  188.         mov     esi, errorlen1-error1
  189.         mcall
  190.  
  191.         mov     eax, 4
  192.         mov     ebx, 15*65536+95
  193.         mov     ecx, 0x000000
  194.         mov     edx, error2
  195.         mov     esi, errorlen2-error2
  196.         mcall
  197.  
  198.         ret
  199.  
  200. ; MPU401 interface
  201.  
  202. midi_reset:
  203. @@:
  204.         ; reset device
  205.         call    is_output
  206.         test    al, al
  207.         jnz     @b
  208.         mov     dx, word [midisp]
  209.         mov     al, 0xff
  210.         out     dx, al
  211. @@:
  212.         mov     dx, word [midisp]
  213.         mov     al, 0xff
  214.         out     dx, al
  215.         call    is_input
  216.         test    al, al
  217.         jnz     @b
  218.         call    get_mpu_in
  219.         cmp     al, 0xfe
  220.         jnz     @b
  221. @@:
  222.         call    is_output
  223.         test    al, al
  224.         jnz     @b
  225.         mov     dx, word [midisp]
  226.         mov     al, 0x3f
  227.         out     dx, al
  228.         ret
  229.  
  230. midi_output_byte:
  231.         ; output byte
  232. @@:
  233.         call    get_mpu_in
  234.         call    is_output
  235.         test    al, al
  236.         jnz     @b
  237.         mov     al, cl
  238.         call    put_mpu_out
  239.         ret
  240.  
  241. is_input:
  242.         push    edx
  243.         mov     dx, word [midisp]
  244.         in      al, dx
  245.         and     al, 0x80
  246.         pop     edx
  247.         ret
  248.  
  249. is_output:
  250.         push    edx
  251.         mov     dx, word [midisp]
  252.         in      al, dx
  253.         and     al, 0x40
  254.         pop     edx
  255.         ret
  256.  
  257. get_mpu_in:
  258.         push    edx
  259.         mov     dx, word [mididp]
  260.         in      al, dx
  261.         pop     edx
  262.         ret
  263.  
  264. put_mpu_out:
  265.         push    edx
  266.         mov     dx, word [mididp]
  267.         out     dx, al
  268.         pop     edx
  269.         ret
  270.  
  271.  
  272.  
  273.  
  274.  
  275. ; DATA AREA
  276.  
  277.  
  278. title    db   'MIDI TEST',0
  279.  
  280. buttont:
  281.     db   'PLAY A FEW NOTES'
  282. buttontlen:
  283. buttont2:
  284.     db   'RESET MIDI DEVICE'
  285. buttontlen2:
  286.  
  287. error1:
  288.     db   'NO BASE DEFINED FOR MPU-401'
  289. errorlen1:
  290.  
  291. error2:
  292.     db   'USE SETUP AND RESET MIDI DEVICE.'
  293. errorlen2:
  294.  
  295. base db 0x0
  296.  
  297. I_END:
  298.  
  299.  
  300.  
  301.