first of all thanks for your relpy..
i have to draw the screen when following opcode appears in ROM
Dxyn - DRW Vx, Vy, nibble
(where x and y are 4 bit constant)
(V(0-F) are 16 register of 8-bit each, VF register is used as flag for some operations)
the Dxyn Instruction opcode is break and read byte by byte as...
opcode1 = D //any thing which is replaced by D goes in opcode1
opcode2 = x //any thing which is replaced by x in opcode goes here
opcode3 = y // any thing which is replaced by y in opcode goes here
opcode4 = n // any thing which is replaced by n in opcode goes here
the instruction say, Display n-byte sprite starting at memory location I at (Vx, Vy), set VF = collision.
The interpreter reads n bytes from memory, starting at the address stored in I. These bytes are then displayed as sprites on screen at coordinates (Vx, Vy). Sprites are XORed onto the existing screen. If this causes any pixels to be erased, VF is set to 1, otherwise it is set to 0. If the sprite is positioned so part of it is outside the coordinates of the display, it wraps around to the opposite side of the screen.
the code i have provided the DrawSprite() functions work as..
v(&HF) = 0 //initially VF register flag is set to 0
x = v(opcode2) * 4 //getting x-cordinate from instruction opcode
y = v(opcode3) * 4 //getting y-cordinates from instruction opcode
//now the forloop comes which is runnig 0 to opcode4 -1; where opcode 4 is the address of memory loaction
For j = 0 To opcode4 - 1
datax = ram(Index + j) // let suppose at any moment the value of index is 922
// when the drawSprite() function is called, it say copy
// the data of memory location ram(index+j) to datax
/////////////////////////////////////////////////////////////////////////////////////
now the following code comes which is my problem to understand that why we are comapring datax>=64, datax>=32 so on?????????? and why is 'i' incrementing??? (i is declared as a byte)
/////////////////////////////////////////////////////////////////////////////////////
Code:
i = 0
If datax >= 64 Then
DrawScreen()
datax = datax - 64
End If
i = i + 1
If datax >= 32 Then
DrawScreen()
datax = datax - 32
End If
i = i + 1
If datax >= 16 Then
DrawScreen()
datax = datax - 16
End If
i = i + 1
If datax >= 8 Then
DrawScreen()
datax = datax - 8
End If
i = i + 1
If datax >= 4 Then
DrawScreen()
datax = datax - 4
End If
i = i + 1
If datax >= 2 Then
DrawScreen()
datax = datax - 2
End If
i = i + 1
If datax >= 1 Then
DrawScreen()
datax = datax - 1
End If
Next j