diff --git a/cd.h b/cd.h index be8fcd3..93b9057 100644 --- a/cd.h +++ b/cd.h @@ -8,6 +8,7 @@ typedef struct int start; int end; int type; + int sector_size; } track_t; typedef struct diff --git a/menu.cpp b/menu.cpp index b202427..b93ae6d 100644 --- a/menu.cpp +++ b/menu.cpp @@ -1155,6 +1155,7 @@ void HandleUI(void) } else { + parentstate = MENU_NONE1; menustate = MENU_8BIT_MAIN1; } } @@ -1325,6 +1326,7 @@ void HandleUI(void) hdmask = spi_w(0); DisableIO(); user_io_read_confstr(); + uint32_t s_entry = 0; int entry = 0; while(1) { @@ -1384,6 +1386,7 @@ void HandleUI(void) // check for 'F'ile or 'S'D image strings if ((p[0] == 'F') || (p[0] == 'S')) { + if (p[0] == 'S') s_entry = selentry; substrcpy(s, p, 2); if (strlen(s)) { @@ -1518,6 +1521,12 @@ void HandleUI(void) menusub_last = selentry; menumask = (menumask << 1) | 1; + if (parentstate == MENU_NONE1 && is_pce() && pcecd_using_cd() && menusub != s_entry) + { + menusub = s_entry; + continue; + } + if (!adjvisible) break; firstmenu += adjvisible; } diff --git a/support/pcecd/pcecd.cpp b/support/pcecd/pcecd.cpp index c0a68a8..2207661 100644 --- a/support/pcecd/pcecd.cpp +++ b/support/pcecd/pcecd.cpp @@ -69,7 +69,7 @@ void pcecd_poll() data_mode = spi_w(0); DisableIO(); - + switch (data_mode & 0xFF) { case 0: @@ -120,6 +120,11 @@ static void notify_mount(int load) } } +int pcecd_using_cd() +{ + return pcecdd.loaded; +} + void pcecd_set_image(int num, const char *filename) { (void)num; diff --git a/support/pcecd/pcecd.h b/support/pcecd/pcecd.h index 2d34d81..9a6aaa2 100644 --- a/support/pcecd/pcecd.h +++ b/support/pcecd/pcecd.h @@ -22,7 +22,7 @@ #define PCECD_STATUS_CHECK_COND 1 #define PCECD_STATUS_CONDITION_MET 2 #define PCECD_STATUS_BUSY 4 -#define PCECD_STATUS_INTERMEDIATE 8 +#define PCECD_STATUS_INTERMEDIATE 8 #define SENSEKEY_NO_SENSE 0x0 #define SENSEKEY_NOT_READY 0x2 @@ -30,7 +30,7 @@ #define SENSEKEY_HARDWARE_ERROR 0x4 #define SENSEKEY_ILLEGAL_REQUEST 0x5 #define SENSEKEY_UNIT_ATTENTION 0x6 -#define SENSEKEY_ABORTED_COMMAND 0xB +#define SENSEKEY_ABORTED_COMMAND 0xB #define NSE_NO_DISC 0x0B #define NSE_TRAY_OPEN 0x0D @@ -44,7 +44,7 @@ #define NSE_END_OF_VOLUME 0x25 #define NSE_INVALID_REQUEST_IN_CDB 0x27 #define NSE_DISC_CHANGED 0x28 -#define NSE_AUDIO_NOT_PLAYING 0x2C +#define NSE_AUDIO_NOT_PLAYING 0x2C #include "../../cd.h" @@ -84,7 +84,6 @@ private: int index; int lba; int cnt; - uint16_t sectorSize; int scanOffset; int audioLength; int audioOffset; @@ -123,5 +122,6 @@ void pcecd_poll(); void pcecd_set_image(int num, const char *filename); int pcecd_send_data(uint8_t* buf, int len, uint8_t index); void pcecd_reset(); +int pcecd_using_cd(); #endif diff --git a/support/pcecd/pcecdd.cpp b/support/pcecd/pcecdd.cpp index fa9c341..c4ee524 100644 --- a/support/pcecd/pcecdd.cpp +++ b/support/pcecd/pcecdd.cpp @@ -141,19 +141,19 @@ int pcecdd_t::LoadCUE(const char* filename) { { if (strstr(lptr, "MODE1/2048")) { - this->sectorSize = 2048; + this->toc.tracks[this->toc.last].sector_size = 2048; this->toc.tracks[this->toc.last].type = 1; } else if (strstr(lptr, "MODE1/2352")) { - this->sectorSize = 2352; + this->toc.tracks[this->toc.last].sector_size = 2352; this->toc.tracks[this->toc.last].type = 1; FileSeek(&this->toc.tracks[this->toc.last].f, 0x10, SEEK_SET); } else if (strstr(lptr, "AUDIO")) { - this->sectorSize = 2352; + this->toc.tracks[this->toc.last].sector_size = 2352; this->toc.tracks[this->toc.last].type = 0; FileSeek(&this->toc.tracks[this->toc.last].f, 0, SEEK_SET); @@ -195,7 +195,7 @@ int pcecdd_t::LoadCUE(const char* filename) { else if ((sscanf(lptr, "INDEX 01 %02d:%02d:%02d", &mm, &ss, &bb) == 3) || (sscanf(lptr, "INDEX 1 %02d:%02d:%02d", &mm, &ss, &bb) == 3)) { - this->toc.tracks[this->toc.last].offset += pregap * 2352; + this->toc.tracks[this->toc.last].offset = pregap * this->toc.tracks[this->toc.last].sector_size; if (!this->toc.tracks[this->toc.last].f.opened()) { @@ -211,11 +211,8 @@ int pcecdd_t::LoadCUE(const char* filename) { FileSeek(&this->toc.tracks[this->toc.last].f, 0, SEEK_SET); this->toc.tracks[this->toc.last].start = this->toc.end + pregap; - this->toc.tracks[this->toc.last].offset += this->toc.end * 2352; - - int sectorSize = 2352; - if (this->toc.tracks[this->toc.last].type) sectorSize = this->sectorSize; - this->toc.tracks[this->toc.last].end = this->toc.tracks[this->toc.last].start + ((this->toc.tracks[this->toc.last].f.size + sectorSize - 1) / sectorSize); + this->toc.tracks[this->toc.last].offset += this->toc.tracks[this->toc.last].start * this->toc.tracks[this->toc.last].sector_size; + this->toc.tracks[this->toc.last].end = this->toc.tracks[this->toc.last].start + ((this->toc.tracks[this->toc.last].f.size + this->toc.tracks[this->toc.last].sector_size - 1) / this->toc.tracks[this->toc.last].sector_size); this->toc.tracks[this->toc.last].start += (bb + ss * 75 + mm * 60 * 75); this->toc.end = this->toc.tracks[this->toc.last].end; @@ -243,46 +240,13 @@ int pcecdd_t::LoadCUE(const char* filename) { int pcecdd_t::Load(const char *filename) { - //char fname[1024 + 10]; - static char header[1024]; - fileTYPE *fd_img; - Unload(); if (LoadCUE(filename)) { return (-1); } - fd_img = &this->toc.tracks[0].f; - - FileSeek(fd_img, 0, SEEK_SET); - FileReadAdv(fd_img, header, 0x10); - - if (!memcmp("SEGADISCSYSTEM", header, 14)) - { - this->sectorSize = 2048; - } - else - { - FileReadAdv(fd_img, header, 0x10); - if (!memcmp("SEGADISCSYSTEM", header, 14)) - { - this->sectorSize = 2352; - } - } - - if (this->sectorSize) - { - FileReadAdv(fd_img, header + 0x10, 0x200); - FileSeek(fd_img, 0, SEEK_SET); - } - else - { - FileClose(fd_img); - return (-1); - } - - printf("\x1b[32mPCECD: Sector size = %u, Track 0 end = %u\n\x1b[0m", this->sectorSize, this->toc.tracks[0].end); + printf("\x1b[32mPCECD: Tr0 Sector size = %u, Tr0 end = %u\n\x1b[0m", this->toc.tracks[0].sector_size, this->toc.tracks[0].end); if (this->toc.last) { @@ -315,7 +279,6 @@ void pcecdd_t::Unload() } memset(&this->toc, 0x00, sizeof(this->toc)); - this->sectorSize = 0; } void pcecdd_t::Reset() { @@ -551,13 +514,10 @@ void pcecdd_t::CommandExec() { lba_ = this->toc.tracks[index].start; } - if (this->toc.tracks[index].type) + if (this->toc.tracks[index].f.opened()) { - FileSeek(&this->toc.tracks[0].f, lba_ * this->sectorSize, SEEK_SET); - } - else if (this->toc.tracks[index].f.opened()) - { - FileSeek(&this->toc.tracks[index].f, (lba_ * 2352) - this->toc.tracks[index].offset, SEEK_SET); + int offset = (lba_ * this->toc.tracks[index].sector_size) - this->toc.tracks[index].offset; + FileSeek(&this->toc.tracks[index].f, offset, SEEK_SET); } this->audioOffset = 0; @@ -760,16 +720,16 @@ void pcecdd_t::ReadData(uint8_t *buf) { if (this->toc.tracks[this->index].type && (this->lba >= 0)) { - if (this->sectorSize == 2048) + if (this->toc.tracks[this->index].sector_size == 2048) { - FileSeek(&this->toc.tracks[0].f, this->lba * 2048, SEEK_SET); + FileSeek(&this->toc.tracks[this->index].f, this->lba * 2048 - this->toc.tracks[this->index].offset, SEEK_SET); } else { - FileSeek(&this->toc.tracks[0].f, this->lba * 2352 + 16, SEEK_SET); + FileSeek(&this->toc.tracks[this->index].f, this->lba * 2352 + 16 - this->toc.tracks[this->index].offset, SEEK_SET); } - FileReadAdv(&this->toc.tracks[0].f, buf, 2048); + FileReadAdv(&this->toc.tracks[this->index].f, buf, 2048); } }