JohnEarnest / Octo

A Chip8 IDE
MIT License
679 stars 55 forks source link

Granular detection of collisions on both bitplanes #105

Closed tobiasvl closed 4 years ago

tobiasvl commented 4 years ago

It would be nice if VF could reflect what planes collisions occured on when drawing to both bitplanes; ie. VF taking a value between 0 and 3 according to what plane(s) a collision occured on.

There is precedence for granular collision detection, since the original Super-CHIP 1.1 implementation for HP48 sets VF to the number of rows that either collide with another sprite or are clipped by the bottom of the screen (in hires mode only).

I haven't actually checked if Octo implements that behavior/quirk, but its existence means that people who want to write widely compatible programs already need to take into account that VF isn't restricted to the values 0 and 1 when checking for collisions.

tobiasvl commented 4 years ago

My specific use case this time was "incrementing" the value of a pixel in a cycle from 0 through 3; ie. if the pixel was empty on both bitplanes, plane 1 should be set, if it was set on plane 1 only it should be unset there and set on plane 2, and if it was set on plane 2 only it should be set on plane 1 as well. I ended up implementing it like this:

plane 2
sprite va vb 1
v0 := vf
v0 <<= v0
plane 1
sprite va vb 1
v0 |= vf
v0 >>= v0
if vf == 0 begin
    plane 2
    draw
end

But I guess that specific use case would not be any easier if this proposal was implemented.

After some thought I think my ideal solution would be to change the FN01 instruction to FX01, so the plane could be selected dynamically rather than as a constant. That's obviously not going to happen though, so I suppose getting plane collision wouldn't be as useful as I first thought. Unless you can think of other use cases!

JohnEarnest commented 4 years ago

I've given this some consideration, and I don't think there's a clear enough use-case to justify it. Your example demonstrates a reasonable way to get collision information on a per-plane basis: just draw to each plane separately. As always, I appreciate the suggestion.