;
;    Mecrisp - A native code Forth implementation for MSP430 microcontrollers
;    Copyright (C) 2011  Matthias Koch
;
;    This program 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.
;
;    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
;

; Terminalroutinen für die serielle Schnittstelle, identisch beim 2553 und 2274

terminal_qkey_schnippsel macro
;------------------------------------------------------------------------------
; ( -- Flag ) Prüft, ob eine Taste gedrückt wurde
;------------------------------------------------------------------------------
  pushda #0
  bit.b #UCA0RXIFG, &IFG2
  jz +
  mov #-1, @r4
+ ret
  endm

terminal_key_schnippsel macro
;------------------------------------------------------------------------------
; ( -- c ) Holt den Tastendruck
;------------------------------------------------------------------------------
- bit.b #UCA0RXIFG, &IFG2
  jz -

  decd r4
  clr @r4
  mov.b &UCA0RXBUF, @r4
  ret
  endm

terminal_emit_schnippsel macro
;------------------------------------------------------------------------------
; ( c -- ) Gibt ein Zeichen aus
;------------------------------------------------------------------------------
- bit.b #UCA0TXIFG, &IFG2       ; USCI_A0 TX buffer ready?
  jz -                          ; Jump if TX buffer not ready
  mov.b @r4, &UCA0TXBUF         ; TX -> RXed character
  drop
  ret
  endm

