0

Does anyone have actual documentation on how MS/Commodore BASIC handles line wrapping in PRINT statements?

I tried this in an online emulator:

PRINT 1,2,3,4,5,6,7,8,9,0

In this case it wraps at the 40-column mark (or thereabouts) so the 5 appears under the 1 in column 2. But as the tab width is 10 characters that might just be luck. So;

PRINT 1,2,3,4;5;6;7;8;9;10

...wraps between the 6 and 7 and the 7 ends up in column 1. This seems to imply it doesn't simply reset the cursor to column 1 when it passes the 40 mark. I tried longer versions too, and it doesn't seem there's any logical line length - I thought it was 80 but it seemed to just keep going.

Does anyone know the rules here?

3
  • 1
    My recollection is semicolons were used to print items next to one another, such as PRINT "X= ";X would result in X= 2, if the value of X was 2. When commas were used then the items would be separated by the tab distance. Thus PRINT "X= ",X would result in X= __________2. the underscores represent spaces. – Fred Oct 19 '20 at 2:35
  • 1
    And IIRC, the exact behaviour was different between BASIC dialects and platforms. – dirkt Oct 19 '20 at 6:44
  • 2
    It helps to keep in mind that if you ask BASIC to print a positive integer 6, it outputs " 6" with a leading space for the sign. So most of what you see onscreen is shifted right by one space. – Nimloth Oct 19 '20 at 11:40
1

When I implemented this in my MS-BASIC alike I ended up using 14 characters as the comma field and keeping track of where I was on the line and then padding to the next 14 characters. I think I tested this on either a 4K or 8K MS basic and that was the "best" result I could come up with on a system without an defined screen size. I suspect this was chosen originally as an ASR33 has 72 characters across and 14 characters gives 5 "fields" for a comma separation with a total width of 70.

From the later CP/M basics have a WIDTH command which sets where the internal wrap point is. The manual for MBASIC-80 notes the default value (and wrap point) is 72 characters.

https://archive.org/details/BASIC-80_MBASIC_Reference_Manual/page/n101/mode/2up

Having just had a look at the code I wrote it forces a newline if the comma position is greater than the line width (current position starts at 0 and is incremented as each character is printed).

public void NextComma()
{
    // Originally commas are split in to 14 character cells
    // which makes sense where width is 72.
    var newPosition = ((_currentPosition / CommaCellWidth) + 1) * CommaCellWidth;
    if ((newPosition + CommaCellWidth) >= _teletype.Width)
    {
        NewLine();
    }
    else
    {
        Tab((short)(newPosition + 1));
    }
}
0

In MS-BASIC

  • a comma advances the cursor to the begin of the next tab 'field'.
  • Size of tab fields is implementation depended
  • Size is usually a divisor of line length (*1).

Bottom line: It doesn't matter as tab field and line length are synchronized anyway.


Now, in a more basic way, BASIC does not have an assumption of line length at all (*2). It's pretty deeeeeevice agnostic in this and leaves decisions about automatic wrap (or not) to output devices. Well, or program control that is.

Commata, like semi colons, do only structure within a line. So, as adaptors of MS BASIC did, choosing a sensible value helps quite on line length deprivated devices is a good idea.


*1 - For example 10 on a 40 character per line PET, 11 on a 22 cpl VIC20 or 8 on a 40/80 cpl Apple II

*2 - An exception here is Commodore BASIC, or more exact its screen editor, as it does manage logical lines that can spread over multiple screen lines. But as such it's not part of BASIC, but a Commodore specific device/editor handling.

6
  • I think you're over-generalising at (2). There are lots of BASIC implementations that have a concept of device output width. Sinclair SuperBASIC for the QL even has a command WIDTH to set it. Admit it's hard to say anything definitive about BASIC in it's many incarnations, though – tofro Oct 20 '20 at 10:52
  • @tofro True, there's more than basic BASIC, still (and to my knowledge) SuperBASIC's WIDTH does not set a line length, but a window width. Printing using coma and semicolon doesn't really care for it. – Raffzahn Oct 20 '20 at 10:59
  • Nope, doesn't set a window width (that's [obviously] done with WINDOW), but rather really the output device's line length (e.g. for printers). – tofro Oct 20 '20 at 11:03
  • @tofro Hmm. Guess I'm mixing that up with some other BASIC. So does it reset for example the positioning with comma? – Raffzahn Oct 20 '20 at 12:01
  • Yep, it does. That's actually one of its main purposes. My main point is, however, it's a bit daunting to claim "BASIC is like that" - You could probably say that for MS Basic, but "the others" are just way too diverse and "creative". – tofro Oct 20 '20 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.