From: Alan Cox Date: Sun, 15 Feb 2015 22:21:31 +0000 (+0000) Subject: zx128: add a .z80 maker from the image X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7991052b7198689caa09ac46a36cd38c7dadfc24;p=FUZIX.git zx128: add a .z80 maker from the image This is easier to work with as we can set the machine type reliably --- diff --git a/Kernel/cpu-z80/image.mk b/Kernel/cpu-z80/image.mk index 1e50258c..3795cf84 100644 --- a/Kernel/cpu-z80/image.mk +++ b/Kernel/cpu-z80/image.mk @@ -13,6 +13,8 @@ tools/bintomdv: tools/bintomdv.c tools/bin2sna: tools/bin2sna.c +tools/bin2z80: tools/bin2z80.c + tools/bankld/sdldz80: +(cd tools/bankld; make) diff --git a/Kernel/tools/bin2z80.c b/Kernel/tools/bin2z80.c new file mode 100644 index 00000000..cab6076d --- /dev/null +++ b/Kernel/tools/bin2z80.c @@ -0,0 +1,109 @@ +/* + * Convert a banked FUZIX spectrum binary into a .Z80 file for ease + * of testing. + */ + +#include +#include +#include +#include +#include +#include + +static uint8_t emptybank[16384]; +static uint8_t bank0[16384]; +static uint8_t bank1[16384]; +static uint8_t bank2[16384]; +static uint8_t bank5[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_at(uint8_t *p, char *name, int offset) +{ + int fd = open(name, O_RDONLY); + if (fd == -1) { + perror(name); + exit(1); + } + if (lseek(fd, offset, SEEK_SET) != offset) { + perror("lseek"); + exit(1); + } + if (read(fd, p, 16384) < 1) { + perror(name); + exit(1); + } + close(fd); +} + +static void load_bank(uint8_t *p, char *name) +{ + load_bank_at(p, name, 0xC000); +} + +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] = 54; + header[32] = 0x03; /* Run from C003 */ + header[33] = 0xC0; + header[34] = 5; /* 128K with Interface 1 */ + header[37] = 3; /* Emulate LDIR and R details */ + header[61] = 0xFF; /* low memory is ROM */ + header[62] = 0xFF; + write(fd, header, 86); /* Header */ + + writeblock(fd, 0, bank0); + writeblock(fd, 1, bank1); + writeblock(fd, 2, bank5); + writeblock(fd, 3, emptybank); + writeblock(fd, 4, emptybank); + writeblock(fd, 5, bank2); + writeblock(fd, 6, emptybank); + writeblock(fd, 7, bank7); + close(fd); +} + + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + fprintf(stderr, "%s: file.z80\n", argv[0]); + exit(1); + } + load_bank_at(bank5, "common.bin", 0x8000); + load_bank_at(bank2, "common.bin", 0x4000); + load_bank(bank0, "bank1.bin"); + load_bank(bank1, "bank2.bin"); + load_bank(bank7, "bank3.bin"); + write_z80(argv[1]); + exit(0); +}