Jump to content
IGNORED

Cubiks (Rubik's Cube)


Andrew Davie

Recommended Posts

Here's a demo drawing a Rubik's cube.

I only have 2 cubes defined here, and randomly chaging between them.

But, since I have 8 colours (including black) to play with, it looks like a complete implementation of Rubik's cube using this system would look good.

The "internals" (would be one of the dark colours).  Then black for the BG, and that leaves 6 other colours - enough for the 6 face colours.

 

1954502736_ScreenShot2021-11-23at1_11_36pm.thumb.png.8c4b3db86f062d905feb2965608d4fed.png

cubixCDFJ20211123.bin

Edited by Andrew Davie
  • Like 18
Link to comment
Share on other sites

I'm now handling all the possible colours. This binary just randomly switches face colour for each cube.

The draw is also handled a bit more "efficiently". Not sure what that blinking thing at the top is caused by :P

 

 

922420304_ScreenShot2021-11-24at12_52_39am.thumb.png.816e4901492c03ff073caddf888addfa.png

 

 

Not sure... might leave it at this stage.

 

 

 

cubicks20211124.bin

Edited by Andrew Davie
  • Like 13
Link to comment
Share on other sites

I've started the rotations/animations.

 

2012501903_ScreenShot2021-11-27at3_12_43pm.thumb.png.7f325f3271a6e2d35f51295d21ef5482.png

 

This shows the 45° frame; it will only be seen very briefly during a move, so it doesn't have to be perfect.

The binary shows this "animating" back and forth. I plan to do a 22.5° frame either side of that.

Then there's the three axes, so there are 4 frames for each -- 12 animation groupings total.

That will allow each "layer" (top/bottom/mid) on each of the 3 axes to rotate.

That will give me full movement - I'll be able to rotate either the whole cube in any axis, or any layer in any axis.

It's complex to work on - particularly the alignment of colours to the "real" cube. I'm getting there...

 

This version has improved timing, and should run OK on Gopher, too.

 

 

cubiks20211127.bin

  • Like 5
Link to comment
Share on other sites

5 hours ago, Andrew Davie said:

This version has improved timing, and should run OK on Gopher, too.

 

Excellent. In the latest binary, you're not using much ARM time at all compared to previous versions, so you have lots of room for more processing.

 

Incidentally, all versions work OK on Gopher2600 but cycle counting is on by default, so for earlier versions of your binary you need to turn it off, or the scanline count is unstable. In the latest version of Stella, it is the other way around - cycle counting is off by default and on in developer mode.

Link to comment
Share on other sites

I've put in one "inbetween" rotation.  The resolution makes it difficult to get the spacing right.

However, these "inbetween" rotation shapes are going to be very brief anyway, so I think this will do nicely.

 

 

Because it seems Stella (by default, I guess - I'm probably running an old less-capable version - 6.5) does not cycle count ARM code in normal mode, I am constantly switching between code that "looks good in stella" and code that "looks good in Gopher (and presumably hardware)".  It's to do with where I call ARM code -- in default config, Stella runs all this at super-speed, so the rotation speed is insane. I will include a binary (superfast) to show this. Compare running the same binary on Gopher and Stella to see the difference. I think Stella might be better with cycle counting on by default so this sort of thing doesn't happen. Of course I could be misunderstanding what's going on... but the differences between running "superfast" in the two is quite telling.

 

 

 

 

Edit: Forgot to mention... not that it is very useful right now, but holding down fire button will rotate the whole cube instead of the top layer.

 

 

 

cubiks20211127b.bin CubiksSuperfast.bin

Edited by Andrew Davie
  • Like 3
Link to comment
Share on other sites

1 hour ago, Andrew Davie said:

Because it seems Stella (by default, I guess - I'm probably running an old less-capable version - 6.5) does not cycle count ARM code in normal mode, I am constantly switching between code that "looks good in stella" and code that "looks good in Gopher (and presumably hardware)".  It's to do with where I call ARM code -- in default config, Stella runs all this at super-speed, so the rotation speed is insane. I will include a binary (superfast) to show this. Compare running the same binary on Gopher and Stella to see the difference. I think Stella might be better with cycle counting on by default so this sort of thing doesn't happen. Of course I could be misunderstanding what's going on... but the differences between running "superfast" in the two is quite telling.

 

 

I've not dug into it too much but a quick look at what's happening to the memory in the ARM, it looks like there's a value in RAM that's not being updated when cycle counting is off. It looks to be a value that's copied to address 0x82 of the VCS RAM (or maybe the other way around). That might be a clue as to what is happening.

 

 

 

Edited by JetSetIlly
Link to comment
Share on other sites

2 minutes ago, JetSetIlly said:

 

Interesting, and thanks for looking. But I'm pretty sure I know what's happening... sorry I wasn't clear.

I have a "code stuffer" wait loop in the 6507 display overscan/vblank, which once the regular code finishes its stuff... this "stuffer" looks at INTIM and if there's enough time left (say, 10 timer units) it calls "idle" in the C-code.  In the "idle" C-code, I draw one of the sub-cubes.  If the emulator does not count ARM cycles, then this "code stuffer" calls the sub-cube-draw many times, as it thinks there's plenty of unused cycles. If the emulator does count ARM cycles, then the "code stuffer" runs much slower, because it has an accurate idea of how much time is really left to do idle stuff.

So, for the "superspeed" version to work properly, the ARM cycles MUST be counted. Otherwise the idle calls a gazillion sub-cube draws.

For Stella versions, I disable the "code stuffer" and put the sub-cube-draw inside the overscan or vblank, and only call once or twice each frame.

Link to comment
Share on other sites

It's a bit rickety, but!  This is the first binary which has a full-rotation of a face with all colours correct.

It's a bit hardwired (the colours) and I spent way too many hours on hardwiring instead of doing it properly and indexing the colour into an array.

I just wanted to see it quick-n-dirty, but it turned out to be slow-n-dirty.  About 6 hours all-up.  Oh well.

The rickety nature is partly due to the chunky pixel resolution, but also due to the hand-drawing/alignment. One day I may do it from a 3D-rendered source (or even photograph) of a cube in the various rotation positions. That should make it look smoother/cleaner.  Come to think of it, would need to be an isometric (no perspective) rendering, as I use the same sub-shapes for similar surfaces. Anyway, fairly sure I can improve on this.

Here's the first version, and it looks OK, I think....  don't forget, hold trigger to rotate all layers at the same time.

 

Edit: Just noticed a face-colour error on the corner piece with green top. One of the sides changes colour. That's because... hardwire hackity hack hack error. I'll fix that up soonish.

 

 

cubiks20211130.bin

Edited by Andrew Davie
  • Like 6
Link to comment
Share on other sites

Final version for today. This has a real cube-like feel to it.  Each layer rotating independently randomly, different speeds and directions.

 

 

cubiks20211129c.bin

 

Edit: If you are running Stella you must turn on developer settings (and restart the emulator) to get the correct run-speed.  It's to do with timing calculations and how the screen is drawn. On Gopher, no settings are required.

Edited by Andrew Davie
  • Like 5
Link to comment
Share on other sites

Now under joystick control...  UP/DOWN will highlight the layer you are controlling.  LEFT/RIGHT will rotate it.

If you hold the fire button and LEFT/RIGHT, that will spin the whole cube.

 

Next up I will probably have to do the rotation animations for the other two axes. Not sure how they will look... pixel aspect ratio is tricky.  After that's done then I'll have to get some sort of sensible control system going, get the colours correctly indexing into a "cube" variable, get the rotations working on that variable, add some basic reset/select functionality... and I guess it will be close to done.

 

 

I guess I could add a 2x2x2 cube and even a 4x4x4 cube, too.

 

 

 

cubiks20211130f.bin

Edited by Andrew Davie
  • Like 4
Link to comment
Share on other sites

11 minutes ago, Bomberman94 said:

Wow - very cool what you‘ve done!

 

Any chance for a release (demo or something) for the „real machine“? ?

The binary should work on hardware....   put it on a Harmony Cart, for example.

Edited by Andrew Davie
  • Like 1
Link to comment
Share on other sites

I've increased the screen to 276 scanlines (from 262). This reduces the frame rate from 60Hz to about 57Hz -- barely noticeable. But it dramatically increases the game speed.... ironically!  Because I draw the little cubes piecemeal, when there's spare time, it takes a number of frames to draw the whole thing. Now, with 262 scanlines there's only enough time to draw 1 ... maybe 2... pieces in each of the Vertical Blank, and the Overscan. But when I increase to 276 scanlines, those two areas have way more "space" in them, and there's enough time to draw 2... maybe 3... pieces. So the game gains a doubling of speed of the draw (4 pieces per frame rather than 2). At least. And it shows in this binary... nice and zippy.

 

 

Don't forget: Stella to developer mode

Hold button and left/right to turn entire cube.

UP/DOWN to select layer

LEFT/RIGHT to rotate

 

 

cubiks20211202.bin

  • Like 6
Link to comment
Share on other sites

Here's a version just in case @ZeroPage Homebrew put this in the news/previews section today. Show day is a lot of pressure for us poor programmers! I've smoothed out the animation a bit (more particularly, now symmetrical), and increased the speed as much as I can.

 

cubiks20211203.bin

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...