|
| 1 | +#PRINT |
| 2 | + |
| 3 | +##Syntax |
| 4 | + |
| 5 | +``` |
| 6 | + PRINT [<item>][;] |
| 7 | +``` |
| 8 | + |
| 9 | +##Description |
| 10 | + |
| 11 | +`PRINT` is a sentence used to output information on the screen. The ZX Spectrum screen is divided in 24 rows (numbered |
| 12 | +from 0 to 23), and 32 columns (numbered from 0 to 31). So it's composed of 24 x 32 = 96 cells. Cells are referred by |
| 13 | +its coordinate (row, column), being (0, 0) the top-leftmost cell, and (23, 31) the bottom-rightmost one. |
| 14 | + |
| 15 | +There's a _hidden cursor_ on the screen that points to the coordinate where the next character will be printed. |
| 16 | +Each time something is printed, a _carriage return_ is also printed and the screen cursor is advanced to |
| 17 | +the next line (row): |
| 18 | + |
| 19 | +``` |
| 20 | +PRINT "I'M ON ONE LINE" |
| 21 | +PRINT "I'M ON THE NEXT ONE" |
| 22 | +``` |
| 23 | + |
| 24 | +If you don't want this to happen, you can add a semicolon (;) at the end of the `PRINT` sentence, and the next |
| 25 | +printed expression will still be on the same line: |
| 26 | + |
| 27 | +``` |
| 28 | +PRINT "I'M ON ONE LINE"; |
| 29 | +PRINT "... AND I'M ALSO ON THE SAME LINE" |
| 30 | +PRINT "AND I'M ON A NEW LINE" |
| 31 | +``` |
| 32 | +Notice the first `PRINT` ends with a semicolon to avoid _carriage return_. Executing a single `PRINT` will just |
| 33 | +advance the cursor to the next line. |
| 34 | + |
| 35 | +> **NOTE**: when the cursor reaches the end of the screen, it will **scroll upwards** all rows 1 position. |
| 36 | +
|
| 37 | +Let's prints numbers from 0 to 25 and see what happens: |
| 38 | + |
| 39 | +``` |
| 40 | +CLS: REM Clears screeen and puts the cursor at the top-leftmost corner |
| 41 | +FOR i = 0 TO 25 |
| 42 | + PRINT i |
| 43 | +NEXT i |
| 44 | +``` |
| 45 | +You'll see that number 0 and 1 are gone (they were shifted up and went out of the screen). |
| 46 | + |
| 47 | +> **NOTE**: When the screen is cleared with [CLS](cls.md), the cursor is set to its default position (0, 0), |
| 48 | +> that is, the top-leftmost screen corner. |
| 49 | + |
| 50 | +`PRINT` can print everything that is a _single_ expression (also called an _item_). |
| 51 | +That is, strings (like in the previous example), numbers, variable values, and array elements |
| 52 | +(it can not print an entire array; that's not a `single` element but a collection): |
| 53 | + |
| 54 | +For example: |
| 55 | + |
| 56 | +``` |
| 57 | +LET a = 5 |
| 58 | +PRINT "Variable 'a' contains the value: "; |
| 59 | +PRINT a |
| 60 | +``` |
| 61 | + |
| 62 | +Indeed, if you want to chain several expressions one after another you can _chain_ them in a single PRINT sentence |
| 63 | +using semicolons: |
| 64 | +``` |
| 65 | +LET a = 5 |
| 66 | +PRINT "Variable 'a' contains the value: "; a |
| 67 | +``` |
| 68 | + |
| 69 | +## Changing the print position |
| 70 | +You can change the current _cursor_ position using the [AT](at.md) modifier: |
| 71 | + |
| 72 | +``` |
| 73 | +PRINT AT 5, 0; "This message starts at ROW 5" |
| 74 | +PRINT AT 10, 10; "This message starts at ROW 10, COLUMN 10" |
| 75 | +``` |
| 76 | + |
| 77 | +Again, you can chain all `PRINT` _items_ using semicolon: |
| 78 | + |
| 79 | +``` |
| 80 | +PRINT AT 5, 0; "ROW 5"; AT 10, 10; "ROW 10, COLUMN 10" |
| 81 | +``` |
| 82 | + |
| 83 | +## Changing appearance |
| 84 | +You can temporarily override the aspect of the items printed using them inline: |
| 85 | + |
| 86 | +``` |
| 87 | +CLS |
| 88 | +FOR i = 1 to 7 |
| 89 | + PRINT AT i, 0; PAPER 0; INK i; "PRINT AT ROW "; i; " WITH INK "; i |
| 90 | +NEXT i |
| 91 | +``` |
| 92 | + |
| 93 | +See the related commands section for further info. |
| 94 | + |
| 95 | +##Examples |
| 96 | + |
| 97 | +``` |
| 98 | +REM Prints a letter in the 10th row of the screen moving from left to right |
| 99 | +CLS |
| 100 | +FOR i = 0 TO 31 |
| 101 | + PRINT AT 10, i; "A" |
| 102 | + PAUSE 10 |
| 103 | + PRINT AT 10, i; " ": REM Erases the letter |
| 104 | +NEXT i |
| 105 | +``` |
| 106 | + |
| 107 | + |
| 108 | +##Remarks |
| 109 | + |
| 110 | +* This sentence is compatible with Sinclair BASIC but _expands_ it, since it allows printing at rows 22 and 23 |
| 111 | + (all 24 rows are available to the programmer). Traditionally, Sinclair BASIC only allows to print at rows 0..21. |
| 112 | +* You can use [ITALIC](italic.md) and [BOLD](bold.md) modifiers (not available in Sinclair BASIC) |
| 113 | + |
| 114 | +##See also |
| 115 | + |
| 116 | +* [CLS](cls.md) |
| 117 | +* [AT](at.md) |
| 118 | +* [PAPER](paper.md) |
| 119 | +* [BORDER](border.md) |
| 120 | +* [INVERSE](inverse.md) |
| 121 | +* [INK](ink.md) |
| 122 | +* [ITALIC](italic.md) |
| 123 | +* [BOLD](bold.md) |
| 124 | +* [OVER](over.md) |
0 commit comments