Skip to content

Commit

Permalink
#12: stack comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TG9541 committed Apr 12, 2020
1 parent 836d71f commit f977cde
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion MBPROTO
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ NVM
rxp @ 2- ( a1 ) DUP rxbuf ( a1 a1 a0 )
MBCRC ( a1 crc-le ) SWAP @ = ( crc OK )
( crc-ok ) IF
mbnode @ rxbuf C@ = ( node address match ) IF
mbnode @ rxbuf C@ = IF \ node address match
rxbuf C@ ( DUP ." S: " . CR ) txc+
rxbuf 1+ C@ DUP txc+ ( fc )
DUP 1 17 WITHIN IF
Expand Down
27 changes: 18 additions & 9 deletions MBSERVER
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ NVM

\ FC01 handler
:NVM ( -- )
[ ( xt1 xt2 ) SWAP ] LITERAL 1 ( xt bpu ) mbread
;NVM ( xt ) 1 FC>XT !
[ ( xt xth ) SWAP ] LITERAL 1 ( xth xt bpu ) mbread
;NVM ( xth ) 1 FC>XT !


\ --- FC02 "Read Discrete Inputs"
Expand All @@ -42,8 +42,8 @@ NVM

\ FC02 handler
:NVM ( -- )
[ ( xt1 xt2 ) SWAP ] LITERAL 1 ( xt bpu ) mbread
;NVM ( xt ) 2 FC>XT !
[ ( xt xth ) SWAP ] LITERAL 1 ( xth xt bpu ) mbread
;NVM ( xth ) 2 FC>XT !


\ --- FC03 "Read Holding Registers"
Expand All @@ -52,13 +52,22 @@ NVM

\ FC03 holding register iterated transfer
:NVM ( i -- 1 )
2* holding + @ tx+ 1 ( inc )
( i ) DUP 0 EECELLS WITHIN IF
2* EESTART + @
ELSE
( i ) EECELLS - DUP 0 HOLDINGCELLS WITHIN IF
2* holding + @
ELSE
( i ) DROP 0
THEN
THEN
tx+ 1 ( inc )
;NVM ( xt )

\ FC03 handler
:NVM ( -- )
[ ( xt1 xt2 ) SWAP ] LITERAL 16 ( xt bpu ) mbread
;NVM ( xt ) 3 FC>XT !
[ ( xt xth ) SWAP ] LITERAL 16 ( xth xt bpu ) mbread
;NVM ( xth ) 3 FC>XT !


\ --- FC04 "Read Input Registers"
Expand Down Expand Up @@ -110,12 +119,12 @@ NVM
\ FC15 handler
:NVM ( -- )
COILBYTES mbprange? IF
[ ( xt1 xt2 ) SWAP ] LITERAL ( xt ) mbloop
[ ( xt xth ) SWAP ] LITERAL ( xth xt ) mbloop
MBSWR
ElSE
2 MBEC
THEN
;NVM ( xt ) 15 FC>XT !
;NVM ( xth ) 15 FC>XT !


\ --- FC16 "Write Multiple Register"
Expand Down

0 comments on commit f977cde

Please sign in to comment.