www.retrosoftware.co.uk
http://www.retrosoftware.co.uk/forum/

Modulo 80
http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=758
Page 1 of 1

Author:  PitfallJ [ Sat Mar 31, 2012 11:04 am ]
Post subject:  Modulo 80

Has anybody got a good modulo 80?

I currently use this code but have just found the number can exceed 160 so it fails:

Code:
MACRO   WRAP80
      CMP   #80
      BCC   ok781
      SEC
      SBC   #80
.ok781:
ENDMACRO


I guess I could use a table but don't want to use up 256 bytes:

Code:
  TAX
  LDA mod80,X


- PJ

Author:  PaulDv [ Sat Mar 31, 2012 12:13 pm ]
Post subject:  Re: Modulo 80

You could just repeat the test a second time to catch values over 160.

The routine can also be optimised slightly by removing the redundant SEC:

Code:
MACRO   WRAP80
      CMP   #80
      BCC   ok781
      SBC   #80
      CMP   #80
      BCC   ok781
      SBC   #80
.ok781:
ENDMACRO

Author:  RichTW [ Sat Mar 31, 2012 10:18 pm ]
Post subject:  Re: Modulo 80

In a similar vein is this, which will work for any value of A:

Code:
MACRO MOD80
    CMP #160
    BCC lessthan160
    SBC #160
    .lessthan160
    CMP #80
    BCC lessthan80
    SBC #80
    .lessthan80
ENDMACRO

Author:  PitfallJ [ Sun Apr 01, 2012 3:03 pm ]
Post subject:  Re: Modulo 80

Thanks for that - with the idea of testing it twice I've come up with this variation:

Code:
MACRO   WRAP80
.again:
      CMP   #80
      BCC   ok781
      SEC
      SBC   #80
      BNE   again
.ok781:
ENDMACRO

Author:  RichTW [ Sun Apr 01, 2012 6:01 pm ]
Post subject:  Re: Modulo 80

You don't need the SEC, as C is obviously already set if it gets there. Other than that, yep, works a treat!

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/