Re: A83: Switching the calculator off


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

Re: A83: Switching the calculator off




>I didn't use any push or pop's (mainly cause I don't understand them).

o ok.... pushes and pops are a big way to save lots of memory in routines
and a good way to keep from doing stupid stuff.
push af ; this pushes af onto the stack
pop af ;this pops the last values put on the stack into af
this can be done with af,bc,de,hl theres also calls to push and pop the OPs

heres one use for the push/pop
 ld hl,sprite
 ld b,14
 ld a,0 ;load the x-coord of the sprite into a
loop:
 ld e,y-coord
 push af ;push whatever is in af onto the stack because the call destroys a
 push bc ;push this too because b and c are destroyed too
 call PutSprite
 pop bc ;pop the last register you pushed first so you dont end up with the
values in the wrong registers
 pop af ;pop the values back into a
 push bc ;push the original loop counter so we dont lose it
 ld b,8
loop2:
 inc a ;increases a 8 times so the next sprite is side by side with the last
one
 djnz loop2
 pop bc ;restore the original loop counter
 djnz loop