Jump to content
  • 2
geek504

BASIC Command: Position the Cursor

Question

Posted (edited)

I read the KERNEL-BASIC documentation and have not found a command to be able
to position the text cursor (same as LOCATE in MS-Basic or HTAB and VTAB on the Apple ][).

C64 BASIC solves this problem with the never-ending POKE hacks:

June 1992 issue of COMPUTE
Magazine, Gazette edition! (page G-24, "Programmer's Page" column)

POKE 211,C (moves cursor to specified Column, 0-79)
POKE 214,R (moves cursor to specified Row, 0-24)

BUT you must PRINT a carriage return after that, or the ($D1) and
($F3) pointers won't be changed. So, that's why you must make:

POKE 214,(R-1)AND255:PRINT:POKE 211,C

Yuck!

Edited by geek504
  • Like 1

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

There is a better way, using the Kernal from BASIC. You can set register values starting at $030C: A,X,Y,P.

So, you can set X by poking to $30D, and Y by poking to $30E. Then you can call PLOT by jumping to $FFF0.

This code will plot "HELLO, PLOT!" to row 30, column 40:

10 POKE $30D,30

20 POKE $30E,40

30 SYS $FFF0

40 PRINT "HELLO, PLOT!"

 

Share this post


Link to post
Share on other sites
  • 0
3 hours ago, SlithyMatt said:

There is a better way, using the Kernal from BASIC.

I was just giving feedback on improvements to BASIC since the dev people were asking 🙂 LOCATE would be cool.

MOD is another one:

A-INT(A/B)*B

Can't help shudder at the wasted CPU cycles...

 

Share this post


Link to post
Share on other sites
  • 0

I have another way of doing it, as well as some code that seems to be working for me so far:

10 REM //SUBROUTINE - LOCATE
11 REM // CALL BY SET LY LX AND GOSUB
12 POKE $30D,LY% : POKE $30E,LX% : SYS $FFF0
13 RETURN
	
Edited by Starsickle
Looks better.

Share this post


Link to post
Share on other sites
  • 0

On the C64, VIC-20, and PET -- and probably on the other machines as well -- you could POKE straight to screen memory.  Which I never did, because I didn't like it, but it was available.  I guess we can VPOKE to VERA.

There is SPC(X), which might be similar to HTAB.

You might also not know about the Commodore cursor character codes.  It ain't pretty, but sometimes they're useful.  That would be one way of simulating a VTAB... poorly.  Tom shared one of those hacks recently:

VV$="{down}{down}{down}{down}... (about 25 times)"
({down} is the printable representation of cursor-down...
...which isn't printable on ASCII)

Then:
? "{home}" LEFT$(VV$,Y)

Gets you to the Y-th row.
	

Hmm, we could probably do a DEF FN that simulates a VTAB.

 

Now if you don't want to trigger BASIC 2.0's Maladjusted Garbage Collector, you'll need to be more creative.

 

Okay, FINE, I'll put a feature request in github for something like BASIC 4.0 string handling.  But it doesn't sound easy.

 

...and I see that Michael has already put this on the request list.  Back in July: https://github.com/commanderx16/x16-rom/issues/155

 

 

Edited by rje

Share this post


Link to post
Share on other sites
  • 0

One thing I should mention is if you make the first character of VV$ {home}, you can just PRINT LEFT$(VV$,Y);. If Y is 1, this will place the cursor on the top row by just printing the HOME. 

Yes, we badly need LOCATE, MOD, and HEX$. 

Share this post


Link to post
Share on other sites
  • 0

Is there any possibility to extend the BASIC Opcode in RAM (so user defined basic commands if you want to name it that way)?

I am just asking because I learned today, that the Schneider CPC hat this possibility to define the 20 unused Basic Opcodes however you want with normal RAM. 

Share this post


Link to post
Share on other sites
  • 0
3 minutes ago, SerErris said:

Is there any possibility to extend the BASIC Opcode in RAM (so user defined basic commands if you want to name it that way)?

I am just asking because I learned today, that the Schneider CPC hat this possibility to define the 20 unused Basic Opcodes however you want with normal RAM. 

That would be cool BUT since there is no way to know what routines will be implemented by the user, the extended BASIC opcodes will be generic names, e.g. "USER1", "USER2", etc.

Being generic and cryptic, it might as well be a SYS call to the machine code. The only imediate benefit I can see is perhaps the transfer of the resulting value (if it is a function) to a BASIC variable name.

Share this post


Link to post
Share on other sites
  • 0

The C-64 allowed this by hooking into the CHRGET parse routine which was sitting in zeropage RAM so you can modify it to call into your own code to add commands. Most well known are the "DOS-wedge" extensions such as DOS"$    that displays the disk contents without destroying the current program as LOAD"$",8 would do.

I don't know if the basic implementation in CommanderX16's ROM has a similar wedge option?

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, geek504 said:

That would be cool BUT since there is no way to know what routines will be implemented by the user, the extended BASIC opcodes will be generic names, e.g. "USER1", "USER2", etc.

Being generic and cryptic, it might as well be a SYS call to the machine code. The only imediate benefit I can see is perhaps the transfer of the resulting value (if it is a function) to a BASIC variable name.

The way it was implemented on Amstrad was, that you could use any command you like and connect it to one of the 20 unused opcodes. 

You could for instance create a CIRCLE command that draws a circle around any given position and connect it to $20 opcode.

The user Opcodes actually are not standardized and are for users individually. But we could define a user command repository, where you can draw from to use the ones that benefits your program the most. So if you are drawing a lot of circles - that basic command would help, as it speeds up the process massively by implementing a assembler routine for it, but keeps is accessible for BASIC.

Thanks @desertfish , I will look it up.

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
Answer this question...

×   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.


×
×
  • Create New...

Important Information

Please review our Terms of Use