Skip to content

Instantly share code, notes, and snippets.

@TG9541
Created July 17, 2020 13:06
Show Gist options
  • Save TG9541/1e3ca3347c2e4910b95f97023fa78b76 to your computer and use it in GitHub Desktop.
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)
\ 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