Author Topic: Controlls script question  (Read 2879 times)

0 Members and 1 Guest are viewing this topic.

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Controlls script question
« on: June 11, 2011, 06:01:16 am »
Currently I'm using the pretty much standart standart way of reacting to input:
Code: [Select]
   b_call _GetCSC
    CP     skDel
    JP     Z, Quit
    CP     skYequ
    JP     Z, presYequ
    CP     skWindow
    JP     Z, presWindow
    CP     skZoom
    JP     Z, presZoom
    CP     skTrace
    JP     Z, presTrace
    CP     skGraph
    JP     Z, presGraph
in a,($04)
bit 3,a
jp z,Quit
However, some things have come to attention when using this, for example that if you press two or more buttons, it won't react (obviously), but when releasing all but one of them, it'll register the remaining key as one press.

The mechanics I'm looking for (but have no idea on how to achieve) is this:
 - register the lást key pressed as a single keypress (for example, let's say we press and hold the '1' button, and then the '2' (so both are being held down now), it performs a 'JumpTo1' script and then a 'JumpTo2' script when 2 is being pressed).
 - the same goes for the other way around, when first pressing and holding '2' and then '1', it performs a 'JPto2' and on the second keypress a 'JPto1'. So a normal 'react-to-2-buttons' script won't work, since the order doesn't matter for that.
 - normally, when holding down 2 buttons and then releasing one, the button still being held down after the other one's released gets counted. However, in this situation you can bash any buttons you want (while still holding down the remaining one) and nothing will count, not on the press or on the release of any buttons. What I'm looking for is a way to still react to those button presses.

This is getting kind of wordy, so let's use an example that'll (hopefully) make clear what I mean:

-We press and hold down '1', now we press and hold '2' (with '1' still down) then release '2' again. The wanted reaction is 'JPto1', then on the second press a 'JPto2', then on the release of '2' another 'JPto1'.

-We hold '1' down and press '2', and now release '1'. The reaction would be 'JPto1' on the first press, 'JPto2' on the second, but NO reaction on the release of '1'. (so it doesn't perform a 'JPto2' twice when pressing '2' and releasing '1').


This may be hard to do using GetCSC, but the problem of trying something involving:
Code: [Select]
   LD     A, %10111111
    OUT    (1), A
    IN     A, (1)
    CP     %11101111
    Call     Z, yequsprshow
is that the script gets excecuted continously. I already have a solution for that (thanks to Axe) but I'd still not know how to use that for the behaviour described above.


Sorry for this lòng explanation.
If anyone has any tips or tricks on how to do such mechanics, it'd be greatly appreciated! Note that I'm not asking for a complete script for this of course (though feel free  ;)); some waypoints and tips are very welcome!
Thank you in advance.
« Last Edit: June 11, 2011, 08:11:16 am by Jerros »


79% of all statistics are made up randomly.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Controlls script question
« Reply #1 on: June 11, 2011, 09:12:22 am »
Welcome back Jerros!

The solution is actually easier than you think
Code: [Select]
ld a, $BF
out (01), a

ld a, (keyStates) ;for our case, this is a better option
ld b, a ;than just putting nop \ nop
ld c, 0

;b is what was pressed last loop
;c is what is pressed this loop


in a, (01)

;bits 0 to 4 are:
;graph, trace, zoom, window, y=

rrca
call nc, graphPressed
rrca
call nc, tracePressed
rrca
call nc, zoomPressed
rrca
call nc, windowPressed
rrca
call nc, yEquPressed


ld a, c
ld (keyStates), a

jp anywhere



graphPressed:
push af

set 0, c ;graph is pressed this time
bit 0, b
jr nz, graphIsHeld


;do stuff here for graph is being pressed
;remember not to kill bc

jr graphDone

graphIsHeld:

;do stuff here for graph is being held
;again, don't kill bc

graphDone:
pop af
ret

So the general idea here is just to call a subroutine for each key. That subroutine will handle what needs to be done, and it will return so the rest of the keys can be checked. I also did a clever thing with BC there because unlike getCSC, using direct input like this will report the keys ever frame, not just when they're pressed. So when a key is pressed, checking the state of B, you can see whether it is being held, or is being pressed.

With this routine, you can finally implement both held notes and chords.  :D
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Controlls script question
« Reply #2 on: June 11, 2011, 10:04:06 am »
Wow, that routine is awesome. :D

Thepenguin, I check the asm help topics all the time because I learn from them, and this is a great example of that.  That routine is awesome. :D

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Controlls script question
« Reply #3 on: June 11, 2011, 11:26:35 am »
I was pretty proud when I thought about using BC like that. This is probably one of the best/simplest keycheckers I've made.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Jerros

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 137
  • Rating: +9/-0
    • View Profile
Re: Controlls script question
« Reply #4 on: June 12, 2011, 06:38:23 am »
Wow, incredibly smart! :O I'll probably have to redo a huge part of how the programm works now, but in the end the controlls should be sóó much better when using this (and manage to get it working >.>), thank you!


EDIT: it works... sort of. It just keeps reacting when a button's being held down, rather than performing the 'do stuff here for graph is being pressed' once.
Never mind that, was killing BC.  *derp* It seems to work properly now, all that's left is to create something that does what I want with it.
« Last Edit: July 03, 2011, 04:12:42 pm by Jerros »


79% of all statistics are made up randomly.