-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDARTDriver.asm
More file actions
134 lines (123 loc) · 4.73 KB
/
Copy pathDARTDriver.asm
File metadata and controls
134 lines (123 loc) · 4.73 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
;***************************************************************************
; PROGRAM: DARTDriver
; PURPOSE: Subroutines for a Z80 DART
; ASSEMBLER: Z80asm
; LICENCE: The MIT Licence
; AUTHOR : F.J. Kraan based on UARTDriver from MCook
; CREATE DATE : 2020-12-25
;***************************************************************************
; The addresses of the DART in I/O space.
; Change to suit hardware in CONSTANTS.asm.
; useful patterns
TXBUFEMPTY: EQU 000000100b
RXCHARAVL: EQU 000000001b
; unused
XOFF: EQU 013h
XON: EQU 015h
;***************************************************************************
;UART_INIT
;Function: Initialize the UART to 16x BAUD Rate clock,
; 8 bits, 1 stop bit, no parity, enable Tx and Rx
;***************************************************************************
UART_INIT:
LD HL, DRTTB
LD C, UART_1CTL
LD B, E_DRTTB - DRTTB
OTIR ; write bytes from DRTTB to port DRTCTL
LD HL, DRTTB
LD C, UART_2CTL
LD B, E_DRTTB - DRTTB
OTIR ; write bytes from DRTTB to port DRT2CTL
RET
DRTTB: ; alternate register select and values (not for WR0)
DEFB 00011000b ; DRTWR0 - Register pointer & modes. Channel reset.
DEFB 00000100b ; DRTWR4 - Tx/Rx misc. params & modes
DEFB 01000100b ; X16+STOP1+NOPARITY
; DEFB 00000100b ; X1+STOP1+NOPARITY
DEFB 00000101b ; DRTWR5 - Tx params & controls
DEFB 01101000b ; TX8+TXEN
DEFB 00000011b ; DRTWR3 - Rx params & controls
DEFB 11000001b ; RX8+RXEN
E_DRTTB:
;***************************************************************************
;UART_PRNT_STR:
;Function: Print out string starting at MEM location (HL) to Z80 DART
;***************************************************************************
UART_PRNT_STR:
PUSH AF
UARTPRNTSTRLP:
LD A,(HL)
CP EOS ; Test for end byte
JP Z,UART_END_PRNT_STR ; Jump if end byte is found
CALL UART_TX
INC HL ; Increment pointer to next char
JP UARTPRNTSTRLP ; Transmit loop
UART_END_PRNT_STR:
POP AF
RET
;***************************************************************************
;UART_TX_READY
;Function: Check if UART is ready to transmit
;***************************************************************************
UART_TX_RDY:
WAITTXRDY:
IN A, (UART_1CTL) ;
; LD A,(UART1CTLP)
; LD C, A
; IN A, (C) ;
AND TXBUFEMPTY ; Can we send the next char?
JR Z, WAITTXRDY ; If not, wait
RET
;***************************************************************************
;UART_TX_SEND
;Function: Transmit character in A to DART
;***************************************************************************
TX_SEND:
OUT (UART_1DAT), A ; Out it goes!
; PUSH AF
; LD A,(UART1DATP)
; LD C, A
; POP AF
; OUT (C), A ; Out it goes!
RET
;***************************************************************************
; UART_TX
; Function: Blocking TX routine
;***************************************************************************
UART_TX:
PUSH AF
CALL UART_TX_RDY
POP AF
CALL TX_SEND
RET
;***************************************************************************
;UART_RX_READY
;Function: Check if UART is ready to receive - blocking receive check
;***************************************************************************
UART_RX_RDY:
RX_NOT_RDY:
CALL RX_CHK
JR Z, RX_NOT_RDY ; If rx_ready_bit zero, wait
RET
;***************************************************************************
; DART_RX_CHK
; Function: Non-blocking receive check
;***************************************************************************
RX_CHK:
IN A, (UART_1CTL) ;
; LD A,(UART1CTLP)
; LD C, A
; IN A, (C) ;
AND RXCHARAVL ; Mask other bits, has some char arrived?
RET
;***************************************************************************
;UART_RX
;Function: Receive character in UART to A; wait for char
;***************************************************************************
UART_RX:
CALL UART_RX_RDY ; Make sure UART has received a char
IN A, (UART_1DAT) ; Get it
; LD A,(UART1DATP)
; LD C, A
; IN A, (C) ; Get it
RET