TXG/MNX Posted March 11, 2003 Share Posted March 11, 2003 Hi, Until now I never used the following instructions: BRK and BIT. BRK should do something like a software interupt Could some send an example and how does the processor know where to jump to??? BIT Also an example please... Quote Link to comment Share on other sites More sharing options...
DanBoris Posted March 11, 2003 Share Posted March 11, 2003 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 Quote Link to comment Share on other sites More sharing options...
EricBall Posted March 12, 2003 Share Posted March 12, 2003 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). Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted March 12, 2003 Share Posted March 12, 2003 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 Quote Link to comment Share on other sites More sharing options...
DEBRO Posted March 12, 2003 Share Posted March 12, 2003 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 Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted March 12, 2003 Share Posted March 12, 2003 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... As you can see, it also has the advantage of not interfering with the contents of the Accumulator Quote Link to comment Share on other sites More sharing options...
TXG/MNX Posted March 31, 2003 Author Share Posted March 31, 2003 thanx for the info it's much clearer now... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.