To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.pbforthOpen lugnet.robotics.rcx.pbforth in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / pbFORTH / 181
180  |  182
Subject: 
Save image in pbForth (srec version)
Newsgroups: 
lugnet.robotics.rcx.pbforth
Date: 
Thu, 11 Nov 1999 21:38:02 GMT
Viewed: 
1417 times
  
Hi Ralph,

Finally I got it to work.
Now there is XMODEM protocol and S-record writer on top of it. SAVE-SYSTEM
word has been redefined to produce S-record image.

Although upload time is up to 5 min now, instead I don't spend time anymore to
mess with other tools. ;)
And you were right, this is much more convenient.

Sergey


-- pbForth code -------------------------------------------------------------

RCX_INIT

\
\ srec.f
\ S-Record format
\

BASE @ HEX
GET-CURRENT NONSTANDARD-WORDLIST SET-CURRENT

\ utilities

' TX! VALUE 'byte!    \ vector for "emit" word

: byte! ( b -- )
  'byte! EXECUTE ;

: data! ( addr n -- )
  0 DO
    DUP C@ 'byte! EXECUTE CHAR+
  LOOP DROP ;

\ s-record fields

VARIABLE srec.checksum

: srec.type! ( type -- )
  [CHAR] S byte!
  0 <# # #> DROP C@ byte! ;

: srec.count! ( data-size -- )
  2 + 1+   \ address-size + checksum-size
  DUP srec.checksum !
  0 <# # # #> data! ;

: srec.address! ( addr-n -- )
  DUP FF AND OVER 8 RSHIFT + srec.checksum +!
  0 <# # # # # #> data! ;

: srec.data! ( data-addr data-size -- )
  ?DUP IF
    0 DO
      DUP C@ DUP srec.checksum +!
      0 <# # # #> data! CHAR+
    LOOP
  THEN DROP ;

: srec.checksum! ( -- )
  srec.checksum @ INVERT FF AND
  0 <# # # #> data! ;

: srec.cr_lf! ( -- )
  0D byte! 0A byte! ;

\ s-record types

: S-record! ( address data-addr data-size type -- )
  srec.type!
  DUP srec.count!
  ROT srec.address!
  srec.data!
  srec.checksum!
  srec.cr_lf! ;

: S0-record! ( -- )
  0 S" pbForth" 0 S-record! ;

: S1-record! ( data-addr data-size -- )
  OVER SWAP 1 S-record! ;

: S9-record! ( address -- )
  0 0 9 S-record! ;

\ s-record dump

15 VALUE srec.data_size

: srec-data-size ( begin-addr end-addr -- data-size )
  SWAP - DUP srec.data_size > IF
    DROP srec.data_size
  THEN ;

: srec-data! ( addr size -- )
  OVER + DUP ROT DO
    I OVER srec-data-size
    I OVER S1-record!
  +LOOP DROP ;

: srec-dump ( addr size xt-emit -- )
  'byte! >R TO 'byte!    \ set "emit" vector
  BASE @ >R HEX          \ for <# .. #>
  DUP IF
    S0-record! 2DUP srec-data! OVER S9-record!
  THEN 2DROP
  R> BASE !
  R> TO 'byte! ;

: SREC-DUMP ( addr size -- )
  CR ['] TX! srec-dump ;

SET-CURRENT
BASE !


\
\ x-send.f
\ Simple XMODEM protocol (sender)
\

RCX_INIT

BASE @ HEX
GET-CURRENT NONSTANDARD-WORDLIST SET-CURRENT

\ RCX utilities

: RUN-BUTTON? ( -- flag )
  RCX_BUTTON DUP BUTTON_GET @ 1 AND 1 = ;

: LCD-INT ( n -- )
  3002 SWAP 3001 LCD_NUMBER LCD_REFRESH ;

\ communication

: rx? ( -- flag )
  RUN-BUTTON? IF ABORT" Interrupted" THEN RX? PAUSE ;

: rx@ ( -- c )
  BEGIN rx? UNTIL RX@ ;

: response? ( c-request -- c-response )
  0 0 timer_SET
  BEGIN
    0 timer_GET 0= IF DUP TX! 5 0 timer_SET THEN
    rx?
  UNTIL DROP RX@ ;

\ XMODEM block

1  CONSTANT <SOH>
4  CONSTANT <EOT>
6  CONSTANT <ACK>
15 CONSTANT <NAK>

80 CONSTANT block.data_size

memTop 100 - VALUE block           \ tmp value for safety

: block.create ( -- )
  HERE TO block
  0 , 0 , 0 ,                      \ blk-nr, offset, checksum
  HERE block.data_size DUP ALLOT   \ data
  memTop 100 - FILL ;

: block.destroy ( -- )
  block HERE - ALLOT       \ restore
  0 TO block ;

\ block fields
: block.number   ( -- nr-addr )   block ;
: block.offset   ( -- off-addr )  block CELL+ ;
: block.checksum ( -- sum-addr )  block CELL+ CELL+ ;
: block.data     ( -- data-addr ) block 3 CELLS + ;

: block.next ( -- )
  1 block.number +! 0 block.offset ! 0 block.checksum !
  block.data block.data_size 0 FILL
  block.number @ LCD-INT ;  \ block nr on LCD

: block.remain ( -- n )
  block.data_size block.offset @ - ;

: block.byte! ( b -- )
  DUP block.data block.offset @ + C!
  FF AND block.checksum +!
  1 block.offset +! ;

: block.tx_header ( -- ; header: <SAH> <blk-nr> <FF - blk-nr> )
  <SOH> TX!
  block.number @ 1+ DUP TX!
  FF SWAP - TX! ;

: block.tx_checksum ( -- )
  block.checksum @ FF AND TX! ;

: block.tx_data ( off -- )
  DUP block.data + block.data_size ROT - 0 DO
     DUP C@ TX! CHAR+
  LOOP DROP ;

: block.sent? ( -- )
  BEGIN rx@ <ACK> = INVERT WHILE
    block.tx_header 0 block.tx_data block.tx_checksum
  REPEAT
  block.next ;

: block.put_byte ( b -- )
  block.offset @ 0= IF
    block.tx_header
  THEN
  DUP block.byte! TX!
  block.remain 0= IF
    block.tx_checksum block.sent?
  THEN ;

: block.flush ( -- )
  block.offset @ 0 > IF
    block.remain 0 > IF
       block.offset @ block.tx_data
    THEN
    block.tx_checksum block.sent?
  THEN ;

\ XMODEM protocol

: x-transmit-byte ( b -- )
  block.put_byte ;

: x-transmit ( addr count -- )
   0 DO
     DUP C@ block.put_byte CHAR+
   LOOP DROP ;

: x-begin ( -- )
  block.create
  BEGIN rx@ <NAK> = UNTIL
  301C LCD_SHOW LCD_REFRESH ;  \ tx indicator

: x-end ( -- )
  block.flush block.destroy
  BEGIN <EOT> response? <ACK> = UNTIL
  301C LCD_HIDE LCD_REFRESH ;  \ tx indicator

: X-SEND ( addr count -- )
  x-begin x-transmit x-end ;

SET-CURRENT
BASE !


\
\ save-sys.f
\ Save FORTH image
\

BASE @ HEX
GET-CURRENT NONSTANDARD-WORDLIST SET-CURRENT

: X-SEND-SREC ( addr size -- )
  x-begin
  ['] x-transmit-byte srec-dump
  x-end ;

: SAVE-SYSTEM ( -- )
  CR ." Saving image..."
  CR ." (Press 'RUN' to abort)"
  8000 HERE OVER - X-SEND-SREC ;

SET-CURRENT
BASE !

-- end of pbForth code ------------------------------------------------------



Message has 1 Reply:
  RE: Save image in pbForth (srec version)
 
(...) <snipped pbForth code> COOL! I guess you could load this in just before you actually need to do the dumping of the memory. This is a great contribution, Sergey. Do you mind if I put it in script format and package it with the standard (...) (25 years ago, 11-Nov-99, to lugnet.robotics.rcx.pbforth)

6 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR