Skip to content

Commit

Permalink
pcecd: initial support.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorgelig committed Apr 19, 2020
1 parent a4f6f0d commit d2e3d0f
Show file tree
Hide file tree
Showing 15 changed files with 1,183 additions and 28 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CPP_SRC = $(wildcard *.cpp) \
$(wildcard ./support/neogeo/*.cpp) \
$(wildcard ./support/arcade/*.cpp) \
$(wildcard ./support/megacd/*.cpp) \
$(wildcard ./support/pcecd/*.cpp) \
$(wildcard ./support/c64/*.cpp) \
lib/lodepng/lodepng.cpp

Expand Down
4 changes: 4 additions & 0 deletions MiSTer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
<ClCompile Include="support\minimig\minimig_fdd.cpp" />
<ClCompile Include="support\minimig\minimig_hdd.cpp" />
<ClCompile Include="support\neogeo\loader.cpp" />
<ClCompile Include="support\pcecd\pcecd.cpp" />
<ClCompile Include="support\pcecd\pcecdd.cpp" />
<ClCompile Include="support\sharpmz\sharpmz.cpp" />
<ClCompile Include="support\snes\snes.cpp" />
<ClCompile Include="support\st\st_tos.cpp" />
Expand All @@ -98,6 +100,7 @@
<ClInclude Include="battery.h" />
<ClInclude Include="bootcore.h" />
<ClInclude Include="brightness.h" />
<ClInclude Include="cd.h" />
<ClInclude Include="cfg.h" />
<ClInclude Include="charrom.h" />
<ClInclude Include="cheats.h" />
Expand Down Expand Up @@ -142,6 +145,7 @@
<ClInclude Include="support\minimig\minimig_hdd.h" />
<ClInclude Include="support\minimig\minimig_hdd_internal.h" />
<ClInclude Include="support\neogeo\loader.h" />
<ClInclude Include="support\pcecd\pcecd.h" />
<ClInclude Include="support\sharpmz\sharpmz.h" />
<ClInclude Include="support\snes\snes.h" />
<ClInclude Include="support\st\st_tos.h" />
Expand Down
12 changes: 12 additions & 0 deletions MiSTer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@
<ClCompile Include="support\c64\c64.cpp">
<Filter>Source Files\support</Filter>
</ClCompile>
<ClCompile Include="support\pcecd\pcecd.cpp">
<Filter>Source Files\support</Filter>
</ClCompile>
<ClCompile Include="support\pcecd\pcecdd.cpp">
<Filter>Source Files\support</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="battery.h">
Expand Down Expand Up @@ -348,5 +354,11 @@
<ClInclude Include="support\c64\c64.h">
<Filter>Header Files\support</Filter>
</ClInclude>
<ClInclude Include="cd.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="support\pcecd\pcecd.h">
<Filter>Header Files\support</Filter>
</ClInclude>
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions cd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef CD_H
#define CD_H

typedef struct
{
fileTYPE f;
int offset;
int start;
int end;
int type;
} track_t;

typedef struct
{
int end;
int last;
track_t tracks[100];
// fileTYPE sub;
} toc_t;

typedef struct
{
uint8_t m;
uint8_t s;
uint8_t f;
} msf_t;


typedef int (*SendDataFunc) (uint8_t* buf, int len, uint8_t index);

#endif
6 changes: 5 additions & 1 deletion menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,10 @@ void HandleUI(void)
}
mcd_set_image(ioctl_index, SelectedPath);
}
else if (is_pce())
{
pcecd_set_image(ioctl_index, SelectedPath);
}
else
{
user_io_set_index(user_io_ext_idx(SelectedPath, fs_pFileExt) << 6 | (menusub + 1));
Expand Down Expand Up @@ -3545,7 +3549,7 @@ void HandleUI(void)
char type = flist_SelectedItem()->de.d_type;
memcpy(name, flist_SelectedItem()->de.d_name, sizeof(name));

if ((fs_Options & SCANO_UMOUNT) && is_megacd() && type == DT_DIR && strcmp(flist_SelectedItem()->de.d_name, ".."))
if ((fs_Options & SCANO_UMOUNT) && (is_megacd() || is_pce()) && type == DT_DIR && strcmp(flist_SelectedItem()->de.d_name, ".."))
{
int len = strlen(SelectedPath);
strcat(SelectedPath, "/");
Expand Down
1 change: 1 addition & 0 deletions osd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ void OsdUpdate()
spi_write(osdbuf + i * 256, 256, 0);
DisableOsd();
if (is_megacd()) mcd_poll();
if (is_pce()) pcecd_poll();
}
}

Expand Down
3 changes: 3 additions & 0 deletions support.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@

// C64 support
#include "support/c64/c64.h"

// PCECD support
#include "support/pcecd/pcecd.h"
2 changes: 1 addition & 1 deletion support/megacd/cdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ void cdd_t::CommandExec() {
/* DATA track */
FileSeek(&this->toc.tracks[0].f, lba_ * this->sectorSize, SEEK_SET);
}
else if (cdd.toc.tracks[index].f.opened())
else if (this->toc.tracks[index].f.opened())
{
/* PCM AUDIO track */
FileSeek(&this->toc.tracks[index].f, (lba_ * 2352) - this->toc.tracks[index].offset, SEEK_SET);
Expand Down
2 changes: 1 addition & 1 deletion support/megacd/megacd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define SAVE_IO_INDEX 5 // fake download to trigger save loading

int loaded = 0, unloaded = 0, need_reset=0;
static int loaded = 0, unloaded = 0, need_reset=0;
static uint8_t has_command = 0;

void mcd_poll()
Expand Down
26 changes: 1 addition & 25 deletions support/megacd/megacd.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,7 @@
#define CD_COMM_TRAY_CLOSE 0x0C
#define CD_COMM_TRAY_OPEN 0x0D

typedef struct
{
fileTYPE f;
int offset;
int start;
int end;
int type;
} track_t;

typedef struct
{
int end;
int last;
track_t tracks[100];
// fileTYPE sub;
} toc_t;

typedef struct
{
uint8_t m;
uint8_t s;
uint8_t f;
} msf_t;

typedef int (*SendDataFunc) (uint8_t* buf, int len, uint8_t index);
#include "../../cd.h"

class cdd_t
{
Expand Down
136 changes: 136 additions & 0 deletions support/pcecd/pcecd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

#include "../../file_io.h"
#include "../../user_io.h"
#include "../../spi.h"
#include "../../hardware.h"
#include "pcecd.h"


static int /*loaded = 0, unloaded = 0,*/ need_reset=0;
static uint8_t has_command = 0;

void pcecd_poll()
{
static uint32_t poll_timer = 0;
static uint8_t last_req = 255;
static uint8_t adj = 0;

if (!poll_timer || CheckTimer(poll_timer))
{
poll_timer = GetTimer(13 + (!adj ? 1 : 0));
if (++adj >= 3) adj = 0;

if (pcecdd.has_status) {
uint16_t s;
pcecdd.GetStatus((uint8_t*)&s);

spi_uio_cmd_cont(UIO_CD_SET);
spi_w(s);
DisableIO();

pcecdd.has_status = 0;

printf("\x1b[32mPCECD: Send status = %02X, message = %02X\n\x1b[0m", s&0xFF, s >> 8);
}

pcecdd.Update();
}


uint8_t req = spi_uio_cmd_cont(UIO_CD_GET);
if (req != last_req)
{
last_req = req;

uint16_t data_in[6];
data_in[0] = spi_w(0);
data_in[1] = spi_w(0);
data_in[2] = spi_w(0);
data_in[3] = spi_w(0);
data_in[4] = spi_w(0);
data_in[5] = spi_w(0);
DisableIO();

if (need_reset) {
need_reset = 0;
pcecdd.Reset();
}

if (!((uint8_t*)data_in)[11]) {
pcecdd.SetCommand((uint8_t*)data_in);
pcecdd.CommandExec();
has_command = 1;
}
else {
pcecdd.can_read_next = true;
}


//printf("\x1b[32mMCD: Get command, command = %04X%04X%04X, has_command = %u\n\x1b[0m", data_in[2], data_in[1], data_in[0], has_command);
}
else
DisableIO();
}

void pcecd_reset() {
need_reset = 1;
}

static void notify_mount(int load)
{
spi_uio_cmd16(UIO_SET_SDINFO, load);
spi_uio_cmd8(UIO_SET_SDSTAT, 1);

if (!load)
{
user_io_8bit_set_status(UIO_STATUS_RESET, UIO_STATUS_RESET);
usleep(100000);
user_io_8bit_set_status(0, UIO_STATUS_RESET);
}
}

void pcecd_set_image(int num, const char *filename)
{
(void)num;

pcecdd.Unload();
pcecdd.status = CD_STAT_OPEN;

if (strlen(filename)) {
static char path[1024];

if (pcecdd.Load(filename) > 0) {
pcecdd.status = pcecdd.loaded ? CD_STAT_STOP : CD_STAT_NO_DISC;
pcecdd.latency = 10;
pcecdd.SendData = pcecd_send_data;

// load CD BIOS
sprintf(path, "%s/cd.rom", user_io_get_core_path());
user_io_file_tx(path, 0);
notify_mount(1);
}
else {
notify_mount(0);
pcecdd.status = CD_STAT_NO_DISC;
}
}
else
{
pcecdd.Unload();
notify_mount(0);
pcecdd.status = CD_STAT_NO_DISC;
}
}

int pcecd_send_data(uint8_t* buf, int len, uint8_t index) {
user_io_set_index(index);
user_io_set_download(1);
user_io_file_tx_write(buf, len);
user_io_set_download(0);
return 1;
}
Loading

0 comments on commit d2e3d0f

Please sign in to comment.