Advertisement
Guest User

routine calcul matrice de rotation

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