Page 1 of 1
[TI ASM] Reading the Ans Variable
Posted: Sun 07 Mar, 2010 12:40 pm
by Matthias1992
Okay before the whole MaxCoderz Staff is getting Angry with me, I did search throught the forum But I could only find the "reverse" of my question, how to store to (TIOS) Varaibles, that was here:
http://www.junemann.nl/maxcoderz/viewtopic.php?t=304
My Question is, is there a way to Get the value of the ANS variable into the A register so I can "CP" it and by that define a appropiate action. For example my program could clear the screen the ASM way (fast!) by calling
Code: Select all
1:prgmLIBRARY ;1 is stored to ans, then my prgm is executed
my program now sees that ANS is 1 and (for example) reacts on that by Clearing the Homescreen...
I am aware there are tons of these prgms out there but it is more for learning purposes...
Thanks in advance!
Re: [TI ASM] Reading the Ans Variable
Posted: Sun 07 Mar, 2010 2:23 pm
by King Harold
You could use RclAns and ConvOP1
Re: [TI ASM] Reading the Ans Variable
Posted: Mon 08 Mar, 2010 10:42 am
by Matthias1992
Ok thanks Alot, I figured it out. Now onto something else (Should I start a new topic for this?) I can't seem to get the
to work...
the context of this code is written below, please note that I am still learning asm so bare with me for (major) mistakes, any optimization is greatly appreciated but please comment it well so I can understand your optimization.
Code: Select all
.nolist
#include "ti83plus.inc"
#define ProgStart $9D95
.list
.org ProgStart -2
.db t2ByteTok, tAsmCmp
ld IY,flags
B_CALL(_RclAns)
B_CALL(_ConvOP1)
cp 0
jp z, ClrScreen ;0
cp 1
jp z, DispDoneOff ;1
cp 2
jp z, APDOff ;2
cp 3
jp z, APDOn ;3
cp 4
jp z, DrawSquare ;4
cp 5
jp z, GameScreenOn ;5
cp 6
jp z, GameScreenOff ;6
cp 7
jp z, TextInverseOn ;7
cp 8
jp z, TextInverseOff ;8
cp 9
jp z, LowerCaseOn ;9
cp 10
jp z, LowerCaseOff ;10
cp 11
jp z, ShiftAlockOn
cp 12
jp z, ShiftAlockOff
jp Stop
ClrScreen:
B_CALL(_ClrLCDFull)
B_CALL(_ClrScrnFull)
jp Stop
DispDoneOff:
res donePrgm, (IY+doneFlags)
jp Stop
APDOff:
res APDAble, (IY+apdFlags)
jp Stop
APDOn:
set APDAble, (IY+apdFlags)
jp Stop
DrawSquare:
B_CALL(_ZeroOP1)
LD A, 'X'
LD (OP1+1),A
B_CALL(_RclVarSym)
LD A, (OP1)
LD L, A ;L is X
B_CALL(_ZeroOP1)
LD A, 'Y'
LD (OP1+1),A
B_CALL(_RclVarSym)
LD A, (OP1)
LD H, A ;H is Y
B_CALL(_ZeroOP1)
LD A, 'O'
LD (OP1+1),A
B_CALL(_RclVarSym)
LD A, (OP1) ;offset is in A
ADD A, L ;A is X2
LD E, A ;E is X2
B_CALL(_ZeroOP1) ; A weer reseten naar de Offset
LD A, 'O'
LD (OP1+1),A
B_CALL(_RclVarSym)
LD A, (OP1) ;offset is in A
ADD A, H ;A is Y2 (of y+offset)
LD D, A ;D is Y2
jp Stop
GameScreenOn:
set grfNoCoord, (IY+grfDBFlags)
set grfNoAxis, (IY+grfDBFlags)
res grfGrid, (IY+grfDBFlags)
B_CALL(_ZeroOP1)
LD A, XMINt
B_CALL(_StoSysTok)
LD A, YMINt
B_CALL(_StoSysTok)
B_CALL(_OP1Set1)
LD A, DELTAXt
B_CALL(_StoSysTok)
LD A, DELTAYt
B_CALL(_StoSysTok)
jp Stop
GameScreenOff:
res grfNoCoord, (IY+grfDBFlags)
res grfNoAxis, (IY+grfDBFlags)
set grfGrid, (IY+grfDBFlags)
jp Stop
TextInverseOn:
set textInverse, (IY+textFlags)
jp Stop
TextInverseOff
res textInverse, (IY+textFlags)
jp Stop
LowerCaseOn:
set shiftLwrAlph, (IY+shiftFlags)
jp Stop
LowerCaseOff:
res shiftLwrAlph, (IY+shiftFlags)
jp Stop
ShiftAlockOn:
set shiftALock, (IY+shiftFlags)
jp Stop
ShiftAlockOff:
res shiftALock, (IY+shiftFlags)
jp Stop
Stop:
RET
.end
.end
Thanks once more!
P.S don't mind the comments you most likely won't understand them unless your native language is dutch...
Re: [TI ASM] Reading the Ans Variable
Posted: Mon 08 Mar, 2010 10:31 pm
by King Harold
Actually, my native language
is Dutch - imagine the odds
I don't have a lot of time right now and I will have a closer look at it later, one thing I can say already though is that you can replace something like
Code: Select all
cp 0
jr z, somewhere
cp 1
jr z, somewhere else
etc
With
Code: Select all
or a
jr z, somewhere ; a|a==a so "or a" tests for "a==0"
dec a
jr z, somewhere else ; if a-1 is 0, than a was 1
dec a etc
Which not only saves a couple of clock cycles, it saves bytes (which is especially important in asm problems, not so much in applications until you run out of space)
And of course the jp's you put there can easily be jr's, the speed difference is not going matter since they are not in a loop (and even a "do nothing" bcall would totally dominate the execution time) - saves some more bytes
jp stop can be replaces by ret, saves 2 bytes every time
ShiftAlockOff doesn't have to be closed with a jp stop/ret, it falls through to a ret anyway
IY doesn't have to be loaded with flags, it always points to the flags (if it doesn't, the TIOS will likely crash, so you can assume that if your program is running IY is pointing to the flags)
The reason your draw square isn't working is that RclVarSym kills most registers, you have to save them somewhere (I'd just push them on the stack)
edit: a second reason is that you're not getting the actual value, but only the first byte (which means close to nothing), you should use ConvOP1 or something similar
Re: [TI ASM] Reading the Ans Variable
Posted: Tue 09 Mar, 2010 9:55 pm
by Galandros
For saving memory a vector table would be nifty too.
Sorry for no explaining and giving an example vector table but I don't have time...
Re: [TI ASM] Reading the Ans Variable
Posted: Wed 10 Mar, 2010 1:41 pm
by Matthias1992
First of all thanks for the replies, I'll optimize the code...
But I still can not get my DrawSquare "function" to work. I have worked on it for 3 days now (nearly 5 hours in total) and am getting a little annoyed...Here is the code I tried (I have tried loading A onto the stack instead of AF that compiled correctly but did not work (it drew the square but not on the correct heigth and width)the second try on compiling it did NOT work...)
Code: Select all
.nolist
#include "ti83plus.inc"
#define ProgStart 9D95h
.list
.org ProgStart -2
.db t2ByteTok, tAsmCmp
LD HL, 0
B_CALL(_ZeroOP1)
LD A, 'X'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;L
B_CALL(_ZeroOP1)
LD A, 'Y'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;H
B_CALL(_ZeroOP1)
LD A, 'P'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;E
B_CALL(_ZeroOP1)
LD A, 'Q'
LD (OP1+1), A
B_CALL(_RclVarSym)
POP AF
LD E, A
POP AF
LD H, A
POP AF
LD L, A
B_CALL(_FillRect)
B_CALL(_BufCpy)
RET
.end
.end
All I can say is that I am very puzzled about this, I looked up the B_CALLS and indeed, AF HL DE and BC are destroyed by the RclVarSym but as far as I know the LSB part of the recaaled variable is stored to A...right? Well if someone can come up with a good alternative (or just completely different code) and a small explanation you can make my day!
Re: [TI ASM] Reading the Ans Variable
Posted: Wed 10 Mar, 2010 2:04 pm
by King Harold
Matthias1992 wrote:AF HL DE and BC are destroyed by the RclVarSym but as far as I know the LSB part of the recaaled variable is stored to A...right?
If that is so, then it is not documented.
equivalent to
(you could do the same for DE by restructuring the code)
The problem this time is that you're not setting D correctly (or, rather, you're not setting it at all) before calling FillRect
Re: [TI ASM] Reading the Ans Variable
Posted: Wed 10 Mar, 2010 5:10 pm
by Matthias1992
Then in my opinion this should work...but it does not....
Code: Select all
.nolist
#include "ti83plus.inc"
#define ProgStart 9D95h
.list
.org ProgStart -2
.db t2ByteTok, tAsmCmp
LD HL, 0
B_CALL(_ZeroOP1)
LD A, 'X'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;L
B_CALL(_ZeroOP1)
LD A, 'Y'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;H
B_CALL(_ZeroOP1)
LD A, 'P'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;E
B_CALL(_ZeroOP1)
LD A, 'Q'
LD (OP1+1), A
B_CALL(_RclVarSym)
LD D, A
POP AF
LD E, A
POP HL
POP AF
LD L, A
B_CALL(_FillRect)
B_CALL(_BufCpy)
RET
.end
.end
Re: [TI ASM] Reading the Ans Variable
Posted: Wed 10 Mar, 2010 5:21 pm
by King Harold
D and A are both "garbage" now
IOW you're skipping a ConvOP1
Re: [TI ASM] Reading the Ans Variable
Posted: Wed 10 Mar, 2010 6:23 pm
by Matthias1992
YES! I finally got it to work!! Thank you very much for your help! Sure there is no reason why to point IY to flags and I bet there might be more optimizations but for now, I am too damn glad to take the effort to correct them!
Code: Select all
.nolist
#include "ti83plus.inc"
#define ProgStart 9D95h
.list
.org ProgStart -2
.db t2ByteTok, tAsmCmp
LD HL, 0
B_CALL(_ZeroOP1)
LD A, 'X'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;L
B_CALL(_ZeroOP1)
LD A, 'Y'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;H
B_CALL(_ZeroOP1)
LD A, 'P'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
PUSH AF ;E
B_CALL(_ZeroOP1)
LD A, 'Q'
LD (OP1+1), A
B_CALL(_RclVarSym)
B_CALL(_ConvOP1)
LD D, A
POP AF
LD E, A
POP HL
POP AF
LD L, A
LD IY, flags
res plotLoc, (IY+plotFlags)
B_CALL(_FillRect)
RET
.end
.end
Re: [TI ASM] Reading the Ans Variable
Posted: Wed 10 Mar, 2010 7:05 pm
by King Harold
Grats
Do you need more help optimizing it?
Re: [TI ASM] Reading the Ans Variable
Posted: Wed 10 Mar, 2010 7:13 pm
by Matthias1992
Well, Any help is more then welcome!