-; Serial interface using the ATmega8/88 USART.
+; Serial interface using the ATmega8/88 USART.
; This is part of the Z80-CP/M emulator written by Sprite_tm.
;
; Copyright (C) 2010 Leo C.
#define TXBUFMASK TXBUFSIZE-1
.dseg
-
+
rxcount:
.byte 1
rxidx_w:
txfifo:
.byte TXBUFSIZE
-
+
.cseg
-; Init
+; Init
uart_init:
ldi temp, (1<<TXEN0) | (1<<RXEN0) | (1<<RXCIE0)
; USART receive interrupt
- INTERRUPT URXCaddr
+ INTERRUPT URXCaddr
push temp
in temp,sreg
inm8 temp,RXTXDR0
lds zh,rxcount ;if rxcount < RXBUFSIZE
cpi zh,RXBUFSIZE ; (room for at least 1 char?)
- brsh rxi_ov ;
+ brsh rxi_ov ;
inc zh ;
sts rxcount,zh ; rxcount++
- ldi zl,low(rxfifo) ;
+ ldi zl,low(rxfifo) ;
lds zh,rxidx_w ;
add zl,zh ;
inc zh ;
lds temp,rxcount ; Number of characters in buffer
tst temp
breq uartgetc ;Wait for char
-
+
push zh
push zl
ldi zl,low(rxfifo)
push temp
lds temp,txcount ;if txcount != 0
tst temp ;
- breq txi_e ;
+ breq txi_e ;
dec temp ;
sts txcount,temp ; --txcount
push zh ;
push zl ;
- ldi zl,low(txfifo) ;
+ ldi zl,low(txfifo) ;
ldi zh,high(txfifo) ;
lds temp,txidx_r ;
add zl,temp ;
reti
-;Sends a char from temp to the uart.
+;Sends a char from temp to the uart.
uartputc:
push zh
push zl
cpi temp,TXBUFSIZE ;
brsh putc_l ;} while (txcount >= TXBUFSIZE)
- ldi zl,low(txfifo) ;
+ ldi zl,low(txfifo) ;
ldi zh,high(txfifo) ;
lds temp,txidx_w ;
add zl,temp ;
ret
; vim:set ts=8 noet nowrap
-