Jump to content
IGNORED

Macro VS Subroutine


Cisano

Recommended Posts

Hi, I have a problem.

I created a macro for update GRP1 X coordinate. Not the positioning, but only the value.

The code is executed during vertical blank time.

Y is used inside the Macro. All works great.

 

ldy #0
UpdateGRP1_Macro

 

I tried to use the same code by a Subroutine.

ldy #0
jsr UpdateGRP1

It doesn't work good. The sprite movement is not smooth.

Is there something I don't know about these 2 way to use code?

Thanks.

 

Edited by Cisano
Link to comment
Share on other sites

        lda FrqFrameGRPX
        and MaskOne,y
        bne .end
        lda XposGRP1,y
        cmp StartOne,y
        bne .other
        lda #1
        sta CursorSpringOne,y
        jmp .opera
.other
        ;lda XposGRP1,y
        cmp ArriveOne,y
        bne .opera
        lda #$ff
        sta CursorSpringOne,y
.opera
        clc
        lda CursorSpringOne,y
        adc XposGRP1,y
        sta XposGRP1,y
.end
        lda StartOne,y
        cmp ArriveOne,y
        bne exit
        sta XposGRP1,y
exit
		rts

The Macro has not the rts.

Link to comment
Share on other sites

Just some generic things to look for...

 

1.

Jumping to the subroutine takes a few cycles.
Returning also takes a few cycles.

You said it is in the vertical blank code but is it time sensitive?

 

2.

Storing the return address takes a few bytes of stack.

Is the stack big enough?

 

3.

Some bank switching schemes trigger off subroutine calls (ie when you write/read the return address in the first few elements of the stack).

Link to comment
Share on other sites

1. I set a timer and the vertical blank time is not all used.

2. yes it is

3. no bank switching for now

 

I just moved the subroutine in another part of the cose, upper, and it works good.

It is the normality or there are solutions?

Thanks.

Edited by Cisano
Link to comment
Share on other sites

15 hours ago, Cisano said:

Penalty? You mean extra cycles?

Yup.

 

Always when a branch or an indexed table access crosses a 256 bytes page the instruction takes one extra cycle.

To check this during assembly I have written a simple macro:

  MAC CHECKPAGE
    IF >. != >{1}
      ECHO ""
      ECHO "ERROR: different pages! (", {1}, ",", ., ")"
      ECHO ""
      ERR
    ENDIF
  ENDM

If your branch moves backward, put this behind the branch and provide the branch address. If it is a table, put it at the end of the table and provide the table address.

Edited by Thomas Jentzsch
  • Like 2
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...
  • Recently Browsing   0 members

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