Unfortunately when I went to another Linux system which, significantly, has 64 bit addresses, the emulation broke completely.
It looks like the code uses its 'genaddr' array to pun on ns32016 addresses (which are really just indexes into the memory array that represents the 32016 memory) and the addresses of actual variables in the local program, such as the local copy of the 32016 registers.
Unfortunately this falls apart when the local addresses have to be 64 bit.
Looking around I see some other versions of this emulator which have separate genaddr and genreg arrays rather than using genaddr for both purposes. Is this a fix for the problem I'm seeing?
Any advice on which of these 32016 emulators is the best one to build on?:
in the 'no genreg' camp:
Code: Select all
https://github.com/hoglet67/PiTubeClient/blob/master/NS32016/32016.c <---
// B-em v2.2 by Tom Walker
// 32016 parasite processor emulation (not working yet)
// And Simon R. Ellwood
https://github.com/hoglet67/PiTubeDirect/blob/cobra-dev/src/NS32016/32016.c
// B-em v2.2 by Tom Walker
// 32016 parasite processor emulation (not working yet)
// And Simon R. Ellwood
https://github.com/neozeed/emul32k/blob/main/32016.c
// B-em v2.2 by Tom Walker
// 32016 parasite processor emulation (not working yet)
// And Simon R. Ellwood
and:
http://cpu-ns32k.net/files/emul32k.zip (from http://cpu-ns32k.net/Emulator.html from
https://virtuallyfun.com/wordpress/2017/09/09/definicon-dsi-32-co-processor-emulation/ )
https://github.com/fesh0r/b-em/blob/master/src/32016.c
/*B-em v2.2 by Tom Walker
32016 parasite processor emulation (not working yet)*/
http://b-em.bbcmicro.com/B-emv2.2Linux.tar.gz
/*B-em v2.2 by Tom Walker
32016 parasite processor emulation (not working yet)*/
Code: Select all
https://github.com/hoglet67/PiTubeDirect/blob/master/src/NS32016/32016.c
// B-em v2.2 by Tom Walker
// 32016 parasite processor emulation (not working yet)
// And Simon R. Ellwood
https://github.com/kilograham/b-em/blob/pico/src/NS32016/32016.c
// B-em v2.2 by Tom Walker
// 32016 parasite processor emulation (not working yet)
// And Simon R. Ellwood
https://github.com/stardot/b-em/blob/master/src/NS32016/32016.c
// B-em v2.2 by Tom Walker
// 32016 parasite processor emulation (not working yet)
// And Simon R. Ellwood
Thanks,
Graham
PS Below are what I believe to be the problem areas in the copy I'm working from. I've marked the lines that gcc complained about when trying to compile on the 64 bit host.
Code: Select all
uint32_t reg_addr = genaddr[1] + ((Regs[1].Whole & 1) ? -4 : 4);
*(uint8_t *)(reg_addr) = temp; /* int-to-pointer-cast */
*(uint16_t *)(reg_addr) = temp; /* int-to-pointer-cast */
*(uint32_t *)(reg_addr) = temp; /* int-to-pointer-cast */
uint32_t genaddr[2];
return read_x8(genaddr[c]);
return read_x16(genaddr[c]);
return read_x32(genaddr[c]);
Temp = *(uint32_t *)genaddr[c]; /* int-to-pointer-cast */
return Truncate(genaddr[c], OpSize.Op[c]);
Temp = read_x64(genaddr[c]);
Temp = *(uint64_t *)genaddr[c];
return *(uint32_t *)genaddr[c];
return genaddr[c];
genaddr[c] = (uint32_t)&r[gen.OpType]; /* int-to-pointer-cast */
genaddr[c] = (uint32_t)&FR.fr32[IndexLKUP[gen.OpType]]; /* int-to-pointer-cast */
genaddr[c] = (uint32_t)&FR.fr64[gen.OpType]; /* int-to-pointer-cast */
genaddr[c] = temp3.u8;
genaddr[c] = temp3.u16;
genaddr[c] = temp3.u32;
genaddr[c] = r[gen.Whole & 7] + GetDisplacement(&pc);
genaddr[c] += Offset;
genaddr[c] = *((uint32_t *)genaddr[c]) + Offset; /* int-to-pointer-cast */
genaddr[c] = read_x32(fp + temp);
genaddr[c] += temp2;
genaddr[c] = read_x32(GET_SP() + temp);
genaddr[c] += temp2;
genaddr[c] = read_x32(sb + temp);
genaddr[c] += temp2;
genaddr[c] = GetDisplacement(&pc);
genaddr[c] = temp2 + GetDisplacement(&pc);
genaddr[c] = GET_SP();
genaddr[c] = GetDisplacement(&pc) + fp;
genaddr[c] = GetDisplacement(&pc) + GET_SP();
genaddr[c] = GetDisplacement(&pc) + sb;
genaddr[c] = GetDisplacement(&pc) + startpc;
uint32_t reg_addr = genaddr[1] + ((Regs[1].Whole & 1) ? -4 : 4);
write_x8(genaddr[1] + 4, temp);
write_x16(genaddr[1] + 4, temp);
write_x32(genaddr[1] + 4, temp);
genaddr[1] += OffsetDiv8(Offset);
genaddr[0] += OffsetDiv8(Offset);
genaddr[1] += OffsetDiv8(Offset);
genaddr[1] += OffsetDiv8(Offset);
write_x8(genaddr[WriteIndex], temp);
write_x16(genaddr[WriteIndex], temp);
write_x32(genaddr[WriteIndex], temp);
write_x64(genaddr[WriteIndex], temp64.u64);
*((uint8_t *)genaddr[WriteIndex]) = temp; /* int-to-pointer-cast */
*((uint16_t *)genaddr[WriteIndex]) = temp; /* int-to-pointer-cast */
*((uint32_t *)genaddr[WriteIndex]) = temp; /* int-to-pointer-cast */
*((uint64_t *)genaddr[WriteIndex]) = temp64.u64; /* int-to-pointer-cast */