Jump to content
IGNORED

bcc bcs does it work with RTS as subroutine ?


 Share

Recommended Posts

Does the BCC and BCS commands work with the RTS ? so you give a bcc command, then it will branch when carry is clear, Can i then have a RTS in branch so that i returns to the BCC or must one use the JSR or similar command ?

 

And also whats a smart and easy way to have a event counter, Lets say i want to control (in my case a Bat flying in a controlled flight path) within the vbi in assembler.

 

i tried something like this but it doesnt seem to work:

The MBU and MBR are for moving the bat up and to the right.

 

 

 

2044 LDX MULF2 ; Event counter
2044 INX
2044 CPX #5
2044 BCC MBU ; bat fly up as long as Mulf is less than 5
2044 CPX #10
2044 BCS MBR ; Comment here its supposed to move bat to right. but this doesnt work ( i messed up probably carry is already set ?)
2044 RTS
2044 MBU
2044 DEC P0Y ; Equates for Player 0 Y pos
2044 DEC P1Y ; Equates for Player 1 Y pos
2044 DEC P0Y
2044 DEC P1Y
2044 RTS
2044 MBR
2044 INC PX ; Player X pos Counter
2044 LDX PX
2044 STX P0X ; Equates for player 0 X pos
2044 STX P1X ; Equates for player 1 X pos
2044 RTS

 

Link to comment
Share on other sites

RTS is paired with JSR usually - JSR puts the return address onto the stack so that RTS will pull it and resume where the sub was called from.

 

BCC or any other branch for that matter, as well as plain JMP - none of these put return info onto the stack.

If you want to implement special conditions you just need to put more test/branches into your program.

 

Generally the trick is to program your code such that the complexity of branches is minimized. Sometimes you can use tricky programming instead of branching.

 

e.g. though this isn't exactly tricky. Incrementing a 16-bit integer you can either have.

 

 

  INC LOW
  BNE NO_INC1
  INC HIGH
NO_INC1
 ; program continues...

 

or

 

 

  LDA LOW
  CLC
  ADC #1
  STA LOW
  LDA HIGH
  ADC #0
  STA HIGH

 

Probably not the best example, in this case the method of avoiding branches actually means more program code.

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

  • Recently Browsing   0 members

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