From: Alan Cox Date: Tue, 15 Aug 2017 21:21:26 +0000 (+0100) Subject: Z80: add a flat binary to Z80 snapshot maker X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=ec8887855fc69f703aec6290e0aec6cc0688c2f1;p=FUZIX.git Z80: add a flat binary to Z80 snapshot maker Yes one day we'll need a boot loader but for emulator debug work it's so much easier to work on snapshots --- diff --git a/Kernel/cpu-z80/image.mk b/Kernel/cpu-z80/image.mk index 58a6eefe..73cdd732 100644 --- a/Kernel/cpu-z80/image.mk +++ b/Kernel/cpu-z80/image.mk @@ -15,6 +15,8 @@ tools/bin2sna: tools/bin2sna.c tools/bin2z80: tools/bin2z80.c +tools/flat2z80: tools/flat2z80.c + tools/bankld/sdldz80: +(cd tools/bankld; make) @@ -26,7 +28,7 @@ tools/makejv3: tools/makejv3.c fuzix.ihx: target $(OBJS) platform-$(TARGET)/fuzix.lnk tools/bankld/sdldz80 $(CROSS_LD) -n -k $(LIBZ80) -f platform-$(TARGET)/fuzix.lnk -fuzix.bin: fuzix.ihx tools/bihx tools/analysemap tools/memhogs tools/binman tools/bintomdv tools/binmunge tools/bin2sna tools/bin2z80 cpm-loader/cpmload.bin +fuzix.bin: fuzix.ihx tools/bihx tools/analysemap tools/memhogs tools/binman tools/bintomdv tools/binmunge tools/bin2sna tools/bin2z80 cpm-loader/cpmload.bin tools/flat2z80 -cp hogs.txt hogs.txt.old tools/memhogs hogs.txt head -5 hogs.txt diff --git a/Kernel/tools/flat2z80.c b/Kernel/tools/flat2z80.c new file mode 100644 index 00000000..359f8700 --- /dev/null +++ b/Kernel/tools/flat2z80.c @@ -0,0 +1,109 @@ +/* + * Convert an unbanked binary into a ZX spectrum +3 image for ease + * of testing. + */ + +#include +#include +#include +#include +#include +#include + +static uint8_t emptybank[16384]; +static uint8_t bank3[16384]; +static uint8_t bank4[16384]; +static uint8_t bank6[16384]; +static uint8_t bank7[16384]; + +static uint8_t header[86]; +static uint8_t blkhdr[3] = { 0xFF, 0xFF, 0x00 }; + +static void write_buf(char *name, int fd, uint8_t *buf, int len) +{ + if (write(fd, buf, len) != len) { + perror(name); + exit(1); + } +} + +static void load_bank(uint8_t *p, int fd) +{ + if (read(fd, p, 16384) < 1) { + perror("read"); + exit(1); + } +} + +static void load_first_bank(uint8_t *p, int fd) +{ + if (read(fd, p + 256, 16384 - 256) < 1) { + perror("read"); + exit(1); + } +} + +static void writeblock(int fd, int block, uint8_t *ptr) +{ + blkhdr[2] = 3 + block; + write(fd, blkhdr, 3); + write(fd, ptr, 16384); + printf("Bank %d signature %x %x %x\n", + block, ptr[0],ptr[1],ptr[2]); + +} + +static void write_z80(char *name) +{ + int fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644); + if (fd == -1) { + perror(name); + exit(1); + } + header[8] = 0xF0; /* set SP somewhere */ + header[9] = 0xFF; + + header[29] = 0x40 | 1; /* IM1, Kempston joystick */ + header[30] = 55; + header[32] = 0x00; /* Run from 0x0100 */ + header[33] = 0x01; + header[34] = 7; /* Spectrum +3 */ + header[35] = 0; /* Screen at bank 5 */ + header[37] = 3; /* Emulate LDIR and R details */ + header[61] = 0x00; /* low memory is RAM */ + header[62] = 0x00; + header[86] = 0x07; /* Map 4/7/6/3 */ + write(fd, header, 87); /* Header */ + + writeblock(fd, 0, emptybank); + writeblock(fd, 1, emptybank); + writeblock(fd, 2, emptybank); + writeblock(fd, 3, bank3); + writeblock(fd, 4, bank4); + writeblock(fd, 5, emptybank); + writeblock(fd, 6, bank6); + writeblock(fd, 7, bank7); + close(fd); +} + + +int main(int argc, char *argv[]) +{ + int fd; + if (argc != 3) { + fprintf(stderr, "%s: input.bin output.z80\n", argv[0]); + exit(1); + } + fd = open(argv[1], O_RDONLY); + if (fd == -1) { + perror(argv[1]); + exit(1); + } + load_first_bank(bank4, fd); + load_bank(bank7, fd); + load_bank(bank6, fd); + load_bank(bank3, fd); + close(fd); + write_z80(argv[2]); + exit(0); +}