Page 1 of 1

Just a little head-scratcher

Posted: Wed Jan 09, 2019 10:40 pm
by Bizzley
I've had the idea for this for years, and with time over Xmas and New Year thanks to some lousy TV decided to see if I could get it to work. I'm sure it's been done before, the logic isn't that difficult to work out, but it was fun to code something that has no real purpose.

So, Copy and Paste the block of code below into your assembler, run it from 32768, and enjoy a little 1/2K illusion. ;)

Code: Select all

	org 32768
	defb 205,72,129,205,18,128,205,160,128,118,205,189,128,205,45,128,24,241,58,252,129,238,1,50,252,129,200,1,133,129,62,88	
	defb 17,176,44,221,33,173,129,253,33,0,64,24,16,1,141,129,62,90,17,184,45,221,33,186,129,253,33,128,80,33,104,128
	defb 113,35,112,50,143,128,33,150,128,114,33,155,128,115,253,229,209,221,35,221,126,0,254,255,200,221,134,5,254,8,245,230
	defb 7,221,119,0,6,0,79,33,133,129,9,6,32,126,18,20,126,18,20,126,18,20,126,18,20,126,18,20,126,18,20,126
	defb 18,20,126,18,20,203,154,28,16,227,241,56,196,213,38,88,221,110,9,126,84,93,44,1,31,0,237,176,18,209,24,177
	defb 1,32,0,205,63,129,221,33,199,129,17,2,72,58,252,129,167,196,216,128,221,33,212,129,17,10,72,24,27,1,224,47
	defb 205,63,129,221,33,225,129,17,18,72,58,252,129,167,196,216,128,221,33,238,129,17,26,72,221,35,221,126,0,254,255,200
	defb 221,134,5,254,8,245,230,7,221,119,0,47,230,7,6,0,79,33,149,129,9,6,8,213,229,126,18,44,20,126,18,44
	defb 20,126,18,44,20,126,18,44,20,126,18,44,20,126,18,44,20,126,18,44,20,126,18,44,20,33,32,248,25,235,225,16
	defb 215,209,28,241,56,178,213,38,89,221,110,9,78,84,93,6,7,107,123,198,224,95,26,119,16,247,121,18,209,24,153,33
	defb 235,128,112,33,52,129,113,201,33,2,89,17,165,129,213,229,6,4,26,119,44,16,251,225,84,125,198,8,95,1,24,0
	defb 237,176,125,198,8,111,209,19,26,254,255,32,225,17,0,88,205,118,129,17,128,90,213,33,165,129,1,8,0,237,176,225
	defb 14,120,237,176,201,255,254,252,248,240,224,192,128,128,192,224,240,248,252,254,255,255,255,255,255,255,255,255,255,0,0,0
	defb 0,0,0,0,0,72,81,90,99,108,117,126,71,255,0,1,2,3,255,1,2,3,4,0,32,64,96,0,1,2,3,255
	defb 1,2,3,4,159,191,223,255,0,1,2,3,255,1,2,3,4,2,3,4,5,0,1,2,3,255,1,2,3,4,10,11
	defb 12,13,0,1,2,3,255,1,2,3,4,242,243,244,245,0,1,2,3,255,1,2,3,4,250,251,252,253,0,0,0,0
[Amended to reduce flicker]

Re: Just a little head-scratcher

Posted: Wed Jan 09, 2019 11:17 pm
by Ast A. Moore
This is really neat! Want to fix up the top part? It’s pretty glitchy. The rest is beautifully smooth.

Oh, and I love the fact that it’s 512 bytes. :D

Re: Just a little head-scratcher

Posted: Wed Jan 09, 2019 11:50 pm
by Bizzley
The emulator I was using didn't give me any problems but when I tried it on some others I had the flicker you mentioned. It should be fixed now and I've changed the code above (new data in the first line) if you want to give it a try.

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 12:39 am
by Ast A. Moore
Yup. That did fix it. Ta!

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 11:19 am
by R-Tape
Image

Pretty. Somehow it's psychadelic as well as soothing.

I haven't tried to code something like this, but I wonder if it's something that seems deceptively simple until you sit down to do it (especially in 500 bytes).

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 11:38 am
by PeterJ
Ohhh. I'm in hypnotic trance [mention]R-Tape[/mention]

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 11:41 am
by Sokurah
Looks great :)

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 1:07 pm
by Pegaz
Beautiful.
This reminds me of an article I read long ago.
With certain Poke commands in system variables, you could get a nice effects, similar to this one.
I found it, here:
http://retrospec.sgn.net/users/tomcat/y ... =MMH_85_01

No translation required, just type Pokes. ;)

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 2:06 pm
by Joefish
It's neat. Somewhere I've got scraps of a scrolling engine that worked like this, pixel-rolling a pattern so you could scroll a picture of blocky attributes left/right with pixel precision. I tried to synchronise it with a per-row 128K screen-swap to give you double the attribute resolution. I was thinking of the simple 'PlaySchool' backgrounds in something like Pac-Land.

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 2:52 pm
by dfzx
Clearly the clever people can see how it works, but can someone post a dumbed down explanation of how it's doing it for the rest of us? :?

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 3:07 pm
by stupidget
dfzx wrote: Thu Jan 10, 2019 2:52 pm Clearly the clever people can see how it works, but can someone post a dumbed down explanation of how it's doing it for the rest of us? :?
Yep +1 vote from me for this info as well please. I'm as thick as a plank me is :lol:

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 3:25 pm
by Ast A. Moore
dfzx wrote: Thu Jan 10, 2019 2:52 pm Clearly the clever people can see how it works, but can someone post a dumbed down explanation of how it's doing it for the rest of us? :?
Just a note that each 8x8 cell still contains no more that one INK and one PAPER color at any one time; so no ULA timing tomfoolery here.

It’s kind of easier to draw on a piece of paper than to put into writing, but I’ll try.

Imagine the following pattern:

Code: Select all

xxxxxxxo|ooooooox|xxxxxxxo| . . .
Here, xs represent the set screen bits (or pixels) and os the reset bits.

Now, let’s shift the whole thing one pixel to the left:

Code: Select all

xxxxxxoo|ooooooxx|xxxxxxoo| . . .
The attribute pattern looks something like this:

Code: Select all

BLUE/YELLOW|YELLOW/MAGENTA|MAGENTA/RED| . . .
At a pixel level, the colors will be as follows:

Code: Select all

BBBBBBYY|YYYYYYMM|MMMMMMRR| . . .
And so on.

Once we’ve shifted our pixel pattern eight times, we need to shift our attributes one cell to the left, and start shifting the pixels again.

The vertical shifting is done in a similar manner.

Hope this clears things up a bit.

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 3:29 pm
by dfzx
Ast A. Moore wrote: Thu Jan 10, 2019 3:25 pm Hope this clears things up a bit.
Yes, thanks! Kind of obvious when you put it like that, but I wouldn't have worked it out from looking at the code. :)

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 3:32 pm
by Joefish
Each character cell starts off empty of pixels so it's showing its PAPER colour. What you can't see (because it's empty) is that the INK of that square is set to the colour of its neighbour.

So then you start filling in pixels on the right-hand-side of that character cell, and it looks like it's neighbouring character square is moving into it one pixel at a time.

As I say, knowing this you can paint a big 'PlaySchool' style (child's drawing) house and road using only PAPER attributes, then make the whole thing pixel-scroll to the left.

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 9:29 pm
by Bizzley
If you start the code from 32771 instead of 32768 (or zero out the first three bytes) you'll remove the Call to the routine that initially draws the attributes, then you can see the raw pixel data being redrawn behind the scenes every loop.

Re: Just a little head-scratcher

Posted: Thu Jan 10, 2019 10:57 pm
by R-Tape
Bizzley wrote: Thu Jan 10, 2019 9:29 pm ...then you can see the raw pixel data being redrawn behind the scenes every loop.
Image
:)