Skip to content

Commit

Permalink
AltairZ80: Adds "ROM" option to "load -h"
Browse files Browse the repository at this point in the history
HEX file loader "load -h <filename> ROM" will mark the pages as ROM.
  • Loading branch information
deltecent committed Sep 4, 2024
1 parent 8ed26d3 commit 12d4dfb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions AltairZ80/altairz80_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,15 @@ static void PutBYTE(register uint32 Addr, const register uint32 Value) {
}
}

static void PutBYTEasROMorRAM(register uint32 Addr, const register uint32 Value, const register uint32 makeROM) {
Addr &= ADDRMASK; /* registers are NOT guaranteed to be always 16-bit values */
if ((cpu_unit.flags & UNIT_CPU_BANKED) && (((common_low == 0) && (Addr < common)) || ((common_low == 1) && (Addr >= common))))
Addr |= bankSelect << MAXBANKSIZELOG2;

mmu_table[Addr >> LOG2PAGESIZE] = makeROM ? ROM_PAGE : RAM_PAGE;
M[Addr] = Value;
}

void PutBYTEExtended(register uint32 Addr, const register uint32 Value) {
MDEV m;

Expand Down Expand Up @@ -7380,10 +7389,17 @@ t_stat sim_load(FILE *fileref, CONST char *cptr, CONST char *fnam, int flag) {
https://deramp.com/downloads/misc_software/hex-binary utilities for the PC/
*/
static t_stat cpu_hex_load(FILE *fileref, CONST char *cptr, CONST char *fnam, int flag) {
char gbuf[CBUFSIZE];
char linebuf[1024], datastr[1024], *bufptr;
int32 bytecnt, rectype, databyte, chksum, line = 0, cnt = 0;
uint32 makeROM = FALSE;
t_addr addr, org = 0;

get_glyph(cptr, gbuf, 0);
if (strcmp(gbuf, "ROM") == 0) {
makeROM = TRUE;
}

while (!feof(fileref)) {
if (fgets(linebuf, sizeof(linebuf), fileref) == NULL)
break;
Expand Down Expand Up @@ -7421,7 +7437,7 @@ static t_stat cpu_hex_load(FILE *fileref, CONST char *cptr, CONST char *fnam, in
}
bufptr += 2;

PutBYTE(addr++, databyte);
PutBYTEasROMorRAM(addr++, databyte, makeROM);

chksum += databyte;
cnt++;
Expand All @@ -7437,7 +7453,7 @@ static t_stat cpu_hex_load(FILE *fileref, CONST char *cptr, CONST char *fnam, in
}
}

return sim_messagef(SCPE_OK, "%d byte%s loaded at %x.\n", PLURAL(cnt), org);
return sim_messagef(SCPE_OK, "%d byte%s loaded at %x%s.\n", PLURAL(cnt), org, (makeROM) ? " [ROM]" : "");
}

void cpu_raise_interrupt(uint32 irq) {
Expand Down

0 comments on commit 12d4dfb

Please sign in to comment.