Bacon bugfix

This commit is contained in:
ChisBread 2024-11-13 02:39:45 +08:00
parent 4732398e07
commit 4e05ff01f0
3 changed files with 18 additions and 11 deletions

View File

@ -1425,8 +1425,8 @@ class LK_Device(ABC):
return (agb_flash_chip, agb_flash_chip_name)
def ReadROM(self, address, length, skip_init=False, max_length=64):
if self.DEVICE_NAME == "Bacon" and max_length < 0x10000:
max_length = 0x10000
if self.DEVICE_NAME == "Bacon":
max_length = length
num = math.ceil(length / max_length)
dprint("Reading 0x{:X} bytes from cartridge ROM at 0x{:X} in {:d} iteration(s)".format(length, address, num))
if length > max_length: length = max_length
@ -1494,8 +1494,8 @@ class LK_Device(ABC):
return self.ReadROM(address=addr, length=length, max_length=max_length)
def ReadRAM(self, address, length, command=None, max_length=64):
if self.DEVICE_NAME == "Bacon" and max_length < 0x10000:
max_length = 0x10000
if self.DEVICE_NAME == "Bacon":
max_length = length
num = math.ceil(length / max_length)
dprint("Reading 0x{:X} bytes from cartridge RAM in {:d} iteration(s)".format(length, num))
if length > max_length: length = max_length
@ -1582,6 +1582,8 @@ class LK_Device(ABC):
def WriteRAM(self, address, buffer, command=None, max_length=256):
length = len(buffer)
if self.DEVICE_NAME == "Bacon":
max_length = length
num = math.ceil(length / max_length)
dprint("Writing 0x{:X} bytes to cartridge RAM in {:d} iteration(s)".format(length, num))
if length > max_length: length = max_length
@ -1707,6 +1709,8 @@ class LK_Device(ABC):
def WriteROM(self, address, buffer, flash_buffer_size=False, skip_init=False, rumble_stop=False, max_length=MAX_BUFFER_WRITE):
length = len(buffer)
if self.DEVICE_NAME == "Bacon":
max_length = length
num = math.ceil(length / max_length)
dprint("Writing 0x{:X} bytes to Flash ROM in {:d} iteration(s) flash_buffer_size=0x{:X} skip_init={:s}".format(length, num, flash_buffer_size, str(skip_init)))
if length == 0:

View File

@ -255,13 +255,13 @@ def make_ram_read_cycle_command(addr=0, times=1, postfunc=command2bytes) -> byte
]) for i in range(times)])
return postfunc(cmd)
__len_of_write = len(make_v16bit_data_write_command(data=0, postfunc=echo_all))
__len_of_read = len(make_gba_rom_addr_read_command(postfunc=echo_all))
__len_of_v16bit_write = len(make_v16bit_data_write_command(data=0, postfunc=echo_all))
__len_of_v8bit_write = len(make_gba_rom_addr_read_command(postfunc=echo_all))
def extract_ram_read_cycle_data(data: bytes, times=1):
command = bytes2command(data)
ret = []
for i in range(0, len(command), __len_of_write + __len_of_read + 2):
one = command[i + __len_of_write + 1: i + __len_of_write + 1 + __len_of_read + 1]
for i in range(0, len(command), __len_of_v16bit_write + __len_of_v8bit_write + 2):
one = command[i + __len_of_v16bit_write + 1: i + __len_of_v16bit_write + 1 + __len_of_v8bit_write + 1]
ret.append(extract_gba_rom_addr_read_data(command2bytes(one, endclk=False)))
if len(ret) >= times:
break

View File

@ -294,12 +294,15 @@ class BaconFakeSerialDevice:
cmds = []
for i in range(num):
addr = int.from_bytes(cmd[3+i*6:7+i*6], byteorder='big')
#if self.MODE == "AGB" and flashcart:
addr = MappingAddressToReal(addr<<1)
if self.MODE == "AGB" and flashcart:
addr = MappingAddressToReal(addr<<1)
data = int.from_bytes(cmd[7+i*6:9+i*6], byteorder='big')
dprint("[BaconFakeSerialDevice] CART_WRITE_FLASH_CMD:0x%08X Value:%s" % (addr, hex(data)))
cmds.append((addr, data))
self.bacon_dev.AGBWriteROMWithAddress(commands=cmds).Flush()
if self.MODE == "AGB" and flashcart:
self.bacon_dev.AGBWriteROMWithAddress(commands=cmds).Flush()
else:
self.bacon_dev.AGBWriteRAMWithAddress(commands=cmds)
self._push_ack()
elif cmdname == "FLASH_PROGRAM":
self.FLASH_PROGRAMMING = True