tools: add smsrom
Running a ROM on an everdrive is one thing, but running a ROM directly is another: my hacked up sega.bin didn't have a proper checksum, so the ROM didn't run. This new tool transforms a binary into a properly-headered ROM. Has been tested on an actual SMS.
This commit is contained in:
parent
32d5f87b4e
commit
0d172cc2c4
@ -2,6 +2,7 @@ TARGET = os.bin
|
|||||||
BASE = ../../
|
BASE = ../../
|
||||||
STAGE = $(BASE)/cvm/stage
|
STAGE = $(BASE)/cvm/stage
|
||||||
BLKPACK = $(BASE)/tools/blkpack
|
BLKPACK = $(BASE)/tools/blkpack
|
||||||
|
SMSROM = $(BASE)/tools/smsrom
|
||||||
EMUL = $(BASE)/emul/hw/sms/sms
|
EMUL = $(BASE)/emul/hw/sms/sms
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
@ -9,6 +10,7 @@ all: $(TARGET)
|
|||||||
$(TARGET): xcomp.fs $(STAGE) blkfs
|
$(TARGET): xcomp.fs $(STAGE) blkfs
|
||||||
cat xcomp.fs | $(STAGE) blkfs > $@
|
cat xcomp.fs | $(STAGE) blkfs > $@
|
||||||
|
|
||||||
|
$(SMSROM):
|
||||||
$(BLKPACK):
|
$(BLKPACK):
|
||||||
$(MAKE) -C ../tools
|
$(MAKE) -C ../tools
|
||||||
|
|
||||||
@ -18,8 +20,8 @@ blkfs: $(BLKPACK)
|
|||||||
$(STAGE):
|
$(STAGE):
|
||||||
$(MAKE) -C $(BASE)/cvm stage
|
$(MAKE) -C $(BASE)/cvm stage
|
||||||
|
|
||||||
os.sms: $(TARGET) $(STAGE)
|
os.sms: $(TARGET) $(STAGE) $(SMSROM)
|
||||||
dd if=$(TARGET) bs=32752 conv=sync | cat - sega.bin > $@
|
$(SMSROM) $(TARGET) > $@
|
||||||
|
|
||||||
$(EMUL):
|
$(EMUL):
|
||||||
$(MAKE) -C ${@:%/sms=%}
|
$(MAKE) -C ${@:%/sms=%}
|
||||||
|
Binary file not shown.
5
tools/.gitignore
vendored
5
tools/.gitignore
vendored
@ -1,13 +1,10 @@
|
|||||||
/memdump
|
/memdump
|
||||||
/blkdump
|
/blkdump
|
||||||
/upload
|
/upload
|
||||||
/fontcompile
|
|
||||||
/ttysafe
|
/ttysafe
|
||||||
/pingpong
|
/pingpong
|
||||||
/slatest
|
|
||||||
/stripfc
|
|
||||||
/bin2c
|
|
||||||
/exec
|
/exec
|
||||||
/blkpack
|
/blkpack
|
||||||
/blkunpack
|
/blkunpack
|
||||||
/blkup
|
/blkup
|
||||||
|
/smsrom
|
||||||
|
@ -6,9 +6,10 @@ EXEC_TGT = exec
|
|||||||
BLKPACK_TGT = blkpack
|
BLKPACK_TGT = blkpack
|
||||||
BLKUNPACK_TGT = blkunpack
|
BLKUNPACK_TGT = blkunpack
|
||||||
BLKUP_TGT = blkup
|
BLKUP_TGT = blkup
|
||||||
|
SMSROM_TGT = smsrom
|
||||||
TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT) \
|
TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT) \
|
||||||
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \
|
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \
|
||||||
$(BLKUNPACK_TGT) $(BLKUP_TGT)
|
$(BLKUNPACK_TGT) $(BLKUP_TGT) $(SMSROM_TGT)
|
||||||
OBJS = common.o
|
OBJS = common.o
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
@ -25,6 +26,7 @@ $(EXEC_TGT): $(EXEC_TGT).c
|
|||||||
$(BLKPACK_TGT): $(BLKPACK_TGT).c
|
$(BLKPACK_TGT): $(BLKPACK_TGT).c
|
||||||
$(BLKUNPACK_TGT): $(BLKUNPACK_TGT).c
|
$(BLKUNPACK_TGT): $(BLKUNPACK_TGT).c
|
||||||
$(BLKUP_TGT): $(BLKUP_TGT).c
|
$(BLKUP_TGT): $(BLKUP_TGT).c
|
||||||
|
$(SMSROM_TGT): $(SMSROM_TGT).c
|
||||||
$(TARGETS): $(OBJS)
|
$(TARGETS): $(OBJS)
|
||||||
$(CC) $(CFLAGS) $@.c $(OBJS) -o $@
|
$(CC) $(CFLAGS) $@.c $(OBJS) -o $@
|
||||||
|
|
||||||
|
53
tools/smsrom.c
Normal file
53
tools/smsrom.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* ./smsrom fname
|
||||||
|
|
||||||
|
Transforms binary at fname into an 8K, 16K or 32K Sega Master System ROM with
|
||||||
|
a header fit for an Export SMS. The resulting ROM is spit to stdout.
|
||||||
|
|
||||||
|
Whether the ROM is 8, 16 or 32K depends on the size of binary at fname.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if (argc != 2) {
|
||||||
|
fprintf(stderr, "Usage: ./smsrom fname\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
FILE *fp = fopen(argv[1], "r");
|
||||||
|
if (!fp) {
|
||||||
|
fprintf(stderr, "Can't open %s.\n", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
long fsize = ftell(fp);
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
uint8_t hdsz = 0x4a; // size flag in header. either 4a, 4b or 4c.
|
||||||
|
int romsize = 0x2000;
|
||||||
|
while (romsize-16 < fsize) {
|
||||||
|
romsize *= 2;
|
||||||
|
hdsz++;
|
||||||
|
if (romsize > 0x8000) {
|
||||||
|
fprintf(stderr, "binary too big\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint16_t chksum = 0;
|
||||||
|
for (int i=0; i<romsize-16; i++) {
|
||||||
|
int c = getc(fp);
|
||||||
|
if (c == EOF) c = 0;
|
||||||
|
putchar(c);
|
||||||
|
chksum += c;
|
||||||
|
}
|
||||||
|
// and now, the header
|
||||||
|
printf("TMR SEGA");
|
||||||
|
putchar(0);
|
||||||
|
putchar(0);
|
||||||
|
putchar(chksum & 0xff);
|
||||||
|
putchar(chksum >> 8);
|
||||||
|
putchar(0);
|
||||||
|
putchar(0);
|
||||||
|
putchar(0);
|
||||||
|
putchar(hdsz);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user