Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Xeda112358

Pages: 1 ... 36 37 [38] 39 40 ... 317
556
ASM / Fast 8-bit Squaring
« on: January 28, 2014, 09:03:43 am »
Last night I was thinking again about my Sine Approximation routine and holy crud, I must have been really tired not to recognize this:

In the approximation, I was taking the upper 8 bits, truncating propagation. This was so that I had a fixed-point routine. But if I had taken the lower 8 bits, I would have had a useful 8-bit integer routine for -x2-x.

But wait.

If I start the accumulator with x (which is actually 3 cycles faster to do), then I end up with -x2.

Well then, anybody wanna optimize this? ^^ :
Code: [Select]
L_sqrd:
;Input: L
;Output: L*L->A
;159 t-states
;39 bytes
ld h,l
ld c,l
rr h
sbc a,a
xor l
add a,c
ld c,a
rl l

rr h
sbc a,a
xor l
and %11111000
add a,c
ld c,a
rl l

rr h
sbc a,a
xor l
and %11100000
add a,c
ld c,a
rl l

ld a,h
rrca
xor l
and 128
xor c
neg
ret

It might be more easy if I explain that it is computing:
Code: [Select]
=(hhhhhhhh^abcdefgh)+(gggggg00^bcdefg00)+(ffff0000^cdef0000)+(ee000000^de000000)
=(hhhhhhhh^abcdefgh)+(ggggg000^bcdef000)+(fff00000^cde00000)+(e0000000^d0000000)
=((hhhhhhhh^abcdefgh)+(ggggg000^bcdef000)+(fff00000^cde00000))^e0000000^d0000000

^ is XOR
+ is addition modulo 256
EDIT: Cross-posted:
I thought of a way to optimize the first iteration. Saved 2 bytes, 8 t-states.
Basically, at the first iteration, C=-1 or C=2L, then I shift L up one bit for the next iteration. I got rid of the initial ld c,a and use the first iteration to compute c. To do this, I just shift L at the beginning, then after the "sbc a,a" I just OR that with L. If a was $FF, the result is FF (which is -1), else it is 2*L:
Code: [Select]
L_sqrd:
;Input: L
;Output: L*L->A
;151 t-states
;37 bytes
ld h,l
;First iteration, get the lowest 3 bits
sla l
rrh
sbc a,a
or l
;second iteration, get the next 2 bits
ld c,a
rr h
sbc a,a
xor l
and $F8
add a,c
;third iteration, get the next 2 bits
ld c,a
sla l
rr h
sbc a,a
xor l
and $E0
add a,c
;fourth iteration, get the last bit
ld c,a
ld a,l
add a,a
rrc h
xor h
and $80
xor c
neg
ret
Also, as a note, if you stop at any iteration and perform NEG, you can mask to get the lower bits of the square. So for example, the first iteration gives you -L*L mod 8->A, the second returns -L*L mod 32->A, the third gives it mod 128.

557
Minecraft Discussion / Re: Minecraft Recruiting
« on: January 26, 2014, 02:54:54 pm »
Unfortunately, Omnimaga is not very strictly devoted to calculators. In fact, it is less so than other sites. We do computer programming and music among other things. Primarily, we make and play games and those games have inspired a number of programs.

558
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 01:51:01 pm »
Yep, that is what I am using. By the way, I am just running through the program 3 times and timing it with the given rand seeds. (I am doing it all in one program, though)

559
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 01:43:46 pm »
Do you generate a new snowflake with probability .5 ?

560
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 01:39:59 pm »
[discussion in IRC]
[time passes]
Here is my program, it just does one at a time for competition and it spits out a new flake at each iteration with probability 1/2.

561
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 01:09:15 pm »
That appears to be a bug with collision detection. Feel free to try to figure it out :P
Theoretically, the top spots should only be full if all the rest below are full.

562
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 12:53:52 pm »
It generates 2 each cycle by default.
There are 128 positions.
This will never happen :P

And in case you wanted to do a number that doesn't evenly divide into 128, this piece of the code allows exiting as soon as 128 flakes are on screen:
Code: [Select]
E+1→E
If E=128
S→B
That exits the For() loop to prevent generating any more snow flakes, then if you look at the main Repeat loop conditions:
Code: [Select]
Repeat E>=128 or getKey=45
This exits if [Clear] is pressed or E is 128 or larger. E counts how many flakes have been drawn.

563
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 12:39:05 pm »
It shouldn't freeze... I mean, theoretically, with a perfect random number generator it can, but the probability that it hasn't found an opening after n iterations is (15/16)n.

It has always worked pretty quickly for me at finding the opening. Also, my program exits when the screen is full (or clear is pressed).

564
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 12:27:00 pm »
Uh, yup, I forgot to add one line:
Code: [Select]
Ans→L2(Ans
This should be inserted before (or after, doesn't really matter) the line redrawing the new location of the snowflake.

565
Axe / Re: [Axe] Plane deformations are fun
« on: January 26, 2014, 12:01:55 pm »
Okay, cool, thanks!

566
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 11:37:02 am »
From Source Coder:
Code: [Select]
{16,8->dim([A]
DelVar EE[A]→[A]
ClrHome
2→S
Repeat E>=128 or getKey=45
For(B,1,S
Repeat not([A](Ans,1
randInt(1,16
End
Ans→[A](Ans,1
Output(1,Ans,"*
E+1→E
If E=128
S→B
End
Matr>list([A],8,L2
For(A,7,1,-1
Matr>list([A],A,L1
L1*(L1 and not(L2→L3
L1-Ans→L1
While max(L3
max(L3→B
0→L3(Ans
0→[A](B,A
Output(A,B,"
min(16,max(1,B+1-2int(2rand
If L2(Ans
B
Ans→[A](Ans,A+1
Ans→L2(Ans
Output(A+1,Ans,"*
End
L1→L2
End
End

EDIT: Forgot a line.

567
Axe / Re: [Axe] Plane deformations are fun
« on: January 26, 2014, 09:56:09 am »
That really does look cool! Is there a source? If I ever get free time, I might want to look into optimizing it with assembly or something.

568
TI Z80 / Re: Snow Demo
« on: January 26, 2014, 08:37:54 am »
Mine draws the flakes when they are newly added at the top of the screen, then it searches the matrix for snowflakes that can move down. It erases those ones and draws their new position.

Also, DJ_O, you didn't need the "1=" part of those If statements.
* Xeda112358 runs

The way I test for flakes that can move is I store the matrix rotated so that column 1 is the first row of snow flakes. Then each snow flake is represented by the column number it is in (so if it is homescreen column 6, it has a 6 in the matrix). My code is then:
Code: [Select]
Matr>list([A],8,L2 ;get the last row
For(A,7,1,-1
Matr>list([A],A,L1
L1*(L1 and not(L2→L3 ;This checks if anything in L1 can move down into L2
;"not(L2" leaves a 0 where there is already a flake, else 1 if empty
;Then "L1 and not(L2" leaves a 1 if there is a snowflake above an empty space
L1-Ans→L1 ;remove the snowflakes that can move down from L1
While max(L3
max(L3→B ;location of the snowflake furthest to the right
0→L3(Ans ;remove the snowflake from L3, the list of moveable flakes
0→[A](B,A ;remove it from the matrix
Output(A,B," ;Erase it
min(16,max(1,B+1-2int(2rand ;randomly move left/right
If L2(Ans ;check if the space is occupied
B
Ans→[A](Ans,A+1 ;write the snowflake to the new coordinate
Output(A+1,Ans,"*
End
L1→L2 ;now This row becomes the new lower row
End

569
TI Z80 / Re: ORG: online Z80 IDE and assembler
« on: January 26, 2014, 08:21:08 am »
Is that due to things like me using ORG a few dozen times in a short period of time to generate and download files?

570
TI Z80 / Re: Snow Demo
« on: January 25, 2014, 10:14:31 pm »
Judging by your screenshot, your program would actually run a lot faster with a matrix, since it seems like you are only keeping track of one snowflake at a time. I didn't realize that until just now as I was about to post my attempt x.x Mine handles multiple flakes at a time :/

EDIT: Oops, now I see that it does handle multiple flakes. I am too sleepy.

Pages: 1 ... 36 37 [38] 39 40 ... 317