Jump to content

Zach's Projects

  • entries
    53
  • comments
    535
  • views
    67,107

Chetiry Technical Notes

Sign in to follow this  
Zach

1,204 views

If you haven't seen it in the homebrew forum yet, I have posted a demo of a well-known Russian block game. The kernel manages 10 independently colored blocks at 8 pixels wide. (Well, 9 pixels for the far right one.)

 

Although there are only 4 COLUxx registers in the TIA, VBLANK offers an often overlooked 5th color (always black).

 

There are four colors available for the first 4 cells: background, playfield, player 0, and player 1. There are also three registers that can be pre-loaded with new colors. Then there is just barely enough time to load and store the last three colors, only because I am running code in RAM and using immediate addressing. Finally, to close off the edges of the play area, I turn VBLANK on and off.

 

In order to turn on VBLANK on the right side, I chose color values whose bit #1 were set. Then whatever value was saved to COLUPF on the right could also be saved to VBLANK. Turning it off on the left side was more of a challenge. I ended up using PHP, knowing that none of the color values loaded were zero, and bit 1 of the status register would be clear.

 

I also experimented with SHX to clear VBLANK. It has the advantage of using fewer cycles and freeing the SP, but the disadvantage is that it is a little understood illegal opcode that may not be entirely stable. So far, my tests with SHX have been successful, but I'll stick to PHP unless I find another use for the SP.

 

Currenlty it takes two scanlines to update the colors for the next row. I wish I could have done it in one line, but the block data has to be compressed to fit in 128 bytes of RAM, and I don't see any way to unpack and store 10 colors in only 76 cycles.

 

Without further ado, here is the code for coloring the blocks, part of an unwrapped loop.

;------------------------------------------
  pla
  lda #<BackToRom1
  sta SelfMod+22
  lda color4;
  sta COLUP1; block 4 
  lda color1
  sta COLUBK; block 1
  lda color2
  sta COLUPF; block 2
  lda color3
  sta COLUP0; block 3
  lda color5
  sleep 4
  jmp SelfMod
BackToRom1
;--------------------------------------------

SelfModCode; byte count
  php; 0; turn off vblank
  sta COLUBK; 1 2; block 5
  stx COLUPF; 3 4; block 6
  sty COLUP0; 5 6; block 7
  lda #COLOR0; 7 8
  sta COLUP1; 9 10; block 8
  lda #COLOR0; 11 12
  sta COLUBK; 13 14; block 9
  lda #COLOR0; 15 16
  sta COLUPF; 17 18; block 10
  sta VBLANK; 19 20
  jmp BackToRom1; 21 22 23
;-------------------------------------------

 

EDIT: Added a screenshot using DEC VBLANK. (I tried this on hardware too.)

 

 

EDIT2: Check out what INC VBLANK does!

 

Sign in to follow this  


10 Comments


Recommended Comments

Not sure, but maybe something like ASL or DEC VBLANK might work too.

Thanks for the idea, Thomas! I did try DEC, and while it did clear VBLANK it seems to do it a cycle earlier than SHX, or even a regular LDA #0, STA VBLANK. I've attached a screenshot on top so you can see what I'm talking about. I don't think I can afford to delay DEC VBLANK for a cycle.

 

I also tried INC, ASL, LSR, ROL, ROR, DCP, and ISB, and all of them seem to change VBLANK early.

Share this comment


Link to comment

What's even weirder is the behavior of INC and some other opcodes. They seem to change VBLANK twice, first clearing it for a cycle, and then setting it again. See above. I suspect that this behavior has been studied before, based on the fact that both z26 and Stella appear to emulate it accurately.

Share this comment


Link to comment

What's even weirder is the behavior of INC and some other opcodes. They seem to change VBLANK twice, first clearing it for a cycle, and then setting it again. See above. I suspect that this behavior has been studied before, based on the fact that both z26 and Stella appear to emulate it accurately.

The read-modify write instructions write twice. The first write occurs on cycle 4 and just writes back what was read from the location, and then it does the operation and writes the result on cycle 5.

 

INC VBLANK would first write a $01, then a $02 one cycle apart, as would ASL and ROL, but DEC, LSR and ROR would write a $01 and then a $00.

Share this comment


Link to comment

The read-modify write instructions write twice. The first write occurs on cycle 4 and just writes back what was read from the location, and then it does the operation and writes the result on cycle 5.

Hm, I wonder if eventually someone finds a good use for that.

Share this comment


Link to comment

The read-modify write instructions write twice. The first write occurs on cycle 4 and just writes back what was read from the location, and then it does the operation and writes the result on cycle 5.

Hm, I wonder if eventually someone finds a good use for that.

I was just thinking this morning, could you use INC ENAM0 to create a three-pixel long missile? (and would that ever be useful?)

Share this comment


Link to comment

The read-modify write instructions write twice. The first write occurs on cycle 4 and just writes back what was read from the location, and then it does the operation and writes the result on cycle 5.

Hm, I wonder if eventually someone finds a good use for that.

I was just thinking this morning, could you use INC ENAM0 to create a three-pixel long missile? (and would that ever be useful?)

I just found this posted by Supercat on [stella] but I don't know when it was posted since my email is set to GMT and I never bothered to fix it.

[stella] Read/modify/write VBLANK, ENAxx, etc.

 

The following is of particular relevance to a "Chitry" thread in the

homebrew forum on AtariAge, but for some reason attempts to post there

always time out. Maybe someone can forward this information.

 

Read/modify/write instructions (absolute mode) take five cycles, performing

writes on cycles 4 and 5. The first value written will be the value just

read; the next value written will be the new value.

 

Thus:

 

ASL VBLANK+$0300 will turn on VBLANK in cycle 4

 

INC VBLANK+$0300 will turn on VBLANK in cycle 4 and turn it off in cycle 5

 

ASL VBLANK+$0100 will turn on VBLANK in cycle 5; it will most likely turn

it off in cycle 4, but on 7800's it may turn on then (it will be on in

cycle 5 regardless)

 

INC VBLANK will probably turn off VBLANK in cycle 4, and if that fails

(some 7800's) it will probably turn it off in cycle 5. This is probably

the least reliable one.

 

The status of the upper bits of VBLANK should be considered indeterminate

after the above operations, so do not use them with paddles and be sure to

write "0" to them before trying to read the fire buttons.

Share this comment


Link to comment
I just found this posted by Supercat on [stella] but I don't know when it was posted since my email is set to GMT and I never bothered to fix it.

 

Thanks for reposting it, though I flubbed by a cycle the timings for all "RMW abs" instructions.

 

I would consider "dec vblank" a reliable means of turning off VBLANK on cycle 4 of a 5-cycle instruction; "asl vblank" would probably turn it off at cycle 4 and on at cycle 5, but on a 7800 it might turn it on at cycle 4 (leaving it on at cycle 5).

 

Getting ten flicker-free colors on a line is a nice trick, though I don't know if the fill-rows-with-any-color-blocks game is the best use of it. Some other styles of color-grouping games that don't involve rotation might be better since aspect ratio would not be a problem. Alternatively, it might be possible to use a taller aspect ratio and a squashing or scrolling screen. The squashing screen might be particularly interesting since the game is usually focused on the falling piece and the top four non-empty rows. Other rows are far less important.

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