所以我试图将像素移动到指定位置。像素出现在指定位置,但现在屏幕上有两个点。我想让点逐渐平滑地在屏幕上移动,就像蛇在蛇游戏中移动一样。
.data
yspeed: .word 10
# angle is 15.255
cosangle: .float 0.96
sinofangle: .float 0.44
colour: .word 0xffff0000
targetx: .word 30
targety: .word 60
width: .word 64
base: .word 0x10040000
.text
main:
li $a0, 10
li $a1, 50
#lw $s3, yspeed
lwc1 $f1, cosangle
lwc1 $f2, sinofangle
lwc1 $f3, yspeed
jal setpixel
velocity:
# x velocity
#move $f3, $s3
#move $t4, $s3
#lwc1 $f3, ($t4)
#move $f4, $s4
#move $f5, $s5
mul.s $f4, $f3, $f1
mul.s $f5, $f3, $f2
#l.s $t1, ($f4) #s4
mfc1 $t1, $f4
mfc1 $t3, $f5
#l.s $t3, ($f5)#s5
#s4 is t1, s5 is t3
move $s4, $t1
move $s5, $t3
#mul.d $s4, $s3, $f1 # x velocity is in $s4
# y velocity
#mul.d $s5, $s3, $f2 # y velocity is in $s5
#move $s4, $f4
#move $s5, $f5
jal timediff
timediff:
# calculate distance
# time is distance divided by velocity
lw $s6, targetx
lw $s2, targety
move $s0, $a0
move $s1, $a1 #s8 to s1
sub $s6, $s6, $s0 # x distance
sub $s7, $s7, $s1 # y distance
#time , dt
div $s6, $s6, $s4 # dt
div $s7, $s7, $s5 # dt
jal update
update:
move $a2, $s4
move $a3, $s5
#updating x position
add $a0, $a0, $a2
jal write_byte
# updating y position
add $a1, $a1, $a3
jal write_byte
jal setpixel1
nop
#jal updatecircleconstantly
updatecircleconstantly:
#circlepositionx + = circlepositionx/dt
#circlepositiony + = circlepositiony/dt
move $t1, $a0
move $t4, $a1
move $t5, $s6
move $t6, $s7
div $t1, $t1, $t5
div $t4, $t4, $t6
bgt $s4, 600, exit
jal updating
#blez $s4, exit
updating:
move $a2, $t1
move $a3, $t4
li $t1, 0
li $t4, 0
add $a0, $a0, $a2
add $a1, $a1, $a3
jal toupdate
jal write_byte
toupdate:
bltz $s4, updatecircleconstantly
jal moveit
#jal decrementyvel
jal write_byte
#blez $s4, exit
exit:
li $v0, 10
syscall
write_byte:
li $t7, 0xffff0008
displaywrite:
#lw $t8, ($t7)
move $t8, $t7
andi $t8, $t8, 1
beq $t8, 600, displaywrite
sw $a0, 4($t0)
jr $ra
setpixel:
lw $t0, colour
lw $s6, width
lw $s7, base
mul $t9, $a1, $s6
add $t9, $t9, $a0
sll $t9, $t9, 2
add $t9, $t9, $s7
sw $t0, ($t9)
jal moveit
nop
jal velocity
setpixel1:
lw $t0, colour
lw $s6, width
lw $s7, base
mul $t9, $a1, $s6
add $t9, $t9, $a0
sll $t9, $t9, 2
add $t9, $t9, $s7
sw $t0, ($t9)
jal updatecircleconstantly
decrementyvel: #this causes multiple dots
addi $s5, $s5, -1
jal velocity
moveit:
#li $a0, 10
#li $a1, 50
lw $s1, width
mult $s1, $a1
mflo $v0
add $v0, $v0, $a0
sll $v0, $v0, 2
add $v0, $v0, 0x10040000
jr $ra