\
\    Mecrisp-Across - A Forth cross compiler for small MSP430 microcontrollers
\    Copyright (C) 2016  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/>.
\


\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\  8. Teil: Schließlich jenes, was kompiliert werden soll :-)
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

new \ Das Dictionary des Crosscompilers zurücksetzen

\ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
    TARGET
\ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

: delchar ( addr len -- addr len )
  dup if 8 emit 32 emit 8 emit then

  begin
    dup 0= if exit then
    1- 2dup + c@
    $C0 and $80 <>
  until
;

: accept ( addr maxlen -- len )
  >r 0  ( addr len R: maxlen )

  begin
    key    ( addr len key R: maxlen )

    dup   9 = if drop 32 then
    dup 127 = if drop  8 then

    dup 31 u>
    if

      over r@ u<
      if
          dup emit
          >r 2dup + r@ swap c! 1+ r>
      then
    then

    dup 8 = if >r delchar r> then

    dup 10 = swap 13 = or
  until

  rdrop nip
  space
;


: type ( addr len -- )
  begin
    dup
  while
    over c@ >r
    1- swap 1+ swap
    r> emit
  repeat
  2drop
;

16 constant maxlength
maxlength buffer: tib

: terminal ( -- )
  8MHz uart-init
  begin
    [char] > emit space

    tib dup maxlength accept

    [char] { emit
    type
    [char] } emit
    cr
  again
;

\ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
    HOST
\ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

$FFFE vector terminal  \ Vektortabelle füllen und Einsprungpunkte definieren
crosscompile            \ Zeit für die Crosscompilation !

\ -----------------------------------------------------------------------------

\ Was hat der Compiler daraus gemacht ?

\ t-listing
t-listing-file accept.list

\ Was ist entstanden ? Einen tiefen Einblick für den Menschen ermöglichen.

disimage
disimage-file accept.asm

\ Und die fertige Intel-Hex-Datei für den Chip ausgeben.

hexdump
hexdump-file accept.hex

