
compiletoflash

: u.4 ( u -- ) 0 <# # # # # #> type ;
: u.2 ( u -- ) 0 <# # # #> type ;

: hexdump ( -- ) \ Dumps complete Flash
  cr hex

  \ MSP430F2274: Complete: $FFFF $8000 Dictionary only: $DBFF $8000
  \ MSP430G2553: Complete: $FFFF $C000 Dictionary only: $DBFF $C000

  $DBFF $C000 \ Dictionary only for faster dump
  do
    \ Check if it would be $FFFF only:
    0                 \ Not worthy to print
    i #16 + i do      \ Scan data
      i c@ $FF <> or  \ Set flag if there is a non-$FF byte
    loop

    if
      ." :10" i u.4 ." 00" \ Write record-intro with 4 digits.
      $10                   \ Begin checksum
      i    $FF and +        \ Sum the address bytes 
      i >< $FF and +        \ separately into the checksum

      i #16 + i do
        i c@ u.2 \ Print data with 2 digits
        i c@ +     \ Sum it up for Checksum
      loop

      negate u.2  \ Write Checksum
      cr
    then

  #16 +loop
\  ." :00000001FF" cr
  decimal
;
