Jump to content
IGNORED

BRK, BIT instruction


TXG/MNX

Recommended Posts

BRK casues in internal NMI interrupt. So the program will jump to the address stored at $FFFE/$FFFF. The important thing to remeber is that when an RTI occurs the code will return to the instruction in the second byte after the BRK instruction. So if there is a BRK at $1000, the RTI will return to $1002, NOT $1001. One use of this is to create your own instructions. Put a value in the byte after the break that represents your instruction and then in the break routine you can look at the address that was pushed onto the stack to find this value and then jump to a specific piece of code based on the value.

 

Here is a good explination I found of BIT in a tutorial:

 

The BIT instruction tests bits in memory with the accumulator but changes neither. Only processor status flags are set. The contents of the specified memory location are logically ANDed with the accumulator, then the status bits are set such that,

 

* N receives the initial, un-ANDed value of memory bit 7.

* V receives the initial, un-ANDed value of memory bit 6.

* Z is set if the result of the AND is zero, otherwise reset.

 

So, if $23 contained $7F and the accumulator contained $80 a BIT $23 instruction would result in the V and Z flags being set and N reset since bit 7 of $7F is 0, bit 6 of $7F is 1, and $7F AND $80 = 0.

 

Dan

Link to comment
Share on other sites

From www.6502.org:

 

BIT is often used to skip one or two following bytes as in:

 

CLOSE1 LDX #$10 If entered here, we

.BYTE $2C effectively perform

CLOSE2 LDX #$20 a BIT test on $20A2,

.BYTE $2C another one on $30A2,

CLOSE3 LDX #$30 and end up with the X

CLOSEX LDA #12 register still at $10

STA ICCOM,X upon arrival here.

 

Thomas Jentzsch is a master at using BIT (or undocumented multicycle NOPs) to make constant cycle routines. e.g.

 

CPY TOPP0 ; 3 cycles

BCC SETP0 ; 3 cycles taken, 2 cycles not taken

DC $2C ; opcode for BIT ABS 4 cycles

SETP0 STA GRP0 ; 3 cycles

 

Whether or not Y

 

Skeleton makes a heavy use of BIT to decode the maze bitmap since 8 mazes are stored in the same byte. Skeleton also uses BIT to sample the random number generator (either 1 or 2 bits as required).

Link to comment
Share on other sites

Hi there!

 

* V receives the initial, un-ANDed value of memory bit 6.

 

This is an excellent thing for a second ultra-quick status bit access. Normally You'd only think of

 

LDA status

BMI/BPL

 

for the 7th bit, but

 

BIT status

BVC/BVS

 

gives you the same for the 6th one...

 

Greetings,

Manuel

Link to comment
Share on other sites

I thought I'd chime in here too.

 

I use bit a lot in my 2600 coding. It helps to check the state my game without changing the value of the accumulator.

 

Example...

;----------------------------------------------
; C O N S T A N T S
;----------------------------------------------

GAMERUNNING = #%00000000

TITLESCREEN = #%10000000

GAMEPAUSED = #%01000000

.

.

.

gameState ds 1

.

.

.

   bit gameState

   bmi DoTitleScreenProcessing

   bvs DoGamePausedProcessing

.

.

.

 

You could also use it in 2600 coding for checking the timer for the "big wait". You would have to adjust the value you store in the timer as this checks for when the timer reaches #$FF and not #$00 as is normally done. This again would save you from destroying the values presently in the registers.


.bigWait

   bit INTIM

   bpl .bigWait

Link to comment
Share on other sites

  • 3 weeks later...

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