Jump to content
  • entries
    62
  • comments
    464
  • views
    85,015

Hit the bricks!

Sign in to follow this  
Guest

465 views

This is an extension of my brick-buster kernel demo, with some collision-detection code added. As you move your player left and right, the program will highlight the bricks you're over on rows 1, 3, and 5. The collision-detect code is presently a bit too slow to be practical (though it does manage to run three times in vblank, which would be barely enough to allow for three balls bouncing, the timing is really very tight). The technique is nonetheless interesting and may be useful elsewhere.Each row of bricks is stored as two variable-length sections of code, starting $39 bytes apart. The code consists of some initialization, then a mixture of the following instructions:

$7A  nop$84  sty COLUPF$85  sta COLUPF$86  stx COLUPF$87  sax COLUPF$8C  sty.w COLUPF$8D  sta.w COLUPF$8E  stx.w COLUPF$8F  sax.w COLUPF

Note that every opcode is >= $7A, all of the operands $08 or less, and the number of cycles for each instruction is equal to the number of bytes plus one.The most interesting loop of my brick-finder routine looks like this; the accumulator must hold $3F + the number of cycles corresponding to the ball's position.

                ldy     #1BrickFindLp:                cmp     (hitptr),y                iny                sbc     #1    ; Subtract 1 or 2                cmp     #$40                bcs     BrickFindLp

It's unfortunate that I have to waste two cycles on the CMP, but I can't figure any way to make the loop end someplace "nicer" since the accumulator has to be kept between $08 and $7A. If the sense of carry on the compare were reversed, I could have the loop count up to $80, but that doesn't work here--the loop has to count down.Anyway, after the loop finds what instruction the CPU will be executing when it reaches the proper position, it then searches backward to find the last "store" opcode. Here, the use of $7A as a NOP comes in handy, since all the stores are >= $84 while the NOPs and operands aren't.Although this loop iterates rather quickly, it has to run an iteration for every operand byte in addition to the opcode bytes. The worst case is running 36 iterations (to parse through to the end of twelve st?.w instructions). Next rev I'll rewrite the code to parse based upon opcodes which ends up with a worst-case time about 100 cycles faster.Update 060205Changed colors some. Should be less flicker, but some of the colors are no longer as distinct.There are now three bouncing balls. One of them has a "comb" surrounding it to demonstrate that the 1lk is free of tearing. The bouncing balls highlight bricks. Note that when all three balls are in the top half of the screen near the right hand side the vertical timing will slip slightly because this version still uses the slow collision detect.The planned fix is to use a faster collision detect which won't identify the code spot to be patched but will determine if there's a collision. I'll then queue up collisions so the appropriate blocks can be erased (limit one erasure per frame). Note that blocks will be removed from the small bitmap immediately even if their erasure is delayed a frame or two, so the delay shouldn't affect gameplay.The score is maybe a tease; it would be nice to make score digits look like that, but the 200+ bytes it would require could probably be better spent on other things.Update 060206Changed colors. See note below.

Sign in to follow this  


5 Comments


Recommended Comments

Are you planning to turn this into a game?

 

That would sort of be the idea I think, though I haven't figured out all the details yet. I don't want to do a direct Arkanoid rip-off, but some sort of power-ups would seem to be apropos.

 

A few thoughts:

 

-1- Every row of bricks I support is 128 bytes. The demo now uses 16 rows. I don't want to go much below that, but with 6K total I expect I'll run out of RAM before running out of things I could do with it.

 

-2- Whatever means I use for splitting the ball (be it a "disruptor" token or something else) I'm thinking of making the extra balls be a different color from the main one; the extra balls will be "expendable" but the main one will not.

 

-3- I like the yellow border, but it will pose some interesting challenges at the bottom of the screen. Presently the 1lk for the balls doesn't extend down that far, but for a real game it would have to. Losing the yellow border would simplify that part of the screen a lot.

 

-4- I may be able to rework the colors to gain a freely-colorable background (in exchange for restrictions on other colors). I'll have to see how that looks.

 

-5- I've been thinking of making the game use a memcard/Atarivox (if present) to hold level data. In that case, depending upon the number of levels the game would either be a single load, or else two loads in immediate succession, with no further loading required to advance from level to level. Otherwise a lot of loading would be necessary.

 

-6- It might be interesting to do this game as a 4A50-format cart, though I'd want to rewrite most of it if I did that.

Share this comment


Link to comment

Another update. Version 060206 changed the colors. Please let me know whether this version or the previous looks better (my 7800's RF is terrible, and the video mod colors seem a little "off").

 

Colors are set based on five parameters. This version uses parameters A1, A2, X1, X2, and Y. Every brick is a blend of two colors. The first is chosen from:

(A1) (X1) (Y) (A1 & X1)

and the second from

(A2) (X2) (Y) (A2 & X2)

 

In this demo, A1 and X1 are $1C and $8A, so (A1 & X1) is $08. A2 and X2 are $4C and $AA, so (A2 & X2) is $08. Y is $80.

 

In earlier versions, colors were set slightly differently:

(A1) (X) (Y1) (A1 & X)

and

(A2) (X) (Y2) (A2 & X)

 

In those demo, X was set to $06 and A1 and A2 both had luminance values of $08 (for a black background) or $0A (for gray).

 

So which method of color do people prefer?

Share this comment


Link to comment
Another update.  Version 060206 changed the colors.  Please let me know whether this version or the previous looks better (my 7800's RF is terrible, and the video mod colors seem a little "off").

 

So which method of color do people prefer?

 

The newer version looks best to me. I hope you are going to turn this into an Arkanoid port eventually?

 

Chris

Share this comment


Link to comment

Both the gray and the blue backgrounds look better than the black in regards to "taming the flicker". I'm partial to the gray myself.

Share this comment


Link to comment
Guest
Add a comment...

×   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...