Detecting USB flash cart and AR/Gameshark carts

mrkotfw

Mid Boss
Hello all!

Is there a way to reliably detect whether a USB cartridge is inserted or an AR cart? I know with an AR cart, reading from 0x22004AF0 will return a string, but is there a reliable way to know if a USB cart is inserted?

Are there different locations that I need to read from to detect an AR/Gameshark cart?
 

antime

Extra Hard Mid Boss
You can read the cartridge header, but I know there's one CD emulation cartridge that just copied the header without changes. And of course anyone can flash it with whatever image they like. You could also try deducing something from the status flags (0x22200001) but that's not completely reliable either.
 

cafe-alpha

Established Member
Here are the functions I'm using. As indicated by antime, I'm looking at the status flags (details here).

Code:
#define USB_FLAGS (*(volatile unsigned char*)(0x22200001))
#define USB_PWREN  (1 << 7)

int usb_is_available(void)
{
  unsigned char tmp = USB_FLAGS;

  if((tmp & 0x7C) == 0)
  {
    return 1;
  }

  return 0;
}

int usb_is_connected(void)
{
  unsigned char tmp = USB_FLAGS;

  if((tmp & 0xFC) == USB_PWREN)
  {
    return 0;
  }

  return 1;
}

usb_is_available function looks at unused (zero) bits in status register. On other cartridges, theses bits are usually set to high states, so it works, but of course it's not 100% reliable.
usb_is_connected function will return 1 if USB is connected to both Saturn and PC. It won't detect anything in the case USB port is not powered.
 
Top