print at x,y equivalent

SYS 64738
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

print at x,y equivalent

Post by Shaun_B »

Here's a quick example of how to do print to position x, y in basic:

Code: Select all

0 x$="{home}{right*39}":y$="{down*24}"
10 x=10:y=7: rem x is across and y is down
20 print left$(x$,x)right$(y$,y)"hello";
Please note that you are not able to print to the last character of the screen without forcing a new line. If you want a character to be written to the last screen position, you'll need to poke it there, like poke 2023,81 - I don't know if there's an advanced trick in basic that will stop a new line when printing to the last character position. Someone here may be able to answer that.

Regards,

Shaun.


BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: print at x,y equivalent

Post by Shaun_B »

I think I got the logic the wrong way around, I think it should be printing {home} first, then down, then across.

Anyway, try it and see what happens.

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
ajordison
Developer
Developer
Posts: 59
Joined: Wed Apr 16, 2014 1:28 pm
Location: Hartlepool, UK
Contact:

Re: print at x,y equivalent

Post by ajordison »

Or you can try this:

Code: Select all

10 print "{clear}"
20 row = 5:col = 10:gosub 1000
30 print "hello"
40 row = 6:col = 10:gosub 1000
50 print "world"
60 end
1000 poke 780,0
1010 poke 781,row
1020 poke 782,col
1030 sys 65520
1040 return
The sys call sets the screen cursor position.
Try out CBM prg Studio for all your Commodore development needs!
Stay a while...stay for erm quite a while!
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: print at x,y equivalent

Post by Shaun_B »

Out of interest, which would be faster out of the two methods? That's more of interest to me.

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
ajordison
Developer
Developer
Posts: 59
Joined: Wed Apr 16, 2014 1:28 pm
Location: Hartlepool, UK
Contact:

Re: print at x,y equivalent

Post by ajordison »

I'd say that the sys call is quicker (not because it's my suggestion!) because the left and right string operations are very expensive, processor-time wise. No doubt I'll get shot down in flames (oh hang on, wrong forum ;) )
Try out CBM prg Studio for all your Commodore development needs!
Stay a while...stay for erm quite a while!
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: print at x,y equivalent

Post by Shaun_B »

But are you including the overheads of the gosub, pokes and return? With the left$...right$..."blah" you're doing everything on one line so I would have thought that would be quicker...? I'll have to see which it is.

If I'm ever in the North East again, I'll nudge you and we'll have a pint and mull over some Commodore, eh?

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
ajordison
Developer
Developer
Posts: 59
Joined: Wed Apr 16, 2014 1:28 pm
Location: Hartlepool, UK
Contact:

Re: print at x,y equivalent

Post by ajordison »

You might be right. wrap it up in a timer and call it 1000 times.
If I'm ever in the North East again, I'll nudge you and we'll have a pint and mull over some Commodore, eh?
Good idea! We can cry into our beer together...
Try out CBM prg Studio for all your Commodore development needs!
Stay a while...stay for erm quite a while!
satpro

Re: print at x,y equivalent

Post by satpro »

ajordison wrote:You might be right. wrap it up in a timer and call it 1000 times.
If I'm ever in the North East again, I'll nudge you and we'll have a pint and mull over some Commodore, eh?
Good idea! We can cry into our beer together...
I think you guys drink too much.
ajordison
Developer
Developer
Posts: 59
Joined: Wed Apr 16, 2014 1:28 pm
Location: Hartlepool, UK
Contact:

Re: print at x,y equivalent

Post by ajordison »

pots and kettles...
Try out CBM prg Studio for all your Commodore development needs!
Stay a while...stay for erm quite a while!
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: print at x,y equivalent

Post by Shaun_B »

Hi Bert, you say we drink too much but then I hear that you can't have too much of a good thing... so who is right?

AJordison, I'll do some testing later. Unfortunately I was woken up early this morning by my daughter so I'm not braining very well at the moment.

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 7 guests