Jump to content
Sign in to follow this  
GDMike

KSCAN Examples

Recommended Posts

I have seen so many KSCAN examples but im still having troubles. Sometimes the keys completely become useless and even a reboot doesnt fix it, but actually resetting the computer to run a program that just ran fine with KSCAN but NOT the second time back to back.

ive tried clearing 8374,5 837C on exit, on start..no matter what i try i seem to always have an issue, but not all the time but more than 60 perc of the time.

im usually going to write to the screen straight from a key routine..ive tried saving my R11 on BL routines and that isnt affecting my outcome. ive tried straight thru programming with no BL..still have the same issues. im using a NANO not sure why it would matter..But if someone could post a routine that works for them so i can test against it id appreciate it. thanks, here is a photo of my last kscan use...BTW spaceb was a Data >2000

 

IMG_20190701_215551622.jpg

Share this post


Link to post
Share on other sites
KEYMOD EQU  >8374
KEYVAL EQU  >8375
STATUS EQU  >837C
NOKEY  BYTE >FF
ANYKEY BYTE >20
*
*
*
SCAN   CLR  @KEYMOD
       LIMI 2
       LIMI 0
       CLR  @STATUS
       BLWP @KSCAN
       CB   @NOKEY,@KEYVAL
       JEQ  SCAN
       RT

* or

SCAN   CLR  @KEYMOD
       LIMI 2
       LIMI 0
       CLR  @STATUS
       BLWP @KSCAN
       CB   @ANYKEY,@STATUS
       JNE  SCAN
       RT
       
* call using

       BL   @SCAN

:)

Edited by HOME AUTOMATION
I had listed the same line twice.

Share this post


Link to post
Share on other sites

thank you..a simple thing has turned into a three hr ordeal..yesterday i accomplished a huge amount of progress, but it all got smashed by a bad kscan. some illustrations say put a 5 into 8374 some say clr status and drop out..but  from what i know is that i want it to be a subroutine, i want to be able have different branches for the same key for diff areas within my prog. and i can accomp that by using an index type reg. so i can handle that. i cant wait to try this in its form. ty very much! i wasnt getting anywhere with the crap i had going on.

Share this post


Link to post
Share on other sites

I remember doing a lot of trial and error to get a version than ran in Forth to my liking.

Here is my latest which test for a keystroke and moves it on the top of the Forth stack (cached in R4 here, called TOS) if a key-press is detected.

 

It shows how to use BL to call KSCAN by manually changing work-spaces to GPL and back to Forth. (In case it might be useful to someone)

Like FBForth, Camel99 runs with interrupts on so I only disable them while in the KSCAN routine.

 

Put your Yoda ears on when you read it and it makes more sense. 🙂

 

FYI:  The NE IF, line assembles the instruction   JEQ ENDIF

 

Edit:

I know about my terrible heresy, reading >8374 with MOV instead of MOVB but it works and I don't need to SWPB to put the character on the correct side for Forth to work with it

 

CODE: KEY? ( -- ?)  \ *WARNING* it takes 1,128uS for KEY? scan to run
            TOS PUSH,
            TOS CLR,            \ TOS will be our true/false flag
            0 LIMI,
            83E0 LWPI,          \ switch to GPL workspace
            000E @@ BL,         \ call ROM keyboard scanning routine
            8300 LWPI,          \ return to Forth's workspace , interrupts are restored
            2 LIMI,
            837C @@ R0 MOVB,    \ read GPL status byte (=2000 if key pressed)
            NE IF,
                8374 @@ TOS MOV, \ read the key
            ENDIF,
            NEXT,               \ return
            END-CODE

 

Edited by TheBF
Clarification
  • Thanks 1

Share this post


Link to post
Share on other sites
45 minutes ago, TheBF said:

I know about my terrible heresy, reading >8374 with MOV instead of MOVB but it works and I don't need to SWPB to put the character on the correct side for Forth to work with it

 

Not that it matters here, but I do not think this will work for >8374 set to keyboard = 1 or 2 because >8374 is only reset to 0 by the console ROM’s keyboard scanner following setting >8374 to keyboard = 3, 4, or 5 and, of course, untouched if set to keyboard = 0 (default keyboard indicated at >83C6).

 

...lee

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
50 minutes ago, Lee Stewart said:

 

Not that it matters here, but I do not think this will work for >8374 set to keyboard = 1 or 2 because >8374 is only reset to 0 by the console ROM’s keyboard scanner following setting >8374 to keyboard = 3, 4, or 5 and, of course, untouched if set to keyboard = 0 (default keyboard indicated at >83C6).

 

...lee

I only read 8374  (16 bits) when the status byte is non zero so I don't think I need to care if >8374 is reset to zero by the system?

 

A bigger question is that I just plugged a bunch of different byte values into >83C6 and I don't see a difference in my keyboard values.

Edit: I can see a difference.

Maybe I have to do it  every time I call KSCAN to get it to change. (?)

 

Ah  yes when I did this 

: KEYTEST   1 83D6 C!  KEY ;

I got difference values for control keys. So I will do some further testing to understand if my heresy can stand the inquisitional rigor of Atariage. 🙂

 

And still I am learning 

Edited by TheBF
  • Thanks 1

Share this post


Link to post
Share on other sites

After learning more about the TMS9900 architecture, I somewhat started to dislike MOVB and the other byte commands. MOV is OK, as long as you what what you are doing. :)

 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, TheBF said:

I only read 8374  (16 bits) when the status byte is non zero so I don't think I need to care if >8374 is reset to zero by the system?

 

A bigger question is that I just plugged a bunch of different byte values into >83C6 and I don't see a difference in my keyboard values.

Edit: I can see a difference.

Maybe I have to do it  every time I call KSCAN to get it to change. (?)

 

Ah  yes when I did this 

: KEYTEST   1 83D6 C!  KEY ;

I got difference values for control keys. So I will do some further testing to understand if my heresy can stand the inquisitional rigor of Atariage. 🙂

 

And still I am learning 

 

Re >83C6:  Unless you never plan to use the console ROM’s KSCAN, I would not ever set the byte at >83C6.  That is for KSCAN to keep track of the “default” keyboard. It only gets changed when KSCAN detects a 3, 4 or 5 in the byte at >8374. When that happens, KSCAN effectively subtracts 3 from it, stores that value at >83C6 for future keyboard restoration to this new default and zeroes >8374. The next time KSCAN is run and detects 0 at >8374, it checks >83C6 to set the default keyboard to 3 (standard TI-99/4 keyboard scan), 4 (Pascal keyboard scan) or 5 (Basic keyboard scan).

 

Re reading word at >8374 to read new character into LSB in one operation:  The status byte’s COND bit is set for keyboards 1 (left half) and 2 (right half) when a key is struck, just as it is for keyboards 3, 4 and 5. But for keyboards 1 and 2, you will have a value greater than >FF for your new character value you store in TOS, viz., >01xx or >02xx, not >00xx as you expect because the byte at >8374 does not get zeroed. Your ruse only works for full keyboard scans (0 [default], 3, 4 and 5).

 

...lee

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

I am laughing out loud regarding your use of the word "ruse".😃

Excellent. If the shoe fits I guess.

 

Thanks as always for the extremely lucid description.

What with Flat earth advocates and Moon Landing deniers I may have to re-consider my options lest my ruse be lumped together with that lot. 🙂

 

0xBF

  • Like 1
  • Haha 1

Share this post


Link to post
Share on other sites
On 7/2/2019 at 12:43 AM, GDMike said:

thank you..a simple thing has turned into a three hr ordeal..yesterday i accomplished a huge amount of progress, but it all got smashed by a bad kscan. some illustrations say put a 5 into 8374 some say clr status and drop out..but  from what i know is that i want it to be a subroutine, i want to be able have different branches for the same key for diff areas within my prog. and i can accomp that by using an index type reg. so i can handle that. i cant wait to try this in its form. ty very much! i wasnt getting anywhere with the crap i had going on.

i was easily able to make this work, it was very similar to what i had been experimenting with..and the key selection worked, but my next command, a BL @cls did not, or sorta kinda did..

i selected key 1 to take me to a cls and only part of the screen cleared..apparently it does not like my mov R11,@Savrtn command because i got rid of my BL @cls and just went straight to a clear screen..too bad..but apparently it was NOT my kscan all along..but my returning R11..#$#@

----

SAVRTN DATA 0

...

then i start a BL routine with:

mov R11,@savrtn

and end with

mov @Savrtn,R11

RT  *R11

im sure i tried B *R11 as well but i could try it again...and 5 mins. later, none of those worked..well ay least i now know why half of my sub programs arent working, as my sound routine works once and no more after calling it as well. so until i can wrap my head around the R11 rt, or RTWP or B *R11 ill just write straight thru code.

 

15621842355571731365862.jpg

Edited by GDMike

Share this post


Link to post
Share on other sites

Do you have a LWPI in your program?

 

Normally you don't need one because when started from E/A your program has WP = 20BA

Essentially "Load and Run" has already done this for you:

   LWPI >20BA


For instance you could do,

MYWS  BSS 32

START  LWPI MYWS
       LIMI 0

This will make your program's registers reside in MYWS which you own.     It's a good practice, to have your program to set up things for itself. (It might be launched from DM1000 for example)

 

What you should never have is LWPI >83E0  or LWPI GPLWS  if you are going to use KSCAN. They will fight.

 

 

Here is the source to the E/A version of KSCAN. It actually is polite enough to save R11, though it will .

GPLWS  EQU >83E0
UTLWS  EQU >2094
KSCAN0 EQU >21DE
KSCAN  DATA UTLWS,KSCAN0

KSCAN0
   LWPI GPLWS              Set WS = GPLWS
   MOV  R11,@UTLWS+22      Save the GPLWS R11 by putting it in our R11, haha
   BL   @SCAN              BL uses R11 of GPLWS
   LWPI UTLWS              Set WS = our WS
   MOV  R11,@GPLWS+22      Restore GPL's R11              
   RTWP  

 

 

 

Share this post


Link to post
Share on other sites

ok, now it works...why..let me take a look at why..oh i added LIMI 0

earlier i had Limi 2 limi 0

so after i couldnt get a change i then removed it altogether and got further than i was getting with half a screen getting cleared...lol

i had a routine that included a sound table and it would always work once but never twice, so i found a GPLlnk routine to make a beep.. (since im hitting numbers at a menu i wanted a beep).

and the GPLlnk routine always worked. now maybe i can try my sound table all over again.

i call this progress...but one day ill figure out my addresses that perform those basic functions without the use of Defs..

i know thats the best route, and i use to try to include those, but as soon as i started losing WP info i went back to the basics to attempt to get things in a staggering forward direction as to where i was, a drunkard Hobo looking for a bottle..

 

Edited by GDMike

Share this post


Link to post
Share on other sites

thank you all so much!!! im making lots of progress on my little routine and its never run so smoothly! i dont even have to make more than one Kscan type of subr. everything i BL to actually comes back..im thrilled.

Edited by GDMike
  • Like 4

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...