OSDN Git Service

no idea how to get joy buttons 2 and 3 to function.
[proj16/16.git] / src / imfplay.c
1 /* midi.c
2  *
3  * Adlib OPL2/OPL3 FM synthesizer chipset test program.
4  * Play MIDI file using the OPLx synthesizer (well, poorly anyway)
5  * (C) 2010-2012 Jonathan Campbell.
6  * Hackipedia DOS library.
7  *
8  * This code is licensed under the LGPL.
9  * <insert LGPL legal text here>
10  *
11  * Compiles for intended target environments:
12  *   - MS-DOS [pure DOS mode, or Windows or OS/2 DOS Box]
13  */
14
15 #include "src/lib/16_head.h"
16 #include "src/lib/16_tail.h"
17 #include "src/lib/16_pm.h"
18 #include "src/lib/16_ca.h"
19 #include "src/lib/16_mm.h"
20 #include "src/lib/16_hc.h"
21 #include "src/lib/16_dbg.h"
22 #include "src/lib/16_snd.h"
23
24 extern struct glob_game_vars    *ggvv;
25
26 void main(int argc,char **argv) {
27         static global_game_variables_t gvar;
28         unsigned long adv;
29         int c;
30 #ifdef __DEBUG_CA__
31         dbg_debugca=1;
32 #endif
33 #ifdef __DEBUG_MM_
34         dbg_debugmm=1;
35 #endif
36         ggvv=&gvar;
37         StartupCAMMPM(&gvar);
38         printf("ADLIB FM test program IMFPLAY\n");
39         if (argc < 2) {
40                 printf("You must specify an IMF file to play\n"); ShutdownCAMMPM(&gvar);
41                 return;
42         }
43
44         SD_Initimf(&gvar);
45
46         if (!SD_imf_load_music(argv[1], &gvar)) {
47                 printf("Failed to load IMF Music\n"); ShutdownCAMMPM(&gvar);
48                 return;
49         }
50
51         SD_StartupTimer(&gvar);
52
53         printf("playing!\n");
54         while (1) {
55                 _cli();
56                 adv = gvar.ca.sd.irq0_ticks - gvar.ca.sd.ptick;
57                 if (adv >= 100UL) adv = 100UL;
58                 gvar.ca.sd.ptick = gvar.ca.sd.irq0_ticks;
59                 _sti();
60
61                 while (adv != 0) {
62                         SD_imf_tick(&gvar);
63                         adv--;
64                 }
65
66                 if (kbhit()) {
67                         c = getch();
68                         if (c == 0) c = getch() << 8;
69
70                         if (c == 27) {
71                                 break;
72                         }
73                 }
74         }
75 //0000  printf("contents of the imf_music\n[\n%s\n]\n", gvar.ca.sd.imf_music);
76
77         SD_imf_free_music(&gvar);
78         SD_adlib_shut_up();
79         shutdown_adlib();
80         SD_ShutdownTimer();
81         write_8254_system_timer(0);     /* back to normal 18.2Hz */
82         ShutdownCAMMPM(&gvar);
83 }