Browse Source

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.
master
Virgil Dupras 3 years ago
parent
commit
0d172cc2c4
5 changed files with 61 additions and 7 deletions
  1. +4
    -2
      recipes/sms/Makefile
  2. BIN
      recipes/sms/sega.bin
  3. +1
    -4
      tools/.gitignore
  4. +3
    -1
      tools/Makefile
  5. +53
    -0
      tools/smsrom.c

+ 4
- 2
recipes/sms/Makefile View File

@@ -2,6 +2,7 @@ TARGET = os.bin
BASE = ../../
STAGE = $(BASE)/cvm/stage
BLKPACK = $(BASE)/tools/blkpack
SMSROM = $(BASE)/tools/smsrom
EMUL = $(BASE)/emul/hw/sms/sms

.PHONY: all
@@ -9,6 +10,7 @@ all: $(TARGET)
$(TARGET): xcomp.fs $(STAGE) blkfs
cat xcomp.fs | $(STAGE) blkfs > $@

$(SMSROM):
$(BLKPACK):
$(MAKE) -C ../tools

@@ -18,8 +20,8 @@ blkfs: $(BLKPACK)
$(STAGE):
$(MAKE) -C $(BASE)/cvm stage

os.sms: $(TARGET) $(STAGE)
dd if=$(TARGET) bs=32752 conv=sync | cat - sega.bin > $@
os.sms: $(TARGET) $(STAGE) $(SMSROM)
$(SMSROM) $(TARGET) > $@

$(EMUL):
$(MAKE) -C ${@:%/sms=%}


BIN
recipes/sms/sega.bin View File


+ 1
- 4
tools/.gitignore View File

@@ -1,13 +1,10 @@
/memdump
/blkdump
/upload
/fontcompile
/ttysafe
/pingpong
/slatest
/stripfc
/bin2c
/exec
/blkpack
/blkunpack
/blkup
/smsrom

+ 3
- 1
tools/Makefile View File

@@ -6,9 +6,10 @@ EXEC_TGT = exec
BLKPACK_TGT = blkpack
BLKUNPACK_TGT = blkunpack
BLKUP_TGT = blkup
SMSROM_TGT = smsrom
TARGETS = $(MEMDUMP_TGT) $(UPLOAD_TGT) \
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(EXEC_TGT) $(BLKPACK_TGT) \
$(BLKUNPACK_TGT) $(BLKUP_TGT)
$(BLKUNPACK_TGT) $(BLKUP_TGT) $(SMSROM_TGT)
OBJS = common.o

all: $(TARGETS)
@@ -25,6 +26,7 @@ $(EXEC_TGT): $(EXEC_TGT).c
$(BLKPACK_TGT): $(BLKPACK_TGT).c
$(BLKUNPACK_TGT): $(BLKUNPACK_TGT).c
$(BLKUP_TGT): $(BLKUP_TGT).c
$(SMSROM_TGT): $(SMSROM_TGT).c
$(TARGETS): $(OBJS)
$(CC) $(CFLAGS) $@.c $(OBJS) -o $@



+ 53
- 0
tools/smsrom.c View 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…
Cancel
Save