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 / 171
170  |  172
Subject: 
Save image word for pbForth.
Newsgroups: 
lugnet.robotics.rcx.pbforth
Date: 
Sat, 6 Nov 1999 23:47:16 GMT
Viewed: 
1469 times
  
Hello,

Being bored uploading all the optional libraries to my pbForth system all the
time, I’ve reinvented the wheel and implemented SAVE-SYSTEM word. Now I can
create many different “saved” pbForth versions and load them at will.

The idea is simple: send current pbForth image to PC and convert this image to
SREC file.
First goal resolved by simple XMODEM implementation, which could send some
data to “any” terminal program (Telix and Hyperterminal were tested).
To convert the received binary image to SREC file, I’ve used standard objcopy
utility from Cygwin32 package.

pbForth code attached to the end of this post. Note that XMODEM implementation
is really simple, it’s even not a CRC – just a checksum. So terminal programs
will need some time to realize it (~10sec for Telix and ~1min for
Hyperterminal).

Hire is a line I’ve used to convert resulting bin to SREC:
    objcopy –adjust-vma=0x8000 –I binary –O srec save.bin save.srec

Regards
Sergey Udovenko

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

RCX_INIT
BUTTON_INIT

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

\ RCX utilities

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

: int_lcd ( n -- )
  3002 SWAP 3001 LCD_NUMBER LCD_REFRESH ;

: tx_lcd_show ( -- )
  301C LCD_SHOW LCD_REFRESH ;

: tx_lcd_hide ( -- )
  301C LCD_HIDE LCD_REFRESH ;

\ XMODEM constants

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

80 CONSTANT block_size

\ XMODEM utilities

: 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@ ;

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

: tx_checksum ( checksum -- )
  FF AND TX! ;

: tx_data ( data-addr -- checksum ; 128-byte block )
  0 block_size 0 DO
    OVER I + C@ DUP TX! +
  LOOP NIP ;

: tx_block ( data-addr blk-nr -- ; block: <header> <data> <checksum> )
  tx_header tx_data tx_checksum ;

: range>count ( begin-addr end-addr -- begin-addr count )
  OVER - block_size /MOD SWAP IF 1+ THEN ;

: index>addr ( begin-addr index -- data-addr )
  block_size * + ;

: next_block? ( -- blk-increment )
  rx@ <ACK> = IF 1 ELSE 0 THEN ;

\ XMODEM protocol

: x-transmit ( begin-addr end-addr -- )
  range>count 0 DO
    I int_lcd
    DUP I index>addr I tx_block next_block?
  +LOOP DROP ;

: x-begin ( -- )
  BEGIN rx@ <NAK> = UNTIL tx_lcd_show ;

: x-end ( -- )
  BEGIN <EOT> response? <ACK> = UNTIL tx_lcd_hide ;

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

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

SET-CURRENT
BASE !

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



Message has 1 Reply:
  RE: Save image word for pbForth.
 
(...) Sergey, This is an EXCELLENT idea. On an old project I used to work on, I actually used an SREC dump routine, but here the tower would cause problems because the PC would keep having to poll for addresses. Using XMODEM transfer will work great (...) (25 years ago, 7-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