; 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.
;
; This file is part of avrcpm.
;
; avrcpm is free software: you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; avrcpm is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with avrcpm. If not, see .
;
; $Id$
;
#define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) /* clever rounding */
#define RXBUFMASK RXBUFSIZE-1
#define TXBUFMASK TXBUFSIZE-1
.dseg
rxcount:
.byte 1
rxidx_w:
.byte 1
rxidx_r:
.byte 1
txcount:
.byte 1
txidx_w:
.byte 1
txidx_r:
.byte 1
rxfifo:
.byte RXBUFSIZE
txfifo:
.byte TXBUFSIZE
.cseg
; Init
uart_init:
ldi temp, (1<= TXBUFSIZE)
ldi zl,low(txfifo) ;
ldi zh,high(txfifo) ;
lds temp,txidx_w ;
add zl,temp ;
brcc PC+2 ;
inc zh ;
inc temp ;
andi temp,TXBUFMASK ;
sts txidx_w,temp ; txidx_w = ++txidx_w % TXBUFSIZE
pop temp ;
st z,temp ; txfifo[txidx_w] = char
cli
lds zl,txcount
inc zl
sts txcount,zl
ldi zl, (1<