SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
serial.h
1
/************************************************************************
2
* \brief Simple Serial Driver to comunicate by game port.
3
*
4
* \author Juan Antonio Ruiz (PaCHoN)
5
* \date 2024-2025
6
* \defgroup MW Serial
7
* \brief
8
* ## Hardware
9
*
10
* ### Controller Port Pinout
11
*
12
* | Pin | Parallel Mode \* | Serial Mode | I/O Reg Bit |
13
* | --- | ------------------- | ----------- | ----------- |
14
* | 1 | Up | | UP (D0) |
15
* | 2 | Down | | DOWN (D1) |
16
* | 3 | Gnd / Left | | LEFT (D2) |
17
* | 4 | Gnd / Right | | RIGHT (D3) |
18
* | 5 | +5VDC | +5VDC |
19
* | 6 | Button A / Button B | Tx | TL (D4) |
20
* | 7 | Select | |
21
* | 8 | Gnd | Gnd |
22
* | 9 | Start / Button C | Rx | TR (D5) |
23
*
24
* \* Pins in parallel mode can have two interpretations, depending on if `Select` has been set low or high (L / H) from the console.
25
*
26
* ### Controller Plug
27
*
28
* Looking directly at plug (Female 9-pin Type D)
29
*
30
* ```
31
* -------------
32
* \ 5 4 3 2 1 /
33
* \ 9 8 7 6 /
34
* ---------
35
* ```
36
*
37
* ### FTDI USB TTL Serial Cable
38
*
39
* From the [datasheet](https://www.ftdichip.com/Support/Documents/DataSheets/Cables/DS_TTL-232RG_CABLES.pdf):
40
*
41
* | Colour | Name | Type | Description |
42
* | ------ | ---- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
43
* | Black | GND | GND | Device ground supply pin. |
44
* | Brown | CTS# | Input | Clear to Send Control input / Handshake signal. |
45
* | Red | VCC | Output or input | Power Supply Output except for the TTL-232RG-VIPWE were this is an input and power is supplied by the application interface logic. |
46
* | Orange | TXD | Output | Transmit Asynchronous Data output. |
47
* | Yellow | RXD | Input | Receive Asynchronous Data input. |
48
* | Green | RTS# | Output | Request To Send Control Output / Handshake signal. |
49
*
50
* ### Mappings
51
*
52
* | FTDI Cable | Mega Drive Port Pin |
53
* | ------------ | ------------------- |
54
* | Red (VCC) | 5 (5v) |
55
* | Orange (TXD) | 9 (Rx) |
56
* | Yellow (RXD) | 6 (Tx) |
57
* | Black (GND) | 8 (Gnd) |
58
* *************************************** */
59
#ifndef _SERIAL_H_
60
#define _SERIAL_H_
61
62
#include "genesis.h"
63
#include "
types.h
"
64
65
#define PORT2_CTRL 0xA1000B
66
#define PORT2_SCTRL 0xA10019
67
#define PORT2_TX 0xA10015
68
#define PORT2_RX 0xA10017
69
70
#define EXT_CTRL 0xA1000D
71
#define EXT_SCTRL 0xA1001F
72
#define EXT_TX 0xA1001B
73
#define EXT_RX 0xA1001D
74
75
#define SCTRL_SIN 0x20
76
#define SCTRL_SOUT 0x10
77
#define SCTRL_300_BPS 0xC0
78
#define SCTRL_1200_BPS 0x80
79
#define SCTRL_2400_BPS 0x40
80
#define SCTRL_4800_BPS 0x00
81
82
#define SCTRL_TFUL 0x1
83
#define SCTRL_RRDY 0x2
84
#define SCTRL_RERR 0x4
85
#define SCTRL_RINT 0x8
86
87
#define CTRL_PCS_OUT 0x7F
88
89
#define VDP_MODE_REG_3 0xB
90
#define VDP_IE2 0x08
91
#define INT_MASK_LEVEL_ENABLE_ALL 1
92
93
#define SERIAL_BUFLEN 1
94
#define SERIAL_TXFIFO_LEN 1
95
96
typedef
enum
IoPort {
97
IoPort_Ext,
98
IoPort_Ctrl2
99
} IoPort;
100
101
bool
serial_is_present(
void
);
102
void
serial_write(
u8
data);
103
bool
serial_read_ready(
void
);
104
bool
serial_write_ready(
void
);
105
u8
serial_read(
void
);
106
void
serial_init(
void
);
107
108
void
serial_reset_fifos(
void
);
109
u16
serial_baud_rate(
void
);
110
u8
serial_get_sctrl(
void
);
111
void
serial_set_sctrl(
u8
value);
112
113
#endif
/*_SERIAL_H_*/
types.h
Types definition.
u16
unsigned short u16
Definition
types.h:100
u8
unsigned char u8
Definition
types.h:95
SGDK
inc
ext
serial
serial.h
Generated by
1.16.1