\
\    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/>.
\


\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\  4. Teil: Die Speicherkarte und Aufteilung des vorhandenen Platzes
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


\ -----------------------------------------------------------------------------
\   Memory map of MSP430F2011/MSP430F2012/MSP430F2013:
\ -----------------------------------------------------------------------------

\ $0000 - $000F  Special function registers, mostly for peripheral interrupt configuration
\ $0010 - $00FF  Byte peripheral registers
\ $0100 - $01FF  Word peripheral registers
\ $0200 - $027F  RAM, 128 Bytes
\ $1000 - $10FF  Info Flash, 256 Bytes, contains factory calibration values. Better do not touch.
\ $F800 - $FFFF  Flash, 2048 Bytes

\ Vector table, 16 entries, at the end of flash from $FFE0 to $FFFF.
\ $FFFE contains the Reset vector.

 $0200 constant ramstart

    \ Space for Variables and Buffers

    $0240 constant stackarea
    $0260 constant initialdatastack
    $0280 constant initialreturnstack
 $0280 constant ramend

 $F800 constant flashstart

    \ Space for Forth Dictionary

    $FFE0 constant vectortable
$10000 constant flashend


\ -----------------------------------------------------------------------------
\   Small tools for handling a memory image
\ -----------------------------------------------------------------------------

flashend flashstart - buffer: memoryimage

\ Enforce little endian.

: imagec! ( x addr -- ) flashstart - memoryimage + c! ;
: imagec@ ( addr -- x ) flashstart - memoryimage + c@ ;

:  image! ( x addr -- ) 2dup imagec! swap 8 rshift swap 1+ imagec! ;
:  image@ ( addr -- x )  dup imagec@ swap 1+ imagec@ 8 lshift or ;

: clearmemory ( -- ) flashend flashstart do $FF i imagec! loop ;

0 variable org

: image, ( x -- )
  \  ."  Image, " org @ hex. ." : " dup hex. cr

  org @ image! 2 org +!

  org @ vectortable u>= if ." Flash full." cr quit then
;

ramstart variable variablenpointer \ Hier wird begonnen, Variablen einzukompilieren.

