It is currently Mon Sep 25, 2017 1:32 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu May 11, 2017 10:26 pm 
Offline
User avatar

Joined: Thu Jan 19, 2006 5:08 pm
Posts: 744
Location: Shelton, Washington.
tokumaru wrote:
That's only one addressing mode though, and offers no speed improvements.


Got any other bright ideas for him (pubby)?

EDIT: This is not to come as any way offensive, Just trying to let others (including me) find other ideas!

_________________
AKA SmilyMZX/AtariHacker.


Top
 Profile  
 
PostPosted: Fri May 12, 2017 1:50 am 
Offline
User avatar

Joined: Sat Jan 03, 2015 5:58 pm
Posts: 366
Location: ...
From ca65's generic macpack:
Code:
; add - Add without carry
.macro  add     Arg1, Arg2
        clc
        .if .paramcount = 2
                adc     Arg1, Arg2
        .else
                adc     Arg1
        .endif
.endmacro

; sub - subtract without borrow
.macro  sub     Arg1, Arg2
        sec
        .if .paramcount = 2
                sbc     Arg1, Arg2
        .else
                sbc     Arg1
        .endif
.endmacro

You nailed it as best as it seems possible for other assemblers.


Top
 Profile  
 
PostPosted: Fri May 12, 2017 6:08 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10017
Location: Rio de Janeiro - Brazil
Hamtaro126 wrote:
Got any other bright ideas for him (pubby)?

There's nothing that can be done about speed, which's why I prefer to not use a macro like this and instead optimize the CLC/SEC out whenever the logic allows (for example, in multiplication and division routines you usually know the state of the carry before adding or subtracting).

As for the addressing modes...

nicklausw wrote:
You nailed it as best as it seems possible for other assemblers.

Yeah, AFAIK only ca65 is flexible enough to handle multiple addressing modes in macros like this.


Top
 Profile  
 
PostPosted: Fri May 12, 2017 11:42 pm 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 248
64TASS will let you do a lot of things, you can use default params to set the extra args to known things for example.
I have one that gives me an auto size length for STZ, so if I define a word and STZ the word it will clear both bytes. If I declare an int it will clear all 4 etc
Code:
STZ .macro
   lda #0
   .proff
   ;.if type(\1) == bits
   .if IsParamDirectAddress(\1)
   .pron
   sta \1
   .proff
   .else
   .pron
   sta (\1)+range(size(\1))
   .proff
   .endif
   .pron
.endm
so
Code:
myVar .byte ?
myWordVar  .word ?
myWordVarHL .dunion HLWord

#STZ myVar = lda #0 sta myVar
#STZ myWordVar = lda #0 sta myWordVar sta myWordVar+1
#STZ myWordVarHL = lda #0 sta myWordVarHL sta myWordVarHL +1
#STZ myWordVarHL.lo = lda #0 sta myWordVarHL.lo

where HLWord is defined as
HLWord .union
 .word ?
 .struct
    lo .byte ?
    hi .byte ?
 .ends
.endu
You can also make whole functions like so
Code:
dfont    .function f       
      .proff      
i      := f
      .for n = 0, n < len(f)/8, n = n + 1      
r      := bits(0)            
         .for m = 0, m < 8, m = m + 1      
r            ..= (i[0] == '#') ? %1 : %0            
i          := i[1:]            
            .if i == ''             
               .break            
            .endif            
         .next            
         .pron            
         .byte r            
         .proff                  
      .next      
      .pron      
.endf

dfontM    .function f       
      .proff      
i      := f
      .for n = 0, n < len(f)/4, n = n + 1      
r      := bits(0)            
         .for m = 0, m < 4, m = m + 1      
             .if (i[0] == '#') 
            r ..= %10
         .elsif (i[0] == '@')
            r ..= %01
         .elsif (i[0] == '*')
            r ..= %11
         .else
            r ..= %00
         .endif             
i          := i[1:]            
            .if i == ''             
               .break            
            .endif            
         .next            
         .pron            
         .byte r            
         .proff                  
      .next      
      .pron      
.endf   
these allow me to do things like
.dfont "##_##___"
.dfont "##_##___"
.dfont "#####___"
.dfont "##_##___"
.dfont "##_##___"
and it will convert it to
%11011000
%11011000
%11111000
%11011000
%11011000
The 2nd one lets me specify multicolour graphics
Code:
ILIW .macro
   .proff   
   .if \2 == x
   .pron
      ldy \1.lo,\2
      sty \3.lo
      ldy \1.hi,\2
      sty \3.hi
   .proff      
   .elsif \2 == y
   .pron
      ldx \1.lo,\2
      stx \3.lo
      ldx \1.hi,\2
      stx \3.hi
   .else
   .pron
      .cerror "invalid index input"
   .endif
.endm
lets me specify ,x or ,y on the params list.
You can also get it to do array of structs to struct of arrays conversions for you
Code:
sorted  = sort([(60, irq1), (50, irq2)])
lines   .byte sorted[:, 0] ; 50, 60
irqs    .addr sorted[:, 1] ; irq2, irq1


However if one really wants scripting power KICKASS is the insane one

It has a optimiser that you can enable which will point out most of the things you can skip, so if you want to break the macros out into full code to save a clc or sec or A is already 0 etc it will give you a nice list.


Top
 Profile  
 
PostPosted: Sun May 14, 2017 3:57 am 
Offline
User avatar

Joined: Thu Sep 15, 2016 6:29 am
Posts: 248
Location: Denmark (PAL)
lidnariq wrote:
Because SEC/ADC #0 isn't that much bigger.


Curious why you'd chose SEC/ADC#0 over CLC/ADC#1?
I get that they do the same, but the latter just seems to give a much better visual on what you are actually trying to do.


Top
 Profile  
 
PostPosted: Sun May 14, 2017 9:28 am 
Online

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6185
Location: Seattle
Because "INX" can only add one, and likewise the Carry bit only can add one.

Not saying it's a great reason.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: LightStruk, tepples and 7 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