SPI bug: works on Duemilanove but not on Mega

I have a SparkFun 8x8 RGB LED matrix with a backpack that is controlled via SPI. The following program works just fine on the Duemilanove but not when run on an Arduino Mega. Other programs run fine on the Mega including those using serial communication. Could anyone out there who has a Mega and one of these LED displays try this sketch to see if it works on their hardware?

// Blinking LEDs

// Simple program to test the SparkFun 8x8 RGB LED matrix and its SPI backpack
//
// Revised 2009.12.24
//
// Credits:
//   Heather Dewey-Hagborg
//   Arduino Forum user Little-Scale
//   Daniel Hirschmann
//   Arduino Forum user chessplayer

// SPI register bit positions

#define RX_IN  0
#define TX_OUT 1
#define CS     2
#define MOSI   3
#define MISO   4
#define SCK    5

// Arduino Duemilanove pin numbers for SPI

#define CHIPSELECT 10 // CS
#define DATAOUT    11 // MOSI
#define DATAIN     12 // MISO (not used)
#define SPICLOCK   13 // SCK

// SparkFun 8x8 RGB LED backpack officially supported LED colors

typedef unsigned char ledcolorType;

#define ledcolorBlack   0x00
#define ledcolorRed     0xe0
#define ledcolorGreen   0x1c
#define ledcolorBlue    0x03
#define ledcolorOrange  0xfc
#define ledcolorMagneta 0xe3
#define ledcolorTeal    0x1f
#define ledcolorWhite   0xff

#define ledcolorLen 8

static const ledcolorType ledcolors[ledcolorLen] =
{
  ledcolorBlack,  ledcolorRed,     ledcolorGreen, ledcolorBlue,
  ledcolorOrange, ledcolorMagneta, ledcolorTeal,  ledcolorWhite
};

// SparkFun 8x8 RGB LED backpack frame geometry

#define rowLen 8
#define colLen 8

typedef struct
{
  ledcolorType pixels[rowLen][colLen];
} frameType;

static void SetFrameToColor(frameType& frame, const ledcolorType ledcolor)
{
  for (unsigned int col = 0; col < colLen; col++)
    for (unsigned int row = 0; row < rowLen; row++)
      frame.pixels[row][col] = ledcolor;
}

static void SetFrameToBlack(frameType& frame) {SetFrameToColor(frame, ledcolorBlack);}

static unsigned char PickRandomColor(void) {return ledcolors[random(ledcolorLen)];}

static void ChangeOneRandomPixelToColor(frameType& frame, const ledcolorType ledcolor)
{
  frame.pixels[random(rowLen)][random(colLen)] = ledcolor;
}

static void SetBackpackSelectStatus(const unsigned int status)
{
  digitalWrite(CHIPSELECT, status); delayMicroseconds(500);
}

static void BackpackEnable(void)  {SetBackpackSelectStatus(LOW);}
static void BackpackDisable(void) {SetBackpackSelectStatus(HIGH);}

static unsigned char WriteSPIByte(unsigned char data)
{
  SPDR = data; while (!(SPSR & (1 << SPIF))); return SPDR;
}

static void SetBackpackDaisyChainLength(const unsigned int length)
{
  BackpackEnable();
  WriteSPIByte('%'); WriteSPIByte(length);  
  BackpackDisable();
}

static void WriteFrame(const frameType& frame)
{
  BackpackEnable();
  for (unsigned int row = 0; row < rowLen; row++)
    for (unsigned int col = 0; col < colLen; col++)
      WriteSPIByte(frame.pixels[row][col]);
  BackpackDisable();
}

// The last real frame displayed

static frameType realframe;

// One time setup

void setup()
{
  // Initialize the Arduino SPI pin directions
  
  pinMode(CHIPSELECT, OUTPUT);
  pinMode(DATAIN,     INPUT);      
  pinMode(DATAOUT,    OUTPUT);      
  pinMode(SPICLOCK,   OUTPUT);

  // Magical initialization of the Arduino SPI registers

  volatile byte clr;

  DDRB = (1 << CS) | (1 << MOSI) | (1 << SCK);
  DDRD = (1 << TX_OUT);
  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1);
  SPSR = SPSR & 0xfe;  
  clr = SPSR; clr = SPDR;

  // Set the backpack to its default state

  BackpackDisable();
  SetBackpackDaisyChainLength(1);  // Be careful with this one

  // Initial display is all black pixels

  SetFrameToBlack(realframe); WriteFrame(realframe);
}

// Main loop

void loop()
{
  delay(100);
  ChangeOneRandomPixelToColor(realframe, PickRandomColor());
  WriteFrame(realframe);
}

Well, this is embarrassing. I looked at this all day and only after I posted the above did I figure out the problem.

1) In the sketch, take out the DDRB/DDRD initialialization. 2) Replace the SPI pin numbers:

// Arduino Mega pin numbers for SPI

#define CHIPSELECT 53 // CS
#define DATAIN     50 // MISO (not used)
#define DATAOUT    51 // MOSI
#define SPICLOCK   52 // SCK