A miracle when it works first time!

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Cosmium
Berk
Posts: 36
Joined: Tue Dec 04, 2018 10:20 pm
Location: USA

A miracle when it works first time!

Post by Cosmium » Thu Aug 29, 2019 6:15 am

Following on from the "An impressive way to crash the Speccy?" thread (viewtopic.php?f=6&t=918), I was working on a sprite clipping m/c routine and when it came to test my first attempt, while not exactly crashing, I watched it spectacularly fail as the sprite "exited" the top of the screen :lol:

Image

It occurred to me that not only do assembly routines often fail the first time you run them, they often fail in quite dramatic fashion!

There are those rare (but memorable) occasions when it does work first time but anyone else captured any amusing pseudo-crashes when it doesn't?

BTW, I got it going the next day, though the result seemed a bit boring and pedestrian in comparison :)

Image
0 x

User avatar
R-Tape
Site Admin
Posts: 2541
Joined: Thu Nov 09, 2017 11:46 am

Re: A miracle when it works first time!

Post by R-Tape » Thu Aug 29, 2019 6:57 am

Heh nice. I've had a few firework displays like that. I'll see if I can find them later. It is usually for the same reason - sometimes I even see the sprite data walking around the attributes, and can safely walk it back up to the display file.

It's not quite the same, but something I keep doing when starting my code is hurriedly typing RANDOMIZE USR 3268 (I think) instead of 32768. I get a flashing dashed line at the screen bottom - I must have done it hundreds of times!
0 x

Ralf
Dynamite Dan
Posts: 1287
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: A miracle when it works first time!

Post by Ralf » Thu Aug 29, 2019 4:28 pm

Do you mean by "sprite clipping" a situation where a sprite emerges from a side of a screen so you draw only visible part of it?

If so then it's a troublesome job. If you put clipping into your sprite drawing routine then unfortunately it'll become slower and more complicated.
In many cases you may consider the effect is not worth the cost and just draw full sprites when they appear at the screen edge.

If you use a screen buffer in memory then a common trick is to make the buffer a bit wider than the visible screen. So you never clip sprites when you draw them into the buffer but when you copy buffer to the visible screen then you do it without the edges and the sprites will look like clipped.
0 x

AndyC
Manic Miner
Posts: 251
Joined: Mon Nov 13, 2017 5:12 am

Re: A miracle when it works first time!

Post by AndyC » Thu Aug 29, 2019 5:12 pm

A third trick is to put part of the edge of the screen as black paper and black ink, so that drawing sprites can "leak" over the edges (as long as you also reserve some memory after the display) and the effect won't be visible on screen. How well that works does depend on the size of your sprites too (or at least the granularity with which you can draw them)
0 x

User avatar
Seven.FFF
Manic Miner
Posts: 340
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: A miracle when it works first time!

Post by Seven.FFF » Thu Aug 29, 2019 6:18 pm

My favourite one is working in all-ram mode. Normally we’re used to bugs doing a reset after eventually jumping to some part of the ROM.

In all-ram mode it’s ALL your code, and it has an annoying habit or restarting your program at a random point rather than crashing. Makes debugging it hard sometimes.
0 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
Cosmium
Berk
Posts: 36
Joined: Tue Dec 04, 2018 10:20 pm
Location: USA

Re: A miracle when it works first time!

Post by Cosmium » Thu Aug 29, 2019 7:39 pm

Ralf wrote:
Thu Aug 29, 2019 4:28 pm
Do you mean by "sprite clipping" a situation where a sprite emerges from a side of a screen so you draw only visible part of it?
Yeah!
Ralf wrote:
Thu Aug 29, 2019 4:28 pm
If so then it's a troublesome job. If you put clipping into your sprite drawing routine then unfortunately it'll become slower and more complicated.
In many cases you may consider the effect is not worth the cost and just draw full sprites when they appear at the screen edge.
Very true, but I thought I'd update my existing "non-clipped" sprite routine to first test for sprites partially off screen (via their coordinates) and add a branch to the new clipping code which adjusts some draw values before returning to the (mainly) unchanged main draw loop. That way there wouldn't be as much impact on the original code's performance.
0 x

User avatar
Cosmium
Berk
Posts: 36
Joined: Tue Dec 04, 2018 10:20 pm
Location: USA

Re: A miracle when it works first time!

Post by Cosmium » Thu Aug 29, 2019 7:50 pm

AndyC wrote:
Thu Aug 29, 2019 5:12 pm
A third trick is to put part of the edge of the screen as black paper and black ink, so that drawing sprites can "leak" over the edges (as long as you also reserve some memory after the display) and the effect won't be visible on screen. How well that works does depend on the size of your sprites too (or at least the granularity with which you can draw them)
Thanks for these tips. This black attribute trick was actually my plan for sprites entering/leaving the left/right sides of the screen. It's better than suddenly fully appearing at the screen's edge yet barely requires any code changes to the render loop :)

And the sprite clipping at the screen top/bottom only required changes to the sprite's source address and number of lines to draw, which was relatively easy to change and hasn't had much impact on performance.
0 x

User avatar
Turtle_Quality
Berk
Posts: 48
Joined: Fri Dec 07, 2018 10:19 pm

Re: A miracle when it works first time!

Post by Turtle_Quality » Thu Aug 29, 2019 8:06 pm

For vertical clipping , if you use a lookup table to get the address of each row, you point rows 192-255 to somewhere harmless, ROM for instance. That way there is no loss of speed. I assume you hold the y address in a single byte so -1 would be 255.
0 x
Definition of loop : see loop

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1194
Joined: Mon Nov 13, 2017 3:16 pm

Re: A miracle when it works first time!

Post by Ast A. Moore » Thu Aug 29, 2019 9:20 pm

Yup, even the release version of Exolon has a similar bug.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
Cosmium
Berk
Posts: 36
Joined: Tue Dec 04, 2018 10:20 pm
Location: USA

Re: A miracle when it works first time!

Post by Cosmium » Thu Aug 29, 2019 10:30 pm

R-Tape wrote:
Thu Aug 29, 2019 6:57 am
It's not quite the same, but something I keep doing when starting my code is hurriedly typing RANDOMIZE USR 3268 (I think) instead of 32768. I get a flashing dashed line at the screen bottom - I must have done it hundreds of times!
Yeah, USR 3268 does it. Reminds me of some old ZX81 BASIC laser effect!
0 x

Post Reply