-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart.sif
54 lines (50 loc) · 1.29 KB
/
uart.sif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
.org $;
UART_Init: LDYI UART_CONTROL;
LDAI 3; // reset
STA, M[Y];
LDAI 0x10; // all int off, 8N2, baudrate / 1
STA, M[Y];
RTS;
// Wait until character is received
UART_GetChr:PUSHF;
TRACEOFF;
PUSHY;
LDYI UART_STATUS;
RdStatus0: JSR GetStatus;
ANDI 0x0001; // check if RDRF (bit 0, receiver data register full) is 1
IF_A_EQ_THEN RdStatus0;
GetChr: INY; // point to UART data register
LDA, M[Y];
NoChar: ANDI 0x00FF;// UART is connected to LSB
POPY;
RTF; // restore TRACE flag
// Don't wait for character, return 0x00 if none received
UART_ChkChr:PUSHF;
TRACEOFF;
PUSHY;
LDYI UART_STATUS;
JSR GetStatus;
ANDI 0x0001; // check if RDRF (bit 0, receiver data register full) is 1
IF_A_EQ_THEN NoChar;
JR GetChr;
// Output character
UART_Beep: LDAI BEL;
UART_OutChr:PUSHY;
PUSHA;
LDYI UART_STATUS;
RdStatus1: JSR GetStatus;
ANDI 0x0002; // check if TDRE (bit 1, transmit register empty) is 1
IF_A_EQ_THEN RdStatus1;
OutChr: INY, POPA; // Y points to UART data register, get the char back
STA, M[Y];
POPY;
RTS;
GetStatus: LDA, M[Y]; // read status register
PUSHA; // save
LDA, M[Y]; // read again
XOR, M[S]; // compare to see if settled
IF_A_EQ_THEN StIsStable;
POPA;
JR GetStatus;
StIsStable: POPA;
RTS;