-
-
Save TG9541/1e3ca3347c2e4910b95f97023fa78b76 to your computer and use it in GitHub Desktop.
New BF! and LEBF! using B! (49 bytes, 23 bytes less than the implementation in STM8 eForth 2.2.25)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\ STM8eForth : BF! and LEBF! TG9541-200717 | |
\ ------------------------------------------------------------------------------ | |
\ Write bit to a bitfield stored in one or more cells (16 bit words) | |
\ Set/reset bit #u (0..8191) in a cell array starting at address a to bool t | |
#require DOXCODE | |
#require A> | |
#require ALIAS | |
#require :NVM | |
\ headerless: TOS/8, modulo in A | |
:NVM ( n -- n>>3 A:n%8 ) | |
DOXCODE [ | |
$9F C, \ LD A,XL | |
$A407 , \ AND A,#0x07 | |
$54 C, \ SRLW X | |
$54 C, \ SRLW X | |
$54 C, \ SRLW X | |
] | |
;RAM ALIAS SR3A | |
NVM | |
\ Write bit to a Little Endian bitfield (list of bytes) | |
\ Set/reset bit #u (0..8191) in an array starting at address a to bool t | |
: LEBF! ( b a n -- ) | |
SR3A ( n/8 | A:n%8 ) | |
[ $88 C, \ PUSH A | |
HERE ] + \ _BFS: | |
[ $84 C, ] \ POP A | |
A> ( b a n ) B! | |
; | |
\ Write bit to a bitfield stored in one or more cells (16 bit words) | |
\ Set/reset bit #u (0..8191) in a cell array starting at address a to bool t | |
: BF! ( b a n -- ) | |
SR3A ( n/8 | A:n%8 ) | |
[ $88 C, ] \ PUSH A | |
1 XOR [ \ Big Endian byte order | |
HERE $20 C, - 2- C, \ JRA _BFS | |
OVERT | |
RAM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment