From: Jacob Moody <moody@mail.posixcafe.org>
To: 9front@9front.org
Subject: [9front] [PATCH] game boy advance header target for 5l
Date: Wed, 1 Mar 2023 23:56:11 -0700 [thread overview]
Message-ID: <f25ecd5a-d303-558a-0dad-30edc7badcf4@posixcafe.org> (raw)
This makes 5l capable of spitting out valid .gba files.
With this I was able to get a basic rom working.
To give this a try:
; hget http://okturing.com/src/15122/body > sprite.c
; 5c sprite.c
; 5l -H8 -Emain sprite.5
; games/gba 5.out
diff e6c6217b35c319127f0200fdb28ec86e1b774a4f uncommitted
--- a/sys/src/cmd/5l/asm.c
+++ b/sys/src/cmd/5l/asm.c
@@ -81,6 +81,7 @@
case 2:
case 5:
case 7:
+ case 8:
OFFSET = HEADR+textsize;
seek(cout, OFFSET, 0);
break;
@@ -126,6 +127,7 @@
seek(cout, OFFSET, 0);
break;
case 7:
+ case 8:
break;
}
if(!debug['s'])
@@ -269,6 +271,9 @@
lput(0x04L); /* protections = R */
lput(0x04L); /* alignment code?? */
break;
+ case 8: /* GameBoy Advance */
+ gbaheader();
+ break;
}
cflush();
}
@@ -1842,4 +1847,80 @@
return n;
}
return -1;
+}
+
+static char cart[] = {
+ /* entry point */
+ 0x00, 0x00, 0x00, 0x00,
+
+ /* nintendo logo */
+ 0x24,0xFF,0xAE,0x51,0x69,0x9A,0xA2,0x21,
+ 0x3D,0x84,0x82,0x0A,0x84,0xE4,0x09,0xAD,
+ 0x11,0x24,0x8B,0x98,0xC0,0x81,0x7F,0x21,
+ 0xA3,0x52,0xBE,0x19,0x93,0x09,0xCE,0x20,
+ 0x10,0x46,0x4A,0x4A,0xF8,0x27,0x31,0xEC,
+ 0x58,0xC7,0xE8,0x33,0x82,0xE3,0xCE,0xBF,
+ 0x85,0xF4,0xDF,0x94,0xCE,0x4B,0x09,0xC1,
+ 0x94,0x56,0x8A,0xC0,0x13,0x72,0xA7,0xFC,
+ 0x9F,0x84,0x4D,0x73,0xA3,0xCA,0x9A,0x61,
+ 0x58,0x97,0xA3,0x27,0xFC,0x03,0x98,0x76,
+ 0x23,0x1D,0xC7,0x61,0x03,0x04,0xAE,0x56,
+ 0xBF,0x38,0x84,0x00,0x40,0xA7,0x0E,0xFD,
+ 0xFF,0x52,0xFE,0x03,0x6F,0x95,0x30,0xF1,
+ 0x97,0xFB,0xC0,0x85,0x60,0xD6,0x80,0x25,
+ 0xA9,0x63,0xBE,0x03,0x01,0x4E,0x38,0xE2,
+ 0xF9,0xA2,0x34,0xFF,0xBB,0x3E,0x03,0x44,
+ 0x78,0x00,0x90,0xCB,0x88,0x11,0x3A,0x94,
+ 0x65,0xC0,0x7C,0x63,0x87,0xF0,0x3C,0xAF,
+ 0xD6,0x25,0xE4,0x8B,0x38,0x0A,0xAC,0x72,
+ 0x21,0xD4,0xF8,0x07,
+
+ /* title */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ /* game code */
+ 'A', 'P', '9', 'E',
+
+ /* maker code */
+ 'P', '9',
+
+ /* fixed */
+ 0x96,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+ /* compliment */
+ 0x00,
+
+ /* reserved */
+ 0x00, 0x00,
+};
+
+void
+gbaheader(void)
+{
+ ulong ep;
+ char *p, *e;
+ char c;
+
+ ep = 0xea000000;
+ ep += (entryvalue() - INITTEXT + HEADR - 8) / 4;
+ cart[3] = ep>>24;
+ cart[2] = ep>>16;
+ cart[1] = ep>>8;
+ cart[0] = ep;
+
+ p = cart + 0xA0;
+ if(strlen(outfile) < 12)
+ strcpy(p, outfile);
+
+ e = cart + 0xBD;
+ for(c = 0; p < e; p++)
+ c += *p;
+ *p = -(0x19+c);
+
+ p = cart;
+ e = p + sizeof cart;
+ for(;p < e; p++)
+ cput(*p);
}
--- a/sys/src/cmd/5l/l.h
+++ b/sys/src/cmd/5l/l.h
@@ -343,6 +343,7 @@
int find1(long, int);
char* findlib(char*);
void follow(void);
+void gbaheader(void);
void histtoauto(void);
double ieeedtod(Ieee*);
long ieeedtof(Ieee*);
--- a/sys/src/cmd/5l/obj.c
+++ b/sys/src/cmd/5l/obj.c
@@ -193,6 +193,15 @@
if(INITRND == -1)
INITRND = 4;
break;
+ case 8: /* GameBoy Advance */
+ HEADR = 192L;
+ if(INITTEXT == -1)
+ INITTEXT = 0x08000000 + HEADR;
+ if(INITDAT == -1)
+ INITDAT = 0;
+ if(INITRND == -1)
+ INITRND = 4;
+ break;
}
if(INITDAT != 0 && INITRND != 0)
print("warning: -D0x%lux is ignored because of -R0x%lux\n",
next reply other threads:[~2023-03-02 6:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 6:56 Jacob Moody [this message]
2023-03-02 11:15 ` [9front] " Anthony Martin
2023-03-02 16:08 ` Jacob Moody
2023-03-02 17:33 ` cinap_lenrek
2023-03-02 17:50 ` Jacob Moody
2023-03-03 20:59 ` cinap_lenrek
2023-03-03 21:18 ` Jacob Moody
2023-03-04 15:53 ` cinap_lenrek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f25ecd5a-d303-558a-0dad-30edc7badcf4@posixcafe.org \
--to=moody@mail.posixcafe.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).