Replace mungerom.c with a python script

This commit is contained in:
Matt Harlum 2024-10-30 06:31:39 +00:00
parent 6f4beaa6ce
commit 83d15869b5
6 changed files with 39 additions and 41 deletions

3
bootrom/.gitignore vendored
View File

@ -5,4 +5,5 @@ at
**/*.out
**/*.device
**/*.hunk
**/*.adf
**/*.adf
*.pyc

View File

@ -14,10 +14,6 @@ OBJS = $(SRCS:%.S=$(OBJDIR)/%.o)
all: ../$(PROJECT).rom ../$(PROJECT)-atbus.rom ../$(PROJECT)-word.rom
$(OBJDIR)/mungerom: mungerom.c
@mkdir -p $(OBJDIR)
$(CC) $< -Wall -o $@
# Nibble-wide boot loader with Byte-wide driver
$(OBJDIR)/%.o: %.S
@mkdir -p $(OBJDIR)
@ -34,9 +30,9 @@ $(OBJDIR)/bootldr: $(OBJDIR)/bootldr.o
$(OBJDIR)/bootldr-word: $(OBJDIR)/bootldr-word.o
$(LINKER) $(LINKFLAGS) -o $@ $^
$(OBJDIR)/bootnibbles: $(OBJDIR)/bootldr $(OBJDIR)/mungerom
$(OBJDIR)/bootnibbles: $(OBJDIR)/bootldr mungerom.py
@mkdir -p $(OBJDIR)
./obj/mungerom
./mungerom.py
$(OBJDIR)/assets.o: assets.S $(OBJDIR)/bootnibbles ../lide.device

View File

@ -2,8 +2,12 @@ SECTIONS {
rom = .;
.bootldr 0x00: {
*(BOOTLDR);
RESERVE(0x1000-.);
RESERVE(0x800-.);
} = 0xFFFF
.reserved 0x800: {
FILL8(0xFF);
RESERVE(0x1000-.);
}
.device 0x1000 : {
*(DEVICE)
}

View File

@ -1,33 +0,0 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
// Chop up the bootrom section into nibbles for Z2 nibblewise bootrom - Kick 1.3 and below don't support DAC_BYTEWIDE :(
// The device driver will be loaded bytewise by reloc
int main () {
FILE *fh = fopen("obj/bootldr","r");
char *src,*dst = NULL;
src = malloc(2048);
dst = malloc(4096);
int len = fread(src,1,2048,fh);
fclose(fh);
for (int i=0; i<len;i++) {
char hi = *(src+i) & 0xF0;
char lo = *(src+i) & 0x0F;
lo <<= 4;
dst[i<<1] = hi;
dst[(i<<1)+1] = lo;
}
fh = fopen("obj/bootnibbles","w");
fwrite(dst,1,len*2,fh);
fclose(fh);
free(src);
free(dst);
}

26
bootrom/mungerom.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import os
import sys
# Chop up the bootrom section into nibbles for Z2 nibblewise bootrom - Kick 1.3 and below don't support DAC_BYTEWIDE :(
# The device driver itself will be loaded bytewise by reloc
c_bright_red = "\033[1;31m"
c_reset = "\033[0m"
# On the AT-Bus the ROM is not selected between $1000-$1FFF
# So we need to fit the boot rom under this limit
size_limit = 1024
with open("obj/bootldr", "rb") as s:
romSize = os.fstat(s.fileno()).st_size
if romSize > size_limit:
print(f"{c_bright_red}bootldr too large, Size: {romSize} Limit: {size_limit}{c_reset}")
sys.exit(1)
rom = s.read()
with open("obj/bootnibbles","wb") as d:
for b in rom:
d.write(bytes([(b & 0xF0) | 0x0F]))
d.write(bytes([((b << 4) & 0xF0) | 0x0F]))

View File

@ -5,6 +5,10 @@ SECTIONS {
} = 0xFFFF
.bootldr 0x04: {
*(BOOTLDR);
RESERVE(0x800-.);
}
.reserved 0x800: {
FILL8(0xFF);
RESERVE(0x1000-.);
}
.device 0x1000 : {