Logo Search packages:      
Sourcecode: cbmlink version File versions  Download package

static int jump_cart ( unsigned  addr  )  [static]

download code for starting a cartridge in jump_cart

Parameters:
addr the desired address for the start-up code
Returns:
zero on success, nonzero on error

Vic-20 cartridge autostart signature

Vic-20 cartridge bootstrapper code

address of the cartridge start routine

address of the server start routine

Definition at line 151 of file cbmlink.c.

References ALTJUMP, buffer, CARTRESET, hostinfo::driver, hostinfo::host, jump(), load(), save(), and Vic.

Referenced by main().

{
  /** Vic-20 cartridge autostart signature */
  static const unsigned char autostart[5] = { 0x41, 0x30, 0xc3, 0xc2, 0xcd };
  /** Vic-20 cartridge bootstrapper code */
  static unsigned char auxcode[] = {
    /* this code starts the cartridge */
    0xa9, 0x7f,       /* lda #$7f  ; initialize the VIAs */
    0x8d, 0x3e, 0x91, /* sta $913e */
    0x8d, 0x3d, 0x91, /* sta $913d */
    0xa9, 0x00,       /* lda #$00 */
    0xa2, 0x0c,       /* ldx #$0c */
    0x9d, 0x10, 0x90, /* sta $9130,x */
    0xca,             /* dex */
    0x10, 0xfa,       /* bpl . - 4 */
    /* ALTJUMP: */
    0x78,             /* sei */
    0xa2, 0xff,       /* ldx #$ff */
    0x9a,             /* txs */
    0xd8,             /* cld */
    0xe8,             /* inx */
    0xa9, 0x41,       /* lda #$41 */
    0x8d, 0x04, 0xa0, /* sta $a004 (validate the boot signature) */
    /* auxstart - 1: */
    0x4c, 0, 0,       /* jmp $0000 (placeholder: original cart start) */
    /* CARTRESET: (executed when the game is reset) */
    0xa2, 0x0d,       /* ldx #$0d */
    0x8d, 0x04, 0xa0, /* stx $a004 (invalidate the boot signature) */
    0x20, 0x8d, 0xfd, /* jsr $fd8d (copied from the reset routine) */
    0x20, 0x52, 0xfd, /* jsr $fd52 */
    0x20, 0xf9, 0xfd, /* jsr $fdf9 */
    /* srvstart - 1: */
    0x20, 0, 0,       /* jsr $0000 (placeholder for server install) */
    0x4c, 0x38, 0xfd  /* jmp $fd38 */
  };

  /** address of the cartridge start routine */
  static unsigned char* const auxstart = &auxcode[30];
  /** address of the server start routine */
  static unsigned char* const srvstart = &auxcode[47];

  if (!hostinfo || hostinfo->host != Vic) {
    fputs ("jump_cart: target must be a Vic-20\n", stderr);
    return 1;
  }

  if (save (comm, 0, 0xa000, 0xa004 + sizeof autostart, buffer))
    return 2;
  if (memcmp (buffer + 4, autostart, sizeof autostart)) {
    fputs ("jump_cart: no autostart signature found\n", stderr);
    return 1;
  }
  /* patch the start-up code */
  memcpy (auxstart, buffer, 2);
  srvstart[0] = hostinfo->driver;
  srvstart[1] = hostinfo->driver >> 8;
  /* load the start-up code */
  if (load (comm, 0, addr, addr + sizeof auxcode, auxcode))
    return 2;
  /* patch the cartridge RESET vector */
  buffer[0] = CARTRESET;
  buffer[1] = CARTRESET >> 8;
  if (load (comm, 0, 0xa000, 0xa002, buffer))
    return 2;
  fprintf (stderr,
         "jump_cart: Restart with SYS%u or SYS%u after reset.\n",
         addr, ALTJUMP);
  /* start the cartridge */
  return jump (comm, 0, addr);
}


Generated by  Doxygen 1.6.0   Back to index