Jump to content
IGNORED

moving screen editor cursor with joystick


OxC0FFEE

Recommended Posts

In a game loop I'm trying to use the stick to move the text-mode cursor in the text window in the easiest, code and cpu-efficient way. Seems like using location 84 and 85 is the way (note: I don't need the high bit, stored in 86, because in text the column will never exceed 40), but the cursor keeps disappearing. I'm assuming when the cursor location is updated using poke, the cursor goes invisible.

 

Things I've tried:

  • Move cursor to new location, poke 752 to turn cursor back on. Doesn't work.

rem get stick position, update posx,posy
...

rem row is 84, column is 85

poke 84,posy:poke 85,posx
poke 752,1

  • print CHR$(29) to print a blank character, has the side effect of showing the cursor, but offset by a row. I need the cursor at the actual cursor location, not one below it.

poke 84,posy:poke 85,posx
print CHR$(29);

Edited by OxC0FFEE
Link to comment
Share on other sites

The problem with the text cursor is that it's only really generated when text is being output.

Simply using POS. or poking in a new set of values isn't sufficient.

If you're dealing with the text window as in 4 lines at bottom of a graphics mode then you're using the wrong locations.

 

656 is text window cursor row.  657,658 is the column.

You might experience annoyances such as cursor remnants being left behind or unwanted scrolling or line insertions.

In a lot of cases you can be better off just calculating and poking in a cursor programatically.

Link to comment
Share on other sites

Sample program.   This shows the problem with putting a generated cursor in the last position, it will force a scroll.

You could always limit to column 38 I guess.  Line 40 is just to print a single inverse space for the cursor.

Uses a special trick also - normally Basic won't let you touch IOCB #0 but if you use #16 it lets you use it (although in this case you could probably just leave the #16 out altogether)

 

10 GRAPHICS 7:POKE 752,1
20 X=20:Y=1
30 POKE 656,Y:POKE 657,X:POKE 658,0
40 ? #16;"{inverse SPACE} ";
50 H=PTRIG(0)-PTRIG(1)
60 S=STICK(0):V=(S=13)-(S=14)
70 IF  NOT (H OR V) THEN 50
80 POKE 656,Y:POKE 657,X:POKE 658,0
90 ? #16;" ";
100 X=X+H:Y=Y+V
110 IF X=1 THEN X=39
120 IF X=40 THEN X=2
130 IF Y=-1 THEN Y=3
140 IF Y=4 THEN Y=0
150 GOTO 30

 

Edited by Rybags
Link to comment
Share on other sites

You could just map joystick axes to the four cursor direction keys and print them to the display. Unless I'm over-simplifying the problem somehow. If you're especially worried about efficiency and don't need the OS screen handler's features, you can just bypass it entirely and manage everything yourself.

 

  • Like 1
Link to comment
Share on other sites

Equally to Ctrl-Tab you can just use 2 x ESC as a non-print character followed by clearing the Esc flag at 658.  Change to code in line 40.

Cursor suppression and printing spaces no longer needed.

This method or Ctrl-Tab as phaeron suggests also gets rid of the scrolling/residual cursor problem.

Actually you could probably rework the whole thing to just use the control arrow as FJC suggests and not worry about tracking the cursor position.

If you need to get the cursor pos you could just read locations 656/657 to get it.

 

 

10 GRAPHICS 7:REM POKE 752,1
20 X=20:Y=1
30 POKE 656,Y:POKE 657,X:POKE 658,0
40 ? #16;"{ESC ESC}";:POKE 674,0
50 H=PTRIG(0)-PTRIG(1)
60 S=STICK(0):V=(S=13)-(S=14)
70 IF  NOT (H OR V) THEN 50
80 POKE 656,Y:POKE 657,X:POKE 658,0
90 REM ? #16;" ";
100 X=X+H:Y=Y+V
110 IF X=1 THEN X=39
120 IF X=40 THEN X=2
130 IF Y=-1 THEN Y=3
140 IF Y=4 THEN Y=0
150 GOTO 30

 

Edited by Rybags
Link to comment
Share on other sites

20 hours ago, OxC0FFEE said:

I'm getting the picture. It might just be easier to poke a fake "cursor" into the right place in the text window. Avoids the needing to tickle the screen editor and the last row/column issue.

That's what I wound up doing. restore last 'under' if any, save what's under new location, place cursor. It ran in a pokey interrupt.

Edited by danwinslow
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...