在BitMap显示MIPS中绘制一个8x8单位 [英] drawing a 8x8 unit in BitMap Display MIPS

查看:316
本文介绍了在BitMap显示MIPS中绘制一个8x8单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的计算机结构课程中,我们正在学习汇编语言,我们必须进行蛇形游戏。它需要使用MARS IDE附带的BitMap显示,而且我遇到了问题。我设法使用以下代码绘制并将蛇从A点移动到B点:

In my computer structure class we are learning about assembly language and we've got to make a snake game. it needs to use the BitMap display that comes with the MARS IDE and there comes the problem i'm having. I managed to draw and move a "snake" from a point A to a point B with the following code:

.text

li $a2, 0x00FF0000  #loads the color red into the register $a2
li $s2,  50         #x1 = x position of the tail
li $s3, 200         #y1 = y position of the tail
li $s0, 50          #x2 = x position of the head
li $s1, 200         #y2 = y position of the head

li $t6, 100         #limit of the x axis for painting the snake for the first time

loop:
   blt $s0, $t6, DrawPixel # while the head isnt in the first limit (100) draws a pixel in (s0,s1)

loop2:
   li $t6, 400 #new head limit,when the head gets to 100, it keeps drawing but now it erases the tail
   li $v0, 32 #sleep
   li $a0, 10 #20ms
   syscall #do the sleep

   blt $s0, $t6, DrawPixel2 #draws a pixel, and deletes the tail


   beq $s2, $t6, end #sends to the label of the end of the program



DrawPixel:

addi $s0, $s0, 1         #adds 1 to the X of the head
li $t3, 0x10000100       #t3 = first Pixel of the screen

sll   $t0, $s3, 9        #y = y * 512
addu  $t0, $t0, $s0      # (xy) t0 = x + y
sll   $t0, $t0, 2        # (xy) t0 = xy * 4
addu  $t0, $t3, $t0      # adds xy to the first pixel ( t3 )
sw    $a2, ($t0)         # put the color red ($a2) in $t0


j loop                   #goes back to the drawing loop

DrawPixel2:

addi $s0, $s0, 1         #adds 1 to the X position of the head
addi $s2, $s2, 1         #adds 1 to the X position of the tail
li $t3, 0x10000100       # t3 = first pixel of the screen

#####paint the head (in red)####
sll     $t0, $s3, 9     # y = y * 512
addu    $t0, $t0, $s0   # (xy) t1 = x + y
sll     $t0, $t0, 2     # (xy) t1 = xy * 4
addu    $t0, $t3, $t0   # adds xy to the first pixel ( t3 )
li $a2, 0x00FF0000      # change the color in a2 to red
sw  $a2, ($t0)          # put the color red ($a2) in $t0

#delete the tail( painting it in black )
sll     $t0, $s3, 9     # y = y * 512
addu    $t0, $t0, $s2   # (xy) t1 = x + y
sll     $t0, $t0, 2     # (xy) t1 = xy * 4
addu    $t0, $t3, $t0   # adds xy to the first pixel ( t3 )
li $a2, 0x10000000      # set the color in a2 to black
sw  $a2, ($t0)          # put the color black($a2) in $t0

j loop2 #goes back to the loop


end:

    ####exit########
    li $v0, 10
    syscall



这会画蛇并将其水平移动。问题是蛇的宽度是1Px,因此非常薄,尝试用它来吃东西会是一种真正的痛苦。在bitmapDisplay中有一个选项来设置单位高度(以像素为单位)和单位宽度(以像素为单位),默认值为1Px * 1px,但正如我所说,太薄了。所以我试着把它设置为8x8,但它没有显示任何东西。我想我必须在代码中做一些事情来制作一个单位8px * 8px(而不是1x1),但我不知道我需要做什么。任何帮助表示赞赏。谢谢,对不起任何拼写错误,英语不是我的母语。


this draws a snake and move it horizontally. the problem is that the snake is 1Px width, so is very thin and it would be a real pain trying to eat something with it. In the bitmapDisplay there is an option to set the unit height in pixels and the unit width in pixels, the default is 1Px*1px, but as i said, is too thin. So i tried to set it to 8x8, but the it doesn't display anything. I suppose that i have to do something in the code to make an unit 8px*8px (instead of 1x1), but i have no clue of what do i need to do. Any help is appreciated. thank you and sorry for any misspell, English isn't my native language.

推荐答案

a2,0x00FF0000#将红色加载到寄存器中
a2, 0x00FF0000 #loads the color red into the register


a2
li
a2 li


s2,50#x1 = x尾部的位置
li
s2, 50 #x1 = x position of the tail li


这篇关于在BitMap显示MIPS中绘制一个8x8单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆