DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
src/hardware/snd_pc98/sound/soundrom.c
00001 #include    "np2glue.h"
00002 //#include      "compiler.h"
00003 #include        "dosio.h"
00004 //#include      "cpucore.h"
00005 //#include      "pccore.h"
00006 #include        "soundrom.h"
00007 
00008 #define     mem     CGetMemBase()
00009 
00010         SOUNDROM        soundrom;
00011 
00012 
00013 static const OEMCHAR file_sound[] = OEMTEXT("sound");
00014 static const OEMCHAR file_extrom[] = OEMTEXT(".rom");
00015 static const UINT8 defsoundrom[9] = {
00016                                                         0x01,0x00,0x00,0x00,0xd2,0x00,0x08,0x00,0xcb};
00017 
00018 
00019 static BRESULT loadsoundrom(UINT address, const OEMCHAR *name) {
00020 
00021         OEMCHAR romname[24];
00022         OEMCHAR path[MAX_PATH];
00023         FILEH   fh;
00024         UINT    rsize;
00025 
00026         file_cpyname(romname, file_sound, NELEMENTS(romname));
00027         if (name) {
00028                 file_catname(romname, name, NELEMENTS(romname));
00029         }
00030         file_catname(romname, file_extrom, NELEMENTS(romname));
00031         getbiospath(path, romname, NELEMENTS(path));
00032         fh = file_open_rb(path);
00033         if (fh == FILEH_INVALID) {
00034                 goto lsr_err;
00035         }
00036         rsize = file_read(fh, mem + address, 0x4000);
00037         file_close(fh);
00038         if (rsize != 0x4000) {
00039                 goto lsr_err;
00040         }
00041         file_cpyname(soundrom.name, romname, NELEMENTS(soundrom.name));
00042         soundrom.address = address;
00043         if (address == 0xd0000) {
00044 //              CPU_RAM_D000 &= ~(0x0f << 0);
00045         }
00046         else if (address == 0xd4000) {
00047 //              CPU_RAM_D000 &= ~(0x0f << 4);
00048         }
00049         return(SUCCESS);
00050 
00051 lsr_err:
00052         return(FAILURE);
00053 }
00054 
00055 
00056 // ----
00057 
00058 void soundrom_reset(void) {
00059 
00060         ZeroMemory(&soundrom, sizeof(soundrom));
00061 }
00062 
00063 void soundrom_load(UINT32 address, const OEMCHAR *primary) {
00064 
00065         if (primary != NULL) {
00066                 if (loadsoundrom(address, primary) == SUCCESS) {
00067                         return;
00068                 }
00069         }
00070         if (loadsoundrom(address, NULL) == SUCCESS) {
00071                 return;
00072         }
00073         CopyMemory(mem + address + 0x2e00, defsoundrom, sizeof(defsoundrom));
00074         soundrom.name[0] = '\0';
00075         soundrom.address = address;
00076 }
00077 
00078 void soundrom_loadex(UINT sw, const OEMCHAR *primary) {
00079 
00080         if (sw < 4) {
00081                 soundrom_load((0xc8000 + ((UINT32)sw << 14)), primary);
00082         }
00083         else {
00084                 ZeroMemory(&soundrom, sizeof(soundrom));
00085         }
00086 }
00087