From 878959a0aa6b5dc5d69045f593331edb95743aee Mon Sep 17 00:00:00 2001 From: krcroft Date: Tue, 21 Jan 2020 18:59:35 -0800 Subject: [PATCH] Formatting and review fixes --- src/dos/cdrom_image.cpp | 17 +- src/dos/dos_programs.cpp | 132 +++++------ src/hardware/mame/fmopl.cpp | 232 +++++++++---------- src/hardware/mame/ymf262.cpp | 421 ++++++++++++++++++----------------- src/hardware/memory.cpp | 34 ++- src/misc/programs.cpp | 30 +-- src/shell/shell_cmds.cpp | 258 ++++++++++----------- 7 files changed, 571 insertions(+), 553 deletions(-) diff --git a/src/dos/cdrom_image.cpp b/src/dos/cdrom_image.cpp index 188e8afa..2896295c 100644 --- a/src/dos/cdrom_image.cpp +++ b/src/dos/cdrom_image.cpp @@ -624,7 +624,7 @@ bool CDROM_Interface_Image::ReadSectors(PhysPt buffer, bool raw, unsigned long s Bit8u* buf = new Bit8u[buflen]; bool success = true; //Gobliiins reads 0 sectors - for(unsigned long i = 0; i < num; i++) { + for (unsigned long i = 0; i < num; i++) { success = ReadSector(&buf[i * sectorSize], raw, sector + i); if (!success) { break; @@ -661,7 +661,7 @@ track_iter CDROM_Interface_Image::GetTrack(const int sector) // (start + length). track_iter track(tracks.begin()); int lower_bound = track->start; - while(track != tracks.end()) { + while (track != tracks.end()) { const int upper_bound = track->start + track->length; if (lower_bound <= sector && sector < upper_bound) { break; @@ -804,10 +804,10 @@ bool CDROM_Interface_Image::LoadIsoFile(char* filename) // try to detect iso type if (CanReadPVD(track.file.get(), BYTES_PER_COOKED_REDBOOK_FRAME, false)) { track.sectorSize = BYTES_PER_COOKED_REDBOOK_FRAME; - // track.mode2 = false (comment only, because this is the default value) + assert(track.mode2 == false); } else if (CanReadPVD(track.file.get(), BYTES_PER_RAW_REDBOOK_FRAME, false)) { track.sectorSize = BYTES_PER_RAW_REDBOOK_FRAME; - // track.mode2 = false (comment only, because this is the default value) + assert(track.mode2 == false); } else if (CanReadPVD(track.file.get(), 2336, true)) { track.sectorSize = 2336; track.mode2 = true; @@ -888,7 +888,7 @@ bool CDROM_Interface_Image::LoadCueSheet(char *cuefile) return false; } - while(!in.eof()) { + while (!in.eof()) { // get next line char buf[MAX_LINE_LENGTH]; in.getline(buf, MAX_LINE_LENGTH); @@ -1071,7 +1071,7 @@ bool CDROM_Interface_Image::AddTrack(Track &curr, int &shift, const int prestart bool CDROM_Interface_Image::HasDataTrack(void) { //Data track has attribute 0x40 - for(const auto &track : tracks) { + for (const auto &track : tracks) { if (track.attr == 0x40) { return true; } @@ -1139,8 +1139,9 @@ bool CDROM_Interface_Image::GetRealFileName(string &filename, string &pathname) bool CDROM_Interface_Image::GetCueKeyword(string &keyword, istream &in) { in >> keyword; - for(Bitu i = 0; i < keyword.size(); i++) keyword[i] = toupper(keyword[i]); - + for (Bitu i = 0; i < keyword.size(); i++) { + keyword[i] = toupper(keyword[i]); + } return true; } diff --git a/src/dos/dos_programs.cpp b/src/dos/dos_programs.cpp index e68d5603..c81dc6f5 100644 --- a/src/dos/dos_programs.cpp +++ b/src/dos/dos_programs.cpp @@ -103,7 +103,7 @@ public: std::string line = ""; char ppp[2] = {newz_drive,0}; std::string tempenv = ppp; tempenv += ":\\"; - if (first_shell->GetEnvStr("PATH",line)){ + if (first_shell->GetEnvStr("PATH",line)) { std::string::size_type idx = line.find('='); std::string value = line.substr(idx +1 , std::string::npos); while ( (idx = value.find("Z:\\")) != std::string::npos || @@ -117,9 +117,9 @@ public: first_shell->SetEnv("COMSPEC",tempenv.c_str()); /* Update batch file if running from Z: (very likely: autoexec) */ - if(first_shell->bf) { + if (first_shell->bf) { std::string &name = first_shell->bf->filename; - if(name.length() >2 && name[0] == 'Z' && name[1] == ':') name[0] = newz_drive; + if (name.length() > 2 && name[0] == 'Z' && name[1] == ':') name[0] = newz_drive; } /* Change the active drive */ if (DOS_GetDefaultDrive() == 25) DOS_SetDrive(i_newz); @@ -134,7 +134,7 @@ public: WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_1")); WriteOut(MSG_Get("PROGRAM_MOUNT_STATUS_FORMAT"),"Drive","Type","Label"); - for(int p = 0;p < 8;p++) WriteOut("----------"); + for (int p = 0;p < 8;p++) WriteOut("----------"); for (int d = 0; d < DOS_DRIVES; d++) { if (!Drives[d]) continue; @@ -172,7 +172,7 @@ public: /* In secure mode don't allow people to change mount points. * Neither mount nor unmount */ - if(control->SecureMode()) { + if (control->SecureMode()) { WriteOut(MSG_Get("PROGRAM_CONFIG_SECURE_DISALLOW")); return; } @@ -221,7 +221,7 @@ public: } /* Parse the free space in mb's (kb's for floppies) */ std::string mb_size; - if(cmd->FindString("-freesize",mb_size,true)) { + if (cmd->FindString("-freesize",mb_size,true)) { char teststr[1024]; Bit16u freesize = static_cast(atoi(mb_size.c_str())); if (type=="floppy") { @@ -257,7 +257,7 @@ public: // get the drive letter cmd->FindCommand(1,temp_line); - if ((temp_line.size() > 2) || ((temp_line.size()>1) && (temp_line[1]!=':'))) goto showusage; + if ((temp_line.size() > 2) || ((temp_line.size() > 1) && (temp_line[1]!=':'))) goto showusage; int i_drive = toupper(temp_line[0]); if (!isalpha(i_drive)) { @@ -284,10 +284,10 @@ public: if (!temp_line.size()) { goto showusage; } - if(path_relative_to_last_config && control->configfiles.size() && !Cross::IsPathAbsolute(temp_line)) { - std::string lastconfigdir(control->configfiles[control->configfiles.size()-1]); + if (path_relative_to_last_config && control->configfiles.size() && !Cross::IsPathAbsolute(temp_line)) { + std::string lastconfigdir(control->configfiles[control->configfiles.size() - 1]); std::string::size_type pos = lastconfigdir.rfind(CROSS_FILESPLIT); - if(pos == std::string::npos) { + if (pos == std::string::npos) { pos = 0; //No directory then erase string } lastconfigdir.erase(pos); @@ -301,16 +301,16 @@ public: bool failed = false; #if defined (WIN32) /* Removing trailing backslash if not root dir so stat will succeed */ - if(temp_line.size() > 3 && temp_line[temp_line.size()-1]=='\\') temp_line.erase(temp_line.size()-1,1); + if (temp_line.size() > 3 && temp_line[temp_line.size() - 1]=='\\') temp_line.erase(temp_line.size() - 1, 1); if (stat(temp_line.c_str(),&test)) { #else if (stat(temp_line.c_str(),&test)) { failed = true; Cross::ResolveHomedir(temp_line); //Try again after resolving ~ - if(!stat(temp_line.c_str(),&test)) failed = false; + if (!stat(temp_line.c_str(),&test)) failed = false; } - if(failed) { + if (failed) { #endif WriteOut(MSG_Get("PROGRAM_MOUNT_ERROR_1"),temp_line.c_str()); return; @@ -321,7 +321,7 @@ public: return; } - if (temp_line[temp_line.size()-1]!=CROSS_FILESPLIT) temp_line+=CROSS_FILESPLIT; + if (temp_line[temp_line.size() - 1] != CROSS_FILESPLIT) temp_line += CROSS_FILESPLIT; Bit8u bit8size=(Bit8u) sizes[1]; if (type == "cdrom") { @@ -350,13 +350,13 @@ public: } else { /* Give a warning when mount c:\ or the / */ #if defined (WIN32) - if( (temp_line == "c:\\") || (temp_line == "C:\\") || + if ( (temp_line == "c:\\") || (temp_line == "C:\\") || (temp_line == "c:/") || (temp_line == "C:/") ) WriteOut(MSG_Get("PROGRAM_MOUNT_WARNING_WIN")); #else - if(temp_line == "/") WriteOut(MSG_Get("PROGRAM_MOUNT_WARNING_OTHER")); + if (temp_line == "/") WriteOut(MSG_Get("PROGRAM_MOUNT_WARNING_OTHER")); #endif - if(type == "overlay") { + if (type == "overlay") { localDrive* ldp = dynamic_cast(Drives[drive - 'A']); cdromDrive* cdp = dynamic_cast(Drives[drive - 'A']); if (!ldp || cdp) { @@ -399,14 +399,14 @@ public: /* For hard drives set the label to DRIVELETTER_Drive. * For floppy drives set the label to DRIVELETTER_Floppy. * This way every drive except cdroms should get a label.*/ - else if(type == "dir" || type == "overlay") { + else if (type == "dir" || type == "overlay") { label = drive; label += "_DRIVE"; newdrive->dirCache.SetLabel(label.c_str(),iscdrom,false); - } else if(type == "floppy") { + } else if (type == "floppy") { label = drive; label += "_FLOPPY"; newdrive->dirCache.SetLabel(label.c_str(),iscdrom,true); } - if(type == "floppy") incrementFDD(); + if (type == "floppy") incrementFDD(); return; showusage: #if defined (WIN32) @@ -508,10 +508,10 @@ private: try { ldp=dynamic_cast(Drives[drive]); - if(!ldp) return NULL; + if (!ldp) return NULL; tmpfile = ldp->GetSystemFilePtr(fullname, "rb"); - if(tmpfile == NULL) { + if (tmpfile == NULL) { if (!tryload) *error=1; return NULL; } @@ -523,12 +523,12 @@ private: fclose(tmpfile); tmpfile = ldp->GetSystemFilePtr(fullname, "rb+"); - if(tmpfile == NULL) { + if (tmpfile == NULL) { // if (!tryload) *error=2; // return NULL; WriteOut(MSG_Get("PROGRAM_BOOT_WRITE_PROTECTED")); tmpfile = ldp->GetSystemFilePtr(fullname, "rb"); - if(tmpfile == NULL) { + if (tmpfile == NULL) { if (!tryload) *error=1; return NULL; } @@ -544,16 +544,16 @@ private: FILE *getFSFile(char const * filename, Bit32u *ksize, Bit32u *bsize,bool tryload=false) { Bit8u error = tryload?1:0; FILE* tmpfile = getFSFile_mounted(filename,ksize,bsize,&error); - if(tmpfile) return tmpfile; + if (tmpfile) return tmpfile; //File not found on mounted filesystem. Try regular filesystem std::string filename_s(filename); Cross::ResolveHomedir(filename_s); tmpfile = fopen_wrap(filename_s.c_str(),"rb+"); - if(!tmpfile) { - if( (tmpfile = fopen_wrap(filename_s.c_str(),"rb")) ) { + if (!tmpfile) { + if ( (tmpfile = fopen_wrap(filename_s.c_str(),"rb")) ) { //File exists; So can't be opened in correct mode => error 2 // fclose(tmpfile); -// if(tryload) error = 2; +// if (tryload) error = 2; WriteOut(MSG_Get("PROGRAM_BOOT_WRITE_PROTECTED")); fseek(tmpfile,0L, SEEK_END); *ksize = (ftell(tmpfile) / 1024); @@ -561,8 +561,8 @@ private: return tmpfile; } // Give the delayed errormessages from the mounted variant (or from above) - if(error == 1) WriteOut(MSG_Get("PROGRAM_BOOT_NOT_EXIST")); - if(error == 2) WriteOut(MSG_Get("PROGRAM_BOOT_NOT_OPEN")); + if (error == 1) WriteOut(MSG_Get("PROGRAM_BOOT_NOT_EXIST")); + if (error == 2) WriteOut(MSG_Get("PROGRAM_BOOT_NOT_OPEN")); return NULL; } fseek(tmpfile,0L, SEEK_END); @@ -595,7 +595,7 @@ public: ChangeToLongCmd(); /* In secure mode don't allow people to boot stuff. * They might try to corrupt the data on it */ - if(control->SecureMode()) { + if (control->SecureMode()) { WriteOut(MSG_Get("PROGRAM_CONFIG_SECURE_DISALLOW")); return; } @@ -609,16 +609,16 @@ public: Bit8u drive = 'A'; std::string cart_cmd=""; - if(!cmd->GetCount()) { + if (!cmd->GetCount()) { printError(); return; } - while(iGetCount()) { - if(cmd->FindCommand(i+1, temp_line)) { - if((temp_line == "-l") || (temp_line == "-L")) { + while (iGetCount()) { + if (cmd->FindCommand(i+1, temp_line)) { + if ((temp_line == "-l") || (temp_line == "-L")) { /* Specifying drive... next argument then is the drive */ i++; - if(cmd->FindCommand(i+1, temp_line)) { + if (cmd->FindCommand(i+1, temp_line)) { drive=toupper(temp_line[0]); if ((drive != 'A') && (drive != 'C') && (drive != 'D')) { printError(); @@ -633,11 +633,11 @@ public: continue; } - if((temp_line == "-e") || (temp_line == "-E")) { + if ((temp_line == "-e") || (temp_line == "-E")) { /* Command mode for PCJr cartridges */ i++; - if(cmd->FindCommand(i + 1, temp_line)) { - for(size_t ct = 0;ct < temp_line.size();ct++) temp_line[ct] = toupper(temp_line[ct]); + if (cmd->FindCommand(i + 1, temp_line)) { + for (size_t ct = 0;ct < temp_line.size();ct++) temp_line[ct] = toupper(temp_line[ct]); cart_cmd = temp_line; } else { printError(); @@ -653,7 +653,7 @@ public: WriteOut(MSG_Get("PROGRAM_BOOT_IMAGE_OPEN"), temp_line.c_str()); Bit32u rombytesize; FILE *usefile = getFSFile(temp_line.c_str(), &floppysize, &rombytesize); - if(usefile != NULL) { + if (usefile != NULL) { diskSwap[i].reset(new imageDisk(usefile, temp_line.c_str(), floppysize, false)); if (usefile_1==NULL) { usefile_1=usefile; @@ -762,7 +762,7 @@ public: fseek(tfile, 0x3000L, SEEK_SET); Bit32u drd=(Bit32u) fread(rombuf, 1, 0xb000, tfile); if (drd==0xb000) { - for(i=0;i<0xb000;i++) phys_writeb(0xf3000+i,rombuf[i]); + for ( i = 0; i < 0xb000; i++) phys_writeb(0xf3000 + i, rombuf[i]); } fclose(tfile); } @@ -788,7 +788,7 @@ public: //fclose(usefile_2); //usefile_2 is in diskSwap structure which should be deleted to close the file /* write cartridge data into ROM */ - for(i=0;itcount=true; @@ -892,10 +892,10 @@ public: try { /* try to read ROM file into buffer */ ldp=dynamic_cast(Drives[drive]); - if(!ldp) return; + if (!ldp) return; FILE *tmpfile = ldp->GetSystemFilePtr(fullname, "rb"); - if(tmpfile == NULL) { + if (tmpfile == NULL) { WriteOut(MSG_Get("PROGRAM_LOADROM_CANT_OPEN")); return; } @@ -1056,7 +1056,7 @@ void LOADFIX::Run(void) args[0] = 0; do { ok = cmd->FindCommand(commandNr++,temp_line); - if(sizeof(args)-strlen(args)-1 < temp_line.length()+1) + if (sizeof(args) - strlen(args) - 1 < temp_line.length() + 1) break; strcat(args,temp_line.c_str()); strcat(args," "); @@ -1089,7 +1089,7 @@ void RESCAN::Run(void) Bit8u drive = DOS_GetDefaultDrive(); - if(cmd->FindCommand(1,temp_line)) { + if (cmd->FindCommand(1,temp_line)) { //-A -All /A /All if (temp_line.size() >= 2 && (temp_line[0] == '-' || @@ -1098,14 +1098,14 @@ void RESCAN::Run(void) temp_line[1] == 'A') ) { all = true; } - else if(temp_line.size() == 2 && temp_line[1] == ':') { + else if (temp_line.size() == 2 && temp_line[1] == ':') { lowcase(temp_line); drive = temp_line[0] - 'a'; } } // Get current drive if (all) { - for(Bitu i =0; iEmptyCache(); } WriteOut(MSG_Get("PROGRAM_RESCAN_SUCCESS")); @@ -1137,17 +1137,17 @@ public: void Run(void) { /* Only run if called from the first shell (Xcom TFTD runs any intro file in the path) */ - if(DOS_PSP(dos.psp()).GetParent() != DOS_PSP(DOS_PSP(dos.psp()).GetParent()).GetParent()) return; - if(cmd->FindExist("cdrom",false)) { + if (DOS_PSP(dos.psp()).GetParent() != DOS_PSP(DOS_PSP(dos.psp()).GetParent()).GetParent()) return; + if (cmd->FindExist("cdrom",false)) { WriteOut(MSG_Get("PROGRAM_INTRO_CDROM")); return; } - if(cmd->FindExist("mount",false)) { + if (cmd->FindExist("mount",false)) { WriteOut("\033[2J");//Clear screen before printing DisplayMount(); return; } - if(cmd->FindExist("special",false)) { + if (cmd->FindExist("special",false)) { WriteOut(MSG_Get("PROGRAM_INTRO_SPECIAL")); return; } @@ -1174,7 +1174,7 @@ public: ChangeToLongCmd(); /* In secure mode don't allow people to change imgmount points. * Neither mount nor unmount */ - if(control->SecureMode()) { + if (control->SecureMode()) { WriteOut(MSG_Get("PROGRAM_CONFIG_SECURE_DISALLOW")); return; } @@ -1194,7 +1194,7 @@ public: std::string fstype = "fat"; cmd->FindString("-t",type,true); cmd->FindString("-fs",fstype,true); - if(type == "cdrom") type = "iso"; //Tiny hack for people who like to type -t cdrom + if (type == "cdrom") type = "iso"; //Tiny hack for people who like to type -t cdrom //Check type and exit early. if (type != "floppy" && type != "hdd" && type != "iso") { @@ -1237,9 +1237,9 @@ public: } } - if(fstype=="fat" || fstype=="iso") { + if (fstype=="fat" || fstype=="iso") { // get the drive letter - if (!cmd->FindCommand(1,temp_line) || (temp_line.size() > 2) || ((temp_line.size()>1) && (temp_line[1]!=':'))) { + if (!cmd->FindCommand(1,temp_line) || (temp_line.size() > 2) || ((temp_line.size() > 1) && (temp_line[1]!=':'))) { WriteOut_NoParsing(MSG_Get("PROGRAM_IMGMOUNT_SPECIFY_DRIVE")); return; } @@ -1266,14 +1266,14 @@ public: } // find all file parameters, assuming that all option parameters have been removed - while(cmd->FindCommand((unsigned int)(paths.size() + 2), temp_line) && temp_line.size()) { + while (cmd->FindCommand((unsigned int)(paths.size() + 2), temp_line) && temp_line.size()) { struct stat test; if (stat(temp_line.c_str(),&test)) { //See if it works if the ~ are written out std::string homedir(temp_line); Cross::ResolveHomedir(homedir); - if(!stat(homedir.c_str(),&test)) { + if (!stat(homedir.c_str(),&test)) { temp_line = homedir; } else { // convert dosbox filename to system filename @@ -1314,7 +1314,7 @@ public: if (paths.size() == 1) temp_line = paths[0]; - if(fstype=="fat") { + if (fstype=="fat") { if (imgsizedetect) { FILE * diskfile = fopen_wrap(temp_line.c_str(), "rb+"); if (!diskfile) { @@ -1363,7 +1363,7 @@ public: } else { // Tear-down all prior drives when we hit a problem WriteOut(MSG_Get("PROGRAM_IMGMOUNT_CANT_CREATE")); - for(auto pImgDisk : imgDisks) { + for (auto pImgDisk : imgDisks) { if (pImgDisk) { delete pImgDisk; } @@ -1373,7 +1373,7 @@ public: } // Update DriveManager - for(ct = 0; ct < imgDisks.size(); ct++) { + for (ct = 0; ct < imgDisks.size(); ct++) { DriveManager::AppendDisk(drive - 'A', imgDisks[ct]); } DriveManager::InitializeDrive(drive - 'A'); @@ -1385,7 +1385,7 @@ public: RealPt save_dta = dos.dta(); dos.dta(dos.tables.tempdta); - for(ct = 0; ct < imgDisks.size(); ct++) { + for (ct = 0; ct < imgDisks.size(); ct++) { DriveManager::CycleDisks(drive - 'A', (ct == (imgDisks.size() - 1))); char root[7] = {drive,':','\\','*','.','*',0}; @@ -1434,14 +1434,14 @@ public: } // error: clean up and leave if (error) { - for(ct = 0; ct < isoDisks.size(); ct++) { + for (ct = 0; ct < isoDisks.size(); ct++) { delete isoDisks[ct]; } return; } } // Update DriveManager - for(ct = 0; ct < isoDisks.size(); ct++) { + for (ct = 0; ct < isoDisks.size(); ct++) { DriveManager::AppendDisk(drive - 'A', isoDisks[ct]); } DriveManager::InitializeDrive(drive - 'A'); diff --git a/src/hardware/mame/fmopl.cpp b/src/hardware/mame/fmopl.cpp index 6f5b3dc5..02a980d9 100644 --- a/src/hardware/mame/fmopl.cpp +++ b/src/hardware/mame/fmopl.cpp @@ -106,7 +106,7 @@ Revision History: #define SIN_BITS 10 #define SIN_LEN (1<> 4 ) +#define ENV_QUIET (TL_TAB_LEN >> 4) #define LFO_AM_TAB_ELEMENTS 210 @@ -257,7 +257,7 @@ struct OPL_SLOT void KEYON(uint32_t key_set) { - if( !key ) + if(!key) { /* restart Phase Generator */ Cnt = 0; @@ -269,11 +269,11 @@ struct OPL_SLOT void KEYOFF(uint32_t key_clr) { - if( key ) + if(key) { key &= key_clr; - if( !key ) + if(!key) { /* phase -> Release */ if (state>EG_REL) @@ -300,7 +300,7 @@ struct OPL_CH SLOT.Incr = fc * SLOT.mul; int const ksr = kcode >> SLOT.KSR; - if( SLOT.ksr != ksr ) + if(SLOT.ksr != ksr) { SLOT.ksr = ksr; @@ -424,7 +424,7 @@ struct FM_OPL status &=~flag; if(status & 0x80) { - if (!(status & statusmask) ) + if (!(status & statusmask)) { status &= 0x7f; /* callback user interrupt handler (IRQ is ON to OFF) */ @@ -479,7 +479,7 @@ struct FM_OPL switch(op.state) { case EG_ATT: /* attack phase */ - if ( !(eg_cnt & ((1<>op.eg_sh_ar)&7)]) @@ -495,11 +495,11 @@ struct FM_OPL break; case EG_DEC: /* decay phase */ - if ( !(eg_cnt & ((1<>op.eg_sh_dr)&7)]; - if ( op.volume >= op.sl ) + if (op.volume >= op.sl) op.state = EG_SUS; } @@ -518,11 +518,11 @@ struct FM_OPL else /* percussive mode */ { /* during sustain phase chip adds Release Rate (in percussive mode) */ - if ( !(eg_cnt & ((1<>op.eg_sh_rr)&7)]; - if ( op.volume >= MAX_ATT_INDEX ) + if (op.volume >= MAX_ATT_INDEX) op.volume = MAX_ATT_INDEX; } /* else do nothing in sustain phase */ @@ -530,11 +530,11 @@ struct FM_OPL break; case EG_REL: /* release phase */ - if ( !(eg_cnt & ((1<>op.eg_sh_rr)&7)]; - if ( op.volume >= MAX_ATT_INDEX ) + if (op.volume >= MAX_ATT_INDEX) { op.volume = MAX_ATT_INDEX; op.state = EG_OFF; @@ -597,7 +597,7 @@ struct FM_OPL { /* uint32_t j; - j = ( (noise_rng) ^ (noise_rng>>14) ^ (noise_rng>>15) ^ (noise_rng>>22) ) & 1; + j = ((noise_rng) ^ (noise_rng>>14) ^ (noise_rng>>15) ^ (noise_rng>>22)) & 1; noise_rng = (j<<22) | (noise_rng>>1); */ @@ -632,17 +632,17 @@ struct FM_OPL SLOT->op1_out[0] = SLOT->op1_out[1]; *SLOT->connect1 += SLOT->op1_out[0]; SLOT->op1_out[1] = 0; - if( env < ENV_QUIET ) + if(env < ENV_QUIET) { if (!SLOT->FB) out = 0; - SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable ); + SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable); } /* SLOT 2 */ SLOT++; env = volume_calc(*SLOT); - if( env < ENV_QUIET ) + if(env < ENV_QUIET) output[0] += op_calc(SLOT->Cnt, env, phase_modulation, SLOT->wavetable); } @@ -712,17 +712,17 @@ struct FM_OPL /* else ignore output of operator 1 */ SLOT->op1_out[1] = 0; - if( env < ENV_QUIET ) + if(env < ENV_QUIET) { if (!SLOT->FB) out = 0; - SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable ); + SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable); } /* SLOT 2 */ SLOT++; env = volume_calc(*SLOT); - if( env < ENV_QUIET ) + if(env < ENV_QUIET) output[0] += op_calc(SLOT->Cnt, env, phase_modulation, SLOT->wavetable) * 2; @@ -747,7 +747,7 @@ struct FM_OPL OPL_SLOT const &SLOT7_1 = P_CH[7].SLOT[SLOT1]; OPL_SLOT const &SLOT8_2 = P_CH[8].SLOT[SLOT2]; env = volume_calc(SLOT7_1); - if( env < ENV_QUIET ) + if(env < ENV_QUIET) { /* high hat phase generation: phase = d0 or 234 (based on frequency only) @@ -798,7 +798,7 @@ struct FM_OPL /* Snare Drum (verified on real YM3812) */ OPL_SLOT const &SLOT7_2 = P_CH[7].SLOT[SLOT2]; env = volume_calc(SLOT7_2); - if( env < ENV_QUIET ) + if(env < ENV_QUIET) { /* base frequency derived from operator 1 in channel 7 */ unsigned char const bit8 = BIT(SLOT7_1.Cnt >> FREQ_SH, 8); @@ -820,12 +820,12 @@ struct FM_OPL /* Tom Tom (verified on real YM3812) */ OPL_SLOT const &SLOT8_1 = P_CH[8].SLOT[SLOT1]; env = volume_calc(SLOT8_1); - if( env < ENV_QUIET ) + if(env < ENV_QUIET) output[0] += op_calc(SLOT8_1.Cnt, env, 0, SLOT8_1.wavetable) * 2; /* Top Cymbal (verified on real YM3812) */ env = volume_calc(SLOT8_2); - if( env < ENV_QUIET ) + if(env < ENV_QUIET) { /* base frequency derived from operator 1 in channel 7 */ unsigned char const bit7 = BIT(SLOT7_1.Cnt >> FREQ_SH, 7); @@ -934,7 +934,7 @@ struct FM_OPL /* first time */ /* allocate total level table (128kb space) */ - if( !init_tables() ) + if(!init_tables()) { num_lock--; return -1; @@ -960,14 +960,14 @@ private: static inline signed int op_calc(uint32_t phase, unsigned int env, signed int pm, unsigned int wave_tab) { - uint32_t const p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + (pm<<16))) >> FREQ_SH ) & SIN_MASK) ]; + uint32_t const p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + (pm<<16))) >> FREQ_SH) & SIN_MASK) ]; return (p >= TL_TAB_LEN) ? 0 : tl_tab[p]; } static inline signed int op_calc1(uint32_t phase, unsigned int env, signed int pm, unsigned int wave_tab) { - uint32_t const p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + pm )) >> FREQ_SH ) & SIN_MASK) ]; + uint32_t const p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + pm )) >> FREQ_SH) & SIN_MASK) ]; return (p >= TL_TAB_LEN) ? 0 : tl_tab[p]; } @@ -1063,8 +1063,8 @@ const uint32_t FM_OPL::ksl_shift[4] = { 31, 1, 2, 0 }; /* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/ #define SC(db) int32_t(db * (2.0 / ENV_STEP)) const int32_t FM_OPL::sl_tab[16]={ - SC( 0),SC( 1),SC( 2),SC( 3),SC( 4),SC( 5),SC( 6),SC( 7), - SC( 8),SC( 9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31) + SC(0),SC(1),SC(2),SC(3),SC(4),SC(5),SC(6),SC(7), + SC(8),SC(9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31) }; @@ -1101,25 +1101,25 @@ O(14),O(14),O(14),O(14),O(14),O(14),O(14),O(14), O(14),O(14),O(14),O(14),O(14),O(14),O(14),O(14), /* rates 00-12 */ -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), /* rate 13 */ -O( 4),O( 5),O( 6),O( 7), +O(4),O(5),O(6),O(7), /* rate 14 */ -O( 8),O( 9),O(10),O(11), +O(8),O(9),O(10),O(11), /* rate 15 */ O(12),O(12),O(12),O(12), @@ -1145,29 +1145,29 @@ O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0), O(12),O(12),O(12),O(12), O(11),O(11),O(11),O(11), O(10),O(10),O(10),O(10), -O( 9),O( 9),O( 9),O( 9), -O( 8),O( 8),O( 8),O( 8), -O( 7),O( 7),O( 7),O( 7), -O( 6),O( 6),O( 6),O( 6), -O( 5),O( 5),O( 5),O( 5), -O( 4),O( 4),O( 4),O( 4), -O( 3),O( 3),O( 3),O( 3), -O( 2),O( 2),O( 2),O( 2), -O( 1),O( 1),O( 1),O( 1), -O( 0),O( 0),O( 0),O( 0), +O(9),O(9),O(9),O(9), +O(8),O(8),O(8),O(8), +O(7),O(7),O(7),O(7), +O(6),O(6),O(6),O(6), +O(5),O(5),O(5),O(5), +O(4),O(4),O(4),O(4), +O(3),O(3),O(3),O(3), +O(2),O(2),O(2),O(2), +O(1),O(1),O(1),O(1), +O(0),O(0),O(0),O(0), /* rate 13 */ -O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0), /* rate 14 */ -O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0), /* rate 15 */ -O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0), /* 16 dummy rates (same as 15 3) */ -O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0), -O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0), +O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0), }; #undef O @@ -1298,10 +1298,10 @@ int FM_OPL::num_lock = 0; -static inline int limit( int val, int max, int min ) { - if ( val > max ) +static inline int limit(int val, int max, int min) { + if (val > max) val = max; - else if ( val < min ) + else if (val < min) val = min; return val; @@ -1343,7 +1343,7 @@ int FM_OPL::init_tables() #if 0 logerror("tl %04i", x*2); for (i=0; i<12; i++) - logerror(", [%02i] %5i", i*2, tl_tab[ x*2 /*+1*/ + i*2*TL_RES_LEN ] ); + logerror(", [%02i] %5i", i*2, tl_tab[ x*2 /*+1*/ + i*2*TL_RES_LEN ]); logerror("\n"); #endif } @@ -1353,7 +1353,7 @@ int FM_OPL::init_tables() for (i=0; i>1; - sin_tab[ i ] = n*2 + (m>=0.0? 0: 1 ); + sin_tab[ i ] = n*2 + (m>=0.0? 0: 1); - /*logerror("FMOPL.C: sin [%4i (hex=%03x)]= %4i (tl_tab value=%5i)\n", i, i, sin_tab[i], tl_tab[sin_tab[i]] );*/ + /*logerror("FMOPL.C: sin [%4i (hex=%03x)]= %4i (tl_tab value=%5i)\n", i, i, sin_tab[i], tl_tab[sin_tab[i]]);*/ } for (i=0; i>2)]; - /*logerror("FMOPL.C: sin1[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[1*SIN_LEN+i], tl_tab[sin_tab[1*SIN_LEN+i]] ); - logerror("FMOPL.C: sin2[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[2*SIN_LEN+i], tl_tab[sin_tab[2*SIN_LEN+i]] ); - logerror("FMOPL.C: sin3[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[3*SIN_LEN+i], tl_tab[sin_tab[3*SIN_LEN+i]] );*/ + /*logerror("FMOPL.C: sin1[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[1*SIN_LEN+i], tl_tab[sin_tab[1*SIN_LEN+i]]); + logerror("FMOPL.C: sin2[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[2*SIN_LEN+i], tl_tab[sin_tab[2*SIN_LEN+i]]); + logerror("FMOPL.C: sin3[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[3*SIN_LEN+i], tl_tab[sin_tab[3*SIN_LEN+i]]);*/ } - /*logerror("FMOPL.C: ENV_QUIET= %08x (dec*8=%i)\n", ENV_QUIET, ENV_QUIET*8 );*/ + /*logerror("FMOPL.C: ENV_QUIET= %08x (dec*8=%i)\n", ENV_QUIET, ENV_QUIET*8);*/ #ifdef SAVE_SAMPLE @@ -1433,29 +1433,29 @@ void FM_OPL::initialize() //TimerBase = attotime::from_hz(clock) * 72; /* make fnumber -> increment counter table */ - for( i=0 ; i < 1024 ; i++ ) + for(i=0 ; i < 1024 ; i++) { /* opn phase increment counter = 20bit */ - fn_tab[i] = (uint32_t)( (double)i * 64 * freqbase * (1<<(FREQ_SH-10)) ); /* -10 because chip works with 10.10 fixed point, while we use 16.16 */ + fn_tab[i] = (uint32_t)((double)i * 64 * freqbase * (1<<(FREQ_SH-10))); /* -10 because chip works with 10.10 fixed point, while we use 16.16 */ #if 0 logerror("FMOPL.C: fn_tab[%4i] = %08x (dec=%8i)\n", - i, fn_tab[i]>>6, fn_tab[i]>>6 ); + i, fn_tab[i]>>6, fn_tab[i]>>6); #endif } #if 0 - for( i=0 ; i < 16 ; i++ ) + for(i=0 ; i < 16 ; i++) { logerror("FMOPL.C: sl_tab[%i] = %08x\n", - i, sl_tab[i] ); + i, sl_tab[i]); } - for( i=0 ; i < 8 ; i++ ) + for(i=0 ; i < 8 ; i++) { int j; logerror("FMOPL.C: ksl_tab[oct=%2i] =",i); for (j=0; j<16; j++) { - logerror("%08x ", static_cast(ksl_tab[i*16+j]) ); + logerror("%08x ", static_cast(ksl_tab[i*16+j])); } logerror("\n"); } @@ -1464,7 +1464,7 @@ void FM_OPL::initialize() /* Amplitude modulation: 27 output levels (triangle waveform); 1 level takes one of: 192, 256 or 448 samples */ /* One entry from LFO_AM_TABLE lasts for 64 samples */ - lfo_am_inc = (1.0 / 64.0 ) * (1< 8) return; + if((r&0x0f) > 8) return; CH = &P_CH[r&0x0f]; if(!(r&0x10)) { /* a0-a8 */ @@ -1687,8 +1687,8 @@ void FM_OPL::WriteReg(int r, int v) if(v&0x20) { - CH->SLOT[SLOT1].KEYON ( 1); - CH->SLOT[SLOT2].KEYON ( 1); + CH->SLOT[SLOT1].KEYON (1); + CH->SLOT[SLOT2].KEYON (1); } else { @@ -1728,7 +1728,7 @@ void FM_OPL::WriteReg(int r, int v) break; case 0xc0: /* FB,C */ - if( (r&0x0f) > 8) return; + if((r&0x0f) > 8) return; CH = &P_CH[r&0x0f]; CH->SLOT[SLOT1].FB = (v>>1)&7 ? ((v>>1)&7) + 7 : 0; CH->SLOT[SLOT1].CON = v&1; @@ -1763,15 +1763,15 @@ void FM_OPL::ResetChip() WriteReg(0x02,0); /* Timer1 */ WriteReg(0x03,0); /* Timer2 */ WriteReg(0x04,0); /* IRQ mask clear */ - for(int i = 0xff ; i >= 0x20 ; i-- ) WriteReg(i,0); + for(int i = 0xff ; i >= 0x20 ; i--) WriteReg(i,0); /* reset operator parameters */ // for(OPL_CH &CH : P_CH) - for(int ch = 0; ch < sizeof( P_CH )/ sizeof(P_CH[0]); ch++) + for(int ch = 0; ch < sizeof(P_CH)/ sizeof(P_CH[0]); ch++) { OPL_CH &CH = P_CH[ch]; // for(OPL_SLOT &SLOT : CH.SLOT) - for(int slot = 0; slot < sizeof( CH.SLOT ) / sizeof( CH.SLOT[0]); slot++) + for(int slot = 0; slot < sizeof(CH.SLOT) / sizeof(CH.SLOT[0]); slot++) { OPL_SLOT &SLOT = CH.SLOT[slot]; @@ -1798,7 +1798,7 @@ void FM_OPL::ResetChip() void FM_OPL::postload() { - for(int ch = 0; ch < sizeof( P_CH )/ sizeof(P_CH[0]); ch++) + for(int ch = 0; ch < sizeof(P_CH)/ sizeof(P_CH[0]); ch++) { OPL_CH &CH = P_CH[ch]; /* Look up key scale level */ @@ -1806,7 +1806,7 @@ void FM_OPL::postload() CH.ksl_base = static_cast(ksl_tab[block_fnum >> 6]); CH.fc = fn_tab[block_fnum & 0x03ff] >> (7 - (block_fnum >> 10)); - for(int slot = 0; slot < sizeof( CH.SLOT ) / sizeof( CH.SLOT[0]); slot++) + for(int slot = 0; slot < sizeof(CH.SLOT) / sizeof(CH.SLOT[0]); slot++) { OPL_SLOT &SLOT = CH.SLOT[slot]; /* Calculate key scale rate */ @@ -1839,7 +1839,7 @@ void FM_OPL::postload() } } #if BUILD_Y8950 - if ( (type & OPL_TYPE_ADPCM) && (deltat) ) + if ((type & OPL_TYPE_ADPCM) && (deltat)) { // We really should call the postlod function for the YM_DELTAT, but it's hard without registers // (see the way the YM2610 does it) @@ -1856,13 +1856,13 @@ static void OPLsave_state_channel(device_t *device, OPL_CH *CH) { int slot, ch; - for( ch=0 ; ch < 9 ; ch++, CH++ ) + for(ch=0 ; ch < 9 ; ch++, CH++) { /* channel */ device->save_item(NAME(CH->block_fnum), ch); device->save_item(NAME(CH->kcode), ch); /* slots */ - for( slot=0 ; slot < 2 ; slot++ ) + for(slot=0 ; slot < 2 ; slot++) { OPL_SLOT *SLOT = &CH->SLOT[slot]; @@ -1912,7 +1912,7 @@ static void OPL_save_state(FM_OPL *OPL, device_t *device) device->save_item(NAME(OPL->noise_rng)); device->save_item(NAME(OPL->noise_p)); - if( OPL->type & OPL_TYPE_WAVESEL ) + if(OPL->type & OPL_TYPE_WAVESEL) { device->save_item(NAME(OPL->wavesel)); } @@ -1921,12 +1921,12 @@ static void OPL_save_state(FM_OPL *OPL, device_t *device) device->save_item(NAME(OPL->st)); #if BUILD_Y8950 - if ( (OPL->type & OPL_TYPE_ADPCM) && (OPL->deltat) ) + if ((OPL->type & OPL_TYPE_ADPCM) && (OPL->deltat)) { OPL->deltat->savestate(device); } - if ( OPL->type & OPL_TYPE_IO ) + if (OPL->type & OPL_TYPE_IO) { device->save_item(NAME(OPL->portDirection)); device->save_item(NAME(OPL->portLatch)); @@ -1961,10 +1961,10 @@ static FM_OPL *OPLCreate(device_t *device, uint32_t clock, uint32_t rate, int ty if (FM_OPL::LockTable(device) == -1) return 0; /* calculate OPL state size */ - int state_size = sizeof(FM_OPL); + int state_size = sizeof(FM_OPL); #if BUILD_Y8950 - if (type&OPL_TYPE_ADPCM) state_size+= sizeof(YM_DELTAT); + if (type & OPL_TYPE_ADPCM) state_size += sizeof(YM_DELTAT); #endif /* allocate memory block */ @@ -2020,7 +2020,7 @@ static void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,devi static int OPLWrite(FM_OPL *OPL,int a,int v) { - if( !(a&1) ) + if(!(a&1)) { /* address port */ OPL->address = v & 0xff; } @@ -2034,7 +2034,7 @@ static int OPLWrite(FM_OPL *OPL,int a,int v) static unsigned char OPLRead(FM_OPL *OPL,int a) { - if( !(a&1) ) + if(!(a&1)) { /* status port */ @@ -2112,7 +2112,7 @@ static inline void CSMKeyControll(OPL_CH *CH) static int OPLTimerOver(FM_OPL *OPL,int c) { - if( c ) + if(c) { /* Timer B */ OPL->STATUS_SET(0x20); } @@ -2120,12 +2120,12 @@ static int OPLTimerOver(FM_OPL *OPL,int c) { /* Timer A */ OPL->STATUS_SET(0x40); /* CSM mode key,TL controll */ - if( OPL->mode & 0x80 ) + if(OPL->mode & 0x80) { /* CSM mode total level latch and auto key on */ int ch; if(OPL->UpdateHandler) OPL->UpdateHandler(OPL->UpdateParam,0); for(ch=0; ch<9; ch++) - CSMKeyControll( &OPL->P_CH[ch] ); + CSMKeyControll(&OPL->P_CH[ch]); } } /* reload timer */ @@ -2216,7 +2216,7 @@ void ym3812_update_one(void *chip, OPLSAMPLE *buffer, int length) OPLSAMPLE *buf = buffer; int i; - for( i=0; i < length ; i++ ) + for(i=0; i < length ; i++) { int lt; @@ -2248,7 +2248,7 @@ void ym3812_update_one(void *chip, OPLSAMPLE *buffer, int length) lt >>= FINAL_SH; /* limit check */ - lt = limit( lt , MAXOUT, MINOUT ); + lt = limit(lt , MAXOUT, MINOUT); #ifdef SAVE_SAMPLE if (which==0) @@ -2348,7 +2348,7 @@ void ym3526_update_one(void *chip, OPLSAMPLE *buffer, int length) OPLSAMPLE *buf = buffer; int i; - for( i=0; i < length ; i++ ) + for(i=0; i < length ; i++) { int lt; @@ -2380,7 +2380,7 @@ void ym3526_update_one(void *chip, OPLSAMPLE *buffer, int length) lt >>= FINAL_SH; /* limit check */ - lt = limit( lt , MAXOUT, MINOUT ); + lt = limit(lt , MAXOUT, MINOUT); #ifdef SAVE_SAMPLE if (which==0) @@ -2481,7 +2481,7 @@ void y8950_set_update_handler(void *chip,OPL_UPDATEHANDLER UpdateHandler,device_ OPLSetUpdateHandler(Y8950, UpdateHandler, device); } -void y8950_set_delta_t_memory(void *chip, void * deltat_mem_ptr, int deltat_mem_size ) +void y8950_set_delta_t_memory(void *chip, void * deltat_mem_ptr, int deltat_mem_size) { FM_OPL *OPL = (FM_OPL *)chip; OPL->deltat->memory = (uint8_t *)(deltat_mem_ptr); @@ -2503,7 +2503,7 @@ void y8950_update_one(void *chip, OPLSAMPLE *buffer, int length) YM_DELTAT *DELTAT = OPL->deltat; OPLSAMPLE *buf = buffer; - for( i=0; i < length ; i++ ) + for(i=0; i < length ; i++) { int lt; @@ -2513,7 +2513,7 @@ void y8950_update_one(void *chip, OPLSAMPLE *buffer, int length) OPL->advance_lfo(); /* deltaT ADPCM */ - if( DELTAT->portstate&0x80 ) + if(DELTAT->portstate&0x80) DELTAT->ADPCM_CALC(); /* FM part */ @@ -2540,7 +2540,7 @@ void y8950_update_one(void *chip, OPLSAMPLE *buffer, int length) lt >>= FINAL_SH; /* limit check */ - lt = limit( lt , MAXOUT, MINOUT ); + lt = limit(lt , MAXOUT, MINOUT); #ifdef SAVE_SAMPLE if (which==0) diff --git a/src/hardware/mame/ymf262.cpp b/src/hardware/mame/ymf262.cpp index fd2e940a..af695a8e 100644 --- a/src/hardware/mame/ymf262.cpp +++ b/src/hardware/mame/ymf262.cpp @@ -368,10 +368,10 @@ static const uint32_t ksl_shift[4] = { 31, 1, 2, 0 }; /* sustain level table (3dB per step) */ /* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/ -#define SC(db) (uint32_t) ( db * (2.0/ENV_STEP) ) +#define SC(db) (uint32_t) (db * (2.0/ENV_STEP)) static const uint32_t sl_tab[16]={ - SC( 0),SC( 1),SC( 2),SC(3 ),SC(4 ),SC(5 ),SC(6 ),SC( 7), - SC( 8),SC( 9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31) + SC(0),SC(1),SC(2),SC(3),SC(4),SC(5),SC(6),SC(7), + SC(8),SC(9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31) }; #undef SC @@ -410,25 +410,25 @@ O(14),O(14),O(14),O(14),O(14),O(14),O(14),O(14), O(14),O(14),O(14),O(14),O(14),O(14),O(14),O(14), /* rates 00-12 */ -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), -O( 0),O( 1),O( 2),O( 3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), +O(0),O(1),O(2),O(3), /* rate 13 */ -O( 4),O( 5),O( 6),O( 7), +O(4),O(5),O(6),O(7), /* rate 14 */ -O( 8),O( 9),O(10),O(11), +O(8),O(9),O(10),O(11), /* rate 15 */ O(12),O(12),O(12),O(12), @@ -454,29 +454,29 @@ O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0), O(12),O(12),O(12),O(12), O(11),O(11),O(11),O(11), O(10),O(10),O(10),O(10), -O( 9),O( 9),O( 9),O( 9), -O( 8),O( 8),O( 8),O( 8), -O( 7),O( 7),O( 7),O( 7), -O( 6),O( 6),O( 6),O( 6), -O( 5),O( 5),O( 5),O( 5), -O( 4),O( 4),O( 4),O( 4), -O( 3),O( 3),O( 3),O( 3), -O( 2),O( 2),O( 2),O( 2), -O( 1),O( 1),O( 1),O( 1), -O( 0),O( 0),O( 0),O( 0), +O(9),O(9),O(9),O(9), +O(8),O(8),O(8),O(8), +O(7),O(7),O(7),O(7), +O(6),O(6),O(6),O(6), +O(5),O(5),O(5),O(5), +O(4),O(4),O(4),O(4), +O(3),O(3),O(3),O(3), +O(2),O(2),O(2),O(2), +O(1),O(1),O(1),O(1), +O(0),O(0),O(0),O(0), /* rate 13 */ -O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0), /* rate 14 */ -O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0), /* rate 15 */ -O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0), /* 16 dummy rates (same as 15 3) */ -O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0), -O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0),O( 0), +O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0), +O(0),O(0),O(0),O(0),O(0),O(0),O(0),O(0), }; #undef O @@ -638,10 +638,10 @@ static inline void OPL3_SLOT_CONNECT(OPL3 *chip, OPL3_SLOT *slot) { } } -static inline int limit( int val, int max, int min ) { - if ( val > max ) +static inline int limit(int val, int max, int min) { + if (val > max) val = max; - else if ( val < min ) + else if (val < min) val = min; return val; @@ -653,13 +653,13 @@ static inline void OPL3_STATUS_SET(OPL3 *chip,int flag) { /* set status flag masking out disabled IRQs */ chip->status |= (flag & chip->statusmask); - if(!(chip->status & 0x80)) + if (!(chip->status & 0x80)) { - if(chip->status & 0x7f) + if (chip->status & 0x7f) { /* IRQ on */ chip->status |= 0x80; /* callback user interrupt handler (IRQ is OFF to ON) */ - if(chip->IRQHandler) (chip->IRQHandler)(chip->IRQParam,1); + if (chip->IRQHandler) (chip->IRQHandler)(chip->IRQParam,1); } } } @@ -669,13 +669,13 @@ static inline void OPL3_STATUS_RESET(OPL3 *chip,int flag) { /* reset status flag */ chip->status &= ~flag; - if(chip->status & 0x80) + if (chip->status & 0x80) { if (!(chip->status & 0x7f)) { chip->status &= 0x7f; /* callback user interrupt handler (IRQ is ON to OFF) */ - if(chip->IRQHandler) (chip->IRQHandler)(chip->IRQParam,0); + if (chip->IRQHandler) (chip->IRQHandler)(chip->IRQParam,0); } } } @@ -697,7 +697,7 @@ static inline void advance_lfo(OPL3 *chip) /* LFO */ chip->lfo_am_cnt += chip->lfo_am_inc; - if (chip->lfo_am_cnt >= ((uint32_t)LFO_AM_TAB_ELEMENTS<lfo_am_cnt >= ((uint32_t)LFO_AM_TAB_ELEMENTS<lfo_am_cnt -= ((uint32_t)LFO_AM_TAB_ELEMENTS<lfo_am_cnt >> LFO_SH ]; @@ -735,8 +735,8 @@ static inline void advance(OPL3 *chip) switch(op->state) { case EG_ATT: /* attack phase */ -// if ( !(chip->eg_cnt & ((1<eg_sh_ar)-1) ) ) - if ( !(chip->eg_cnt & op->eg_m_ar) ) +// if (!(chip->eg_cnt & ((1<eg_sh_ar)-1))) + if (!(chip->eg_cnt & op->eg_m_ar)) { op->volume += (~op->volume * (eg_inc[op->eg_sel_ar + ((chip->eg_cnt>>op->eg_sh_ar)&7)]) @@ -752,12 +752,12 @@ static inline void advance(OPL3 *chip) break; case EG_DEC: /* decay phase */ -// if ( !(chip->eg_cnt & ((1<eg_sh_dr)-1) ) ) - if ( !(chip->eg_cnt & op->eg_m_dr) ) +// if (!(chip->eg_cnt & ((1<eg_sh_dr)-1))) + if (!(chip->eg_cnt & op->eg_m_dr)) { op->volume += eg_inc[op->eg_sel_dr + ((chip->eg_cnt>>op->eg_sh_dr)&7)]; - if ( op->volume >= op->sl ) + if (op->volume >= op->sl) op->state = EG_SUS; } @@ -769,19 +769,19 @@ static inline void advance(OPL3 *chip) one can change percusive/non-percussive modes on the fly and the chip will remain in sustain phase - verified on real YM3812 */ - if(op->eg_type) /* non-percussive mode */ + if (op->eg_type) /* non-percussive mode */ { /* do nothing */ } else /* percussive mode */ { /* during sustain phase chip adds Release Rate (in percussive mode) */ -// if ( !(chip->eg_cnt & ((1<eg_sh_rr)-1) ) ) - if ( !(chip->eg_cnt & op->eg_m_rr) ) +// if (!(chip->eg_cnt & ((1<eg_sh_rr)-1))) + if (!(chip->eg_cnt & op->eg_m_rr)) { op->volume += eg_inc[op->eg_sel_rr + ((chip->eg_cnt>>op->eg_sh_rr)&7)]; - if ( op->volume >= MAX_ATT_INDEX ) + if (op->volume >= MAX_ATT_INDEX) op->volume = MAX_ATT_INDEX; } /* else do nothing in sustain phase */ @@ -789,12 +789,12 @@ static inline void advance(OPL3 *chip) break; case EG_REL: /* release phase */ -// if ( !(chip->eg_cnt & ((1<eg_sh_rr)-1) ) ) - if ( !(chip->eg_cnt & op->eg_m_rr) ) +// if (!(chip->eg_cnt & ((1<eg_sh_rr)-1))) + if (!(chip->eg_cnt & op->eg_m_rr)) { op->volume += eg_inc[op->eg_sel_rr + ((chip->eg_cnt>>op->eg_sh_rr)&7)]; - if ( op->volume >= MAX_ATT_INDEX ) + if (op->volume >= MAX_ATT_INDEX) { op->volume = MAX_ATT_INDEX; op->state = EG_OFF; @@ -816,7 +816,7 @@ static inline void advance(OPL3 *chip) op = &CH->SLOT[i&1]; /* Phase Generator */ - if(op->vib) + if (op->vib) { uint8_t block; unsigned int block_fnum = CH->block_fnum; @@ -860,7 +860,7 @@ static inline void advance(OPL3 *chip) { /* uint32_t j; - j = ( (chip->noise_rng) ^ (chip->noise_rng>>14) ^ (chip->noise_rng>>15) ^ (chip->noise_rng>>22) ) & 1; + j = ((chip->noise_rng) ^ (chip->noise_rng>>14) ^ (chip->noise_rng>>15) ^ (chip->noise_rng>>22)) & 1; chip->noise_rng = (j<<22) | (chip->noise_rng>>1); */ @@ -884,7 +884,7 @@ static inline signed int op_calc(uint32_t phase, unsigned int env, signed int pm { uint32_t p; - p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + (pm<<16))) >> FREQ_SH ) & SIN_MASK) ]; + p = (env<<4) + sin_tab[wave_tab + ((((signed int)((phase & ~FREQ_MASK) + (pm<<16))) >> FREQ_SH) & SIN_MASK) ]; if (p >= TL_TAB_LEN) return 0; @@ -907,7 +907,7 @@ static inline signed int op_calc1(uint32_t phase, unsigned int env, signed int p /* calculate output of a standard 2 operator channel (or 1st part of a 4-op channel) */ -static inline void chan_calc( OPL3 *chip, OPL3_CH *CH ) +static inline void chan_calc(OPL3 *chip, OPL3_CH *CH) { OPL3_SLOT *SLOT; unsigned int env; @@ -926,12 +926,12 @@ static inline void chan_calc( OPL3 *chip, OPL3_CH *CH ) { if (!SLOT->FB) out = 0; - SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable ); + SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable); } if (SLOT->connect) { *SLOT->connect += SLOT->op1_out[1]; } -//logerror("out0=%5i vol0=%4i ", SLOT->op1_out[1], env ); +//logerror("out0=%5i vol0=%4i ", SLOT->op1_out[1], env); /* SLOT 2 */ SLOT++; @@ -939,12 +939,12 @@ static inline void chan_calc( OPL3 *chip, OPL3_CH *CH ) if ((env < ENV_QUIET) && SLOT->connect) *SLOT->connect += op_calc(SLOT->Cnt, env, chip->phase_modulation, SLOT->wavetable); -//logerror("out1=%5i vol1=%4i\n", op_calc(SLOT->Cnt, env, chip->phase_modulation, SLOT->wavetable), env ); +//logerror("out1=%5i vol1=%4i\n", op_calc(SLOT->Cnt, env, chip->phase_modulation, SLOT->wavetable), env); } /* calculate output of a 2nd part of 4-op channel */ -static inline void chan_calc_ext( OPL3 *chip, OPL3_CH *CH ) +static inline void chan_calc_ext(OPL3 *chip, OPL3_CH *CH) { OPL3_SLOT *SLOT; unsigned int env; @@ -955,7 +955,7 @@ static inline void chan_calc_ext( OPL3 *chip, OPL3_CH *CH ) SLOT = &CH->SLOT[SLOT1]; env = volume_calc(SLOT); if (env < ENV_QUIET && SLOT->connect) - *SLOT->connect += op_calc(SLOT->Cnt, env, chip->phase_modulation2, SLOT->wavetable ); + *SLOT->connect += op_calc(SLOT->Cnt, env, chip->phase_modulation2, SLOT->wavetable); /* SLOT 2 */ SLOT++; @@ -1002,7 +1002,7 @@ number number BLK/FNUM2 FNUM Drum Hat Drum Tom Cymbal /* calculate rhythm */ -static inline void chan_calc_rhythm( OPL3 *chip, OPL3_CH *CH, unsigned int noise ) +static inline void chan_calc_rhythm(OPL3 *chip, OPL3_CH *CH, unsigned int noise) { OPL3_SLOT *SLOT; signed int *chanout = chip->chanout; @@ -1031,17 +1031,17 @@ static inline void chan_calc_rhythm( OPL3 *chip, OPL3_CH *CH, unsigned int noise //else ignore output of operator 1 SLOT->op1_out[1] = 0; - if( env < ENV_QUIET ) + if (env < ENV_QUIET) { if (!SLOT->FB) out = 0; - SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable ); + SLOT->op1_out[1] = op_calc1(SLOT->Cnt, env, (out<FB), SLOT->wavetable); } /* SLOT 2 */ SLOT++; env = volume_calc(SLOT); - if( env < ENV_QUIET ) + if (env < ENV_QUIET) chanout[6] += op_calc(SLOT->Cnt, env, chip->phase_modulation, SLOT->wavetable) * 2; @@ -1064,7 +1064,7 @@ static inline void chan_calc_rhythm( OPL3 *chip, OPL3_CH *CH, unsigned int noise /* High Hat (verified on real YM3812) */ env = volume_calc(SLOT7_1); - if( env < ENV_QUIET ) + if (env < ENV_QUIET) { /* high hat phase generation: phase = d0 or 234 (based on frequency only) @@ -1114,7 +1114,7 @@ static inline void chan_calc_rhythm( OPL3 *chip, OPL3_CH *CH, unsigned int noise /* Snare Drum (verified on real YM3812) */ env = volume_calc(SLOT7_2); - if( env < ENV_QUIET ) + if (env < ENV_QUIET) { /* base frequency derived from operator 1 in channel 7 */ unsigned char bit8 = ((SLOT7_1->Cnt>>FREQ_SH)>>8)&1; @@ -1135,12 +1135,12 @@ static inline void chan_calc_rhythm( OPL3 *chip, OPL3_CH *CH, unsigned int noise /* Tom Tom (verified on real YM3812) */ env = volume_calc(SLOT8_1); - if( env < ENV_QUIET ) + if (env < ENV_QUIET) chanout[8] += op_calc(SLOT8_1->Cnt, env, 0, SLOT8_1->wavetable) * 2; /* Top Cymbal (verified on real YM3812) */ env = volume_calc(SLOT8_2); - if( env < ENV_QUIET ) + if (env < ENV_QUIET) { /* base frequency derived from operator 1 in channel 7 */ unsigned char bit7 = ((SLOT7_1->Cnt>>FREQ_SH)>>7)&1; @@ -1204,12 +1204,12 @@ static int init_tables(void) #if 0 logerror("tl %04i", x*2); for (i=0; i<13; i++) - logerror(", [%02i] %5i", i*2, tl_tab[ x*2 +0 + i*2*TL_RES_LEN ] ); /* positive */ + logerror(", [%02i] %5i", i*2, tl_tab[ x*2 +0 + i*2*TL_RES_LEN ]); /* positive */ logerror("\n"); logerror("tl %04i", x*2); for (i=0; i<13; i++) - logerror(", [%02i] %5i", i*2, tl_tab[ x*2 +1 + i*2*TL_RES_LEN ] ); /* negative */ + logerror(", [%02i] %5i", i*2, tl_tab[ x*2 +1 + i*2*TL_RES_LEN ]); /* negative */ logerror("\n"); #endif } @@ -1217,7 +1217,7 @@ static int init_tables(void) for (i=0; i>1; - sin_tab[ i ] = n*2 + (m>=0.0? 0: 1 ); + sin_tab[ i ] = n*2 + (m>=0.0? 0: 1); - /*logerror("YMF262.C: sin [%4i (hex=%03x)]= %4i (tl_tab value=%5i)\n", i, i, sin_tab[i], tl_tab[sin_tab[i]] );*/ + /*logerror("YMF262.C: sin [%4i (hex=%03x)]= %4i (tl_tab value=%5i)\n", i, i, sin_tab[i], tl_tab[sin_tab[i]]);*/ } for (i=0; i>2)]; @@ -1271,7 +1271,7 @@ static int init_tables(void) /* \/ \/ */ /* output whole sinus waveform in half the cycle(step=2) and output 0 on the other half of cycle */ - if (i & (1<<(SIN_BITS-1)) ) + if (i & (1<<(SIN_BITS-1))) sin_tab[4*SIN_LEN+i] = TL_TAB_LEN; else sin_tab[4*SIN_LEN+i] = sin_tab[i*2]; @@ -1281,7 +1281,7 @@ static int init_tables(void) /* */ /* output abs(whole sinus) waveform in half the cycle(step=2) and output 0 on the other half of cycle */ - if (i & (1<<(SIN_BITS-1)) ) + if (i & (1<<(SIN_BITS-1))) sin_tab[5*SIN_LEN+i] = TL_TAB_LEN; else sin_tab[5*SIN_LEN+i] = sin_tab[(i*2) & (SIN_MASK>>1) ]; @@ -1291,7 +1291,7 @@ static int init_tables(void) /* ____ ____*/ /* output maximum in half the cycle and output minimum on the other half of cycle */ - if (i & (1<<(SIN_BITS-1)) ) + if (i & (1<<(SIN_BITS-1))) sin_tab[6*SIN_LEN+i] = 1; /* negative */ else sin_tab[6*SIN_LEN+i] = 0; /* positive */ @@ -1301,8 +1301,8 @@ static int init_tables(void) /* \| \|*/ /* output sawtooth waveform */ - if (i & (1<<(SIN_BITS-1)) ) - x = ((SIN_LEN-1)-i)*16 + 1; /* negative: from 8177 to 1 */ + if (i & (1<<(SIN_BITS-1))) + x = ((SIN_LEN - 1) - i) * 16 + 1; /* negative: from 8177 to 1 */ else x = i*16; /*positive: from 0 to 8176 */ @@ -1311,15 +1311,15 @@ static int init_tables(void) sin_tab[7*SIN_LEN+i] = x; - //logerror("YMF262.C: sin1[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[1*SIN_LEN+i], tl_tab[sin_tab[1*SIN_LEN+i]] ); - //logerror("YMF262.C: sin2[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[2*SIN_LEN+i], tl_tab[sin_tab[2*SIN_LEN+i]] ); - //logerror("YMF262.C: sin3[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[3*SIN_LEN+i], tl_tab[sin_tab[3*SIN_LEN+i]] ); - //logerror("YMF262.C: sin4[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[4*SIN_LEN+i], tl_tab[sin_tab[4*SIN_LEN+i]] ); - //logerror("YMF262.C: sin5[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[5*SIN_LEN+i], tl_tab[sin_tab[5*SIN_LEN+i]] ); - //logerror("YMF262.C: sin6[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[6*SIN_LEN+i], tl_tab[sin_tab[6*SIN_LEN+i]] ); - //logerror("YMF262.C: sin7[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[7*SIN_LEN+i], tl_tab[sin_tab[7*SIN_LEN+i]] ); + //logerror("YMF262.C: sin1[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[1*SIN_LEN+i], tl_tab[sin_tab[1*SIN_LEN+i]]); + //logerror("YMF262.C: sin2[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[2*SIN_LEN+i], tl_tab[sin_tab[2*SIN_LEN+i]]); + //logerror("YMF262.C: sin3[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[3*SIN_LEN+i], tl_tab[sin_tab[3*SIN_LEN+i]]); + //logerror("YMF262.C: sin4[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[4*SIN_LEN+i], tl_tab[sin_tab[4*SIN_LEN+i]]); + //logerror("YMF262.C: sin5[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[5*SIN_LEN+i], tl_tab[sin_tab[5*SIN_LEN+i]]); + //logerror("YMF262.C: sin6[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[6*SIN_LEN+i], tl_tab[sin_tab[6*SIN_LEN+i]]); + //logerror("YMF262.C: sin7[%4i]= %4i (tl_tab value=%5i)\n", i, sin_tab[7*SIN_LEN+i], tl_tab[sin_tab[7*SIN_LEN+i]]); } - /*logerror("YMF262.C: ENV_QUIET= %08x (dec*8=%i)\n", ENV_QUIET, ENV_QUIET*8 );*/ + /*logerror("YMF262.C: ENV_QUIET= %08x (dec*8=%i)\n", ENV_QUIET, ENV_QUIET*8);*/ #ifdef SAVE_SAMPLE sample[0]=fopen("sampsum.pcm","wb"); @@ -1328,7 +1328,7 @@ static int init_tables(void) return 1; } -static void OPLCloseTable( void ) +static void OPLCloseTable(void) { #ifdef SAVE_SAMPLE fclose(sample[0]); @@ -1354,29 +1354,29 @@ static void OPL3_initalize(OPL3 *chip) //chip->TimerBase = attotime::from_hz(chip->clock) * (8*36); /* make fnumber -> increment counter table */ - for( i=0 ; i < 1024 ; i++ ) + for (i=0 ; i < 1024 ; i++) { /* opn phase increment counter = 20bit */ - chip->fn_tab[i] = (uint32_t)( (double)i * 64 * chip->freqbase * (1<<(FREQ_SH-10)) ); /* -10 because chip works with 10.10 fixed point, while we use 16.16 */ + chip->fn_tab[i] = (uint32_t)((double)i * 64 * chip->freqbase * (1<<(FREQ_SH-10))); /* -10 because chip works with 10.10 fixed point, while we use 16.16 */ #if 0 logerror("YMF262.C: fn_tab[%4i] = %08x (dec=%8i)\n", - i, chip->fn_tab[i]>>6, chip->fn_tab[i]>>6 ); + i, chip->fn_tab[i]>>6, chip->fn_tab[i]>>6); #endif } #if 0 - for( i=0 ; i < 16 ; i++ ) + for (i=0 ; i < 16 ; i++) { logerror("YMF262.C: sl_tab[%i] = %08x\n", - i, sl_tab[i] ); + i, sl_tab[i]); } - for( i=0 ; i < 8 ; i++ ) + for (i=0 ; i < 8 ; i++) { int j; logerror("YMF262.C: ksl_tab[oct=%2i] =",i); for (j=0; j<16; j++) { - logerror("%08x ", static_cast(ksl_tab[i*16+j]) ); + logerror("%08x ", static_cast(ksl_tab[i*16+j])); } logerror("\n"); } @@ -1385,7 +1385,7 @@ static void OPL3_initalize(OPL3 *chip) /* Amplitude modulation: 27 output levels (triangle waveform); 1 level takes one of: 192, 256 or 448 samples */ /* One entry from LFO_AM_TABLE lasts for 64 samples */ - chip->lfo_am_inc = (1.0 / 64.0 ) * (1<freqbase; + chip->lfo_am_inc = (1.0 / 64.0) * (1<freqbase; /* Vibrato: 8 output levels (triangle waveform); 1 level takes 1024 samples */ chip->lfo_pm_inc = (1.0 / 1024.0) * (1<freqbase; @@ -1396,14 +1396,14 @@ static void OPL3_initalize(OPL3 *chip) chip->noise_f = (1.0 / 1.0) * (1<freqbase; chip->eg_timer_add = (1<freqbase; - chip->eg_timer_overflow = ( 1 ) * (1<eg_timer_overflow = (1) * (1<eg_timer_add, chip->eg_timer_overflow);*/ } static inline void FM_KEYON(OPL3_SLOT *SLOT, uint32_t key_set) { - if( !SLOT->key ) + if (!SLOT->key) { /* restart Phase Generator */ SLOT->Cnt = 0; @@ -1415,11 +1415,11 @@ static inline void FM_KEYON(OPL3_SLOT *SLOT, uint32_t key_set) static inline void FM_KEYOFF(OPL3_SLOT *SLOT, uint32_t key_clr) { - if( SLOT->key ) + if (SLOT->key) { SLOT->key &= key_clr; - if( !SLOT->key ) + if (!SLOT->key) { /* phase -> Release */ if (SLOT->state>EG_REL) @@ -1437,7 +1437,7 @@ static inline void CALC_FCSLOT(OPL3_CH *CH,OPL3_SLOT *SLOT) SLOT->Incr = CH->fc * SLOT->mul; ksr = CH->kcode >> SLOT->KSR; - if( SLOT->ksr != ksr ) + if (SLOT->ksr != ksr) { SLOT->ksr = ksr; @@ -1445,20 +1445,20 @@ static inline void CALC_FCSLOT(OPL3_CH *CH,OPL3_SLOT *SLOT) if ((SLOT->ar + SLOT->ksr) < 16+60) { SLOT->eg_sh_ar = eg_rate_shift [SLOT->ar + SLOT->ksr ]; - SLOT->eg_m_ar = (1<eg_sh_ar)-1; + SLOT->eg_m_ar = (1<eg_sh_ar) - 1; SLOT->eg_sel_ar = eg_rate_select[SLOT->ar + SLOT->ksr ]; } else { SLOT->eg_sh_ar = 0; - SLOT->eg_m_ar = (1<eg_sh_ar)-1; + SLOT->eg_m_ar = (1<eg_sh_ar) - 1; SLOT->eg_sel_ar = 13*RATE_STEPS; } SLOT->eg_sh_dr = eg_rate_shift [SLOT->dr + SLOT->ksr ]; - SLOT->eg_m_dr = (1<eg_sh_dr)-1; + SLOT->eg_m_dr = (1<eg_sh_dr) - 1; SLOT->eg_sel_dr = eg_rate_select[SLOT->dr + SLOT->ksr ]; SLOT->eg_sh_rr = eg_rate_shift [SLOT->rr + SLOT->ksr ]; - SLOT->eg_m_rr = (1<eg_sh_rr)-1; + SLOT->eg_m_rr = (1<eg_sh_rr) - 1; SLOT->eg_sel_rr = eg_rate_select[SLOT->rr + SLOT->ksr ]; } } @@ -1505,10 +1505,10 @@ static inline void set_mul(OPL3 *chip,int slot,int v) break; case 3: case 4: case 5: case 12: case 13: case 14: - if ((CH-3)->extended) + if ((CH - 3)->extended) { /* update this SLOT using frequency data for 1st channel of a pair */ - CALC_FCSLOT(CH-3,SLOT); + CALC_FCSLOT(CH - 3,SLOT); } else { @@ -1568,10 +1568,10 @@ static inline void set_ksl_tl(OPL3 *chip,int slot,int v) break; case 3: case 4: case 5: case 12: case 13: case 14: - if ((CH-3)->extended) + if ((CH - 3)->extended) { /* update this SLOT using frequency data for 1st channel of a pair */ - SLOT->TLL = SLOT->TL + ((CH-3)->ksl_base>>SLOT->ksl); + SLOT->TLL = SLOT->TL + ((CH - 3)->ksl_base>>SLOT->ksl); } else { @@ -1604,19 +1604,19 @@ static inline void set_ar_dr(OPL3 *chip,int slot,int v) if ((SLOT->ar + SLOT->ksr) < 16+60) /* verified on real YMF262 - all 15 x rates take "zero" time */ { SLOT->eg_sh_ar = eg_rate_shift [SLOT->ar + SLOT->ksr ]; - SLOT->eg_m_ar = (1<eg_sh_ar)-1; + SLOT->eg_m_ar = (1<eg_sh_ar) - 1; SLOT->eg_sel_ar = eg_rate_select[SLOT->ar + SLOT->ksr ]; } else { SLOT->eg_sh_ar = 0; - SLOT->eg_m_ar = (1<eg_sh_ar)-1; + SLOT->eg_m_ar = (1<eg_sh_ar) - 1; SLOT->eg_sel_ar = 13*RATE_STEPS; } SLOT->dr = (v&0x0f)? 16 + ((v&0x0f)<<2) : 0; SLOT->eg_sh_dr = eg_rate_shift [SLOT->dr + SLOT->ksr ]; - SLOT->eg_m_dr = (1<eg_sh_dr)-1; + SLOT->eg_m_dr = (1<eg_sh_dr) - 1; SLOT->eg_sel_dr = eg_rate_select[SLOT->dr + SLOT->ksr ]; } @@ -1630,7 +1630,7 @@ static inline void set_sl_rr(OPL3 *chip,int slot,int v) SLOT->rr = (v&0x0f)? 16 + ((v&0x0f)<<2) : 0; SLOT->eg_sh_rr = eg_rate_shift [SLOT->rr + SLOT->ksr ]; - SLOT->eg_m_rr = (1<eg_sh_rr)-1; + SLOT->eg_m_rr = (1<eg_sh_rr) - 1; SLOT->eg_sel_rr = eg_rate_select[SLOT->rr + SLOT->ksr ]; } @@ -1657,7 +1657,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) int slot; int block_fnum; - if(r&0x100) + if (r&0x100) { switch(r) { @@ -1671,34 +1671,34 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) CH = &chip->P_CH[0]; /* channel 0 */ prev = CH->extended; CH->extended = (v>>0) & 1; - if(prev != CH->extended) + if (prev != CH->extended) update_channels(chip, CH); CH++; /* channel 1 */ prev = CH->extended; CH->extended = (v>>1) & 1; - if(prev != CH->extended) + if (prev != CH->extended) update_channels(chip, CH); CH++; /* channel 2 */ prev = CH->extended; CH->extended = (v>>2) & 1; - if(prev != CH->extended) + if (prev != CH->extended) update_channels(chip, CH); CH = &chip->P_CH[9]; /* channel 9 */ prev = CH->extended; CH->extended = (v>>3) & 1; - if(prev != CH->extended) + if (prev != CH->extended) update_channels(chip, CH); CH++; /* channel 10 */ prev = CH->extended; CH->extended = (v>>4) & 1; - if(prev != CH->extended) + if (prev != CH->extended) update_channels(chip, CH); CH++; /* channel 11 */ prev = CH->extended; CH->extended = (v>>5) & 1; - if(prev != CH->extended) + if (prev != CH->extended) update_channels(chip, CH); } @@ -1747,7 +1747,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) break; #if 0 case 0x04: /* IRQ clear / mask and Timer enable */ - if(v&0x80) + if (v&0x80) { /* IRQ flags clear */ OPL3_STATUS_RESET(chip,0x60); } @@ -1758,17 +1758,17 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) /* IRQRST,T1MSK,t2MSK,x,x,x,ST2,ST1 */ OPL3_STATUS_RESET(chip, v & 0x60); - OPL3_STATUSMASK_SET(chip, (~v) & 0x60 ); + OPL3_STATUSMASK_SET(chip, (~v) & 0x60); /* timer 2 */ - if(chip->st[1] != st2) + if (chip->st[1] != st2) { attotime period = st2 ? chip->TimerBase * chip->T[1] : attotime::zero; chip->st[1] = st2; if (chip->timer_handler) (chip->timer_handler)(chip->TimerParam,1,period); } /* timer 1 */ - if(chip->st[0] != st1) + if (chip->st[0] != st1) { attotime period = st1 ? chip->TimerBase * chip->T[0] : attotime::zero; chip->st[0] = st1; @@ -1788,22 +1788,22 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) break; case 0x20: /* am ON, vib ON, ksr, eg_type, mul */ slot = slot_array[r&0x1f]; - if(slot < 0) return; + if (slot < 0) return; set_mul(chip, slot + ch_offset*2, v); break; case 0x40: slot = slot_array[r&0x1f]; - if(slot < 0) return; + if (slot < 0) return; set_ksl_tl(chip, slot + ch_offset*2, v); break; case 0x60: slot = slot_array[r&0x1f]; - if(slot < 0) return; + if (slot < 0) return; set_ar_dr(chip, slot + ch_offset*2, v); break; case 0x80: slot = slot_array[r&0x1f]; - if(slot < 0) return; + if (slot < 0) return; set_sl_rr(chip, slot + ch_offset*2, v); break; case 0xa0: @@ -1817,10 +1817,10 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) chip->rhythm = v&0x3f; - if(chip->rhythm&0x20) + if (chip->rhythm&0x20) { /* BD key on/off */ - if(v&0x10) + if (v&0x10) { FM_KEYON (&chip->P_CH[6].SLOT[SLOT1], 2); FM_KEYON (&chip->P_CH[6].SLOT[SLOT2], 2); @@ -1831,16 +1831,16 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) FM_KEYOFF(&chip->P_CH[6].SLOT[SLOT2],~2); } /* HH key on/off */ - if(v&0x01) FM_KEYON (&chip->P_CH[7].SLOT[SLOT1], 2); + if (v&0x01) FM_KEYON (&chip->P_CH[7].SLOT[SLOT1], 2); else FM_KEYOFF(&chip->P_CH[7].SLOT[SLOT1],~2); /* SD key on/off */ - if(v&0x08) FM_KEYON (&chip->P_CH[7].SLOT[SLOT2], 2); + if (v&0x08) FM_KEYON (&chip->P_CH[7].SLOT[SLOT2], 2); else FM_KEYOFF(&chip->P_CH[7].SLOT[SLOT2],~2); /* TOM key on/off */ - if(v&0x04) FM_KEYON (&chip->P_CH[8].SLOT[SLOT1], 2); + if (v&0x04) FM_KEYON (&chip->P_CH[8].SLOT[SLOT1], 2); else FM_KEYOFF(&chip->P_CH[8].SLOT[SLOT1],~2); /* TOP-CY key on/off */ - if(v&0x02) FM_KEYON (&chip->P_CH[8].SLOT[SLOT2], 2); + if (v&0x02) FM_KEYON (&chip->P_CH[8].SLOT[SLOT2], 2); else FM_KEYOFF(&chip->P_CH[8].SLOT[SLOT2],~2); } else @@ -1861,10 +1861,10 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) } /* keyon,block,fnum */ - if( (r&0x0f) > 8) return; + if ((r&0x0f) > 8) return; CH = &chip->P_CH[(r&0x0f) + ch_offset]; - if(!(r&0x10)) + if (!(r&0x10)) { /* a0-a8 */ block_fnum = (CH->block_fnum&0x1f00) | v; } @@ -1892,25 +1892,25 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) { //if this is 1st channel forming up a 4-op channel //ALSO keyon/off slots of 2nd channel forming up 4-op channel - if(v&0x20) + if (v&0x20) { FM_KEYON (&CH->SLOT[SLOT1], 1); FM_KEYON (&CH->SLOT[SLOT2], 1); - FM_KEYON (&(CH+3)->SLOT[SLOT1], 1); - FM_KEYON (&(CH+3)->SLOT[SLOT2], 1); + FM_KEYON (&(CH + 3)->SLOT[SLOT1], 1); + FM_KEYON (&(CH + 3)->SLOT[SLOT2], 1); } else { FM_KEYOFF(&CH->SLOT[SLOT1],~1); FM_KEYOFF(&CH->SLOT[SLOT2],~1); - FM_KEYOFF(&(CH+3)->SLOT[SLOT1],~1); - FM_KEYOFF(&(CH+3)->SLOT[SLOT2],~1); + FM_KEYOFF(&(CH + 3)->SLOT[SLOT1],~1); + FM_KEYOFF(&(CH + 3)->SLOT[SLOT2],~1); } } else { //else normal 2 operator function keyon/off - if(v&0x20) + if (v&0x20) { FM_KEYON (&CH->SLOT[SLOT1], 1); FM_KEYON (&CH->SLOT[SLOT2], 1); @@ -1925,14 +1925,14 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) case 3: case 4: case 5: case 12: case 13: case 14: - if ((CH-3)->extended) + if ((CH - 3)->extended) { //if this is 2nd channel forming up 4-op channel just do nothing } else { //else normal 2 operator function keyon/off - if(v&0x20) + if (v&0x20) { FM_KEYON (&CH->SLOT[SLOT1], 1); FM_KEYON (&CH->SLOT[SLOT2], 1); @@ -1946,7 +1946,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) break; default: - if(v&0x20) + if (v&0x20) { FM_KEYON (&CH->SLOT[SLOT1], 1); FM_KEYON (&CH->SLOT[SLOT2], 1); @@ -1961,7 +1961,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) } else { - if(v&0x20) + if (v&0x20) { FM_KEYON (&CH->SLOT[SLOT1], 1); FM_KEYON (&CH->SLOT[SLOT2], 1); @@ -1974,7 +1974,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) } } /* update */ - if(CH->block_fnum != block_fnum) + if (CH->block_fnum != block_fnum) { uint8_t block = block_fnum >> 10; @@ -2017,14 +2017,14 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) /* refresh Total Level in FOUR SLOTs of this channel and channel+3 using data from THIS channel */ CH->SLOT[SLOT1].TLL = CH->SLOT[SLOT1].TL + (CH->ksl_base>>CH->SLOT[SLOT1].ksl); CH->SLOT[SLOT2].TLL = CH->SLOT[SLOT2].TL + (CH->ksl_base>>CH->SLOT[SLOT2].ksl); - (CH+3)->SLOT[SLOT1].TLL = (CH+3)->SLOT[SLOT1].TL + (CH->ksl_base>>(CH+3)->SLOT[SLOT1].ksl); - (CH+3)->SLOT[SLOT2].TLL = (CH+3)->SLOT[SLOT2].TL + (CH->ksl_base>>(CH+3)->SLOT[SLOT2].ksl); + (CH + 3)->SLOT[SLOT1].TLL = (CH + 3)->SLOT[SLOT1].TL + (CH->ksl_base>>(CH + 3)->SLOT[SLOT1].ksl); + (CH + 3)->SLOT[SLOT2].TLL = (CH + 3)->SLOT[SLOT2].TL + (CH->ksl_base>>(CH + 3)->SLOT[SLOT2].ksl); /* refresh frequency counter in FOUR SLOTs of this channel and channel+3 using data from THIS channel */ CALC_FCSLOT(CH,&CH->SLOT[SLOT1]); CALC_FCSLOT(CH,&CH->SLOT[SLOT2]); - CALC_FCSLOT(CH,&(CH+3)->SLOT[SLOT1]); - CALC_FCSLOT(CH,&(CH+3)->SLOT[SLOT2]); + CALC_FCSLOT(CH,&(CH + 3)->SLOT[SLOT1]); + CALC_FCSLOT(CH,&(CH + 3)->SLOT[SLOT2]); } else { @@ -2041,7 +2041,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) case 3: case 4: case 5: case 12: case 13: case 14: - if ((CH-3)->extended) + if ((CH - 3)->extended) { //if this is 2nd channel forming up 4-op channel just do nothing } @@ -2086,11 +2086,11 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) case 0xc0: /* CH.D, CH.C, CH.B, CH.A, FB(3bits), C */ - if( (r&0xf) > 8) return; + if ((r&0xf) > 8) return; CH = &chip->P_CH[(r&0xf) + ch_offset]; - if( chip->OPL3_mode & 1 ) + if (chip->OPL3_mode & 1) { int base = ((r&0xf) + ch_offset) * 4; @@ -2116,7 +2116,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) CH->SLOT[SLOT1].FB = (v>>1)&7 ? ((v>>1)&7) + 7 : 0; CH->SLOT[SLOT1].CON = v&1; - if( chip->OPL3_mode & 1 ) + if (chip->OPL3_mode & 1) { int chan_no = (r&0x0f) + ch_offset; @@ -2126,7 +2126,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) case 9: case 10: case 11: if (CH->extended) { - uint8_t conn = (CH->SLOT[SLOT1].CON<<1) | ((CH+3)->SLOT[SLOT1].CON<<0); + uint8_t conn = (CH->SLOT[SLOT1].CON<<1) | ((CH + 3)->SLOT[SLOT1].CON<<0); switch(conn) { case 0: @@ -2134,8 +2134,8 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) CH->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; CH->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; - (CH+3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; - (CH+3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; + (CH + 3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; + (CH + 3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; break; case 1: /* 1 -> 2 -\ @@ -2143,8 +2143,8 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) CH->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; CH->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no; - (CH+3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; - (CH+3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; + (CH + 3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; + (CH + 3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; break; case 2: /* 1 -----------\ @@ -2152,8 +2152,8 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) CH->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no; CH->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; - (CH+3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; - (CH+3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; + (CH + 3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; + (CH + 3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; break; case 3: /* 1 ------\ @@ -2161,14 +2161,14 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) 4 ------/ */ CH->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no; CH->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; - (CH+3)->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no + 3; - (CH+3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; + (CH + 3)->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no + 3; + (CH + 3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no + 3; break; } OPL3_SLOT_CONNECT(chip, &CH->SLOT[SLOT1]); OPL3_SLOT_CONNECT(chip, &CH->SLOT[SLOT2]); - OPL3_SLOT_CONNECT(chip, &(CH+3)->SLOT[SLOT1]); - OPL3_SLOT_CONNECT(chip, &(CH+3)->SLOT[SLOT2]); + OPL3_SLOT_CONNECT(chip, &(CH + 3)->SLOT[SLOT1]); + OPL3_SLOT_CONNECT(chip, &(CH + 3)->SLOT[SLOT2]); } else { @@ -2182,16 +2182,16 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) case 3: case 4: case 5: case 12: case 13: case 14: - if ((CH-3)->extended) + if ((CH - 3)->extended) { - uint8_t conn = ((CH-3)->SLOT[SLOT1].CON<<1) | (CH->SLOT[SLOT1].CON<<0); + uint8_t conn = ((CH - 3)->SLOT[SLOT1].CON<<1) | (CH->SLOT[SLOT1].CON<<0); switch(conn) { case 0: /* 1 -> 2 -> 3 -> 4 - out */ - (CH-3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; - (CH-3)->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; + (CH - 3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; + (CH - 3)->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; CH->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; CH->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no; break; @@ -2199,8 +2199,8 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) /* 1 -> 2 -\ 3 -> 4 -+- out */ - (CH-3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; - (CH-3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no - 3; + (CH - 3)->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; + (CH - 3)->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no - 3; CH->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; CH->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no; break; @@ -2208,8 +2208,8 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) /* 1 -----------\ 2 -> 3 -> 4 -+- out */ - (CH-3)->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no - 3; - (CH-3)->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; + (CH - 3)->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no - 3; + (CH - 3)->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; CH->SLOT[SLOT1].conn_enum = CONN_PHASEMOD; CH->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no; break; @@ -2217,14 +2217,14 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) /* 1 ------\ 2 -> 3 -+- out 4 ------/ */ - (CH-3)->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no - 3; - (CH-3)->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; + (CH - 3)->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no - 3; + (CH - 3)->SLOT[SLOT2].conn_enum = CONN_PHASEMOD2; CH->SLOT[SLOT1].conn_enum = CONN_CHAN0 + chan_no; CH->SLOT[SLOT2].conn_enum = CONN_CHAN0 + chan_no; break; } - OPL3_SLOT_CONNECT(chip, &(CH-3)->SLOT[SLOT1]); - OPL3_SLOT_CONNECT(chip, &(CH-3)->SLOT[SLOT2]); + OPL3_SLOT_CONNECT(chip, &(CH - 3)->SLOT[SLOT1]); + OPL3_SLOT_CONNECT(chip, &(CH - 3)->SLOT[SLOT2]); OPL3_SLOT_CONNECT(chip, &CH->SLOT[SLOT1]); OPL3_SLOT_CONNECT(chip, &CH->SLOT[SLOT2]); } @@ -2259,7 +2259,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) case 0xe0: /* waveform select */ slot = slot_array[r&0x1f]; - if(slot < 0) return; + if (slot < 0) return; slot += ch_offset*2; @@ -2271,7 +2271,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) CH->SLOT[slot&1].waveform_number = v; /* ... but select only waveforms 0-3 in OPL2 mode */ - if( !(chip->OPL3_mode & 1) ) + if (!(chip->OPL3_mode & 1)) { v &= 3; /* we're in OPL2 mode */ } @@ -2284,12 +2284,13 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) static int OPL3_LockTable(device_t *device) { num_lock++; - if(num_lock>1) return 0; + if (num_lock > 1) { + return 0; + } /* first time */ - if( !init_tables() ) - { + if (init_tables()) { num_lock--; return -1; } @@ -2299,8 +2300,8 @@ static int OPL3_LockTable(device_t *device) static void OPL3_UnLockTable(void) { - if(num_lock) num_lock--; - if(num_lock) return; + if (num_lock) num_lock--; + if (num_lock) return; /* last time */ OPLCloseTable(); @@ -2328,19 +2329,19 @@ static void OPL3ResetChip(OPL3 *chip) //FIX IT (dont change CH.D, CH.C, CH.B and CH.A in C0-C8 registers) - for(c = 0xff ; c >= 0x20 ; c-- ) + for (c = 0xff ; c >= 0x20 ; c--) OPL3WriteReg(chip,c,0); //FIX IT (dont change CH.D, CH.C, CH.B and CH.A in C0-C8 registers) - for(c = 0x1ff ; c >= 0x120 ; c-- ) + for (c = 0x1ff ; c >= 0x120 ; c--) OPL3WriteReg(chip,c,0); /* reset operator parameters */ - for( c = 0 ; c < 9*2 ; c++ ) + for (c = 0 ; c < 9*2 ; c++) { OPL3_CH *CH = &chip->P_CH[c]; - for(s = 0 ; s < 2 ; s++ ) + for (s = 0 ; s < 2 ; s++) { CH->SLOT[s].state = EG_OFF; CH->SLOT[s].volume = MAX_ATT_INDEX; @@ -2355,17 +2356,19 @@ static OPL3 *OPL3Create(device_t *device, int clock, int rate, int type) { // Guard if (device == nullptr) { - return 0; + return nullptr; } OPL3 *chip; - if (OPL3_LockTable(device) == -1) return 0; + if (OPL3_LockTable(device) == -1) { + return nullptr; + } /* allocate memory block */ - chip = auto_alloc_clear(device->machine(), OPL3 ); + chip = auto_alloc_clear(device->machine(), OPL3); if (chip == nullptr) { device->logerror("Could not allocate memory for OPL3 chip"); - return 0; + return nullptr; } chip->device = device; @@ -2404,7 +2407,7 @@ static int OPL3Write(OPL3 *chip, int a, int v) case 1: /* data port - ignore A1 */ case 3: /* data port - ignore A1 */ - if(chip->UpdateHandler) chip->UpdateHandler(chip->UpdateParam,0); + if (chip->UpdateHandler) chip->UpdateHandler(chip->UpdateParam,0); OPL3WriteReg(chip,chip->address,v); break; @@ -2419,7 +2422,7 @@ static int OPL3Write(OPL3 *chip, int a, int v) verified on registers from set#2: 0x01, 0x04, 0x20-0xef The only exception is register 0x05. */ - if( chip->OPL3_mode & 1 ) + if (chip->OPL3_mode & 1) { /* OPL3 mode */ chip->address = v | 0x100; @@ -2427,7 +2430,7 @@ static int OPL3Write(OPL3 *chip, int a, int v) else { /* in OPL2 mode the only accessible in set #2 is register 0x05 */ - if( v==5 ) + if (v==5) chip->address = v | 0x100; else chip->address = v; /* verified range: 0x01, 0x04, 0x20-0xef(set #2 becomes set #1 in opl2 mode) */ @@ -2440,7 +2443,7 @@ static int OPL3Write(OPL3 *chip, int a, int v) static unsigned char OPL3Read(OPL3 *chip,int a) { - if( a==0 ) + if (a==0) { /* status port */ return chip->status; @@ -2453,7 +2456,7 @@ static unsigned char OPL3Read(OPL3 *chip,int a) static int OPL3TimerOver(OPL3 *chip,int c) { - if( c ) + if (c) { /* Timer B */ OPL3_STATUS_SET(chip,0x20); } @@ -2617,7 +2620,7 @@ void ymf262_update_one(void *_chip, OPL3SAMPLE **buffers, int length) OPL3SAMPLE *ch_c = buffers[2]; OPL3SAMPLE *ch_d = buffers[3]; - for( i=0; i < length ; i++ ) + for (i=0; i < length ; i++) { int a,b,c,d; @@ -2650,7 +2653,7 @@ void ymf262_update_one(void *_chip, OPL3SAMPLE **buffers, int length) chan_calc(chip, &chip->P_CH[5]); /* standard 2op ch#5 */ - if(!rhythm) + if (!rhythm) { chan_calc(chip, &chip->P_CH[6]); chan_calc(chip, &chip->P_CH[7]); @@ -2658,7 +2661,7 @@ void ymf262_update_one(void *_chip, OPL3SAMPLE **buffers, int length) } else /* Rhythm part */ { - chan_calc_rhythm(chip, &chip->P_CH[0], (chip->noise_rng>>0)&1 ); + chan_calc_rhythm(chip, &chip->P_CH[0], (chip->noise_rng>>0)&1); } /* register set #2 */ @@ -2776,10 +2779,10 @@ void ymf262_update_one(void *_chip, OPL3SAMPLE **buffers, int length) d >>= FINAL_SH; /* limit check */ - a = limit( a , MAXOUT, MINOUT ); - b = limit( b , MAXOUT, MINOUT ); - c = limit( c , MAXOUT, MINOUT ); - d = limit( d , MAXOUT, MINOUT ); + a = limit(a , MAXOUT, MINOUT); + b = limit(b , MAXOUT, MINOUT); + c = limit(c , MAXOUT, MINOUT); + d = limit(d , MAXOUT, MINOUT); #ifdef SAVE_SAMPLE if (which==0) diff --git a/src/hardware/memory.cpp b/src/hardware/memory.cpp index 0b4352bf..df118e73 100644 --- a/src/hardware/memory.cpp +++ b/src/hardware/memory.cpp @@ -551,25 +551,39 @@ public: Section_prop * section=static_cast(configuration); /* Setup the Physical Page Links */ - Bitu memsize=section->Get_int("memsize"); + uint16_t memsize = section->Get_int("memsize"); if (memsize < 1) memsize = 1; /* max 63 to solve problems with certain xms handlers */ - if (memsize > MAX_MEMORY-1) { + if (memsize > MAX_MEMORY - 1) { LOG_MSG("Maximum memory size is %d MB",MAX_MEMORY - 1); - memsize = MAX_MEMORY-1; + memsize = MAX_MEMORY - 1; } - if (memsize > SAFE_MEMORY-1) { + if (memsize > SAFE_MEMORY - 1) { LOG_MSG("Memory sizes above %d MB are NOT recommended.",SAFE_MEMORY - 1); LOG_MSG("Stick with the default values unless you are absolutely certain."); } - MemBase = new Bit8u[memsize*1024*1024]; - memset((void*)MemBase,0,memsize*1024*1024); - memory.pages = (memsize*1024*1024)/4096; + MemBase = new (std::nothrow) Bit8u[memsize * 1024 * 1024]; + if (!MemBase) { + E_Exit("Can't allocate main memory of %u MB", memsize); + } + memset((void*)MemBase, 0, memsize * 1024 * 1024); + memory.pages = (memsize * 1024 * 1024) / 4096; + /* Allocate the data for the different page information blocks */ - memory.phandlers=new PageHandler * [memory.pages]; - memory.mhandles=new MemHandle [memory.pages]; - for (i = 0;i < memory.pages;i++) { + memory.phandlers = new (std::nothrow) PageHandler * [memory.pages]; + if (!memory.phandlers) { + E_Exit("Can't allocate %" PRIuPTR " bytes for the PageHandler array", + sizeof(PageHandler*) * memory.pages); + } + + memory.mhandles = new (std::nothrow) MemHandle [memory.pages]; + if (!memory.mhandles) { + E_Exit("Can't allocate %" PRIuPTR " bytes worth of memory handles", + sizeof(MemHandle) * memory.pages); + } + + for (i = 0; i < memory.pages; i++) { memory.phandlers[i] = &ram_page_handler; memory.mhandles[i] = 0; //Set to 0 for memory allocation } diff --git a/src/misc/programs.cpp b/src/misc/programs.cpp index 7b858599..0165bcd7 100644 --- a/src/misc/programs.cpp +++ b/src/misc/programs.cpp @@ -63,7 +63,7 @@ void PROGRAMS_MakeFile(char const * const name,PROGRAMS_Main * main) { comdata[CB_POS+1]=(Bit8u)((call_program>>8)&0xff); /* Copy save the pointer in the vector and save it's index */ - if (internal_progs.size()>255) E_Exit("PROGRAMS_MakeFile program size too large (%d)",static_cast(internal_progs.size())); + if (internal_progs.size() > 255) E_Exit("PROGRAMS_MakeFile program size too large (%d)",static_cast(internal_progs.size())); Bit8u index = (Bit8u)internal_progs.size(); internal_progs.push_back(main); @@ -144,7 +144,7 @@ void Program::WriteOut(const char * format,...) { Bit16u size = (Bit16u)strlen(buf); dos.internal_output=true; - for(Bit16u i = 0; i < size;i++) { + for (Bit16u i = 0; i < size; i++) { Bit8u out;Bit16u s=1; if (buf[i] == 0xA && last_written_character != 0xD) { out = 0xD;DOS_WriteFile(STDOUT,&out,&s); @@ -161,7 +161,7 @@ void Program::WriteOut_NoParsing(const char * format) { Bit16u size = (Bit16u)strlen(format); char const* buf = format; dos.internal_output=true; - for(Bit16u i = 0; i < size;i++) { + for (Bit16u i = 0; i < size; i++) { Bit8u out;Bit16u s=1; if (buf[i] == 0xA && last_written_character != 0xD) { out = 0xD;DOS_WriteFile(STDOUT,&out,&s); @@ -228,7 +228,7 @@ bool Program::SetEnv(const char * entry,const char * new_string) { PhysPt env_read = PhysMake(psp->GetEnvironment(),0); //Get size of environment. - DOS_MCB mcb(psp->GetEnvironment()-1); + DOS_MCB mcb(psp->GetEnvironment() - 1); Bit16u envsize = mcb.GetSize()*16; @@ -315,7 +315,7 @@ void CONFIG::Run(void) { bool first = true; std::vector pvars; // Loop through the passed parameters - while(presult != P_NOPARAMS) { + while (presult != P_NOPARAMS) { presult = (enum prs)cmd->GetParameterFromList(params, pvars); switch(presult) { @@ -325,7 +325,7 @@ void CONFIG::Run(void) { else { std::vector restart_params; restart_params.push_back(control->cmdline->GetFileName()); - for(size_t i = 0; i < pvars.size(); i++) { + for (size_t i = 0; i < pvars.size(); i++) { restart_params.push_back(pvars[i]); if (pvars[i].find(' ') != std::string::npos) { pvars[i] = "\""+pvars[i]+"\""; // add back spaces @@ -347,13 +347,13 @@ void CONFIG::Run(void) { WriteOut(MSG_Get("PROGRAM_CONFIG_PRIMARY_CONF"),control->configfiles.front().c_str()); if (size > 1) { WriteOut(MSG_Get("PROGRAM_CONFIG_ADDITIONAL_CONF")); - for(Bitu i = 1; i < size; i++) + for (Bitu i = 1; i < size; i++) WriteOut("%s\n",control->configfiles[i].c_str()); } } if (control->startup_params.size() > 0) { std::string test; - for(size_t k = 0; k < control->startup_params.size(); k++) + for (size_t k = 0; k < control->startup_params.size(); k++) test += control->startup_params[k] + " "; WriteOut(MSG_Get("PROGRAM_CONFIG_PRINT_STARTUP"), test.c_str()); } @@ -410,7 +410,7 @@ void CONFIG::Run(void) { // list the sections WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_SECTLIST")); Bitu i = 0; - while(true) { + while (true) { Section* sec = control->GetSection(i++); if (!sec) break; WriteOut("%s\n",sec->GetName()); @@ -466,7 +466,7 @@ void CONFIG::Run(void) { if (pvars.size()==1) { size_t i = 0; WriteOut(MSG_Get("PROGRAM_CONFIG_HLP_SECTHLP"),pvars[0].c_str()); - while(true) { + while (true) { // list the properties Property* p = psec->Get_prop(i++); if (p==NULL) break; @@ -498,7 +498,7 @@ void CONFIG::Run(void) { propvalues += oss.str(); } } - for(Bitu k = 0; k < pv.size(); k++) { + for (Bitu k = 0; k < pv.size(); k++) { if (pv[k].ToString() =="%u") propvalues += MSG_Get("PROGRAM_CONFIG_HLP_POSINT"); else propvalues += pv[k].ToString(); @@ -543,7 +543,7 @@ void CONFIG::Run(void) { WriteOut(MSG_Get("PROGRAM_CONFIG_SECTION_ERROR")); return; } - for(Bitu i = 0; i < pvars.size(); i++) { + for (Bitu i = 0; i < pvars.size(); i++) { sec->HandleInputline(pvars[i]); } break; @@ -590,7 +590,7 @@ void CONFIG::Run(void) { WriteOut("%s",pline->data.c_str()); break; } - while(true) { + while (true) { // list the properties Property* p = psec->Get_prop(i++); if (p==NULL) break; @@ -723,7 +723,7 @@ void CONFIG::Run(void) { } } } - if(pvars.size() < 3) { + if (pvars.size() < 3) { WriteOut(MSG_Get("PROGRAM_CONFIG_SET_SYNTAX")); return; } @@ -740,7 +740,7 @@ void CONFIG::Run(void) { std::string value(pvars[2]); //Due to parsing there can be a = at the start of value. while (value.size() && (value.at(0) ==' ' ||value.at(0) =='=') ) value.erase(0,1); - for(Bitu i = 3; i < pvars.size(); i++) value += (std::string(" ") + pvars[i]); + for (Bitu i = 3; i < pvars.size(); i++) value += (std::string(" ") + pvars[i]); if (value.empty() ) { WriteOut(MSG_Get("PROGRAM_CONFIG_SET_SYNTAX")); return; diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp index bed75ad3..a3b6198b 100644 --- a/src/shell/shell_cmds.cpp +++ b/src/shell/shell_cmds.cpp @@ -48,7 +48,7 @@ static SHELL_Cmd cmd_list[]={ { "DELETE", 1, &DOS_Shell::CMD_DELETE, "SHELL_CMD_DELETE_HELP"}, { "ERASE", 1, &DOS_Shell::CMD_DELETE, "SHELL_CMD_DELETE_HELP"}, { "ECHO", 1, &DOS_Shell::CMD_ECHO, "SHELL_CMD_ECHO_HELP"}, -{ "EXIT", 0, &DOS_Shell::CMD_EXIT, "SHELL_CMD_EXIT_HELP"}, +{ "EXIT", 0, &DOS_Shell::CMD_EXIT, "SHELL_CMD_EXIT_HELP"}, { "GOTO", 1, &DOS_Shell::CMD_GOTO, "SHELL_CMD_GOTO_HELP"}, { "HELP", 1, &DOS_Shell::CMD_HELP, "SHELL_CMD_HELP_HELP"}, { "IF", 1, &DOS_Shell::CMD_IF, "SHELL_CMD_IF_HELP"}, @@ -70,28 +70,28 @@ static SHELL_Cmd cmd_list[]={ { "TYPE", 0, &DOS_Shell::CMD_TYPE, "SHELL_CMD_TYPE_HELP"}, { "VER", 0, &DOS_Shell::CMD_VER, "SHELL_CMD_VER_HELP"}, {0,0,0,0} -}; +}; /* support functions */ static char empty_char = 0; static char* empty_string = &empty_char; static void StripSpaces(char*&args) { - while(args && *args && isspace(*reinterpret_cast(args))) + while (args && *args && isspace(*reinterpret_cast(args))) args++; } static void StripSpaces(char*&args,char also) { - while(args && *args && (isspace(*reinterpret_cast(args)) || (*args == also))) + while (args && *args && (isspace(*reinterpret_cast(args)) || (*args == also))) args++; } static char* ExpandDot(char*args, char* buffer , size_t bufsize) { - if(*args == '.') { - if(*(args+1) == 0){ + if (*args == '.') { + if (*(args+1) == 0){ safe_strncpy(buffer, "*.*", bufsize); return buffer; } - if( (*(args+1) != '.') && (*(args+1) != '\\') ) { + if ( (*(args+1) != '.') && (*(args+1) != '\\') ) { buffer[0] = '*'; buffer[1] = 0; if (bufsize > 2) strncat(buffer,args,bufsize - 1 /*used buffer portion*/ - 1 /*trailing zero*/ ); @@ -135,12 +135,12 @@ void DOS_Shell::DoCommand(char * line) { if (*line == '/') break; if (*line == '\t') break; if (*line == '=') break; -// if (*line == ':') break; //This breaks drive switching as that is handled at a later stage. +// if (*line == ':') break; //This breaks drive switching as that is handled at a later stage. if ((*line == '.') ||(*line == '\\')) { //allow stuff like cd.. and dir.exe cd\kees *cmd_write=0; Bit32u cmd_index=0; while (cmd_list[cmd_index].name) { - if (strcasecmp(cmd_list[cmd_index].name,cmd_buffer)==0) { + if (strcasecmp(cmd_list[cmd_index].name,cmd_buffer) == 0) { (this->*(cmd_list[cmd_index].handler))(line); return; } @@ -150,19 +150,19 @@ void DOS_Shell::DoCommand(char * line) { *cmd_write++=*line++; } *cmd_write=0; - if (strlen(cmd_buffer)==0) return; + if (strlen(cmd_buffer) == 0) return; /* Check the internal list */ Bit32u cmd_index=0; while (cmd_list[cmd_index].name) { - if (strcasecmp(cmd_list[cmd_index].name,cmd_buffer)==0) { + if (strcasecmp(cmd_list[cmd_index].name,cmd_buffer) == 0) { (this->*(cmd_list[cmd_index].handler))(line); return; } cmd_index++; } /* This isn't an internal command execute it */ - if(Execute(cmd_buffer,line)) return; - if(CheckConfig(cmd_buffer,line)) return; + if (Execute(cmd_buffer,line)) return; + if (CheckConfig(cmd_buffer,line)) return; WriteOut(MSG_Get("SHELL_EXECUTE_ILLEGAL_COMMAND"),cmd_buffer); } @@ -171,7 +171,7 @@ void DOS_Shell::DoCommand(char * line) { WriteOut(MSG_Get("SHELL_CMD_" command "_HELP")); \ const char* long_m = MSG_Get("SHELL_CMD_" command "_HELP_LONG"); \ WriteOut("\n"); \ - if(strcmp("Message not Found!\n",long_m)) WriteOut(long_m); \ + if (strcmp("Message not Found!\n",long_m)) WriteOut(long_m); \ else WriteOut(command "\n"); \ return; \ } @@ -193,14 +193,14 @@ void DOS_Shell::CMD_DELETE(char * args) { WriteOut(MSG_Get("SHELL_ILLEGAL_SWITCH"),rem); return; } - /* If delete accept switches mind the space infront of them. See the dir /p code */ + /* If delete accept switches mind the space infront of them. See the dir /p code */ char full[DOS_PATHLENGTH]; char buffer[CROSS_LEN]; args = ExpandDot(args,buffer, CROSS_LEN); StripSpaces(args); if (!DOS_Canonicalize(args,full)) { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH"));return; } -//TODO Maybe support confirmation for *.* like dos does. +//TODO Maybe support confirmation for *.* like dos does. bool res=DOS_FindFirst(args,0xffff & ~DOS_ATTR_VOLUME); if (!res) { WriteOut(MSG_Get("SHELL_CMD_DEL_ERROR"),args); @@ -212,7 +212,7 @@ void DOS_Shell::CMD_DELETE(char * args) { char name[DOS_NAMELENGTH_ASCII];Bit32u size;Bit16u time,date;Bit8u attr; DOS_DTA dta(dos.dta()); while (res) { - dta.GetResult(name,size,date,time,attr); + dta.GetResult(name,size,date,time,attr); if (!(attr & (DOS_ATTR_DIRECTORY|DOS_ATTR_READ_ONLY))) { strcpy(end,name); if (!DOS_UnlinkFile(full)) WriteOut(MSG_Get("SHELL_CMD_DEL_ERROR"),full); @@ -226,7 +226,7 @@ void DOS_Shell::CMD_HELP(char * args){ HELP("HELP"); bool optall=ScanCMDBool(args,"ALL"); /* Print the help */ - if(!optall) WriteOut(MSG_Get("SHELL_CMD_HELP")); + if (!optall) WriteOut(MSG_Get("SHELL_CMD_HELP")); Bit32u cmd_index=0,write_count=0; while (cmd_list[cmd_index].name) { if (optall || !cmd_list[cmd_index].flags) { @@ -247,12 +247,12 @@ void DOS_Shell::CMD_RENAME(char * args){ StripSpaces(args); if (!*args) {SyntaxError();return;} char* slash = strrchr(arg1,'\\'); - if (slash) { + if (slash) { /* If directory specified (crystal caves installer) - * rename from c:\X : rename c:\abc.exe abc.shr. - * File must appear in C:\ - * Ren X:\A\B C => ren X:\A\B X:\A\C */ - + * rename from c:\X : rename c:\abc.exe abc.shr. + * File must appear in C:\ + * Ren X:\A\B C => ren X:\A\B X:\A\C */ + char dir_source[DOS_PATHLENGTH + 4] = {0}; //not sure if drive portion is included in pathlength //Copy first and then modify, makes GCC happy safe_strncpy(dir_source,arg1,DOS_PATHLENGTH + 4); @@ -288,19 +288,19 @@ void DOS_Shell::CMD_ECHO(char * args){ char* pbuffer = buffer; safe_strncpy(buffer,args,512); StripSpaces(pbuffer); - if (strcasecmp(pbuffer,"OFF")==0) { - echo=false; + if (strcasecmp(pbuffer,"OFF") == 0) { + echo=false; return; } - if (strcasecmp(pbuffer,"ON")==0) { - echo=true; + if (strcasecmp(pbuffer,"ON") == 0) { + echo=true; return; } - if(strcasecmp(pbuffer,"/?")==0) { HELP("ECHO"); } + if (strcasecmp(pbuffer,"/?") == 0) { HELP("ECHO"); } args++;//skip first character. either a slash or dot or space size_t len = strlen(args); //TODO check input of else ook nodig is. - if(len && args[len - 1] == '\r') { + if (len && args[len - 1] == '\r') { LOG(LOG_MISC,LOG_WARN)("Hu ? carriage return already present. Is this possible?"); WriteOut("%s\n",args); } else WriteOut("%s\r\n",args); @@ -320,11 +320,11 @@ void DOS_Shell::CMD_CHDIR(char * args) { if (!*args) { DOS_GetCurrentDir(0,dir); WriteOut("%c:\\%s\n",drive,dir); - } else if(strlen(args) == 2 && args[1]==':') { - Bit8u targetdrive = (args[0] | 0x20)-'a' + 1; + } else if (strlen(args) == 2 && args[1] == ':') { + Bit8u targetdrive = (args[0] | 0x20) - 'a' + 1; unsigned char targetdisplay = *reinterpret_cast(&args[0]); - if(!DOS_GetCurrentDir(targetdrive,dir)) { - if(drive == 'Z') { + if (!DOS_GetCurrentDir(targetdrive,dir)) { + if (drive == 'Z') { WriteOut(MSG_Get("SHELL_EXECUTE_DRIVE_NOT_FOUND"),toupper(targetdisplay)); } else { WriteOut(MSG_Get("SHELL_ILLEGAL_PATH")); @@ -332,25 +332,25 @@ void DOS_Shell::CMD_CHDIR(char * args) { return; } WriteOut("%c:\\%s\n",toupper(targetdisplay),dir); - if(drive == 'Z') + if (drive == 'Z') WriteOut(MSG_Get("SHELL_CMD_CHDIR_HINT"),toupper(targetdisplay)); } else if (!DOS_ChangeDir(args)) { /* Changedir failed. Check if the filename is longer then 8 and/or contains spaces */ - + std::string temps(args),slashpart; std::string::size_type separator = temps.find_first_of("\\/"); - if(!separator) { + if (!separator) { slashpart = temps.substr(0,1); temps.erase(0,1); } separator = temps.find_first_of("\\/"); - if(separator != std::string::npos) temps.erase(separator); + if (separator != std::string::npos) temps.erase(separator); separator = temps.rfind('.'); - if(separator != std::string::npos) temps.erase(separator); + if (separator != std::string::npos) temps.erase(separator); separator = temps.find(' '); - if(separator != std::string::npos) {/* Contains spaces */ + if (separator != std::string::npos) {/* Contains spaces */ temps.erase(separator); - if(temps.size() >6) temps.erase(6); + if (temps.size() >6) temps.erase(6); temps += "~1"; WriteOut(MSG_Get("SHELL_CMD_CHDIR_HINT_2"),temps.insert(0,slashpart).c_str()); } else if (temps.size()>8) { @@ -447,7 +447,7 @@ void DOS_Shell::CMD_DIR(char * args) { char path[DOS_PATHLENGTH]; std::string line; - if(GetEnvStr("DIRCMD",line)){ + if (GetEnvStr("DIRCMD",line)){ std::string::size_type idx = line.find('='); std::string value=line.substr(idx +1 , std::string::npos); line = std::string(args) + " " + value; @@ -511,7 +511,7 @@ void DOS_Shell::CMD_DIR(char * args) { if (!strrchr(args,'*') && !strrchr(args,'?')) { Bit16u attribute=0; - if(DOS_GetFileAttr(args,&attribute) && (attribute&DOS_ATTR_DIRECTORY) ) { + if (DOS_GetFileAttr(args,&attribute) && (attribute&DOS_ATTR_DIRECTORY) ) { strcat(args,"\\*.*"); // if no wildcard and a directory, get its files } } @@ -585,8 +585,8 @@ void DOS_Shell::CMD_DIR(char * args) { dta.GetResult(result.name,result.size,result.date,result.time,result.attr); /* Skip non-directories if option AD is present, or skip dirs in case of A-D */ - if(optAD && !(result.attr&DOS_ATTR_DIRECTORY) ) continue; - else if(optAminusD && (result.attr&DOS_ATTR_DIRECTORY) ) continue; + if (optAD && !(result.attr&DOS_ATTR_DIRECTORY) ) continue; + else if (optAminusD && (result.attr&DOS_ATTR_DIRECTORY) ) continue; results.push_back(result); @@ -745,9 +745,9 @@ void DOS_Shell::CMD_COPY(char * args) { char name[DOS_NAMELENGTH_ASCII]; std::vector sources; // ignore /b and /t switches: always copy binary - while(ScanCMDBool(args,"B")) ; - while(ScanCMDBool(args,"T")) ; //Shouldn't this be A ? - while(ScanCMDBool(args,"A")) ; + while (ScanCMDBool(args,"B")) ; + while (ScanCMDBool(args,"T")) ; //Shouldn't this be A ? + while (ScanCMDBool(args,"A")) ; ScanCMDBool(args,"Y"); ScanCMDBool(args,"-Y"); ScanCMDBool(args,"V"); @@ -769,9 +769,9 @@ void DOS_Shell::CMD_COPY(char * args) { // If StripWord() previously cut at a space before a plus then // set concatenate flag on last source and remove leading plus. if (plus == source_p && sources.size()) { - sources[sources.size()-1].concat = true; + sources[sources.size() - 1].concat = true; // If spaces also followed plus then item is only a plus. - if (strlen(++source_p)==0) break; + if (strlen(++source_p) == 0) break; plus = strchr(source_p,'+'); } if (plus) *plus++ = 0; @@ -779,7 +779,7 @@ void DOS_Shell::CMD_COPY(char * args) { bool has_drive_spec = false; size_t source_x_len = strlen(source_x); if (source_x_len>0) { - if (source_x[source_x_len-1]==':') has_drive_spec = true; + if (source_x[source_x_len-1] == ':') has_drive_spec = true; } if (!has_drive_spec && !strpbrk(source_p,"*?") ) { //doubt that fu*\*.* is valid if (DOS_FindFirst(source_p,0xffff & ~DOS_ATTR_VOLUME)) { @@ -790,7 +790,7 @@ void DOS_Shell::CMD_COPY(char * args) { } sources.push_back(copysource(source_x,(plus)?true:false)); source_p = plus; - } while(source_p && *source_p); + } while (source_p && *source_p); } // At least one source has to be there if (!sources.size() || !sources[0].filename.size()) { @@ -800,26 +800,26 @@ void DOS_Shell::CMD_COPY(char * args) { }; copysource target; - // If more then one object exists and last target is not part of a + // If more then one object exists and last target is not part of a // concat sequence then make it the target. - if(sources.size()>1 && !sources[sources.size()-2].concat){ + if (sources.size() > 1 && !sources[sources.size() - 2].concat){ target = sources.back(); sources.pop_back(); } //If no target => default target with concat flag true to detect a+b+c - if(target.filename.size() == 0) target = copysource(defaulttarget,true); + if (target.filename.size() == 0) target = copysource(defaulttarget,true); copysource oldsource; copysource source; Bit32u count = 0; - while(sources.size()) { + while (sources.size()) { /* Get next source item and keep track of old source for concat start end */ oldsource = source; source = sources[0]; sources.erase(sources.begin()); //Skip first file if doing a+b+c. Set target to first file - if(!oldsource.concat && source.concat && target.concat) { + if (!oldsource.concat && source.concat && target.concat) { target = source; continue; } @@ -843,11 +843,11 @@ void DOS_Shell::CMD_COPY(char * args) { return; } char* temp = strstr(pathTarget,"*.*"); - if(temp) *temp = 0;//strip off *.* from target - + if (temp) *temp = 0;//strip off *.* from target + // add '\\' if target is a directory bool target_is_file = true; - if (pathTarget[strlen(pathTarget)-1]!='\\') { + if (pathTarget[strlen(pathTarget) - 1]!='\\') { if (DOS_FindFirst(pathTarget,0xffff & ~DOS_ATTR_VOLUME)) { dta.GetResult(name,size,date,time,attr); if (attr & DOS_ATTR_DIRECTORY) { @@ -868,42 +868,42 @@ void DOS_Shell::CMD_COPY(char * args) { Bit16u sourceHandle,targetHandle; char nameTarget[DOS_PATHLENGTH]; char nameSource[DOS_PATHLENGTH]; - + bool second_file_of_current_source = false; while (ret) { dta.GetResult(name,size,date,time,attr); - if ((attr & DOS_ATTR_DIRECTORY)==0) { + if ((attr & DOS_ATTR_DIRECTORY) == 0) { strcpy(nameSource,pathSource); strcat(nameSource,name); // Open Source if (DOS_OpenFile(nameSource,0,&sourceHandle)) { // Create Target or open it if in concat mode strcpy(nameTarget,pathTarget); - if (nameTarget[strlen(nameTarget)-1]=='\\') strcat(nameTarget,name); + if (nameTarget[strlen(nameTarget) - 1] == '\\') strcat(nameTarget,name); //Special variable to ensure that copy * a_file, where a_file is not a directory concats. bool special = second_file_of_current_source && target_is_file; - second_file_of_current_source = true; + second_file_of_current_source = true; if (special) oldsource.concat = true; //Don't create a new file when in concat mode if (oldsource.concat || DOS_CreateFile(nameTarget,0,&targetHandle)) { Bit32u dummy=0; //In concat mode. Open the target and seek to the eof - if (!oldsource.concat || (DOS_OpenFile(nameTarget,OPEN_READWRITE,&targetHandle) && + if (!oldsource.concat || (DOS_OpenFile(nameTarget,OPEN_READWRITE,&targetHandle) && DOS_SeekFile(targetHandle,&dummy,DOS_SEEK_END))) { - // Copy + // Copy static Bit8u buffer[0x8000]; // static, otherwise stack overflow possible. bool failed = false; Bit16u toread = 0x8000; do { failed |= DOS_ReadFile(sourceHandle,buffer,&toread); failed |= DOS_WriteFile(targetHandle,buffer,&toread); - } while (toread==0x8000); + } while (toread == 0x8000); failed |= DOS_CloseFile(sourceHandle); failed |= DOS_CloseFile(targetHandle); WriteOut(" %s\n",name); - if(!source.concat && !special) count++; //Only count concat files once + if (!source.concat && !special) count++; //Only count concat files once } else { DOS_CloseFile(sourceHandle); WriteOut(MSG_Get("SHELL_CMD_COPY_FAILURE"),const_cast(target.filename.c_str())); @@ -929,10 +929,10 @@ void DOS_Shell::CMD_SET(char * args) { StripSpaces(args); std::string line; if (!*args) { - /* No command line show all environment lines */ + /* No command line show all environment lines */ Bitu count=GetEnvCount(); for (Bitu a=0;a % + while (*p) { + if (*p != '%') *p_parsed++ = *p++; //Just add it (most likely path) + else if ( *(p+1) == '%') { + *p_parsed++ = '%'; p += 2; //%% => % } else { char * second = strchr(++p,'%'); if (!second) continue; @@ -989,12 +989,12 @@ void DOS_Shell::CMD_IF(char * args) { has_not = !has_not; } - if(strncasecmp(args,"ERRORLEVEL",10) == 0) { + if (strncasecmp(args,"ERRORLEVEL",10) == 0) { args += 10; //skip text //Strip spaces and == StripSpaces(args,'='); char* word = StripWord(args); - if(!isdigit(*word)) { + if (!isdigit(*word)) { WriteOut(MSG_Get("SHELL_CMD_IF_ERRORLEVEL_MISSING_NUMBER")); return; } @@ -1002,7 +1002,7 @@ void DOS_Shell::CMD_IF(char * args) { Bit8u n = 0; do n = n * 10 + (*word - '0'); while (isdigit(*++word)); - if(*word && !isspace(*word)) { + if (*word && !isspace(*word)) { WriteOut(MSG_Get("SHELL_CMD_IF_ERRORLEVEL_INVALID_NUMBER")); return; } @@ -1011,7 +1011,7 @@ void DOS_Shell::CMD_IF(char * args) { return; } - if(strncasecmp(args,"EXIST ",6) == 0) { + if (strncasecmp(args,"EXIST ",6) == 0) { args += 6; //Skip text StripSpaces(args); char* word = StripWord(args); @@ -1025,7 +1025,7 @@ void DOS_Shell::CMD_IF(char * args) { dos.dta(dos.tables.tempdta); bool ret=DOS_FindFirst(word,0xffff & ~DOS_ATTR_VOLUME); dos.dta(save_dta); - if (ret==(!has_not)) DoCommand(args); + if (ret == (!has_not)) DoCommand(args); } return; } @@ -1042,7 +1042,7 @@ void DOS_Shell::CMD_IF(char * args) { while (*args && (*args != '=')) args++; // check for == - if ((*args==0) || (args[1] != '=')) { + if ((*args == 0) || (args[1] != '=')) { SyntaxError(); return; } @@ -1059,7 +1059,7 @@ void DOS_Shell::CMD_IF(char * args) { *args++ = 0; // mark end of second word StripSpaces(args,'='); - if ((strcmp(word1,word2)==0)==(!has_not)) DoCommand(args); + if ((strcmp(word1,word2) == 0) == (!has_not)) DoCommand(args); } } @@ -1067,12 +1067,12 @@ void DOS_Shell::CMD_GOTO(char * args) { HELP("GOTO"); StripSpaces(args); if (!bf) return; - if (*args &&(*args==':')) args++; + if (*args &&(*args == ':')) args++; //label ends at the first space char* non_space = args; while (*non_space) { - if((*non_space == ' ') || (*non_space == '\t')) - *non_space = 0; + if ((*non_space == ' ') || (*non_space == '\t')) + *non_space = 0; else non_space++; } if (!*args) { @@ -1087,7 +1087,7 @@ void DOS_Shell::CMD_GOTO(char * args) { void DOS_Shell::CMD_SHIFT(char * args ) { HELP("SHIFT"); - if(bf) bf->Shift(); + if (bf) bf->Shift(); } void DOS_Shell::CMD_TYPE(char * args) { @@ -1109,7 +1109,7 @@ nextfile: do { n=1; DOS_ReadFile(handle,&c,&n); - if (c==0x1a) break; // stop at EOF + if (c == 0x1a) break; // stop at EOF DOS_WriteFile(STDOUT,&c,&n); } while (n); DOS_CloseFile(handle); @@ -1139,14 +1139,14 @@ void DOS_Shell::CMD_CALL(char * args){ } void DOS_Shell::CMD_DATE(char * args) { - HELP("DATE"); - if(ScanCMDBool(args,"H")) { + HELP("DATE"); + if (ScanCMDBool(args,"H")) { // synchronize date with host parameter time_t curtime; struct tm *loctime; curtime = time (NULL); loctime = localtime (&curtime); - + reg_cx = loctime->tm_year+1900; reg_dh = loctime->tm_mon+1; reg_dl = loctime->tm_mday; @@ -1157,14 +1157,14 @@ void DOS_Shell::CMD_DATE(char * args) { } // check if a date was passed in command line Bit32u newday,newmonth,newyear; - if(sscanf(args,"%u-%u-%u",&newmonth,&newday,&newyear)==3) { + if (sscanf(args,"%u-%u-%u",&newmonth,&newday,&newyear) == 3) { reg_cx = static_cast(newyear); reg_dh = static_cast(newmonth); reg_dl = static_cast(newday); reg_ah=0x2b; // set system date CALLBACK_RunRealInt(0x21); - if(reg_al==0xff) WriteOut(MSG_Get("SHELL_CMD_DATE_ERROR")); + if (reg_al == 0xff) WriteOut(MSG_Get("SHELL_CMD_DATE_ERROR")); return; } // display the current date @@ -1174,47 +1174,47 @@ void DOS_Shell::CMD_DATE(char * args) { const char* datestring = MSG_Get("SHELL_CMD_DATE_DAYS"); Bit32u length; char day[6] = {0}; - if(sscanf(datestring,"%u",&length) && (length<5) && (strlen(datestring)==(length*7+1))) { + if (sscanf(datestring,"%u",&length) && (length<5) && (strlen(datestring) == (length*7+1))) { // date string appears valid - for(Bit32u i = 0; i < length; i++) day[i] = datestring[reg_al*length+1+i]; + for (Bit32u i = 0; i < length; i++) day[i] = datestring[reg_al*length+1+i]; } bool dateonly = ScanCMDBool(args,"T"); - if(!dateonly) WriteOut(MSG_Get("SHELL_CMD_DATE_NOW")); + if (!dateonly) WriteOut(MSG_Get("SHELL_CMD_DATE_NOW")); const char* formatstring = MSG_Get("SHELL_CMD_DATE_FORMAT"); - if(strlen(formatstring)!=5) return; + if (strlen(formatstring)!=5) return; char buffer[15] = {0}; Bitu bufferptr=0; - for(Bitu i = 0; i < 5; i++) { - if(i==1 || i==3) { + for (Bitu i = 0; i < 5; i++) { + if (i == 1 || i == 3) { buffer[bufferptr] = formatstring[i]; bufferptr++; } else { - if(formatstring[i]=='M') bufferptr += sprintf(buffer+bufferptr,"%02u",(Bit8u) reg_dh); - if(formatstring[i]=='D') bufferptr += sprintf(buffer+bufferptr,"%02u",(Bit8u) reg_dl); - if(formatstring[i]=='Y') bufferptr += sprintf(buffer+bufferptr,"%04u",(Bit16u) reg_cx); + if (formatstring[i] == 'M') bufferptr += sprintf(buffer+bufferptr,"%02u",(Bit8u) reg_dh); + if (formatstring[i] == 'D') bufferptr += sprintf(buffer+bufferptr,"%02u",(Bit8u) reg_dl); + if (formatstring[i] == 'Y') bufferptr += sprintf(buffer+bufferptr,"%04u",(Bit16u) reg_cx); } } WriteOut("%s %s\n",day, buffer); - if(!dateonly) WriteOut(MSG_Get("SHELL_CMD_DATE_SETHLP")); + if (!dateonly) WriteOut(MSG_Get("SHELL_CMD_DATE_SETHLP")); }; void DOS_Shell::CMD_TIME(char * args) { HELP("TIME"); - if(ScanCMDBool(args,"H")) { + if (ScanCMDBool(args,"H")) { // synchronize time with host parameter time_t curtime; struct tm *loctime; curtime = time (NULL); loctime = localtime (&curtime); - + //reg_cx = loctime->; //reg_dh = loctime->; //reg_dl = loctime->; // reg_ah=0x2d; // set system time TODO // CALLBACK_RunRealInt(0x21); - + Bit32u ticks=(Bit32u)(((double)(loctime->tm_hour*3600+ loctime->tm_min*60+ loctime->tm_sec))*18.206481481); @@ -1231,7 +1231,7 @@ void DOS_Shell::CMD_TIME(char * args) { reg_cl= // minutes reg_ch= // hours */ - if(timeonly) { + if (timeonly) { WriteOut("%2u:%02u\n",reg_ch,reg_cl); } else { WriteOut(MSG_Get("SHELL_CMD_TIME_NOW")); @@ -1240,7 +1240,7 @@ void DOS_Shell::CMD_TIME(char * args) { }; void DOS_Shell::CMD_SUBST (char * args) { -/* If more that one type can be substed think of something else +/* If more that one type can be substed think of something else * E.g. make basedir member dos_drive instead of localdrive */ HELP("SUBST"); @@ -1254,38 +1254,38 @@ void DOS_Shell::CMD_SUBST (char * args) { CommandLine command(0,args); if (command.GetCount() != 2) throw 0 ; - + command.FindCommand(1,arg); - if( (arg.size()>1) && arg[1] !=':') throw(0); + if ( (arg.size() > 1) && arg[1] !=':') throw(0); temp_str[0]=(char)toupper(args[0]); command.FindCommand(2,arg); - if((arg=="/D") || (arg=="/d")) { - if(!Drives[temp_str[0]-'A'] ) throw 1; //targetdrive not in use + if ((arg == "/D") || (arg == "/d")) { + if (!Drives[temp_str[0]-'A'] ) throw 1; //targetdrive not in use strcat(mountstring,"-u "); strcat(mountstring,temp_str); this->ParseLine(mountstring); return; } - if(Drives[temp_str[0]-'A'] ) throw 0; //targetdrive in use + if (Drives[temp_str[0]-'A'] ) throw 0; //targetdrive in use strcat(mountstring,temp_str); strcat(mountstring," "); Bit8u drive;char fulldir[DOS_PATHLENGTH]; if (!DOS_MakeName(const_cast(arg.c_str()),fulldir,&drive)) throw 0; - - if( ( ldp=dynamic_cast(Drives[drive])) == 0 ) throw 0; - char newname[CROSS_LEN]; + + if ( ( ldp=dynamic_cast(Drives[drive])) == 0 ) throw 0; + char newname[CROSS_LEN]; strcpy(newname, ldp->getBasedir()); strcat(newname,fulldir); CROSS_FILENAME(newname); ldp->dirCache.ExpandName(newname); - strcat(mountstring,"\""); + strcat(mountstring,"\""); strcat(mountstring, newname); - strcat(mountstring,"\""); + strcat(mountstring,"\""); this->ParseLine(mountstring); } catch(int a){ - if(a == 0) { + if (a == 0) { WriteOut(MSG_Get("SHELL_CMD_SUBST_FAILURE")); } else { WriteOut(MSG_Get("SHELL_CMD_SUBST_NO_REMOVE")); @@ -1296,7 +1296,7 @@ void DOS_Shell::CMD_SUBST (char * args) { WriteOut(MSG_Get("SHELL_CMD_SUBST_FAILURE")); return; } - + return; } @@ -1305,8 +1305,8 @@ void DOS_Shell::CMD_LOADHIGH(char *args){ Bit16u umb_start=dos_infoblock.GetStartOfUMBChain(); Bit8u umb_flag=dos_infoblock.GetUMBChainState(); Bit8u old_memstrat=(Bit8u)(DOS_GetMemAllocStrategy()&0xff); - if (umb_start==0x9fff) { - if ((umb_flag&1)==0) DOS_LinkUMBsToMemChain(1); + if (umb_start == 0x9fff) { + if ((umb_flag&1) == 0) DOS_LinkUMBsToMemChain(1); DOS_SetMemAllocStrategy(0x80); // search in UMBs first this->ParseLine(args); Bit8u current_umb_flag=dos_infoblock.GetUMBChainState(); @@ -1340,17 +1340,17 @@ void DOS_Shell::CMD_CHOICE(char * args){ } } if (rem) rem += 2; - if(rem && rem[0]==':') rem++; /* optional : after /c */ + if (rem && rem[0] == ':') rem++; /* optional : after /c */ if (args > last) args = NULL; } if (!rem || !*rem) rem = defchoice; /* No choices specified use YN */ ptr = rem; Bit8u c; - if(!optS) while ((c = *ptr)) *ptr++ = (char)toupper(c); /* When in no case-sensitive mode. make everything upcase */ - if(args && *args ) { + if (!optS) while ((c = *ptr)) *ptr++ = (char)toupper(c); /* When in no case-sensitive mode. make everything upcase */ + if (args && *args ) { StripSpaces(args); size_t argslen = strlen(args); - if(argslen>1 && args[0] == '"' && args[argslen-1] =='"') { + if (argslen > 1 && args[0] == '"' && args[argslen-1] == '"') { args[argslen-1] = 0; //Remove quotes args++; } @@ -1358,10 +1358,10 @@ void DOS_Shell::CMD_CHOICE(char * args){ } /* Show question prompt of the form [a,b]? where a b are the choice values */ if (!optN) { - if(args && *args) WriteOut(" "); + if (args && *args) WriteOut(" "); WriteOut("["); size_t len = strlen(rem); - for(size_t t = 1; t < len; t++) { + for (size_t t = 1; t < len; t++) { WriteOut("%c,",rem[t-1]); } WriteOut("%c]?",rem[len-1]); @@ -1384,10 +1384,10 @@ void DOS_Shell::CMD_ATTRIB(char *args){ void DOS_Shell::CMD_PATH(char *args){ HELP("PATH"); - if(args && strlen(args)){ + if (args && strlen(args)){ char pathstring[DOS_PATHLENGTH+CROSS_LEN+20]={ 0 }; strcpy(pathstring,"set PATH="); - while(args && *args && (*args=='='|| *args==' ')) + while (args && *args && (*args == '='|| *args == ' ')) args++; strcat(pathstring,args); this->ParseLine(pathstring); @@ -1403,9 +1403,9 @@ void DOS_Shell::CMD_PATH(char *args){ void DOS_Shell::CMD_VER(char *args) { HELP("VER"); - if(args && strlen(args)) { + if (args && strlen(args)) { char* word = StripWord(args); - if(strcasecmp(word,"set")) return; + if (strcasecmp(word,"set")) return; word = StripWord(args); if (!*args && !*word) { //Reset dos.version.major = 5;