Skip to content

Commit

Permalink
Merge pull request #110 from TG9541/lib-fix
Browse files Browse the repository at this point in the history
Lib fix
  • Loading branch information
TG9541 authored Nov 11, 2017
2 parents 41f87f6 + 5a65d37 commit 4307122
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 18 deletions.
4 changes: 2 additions & 2 deletions inc/defconf.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
; STM8EF for STM8S (Value line and Access Line devices)
; Default settings for all kinds of options
;--------------------------------------------------------
RELVER1 = 1 ; Revision digit 1
RELVER0 = 9 ; Revision digit 0
RELVER1 = 2 ; Revision digit 1
RELVER0 = 0 ; Revision digit 0

TERM_LINUX = 1 ; LF terminates line
HALF_DUPLEX = 0 ; Use EMIT/?KEY in half duplex mode
Expand Down
27 changes: 17 additions & 10 deletions lib/@inter
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,34 @@
\ Saturates to y(xmin), y(xmax).
\ refer to github.com/TG9541/stm8ef/blob/master/LICENSE.md

\ difference of two values two cells apart, helper for @inter
HERE \ ( -- xt ) \ nameless @dif ( a -- n ) delta of x1-x0 or y1-y0
] DUP 2+ 2+ @ SWAP @ [ $81 C,
HERE \ xt of nameless 2cell+ ( a -- a a+4 )
\ helper for @dif and @inter
] DUP 2+ 2+ [ $81 C,

HERE \ xt of nameless @dif ( a -- n ) delta of x1-x0 or y1-y0
\ difference of two values two cells apart, helper for @inter
OVER ( 2cell+ ) CALL, ] @ SWAP @ - [ $81 C, SWAP

\ find (X0,Y0)/(X1,Y1) in table, interpolate w/ saturation
: @inter ( n a -- n1 )
: @inter ( n a -- n )
\ compile time: consumes xt of 2cell+ and @dif
DUP @ 1- >R 2+ DUP BEGIN
3 PICK OVER @ < NOT WHILE NIP DUP 2+ 2+ NEXT
3 PICK OVER @ < NOT WHILE NIP [ ROT ( 2cell+ ) CALL, ] NEXT
DROP DUP
ELSE R> DROP THEN
OVER = IF
2+ @ NIP
ELSE
DUP ROT OVER @ - OVER 2+ [ DUP CALL, ] ( @dif )
ROT [ CALL, ] ( @dif ) */ SWAP 2+ @ +
then
DUP ROT OVER @ - OVER 2+ [ OVER ( @dif ) CALL, ]
ROT [ SWAP ( @dif ) CALL, ] */ SWAP 2+ @ +
THEN
;

\\ Example:

\ create structure with 3 x/y pairs:
create iTab 3 , -100 , 200 , 0 , 100 , 100 , -1000 ,
CREATE iTab 3 , -100 , 200 , 0 , 100 , 100 , -1000 ,

-150 iTab @inter . \ 200 ok
-200 iTab @inter . \ 200 ok
50 iTab @inter . \ -450 ok
200 iTab @inter . \ -1000 ok
26 changes: 20 additions & 6 deletions lib/MARKER
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
\ STM8eForth : MARKER MM-170929
\ STM8eForth : MARKER for words in RAM MM-170929
\ ------------------------------------------------------------------------------

RAM : _ ; \ dummy word to ensure that last points to RAM, not Flash

HERE \ ( -- xt )
] RAM DUP @ last 2- ! 2+ DUP @ last ! 2+ @ last 10 + ! [ $81 C,
\ get CP stored by MARKER, get last & context from the mark's link field
] RAM DUP @ last 2- ! 2+ @ DUP last ! last 10 + ! [ $81 C,

: MARKER ( "name" -- )
\ The marker "name" removes itself and all later defined words from RAM.
RAM HERE last 2- @ , last @ , last 10 + @ ,
RAM HERE last 2- @ , \ store CP, then define a mark
: [COMPILE] LITERAL ( xt ) LITERAL CALL, [COMPILE] ;
;

\ ------------------------------------------------------------------------------
\ Last Revision: MM-170930 Dummy word _ added. dofence made headerless
\\ Example:

RAM
: _ ; \ dummy word to ensure that last points to RAM, not Flash

MARKER myMarker

: tempWordRAM ;

NVM
: wordFlash ;

RAM
myMarker

\ tempWordRAM and myMarker are removed, wordFlash is still in the dictionary
31 changes: 31 additions & 0 deletions lib/STARTTEMP
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
\ Scaffolding for temporary RAM usage during compilation
\ refer to github.com/TG9541/W1209/blob/master/LICENSE.md

RAM
#require MARKER

\ Mark dictionary in RAM
MARKER tempRAM

\ assume default target if not defined by the application
#require TARGET

: ENDTEMP ( -- )
\ tear down scaffolding if we've been compiling to NVM
HERE 0< IF
RAM tempRAM NVM
THEN
;

\ ---------------------------------------------------------
\\ Example:

\ uncomment for NVM as the compilation target
\ : TARGET NVM ;

#include STARTTEMP
\ use RAM
: temporaryWordInRAM ;
TARGET
: wordInTargetMemory ;
ENDTEMP

0 comments on commit 4307122

Please sign in to comment.