Black squares...

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
1024MAK
Bugaboo
Posts: 3115
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Black squares...

Post by 1024MAK »

Image

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
spider
Dynamite Dan
Posts: 1099
Joined: Wed May 01, 2019 10:59 am
Location: Derby, UK
Contact:

Re: Black squares...

Post by spider »

I see your squares and I raise you a fraction of randomness ;)

Code: Select all

10 FOR N=0 TO 703
20 IF (RND*10) > 4 THEN LET A=32 : GOTO 40
30 LET A=143
40 PRINT CHR$ A;
50 NEXT N
60 PRINT AT 0,0;
70 GOTO 10
That's quite annoying you know as I really wanted to have for L20 "IF (RND*10) > 6 THEN LET A=32 ELSE LET A=143 , that would of saved messing about and saved a line. *sigh* :D Someone forgot to allow that in ZXBasic :oops:

I thought about having a 5 FOR X=2 TO 10 STEP 2 and then having L20 say > X for the randomness check, that way it would print less squares (as X=2 aka RND*10 > 2) for each loop around but increasing in number each time, it seemed a bit too much messing about. Same for colour. :D

I then thought about just writing directly so that I could easily do the bottom two lines with pratting with the #0 / #1 thing but again its going a bit too far maybe hehe.

EDIT... Pic of rubbish listing output:

Image
User avatar
Einar Saukas
Bugaboo
Posts: 3093
Joined: Wed Nov 15, 2017 2:48 pm

Re: Black squares...

Post by Einar Saukas »

spider wrote: Fri Aug 02, 2019 11:09 am That's quite annoying you know as I really wanted to have for L20 "IF (RND*10) > 6 THEN LET A=32 ELSE LET A=143 , that would of saved messing about and saved a line. *sigh* :D Someone forgot to allow that in ZXBasic :oops:
LET A=143-(111 AND RND>.6)
User avatar
spider
Dynamite Dan
Posts: 1099
Joined: Wed May 01, 2019 10:59 am
Location: Derby, UK
Contact:

Re: Black squares...

Post by spider »

Einar Saukas wrote: Fri Aug 02, 2019 11:26 am
spider wrote: Fri Aug 02, 2019 11:09 am That's quite annoying you know as I really wanted to have for L20 "IF (RND*10) > 6 THEN LET A=32 ELSE LET A=143 , that would of saved messing about and saved a line. *sigh* :D Someone forgot to allow that in ZXBasic :oops:
LET A=143-(111 AND RND>.6)
Thanks! :D , that is quite complicated though relatively. This reminds me of a cheat for UU I wrote as its so short on memory I really really needed an ELSE but had to use two lines:

Code: Select all

326 IF w$="*" THEN POKE VAL "23659",VAL "2": INPUT "Where to (1-100) ? ";loc: IF loc<1 OR loc>100 THEN GO TO 326
327 IF w$="*" THEN LET z$="Moving...": GO SUB pr: LET POS=loc: GO SUB 1000: GO TO 100
Ideally I wanted to write it like this:

Code: Select all

326 IF w$="*" THEN POKE VAL "23659",VAL "2": INPUT "Where to (1-100) ? ";loc: IF loc<1 OR loc>100 THEN GO TO 326 ELSE LET z$="Moving...": GO SUB pr: LET POS=loc: GO SUB 1000: GO TO 100
You can probably see what's going on there. If the input is not in the range of 1 to 100 it asks again, otherwise it executes it. An invalid number would cause a crash so I had to error trap it. Unfortunately two lines ate more memory than one but it worked OK, just really pointing out how helpful "ELSE" would of been there! :D
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: Black squares...

Post by PROSM »

spider wrote: Fri Aug 02, 2019 11:09 am I see your squares and I raise you a fraction of randomness ;)
...
Why use RND, when you can use... a Galois linear-feedback shift register! :D

Image

Sure, it's not BASIC, but then again, it's only 44 bytes:

Code: Select all

org 28000

c_mosaicfade:
		ld a,39					; Galois LFSR seed
c_mosaicfade_l1:
		ld b,3					; 9 squares per frame
c_mosaicfade_l2:
		call c_mosaicfade_plot			; Plot square
		djnz c_mosaicfade_l2
		halt
		jr c_mosaicfade_l1

c_mosaicfade_plot:
		rrca					; Rotate
		jr nc,c_mosaicfade_plot_l1
		xor $38					; XOR if last bit cycled was 1 (feedback part)

c_mosaicfade_plot_l1:
		ld l,a
		ld h,$58
		ld c,0
		ld (hl),c				; 1st attr. page
		inc h
		xor 54
		ld l,a
		ld (hl),c				; 2nd attr. page
		inc h
		xor 73
		ld l,a
		ld (hl),c				; 3rd attr. page
		xor 127

c_mosaicfade_plot_l2:
		cp 39					; Are we back to the start of the period?
		ret nz					; Return if not
		or a
		ret z
		pop de					; We want to return directly to the caller

		xor a
		jr c_mosaicfade_plot_l1

end 28000
All software to-date
Working on something, as always.
User avatar
spider
Dynamite Dan
Posts: 1099
Joined: Wed May 01, 2019 10:59 am
Location: Derby, UK
Contact:

Re: Black squares...

Post by spider »

PROSM wrote: Fri Aug 02, 2019 3:01 pm Why use RND, when you can use... a Galois linear-feedback shift register! :D

Sure, it's not BASIC, but then again, it's only 44 bytes:
I see what you did there! :D 8-) And I like it!

I did think about assembly but it seemed a lot of trouble :oops: , you know how it is you sometimes need a few dozen instructions to do what you could do in Basic in 10 seconds! I know it would be about 100 times faster though hehe.


Slightly off topic: I just noted your signature link, will have a read through that this evening as it is something I'm very interested in although currently (as seen elsewhere) my erm primary thing is Quill conversions from one platform to another. But that is something for another topic.


EDIT... Back on topic: I think if you added a splash of colour to the squares in your routine it would be even better 8-)
User avatar
1024MAK
Bugaboo
Posts: 3115
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Black squares...

Post by 1024MAK »

I hope you have your multipoint belts on, as this topic has gone round the square at 90 degrees...

Code: Select all

10 POKE (RND*768)+22528,(RND>.5)*56: GO TO 10
Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
1024MAK
Bugaboo
Posts: 3115
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Black squares...

Post by 1024MAK »

Colour one:

Code: Select all

10 POKE (RND*768)+22528,RND*56: GO TO 10
Alas, both of these demonstrates how computer random is not so much when used lots of times in a row...

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
1024MAK
Bugaboo
Posts: 3115
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Black squares...

Post by 1024MAK »

spider wrote: Fri Aug 02, 2019 4:01 pm EDIT... Back on topic:
:lol: :lol: :lol:
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
spider
Dynamite Dan
Posts: 1099
Joined: Wed May 01, 2019 10:59 am
Location: Derby, UK
Contact:

Re: Black squares...

Post by spider »

1024MAK wrote: Fri Aug 02, 2019 4:06 pm Colour one:

Code: Select all

10 POKE (RND*768)+22528,RND*56: GO TO 10
Alas, both of these demonstrates how computer random is not so much when used lots of times in a row...

Mark
Yes I know the diagonal effect. :)

Despite trying various things with this in the past such as setting RND to be a seed value (frames?) and setting it again as well as introducing another RND check if over X then set to 56 (to set squares back to white) etc etc, it never really looked that brilliant! :lol:
1024MAK wrote: Fri Aug 02, 2019 4:08 pm
spider wrote: Fri Aug 02, 2019 4:01 pm EDIT... Back on topic:
:lol: :lol: :lol:
Yes I know! :oops:
User avatar
1024MAK
Bugaboo
Posts: 3115
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Black squares...

Post by 1024MAK »

A better colour version:

Code: Select all

1 FOR a=0 TO 14444: POKE PEEK a+PEEK (a+1) +PEEK (a+2) +22528,RND*56: NEXT a: GO TO 1
Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: Black squares...

Post by llewelyn »

That's cool Mark. I typed it in and ran it, noticed that diagonal tendency to the way the squares are placed. Interesting.

BTW is there a command to make the keyboard window in Fuse get bigger somehow? I have to use a magnifying glass to read it.
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: Black squares...

Post by PROSM »

llewelyn wrote: Sat Aug 03, 2019 12:33 pm BTW is there a command to make the keyboard window in Fuse get bigger somehow? I have to use a magnifying glass to read it.
If you're talking about the "Keyboard Helper" window, then I'm afraid not - that's the biggest it gets. If you are having trouble with the keyword entry system, you might want to try typing in your BASIC programs from 128K mode; you can type your commands out letter by letter from there.
All software to-date
Working on something, as always.
llewelyn
Manic Miner
Posts: 205
Joined: Thu Feb 22, 2018 3:27 pm
Location: virginias eastern shore
Contact:

Re: Black squares...

Post by llewelyn »

Thanks Prosm! Does that also include key command words and punctuation?
User avatar
PROSM
Manic Miner
Posts: 476
Joined: Fri Nov 17, 2017 7:18 pm
Location: Sunderland, England
Contact:

Re: Black squares...

Post by PROSM »

llewelyn wrote: Sat Aug 03, 2019 2:50 pm Thanks Prosm! Does that also include key command words and punctuation?
In 128K mode, the only key positions you'll have to remember are for the punctuation marks. Everything else is typed out letter by letter, including key command words.

You may also want to consider trying out the "Keyboard Helper" function in ZX Spin. This allows you to write out whole BASIC statements using the PC keyboard mapping by first typing them into a separate input box, and then by clicking a button, allowing the emulator to convert these to Spectrum key presses.

In addition, the BASin development environment allows you to write BASIC programs in a standard Windows environment, and test them out in an integrated emulator at any time. It also comes with many useful features, such as a UDG editor, a debugger and a line renumbering facility.

To get slightly back on topic... :)
spider wrote: Fri Aug 02, 2019 4:01 pm ... I think if you added a splash of colour to the squares in your routine it would be even better 8-)
Image

Not yet random colour, but somewhat prettier:

Code: Select all

org 28000

c_mosaicfade:
		ld a,39					; Galois LFSR seed
		ld d,$38				; LFSR mask (and mask for attributes)
c_mosaicfade_l1:
		ld b,3					; 9 squares per frame
c_mosaicfade_l2:
		call c_mosaicfade_plot			; Plot square
		djnz c_mosaicfade_l2
		halt
		jr c_mosaicfade_l1

c_mosaicfade_plot:
		rrca					; Rotate
		jr nc,c_mosaicfade_plot_l1
		xor d					; XOR if last bit cycled was 1 (feedback part)

c_mosaicfade_plot_l1:
		ld l,a
		ld h,$58

		call c_matchcolours
		ld (hl),a				; 1st attr. page
		
		ld a,l
		inc h
		xor %00110110				; Randomise position
		ld l,a
		call c_matchcolours			; Set ink to be same colour as paper
		ld (hl),a

		ld a,l					; Get page position value
		inc h
		xor %11001001				; Randomise position
		ld l,a
		call c_matchcolours
		ld (hl),a
		
		ld a,l
		cpl					; Restore to original value (equiv. to XOR $FF)

c_mosaicfade_plot_l2:
		cp 39					; Are we back to the start of the period?
		ret nz					; Return if not
		or a
		ret z
		pop hl					; We want to return directly to the caller

		xor a
		jr c_mosaicfade_plot_l1

c_matchcolours:
		and d					; Keep only the paper colour
		ld c,a
		rrca
		rrca
		rrca					; Rotate paper colour into ink colour slot
		or c					; Combine paper and ink colours
		ret

end 28000
All software to-date
Working on something, as always.
dfzx
Manic Miner
Posts: 677
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Black squares...

Post by dfzx »

llewelyn wrote: Sat Aug 03, 2019 12:33 pm BTW is there a command to make the keyboard window in Fuse get bigger somehow? I have to use a magnifying glass to read it.
The Fuse keyboard graphic was replaced by a much better one back in December. Unfortunately development of Fuse has rather stalled and they've not released a new version since before then. :(
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Post Reply