Using the ULAplus 64 colour mode from 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: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Using the ULAplus 64 colour mode from Sinclair BASIC

Post by PeterJ »

Can anybody help me get my head around accessing ULAplus from BASIC? I've read the guide, but I'm struggling to understand it.

Say for example I just want to fill the screen with single characters changing to a random paper and ink from the 64 as I go.

Thanks
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by AndyC »

Is it not just a matter of enabling 64 colour mode, setting up the palette entries you want and then PRINTing characters in a variety of INK/PAPER/FLASH/BRIGHT combinations?
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by Seven.FFF »

It is. The example linked to has the explanation and sample code to actually do it.

Maybe it would be better for Peter to ask specific questions about the parts of the explanation you don’t understand, and say what it is you doesn’t understand.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by PeterJ »

OK,

So I'm enabling ULAplus, electing to change palette number 0 which is flash off, bright off, ink 0. Then writing the RGB, printing in ink 0, changing the RGB, then printing in Ink 0 again.

I would expect the ink colour to change.

Code: Select all

;enable ULAplus
20 OUT 48955,64
30 OUT 65339,1
;choose palette entry 0 (ink 0)
50 OUT 48955,0
;set RGB colours
70 LET r=3
80 LET g=6
90 LET b=1
;set the colours
110 OUT 65339,((g*32)+(r*4)+b)
;print in ink 0
120 PRINT FLASH 0; BRIGHT 0; INK 0;"Hello ";
;change red intensity
130 LET r=r-1
;set new colour
135 OUT 65339,((g*32)+(r*4)+b)
;print again
140 PRINT FLASH 0; BRIGHT 0; INK 0;"World ";
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by AndyC »

PeterJ wrote: Thu Oct 26, 2023 2:14 pm OK,

So I'm enabling ULAplus, electing to change palette number 0 which is flash off, bright off, ink 0. Then writing the RGB, printing in ink 0, changing the RGB, then printing in Ink 0 again.

I would expect the ink colour to change.

Code: Select all

20 OUT 48955,64
30 OUT 65339,1
50 OUT 48955,0
70 LET r=3
80 LET g=6
90 LET b=1
110 OUT 65339,((g*32)+(r*4)+b)
120 PRINT FLASH 0; BRIGHT 0; INK 0;"Hello ";
130 LET r=r-1
135 OUT 65339,((g*32)+(r*4)+b)
140 PRINT FLASH 0; BRIGHT 0; INK 0;"World ";
I would expect Hello and World to be printed in the same colour. Which would be set by line 135.

Every time you change a palette entry, you are redefining what colour that particular combination of INK/PAPER/BRIGHT/FLASH means for the entire screen. Things that were already printed in the particular combination will change to reflect the palette colour change automatically.
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by PeterJ »

OK @AndyC,

so if I do an OUT 48955,1 before line 135 and change link 140 to INK 1 would that do it?
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by AndyC »

PeterJ wrote: Thu Oct 26, 2023 2:27 pm OK @AndyC,

so if I do an OUT 48955,1 before line 135 and change link 140 to INK 1 would that do it?
Yeah, I think so. Things that need to be a different colour need to be printed with different attributes still.

Your initial code was setting colour 0, printing in it, then immediately changing what colour 0 was. And was quick enough the you can't see the colours change. Putting a long PAUSE before line 135 would probably also make this obvious.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by Seven.FFF »

And the other obvious thing that bears spelling out is that attribute cells can still only contain one ink and one paper colour like a standard Speccy. And since both ink and paper in a cell shared the same flash and bright settings in a standard Speccy, in ULAplus that translates to both redefined colours used in a cell needing to come from the same "quadrant" of the 64 colour redefined palette - what I labelled here as A, B, C and D.

Image

ULaplus can be used in conjunction with Timex hicolour mode which has 8x1 attribute cells, too. The SpecEmu TC2048 machine demonstrates that nicely.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by PeterJ »

I've made the change, but it still doesn't seem to be working as expected.

Code: Select all

;enable ULAplus
20 OUT 48955,64
30 OUT 65339,1
;choose palette entry 0 (ink 0)
50 OUT 48955,0
;set RGB colours
70 LET r=3
80 LET g=6
90 LET b=1
;set the colours
110 OUT 65339,((g*32)+(r*4)+b)
;print in ink 0
120 PRINT FLASH 0; BRIGHT 0; INK 0;"Hello ";
;change red intensity
130 LET r=r-1
;set new colour
131 OUT 48955,1
135 OUT 65339,((g*32)+(r*4)+b)
;print again
140 PRINT FLASH 0; BRIGHT 0; INK 1;"World ";
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by Seven.FFF »

Without redefining palettes it looks like this on a standard speccy. You printed in INK 0 and 1, paper 7, non-flashing and non-bright:

Image

After running on a ULAplus capable machine it looks like this. INK 0 and 1 are both redefined to green, paper remains as it was:

Image

Note that Spin has a somewhat screwed up default ULAplus palette entry for dim white - it looks mauve. But on in it's default ULAplus palette, not its standard palette. That's just a Spin thing though.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by Guesser »

PeterJ wrote: Thu Oct 26, 2023 3:28 pm I've made the change, but it still doesn't seem to be working as expected.

Code: Select all

;enable ULAplus
20 OUT 48955,64
30 OUT 65339,1
;choose palette entry 0 (ink 0)
50 OUT 48955,0
;set RGB colours
70 LET r=3
80 LET g=6
90 LET b=1
;set the colours
110 OUT 65339,((g*32)+(r*4)+b)
;print in ink 0
120 PRINT FLASH 0; BRIGHT 0; INK 0;"Hello ";
;change red intensity
130 LET r=r-1
;set new colour
131 OUT 48955,1
135 OUT 65339,((g*32)+(r*4)+b)
;print again
140 PRINT FLASH 0; BRIGHT 0; INK 1;"World ";
You're setting two colours that are nearly identical, set them to values a bit further apart and the change will be more obvious
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by Seven.FFF »

BTW if you're not already using it, Remy's tool to tokenize basic and then export as a .tap is a helpful online way to try out these kind of code snippets in your favourite emulator without installing software or retyping.

https://zx.remysharp.com/bas/
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by PeterJ »

Thanks @Guesser,

I think you solved it!

Changed line 130 to let r=r+3: let g=g-3
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by Seven.FFF »

You didn't say that the two greens were the part you thought was wrong. You just said it was not as expected. If you are specific with your questions then they almost answer themselves, or at least give people the chance to give you a fix wihout having to dig in and try to get inside your head.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
PeterJ
Site Admin
Posts: 6879
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by PeterJ »

Good point @Seven.FFF. I should have been clearer. I would certainly recommend not trying to get inside my head.

Thanks again for your help.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Using the ULAplus 64 colour mode from Sinclair BASIC

Post by Seven.FFF »

It was not meant as criticism. It was fun to help!
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Post Reply