Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ; MINI.ASM
  2. ; --------
  3. ; Shows how to place data and code inside (!!!) the XM track.
  4.  
  5. .386
  6. .model flat
  7.  
  8. include ufmod.inc ; uFMOD API
  9.  
  10. .CODE
  11.  
  12. PE_BASE   db "MENUET01"
  13.           dd 1
  14.           dd OFFSET _START    ; Entry point
  15.           dd OFFSET BSS_START ; End of code and initialized data
  16.           dd OFFSET BSS_END   ; End of uninitialized (BSS) data
  17.           dd OFFSET STACK_B   ; Bottom of the stack
  18.           dd 0                ; Args
  19.           dd 0                ; Reserved
  20.  
  21. err_txt   db "Error"
  22. err_txt_l EQU $ - err_txt
  23.  
  24. _START:
  25.         ; Start playback.
  26.         push XM_MEMORY
  27.         push xm_length
  28.         push BYTE PTR xm
  29.  
  30. ; Let's place the stream right inside the code section.
  31. xm_length EQU 905
  32. xm        EQU $ - PE_BASE
  33. xm_unused_000 LABEL BYTE
  34.  
  35. ; *** The following 60 bytes are not used. So, we'll place
  36. ; *** some code here.
  37. ; (the actual size and location of such gaps may be
  38. ; found out using the Eff utility)
  39.  
  40.         call uFMOD_LoadSong
  41.         xor ebp,ebp             ; global 0
  42.  
  43.         ; Stack fixing is required here, but in this simple
  44.         ; example leaving ESP as it is won't harm. In a real
  45.         ; application you should uncomment the following line:
  46.         ; add esp,12
  47.  
  48.         test eax,eax
  49.         jz error
  50.  
  51.         ; Wait for user input.
  52.         push uFMOD_WaveOut      ; cbProc <- continue fetching data!
  53.         push BYTE PTR msg_txt_l ; cbString
  54.         push OFFSET msg_txt     ; lpString
  55.         push OFFSET msg_cap     ; szCap
  56.         call MessageBoxCB
  57.         ; add esp,16
  58.  
  59.         ; Stop playback.
  60.         call uFMOD_StopSong
  61.  
  62. r:      ; Exit.
  63.         lea eax,[ebp-1]
  64.         int 40h
  65.  
  66. error:
  67.         push ebp                          ; cbProc <- no callback
  68.         push BYTE PTR err_txt_l           ; cbString
  69.         push BYTE PTR (err_txt - PE_BASE) ; lpString
  70.         push OFFSET err_cap               ; szCap
  71.         call MessageBoxCB
  72.         ; add esp,16
  73.         jmp r
  74.  
  75. org xm_unused_000 + 60
  76.         db 034h,000h,000h,000h,020h,000h,000h,000h,002h,000h,00Dh,000h,001h,000h,001h,000h
  77.         db 00Ah,000h,091h,000h,000h,001h,002h,003h,004h,005h,006h,007h,000h,001h,002h,003h
  78.         db 004h,005h,006h,007h,008h,009h,00Ah,00Bh,008h,009h,00Ch,00Bh,008h,009h,00Ah,00Bh
  79.         db 008h,009h,00Ch,00Bh,009h,000h,000h,000h,000h,004h,000h,001h,000h,083h,016h,001h
  80.         db 080h,080h,02Eh,001h,000h,00Eh,060h,080h,03Ah,001h,000h,00Eh,062h,081h,061h,083h
  81.         db 035h,001h,009h,000h,000h,000h,000h,004h,000h,001h,000h,083h,016h,001h,080h,080h
  82.         db 02Eh,001h,000h,00Eh,060h,080h,035h,001h,000h,00Eh,062h,081h,061h,083h,038h,001h
  83.         db 009h,000h,000h,000h,000h,004h,000h,001h,000h,083h,016h,001h,080h,080h,02Eh,001h
  84.         db 000h,00Eh,060h,080h,038h,001h,000h,00Eh,062h,080h,083h,033h,001h,009h,000h,000h
  85.         db 000h,000h,006h,000h,001h,000h,083h,016h,001h,080h,080h,02Eh,001h,000h,00Eh,060h
  86.         db 080h,033h,001h,000h,00Eh,061h,081h,061h,083h,035h,001h,083h,00Dh,001h,083h,036h
  87.         db 001h,080h,083h,036h,001h,009h,000h,000h,000h,000h,004h,000h,001h,000h,083h,00Fh
  88.         db 001h,080h,080h,02Eh,001h,000h,00Eh,060h,080h,036h,001h,000h,00Eh,062h,081h,061h
  89.         db 083h,033h,001h,009h,000h,000h,000h,000h,006h,000h,001h,000h,083h,00Fh,001h,080h
  90.         db 080h,02Eh,001h,000h,00Eh,060h,080h,033h,001h,000h,00Eh,061h,081h,061h,083h,02Eh
  91.         db 001h,083h,012h,001h,083h,033h,001h,080h,083h,035h,001h,009h,000h,000h,000h,000h
  92.         db 006h,000h,001h,000h,083h,016h,001h,080h,080h,02Eh,001h,000h,00Eh,060h,080h,035h
  93.         db 001h,000h,00Eh,061h,081h,061h,083h,02Eh,001h,083h,00Dh,001h,083h,031h,001h,080h
  94.         db 083h,02Eh,001h,009h,000h,000h,000h,000h,008h,000h,001h,000h,083h,012h,001h,098h
  95.         db 00Ah,001h,083h,019h,001h,088h,00Ah,083h,01Eh,001h,081h,061h,083h,012h,001h,080h
  96.         db 083h,014h,001h,080h,083h,01Bh,001h,080h,083h,020h,001h,080h,083h,014h,001h,080h
  97.         db 009h,000h,000h,000h,000h,008h,000h,001h,000h,083h,012h,001h,081h,061h,083h,019h
  98.         db 001h,080h,083h,01Eh,001h,080h,083h,012h,001h,080h,083h,019h,001h,083h,031h,001h
  99.         db 083h,01Eh,001h,080h,083h,012h,001h,083h,031h,001h,083h,019h,001h,080h,009h,000h
  100.         db 000h,000h,000h,008h,000h,001h,000h,083h,014h,001h,083h,033h,001h,083h,01Bh,001h
  101.         db 080h,083h,020h,001h,083h,031h,001h,083h,014h,001h,080h,083h,01Bh,001h,083h,030h
  102.         db 001h,083h,020h,001h,080h,083h,014h,001h,083h,031h,001h,083h,01Bh,001h,080h,009h
  103.         db 000h,000h,000h,000h,008h,000h,001h,000h,083h,016h,001h,083h,030h,001h,083h,01Dh
  104.         db 001h,083h,031h,001h,083h,022h,001h,083h,035h,001h,083h,016h,001h,098h,00Ah,001h
  105.         db 083h,01Dh,001h,088h,00Ah,083h,022h,001h,081h,061h,083h,016h,001h,080h,083h,01Dh
  106.         db 001h,080h,009h,000h,000h,000h,000h,008h,000h,001h,000h,083h,016h,001h,080h,083h
  107.         db 01Dh,001h,080h,083h,022h,001h,080h,083h,016h,001h,080h,083h,018h,001h,080h,083h
  108.         db 01Dh,001h,080h,083h,011h,001h,080h,083h,018h,001h,080h,009h,000h,000h,000h,000h
  109.         db 008h,000h,001h,000h,083h,016h,001h,083h,030h,001h,083h,01Dh,001h,083h,031h,001h
  110.         db 083h,019h,001h,083h,02Eh,001h,083h,016h,001h,098h,00Ah,001h,083h,01Dh,001h,088h
  111.         db 00Ah,083h,019h,001h,081h,061h,083h,016h,001h,080h,083h,01Dh,001h,080h,0F1h,000h
  112.         db 000h,000h
  113. xm_unused_001 LABEL BYTE
  114.  
  115. ; The following 23 bytes are not used.
  116. ; So, let's place the MessageBox text and caption instead.
  117. ; UI text messages.
  118. msg_txt   db "uFMOD ruleZ!"
  119. msg_txt_l equ $ - msg_txt
  120. msg_cap   db "MASM32",0
  121. err_cap   db ":-(",0
  122.  
  123. org xm_unused_001 + 23
  124.         db 001h,000h,012h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  125.         db 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  126.         db 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  127.         db 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  128.         db 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  129.         db 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h
  130.         db 000h,000h,000h,000h,000h,000h,000h,000h,040h,000h,008h,000h,02Ch,000h,00Eh,000h
  131.         db 008h,000h,018h,000h,016h,000h,020h,000h,008h,000h,02Dh,000h,00Dh,000h,032h,000h
  132.         db 004h,000h,03Ch,000h,007h,000h,044h,000h,004h,000h,05Ah,000h,000h,000h,064h,000h
  133.         db 000h,000h,06Eh,000h,000h,000h,000h,000h,020h,000h,00Ah,000h,028h,000h,01Eh,000h
  134.         db 018h,000h,032h,000h,020h,000h,03Ch,000h,020h,000h,046h,000h,020h,000h,050h,000h
  135.         db 020h,000h,05Ah,000h,020h,000h,064h,000h,020h,000h,06Eh,000h,020h,000h,078h,000h
  136.         db 020h,000h,082h,000h,020h,000h,009h,006h,001h,002h,004h,002h,003h,005h,001h,000h
  137.         db 000h,000h,000h,000h,080h,000h,00Ch,000h,000h,000h,000h,000h,000h,000h,00Ch,000h
  138.         db 000h,000h,040h,000h,001h,080h,0F9h,000h,0BFh,000h,0C3h,000h,00Ah,000h,057h,000h
  139.         db 06Eh,000h,023h,000h
  140.  
  141. ; ----------------------------------------------------------
  142. ; void MessageBoxCB(szCap, lpString, cbString, cbProc);
  143. ; ----------------------------------------------------------
  144.  
  145. ; This is similar to a Win32 MessageBox. The box is centered
  146. ; on screen. It contains a single-line text message and an
  147. ; "OK" button. This function returns when user closes the
  148. ; box (via the X button or via the OK button). An optional
  149. ; callback subroutine may be specified to be called when no
  150. ; events are pending in the event queue.
  151.  
  152. ; NOTE: Doesn't work if you already have defined a window
  153. ; in the current process! Doesn't modify the event mask. So,
  154. ; make sure keyboard events are enabled before calling this
  155. ; function. This function doesn't check the validity of the
  156. ; supplied parameters!
  157.  
  158. ; Parameters:
  159. ; szCap     - A pointer to the ASCIIz string containing the
  160. ;             caption. A trailing zero char IS required.
  161. ; lpString  - A pointer to an ASCII string containing a single
  162. ;             line message to pop up in the box. No trailing
  163. ;             zero char is required.
  164. ; cbString  - number of characters in string.
  165. ; cbProc    - Address of the callback subroutine. Can be NULL.
  166.  
  167. sOK db "OK"
  168. MessageBoxCB:
  169. ; EBP = 0
  170.         mov esi,[esp+12] ; cbString
  171.         mov edi,[esp+4]  ; szCap
  172.  
  173.         ; Get screen metrics.
  174.         lea eax,[ebp+14]
  175.         int 40h
  176.         mov ecx,eax
  177.         movzx eax,ax
  178.         shr ecx,16         ; screen w
  179.         xchg eax,edx       ; screen h
  180.         lea ebx,[esi*2+esi]
  181.         lea ebx,[ebx*2+28] ; w = string len * 6 + 28
  182.         sub ecx,ebx
  183.         shr ecx,1
  184.         shl ecx,16
  185.         or ebx,ecx
  186.         lea ecx,[ebp+52h]  ; h = 52h
  187.         sub edx,ecx
  188.         shr edx,1
  189.         shl edx,16
  190.         or ecx,edx         ; y = (screen h - window h) / 2
  191.         mov edx,ebx        ; x = (screen w - window w) / 2
  192.  
  193. _MessageBoxCB_redraw:
  194.         ; Start redraw.
  195.         push edx
  196.         lea eax,[ebp+12]
  197.         lea ebx,[ebp+1]
  198.         int 40h
  199.  
  200.         ; Define and draw window.
  201.         xor eax,eax
  202.         mov ebx,edx        ; x, w (ECX: y, h)
  203.         mov edx,34C0C0C0h  ; style and BG color
  204.         int 40h
  205.  
  206.         ; Define the OK button.
  207.         push esi
  208.         lea eax,[ebp+8]
  209.         sub ebx,28+0Ah
  210.         shr bx,1
  211.         shl ebx,16         ; x = (window w - button w) / 2
  212.         mov bx,18+0Ah      ; w = 18 + 0Ah
  213.         mov ecx,001C0012h  ; y = 1Ch, h = 12h
  214.         lea edx,[ebp+1]    ; ID = close
  215.         mov esi,0C0C0C0h   ; color
  216.         int 40h
  217.  
  218.         ; Draw the OK label.
  219.         lea eax,[ebp+4]
  220.         add ebx,90000h     ; x = button x + 9
  221.         mov bx,22h         ; y = 22h
  222.         xor ecx,ecx        ; style, font and color
  223.         mov edx,OFFSET sOK ; string
  224.         lea esi,[ebp+2]    ; length
  225.         int 40h
  226.         pop esi
  227.  
  228.         ; Draw text string.
  229.         lea eax,[ebp+4]
  230.         mov ebx,000A000Ah  ; x = 0Ah, y = 0Ah
  231.         xor ecx,ecx        ; style, font and color
  232.         mov edx,[esp+12]   ; lpString
  233.         int 40h
  234.  
  235.         ; End redraw.
  236.         lea eax,[ebp+12]
  237.         lea ebx,[ebp+2]
  238.         int 40h
  239.  
  240. _MessageBoxCB_eventloop:
  241.         mov edx,[esp+20]   ; cbProc
  242.         test edx,edx
  243.         lea eax,[ebp+10]
  244.         jz _MessageBoxCB_peekevent
  245.  
  246.         ; Invoke the callback.
  247.         call edx
  248.  
  249.         lea eax,[ebp+23]
  250.         lea ebx,[ebp+10] ; wait for at most 0.1 sec
  251. _MessageBoxCB_peekevent:
  252.         int 40h
  253.         dec eax
  254.         js _MessageBoxCB_eventloop
  255.  
  256.         pop edx
  257.         jz _MessageBoxCB_redraw
  258.         ret
  259.  
  260. .DATA?
  261. BSS_START LABEL BYTE
  262.           db 1020 dup (?)
  263. STACK_B   dd ? ; Stack bottom
  264. BSS_END   LABEL BYTE
  265.  
  266. END _START