how do i get 128 colours on screen in sam basic?

Anything relating to non Sinclair computers from the 1980's, 90's or even before.
Post Reply
User avatar
777
Manic Miner
Posts: 519
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

how do i get 128 colours on screen in sam basic?

Post by 777 »

it it possible in basic? the manual says it is but its not very clear. ive tried using palette to do this but it just seems to reset the colours per line. am i missing something here?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
Stefan
Manic Miner
Posts: 822
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: how do i get 128 colours on screen in sam basic?

Post by Stefan »

The palette consists of 16 colours.
You can change (part of) the palette using line interrupts.

Code: Select all

10 for f=0 to 126
20 palette 0,f line f
30 next f
If you change the loop to 127 you will get error 25 Too many palette changes.
User avatar
777
Manic Miner
Posts: 519
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: how do i get 128 colours on screen in sam basic?

Post by 777 »

Stefan wrote: Tue May 30, 2023 2:34 pm The palette consists of 16 colours.
You can change (part of) the palette using line interrupts.

Code: Select all

10 for f=0 to 126
20 palette 0,f line f
30 next f
If you change the loop to 127 you will get error 25 Too many palette changes.
ok, thank you. is it possible to have a different set of 16 colours every line then? so you could display 128 colours in just 8 lines? i.e draw each pixel one of 16 colours across the screen and then have a different set of colours on the next line?

also, what do you mean 'part' of the palette?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
AndyC
Dynamite Dan
Posts: 1420
Joined: Mon Nov 13, 2017 5:12 am

Re: how do i get 128 colours on screen in sam basic?

Post by AndyC »

You can change multiple palette entries on a line, IIRC. Note however that doing so takes time and while a single palette entry can be changed purely in the border time, subsequent palette changes might happen part way through a line leaving a visible result. Trying to change every palette entry on every line, for example, is probably not going to give the results you'd want (unless the screen has been very carefully crafted around the change timings).
User avatar
Stefan
Manic Miner
Posts: 822
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: how do i get 128 colours on screen in sam basic?

Post by Stefan »

777 wrote: Tue May 30, 2023 3:23 pm is it possible to have a different set of 16 colours every line then? so you could display 128 colours in just 8 lines? i.e draw each pixel one of 16 colours across the screen and then have a different set of colours on the next line?
No. The SAM's Z80 runs at 6MHz. So that's 6 million ticks a second. A screen is updated approx 50 times a second, so that leaves 120 thousand ticks per frame. A frame has approximately 312 lines, so that's approx 384 ticks per line.

To change a complete palette you can:

Code: Select all

ld hl,palette.table + 15	; 10 t-states
ld bc,256*16 + port.clut	; 10 t-states - port.clut = 248
otdr					; 331 t-states (15 * 21 + 16)
					; total 351 t-states
This could be unrolled for speed:

Code: Select all

ld hl,palette.table + 15	; 10 t-states
ld bc,256*16 + port.clut	; 10 t-states - port.clut = 248
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
outd					; 16 t-states 
					; total 276 t-states
BUT memory and port access are contended during screen time, so all of the above numbers are at least rounded up to nearest multiple of 4 and otdr / outd probably to even more since it is BOTH memory and port access, let's assume 24 for outd, that makes it 408 which is more t-states than fit in a line.

You also need to change the palette before it is used, to prevent palette shearing.
User avatar
777
Manic Miner
Posts: 519
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: how do i get 128 colours on screen in sam basic?

Post by 777 »

AndyC wrote: Tue May 30, 2023 5:08 pm You can change multiple palette entries on a line, IIRC. Note however that doing so takes time and while a single palette entry can be changed purely in the border time, subsequent palette changes might happen part way through a line leaving a visible result. Trying to change every palette entry on every line, for example, is probably not going to give the results you'd want (unless the screen has been very carefully crafted around the change timings).
thank you both.

is this not 128 colors on screen all at once across the lines, in basic?


Image

no sure why it has a kind of slanted pixel effect... plus you get the odd flickery pixel, which is weird... and some of the pixels are double or 4x across

here is the code...

Image

line 190 is missing, it should say- 190 next t

run it then type goto 70

here is a disk image of it:

https://filebin.net/rxzn3ypkqmkl5hu0

maybe someone could modify the code so it works better?
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1

http://zxspeccy.great-site.net/
User avatar
Stefan
Manic Miner
Posts: 822
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: how do i get 128 colours on screen in sam basic?

Post by Stefan »

777 wrote: Wed May 31, 2023 2:05 am no sure why it has a kind of slanted pixel effect... plus you get the odd flickery pixel, which is weird... and some of the pixels are double or 4x across
See what we both already wrote.
777 wrote: Wed May 31, 2023 2:05 am maybe someone could modify the code so it works better?
You can get it to work better using assembler, but as I already wrote, that will only get you so far.
Post Reply