Author: chickendude
Posted: 11 Nov 2012 08:21:25 am (GMT -5)
I just sent it to my calc (84+SE OS 2.43 and 83+ OS 1.19) and it works just fine.
As for optimizations and tips, like Kerm said it really would be better to save the coordinates in saferam or put some empty space in your program (.db 0) to store them to, or even better use SMC to load them directly into the location you plan to use them, as using a register to keep track of them, especially when you already are limited to 7 (and ix/iy/sp, but those are kinda "special"), will just complicate things as your program grows. You could maybe get away with using the shadow registers to store them if you disable interrupts and don't plan on using them yourself.
Another thing is you have every bcall(_IPoint) in each individual label, you might be able to fit it into the main loop.
EDIT: Here's some code you can play around with that uses a safer way of keeping track of your X/Y positions and also removes all the extra BCALLs. What it does is store the offset in de, d = X offset (1, 0, or -1) and e = Y offset (1, 0, -1). Note however that if you have -1 in e, de will equal $00FF, or 255 (NOT -1) so you need to change d to $FF also so that de = -1, $FFFF.
Also note the ld hl,updateCoords \ push hl. When you ret, you really take the last value on the stack and load that into the pc. So instead of all of those jr/jp's you can now use rets, but be careful because if you jump back to loop without first popping that value you will eventually fill up the entire stack and start running into outside memory or end up jumping places you don't want to![Wink]()
Code:
Posted: 11 Nov 2012 08:21:25 am (GMT -5)
I just sent it to my calc (84+SE OS 2.43 and 83+ OS 1.19) and it works just fine.
As for optimizations and tips, like Kerm said it really would be better to save the coordinates in saferam or put some empty space in your program (.db 0) to store them to, or even better use SMC to load them directly into the location you plan to use them, as using a register to keep track of them, especially when you already are limited to 7 (and ix/iy/sp, but those are kinda "special"), will just complicate things as your program grows. You could maybe get away with using the shadow registers to store them if you disable interrupts and don't plan on using them yourself.
Another thing is you have every bcall(_IPoint) in each individual label, you might be able to fit it into the main loop.
EDIT: Here's some code you can play around with that uses a safer way of keeping track of your X/Y positions and also removes all the extra BCALLs. What it does is store the offset in de, d = X offset (1, 0, or -1) and e = Y offset (1, 0, -1). Note however that if you have -1 in e, de will equal $00FF, or 255 (NOT -1) so you need to change d to $FF also so that de = -1, $FFFF.
Also note the ld hl,updateCoords \ push hl. When you ret, you really take the last value on the stack and load that into the pc. So instead of all of those jr/jp's you can now use rets, but be careful because if you jump back to loop without first popping that value you will eventually fill up the entire stack and start running into outside memory or end up jumping places you don't want to

Code:
bcall(_ClrLCDFull)
set fullScrnDraw, (IY + apiFlg4) ;So we can use last column/row
ld a, kUp
jp prog
loop:
bcall(_GetKey)
prog:
cp kEnter ;End if Enter or Clear is pressed
jp z,End
cp kClear
jp z,End
ld hl,updateCoords
push hl
ld de,$0000 ;initiate de to 0. d will be added to the Y value, e will be added to
ld hl,X
cp kLeft
jp z,Left
cp kRight
jp z,Right
dec hl ;now points to "Y"
cp kUp
jp z,Up
cp kDown
jp z,Down
ret
Left: ;Move dot left by one pixel if not at the left screen edge
ld a,(hl)
or a
ret z ;quit if X = zero
dec d ;d = -1
ret
Right: ;Move dot right by one pixel if not at the right screen edge
ld a,(hl)
cp 95
ret z ;if (X) = 95, we'll jump to updateCoords leaving d at 0 (which won't change the coordinate)
inc d ;d = 1
ret
Up: ;Move dot up by one pixel if not at the top screen edge
ld a,(hl)
cp 63
ret z
inc e ;e = 1
ret
Down: ;Move dot down by one pixel if not at the bottom screen edge
ld a,(hl)
or a
ret z ;quit if Y = 0
dec e ;
dec d ;de = -1 ($FFFF)
ret
updateCoords:
Y = $+1
X = $+2
coords = $+1
ld bc,$2F1E ;Initialize pixel coordinates at (47, 30)
ld l,c
ld h,b
add hl,de ;update the coordinates (offset in de)
ld (coords),hl
ld d,0
bcall(_IPoint)
ld c,l
ld b,h ;the new coordinates
inc d ;d = 1
bcall(_IPoint)
jr loop