Odyssey Magazine #01
05 марта 1997 |
|
Assembler - How to calculate the sine assemlere.
How to calculate the sine assembly language ? Phantom Lord (C) 1997 Music by SHOV Probably many have noticed that almost all the effects are composed of objects changing or moving along a trajectory on the sine. Many of course can argue that there are effects that change their shape or coordinates does not sine. To which I can only reply: "You not right, young man! ". As said a very good scholar: Any functional relationship can be expressed in terms of functions sine and cosine. But we - mathematics and we know that sin (x) = cos (x-pi / 2), so the phrase can be transform as follows: Any functional relationship can be expressed in terms of sinus. (C) Phantom Lord We return to the topic. So we need to have sine. We define it with the level of BASIC. 10 let adr = 49152 20 for n = 0 to 2 * pi step pi/128 30 poke adr, sin (n) * 127 40 let adr = adr +1 50 next n As a result, we obtain a table of 256 bytes. Each value is the table One of the values of sin (n) * 127. We multiplied sin (n) at 127, to increase its range to [-1,1] to [-127.127]. Now if we take the values of table strictly in order, we will take successive values of sin (n) * 127. Write a program for modifying the sine color attributes of the screen. AGAIN EI HALT CALL INC_SIN CALL SIN CALL IZM LD A, # 7F IN A, (# FE) AND 1 JR NZ, AGAIN RET INC_SIN LD A, 0 INC A LD (INC_SIN +1), A RET SIN LD A, (INC_SIN +1) LD L, A LD H, # C0 LD A, (HL) RET IZM LD HL, # 5800 LD DE, # 5801 LD BC, 767 LD (HL), A LDIR RET INC_SIN procedure allows us to run the entire table, since all the values of 256, while increasing 255 per unit once we get 0, ie element belonging to the set of definitions of our function. This condition is called the frequency of the sine function. SIN procedure selects from a table sinus following value, and IZM fills the screen attributes selected value. The transition from "pure" sine to some advanced features. ABS (SIN (X)) - module sinus. Of course in mathematics of high school you probably know that the sine function module is periodic with period PI. Let's consider segment of the restriction of SIN (X) on poluotrezke [0, PI / 2). It is easy to notice in this case the functions are identical. Write a program calculated the function ABS (SIN X) based on the reasoning set forth above: A_1 CALL SIN_INC CALL SIN JR A_1 SIN_INC LD A, 0 INC A AND 127 LD (SIN_INC +1), A RET SIN ... As you can see after the team we have put INC A AND 127, thereby limiting the value of SIN only for positive numbers, ie on ABS (SIN (X)). -ABS (SIN (X)) Obviously, if prodelyvat similar arguments, we obtain a program similar to the previous one and differs from it only routine SIN_INC: SIN_INC LD A, 0 INC A AND 127 ADD A, 128 LD (SIN_INC +1), A RET Now the question may arise: And it gives our program? This will give your program the realism. Tell me, what nicer looking, by bouncing to the laws of physics ball or mayachuschuyu up-down physical form? You decide. __________________________________________
Other articles:
Similar articles:
В этот день... 23 November