Skip to content

Commit

Permalink
Change PCEAS to use a built-in copy of IPL-SCD when building a HuCC S…
Browse files Browse the repository at this point in the history
…uperCD.

Fix HuCC to pass on the "--sgx" command line flag to PCEAS so that a CD .iso
has the "(for SuperGRAFX)" identifier added to the IPL.
  • Loading branch information
jbrandwood committed Nov 30, 2024
1 parent 0546b84 commit 104d1ed
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 25 deletions.
15 changes: 11 additions & 4 deletions src/hucc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,11 @@ int assemble (char *s)
strcat_s(buf, sizeof(buf), " ");
for (p = buf; (p = strchr(p, '/')) != NULL; *p++ = '\\');

strcat_s(buf, sizeof(buf), "--hucc ");

if (sgflag)
strcat_s(buf, sizeof(buf), "--sgx ");

switch (cdflag) {
case 1:
strcat_s(buf, sizeof(buf), "--cd ");
Expand All @@ -1113,8 +1118,6 @@ int assemble (char *s)
strcat_s(buf, sizeof(buf), "-S -l 3 -m ");
}

strcat_s(buf, sizeof(buf), "--hucc ");

if (debug_info) {
const char * debug_opt;
switch (debug_info) {
Expand Down Expand Up @@ -1148,6 +1151,11 @@ int assemble (char *s)
exe = "pceas";
}
opts[i++] = exe;
opts[i++] = "--hucc"; /* --newproc --strip -O and more! */

if (sgflag)
opts[i++] = "--sgx";

switch (cdflag) {
case 1:
opts[i++] = "--cd";
Expand All @@ -1166,6 +1174,7 @@ int assemble (char *s)
if (overlayflag)
opts[i++] = "--over"; /* compile as overlay */


if (verboseflag) {
opts[i++] = "-S"; /* asm: display full segment map */
opts[i++] = "-l 3"; /* top listing output */
Expand All @@ -1174,8 +1183,6 @@ int assemble (char *s)
else
opts[i++] = "-l 0";

opts[i++] = "--hucc"; /* --newproc --strip -O and more! */

if (debug_info) {
switch (debug_info) {
case 'C': opts[i++] = "-gC"; break;
Expand Down
127 changes: 106 additions & 21 deletions src/mkit/as/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,55 @@ int section_limit[MAX_S] = {
/* S_OSEG */ 0x0100
};

/* custom SuperCD boot sector loader code made from "examples/asm/elmer/ipl-scd/" */
static unsigned char ipl_scd [704] = {
0x20,0x5A,0xE0,0xE0,0x03,0x90,0x59,0x20,0xDE,0xE0,0xB0,0x54,0x22,0x29,0x7F,0x22,
0xE0,0x03,0x90,0x4C,0xA9,0x68,0x53,0x04,0xA0,0x01,0xB9,0x01,0x36,0x38,0xF9,0x00,
0x36,0x85,0xF8,0x64,0xF9,0x43,0x04,0x85,0xFA,0x64,0xFB,0x62,0xCC,0x00,0x37,0x90,
0x01,0x1A,0x85,0xFC,0xB9,0x00,0x37,0x85,0xFD,0xB9,0x00,0x36,0x85,0xFE,0xA9,0x06,
0x85,0xFF,0x20,0x09,0xE0,0xC9,0x00,0xF0,0x06,0xA9,0x67,0xA2,0x31,0x80,0x1A,0x43,
0x04,0x1A,0x53,0x08,0x1A,0x53,0x10,0x1A,0x53,0x20,0x1A,0x53,0x40,0x4C,0x00,0x40,
0xAC,0xFF,0x35,0xD0,0xB5,0xA9,0x46,0xA2,0x31,0x48,0xDA,0x20,0x99,0xE0,0x20,0x7B,
0xE0,0x20,0x84,0x31,0xA9,0x7D,0x85,0xEC,0xA9,0x32,0x85,0xED,0x20,0xC4,0x31,0x62,
0xA2,0x20,0xA0,0x1C,0x20,0x6F,0xE0,0xA9,0x01,0x20,0x69,0xE0,0xA9,0x5D,0x8D,0x20,
0x22,0xA9,0x32,0x8D,0x21,0x22,0xA9,0x01,0x8D,0x22,0x22,0x9C,0x23,0x22,0x9C,0x24,
0x22,0x9C,0x25,0x22,0xA9,0x02,0x8D,0x1F,0x22,0xFA,0x68,0x20,0x1D,0x32,0x20,0x8A,
0xE0,0x20,0x7B,0xE0,0x80,0xFE,0x01,0x0D,0x41,0x42,0x43,0x44,0x45,0x40,0x46,0x47,
0x48,0x49,0x4A,0x4B,0x4C,0x40,0x41,0x4D,0x4E,0x4F,0x44,0x50,0x40,0x45,0x44,0x57,
0x42,0x58,0x45,0x44,0x52,0x53,0x00,0x03,0x0D,0x46,0x47,0x40,0x44,0x45,0x45,0x54,
0x45,0x53,0x40,0x46,0x55,0x51,0x51,0x54,0x4F,0x40,0x45,0x42,0x51,0x40,0x56,0x55,
0x50,0x44,0x53,0x00,0x44,0x14,0xA2,0x1C,0xC2,0x13,0x00,0x23,0x00,0x23,0x00,0x23,
0x00,0x23,0x00,0x88,0xD0,0xF5,0xCA,0xD0,0xF2,0x60,0xA9,0x05,0x85,0xF7,0x03,0x05,
0x23,0x00,0xA9,0x00,0x85,0xF7,0x03,0x00,0x9C,0x02,0x02,0x9C,0x03,0x02,0xA9,0x02,
0x85,0xF7,0x03,0x02,0xA2,0x08,0xC2,0x13,0x40,0x23,0x01,0x23,0x01,0x88,0xD0,0xF9,
0xCA,0xD0,0xF6,0x60,0xA2,0x14,0xA9,0xFF,0x48,0xA9,0x00,0x85,0xF7,0x03,0x00,0x9C,
0x02,0x02,0x8E,0x03,0x02,0xA9,0x02,0x85,0xF7,0x03,0x02,0xA9,0x19,0x85,0xF8,0xC2,
0x82,0x9E,0x00,0x21,0xB1,0xEC,0x9D,0x01,0x21,0x0A,0x11,0xEC,0x9D,0x02,0x21,0x1D,
0x00,0x21,0x5D,0x01,0x21,0x9D,0x00,0x21,0xC8,0xD0,0x02,0xE6,0xED,0xE8,0xE8,0xE0,
0x10,0xD0,0xE1,0xE3,0x00,0x21,0x02,0x02,0x10,0x00,0x68,0xA2,0x08,0x8D,0x02,0x02,
0x8D,0x03,0x02,0xCA,0xD0,0xFA,0x48,0xC6,0xF8,0xD0,0xC5,0x68,0x60,0x85,0xF8,0x86,
0xF9,0xA0,0x01,0xB1,0xF8,0x4A,0xAA,0x62,0x6A,0x22,0x4A,0x22,0x6A,0x12,0xF8,0xC8,
0x08,0x78,0x03,0x01,0x8D,0x02,0x02,0x8E,0x03,0x02,0x03,0x00,0x8D,0x02,0x02,0x8E,
0x03,0x02,0x03,0x02,0xA9,0x02,0x85,0xF7,0x28,0xB1,0xF8,0xF0,0x0F,0xC8,0x18,0x69,
0x00,0x8D,0x02,0x02,0x62,0x69,0x01,0x8D,0x03,0x02,0x80,0xED,0x60,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x4C,0x00,0x69,0x01,0xB2,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x60,0x3C,0x06,0x66,0x3C,0x00,0x00,0x00,0x66,
0x66,0x66,0x66,0x3E,0x00,0x00,0x00,0x7C,0x66,0x66,0x7C,0x60,0x60,0x00,0x00,0x3C,
0x66,0x7E,0x60,0x3C,0x00,0x00,0x00,0x3C,0x66,0x60,0x60,0x60,0x00,0x3C,0x66,0x60,
0x60,0x60,0x66,0x3C,0x00,0x7C,0x66,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x00,0x00,
0x7E,0x00,0x00,0x00,0x00,0x7C,0x66,0x66,0x7C,0x78,0x6C,0x66,0x00,0x3C,0x66,0x66,
0x66,0x66,0x66,0x3C,0x00,0x63,0x77,0x7F,0x6B,0x6B,0x63,0x63,0x00,0x3E,0x03,0x1E,
0x30,0x3F,0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x3C,0x00,0x00,0x3E,
0x60,0x3C,0x06,0x7C,0x00,0x00,0x18,0x7E,0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x36,
0x7F,0x6B,0x6B,0x63,0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x00,0x06,0x06,0x3E,
0x66,0x66,0x66,0x3E,0x00,0x18,0x3C,0x3C,0x18,0x18,0x00,0x18,0x00,0x00,0x00,0x3C,
0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x3C,0x06,0x3E,0x66,0x3E,0x00,0x00,0x00,0x3E,
0x66,0x66,0x3E,0x06,0x3C,0x00,0x00,0x3E,0x66,0x66,0x3E,0x07,0x06,0x18,0x00,0x38,
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};


/* ----
* atexit callback
* ----
Expand All @@ -155,6 +204,7 @@ cleanup(void)
cleanup_path();
}


/* ----
* prepare_ipl()
* ----
Expand Down Expand Up @@ -935,33 +985,68 @@ main(int argc, char **argv)
/* initialize the ipl */
prepare_ipl(ipl_buffer);

/* prg sector base */
ipl_buffer[0x802] = 2;
/* Use the built-in IPL-SCD loader? */
if (scd_opt && (hucc_opt || newproc_opt)) {
/* IPL-SCD loader code from the asm example project */
memcpy(ipl_buffer + 0x890, ipl_scd, sizeof(ipl_scd));

/* prg sector base */
ipl_buffer[0x802] = 0;

/* nb_sectors */
ipl_buffer[0x803] = 0;

/* nb sectors */
if (lablexists("HUC")) {
ipl_buffer[0x803] = 16; /* 4 banks */
/* loading address */
ipl_buffer[0x804] = 0;
ipl_buffer[0x805] = 0;

/* starting address */
ipl_buffer[0x806] = 0x3090 & 255;
ipl_buffer[0x807] = 0;

/* mpr registers */
ipl_buffer[0x808] = 0;
ipl_buffer[0x809] = 1;
ipl_buffer[0x80A] = 2;
ipl_buffer[0x80B] = 3;
ipl_buffer[0x80C] = 4;

/* load mode */
ipl_buffer[0x80D] = 0;
} else {
ipl_buffer[0x803] = (max_bank + 1) * 8192 / 2048;
}
/* prg sector base */
ipl_buffer[0x802] = 2;

/* nb sectors */
if (lablexists("HUCC") || !lablexists("HUC")) {
/* If it's not HuC, load the whole program */
ipl_buffer[0x803] = (max_bank + 1) * 8192 / 2048;
} else {
/* HuC boots segments up to and including the */
/* overlay array. The boot segments will load */
/* the remaining sectors and relocate code to */
/* SCD RAM if necessary */
ipl_buffer[0x803] = 16; /* 4 banks */
}

/* loading address */
ipl_buffer[0x804] = 0x00;
ipl_buffer[0x805] = 0x40;
/* loading address */
ipl_buffer[0x804] = 0x00;
ipl_buffer[0x805] = 0x40;

/* starting address */
ipl_buffer[0x806] = BOOT_ENTRY_POINT & 0xFF;
ipl_buffer[0x807] = (BOOT_ENTRY_POINT >> 8) & 0xFF;
/* starting address */
ipl_buffer[0x806] = BOOT_ENTRY_POINT & 0xFF;
ipl_buffer[0x807] = (BOOT_ENTRY_POINT >> 8) & 0xFF;

/* mpr registers */
ipl_buffer[0x808] = 0x00;
ipl_buffer[0x809] = 0x01;
ipl_buffer[0x80A] = 0x02;
ipl_buffer[0x80B] = 0x03;
ipl_buffer[0x80C] = 0x04;
/* mpr registers */
ipl_buffer[0x808] = 0x00;
ipl_buffer[0x809] = 0x01;
ipl_buffer[0x80A] = 0x02;
ipl_buffer[0x80B] = 0x03;
ipl_buffer[0x80C] = 0x04;

/* load mode */
ipl_buffer[0x80D] = 0x60;
/* load mode */
ipl_buffer[0x80D] = 0x60;
}

/* add a SuperGRAFX signature to the IPL Information Block */
if (sgx_opt)
Expand Down

0 comments on commit 104d1ed

Please sign in to comment.