Author: chickendude
Posted: 10 Dec 2012 05:27:18 pm (GMT -5)
Oops, i got sidetracked and forgot to post the code:
Code:
The main changes are:
1. I removed the call to draw from the dot-moving routines and put it at the end of the Erase routine.
2. I combined the Draw and "Erase" (i called it unDraw since you already had a label called Erase) routines.
3. I moved the coordinates so that they are loaded directly (through SMC) into b and c.
You also didn't need the push/pop around the last check (up) since a no longer needs to be preserved.
Posted: 10 Dec 2012 05:27:18 pm (GMT -5)
Oops, i got sidetracked and forgot to post the code:
Code:
Init:
bcall(_grbufclr) ;So the graph buffer doesnt leave any "ghost pixels"
res indicRun, (IY + indicFlags) ;So the run indicator is off
set fullScrnDraw, (IY + apiFlg4) ;So we can use last column/row
bcall(_clrLCDfull)
call Draw ;So the point will be drawn before the user presses anything
Loop: ;Loop until a key is pressed, then respond accordingly
ld a,%11111101 ;If Clear or Enter, end the program
out ($01),a
in a,($01)
rra
jr nc,Stop
cp %10111111>>1 ;shifted over 1 for the rra
jr z,Stop
ld a,%11111110 ;If an arrow key...
out ($01),a
in a,($01)
cp $FF
call nz,Erase
jr loop
Erase:
;Erase the point at the previous coordinates
call unDraw ;"Erase" was already taken :P
;Go to the appropriate coordinate-changing label
rra
push af
call nc,down
pop af
ld hl,X_COORD ;both left and right use X_COORD, so we can preload it
rra
push af
call nc,left
pop af
rra
push af
call nc,right
pop af
rra
call nc,up
;instead of a ret, we will draw the dot now and use the ret of Draw to return from the subroutine
Draw: ;Redraw the point at the new coordinates
ld d,1
X_COORD = $+1 ;this points to the second byte of the opcode ld b,47, which happens to be the 1-byte integer loaded into b
ld b,47
Y_COORD = $+1 ;again, this will change the byte loaded into c
ld c,31
bcall(_Ipoint)
ret
unDraw: ;drawing and erasing use almost the exact same code, we'll take advantage of that
ld d,0
jr Draw+2 ;+2 to skip the ld d,1
Stop:
bcall(_clrLCDfull)
ret
;hl = address of X_COORD
Left: ;Move point left by one pixel if not at the left screen edge
ld a,(hl)
or a
ret z ;if X_COORD = 0, quit
dec (hl)
ret
;hl = address of X_COORD
Right: ;Move point left by one pixel if not at the right screen edge
ld a,(hl)
cp 95
ret nc
inc (hl)
ret
Up: ;Move point left by one pixel if not at the top screen edge
ld hl,Y_COORD
ld a,(hl)
cp 63
ret nc
inc (hl)
ret
Down: ;Move point down by one pixel if not at the bottom screen edge
ld hl,Y_COORD
ld a,(hl)
or a
ret z
dec (hl)
ret
The main changes are:
1. I removed the call to draw from the dot-moving routines and put it at the end of the Erase routine.
2. I combined the Draw and "Erase" (i called it unDraw since you already had a label called Erase) routines.
3. I moved the coordinates so that they are loaded directly (through SMC) into b and c.
You also didn't need the push/pop around the last check (up) since a no longer needs to be preserved.