Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1845 | yogev_ezra | 1 | ; JMP2PAT.ASM |
2 | ; ----------- |
||
3 | ; Sometimes it makes sense merging various XM tracks |
||
4 | ; sharing the same instruments in a single XM file. |
||
5 | ; This example program uses such an XM file actually |
||
6 | ; containing 3 tracks and the _uFMOD_Jump2Pattern |
||
7 | ; function to play all 3 tracks in the same file. |
||
8 | |||
9 | ; A precompiled version (not packed or whatever) is |
||
10 | ; available in bin\ |
||
11 | |||
12 | use32 |
||
13 | org 0 |
||
14 | db 'MENUET01' |
||
15 | dd 1 |
||
16 | dd START ; Entry point |
||
17 | dd uFMOD_IMG_END ; End of code and initialized data |
||
18 | dd MEMORY_END ; End of uninitialized (BSS) data |
||
19 | dd STACK_B ; Bottom of the stack |
||
20 | dd 0 ; Args |
||
21 | dd 0 ; Reserved |
||
22 | |||
23 | ; uFMOD setup: |
||
24 | UF_FREQ equ 48000 ; Set sampling rate to 48KHz (22050, 44100, 48000) |
||
25 | UF_RAMP equ STRONG ; Select STRONG interpolation (NONE, WEAK, STRONG) |
||
26 | UD_MODE equ UNSAFE ; Select UNSAFE mode (NORMAL, UNSAFE) |
||
27 | DEBUG equ 0 ; Skip debug-board messages |
||
28 | NOLINKER equ 1 ; Select "no linker" mode |
||
29 | |||
30 | ; uFMOD constants: |
||
31 | XM_MEMORY = 1 |
||
32 | XM_FILE = 2 |
||
33 | XM_NOLOOP = 8 |
||
34 | XM_SUSPENDED = 16 |
||
35 | uFMOD_MIN_VOL = 0 |
||
36 | uFMOD_MAX_VOL = 25 |
||
37 | uFMOD_DEFAULT_VOL = 25 |
||
38 | |||
39 | ; BLITZXMK.XM tracked by Kim (aka norki): |
||
40 | ; [00:07] - track #1 |
||
41 | ; [08:10] - track #2 |
||
42 | ; [11:13] - track #3 |
||
43 | xm file '..\ufmodlib\media\BLITZXMK.XM' |
||
44 | xm_length = $ - xm |
||
45 | |||
46 | ; Optimization: |
||
47 | ; This header file is suitable for blitzxmk.xm track only! |
||
48 | ; If you change the track, update the optimization header. |
||
49 | ; (Use the standart eff.inc file for a general purpose player app.) |
||
50 | include '..\ufmodlib\media\blitz.eff.inc' |
||
51 | |||
52 | ; Include the GUI framework. |
||
53 | FRMWRK_CALLBACK_ON equ 0 ; Disable callback |
||
54 | include 'frmwrk.asm' |
||
55 | |||
56 | ; UI text messages. |
||
57 | vals dd 0,8,11 ; Preset pattern indexes |
||
58 | wnd_btns1 db "1 2 3 Pause " |
||
59 | wnd_btns2 db "1 2 3 Resume" |
||
60 | wnd_btns_l = $ - wnd_btns2 |
||
61 | wnd_cap db "Jump2Pattern",0 |
||
62 | err_txt db "Error" |
||
63 | err_txt_l = $ - err_txt |
||
64 | err_cap db ":-(",0 |
||
65 | |||
66 | START: |
||
67 | ; Start playback. |
||
68 | push XM_MEMORY |
||
69 | push xm_length |
||
70 | push xm |
||
71 | call _uFMOD_LoadSong |
||
72 | |||
73 | ; Stack fixing is required here, but in this simple |
||
74 | ; example leaving ESP as it is won't harm. In a real |
||
75 | ; application you should uncomment the following line: |
||
76 | ; add esp,12 |
||
77 | |||
78 | test eax,eax |
||
79 | jz error |
||
80 | xor ebp,ebp ; global 0 |
||
81 | mov [wnd_btns],wnd_btns1 |
||
82 | |||
83 | ; Switch keyboard mode to SCANCODE. |
||
84 | lea ebx,[ebp+1] |
||
85 | lea eax,[ebp+66] |
||
86 | mov ecx,ebx |
||
87 | int 40h |
||
88 | |||
89 | ; Get screen metrics. |
||
90 | lea eax,[ebp+14] |
||
91 | int 40h |
||
92 | mov ecx,eax |
||
93 | movzx eax,ax |
||
94 | shr ecx,16 ; screen w |
||
95 | xchg eax,edx ; screen h |
||
96 | mov ebx,wnd_btns_l*6+42 |
||
97 | sub ecx,ebx |
||
98 | shr ecx,1 |
||
99 | shl ecx,16 |
||
100 | or ebx,ecx |
||
101 | lea ecx,[ebp+40h] ; h = 40h |
||
102 | sub edx,ecx |
||
103 | shr edx,1 |
||
104 | shl edx,16 |
||
105 | or ecx,edx ; y = (screen h - window h) / 2 |
||
106 | mov edx,ebx ; x = (screen w - window w) / 2 |
||
107 | |||
108 | redraw: |
||
109 | ; Start redraw. |
||
110 | push edx |
||
111 | lea eax,[ebp+12] |
||
112 | lea ebx,[ebp+1] |
||
113 | int 40h |
||
114 | |||
115 | ; Define and draw window. |
||
116 | xor eax,eax |
||
117 | mov ebx,edx ; x, w (ECX: y, h) |
||
118 | mov edx,34C0C0C0h ; style and BG color |
||
119 | mov edi,wnd_cap |
||
120 | int 40h |
||
121 | |||
122 | ; Define the 1 2 3 Pause/Resume buttons. |
||
123 | lea eax,[ebp+8] |
||
124 | mov ebx,0A0012h ; x = 0Ah, w = 12h |
||
125 | mov ecx,0A0012h ; y = 0Ah, h = 10h |
||
126 | lea edx,[ebp+10] ; ID = #10 |
||
127 | mov esi,0C0C0C0h ; color |
||
128 | int 40h |
||
129 | mov ebx,280012h ; x = 28h, w = 12h |
||
130 | inc edx ; ID = #11 |
||
131 | int 40h |
||
132 | mov ebx,460012h ; x = 46h, w = 12h |
||
133 | inc edx ; ID = #12 |
||
134 | int 40h |
||
135 | mov ebx,640030h ; x = 64h, w = 30h |
||
136 | inc edx ; ID = #13 |
||
137 | int 40h |
||
138 | |||
139 | ; Draw the labels. |
||
140 | lea eax,[ebp+4] |
||
141 | mov ebx,120011h ; x = 12h, y = 11h |
||
142 | xor ecx,ecx ; style, font and color |
||
143 | mov edx,[wnd_btns] ; string |
||
144 | lea esi,[ebp+wnd_btns_l] ; length |
||
145 | int 40h |
||
146 | |||
147 | ; End redraw. |
||
148 | lea eax,[ebp+12] |
||
149 | lea ebx,[ebp+2] |
||
150 | int 40h |
||
151 | |||
152 | eventloop: |
||
153 | ; Update the PCM buffer. |
||
154 | call _uFMOD_WaveOut |
||
155 | |||
156 | lea eax,[ebp+23] |
||
157 | lea ebx,[ebp+10] ; wait for at most 0.1 sec |
||
158 | int 40h |
||
159 | dec eax |
||
160 | js eventloop ; 0 = idle |
||
161 | jz redraw ; 1 = redraw |
||
162 | |||
163 | dec eax ; 2 = keyboard event |
||
164 | jnz chk_eventbutton |
||
165 | |||
166 | ; Get key scancode. |
||
167 | lea eax,[ebp+2] |
||
168 | int 40h |
||
169 | cmp ah,19h ; P |
||
170 | je do_PauseResume |
||
171 | cmp ah,13h ; R |
||
172 | je do_PauseResume |
||
173 | chk_kb123: |
||
174 | movzx eax,ah |
||
175 | sub eax,2 |
||
176 | jmp do_Jump2Pat123 |
||
177 | |||
178 | chk_eventbutton: ; 3 = button event |
||
179 | lea eax,[ebp+17] |
||
180 | int 40h |
||
181 | cmp ah,1 ; Close |
||
182 | je break_loop |
||
183 | cmp ah,13 ; Pause/Resume |
||
184 | jne chk_btn123 |
||
185 | |||
186 | do_PauseResume: |
||
187 | cmp BYTE [paused],1 |
||
188 | mov edx,_uFMOD_Resume |
||
189 | mov ebx,wnd_btns1 |
||
190 | je do_Resume |
||
191 | mov edx,_uFMOD_Pause |
||
192 | mov ebx,wnd_btns2 |
||
193 | do_Resume: |
||
194 | call edx |
||
195 | xor BYTE [paused],1 |
||
196 | mov [wnd_btns],ebx |
||
197 | jmp redraw |
||
198 | |||
199 | chk_btn123: ; 1 2 3 |
||
200 | movzx eax,ah |
||
201 | sub eax,10 |
||
202 | |||
203 | do_Jump2Pat123: |
||
204 | cmp eax,3 |
||
205 | jae eventloop |
||
206 | push DWORD [vals+eax*4] |
||
207 | call _uFMOD_Jump2Pattern |
||
208 | pop eax ; fix stack |
||
209 | jmp eventloop |
||
210 | break_loop: |
||
211 | |||
212 | ; Stop playback. |
||
213 | call _uFMOD_StopSong |
||
214 | |||
215 | r: ; Exit. |
||
216 | xor eax,eax |
||
217 | dec eax |
||
218 | int 40h |
||
219 | |||
220 | error: |
||
221 | push err_txt_l ; cbString |
||
222 | push err_txt ; lpString |
||
223 | push err_cap ; szCap |
||
224 | call _MessageBox |
||
225 | ; add esp,16 |
||
226 | jmp r |
||
227 | |||
228 | ; Include the whole uFMOD sources here. (Right after |
||
229 | ; your main code to avoid naming conflicts, but still |
||
230 | ; inside your code section.) |
||
231 | macro PUBLIC symbol {} ; hide all publics |
||
232 | include '..\ufmodlib\src\fasm.asm' |
||
233 | |||
234 | wnd_btns dd ? |
||
235 | paused db ? |
||
236 | align 4 |
||
237 | rb 1020 |
||
238 | STACK_B dd ? ; Stack bottom |
||
239 | MEMORY_END: ; End of uninitialized (BSS) data |