A83: Re: Flags


[Prev][Next][Index][Thread]

A83: Re: Flags




GET MY TUTORIALS :)...its pasted below for ya.

James Matthews (matthews@tkb.att.ne.jp)

PS:  If anyone quotes this...delete the tutorials, its big.

ICQ: 7413754
http://home.att.ne.jp/gold/tomcat21/index.html
http://library.advanced.org/18242/

------
Tutorial 8: Mode Flags.
Mode flags:  setting, resetting, checking.
Introduction.
Ever wanted to detect what trig mode or graphing mode you were in when
programming in Ti-BASIC?  Well, using BASIC you can't (trig mode you could,
but...help07) — but using our wonderful ASM you can!  Here is how...

New Commands.
bit:		Returns the value of the trait/function (on/off).
call _newline:	Starts a newline.
call _homeup:	Puts the cursor at 0,0.

Note:  Do you remember the 'set' and 'res' commands from Tutorial #5? 
You'll need those as well.  Also, please note I figured this out by myself,
with no outside help from tutorials/people etc., so it might not be 100%
fool-proof (but you're not a fool, right?)

Offset Table.
What is this?!  Well, just wait a second, and we'll get to that.  Note that
this was copied/pasted right out of the Ti83asm.inc file you should have in
your TASM directory.

trigflags       EQU       0
trigdeg         EQU       2
;
plotflags       EQU       2
plotloc         EQU       1
plotdisp        EQU       2
;
grfmodeflags    EQU       2
grffuncm        EQU       4
grfpolarm       EQU       5
grfparamm       EQU       6
grfrecurm       EQU       7
;
graphflags      EQU       3
graphdraw       EQU       0
graphcursor     EQU       2
;
grfdbflags      EQU       4
grfdot          EQU       0
grfsimul        EQU       1
grfgrid         EQU       2
grfpolar        EQU       3
grfnocoord      EQU       4
grfnoaxis       EQU       5
grflabel        EQU       6
;
textflags       EQU       5
textEraseBelow  EQU       1
textScrolled    EQU       2
textInverse     EQU       3
;
onflags         EQU       9
onRunning       EQU       3
onInterrupt     EQU       4
;
statflags       EQU       9
statsvalid      EQU       6
;
fmtflags        EQU       10
fmtExponent     EQU       0
fmtEng          EQU       1
;
nummode         EQU       10
FMTREAL         EQU       5
FMTRECT         EQU       6
FMTPOLAR        EQU       7
;
curflags        EQU       12
curAble         EQU       2
curOn           EQU       3
curLock         EQU       4
;
appflags        EQU       13
appTextSave     EQU       1
appAutoScroll   EQU       2
;
PLOTFLAG2       EQU       17
EXPR_PARAM      EQU       3
EXPR_WRITING    EQU       4
;
indicflags      EQU       18
indicRun        EQU       0
indicOnly       EQU       2
;
shiftflags      EQU       18
shift2nd        EQU       3
shiftAlpha      EQU       4
shiftALock      EQU       6
;
tblflags        EQU       19
AutoFill        EQU       4
AutoCalc        EQU       5
;
sgrflags        EQU       20
grfSplit        EQU       0
VertSplit       EQU       1
WRITE_ON_GRAPH  EQU       4
textwrite       EQU       7

The Code.
Again, try to bear with the code for the moment, and take in as much as you
can.  The explanation will follow.

.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
	.LIST
.org     9327h
 
  call    _clrLCDFull
  call    _homeup
  ld      hl,0000h
  ld      (PENCOL),hl
  bit     grffuncm,(iy+grfmodeflags)  ; Function.
  jr      nz,function
  bit     grfpolarm,(iy+grfmodeflags) ; Polar.
  jr      nz,polar
  bit     grfparamm,(iy+grfmodeflags) ; Parametric.
  jr      nz,param
  bit     grfrecurm,(iy+grfmodeflags) ; Recurisive.
  jr      nz,recur
  jp      quit                        
function:
  ld      hl,functext
  jp      display

polar:
  ld      hl,polrtext
  jp      display
param:
  ld      hl,parmtext
  jp      display
recur:
  ld      hl,recurtext
  jp      display
display:
  call    _vputs
  call    _newline
quit:
  ret
functext: .db "Function mode.",0
polrtext: .db "Polar mode.",0
parmtext: .db "Parametric mode.",0
recurtext:.db "Recursive mode.",0
.end
.end

Explanation.
You should be able to understand everything but the 'bit
grfpolarm,(iy+grfmodeflags)'etc. stuff.  Now, although I don't really
understand the fundamentals behind the command, I do know this.  Bit checks
whether the 'place' that is specified after is set or reset (using the
'set' and 'res' commands, respectively).  To find any trait/mode simply use
the offset table.  Use this syntax:
	bit <mode/trait>,(iy+<flag offset>)
You can find the <mode/trait> under each of the offset values.  For
example, to check for degrees mode.  Simply use this code:

.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"

.LIST
.org     9327h
  
  bit     trigdeg,(iy+trigflags)
  jr      z,radians
  ld      hl,0000h
  ld      (CURROW),hl
  ld      hl,DegText
  call    _puts
  call    _newline
  jp      quit
radians:
  ld      hl,0000h
  ld      (CURROW),hl
  ld      hl,RadText
  call    _puts
  call    _newline
quit:
  ret

degtext:  .db "Degrees Mode.",0
radtext:  .db "Radians Mode.",0

.end
.end

Conclusion.
Mode flags are very useful in mathematical programs, so hopefully soon we
will learn some mathematical functions.
{button , KLink(Modes;Flags)} Related Topics.
#:If sin(45)=.7071067812
:Then
:Disp "Degrees mode."
:Else
:Disp "Radians mode."
:End
Just thought I'd share that with you all…:)