Switch example to UGBA interrupt handler
Animate dots in example
Update readme
This is a C port of gba-link-connection by rodri042, a library which makes it easy to add multiplayer support to Game Boy Advance homebrew games.
Notes:
malloc
when creating the connection with lc_init
, to allocate internal buffers.A Link Cable connection for Multi-player mode.
Usage:
1) Include this header in your main.c file, then declare and initialise a connection.
#include "link_connection.h"
LinkConnection conn;
// ...
LinkConnectionSettings settings = {
.baud_rate = BAUD_RATE_1,
.timeout = 3,
.remote_timeout = 5,
.buffer_len = 30,
.interval = 50,
.send_timer_id = 3,
};
conn = lc_init(settings);
// Alternatively you can pass in memory for 5 buffers manually:
//
// EWRAM_DATA u16 buffers[LINK_TOTAL_BUFFERS * 30];
// ...
// conn = lc_init_manual(settings, buffers);
2) Add the required interrupt service routines:
void onVBlank() {
lc_on_vblank(&conn);
}
void onSerial() {
lc_on_serial(&conn);
}
void onTimer() {
lc_on_timer(&conn);
}
// ...
irq_init(NULL);
irq_add(II_VBLANK, onVBlank);
irq_add(II_SERIAL, onSerial);
irq_add(II_TIMER3, onTimer);
Note: the above snippet uses Tonc's IRQ functions, but it's recommended to use UGBA's for improved reliability.
Check the example
directory in this repo to see how to do that.
3) Start the library with:
lc_activate(&conn);
4) Send/read messages by using:
lc_send(&conn, data)
lc_is_connected(&conn)
lc_has_message(&conn, player_id)
lc_read_message(&conn, player_id)
Restrictions on sent data: 0xFFFF
and 0x0000
are reserved values, so don't use them (they mean 'disconnected' and 'no data' respectively).
5) If you used lc_init
, be sure to free the internal buffers:
lc_destroy(&conn);