Contrast tool from JeePee

Ok let's study a tiny code dedicated to contrast adjustement.

The code was made by JeePee, and available on ticalc here

So let's go !

.NOLIST #include "ti83plus.inc" #define bcall(label) rst 28h \ .dw label Min .EQU 81h Plus .EQU 80h Enter .EQU 05h Clear .EQU 09h .LIST .org 9D93h .db $BB,$6D


Ok as always we have the include, the equates then the .org 9D93h and finally the AsmCmp token.

Nothing interesting here, go on.

ld a,(8447h) ;load the current contrast from RAM ld (curcontrast),a ;load it into a temporary variable call drawcontrast mainloop: bcall(_getkey) ;checks for keys cp Enter ;on Enter -> Restore the current contrast back in RAM jr z,Change cp Min ;on Min -> Decrese the contrast with 1 jr z,Minder cp Plus ;on Plus -> Increase the contrast with 1 jr z,Meer cp Clear ;on Clear -> Don't restore current contrast back in RAM jr nz,mainloop ;but reload old contrast back from RAM and apply that ld a,(8447h) ;load the current contrast from RAM causes you pushed CLEAR ... jr Do Change: ld a,(curcontrast) ;load the current contrast ... ld (8447h),a ;... load it back into RAM ... Do: call SetContrast ;... and apply it to the LCD ret


Here JeePee simply loads the contrast from the place where it's stored 8447h and keep it into a user variable (curContrast).
Then, as the program is reading keypress to change the contrast or exit, JeePee wait a key press (_getkey) and compare the result to the predefined consts.
So if the key is Enter, jump to the label Change, else if the key is Min, go to Minder, else if the key is Plus, go to Meer...
Finally if the key is not Clear, then restart to mainloop.
If it's Clear, restor the contrast (get it from 8447h) then jump to Do and setContrast the return (stop the program in this case).

Minder: ;Decrease the current contrast ld a,(curcontrast) cp 0h jr z,mainloop dec a ld (curcontrast),a call SetContrast jr mainloop Meer: ;increase the current contrast ld a,(curcontrast) cp 39d jr z,mainloop inc a ld (curcontrast),a call SetContrast jr mainloop


Now we study the More or Less contrast part.

This is really easy to understand, into Minder, if the contrast is 0, we do nothing, else decrement a and setContrast.
Same thing for More (called Meer here). If the contrast is equal to 39, do nothing, else increment a and setContrast.

In any case, return to the main loop.

SetContrast: ;Apply the contrast to the LCD (port 10h) add a,$18 or $c0 call lcdbusy out (10h),a call drawcontrast ret drawcontrast: ld hl,$0404 ld (currow),hl ld a,(curcontrast) ld h,0 ld l,a bcall(_disphl) ret lcdbusy: ;Smal Delay for the display driver push hl inc hl dec hl pop hl ret curcontrast .db 00h ;Temporary variable to store the contrast during the program


The set contrst add $18 to a (which contains a value from 0 to 39 in decimal).

Then it does an or with 11000000 and wait a moment (lcdbusy only make a pause).
Then the contrast is send to the port 10h and a text is displayed by drawcontrast (text start coords are 4,4), _disphl display th evalue of hl (itoa...) and hl contains a (a contains the contrast !).
You should notice that the curcontrast var is declared at the end of the file (adress 00).