Lately I've been playing around with finding ways to check the battery level on my TI-84+SE. Just for fun, I put in some carbon-zinc batteries, which are infamous for not lasting very long. They've been sitting on my desk for way too long and I want to drain them in a non-wasteful way before I dispose of/recycle them. (Don't worry, I am making sure physical leaks aren't happening.) Avg voltage output from all 4 batteries is ~1.45V, according to my multimeter. Anyway, methods of checking the battery level:

Method 1 is by using this code and running it with `Asm(`:

Code:
AsmPrgm
EF6F4C3D280A78FE1E
3805
EF21521808
EFB3503E042001AF
EF8C47EFBF4AC9

Then just type `Ans` into the home screen and a value of 0-4 will indicate the battery level. Pretty simple.

Method 2 works by, well, opening DCS 7.4 and checking the battery meter on the bottom right.

The thing is, DCS7 and the little assembly program have different outputs. As of now, the assembly program outputs 4 (100%) and DCS7 is showing what looks like the level just below 100% on the graphical battery meter. What's even more confusing is that the higher I set my display contrast, the lower the battery meter gets in DCS7 when I close and open it again; but the output of the asm program remains the same.

That's... interesting. And it seems there are no comments in source code hosted on the GitHub repository for DCS7 that have anything to do with the battery meter. There's just a single mention, that's in TODO.txt. What is up with the programming behind this seemingly cursed mechanism?
This block from RenderDesktop looks like the battery meter implementation.

Code:
   ld a,(8447h)               ;actually checks contrast, here was ld a,(battlevel)
   ld de,$01fc               ;init batt mask (for full)
BattDivLoop:                  ;shift loop here
   sub 2                  ;take battlevel-5
   sla e                  ;shift it to the left
   jr nc,BattDivLoop2            ;if didn't overflow, skip over
   sla d                  ;otherwise work with d
   inc d                  ;inc it
   jr BattDivLoop3               ;continue
BattDivLoop2:                  ;if none to add
   sla d                  ;shift over
BattDivLoop3:                  ;all continue here
   cp 22                  ;check if level is now>0
   jp p,BattDivLoop            ;if so, loop up
   ld a,d                  ;get d value
   and $03                  ;mask it
   ld d,a                  ;save it
   ld hl,PlotsScreen+9d+(12*58)         ;screen location
   ld b,3                  ;3 rows to do
BattDivLoop4:                  ;disp loop

It does just seem to treat the current contrast setting as a proxy for battery level (I believe under the theory that maintaining constant actual contrast as battery voltage drops requires a higher setting), but it doesn't seem very useful.

It does also poll port 2 to check for a low-battery condition:

Code:
MouseBatt:                  ;continue here
   in a, (2)               ;poll batt port
   and 01h                ;is low bit set?
   jr nz,MouseNoBatt            ;if ok, skip this
   ld ix,ErrDialogMask            ;get icon
   ld b,8                  ;8 rows
   ld l,46                  ;y=46
   ld a,78                  ;x=78
   call iPutSpriteMask         ;put it up
MouseNoBatt:               ;here starts mem meter disp
I assume your code is also working with port 2, but using the high bits of port 4 (which aren't available on the regular 83+) to improve the resolution beyond 1 bit.
Tari has correctly reversed-engineered the way that Doors CS 7.4 detects battery level. Per Tari's explanation, it uses two separate mechanics for the level of the battery meter and for the low battery pop-up. The former is indeed guessed based on LCD contrast: at least when Doors CS was written, the calculators' LCDs became markedly lighter with depleted batteries, and users would typically adjust their contrast to compensate. The low battery pop-up, by contrast, indeed checks if the lowest bit of Port 02 is set, which indicates low batteries.
KermMartian wrote:
Tari has correctly reversed-engineered the way that Doors CS 7.4 detects battery level. Per Tari's explanation, it uses two separate mechanics for the level of the battery meter and for the low battery pop-up. The former is indeed guessed based on LCD contrast: at least when Doors CS was written, the calculators' LCDs became markedly lighter with depleted batteries, and users would typically adjust their contrast to compensate. The low battery pop-up, by contrast, indeed checks if the lowest bit of Port 02 is set, which indicates low batteries.


Okay, thank you. Thanks Tari as well.

But I'm curious: is it possible to execute the battery checking assembly code inside an Axe program by embedding it? I tried doing it with `Asm(` but the resulting Axe Fusion program unceremoniously crashed.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement