Skip to content

Commit

Permalink
Enable Z80 to work with both hard disc BIOS and MOS 3.50
Browse files Browse the repository at this point in the history
This changes the default tube ROM for the Z80 processor to 1.21 which
doesn't defend against incoming ROMs and then bodges the CMOS RAM
emulation to fake the selected language ROM into one that doesn't crash
the Z80.

The same changes should also work on the PDP11 tube.
  • Loading branch information
Steve Fosdick committed Oct 12, 2023
1 parent 8d62a25 commit f0241d6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
44 changes: 43 additions & 1 deletion src/cmos.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <errno.h>
#include <stdio.h>
#include "b-em.h"
#include "6502.h"
#include "mem.h"
#include "via.h"
#include "sysvia.h"
Expand Down Expand Up @@ -113,13 +114,54 @@ static uint8_t read_cmos_rtc(unsigned addr)
}
}

static uint8_t cmos_fix_tube_lang(uint8_t value, unsigned code_type)
{
unsigned lang = value >> 4;
unsigned cmos_rtype = readmem(0x2a1+lang);
if ((cmos_rtype & 0x0f) != code_type) {
/* The CMOS-defined language is the wrong CPU type for the
* tube processor so see if there is a ROM that has the
* correct CPU type.
*/
for (int r = 15; r >= 0; --r) {
unsigned this_rtype = readmem(0x2a1+r);
if ((this_rtype & 0x0f) == code_type) {
log_info("cmos: overriding configured language with tube present to %u as suitable for tube CPU", r);
return (value & 0x0f) | (r << 4);
}
}
/* There is no suitable language ROM for the tube processor
* so we have to select an unsuitable one because the tube
* host code is too stupid to handle the case of there being
* nothing to send. Make sure what we do pick is not
* something that relocates high.
*/
if (cmos_rtype & 0x20) {
for (int r = 15; r >= 0; --r) {
unsigned this_rtype = readmem(0x2a1+r);
if ((this_rtype & 0x60) == 0x40) {
log_info("cmos: overriding configured language with tube present to %u as non-relocating", r);
return (value & 0x0f) | (r << 4);
}
}
}
}
return value;
}

static uint8_t get_cmos(unsigned addr)
{
if ((addr <= 6 && !(addr & 1)) || (addr >= 7 && addr <= 9))
return read_cmos_rtc(addr);
else {
uint8_t value = cmos[addr];
if (addr == 0x1e && autoboot)
if (addr == 0x13) {
if (curtube == 2)
value = cmos_fix_tube_lang(value, 8);
else if (curtube == 9)
value = cmos_fix_tube_lang(value, 7);
}
else if (addr == 0x1e && autoboot)
value |= 0x10;
return value;
}
Expand Down
6 changes: 3 additions & 3 deletions src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TUBE tubes[NUM_TUBES]=
{
{"6502 Internal", tube_6502_init, tube_6502_reset, &tube6502_cpu_debug, 0x0800, "6502Intern", 4 },
{"ARM", arm_init, arm_reset, &tubearm_cpu_debug, 0x4000, "ARMeval_100", 4 },
{"Z80", z80_init, z80_reset, &tubez80_cpu_debug, 0x1000, "Z80_122", 6 },
{"Z80", z80_init, z80_reset, &tubez80_cpu_debug, 0x1000, "Z80_121", 6 },
{"80186", x86_init, x86_reset, &tubex86_cpu_debug, 0x4000, "BIOS", 8 },
{"65816", w65816_init_recoco, w65816_reset, &tube65816_cpu_debug, 0x8000, "ReCo6502ROM_816", 16 },
{"32016", tube_32016_init, n32016_reset, &n32016_cpu_debug, 0x0000, "", 8 },
Expand All @@ -76,8 +76,8 @@ TUBE tubes[NUM_TUBES]=
#ifdef M68K
{"68000", tube_68000_init, tube_68000_rst, &mc68000_cpu_debug, 0x8000, "CiscOS", 4 },
#endif
{"65816Dossy", w65816_init_dossy, w65816_reset, &tube65816_cpu_debug, 0x8000, "Dossy_816", 16 },
{"Sprow ARM", sprow_init, sprow_reset, &tubesprow_cpu_debug, 0x80000, "Sprow_ARM", 4 },
{"65816Dossy", w65816_init_dossy, w65816_reset, &tube65816_cpu_debug, 0x8000, "Dossy_816", 16 },
{"Sprow ARM", sprow_init, sprow_reset, &tubesprow_cpu_debug, 0x80000, "Sprow_ARM", 4 }
};

static fdc_type_t model_find_fdc(const char *name, const char *model)
Expand Down

0 comments on commit f0241d6

Please sign in to comment.