Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;calcule la matris de rotation pour les angles x, y et z
- ;entrées: GRotateAngle_surX
- ; GRotateAngle_surY
- ; GRotateAngle_surZ
- ; SinTable
- gMatrix:
- .db 0,0,0,0,0,0,0,0,0 ;matrice 3*3
- gMatrixRotationCalcul:
- ;recherche des sinus et cosinus dans les tables
- ;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
- ; pareil pour de où e<249
- ld d,0
- ld hl,GRotateAngle_surZ
- ld b,(hl); b=z; c=y et c=x
- dec hl
- ld c, (hl)
- push bc ;65 T-states
- dec hl
- ld a,(hl)
- ld c,a
- ; sin x 34
- ld hl, SinTable/256
- ld l,a
- ld a, (hl)
- ld (gSin_X),a
- ; cos x 35
- ld a,128
- sub c
- ld l,a
- ld a,(hl)
- ld (gCos_X),a
- ;sin y 55 ; 283 T-states
- pop bc
- ld l,c
- ld a,(hl)
- ld (gSin_Y),a
- neg ;optimisation de 9 T-states pour la 2eme case de la matrice
- ld (gMatrix+1),a
- ;cos y 35
- ld a,128
- sub c
- ld l,a
- ld a, (hl)
- ld (gCos_Y),a
- ;sin z 24
- ld l,b
- ld a, (hl)
- ld (gSin_Z),a
- ;cos z 35
- ld a,128
- sub b
- ld l,a
- ld a, (hl)
- ld (gCos_Z),a
- ;calculs
- ld hl, gCos_Y
- ld e , (hl)
- ld hl, gCos_Z
- ld h, (hl)
- call mult_h_e
- ld (gMatrix),a
- ;64
- ld hl, gCos_Y
- ld e, (hl)
- inc hl
- ld h, (hl)
- call mult_h_e
- ld (gMatrix+2),a
- ;64
- ld hl, gSin_X
- ld e, (hl)
- ld hl, gSin_Z
- ld h,(hl)
- call mult_h_e
- ld c,a
- ld hl,gCos_X
- ld e, (hl)
- ld hl,gCos_Z
- ld h, (hl)
- call mult_h_e
- ld b,c
- ld c,a
- push bc
- ld c,b
- ld e,a
- ld hl,gSin_Y
- ld h, (hl)
- call mult_h_e
- add a,c
- ld (gMatrix+3),a
- ;184
- ld hl,gCos_X
- ld e,(hl)
- ld hl,gCos_Y
- ld h, (hl)
- call mult_h_e
- ld (gMatrix+4),a
- ;64
- ld hl, gCos_Z
- ld e,(hl)
- ld hl, gSin_X
- ld h, (hl)
- call mult_h_e
- ld c,a
- ld hl,gCos_X
- ld e,(hl)
- ld hl,gSin_Z
- ld h,(hl)
- call mult_h_e
- ld b,c
- ld c,a
- push bc
- ld c,b
- ld e,a
- ld hl, gSin_Y
- ld h, (hl)
- call mult_h_e
- sub c
- ld (gMatrix+5),a
- ;184
- pop bc
- ld e,b
- ld hl, gSin_Y
- ld h,(hl)
- call mult_h_e
- sub c
- ld (gMatrix+6),a
- ;65
- ld hl, gSin_X
- ld e, (hl)
- ld hl, gCos_Y
- ld h, (hl)
- call mult_h_e
- ld (gMatrix+9),a
- ;64
- pop bc
- ld e,b
- ld hl, gSin_Y
- ld h,(hl)
- call mult_h_e
- add a,c
- ld (gMatrix+7),a
- ;65
- ret
- gSin_X:
- .db 0
- gCos_X:
- .db 0
- gSin_Y:
- .db 0
- gCos_Y:
- .db 0
- gSin_Z:
- .db 0
- gCos_Z:
- .db 0
- ;fonction d'application de la rotation sur x,y et z
- ;entrée: ix: addresse d'écran à écrire
- ; iy: addresse le données à lire
- ;
- gRotation:
- ;multiplie fixed point à 64 et retourne dans a: résultat signé
- ; si les nombres sont positifs: 509 Tstates
- ; sinon 558
- ; si les 2 sont négatifs: 569 Tstates
- ; si 1 est égal à 0 alors: 33 ou 51 T states
- mult_h_e
- ld a,h
- or a
- jr z ,multquit
- ld a,e ; vérifie que aucun des deux nombre est égale à 0 sinon retourne à la fin de la boucle
- or a ; comme c'est très peu probable, on fait un jr qui est plus rapide si la condition n'est pas bonne
- jr z ,multquit
- xor h
- jp m,setSignMinus
- xor a
- ld (multdefsign+1),a
- jp setsignok
- setsignMinus:
- ld a,128
- ld (multdefsign+1),a
- setsignok:
- ld a,h
- and e ;si h et e sont positifs on va directement a la multiplication donc 105 T-stats
- jp p,mult_h_e_loop
- ld a,h
- or a
- jp p,skipneg ;18 ou 30
- neg
- ld h,a
- skipneg: ; si un est negatif alors 48 tstates sinon 60 tstates
- ld a,e
- or a
- jp p,mult_h_e_loop ;18 ou 30
- neg
- ld e,a
- mult_h_e_loop:
- ld l,0
- ld d, l
- sla h ; optimised 1st iteration
- jr nc, $+3
- ld l, e
- ld b, 7
- _loop:
- add hl, hl
- jr nc, $+3
- add hl, de
- djnz _loop
- ld a,h
- rla
- rla
- or 3 ;43
- ld h,a
- ld a,l
- rla
- rla
- rla
- and h
- multdefsign:
- or 128
- multquit:
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement