Skip to content

Commit

Permalink
Resolve deprecation warnings in mempak and tpak subsystems
Browse files Browse the repository at this point in the history
  • Loading branch information
meeq committed Sep 6, 2023
1 parent e696f01 commit 6753d90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/mempak.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int read_mempak_sector( int controller, int sector, uint8_t *sector_data )
/* Sectors are 256 bytes, a mempak reads 32 bytes at a time */
for( int i = 0; i < 8; i++ )
{
if( read_mempak_address( controller, (sector * MEMPAK_BLOCK_SIZE) + (i * 32), sector_data + (i * 32) ) )
if( joybus_accessory_read_sync( controller, (sector * MEMPAK_BLOCK_SIZE) + (i * 32), sector_data + (i * 32) ) )
{
/* Failed to read a block */
return -2;
Expand Down Expand Up @@ -105,7 +105,7 @@ int write_mempak_sector( int controller, int sector, uint8_t *sector_data )
/* Sectors are 256 bytes, a mempak writes 32 bytes at a time */
for( int i = 0; i < 8; i++ )
{
if( write_mempak_address( controller, (sector * MEMPAK_BLOCK_SIZE) + (i * 32), sector_data + (i * 32) ) )
if( joybus_accessory_write_sync( controller, (sector * MEMPAK_BLOCK_SIZE) + (i * 32), sector_data + (i * 32) ) )
{
/* Failed to read a block */
return -2;
Expand Down Expand Up @@ -768,7 +768,7 @@ int get_mempak_entry( int controller, int entry, entry_structure_t *entry_data )

/* Entries are spread across two sectors, but we can luckly grab just one
with a single mempak read */
if( read_mempak_address( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry * 32), data ) )
if( joybus_accessory_read_sync( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry * 32), data ) )
{
/* Couldn't read note database */
return -2;
Expand Down Expand Up @@ -1097,7 +1097,7 @@ int write_mempak_entry_data( int controller, entry_structure_t *entry, uint8_t *
{
entry_structure_t tmp_entry;

if( read_mempak_address( controller, (3 * MEMPAK_BLOCK_SIZE) + (i * 32), tmp_data ) )
if( joybus_accessory_read_sync( controller, (3 * MEMPAK_BLOCK_SIZE) + (i * 32), tmp_data ) )
{
/* Couldn't read note database */
return -2;
Expand Down Expand Up @@ -1140,7 +1140,7 @@ int write_mempak_entry_data( int controller, entry_structure_t *entry, uint8_t *
__write_note( entry, tmp_data );

/* Store entry to empty slot on mempak */
if( write_mempak_address( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry->entry_id * 32), tmp_data ) )
if( joybus_accessory_write_sync( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry->entry_id * 32), tmp_data ) )
{
/* Couldn't update note database */
return -2;
Expand Down Expand Up @@ -1177,7 +1177,7 @@ int delete_mempak_entry( int controller, entry_structure_t *entry )
if( entry->inode < BLOCK_VALID_FIRST || entry->inode > BLOCK_VALID_LAST ) { return -1; }

/* Ensure that the entry passed in matches what's on the mempak */
if( read_mempak_address( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry->entry_id * 32), data ) )
if( joybus_accessory_read_sync( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry->entry_id * 32), data ) )
{
/* Couldn't read note database */
return -2;
Expand All @@ -1197,7 +1197,7 @@ int delete_mempak_entry( int controller, entry_structure_t *entry )

/* The entry matches, so blank it */
memset( data, 0, 32 );
if( write_mempak_address( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry->entry_id * 32), data ) )
if( joybus_accessory_write_sync( controller, (3 * MEMPAK_BLOCK_SIZE) + (entry->entry_id * 32), data ) )
{
/* Couldn't update note database */
return -2;
Expand Down
20 changes: 10 additions & 10 deletions src/tpak.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int tpak_set_value(int controller, uint16_t address, uint8_t value)
{
uint8_t block[TPAK_BLOCK_SIZE];
memset(block, value, TPAK_BLOCK_SIZE);
return write_mempak_address(controller, address, block);
return joybus_accessory_write_sync(controller, address, block);
}

/**
Expand All @@ -103,18 +103,18 @@ int tpak_init(int controller)
{
int result = 0;

int accessory = identify_accessory(controller);
if (accessory != ACCESSORY_TRANSFERPAK) return TPAK_ERROR_NO_TPAK;
int accessory = joypad_get_accessory_type(controller);
if (accessory != JOYPAD_ACCESSORY_TYPE_TRANSFER_PAK) { return TPAK_ERROR_NO_TPAK; }

result = tpak_set_power(controller, true);
if (result) return result;
if (result) { return result; }

result = tpak_set_access(controller, true);
if (result) return result;
if (result) { return result; }

uint8_t status = tpak_get_status(controller);
if (status & TPAK_STATUS_REMOVED) return TPAK_ERROR_NO_CARTRIDGE;
if (!(status & TPAK_STATUS_READY)) return TPAK_ERROR_UNKNOWN_BEHAVIOUR;
if (status & TPAK_STATUS_REMOVED) { return TPAK_ERROR_NO_CARTRIDGE; }
if (!(status & TPAK_STATUS_READY)) { return TPAK_ERROR_UNKNOWN_BEHAVIOUR; }

return 0;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ int tpak_set_bank(int controller, int bank)
uint8_t tpak_get_status(int controller)
{
uint8_t block[TPAK_BLOCK_SIZE];
read_mempak_address(controller, TPAK_ADDRESS_STATUS, block);
joybus_accessory_read_sync(controller, TPAK_ADDRESS_STATUS, block);

return block[0];
}
Expand Down Expand Up @@ -245,7 +245,7 @@ int tpak_write(int controller, uint16_t address, uint8_t* data, uint16_t size)
adjusted_address = TPAK_ADDRESS_DATA;
}

write_mempak_address(controller, adjusted_address, cursor);
joybus_accessory_write_sync(controller, adjusted_address, cursor);
address += TPAK_BLOCK_SIZE;
cursor += TPAK_BLOCK_SIZE;
adjusted_address += TPAK_BLOCK_SIZE;
Expand Down Expand Up @@ -295,7 +295,7 @@ int tpak_read(int controller, uint16_t address, uint8_t* buffer, uint16_t size)
adjusted_address = TPAK_ADDRESS_DATA;
}

read_mempak_address(controller, adjusted_address, cursor);
joybus_accessory_read_sync(controller, adjusted_address, cursor);
address += TPAK_BLOCK_SIZE;
cursor += TPAK_BLOCK_SIZE;
adjusted_address += TPAK_BLOCK_SIZE;
Expand Down

0 comments on commit 6753d90

Please sign in to comment.