[BASIC] PRINT AT (including the last two lines)

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
uglifruit
Manic Miner
Posts: 703
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

[BASIC] PRINT AT (including the last two lines)

Post by uglifruit »

I've been working on a few BASIC things, and have worked out a neat way to PRINT into the bottom last two lines of the screen (using stream #1)

Given I wanted to PRINT AT X,Y - where X = 0-23 and Y = 0-31 - I've been using ...

PRINT #(1+(x<22));AT (x-(22*(x>21))),y;"*"

.. meaning I don't need any conditionals, and I can just pretend the screen is a seamless 24x32 (rather than a 22x32 main screen and a 2x32 input window).

Explanation:
If x<22 it prints in #2 (the main screen) at co-ordinates as normal, but if X is 22 or 23 is prints AT rows 0 or 1 (respectively) of channel 1, the input stream (a.k.a. last two lines).


(Apologies if I'm teaching people to suck eggs.)
CLEAR 23855
User avatar
R-Tape
Site Admin
Posts: 6400
Joined: Thu Nov 09, 2017 11:46 am

Re: [BASIC] PRINT AT (including the last two lines)

Post by R-Tape »

uglifruit wrote: Sat Jan 04, 2020 2:47 pm (Apologies if I'm teaching people to suck eggs.)
Not me. It looks useful.

It would be even more useful if it didn't 'time out' at x=45, then it could be a very compact scroller.
User avatar
flatduckrecords
Manic Miner
Posts: 785
Joined: Thu May 07, 2020 11:47 am
Location: Oban, Scotland
Contact:

Re: [BASIC] PRINT AT (including the last two lines)

Post by flatduckrecords »

Thanks [mention]uglifruit[/mention], I agree that looks useful. Works nicely as a pair of functions as well:

Code: Select all

10 FOR y=0 TO 23
20 FOR x=0 TO 31
30 PRINT #FN s(); AT FN y(),x; "*"
40 NEXT x
50 NEXT y
100 DEF FN s()=(1+(y<22))
110 DEF FN y()=(y-(22*(y>21)))
(I find it less confusing to use PRINT y, x though, especially if I'm using PLOT and DRAW as well!)

[edit] s() for stream instead of c() for channel!
Post Reply