aboutsummaryrefslogtreecommitdiff
path: root/board-js2x
diff options
context:
space:
mode:
Diffstat (limited to 'board-js2x')
-rw-r--r--board-js2x/slof/helper.fs9
-rw-r--r--board-js2x/slof/rtc.fs4
2 files changed, 13 insertions, 0 deletions
diff --git a/board-js2x/slof/helper.fs b/board-js2x/slof/helper.fs
index 1e2b030..c522c90 100644
--- a/board-js2x/slof/helper.fs
+++ b/board-js2x/slof/helper.fs
@@ -37,3 +37,12 @@
ENDCASE
drop
;
+
+\ count the number of bits equal 1
+\ the idea is to clear in each step the least significant bit
+\ v&(v-1) does exactly this, so count the steps until v == 0
+: cnt-bits ( 64-bit-value -- #bits=1 )
+ dup IF
+ 41 1 DO dup 1- and dup 0= IF drop i LEAVE THEN LOOP
+ THEN
+;
diff --git a/board-js2x/slof/rtc.fs b/board-js2x/slof/rtc.fs
index 861b3f9..5d5dbc3 100644
--- a/board-js2x/slof/rtc.fs
+++ b/board-js2x/slof/rtc.fs
@@ -40,6 +40,10 @@
\ PC87417.pdf page 156 (chapter 8.3.15) - RTC Control Register C
00 0c rtc!
+: bcd-to-bin ( bcd -- bin )
+ dup f and swap 4 rshift a * +
+;
+
\ read from the rtc and do the bcd-to-bin conversion
: rtc-bin@ ( offset -- value )
rtc@ bcd-to-bin