SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
link_cable.h
1
93#ifndef _LINK_CABLE_H_
94#define _LINK_CABLE_H_
95
96#include "config.h"
97
98#if (MODULE_LINK_CABLE != 0)
99
100#include "types.h"
101
105
106// Input/output direction for SEGA MD console port 2 (set individually for each bit)
107// Determines the data line operation mode (input or output) and controls the interrupt request mask from external devices.
108// Essentially, this is memory address 0xA1000B for data transfer control
109// via SEGA Link Cable (CTRL port register CTRL 2 in SEGA documentation)
110// Bit 7 (INT) - Interrupt on SYN line signal. 0 = disabled; 1 = enabled.
111// Bit 6 (PC6) - Data line "SYN" mode. 0 = input; 1 = output.
112// Bits 0-5 (PC0-PC5) - Data line mode. 0 = input; 1 = output.
113#define LCP_Ctrl (*(vu8*) 0xa1000b)
114
115// State of port 2 on SEGA MD console
116// Essentially, this is memory address 0xA10005 for direct data transfer
117// via SEGA Link Cable (DATA register of CTRL port 2 in SEGA documentation)
118//
119// Lower 4 bits (0-3) are used for data transfer.
120//
121// Bit addressing features between consoles:
122// Bit 5 in the current console corresponds to bit 6 in the other console
123// for the same memory address 0xA10005. If we change bit 5 on our console,
124// bit 6 will change in the other console's LCP_Data variable, and vice versa -
125// if bit 5 is changed on the other console, bit 6 will change on our console.
126//
127// Bits 0-3 at address 0xA10005 will have the same value in both consoles,
128// i.e., if we change these bits on one console, they will also change on the other.
129// Which console is currently responsible for this is determined by the LCP_Ctrl state -
130// i.e., which data line is in output mode (sending data),
131// and which is in input mode (receiving data).
132#define LCP_Data (*(vu8*) 0xa10005)
133
134// Bit 5 is set to 1, others to 0. Primarily used to set bit 5 to 1
135// in LCP_Data and LCP_Ctrl to signal the other console that it can
136// read or send data via Link Cable.
137#define LCP_BIT5 0b00100000
138
139// Bit 6 is set to 1, others to 0. Mainly used to determine
140// whether bit 6 is set in LCP_Data, signaling that
141// data can be read from the other console or sent to the other console via Link Cable.
142#define LCP_BIT6 0b01000000
143
144// Bits 7 and 5 are set to 1, other bits are 0. Used to set these bits in LCP_Ctrl, which indicates
145// readiness for data exchange through console port 2 upon external interrupt EX-INT (External Interrupt
146// in SEGA documentation), i.e., reading data from the port (data reception) in the external interrupt handler LCP_slaveCycle().
147//
148// LCP_Ctrl bit values:
149// - Interrupt on SYN line signal enabled, bit 7 = 1
150// - Data line PC5 in output mode (transmission), bit 5 = 1
151// - Data lines PC6, PC4, PC3, PC2, PC1, PC0 in input mode (reception). Corresponding bits = 0
152//
153// At the "hardware" level for my code this means:
154// - Enable pins 0-3 of controller port 2 for data reception
155// - Pin 5 signals that data has been received by our console (on the other console this will be bit 6 in LCP_Data)
156// - Pin 6 signals that data has been sent by the other console (the other console should change bit 5 in its LCP_Data)
157#define LCP_BIT7_AND_BIT5 0b10100000;
158
159// Bits 5, 3, 2, 1, 0 are set to 1, others are 0. Used to set these bits in LCP_Ctrl, which means
160// starting the data write cycle to port 2 (data transmission) by triggering an external interrupt on the slave console.
161//
162// I.e., on the master console, the LCP_masterCycle() method should be called from the main game code, which will set
163// the bits in LCP_Ctrl to the state specified above, and on the slave console we will previously trigger an external
164// interrupt that will halt the main game code execution and call the LCP_slave() method. This will occur when on the
165// master console the 5th bit in LCP_Data is reset to 0 in the LCP_startSendCycle() method.
166//
167// LCP_Ctrl bit values:
168// - Interrupt on SYN line signal disabled, bit 7 = 0
169// - Data lines PC5, PC3, PC2, PC1, PC0 in output mode (transmission), bits 5, 3, 2, 1, 0 = 1
170// - Data lines PC6, PC4 in input mode (reception). Corresponding bits = 0
171//
172// At the "hardware" level for my code this means:
173// - Enable pins 0-3 of controller port 2 for data transmission
174// - Pin 5 signals that data can be read by the other console (on the other console this will be bit 6 in LCP_Data)
175// - Pin 6 signals that data has been read by the other console (the other console should change bit 5 in its LCP_Data)
176#define LCP_BIT_5_3_2_1_0 0b00101111;
177
178// Mask 00001111. Mainly used to reset the high 4 bits in a byte to 0
179#define LCP_LO_BITS 0b00001111
180
181// Mask 11110000. Mainly used to reset the low 4 bits in a byte to 0
182#define LCP_HI_BITS 0b11110000
183
184// Timeout - used for waiting for data from the other console (waiting for reset or set of bit 6 in LCP_Data)
185#define LCP_TIME_OUT 0x40
186
187// Maximum packet size for data transmission via Link Cable
188#define LCP_PACKET_SIZE 2048
189
190
194
195
202void LCP_open();
203
204
211void LCP_init();
212
213
219void LCP_close();
220
221
244void LCP_objectToPacketForSend(u8 *transferObject, u16 objectType , u16 *objectTypeSizes);
245
246
272u16 LCP_getNextObjectFromReceivePacket(u8 *transferObject, u16 *objectSizes);
273
274
298void LCP_masterCycle();
299
300
312u16 LCP_getError();
313
314#endif // MODULE_LINK_CABLE
315
316#endif // _LINK_CABLE_H
Basic SGDK library configuration file.
Types definition.
unsigned short u16
Definition types.h:100
unsigned char u8
Definition types.h:95