]> 4ch.mooo.com Git - 16.git/blob - 16/adplug/adplug/test/emutest.cpp
wwww~
[16.git] / 16 / adplug / adplug / test / emutest.cpp
1 /*
2  * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3  * Copyright (C) 1999 - 2005 Simon Peter, <dn.tlp@gmx.net>, et al.
4  * 
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * 
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * emutest.cpp - Test AdPlug emulators, by Simon Peter <dn.tlp@gmx.net>
20  */
21
22 #include <stdlib.h>
23 #include <stdio.h>
24
25 #include "../src/emuopl.h"
26
27 /***** Local variables *****/
28
29 // String holding the relative path to the source directory
30 static char *srcdir;
31
32 /***** Local functions *****/
33
34 #define BUF_SIZE        1024
35
36 static bool check_emu_output(CEmuopl *emu)
37   /*
38    * Test if the emulator produces any output.
39    */
40 {
41   short *buf = (short *)calloc(BUF_SIZE, sizeof(short));
42   bool  nonull = false, no10k = true, nom10k = true;
43
44   // init emulator
45   emu->init();
46   emu->write(1, 5 << 1);
47
48   // set test instrument
49   emu->write(0x20, 1);
50   emu->write(0x40, 0x10);
51   emu->write(0x60, 0xf0);
52   emu->write(0x80, 0x77);
53   emu->write(0xa0, 0x98);
54   emu->write(0x23, 1);
55   emu->write(0x43, 0);
56   emu->write(0x63, 0xf0);
57   emu->write(0x83, 0x77);
58   emu->write(0xb0, 0x31);
59
60   // check output from emu
61   emu->update(buf, BUF_SIZE);
62   for(int i = 0; i < BUF_SIZE; i++) {
63     if(buf[i] != 0) nonull = true;
64     if(buf[i] > 10000) no10k = false;
65     if(buf[i] < -10000) nom10k = false;
66   }
67
68   free(buf);
69
70   return (nonull && no10k && nom10k);
71 }
72
73 /***** Main program *****/
74
75 int main(int argc, char *argv[])
76 {
77   bool  retval = true;
78
79   // Set path to source directory
80   srcdir = getenv("srcdir");
81   if(!srcdir) srcdir = ".";
82
83   {
84     CEmuopl emu(8000, true, false);
85     retval = check_emu_output(&emu);
86   }
87
88   return retval ? EXIT_SUCCESS : EXIT_FAILURE;
89 }