Closed lgblgblgb closed 2 years ago
Current code in Xemu (now for reading, writing is similar) for buffer access:
DEFINE_READER(disk_buffers_reader) {
#if 1
return disk_buffers[GET_READER_OFFSET()];
#else
if (in_hypervisor)
return disk_buffers[GET_READER_OFFSET()];
else
return disk_buffers[(GET_WRITER_OFFSET() & 0x1FF) + ((sd_reg9 & 0x80) ? SD_BUFFER_POS : FD_BUFFER_POS)];
#endif
}
As it can be seen, about the right behaviour (according to MEGA65 doc) is implemented, however not that version is used currently!
For the I/O mapping:
if (vic_registers[0x30] & 1)
return colour_ram[addr - 0x3800];
if (XEMU_LIKELY(sd_status & SD_ST_MAPPED))
return sd_buffer[addr - 0x3E00];
return 0xFF; // I/O exp is not supported
So, it's fixed that SD buffer can be mapped only into the I/O space.
I did the modification in Xemu, however disk buffer mapping into the I/O space (from $DE00, 512 bytes, when enabled with sd-ctrl command $81) is unclear how it supposed to work. Till now, Xemu always mapped the SD buffer only regardless of hypervisor mode or not or SD-ctrl reg 9 bit 7 status. It worked fine with hyppo, but surely, it makes impossible to write a program which intended to I/O map the FD disk buffer instead of the SD ... Note, Bit Shifter also had problems with this, on the hardware as well, though maybe not the very same kind of issue.
Now, with my Xemu modification to take in account bit 7 of SD-ctrl reg 9 (as it supposed to be?), breaks hyppo, if user space alters that reg 9, as it causes that hyppo happily think that the I/O mapped disk buffer still means SD, even if it's already FD, and just trying to do HDOS service SD communication with using the FD buffer actually ... So I'm not sure what's going on, how it supposed to work. Some possibilities:
Solutions as workarounds:
The safer method is the second, since this what Xemu did in the past, without too much noticed problem, even if it's not correct. Though this should be checked, and as I've written already, this is maybe buggy on MEGA65 itself, too (see the MEGA65 issue, mentioned).
Make MEGA65's FDC emulation more correct for memory mapping point of view:
Xemu/MEGA65 status
Plan
Do what it "should do" later maybe adjust to MEGA65 depending if it's really buggy here, how it is fixed, etc ...