[TI-Z80] howto: properly implement a teacher key

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

[TI-Z80] howto: properly implement a teacher key

Post by driesguldolf »

The easiest way to implement this I tought was to have your own costum interrupt and in that interrupt poll the keypad and if [del] (or any other key) is pressed quit.

This worked fine untill I started to get Odd bugs:
blox is a tilemapped game and whenever the xpos of the screen (the map is larger than the display) is odd TI crashes when del is pressed... (the app exits properly but ti crashes)

Is it correct to assume that the stack level doesn't matter when B_JUMP(_jforcecmdnochar)?
Is it neccesary to properly finish the interrupt before exiting the isr?
This crash does not appear when in the mainloop I do:

Code: Select all

   cp skclear
   jp z, exitapp
or could it be a problem with isr deinitializing:

Code: Select all

   ld a, %00001000
   out (3), a
	ld a, %00001010
	out (3), a
	ld a, %00000110
	out (4), a
	exx
	ex af, af'
	ei
	ret
Speaking of the last, Jim e, it crashes when the isr is active and you pull the cable connecting the computer and calc, I know it's because I output the wrong bytes, I've checked wikiti and I get the idea that you have to ouptut bytes depending on what caused the interrupt?

Any ideas?
Last edited by driesguldolf on Fri 27 Jul, 2007 6:17 pm, edited 1 time in total.
User avatar
calc84maniac
Regular Member
Posts: 112
Joined: Wed 18 Oct, 2006 7:34 pm
Location: The ex-planet Pluto
Contact:

Post by calc84maniac »

Try putting it back into IM 1 before exiting.
~calc84maniac has spoken.

Projects:
F-Zero 83+
Project M (Super Mario for 83+)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

I can't imagine an interrupt being the simplest way to implement a teacher key..
Why do you not just poll it in your game's keyhandler? Interrupts can sure be useful, but imo they're a pain to program. Not to mention the 257 bytes of RAM it takes up.

Also, don't BJUMP(_JForce whatever) from a RAM program, no really - don't. So I hope this is an app?

If not, try this somewhere

Code: Select all

ld (spsave),sp
;some code
exit:
spsave = $+1
ld sp,0
ret
I'm not sure about weird link problems though (Jim E knows - it's hardware related so he probably knows everything about it)


ps: @calc84maniac's sig: RETI and RETN return (like ret) but also mess with the IFF's, you probably won't need RETI and you will never need RETN since NMI's are not enabled on TI's.
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

@calc84maniac: yup, I do that already

@King Harold:
I need an isr anyway so it's always enabled, I'll try it trough the keyhandler, that might solve the problem.
Yup it's an app
I've tried messing with sp before quiting, it 'seems' (not sure) that the sp doesn't need to be preserved.
If it's not a personal problem (my calc weirding out or something) then wikiti is wrong too, as this is exact the same as wikiti.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

I think in most games it should work with the normal keychecking code.. Afterall, most games either wait for a keypress (if they are turn based for example) or check keys often (otherwise real-time games would be unresponsive)

Since it's an app, don't worry too much about SP. I'm not sure but I think you could do pretty much anything with it.

Just out of curiosity: what do you need the ISR for? Timing?
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

Because I like control, I like to fully control All the aspects of the program, and it provides some neat stuff

I have 2 timers (an 8 bit and a 16 bit), I use them to vsync the game and time events, I have 2 timers because weird things happend with the 8bit one if used for vsync (don't ask...)

I used to have a teacher key there (I'm glad that the one inside the key handler works...:))

For more control, I have an empty call there, and thus if any of the games (puzzle action, you know the one I'm making) needs additional timed events I can simply overwrite the address it calls

And ofcourse, it allows the arrow keys to repeat (first theres a large delay then a short one) because I think for games the standard large key delay is way to slow.
As an additional feature you can change any of the delays (standard 25 for largekeydelay, 15 for shortkeydelay)

Code: Select all

; If no arrow key is pressed, reset the timer to 'longkeydelay'
; Else decrement the timer,
; If it hits zero clear (lastkey) and reset the timer to 'shortkeydelay'
	ld a, (lastkey)
	or a
	jr z, {+}
	cp 5
	jr nc, {+}		; Only the arrow keys are allowed to repeat
_keytimer	.equ	$ + 1 - interrupt_start + $8888
	ld a, 1
	dec a
	ld (_keytimer), a
	jr nz, {++}
	ld (lastkey), a		; A is zero
	ld a, (shortkeydelay)
	ld (_keytimer), a
	jr {++}
+  ld a, (longkeydelay)
	ld (_keytimer), a
++
Feel free to use :mrgreen:
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Like MOS's fastkey? looks neat :)
You are aware that the lower byte of a 16bit timer is exactly the same as a normal 8bit timer? You probably knew that already but if you overlooked it you can now save a few bytes code and a byte data ;)

Did you know Brass has .relocate? If you use that you won't have to bother with things like " - int_start + $8888" and such.

Code: Select all

Int_Start:  .relocate $8888
;some code
_keytimer = $+1
ld a,1
dec a
;some code
.endrelocate
End_Int:
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

Thanks King Harold, for opening my eyes!

and I did overlooked it...

And I do use the .relocate thingie but I didn't realize it has a .endrelocate! Thanks!
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

Hmmm...Some one assumed I would answer right away, is there still a problem?
Image
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Post by driesguldolf »

Hey Jim e,
Yeah, there is a problem:
a while ago you helped me with proper ending a mode 2 interrupt, the problem is that my calc crashes when you pull the cable while the interrupt is running, it gives similar results as when I outputted the wrong bytes (the interrupts continusly gets called if you do 'ei' causing a stack overflow)
Post Reply