X and Y axis. Printing Sinclair BASIC

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
PeterJ
Site Admin
Posts: 6878
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

X and Y axis. Printing Sinclair BASIC

Post by PeterJ »

Does anyone know why Sinclair went against the accepted standard of X & Y coordinates when creating the BASIC PRINT AT X,Y?

Thanks
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Well...
PCs GW Basic BASICA's LOCATE have the same syntax
LOCATE [row][,[col]
40 LOCATE 5,1: PRINT 55
Moves the cursor to line 5, column 1
is the same as PRINT AT 5,1;55
why the reason? good question
Mad Fritz
Dizzy
Posts: 59
Joined: Wed Jun 27, 2018 1:21 pm

Re: X and Y axis. Printing Sinclair BASIC

Post by Mad Fritz »

My guess: row counting in a text starts from top.
User avatar
TMD2003
Rick Dangerous
Posts: 2043
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by TMD2003 »

The row,column format makes a lot more sense to me when printing on screen. I always think of it as PRINT AT (this number of ENTER characters),(TAB this number);"Text" - and if I'm using variables with PRINT AT, I'll use r and c rather than x and y.

Then, if you want to dig into the QL, there's the CURSOR command, which allows the PRINT position to be anywhere on screen, so you can centre your text perfectly - and that uses the pixel-coordinate grid which is calculated from the top left with x and y coordinates the way round you'd expect. Hence:
MODE 4 - AT #chan,row,col: PRINT #chan,"text" becomes CURSOR #chan,c*6,r*10: PRINT #chan,"text"
MODE 8 - AT #chan,row,col: PRINT #chan,"text" becomes CURSOR #chan,c*12,r*10: PRINT #chan,"text"
I make heavy use of this command any time any time there's centred text involved.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
p13z
Manic Miner
Posts: 611
Joined: Sun Feb 17, 2019 10:41 pm
Location: UK
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by p13z »

Mad Fritz wrote: Sun May 01, 2022 11:17 pm My guess: row counting in a text starts from top.
I'd always assumed this. The PRINT command is for text, it where convention would be "first line / first character" to describe location of a word on a page. We start at the top of a page and read from left to right.
X,Y is convention for graphs, so the graphics commands follow this. Graphs are generally drawn with an origin at the bottom left.
Using PRINT for graphics is just a quirk of the way people (mis/ab)use BASIC.
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: X and Y axis. Printing Sinclair BASIC

Post by 1024MAK »

PRINT in BASIC originally output to either a terminal or a file. A terminal could use a real printer (teletype). Only later was a screen (VDU) used.

Most BASIC versions did not include any command or function to specify which line the output would appear on. To move to a different line you had to move down a line by using PRINT on its own…

The Microsoft BASICs that @zx_if1 mentioned are improved versions of older Microsoft BASICs.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Ok
more older Microsoft Basic?
CP/M's M-Basic use ESCape codes:
sintaxis: PRINT CHR$(27);"Y";CHR$(x+32);CHR$(y+32);....
Mallard Basic use that too
where: 27 = ESC, Y = AT code type, x & y = coordinates +32
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Hi all
I want not to let the subject die, then let's turn it into a comparison
Apple uses two statements instead of one:
VTAB and HTAB
For this purpose Applesoft BASIC has two commands, VTAB (row) and
HTAB (column), which take a row and column to move the cursor to.
So in order to print something starting on third line from top of the screen,
at the leftmost position, you set cursor position with
"VTAB 3 : HTAB 1: PRINT XXX"

What if Sinclair had chosen something similar to this for his Basic?
Mad Fritz
Dizzy
Posts: 59
Joined: Wed Jun 27, 2018 1:21 pm

Re: X and Y axis. Printing Sinclair BASIC

Post by Mad Fritz »

PRINT AT()
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

PRINT AT()
AT...

Ok

The more oldest AT was TRS80 MODEL I LEVEL I BASIC's AT
sintax: PRINT AT nn;text
where nn= 0 to (64*16)-1=1023
Begins print at specified location on Display. Example: 10 PRINT AT 650 "HELLO"

The TRS80 LEVEL II BASIC version was @
now: 10 PRINT @ 650 "HELLO"

Tandy Color and Dragon 32 use @ too
but nn= 0 to (32*16)-1= 511 positions on Display

Laser 200 use P'RINT @ too

what if the speccy had used that version of AT?
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Continuing with the TANDY Color and Dragon 32 PRINT @
I try to convert it to Spectrum as:

1 DEF FN x(x)=INT(x/32): DEF FN a$(x)=CHR$ 22+CHR$ FNx(x)+CHR$ INT(x-32*FN x(x))

Dragon @ example: PRINT @360;"HELLO"
in Speccy: PRINT FN a$(360);"HELLO" - do the same
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Acorn BBC micro

BBC Basic's TAB
sintax: TAB (col {,row})
examples:
10 PRINT TAB(5);"HELLO"
20 PRINT TAB(5,5);"HELLO"
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: X and Y axis. Printing Sinclair BASIC

Post by ZXDunny »

Row, Column is the most common text output coordinate system.

What was more annoying was the inverted y-axis for PLOT/DRAW et al. I know this was because paper graphs generally tend to have their origin at the bottom-right, but as a coder it bugged the hell out of me when the first byte of a display is at the top-left.
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Now is Atari Basic's time

Position
abbrevation: POS.
syntax: POSITION col,row

Example:
10 POSITION 5,5: ?"HELLO WORLD"
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: X and Y axis. Printing Sinclair BASIC

Post by AndyC »

Locomotive BASIC on the Amstrad CPC uses:

LOCATE x,y
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

yeah
Spectravideo 318/328 and MSX the same Amstrad LOCATE too:
LOCATE x, y
but is not the same as Gwbasic LOCATE row, col
but
LOCATE col, row
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

while other BASICs use LOCATE (Microsoft), POSITION (Atari), HTAB and VTAB (Apple), or @ (Dragon)....
Commodore instead chose to use special characters within PRINT to it. Thus, typing:
PRINT"Q equals PRINTCHR$(16) - cursor down
PRINT"] equals PRINTCHR$(29) - cursor right
PRINT"| equals PRINTCHR$(157) - left cursor
PRINT"^ equals PRINTCHR$(145) - cursor up
because I cannot type the real cbm signs I use any aliked

and the other is through POKEs, as we will see below.

POKE(7680+x+y*22),z
The CBM VIC-20 prints the character z on the screen, at positions x,y. Starting with the memory area 7680 through 8185. If an inverse character is desired, simply do z+128.
User avatar
TMD2003
Rick Dangerous
Posts: 2043
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by TMD2003 »

And something I soon found on all the Commies is: the codes to POKE a character to the screen are not the same as the codes required for CHR$...
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: X and Y axis. Printing Sinclair BASIC

Post by AndyC »

It never ceases to amaze me how many simple things to require resorting to POKE on the CBM. I mean I understand why (they cheaper out and did a deal with Microsoft for a non-customised version of BASIC) but it really makes the machine feel very unfinished compared to other machines. I guess it survived by being a solid games machine where others were more compromised.
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: X and Y axis. Printing Sinclair BASIC

Post by 1024MAK »

The Commodore 64 did well because of it’s sophisticated (for the time) hardware. It did cost more than the ZX Spectrum.

The later PET systems got a better BASIC. But the Commodore 64 kept the generic Microsoft BASIC with a severe lack of support for the hardware facilities. Which was a real shame.

Of course, for use as a games machine, how good the BASIC is becomes irrelevant. If you were serious about programming in BASIC, you could always buy one of the extended BASIC cartridges…

Or later on buy a Plus/4 which had a much better BASIC and more RAM available for BASIC programs.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Now is C=64s time

POKE(1024+x+40*y),c

The CBM C=64 prints the character c on the screen, at positions x,y, starting with the memory area 1024 through 2023. If an inverse character is desired, simply do c+128. As Vic-20 but different address
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

VIC Super Expander have: CHAR row,col,"txt"

C=16, Plus/4 and C=128version: CHAR {color source},col,row,"txt"{,rvs}
where rvs= 1(inverse on) / 0(inv. off)
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Sharp's time!

mz series (700,800,1500)

syntax: cursor col, row

esample: 10 CURSOR 5,6:PRINT"HELLO WORLD"
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

MEMOTECH basic

syntax: csr col, row

example: 10 CSR 5,6:PRINT "HELLO WORLD"
zx_if1
Drutt
Posts: 48
Joined: Fri Jul 16, 2021 8:53 pm
Location: Peru
Contact:

Re: X and Y axis. Printing Sinclair BASIC

Post by zx_if1 »

Oric's time

You need select text mode with TEXT sentences o LORES 0/1 first
to use PLOT to PRINT into display

Example:
10 LORES 0
20 PLOT 16,12,“HELLO"
Post Reply