Advertisement
Guest User

routine calcul matrice de rotation

a guest
Mar 16th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ;calcule la matris de rotation pour les angles x, y et z
  3. ;entrées:  GRotateAngle_surX
  4. ;       GRotateAngle_surY
  5. ;       GRotateAngle_surZ
  6. ;       SinTable
  7. gMatrix:   
  8.     .db 0,0,0,0,0,0,0,0,0       ;matrice 3*3
  9. gMatrixRotationCalcul:
  10.     ;recherche des sinus et cosinus dans les tables
  11.     ;attention pour des raisons de vitesse il faut placer la table des sinus a une addresse ou h ne risque pas d'être changer comme $8000 ou $8500
  12.     ; pareil pour de où e<249
  13.     ld d,0
  14.     ld hl,GRotateAngle_surZ
  15.     ld b,(hl); b=z; c=y et c=x
  16.     dec hl
  17.     ld c, (hl)
  18.     push bc         ;65 T-states
  19.     dec hl
  20.     ld a,(hl)
  21.     ld c,a
  22.    
  23.     ; sin x         34
  24.     ld hl, SinTable/256
  25.     ld l,a
  26.     ld a, (hl)
  27.     ld (gSin_X),a
  28.     ; cos x         35
  29.     ld a,128
  30.     sub c
  31.     ld l,a
  32.     ld a,(hl)
  33.     ld (gCos_X),a
  34.     ;sin y          55                                      ; 283 T-states
  35.     pop bc
  36.     ld l,c
  37.     ld a,(hl)
  38.     ld (gSin_Y),a
  39.     neg                 ;optimisation de 9 T-states pour la 2eme case de la matrice
  40.     ld (gMatrix+1),a
  41.     ;cos y          35
  42.     ld a,128
  43.     sub c
  44.     ld l,a
  45.     ld a, (hl)
  46.     ld (gCos_Y),a
  47.     ;sin z          24
  48.     ld l,b
  49.     ld a, (hl)
  50.     ld (gSin_Z),a
  51.     ;cos z          35
  52.     ld a,128
  53.     sub b
  54.     ld l,a
  55.     ld a, (hl)
  56.     ld (gCos_Z),a
  57.    
  58.     ;calculs
  59.     ld hl, gCos_Y
  60.     ld e , (hl)
  61.    
  62.     ld hl, gCos_Z
  63.     ld h, (hl)
  64.     call    mult_h_e
  65.     ld (gMatrix),a
  66.     ;64
  67.    
  68.     ld hl, gCos_Y
  69.     ld e, (hl)
  70.    
  71.     inc hl
  72.     ld h, (hl)
  73.     call    mult_h_e
  74.     ld (gMatrix+2),a
  75.     ;64
  76.    
  77.     ld hl, gSin_X
  78.     ld e, (hl)
  79.    
  80.     ld hl, gSin_Z
  81.     ld h,(hl)
  82.     call    mult_h_e
  83.     ld c,a
  84.     ld hl,gCos_X
  85.     ld e, (hl)
  86.    
  87.     ld hl,gCos_Z
  88.     ld h, (hl)
  89.     call    mult_h_e
  90.     ld b,c
  91.     ld c,a
  92.     push bc
  93.     ld c,b
  94.     ld e,a
  95.     ld hl,gSin_Y
  96.     ld h, (hl)
  97.     call mult_h_e
  98.     add a,c
  99.     ld (gMatrix+3),a
  100.     ;184
  101.     ld hl,gCos_X
  102.     ld e,(hl)
  103.     ld hl,gCos_Y
  104.     ld h, (hl)
  105.     call mult_h_e
  106.     ld (gMatrix+4),a
  107.     ;64
  108.     ld hl, gCos_Z
  109.     ld e,(hl)
  110.     ld hl, gSin_X
  111.     ld h, (hl)
  112.     call mult_h_e
  113.     ld c,a
  114.     ld hl,gCos_X
  115.     ld e,(hl)
  116.     ld hl,gSin_Z
  117.     ld h,(hl)
  118.     call mult_h_e
  119.     ld b,c
  120.     ld c,a
  121.     push bc
  122.     ld c,b
  123.     ld e,a
  124.     ld hl, gSin_Y
  125.     ld h, (hl)
  126.     call mult_h_e
  127.     sub c
  128.     ld (gMatrix+5),a
  129.     ;184
  130.     pop bc
  131.     ld e,b
  132.     ld hl, gSin_Y
  133.     ld h,(hl)
  134.     call mult_h_e
  135.     sub c
  136.     ld (gMatrix+6),a
  137.     ;65
  138.     ld hl, gSin_X
  139.     ld e, (hl)
  140.     ld hl, gCos_Y
  141.     ld h, (hl)
  142.     call mult_h_e
  143.     ld (gMatrix+9),a
  144.     ;64
  145.     pop bc
  146.     ld e,b
  147.     ld hl, gSin_Y
  148.     ld h,(hl)
  149.     call mult_h_e
  150.     add a,c
  151.     ld (gMatrix+7),a
  152.     ;65
  153.     ret
  154. gSin_X:
  155.     .db 0  
  156. gCos_X:
  157.     .db 0
  158. gSin_Y:
  159.     .db 0  
  160. gCos_Y:
  161.     .db 0
  162. gSin_Z:
  163.     .db 0
  164. gCos_Z:
  165.     .db 0
  166.  
  167. ;fonction d'application de la rotation sur x,y et z
  168. ;entrée:   ix: addresse d'écran à écrire
  169. ;       iy: addresse le données à lire
  170. ;
  171. gRotation:
  172.    
  173.    
  174.    
  175.    
  176. ;multiplie fixed point à 64 et retourne dans a: résultat signé
  177. ; si les nombres sont positifs: 509 Tstates
  178. ; sinon 558
  179. ; si les 2 sont négatifs: 569 Tstates
  180. ; si 1 est égal à 0 alors: 33 ou  51 T states
  181. mult_h_e   
  182.     ld a,h
  183.     or a
  184.     jr z ,multquit
  185.     ld a,e          ; vérifie que aucun des deux nombre est égale à 0 sinon retourne à la fin de la boucle
  186.     or a                ; comme c'est très peu probable, on fait un jr qui est plus rapide si la condition n'est pas bonne
  187.     jr z ,multquit     
  188.     xor h
  189.     jp m,setSignMinus
  190.     xor a
  191.     ld (multdefsign+1),a
  192.     jp setsignok
  193. setsignMinus:  
  194.     ld a,128
  195.     ld (multdefsign+1),a
  196. setsignok:
  197.     ld a,h
  198.     and e               ;si h et e sont positifs on va directement a la multiplication donc 105 T-stats
  199.     jp p,mult_h_e_loop
  200.  
  201.     ld a,h         
  202.     or a
  203.     jp p,skipneg    ;18 ou 30
  204.     neg
  205.     ld h,a
  206. skipneg:                    ; si un est negatif alors 48 tstates sinon 60 tstates
  207.     ld a,e         
  208.     or a
  209.     jp p,mult_h_e_loop  ;18 ou 30
  210.     neg
  211.     ld e,a
  212.    
  213. mult_h_e_loop: 
  214.     ld l,0
  215.     ld  d, l
  216.  
  217.     sla h       ; optimised 1st iteration
  218.     jr  nc, $+3
  219.     ld  l, e
  220.    
  221.     ld b, 7
  222. _loop:
  223.     add hl, hl          
  224.     jr  nc, $+3
  225.     add hl, de
  226.    
  227.     djnz    _loop
  228.     ld a,h
  229.     rla
  230.     rla
  231.     or 3                ;43
  232.     ld h,a
  233.     ld a,l
  234.     rla
  235.     rla
  236.     rla
  237.     and h
  238. multdefsign:
  239.     or 128
  240. multquit:
  241.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement