Skip to content

Commit

Permalink
AltairZ80: Adds "rom" option to "load -h"
Browse files Browse the repository at this point in the history
Adds "rom" option to set pages to ROM when loading an Intel
HEX file.
  • Loading branch information
deltecent authored and pkoning2 committed Sep 5, 2024
1 parent 36605c4 commit 2437b13
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions AltairZ80/altairz80_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ uint32 getCommon(void);
uint32 sim_map_resource(uint32 baseaddr, uint32 size, uint32 resource_type,
int32 (*routine)(const int32, const int32, const int32), const char* name, uint8 unmap);

static void PutBYTEasROMorRAM(register uint32 Addr, const register uint32 Value, const register uint32 makeROM);
void PutBYTEExtended(register uint32 Addr, const register uint32 Value);
uint32 GetBYTEExtended(register uint32 Addr);
void cpu_raise_interrupt(uint32 irq);
Expand Down Expand Up @@ -1937,6 +1938,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 @@ -7507,10 +7517,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 @@ -7548,7 +7565,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 @@ -7564,7 +7581,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 2437b13

Please sign in to comment.