Need idea to do something faster

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Need idea to do something faster

Postby FedePede04 » Thu May 31, 2018 9:38 pm

Hi.
i need to convert and print a Hex number as an decimal number one digit at the time, the only way i can think of is some like this

i have not tested it, its just writing it down right now, (but have been thinking over) :D

Code: Select all

   Move.w   Number,D0
   Divu      #10,D0
   Move.w   D0,D1
   Swap    D0
   Bsr      PrintTheOne (D0)
   Divu      #10,D1
   Move.w   D1,D0
   Swap    D1
   Bsr      PrintTheTens (D1)
   Divu      #10,D0
   Move.w   D0,D1
   Swap    D0
   Bsr      PrintTheHundreds (D0)
   
   Etc.

but what i don't like with this routine is that it takes a Divu on each steep.
so if some have a fast solutions then i would be glad for some help :cheers:
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
ggn
Atari God
Atari God
Posts: 1202
Joined: Sat Dec 28, 2002 4:49 pm

Re: Need idea to do something faster

Postby ggn » Fri Jun 01, 2018 3:53 am

Here's a small gem I unearthed from Turbo Assembler's source some years ago:

Code: Select all

************************************************************************
* Dezimal-Zahl in D1 ausgeben                                          *
* Anzahl der Stellen in D4                                             *
************************************************************************
dezw_out:       movem.l D0-D5,-(SP)

                lea     dez_tab(PC),A1
                move.w  D4,D5
                lsl.w   #2,D5
                lea     4(A1,D5.w),A1
                moveq   #' ',D5
dez_loop:       move.l  -(A1),D3
                moveq   #$D0,D2
subtr:          sub.l   D3,D1
                dbcs    D2,subtr
                neg.b   D2
                move.b  D2,D0
                cmp.b   #'0',D0
                beq.s   dez_zero
                moveq   #'0',D5
dez_zero2:                              ;bsr     chrout
                move.b  D0,(A0)+

                add.l   D3,D1
                dbra    D4,dez_loop
                clr.b   (a0);           ; zero terminate
                rts
dez_zero:       move.w  D5,D0
                tst.w   D4
                bne.s   dez_zero2
                moveq   #'0',D0
                bra.s   dez_zero2

dez_tab:        DC.L 1,10,100,1000,10000,100000
                DC.L 1000000,10000000,100000000,1000000000


Just load d1 with the number you want to covert, d4 with the number of digits minus one (careful with this, you might get a crash!) and a0 with a buffer that will contain the result bytes.

I've modified it a bit to suit my needs, as you see you can replace that "move.b d0,(a0)+" with your "Bsr PrintTheOne" and remove that zero termination before the rts.

Kudos to Sören Hellwig & Markus Fritze for this of course :)

P.S. I think that your routine won't work with very large numbers either, for example if you try to divide $f000000 with 10 you'll get an overflow error as the result cannot fit in 16 bits :)
is 73 Falcon patched atari games enough ? ^^

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 4:46 am

Hi
Many many thx i have a look at this later when i wake up (get filled with coffee)....
and you right the my example only works with a word and i have to show numbers in the hundred thousand so my routine would not work. and it would take around 500 clk cycles.
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

mikro
Atari God
Atari God
Posts: 1617
Joined: Sat Sep 10, 2005 11:11 am
Location: Kosice, Slovakia
Contact:

Re: Need idea to do something faster

Postby mikro » Fri Jun 01, 2018 7:08 am

Out of curiosity, why would you want an optimised routine for task like this?

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 7:13 am

i need to print a score and a high score to the screen :)
but i want to keep it a little close for the moment, if i should go dead in the project...
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 7:30 am

ggn wrote:Here's a small gem I unearthed from Turbo Assembler's source some years ago:

Code: Select all

************************************************************************
* Dezimal-Zahl in D1 ausgeben                                          *
* Anzahl der Stellen in D4                                             *
************************************************************************
dezw_out:       movem.l D0-D5,-(SP)

                lea     dez_tab(PC),A1
                move.w  D4,D5
                lsl.w   #2,D5
                lea     4(A1,D5.w),A1
                moveq   #' ',D5
dez_loop:       move.l  -(A1),D3
                moveq   #$D0,D2
subtr:          sub.l   D3,D1
                dbcs    D2,subtr
                neg.b   D2
                move.b  D2,D0
                cmp.b   #'0',D0
                beq.s   dez_zero
                moveq   #'0',D5
dez_zero2:                              ;bsr     chrout
                move.b  D0,(A0)+

                add.l   D3,D1
                dbra    D4,dez_loop
                clr.b   (a0);           ; zero terminate
                rts
dez_zero:       move.w  D5,D0
                tst.w   D4
                bne.s   dez_zero2
                moveq   #'0',D0
                bra.s   dez_zero2

dez_tab:        DC.L 1,10,100,1000,10000,100000
                DC.L 1000000,10000000,100000000,1000000000


Just load d1 with the number you want to covert, d4 with the number of digits minus one (careful with this, you might get a crash!) and a0 with a buffer that will contain the result bytes.

I've modified it a bit to suit my needs, as you see you can replace that "move.b d0,(a0)+" with your "Bsr PrintTheOne" and remove that zero termination before the rts.

Kudos to Sören Hellwig & Markus Fritze for this of course :)

P.S. I think that your routine won't work with very large numbers either, for example if you try to divide $f000000 with 10 you'll get an overflow error as the result cannot fit in 16 bits :)


am i completely wrong when i saying, that you get the value as a CHR (string) and not a value form 0-9? :oops:
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
ggn
Atari God
Atari God
Posts: 1202
Joined: Sat Dec 28, 2002 4:49 pm

Re: Need idea to do something faster

Postby ggn » Fri Jun 01, 2018 7:42 am

FedePede04 wrote:am i completely wrong when i saying, that you get the value as a CHR (string) and not a value form 0-9? :oops:


Yes, that is correct! You get a string of ascii characters, ready to print. I guess it's possible to convert to 0-9 values if you change the '0' constants loaded to 0 (and probably a few other things). I can take a look if you can't figure it out
is 73 Falcon patched atari games enough ? ^^

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 7:50 am

if you like to have a look, then i would be very happy, i have a hard time to overlook this routine.
my brain is pretty scramble at the moment, been very stress over a long period, so i does not work like it use to :lol:
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 8:24 am

ok i been thinking a little.
my max score is 999999 (hex F423F) so if i use my routine it would not work because the result will be greater then $ffff

but if i divided instead with 100, and use a lookup list, then i think its should work and it would only take 3 div.


pseudo code (can contain errors just some i did fast in this browser)

Code: Select all


  Move.w   Number,D0
   Lea   LookupList,A0

   Divu      #100,D0
   Move.w   D0,D1
   Swap       D0
   Add.w   D0,D0
   Move.b   1(A0,D0.w),D2
   Bsr         PrintTheOne (D2)
   Move.b   (A0,D0.w),D2
   Bsr         PrintTheOne (D2)
   
   
   Divu      #100,D1
   Move.w  D1,D0
   Swap       D1
   Add.w   D1,D1
   Move.b   1(A0,D1.w),D2
   Bsr         PrintTheOne (D2)
   Move.b   (A0,D1.w),D2
   Bsr         PrintTheOne (D2)

   Divu      #100,D0
   Swap       D0
   Add.w   D0,D0
   Move.b   1(A0,D0.w),D2
   Bsr         PrintTheOne (D2)
   Move.b   (A0,D0.w),D2
   Bsr         PrintTheOne (D2)


lookuplist   
      Dc.b   0,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9
      Dc.b 1,0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9
      Dc.b 2,0,2,1,2,2,2,3,2,4,2,5,2,6,2,7,2,8,2,9
      Dc.b 3,0,3,1,3,2,3,3,3,4,3,5,3,6,3,7,3,8,3,9
      Dc.b 4,0,4,1,4,2,4,3,4,4,4,5,4,6,4,7,4,8,4,9
      Dc.b 5,0,5,1,5,2,5,3,5,4,5,5,5,6,5,7,5,8,5,9
      Dc.b 6,0,6,1,6,2,6,3,6,4,6,5,6,6,6,7,6,8,6,9
      Dc.b 7,0,7,1,7,2,7,3,7,4,7,5,7,6,7,7,7,8,7,9
      Dc.b 8,0,8,1,8,2,8,3,8,4,8,5,8,6,8,7,8,8,8,9
      Dc.b 9,0,9,1,9,2,9,3,9,4,9,5,9,6,9,7,9,8,9,9
      


i think the about code should work, but i don't know if its any good or if its to slow compare to you code :lol:
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 8:39 am

mikro wrote:Out of curiosity, why would you want an optimised routine for task like this?


btw i forgot to say
it is a Spectrum game from 1983 (msx1984) (done on many platforms) that i am play around with
but i doing it from the ground and up not using any of the original code, i have taken the original graphic and started to recolor it so it look more 16bit
(i don't know how its going to look, I am not the greatest artist out there :lol: )

but again i am doing it more for fun(and to try to keep my brain fit)
so hopeful i wont go dead in it and can release it later this year.....
Last edited by FedePede04 on Fri Jun 01, 2018 10:53 am, edited 2 times in total.
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

joska
Hardware Guru
Hardware Guru
Posts: 4013
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Need idea to do something faster

Postby joska » Fri Jun 01, 2018 9:49 am

FedePede04 wrote:i need to print a score and a high score to the screen :)


What about using the BCD instructions? No need to convert except for simple mask and shift.

http://meseec.ce.rit.edu/eecc250-winter ... 0-2000.pdf
Jo Even

Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 10:07 am

joska wrote:
FedePede04 wrote:i need to print a score and a high score to the screen :)


What about using the BCD instructions? No need to convert except for simple mask and shift.

http://meseec.ce.rit.edu/eecc250-winter ... 0-2000.pdf


Mange Tak ;)
i have seen the BCD instruction before, never really got around to use it..
for some reason i like my program to use hex numbers inside and to show decimal on the screen.
i tried my code snipe about that i made, and i work, it take around 1.5 scanline, and with printing 6 char it take around 7 scanlines, the print routine can be optimized but i don't really think for the moment that i need to do it.
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

joska
Hardware Guru
Hardware Guru
Posts: 4013
Joined: Tue Oct 30, 2007 2:55 pm
Location: Florø, Norway
Contact:

Re: Need idea to do something faster

Postby joska » Fri Jun 01, 2018 10:18 am

FedePede04 wrote:for some reason i like my program to use hex numbers inside and to show decimal on the screen.


You can have two separate variables, one normal int that you use for logic (e.g. bonus life when achieving a certain score) and one BCD used for display. Just increment both at the same time.
Jo Even

Firebee - Falcon060 - Milan060 - Falcon040 - MIST - Mega ST - STM - STE - Amiga 600 - Sharp MZ700 - MSX - Amstrad CPC - C64

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 746
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Need idea to do something faster

Postby mfro » Fri Jun 01, 2018 10:23 am

FedePede04 wrote:... for some reason i like my program to use hex numbers inside and to show decimal on the screen ...


I would assume we first need to get the wording right?

You most likely want to use binary numbers internally (because that's what the CPU can deal with best).

Hexadecimal and decimal numbers are just textual notations of binary numbers and the only reason for them to exist is that they are more readable for humans.

Consequently, you only need them where you present values to the user (or where you want the user to input a number).

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 10:35 am

yes you are right mfro binary numbers.
i just write hex because its what i see in Devpac and also because i thought it made it easier to describe my problem, but i want to see them as decimal numbers :D
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 10:44 am

joska wrote:
FedePede04 wrote:for some reason i like my program to use hex numbers inside and to show decimal on the screen.


You can have two separate variables, one normal int that you use for logic (e.g. bonus life when achieving a certain score) and one BCD used for display. Just increment both at the same time.


yes i can see that, but i think this over complicate the things, in this situation..

with the test i have done on the graphic, it look when i animate the sprite i have to skip 3 raster to make it look at the right speed, also i only have to have 8 16x16 sprite on the screen at the same time.

so in reality i have plenty of time, i just don't like to use Divu/Divs on the 68000, and i also wanted to to hear if other had some good idea.
but i have learn some great things today, how the Divu can fail and also about BCD instruction, that i can use later :D
so thx all
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 746
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Need idea to do something faster

Postby mfro » Fri Jun 01, 2018 12:31 pm

FedePede04 wrote:... i just don't like to use Divu/Divs on the 68000, and i also wanted to to hear if other had some good idea.
but i have learn some great things today, how the Divu can fail and also about BCD instruction, that i can use later :D
so thx all


What you essentially need (probably not, but you asked for it and I think it's a nice opportunity to show something - at least I consider - smart from a book I own ;) ) is a fast replacement for a division by 10 that preserves the division rest (x / 10, x % 10).

At least on Hatari (and using a C compiler), that said algorithm is roughly 6 times faster than a plain div/mod (don't know how it does on real hw).

The idea is to replace the division with a multiplication of the inverse of the divisor and replace that with an approximation of shifts and adds. This will produce a (known) error that needs to be accounted for in the end:

Code: Select all

void divmod10(long in, long *div, long *mod)
{
    /*
     * 8 / 10 = (approx.) 0.1100 1100 1100 1100 1100 1100 1100 1100
     */
    long q = (in >> 1) + (in >> 2);

    q = q + (q >> 4);
    q = q + (q >> 8);
    q = q + (q >> 16);
    q = q >> 3;

    long r = in - ((q << 3) + (q << 1));
    *div = q + (r > 9);
    if (r > 9) *mod = r - 10;
    else *mod = r;
}


The code is (more or less) a straight copy of Hacker's Delight, 2nd edition", pg. 257, Figure 10-12. A nice read, delightful ;) )

I'll leave it to you to translate it into assembler ;).

User avatar
ggn
Atari God
Atari God
Posts: 1202
Joined: Sat Dec 28, 2002 4:49 pm

Re: Need idea to do something faster

Postby ggn » Fri Jun 01, 2018 5:47 pm

mfro wrote:
FedePede04 wrote:... i just don't like to use Divu/Divs on the 68000, and i also wanted to to hear if other had some good idea.
but i have learn some great things today, how the Divu can fail and also about BCD instruction, that i can use later :D
so thx all


What you essentially need (probably not, but you asked for it and I think it's a nice opportunity to show something - at least I consider - smart from a book I own ;) ) is a fast replacement for a division by 10 that preserves the division rest (x / 10, x % 10).

At least on Hatari (and using a C compiler), that said algorithm is roughly 6 times faster than a plain div/mod (don't know how it does on real hw).

The idea is to replace the division with a multiplication of the inverse of the divisor and replace that with an approximation of shifts and adds. This will produce a (known) error that needs to be accounted for in the end:

Code: Select all

void divmod10(long in, long *div, long *mod)
{
    /*
     * 8 / 10 = (approx.) 0.1100 1100 1100 1100 1100 1100 1100 1100
     */
    long q = (in >> 1) + (in >> 2);

    q = q + (q >> 4);
    q = q + (q >> 8);
    q = q + (q >> 16);
    q = q >> 3;

    long r = in - ((q << 3) + (q << 1));
    *div = q + (r > 9);
    if (r > 9) *mod = r - 10;
    else *mod = r;
}


The code is (more or less) a straight copy of Hacker's Delight, 2nd edition", pg. 257, Figure 10-12. A nice read, delightful ;) )

I'll leave it to you to translate it into assembler ;).


Just for fun #1: I pasted this code to brownbot with gcc 8.1 and all opts on and it gave me this:

Code: Select all

divmod10:
  movem.l #12320,-(%sp)
  move.l 16(%sp),%d1
  move.l 24(%sp),%a0
  move.l %d1,%d2
  asr.l #1,%d2
  move.l %d1,%d0
  asr.l #2,%d0
  add.l %d2,%d0
  move.l %d0,%d2
  asr.l #4,%d2
  add.l %d0,%d2
  move.l %d2,%d0
  asr.l #8,%d0
  add.l %d0,%d2
  move.l %d2,%d0
  swap %d0
  ext.l %d0
  add.l %d2,%d0
  move.l %d0,%d2
  asr.l #3,%d2
  moveq #-8,%d3
  and.l %d3,%d0
  move.l %d2,%a1
  add.l %d2,%a1
  add.l %a1,%d0
  sub.l %d0,%d1
  move.l %d1,%d0
  moveq #9,%d1
  cmp.l %d0,%d1
  slt %d1
  ext.w %d1
  move.w %d1,%a1
  sub.l %a1,%d2
  move.l 20(%sp),%a2
  move.l %d2,(%a2)
  moveq #9,%d1
  cmp.l %d0,%d1
  jge .L2
  moveq #-10,%d3
  add.l %d0,%d3
  move.l %d3,(%a0)
  movem.l (%sp)+,#1036
  rts
.L2:
  move.l %d0,(%a0)
  movem.l (%sp)+,#1036
  rts
 


Maybe you can use this as a basis to do a quicker version? :)

Just for fun #2: I modified the code I posted to output an array of values from 0 to 9 instead of ascii "0" to "9":

Code: Select all

************************************************************************
* Dezimal-Zahl in D1 ausgeben                                          *
* Anzahl der Stellen in D4                                             *
************************************************************************
dezw_out:       movem.l D0-D5,-(SP)

                lea     dez_tab(PC),A1
                move.w  D4,D5
                lsl.w   #2,D5
                lea     4(A1,D5.w),A1
                moveq   #' ',D5
dez_loop:       move.l  -(A1),D3
                moveq   #$ff,D2
subtr:          sub.l   D3,D1
                dbcs    D2,subtr
                not.b   D2
                move.b  D2,D0
                cmp.b   #'0',D0
                beq.s   dez_zero
                moveq   #'0',D5
dez_zero2:                              ;bsr     chrout
                move.b  D0,(A0)+

                add.l   D3,D1
                dbra    D4,dez_loop
                clr.b   (a0);           ; zero terminate
                rts
dez_zero:       move.w  D5,D0
                tst.w   D4
                bne.s   dez_zero2
                moveq   #'0',D0
                bra.s   dez_zero2

dez_tab:        DC.L 1,10,100,1000,10000,100000
                DC.L 1000000,10000000,100000000,1000000000


Again, you can remove the "move.b d0,(a0)+" and bsr to your PrintTheOne subroutine I guess. But I would imagine that since you want to print the score you'd kinda want to have ASCII values? But I might have misread - anyway, all good fun :)
is 73 Falcon patched atari games enough ? ^^

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 6:19 pm

Thx mfro and ggn
i will try out your code tomorrow and see how much faster they are compared to mine :)
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
Eero Tamminen
Atari God
Atari God
Posts: 1712
Joined: Sun Jul 31, 2011 1:11 pm

Re: Need idea to do something faster

Postby Eero Tamminen » Fri Jun 01, 2018 7:40 pm

mfro wrote:At least on Hatari (and using a C compiler), that said algorithm is roughly 6 times faster than a plain div/mod (don't know how it does on real hw).


For ST/STE emulation, Hatari should be cycle accurate, especially for things that use just CPU.

And you can use debugger/profiler to measure the performance too.

(Just set breakpoint to start and end of the routine, use "profile on" and run the code, and Hatari will output the used cycles when it hits the breakpoint at end of the routine.)

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 9:36 pm

ok progress for today.
here is my code for now, tomorrow i will tried one of the other method.
but it takes a little more then 12 scanlines for printing 2 numbers (with 6 digits) to the screen

Code: Select all


      Text
;----------------------------------------------------------
;      D0    Data To Be Converted and Printed Long word
;      A6   Pointer   To Output Address
;----------------------------------------------------------

ConvertNumberAndPrint:   
         Lea      LookupList,A0
         Divu      #100,D0
      
         Moveq      #0,D1
         Move.w    D0,D1
         Swap       D0
         Add.w      D0,D0
         Move.b     1(A0,D0.w),D2
         Bsr        PrintTheOne       ;(D2)
         Move.b     (A0,D0.w),D2
         Bsr        PrintTheOne       ;(D2)
   
   
         Divu       #100,D1
         Moveq   #0,D0
         Move.w   D1,D0
         Swap       D1
         Add.w      D1,D1
         Move.b     1(A0,D1.w),D2
         Bsr        PrintTheOne (D2)
         Move.b     (A0,D1.w),D2
         Bsr        PrintTheOne (D2)

         Divu       #100,D0
         Swap       D0
         Add.w      D0,D0
         Move.b     1(A0,D0.w),D2
         Bsr        PrintTheOne (D2)
         Move.b     (A0,D0.w),D2
         Bsr        PrintTheOne (D2)
         Rts
      
      
PrintTheOne:
         Lea      NumberArray(PC),A1
         And.w   #$FF,D2
         Lsl.w   #5,D2
         Lea      (A1,D2.w),A1

         Moveq   #1,D2
         Move.w   A6,D4
         Btst      #0,D4
         Bne.s   PTO_JumpAddOne
         Moveq   #7,D2
PTO_JumpAddOne
         Movem.l   (A1)+,D3/D5-D7
         Movep.l   D3,(A6)
         Movep.l   D5,160(A6)
         Movep.l   D6,320(A6)
         Movep.l   D7,480(A6)
         Movem.l   (A1)+,D5-D7
         Movep.l   D5,640(A6)
         Movep.l   D6,800(A6)
         Movep.l   D7,960(A6)
         Sub.w   D2,A6      
         Rts
         
MakeNewNumber
         Lea      NUMBERS(PC),A5
         Lea      NumberArray(PC),A6
         Moveq   #9,D7
         Moveq   #1,D4
MNN_Loop         
         Movep.l   (A5),D5
         Move.l   D5,(A6)+
         Movep.l   40(A5),D5
         Move.l   D5,(A6)+
         Movep.l   80(A5),D5
         Move.l   D5,(A6)+
         Movep.l   120(A5),D5
         Move.l   D5,(A6)+
         Movep.l   160(A5),D5
         Move.l   D5,(A6)+
         Movep.l   200(A5),D5
         Move.l   D5,(A6)+
         Movep.l   240(A5),D5
         Move.l   D5,(A6)+
         Clr.l      (A6)+
         Add.w   D4,A5
         Eor.w   #%110,D4
         Dbra      D7,MNN_Loop
         Rts
         Data
         
lookuplist   
         Dc.b   0,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9
         Dc.b   1,0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9
         Dc.b   2,0,2,1,2,2,2,3,2,4,2,5,2,6,2,7,2,8,2,9
         Dc.b   3,0,3,1,3,2,3,3,3,4,3,5,3,6,3,7,3,8,3,9
         Dc.b   4,0,4,1,4,2,4,3,4,4,4,5,4,6,4,7,4,8,4,9
         Dc.b   5,0,5,1,5,2,5,3,5,4,5,5,5,6,5,7,5,8,5,9
         Dc.b   6,0,6,1,6,2,6,3,6,4,6,5,6,6,6,7,6,8,6,9
         Dc.b   7,0,7,1,7,2,7,3,7,4,7,5,7,6,7,7,7,8,7,9
         Dc.b   8,0,8,1,8,2,8,3,8,4,8,5,8,6,8,7,8,8,8,9
         Dc.b   9,0,9,1,9,2,9,3,9,4,9,5,9,6,9,7,9,8,9,9
NUMBERS      Incbin 'RESOURCE\NUMBERS.OBJ',0
NumberArray   Dcb.b   320,0      



Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
MiggyMog
Atari Super Hero
Atari Super Hero
Posts: 824
Joined: Sun Oct 30, 2005 4:43 pm
Location: Scotland

Re: Need idea to do something faster

Postby MiggyMog » Fri Jun 01, 2018 11:00 pm

M-coder shared some tips on using BCD

viewtopic.php?f=68&t=12146&hilit=Bcd
Last edited by MiggyMog on Sat Jun 02, 2018 6:51 pm, edited 1 time in total.
('< o o o o |''| STM,2xSTFM,2xSTE+HD,C-Lab Falcon MK2+HD,Satandisk,Ultrasatandisk,Ethernat.

FedePede04
Atari God
Atari God
Posts: 1025
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Need idea to do something faster

Postby FedePede04 » Fri Jun 01, 2018 11:26 pm

Thx for the link, more to read :D
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

Moulinaie
Captain Atari
Captain Atari
Posts: 201
Joined: Wed Feb 01, 2012 9:34 pm

Re: Need idea to do something faster

Postby Moulinaie » Sat Jun 02, 2018 6:57 am

FedePede04 wrote:but what i don't like with this routine is that it takes a Divu on each steep.


If you work on a 68030, you have the UNPK instruction, for example:

D0=$47 (BCD byte)

UNPK d0,d1,#$3030 (code for character 0)

then D1=$3437 (ascii for 47)

works also with :

UNPK -(a0),-(a1),#$3030

A0 points on BCD bytes and A1 on ASCII words with two digits each.

Guillaume.

Moulinaie
Captain Atari
Captain Atari
Posts: 201
Joined: Wed Feb 01, 2012 9:34 pm

Re: Need idea to do something faster

Postby Moulinaie » Sat Jun 02, 2018 7:02 am

Moulinaie wrote:
FedePede04 wrote:but what i don't like with this routine is that it takes a Divu on each steep.


If you work on a 68030, you have the UNPK instruction, for example:

D0=$47 (BCD byte)

UNPK d0,d1,#$3030 (code for character 0)

then D1=$3437 (ascii for 47)

works also with :

UNPK -(a0),-(a1),#$3030

A0 points on BCD bytes and A1 on ASCII words with two digits each.


So, if your high score is a BCD value into a long stored at SCORE,

Code: Select all

lea a0,SCORE+4
lea a1,TEXT+8
clr.b (a1)    ; an ending zero for the string
UNPK -(a0),-(a1),#$3030
UNPK -(a0),-(a1),#$3030
UNPK -(a0),-(a1),#$3030
UNPK -(a0),-(a1),#$3030


you get into TEXT the 8 ASCII digits


Guillaume.


Social Media

     

Return to “Coding”

Who is online

Users browsing this forum: insane and 3 guests