Re: LZ: Me agian Same Problem
[Prev][Next][Index][Thread]
Frank wrote:
>
> can u explain what push and pop do ?
>
> ----------
> From: owner-list-zshell@lists.ticalc.org on behalf of barrym
> Sent: Thursday, September 26, 1996 7:05 PM
> To: Zshell
> Subject: Re: LZ: Me agian Same Problem
>
> On Thu, 26 Sep 1996, Frank wrote:
>
> > Well i still cannot figure out why the program (etch a sketch ) has this
> > bug... the bug is that it will only draw a few pixels to the left (but as
> many
> > as wanted to all other directions).... the only thing i noticed is that
> maybe
> > the problem comes into play b/c left: is the last of the directional labels
> > here is the new code... if anyone sees the problem let me know thanx...
>
> Youre not doing anything to retain the values in b and c.
> Your rom calls probably are clobbering them,
>
> Try pushing them before a rom call and popping them aftward,
> like this:
>
> push bc
> rom_call(xxx)
> pop bc
>
> But really the best solution if youre gonna add to the program is to
> store them in memory and free up bc for other stuff you'll need it
> for.
>
> Barry
> > #include "ti-85.h"
> > .org 0
> > .db "By Frank Apap",0
> >
> > Init:
> > ld a,4
> > out (5),a
> > ROM_CALL(CLEARLCD)
> > ld b,40 ; x start
> > ld c,40 ; y start
> >
> > Start:
> > call GET_KEY ; get a key
> > cp K_UP
> > CALL_Z(up)
> > cp K_DOWN
> > CALL_Z(down)
> > cp K_LEFT
> > CALL_Z(left)
> > cp K_RIGHT
> > CALL_Z(right)
> > cp 0F
> > JUMP_Z(clear)
> > cp $37
> > JUMP_Z(exit)
> > jr Start
> > up:
> > inc c ; x=x+1
> > CALL_(PlotPixel) ; draw it
> > ret
> >
> > down:
> > dec c ; x=x-1
> > CALL_(PlotPixel)
> > ret
> >
> > right:
> > inc b ; y=y+1
> > CALL_(PlotPixel) ; draw it
> > ret ; go back
> >
> > left:
> > dec b ; y=y-1
> > CALL_(PlotPixel) ; draw it
> > ret ; Maybe this is wrong? not sure
> > clear:
> > ROM_CALL(CLEARLCD)
> > JUMP_(init)
> >
> > PlotPixel:
> > ROM_CALL(FIND_PIXEL)
> > ld de,$FC00
> > add hl,de
> > or (HL)
> > ld (HL),a
> > ret
> >
> > exit:
> > ROM_CALL(CLEARLCD)
> > ld hl,$1A1A
> > ld ($8333), hl
> > ld hl, (PROGRAM_ADDR)
> > ld de,bye
> > add hl,de
> > ROM_CALL(D_ZM_STR)
> > exitloop:
> > call GET_KEY
> > cp $37
> > ret z
> > jr nz,exitloop
> >
> > bye: .db "BYE THANKS FOR TESTING",0
> > .end
> >
> >
push and pop use the stack to store variables for a short time. The stack? It's a
place in memory right before the video memory. When you store stuff there the stack
pointer, or register SP, is decremented to hold the new data. Think of it as a tight
stack of paper. You can easily put a new piece of paper on top, and also take one off.
But it's hard to put or take something out of the middle of the stack. same in asm.
To use it :
push hl ;pushes hl to the top of the stack
... ;more instructions, or ROM_CALL
pop de ;pops the last two bytes off of the stack, even
;though hl was put there, you can pop it into another register
By the way, this only works for two-byte registers, if you want to push A, go
push af ;f is the condition byte, holds carry flag z flag, n, p...
Lastly, be sure you pop what ever you push, or else the return to zshell will ceratinly
crash. and only pop what you have pushed.
<pre>
--
Compliments of:
_-_-_-_-_-_-_-_
Alan Bailey
mailto:bailala@mw.sisna.com
IRC:Abalone
Web:http://www.mw.sisna.com/users/bailala/home.htm
</pre>
References: