It is currently Wed Nov 22, 2017 7:08 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Aug 06, 2017 8:01 am 
Offline
User avatar

Joined: Sun Nov 09, 2008 9:18 pm
Posts: 987
Location: Pennsylvania, USA
These two macros, ins_lo and ins_hi, enable a series of higher level macros to be written which autodetect the parameters both for immediate, zp or absolute but also if they start with entity_ where they are then indexed by x or y. Makes it very simple to transfer between zp, ram, immediate and structures of arrays for entities using single lines like this:

Code:
move16 #100, entity_x_velocity   ; automatically stores lo byte in entity_x_velocity_lo,x and hi byte in entity_x_velocity_hi,x


or say between "this" and "that" entity like this:

Code:
move16 entity_x_velocity, entity_x_velocity, x, y  ;moves velocity of entity indexed by x to entity indexed by y, automatically using the _lo and _hi arrays for each


Code:

.macro ins_lo reg, ins, arg, suf

    .local entity_lo
    .if !.xmatch (.left (1, {arg}), #)
        .if .xmatch (.left (1, .ident(.sprintf("%.7s", .string(arg)))), entity_)
            .ifnblank suf
                entity_lo = .ident(.concat(.string(arg), suf))
            .else
                entity_lo = arg
            .endif
            .ifnblank reg
                ins entity_lo,reg
            .else
                ins entity_lo,x
            .endif
        .else
            ins arg
        .endif
    .else
        ins #<(.right (.tcount ({arg})-1, {arg}))
    .endif

.endmacro

.macro ins_hi reg, ins, arg

    .local entity_hi
    .if !.xmatch (.left (1, {arg}), #)
        .if .xmatch (.left (1, .ident(.sprintf("%.7s", .string(arg)))), entity_)
             entity_hi = .ident(.concat(.string(arg), "_hi"))
            .ifnblank reg
                ins entity_hi,reg
            .else
                ins entity_hi,x
            .endif
        .else
            ins arg+1
        .endif
    .else
        ins #>(.right (.tcount ({arg})-1, {arg}))
    .endif

.endmacro

.macro move16 source, dest, rega, regb

    ins_lo rega, lda, source, "_lo"
    ins_lo regb, sta, dest, "_lo"
    ins_hi rega, lda, source
    ins_hi regb, sta, dest

.endmacro

;...a whole series of other possible 16 bit and 8 bit macros using ins_lo and ins_hi follows in my codebase, you can easily imagine how they would look based on move16.



Last edited by GradualGames on Mon Aug 07, 2017 10:31 am, edited 3 times in total.

Top
 Profile  
 
PostPosted: Sun Aug 06, 2017 9:15 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2981
Location: Tampere, Finland
GradualGames wrote:
*edit* Much like the rubber duckie technique, posting this has made me scrutinize these macros. I'm trying to get rid of that .scope ... .endscope in my ins_lo and ins_hi macros, because I think it's causing ca65 to emit absolute addressing instead of zp addressing in some cases.

If you're using the scope to make entity_lo/entity_hi local to the macro, you can get the same effect with .local.

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Sun Aug 06, 2017 9:49 am 
Offline
User avatar

Joined: Sun Nov 09, 2008 9:18 pm
Posts: 987
Location: Pennsylvania, USA
thefox wrote:
GradualGames wrote:
*edit* Much like the rubber duckie technique, posting this has made me scrutinize these macros. I'm trying to get rid of that .scope ... .endscope in my ins_lo and ins_hi macros, because I think it's causing ca65 to emit absolute addressing instead of zp addressing in some cases.

If you're using the scope to make entity_lo/entity_hi local to the macro, you can get the same effect with .local.


Cool...works, but interestingly I'm still getting absolute addressing in some cases, see my new post. I may have been incorrect in thinking the .scope was what was causing ca65 to emit absolute addressing.


Top
 Profile  
 
PostPosted: Mon Aug 07, 2017 10:27 am 
Offline
User avatar

Joined: Sun Nov 09, 2008 9:18 pm
Posts: 987
Location: Pennsylvania, USA
Updated OP with dramatically cleaner versions of ins_lo and ins_hi. The other above mentioned issues are gone now (no .scope... .endscope still remain in the macros so they shouldn't introduce address size change problems where they didn't already exist)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], ReverendSA and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group