Advertisement
Guest User

routine calcul matrice

a guest
Mar 11th, 2015
99
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. ;doit etre appeler après que la fonction gMakeMatrix(crée la matris)
  3. ;calcule les rorttions séparéments
  4. ;entrées:  GRotateAngle_surX
  5. ;       GRotateAngle_surY
  6. ;       GRotateAngle_surZ
  7. ;       SinTable et SinTable
  8. gMatrix:   
  9.     .db 0,0,0,0,0,0,0,0,0       ;matrice 3*3
  10. gMatrixRotationCalcul:
  11.     ;recherche des sinus et cosinus dans les tables
  12.     ;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
  13.     ; pareil pour de où e<249
  14.     ld d,0
  15.     ld hl,GRotateAngle_surZ
  16.     ld b,(hl); b=z; c=y et c=x
  17.     dec hl
  18.     ld c, (hl)
  19.     push bc         ;65 T-states
  20.     dec hl
  21.     ld a,(hl)
  22.     ld c,a
  23.    
  24.     ; sin x         34
  25.     ld hl, SinTable/256
  26.     ld l,a
  27.     ld a, (hl)
  28.     ld (gSin_X),a
  29.     ; cos x         39
  30.     ld a,128
  31.     ld l,c
  32.     sub a,l
  33.     ld l,a
  34.     ld a,(hl)
  35.     ld (gCos_X),a
  36.     ;sin y          55                                      ; 295 T-states :D
  37.     pop bc
  38.     ld l,c
  39.     ld a,(hl)
  40.     ld (gSin_Y),a
  41.     neg                 ;optimisation de 9 T-states pour la 2eme case de la matrice
  42.     ld (gMatrix+1),a
  43.     ;cos y          39
  44.     ld a,128
  45.     ld l,c
  46.     sub a,l
  47.     ld l,a
  48.     ld a, (hl)
  49.     ld (gCos_Y),a
  50.     ;sin z          24
  51.     ld l,b
  52.     ld a, (hl)
  53.     ld (gSin_Z),a
  54.     ;cos z          39
  55.     ld a,128
  56.     ld l,b
  57.     sub a,l
  58.     ld l,a
  59.     ld a, (hl)
  60.     ld (gCos_Z),a
  61.    
  62.     ;calculs
  63.     ld hl, gCos_Y
  64.     ld e , (hl)
  65.     ld hl, gCos_Z
  66.     ld h, (hl)
  67.     call    mult_h_e
  68.     ld (gMatrix),a
  69.     ;64
  70.    
  71.     ld hl, gCos_Y
  72.     ld e, (hl)
  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.     ld hl, gSin_Z
  82.     ld h,(hl)
  83.     call    mult_h_e
  84.     ld c,a
  85.     ld hl,gCos_X
  86.     ld e, (hl)
  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 a,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 a,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
  177. mult_h_e
  178.     ld  l, 0
  179.     ld  d, l
  180.  
  181.     sla h       ; optimised 1st iteration
  182.     jr  nc, $+3
  183.     ld  l, e
  184.    
  185.     ld b, 7
  186. _loop:
  187.     add hl, hl          
  188.     jr  nc, $+3
  189.     add hl, de
  190.    
  191.     djnz    _loop
  192.     ld a,h
  193.     rl l
  194.     rl l
  195.     rl l
  196.     rla
  197.     rla
  198.     or 3
  199.     and l
  200.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement