Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Game Programming > Chip 8 Emulator in Vb.Net


Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2010, 12:17 PM
s33k-n-d3str0y s33k-n-d3str0y is offline
Newcomer
 
Join Date: May 2010
Posts: 6
Question Chip 8 Emulator in Vb.Net


hi friends..
i really need your help in this problem..i am trying to create chip 8 emulator in vb.net, i have coded all opcodes so far but the real problem is in drawing sprites as i have really dont have any idea of graphics and how to draw pixels.. please help me i have found this vb 6 code on internet if any one can help me in converting it to vb.net and also improve it and also tell me the logic behind that it will be highly appreciated... but pls do reply quick and keep replying as i have lot of questions but first let done this...

i have these two function that will draw pixels on a picture box..

Code:
Sub DrawSprite()
    v(&HF) = 0
   
    x = v(opcode2) * 4
    y = v(opcode3) * 4
    For j = 0 To opcode4 - 1
        datax = ram(Index + j)
        i = 0
        If datax >= 128 Then
            DrawScreen
            datax = datax - 128
        End If
        i = i + 1
        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

End Sub
Code:
Sub DrawScreen()
        If Picture1.Point(1 + x + (i * 4), y + (j * 4)) = RGB(c1, c2, c3) Then
            v(&HF) = 1
            Picture1.Line (1 + x + (i * 4), y + (j * 4))-(1 + x + (i * 4) + 3, y + (j * 4) + 3), RGB(0, 0, 0), BF
        Else
            Picture1.Line (1 + x + (i * 4), y + (j * 4))-(1 + x + (i * 4) + 3, y + (j * 4) + 3), RGB(c1, c2, c3), BF
        End If
End Sub
the problem Picture.Point and Picture.Line is no longer supported in vb.Net so ho to improve DrawScreen() function??????????
Reply With Quote
  #2  
Old 05-08-2010, 06:44 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 871
Default

If you want to programatically manipulate individual pixels, you probably want to create a Bitmap as a buffer and use LockBits to get/set image data. You can then draw the buffer Bitmap to the screen to show the rendered image.

Using the Lockbits method to access image data

If you want to render other graphics, you need to use a Graphics object, which will output the result of the drawing operations to the target it was created for. It can be used for a control (Control.CreateGraphics) or a Bitmap (Graphics.FromImage). You would probably want to look into a GDI+ tutorial.
__________________
C# _VB.NET _
Reply With Quote
  #3  
Old 05-09-2010, 02:24 AM
s33k-n-d3str0y s33k-n-d3str0y is offline
Newcomer
 
Join Date: May 2010
Posts: 6
Default understanding logic

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

Last edited by s33k-n-d3str0y; 05-09-2010 at 02:25 AM. Reason: some spelling mistakes
Reply With Quote
  #4  
Old 05-09-2010, 01:51 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 871
Default

Just to be clear, I'm not particularly familiar with Chip 8. Anyways, this code:
Code:
            If datax >= 64 Then
                DrawScreen()
                datax = datax - 64
            End If
            i = i + 1
            If datax >= 32 Then
                DrawScreen()
                datax = datax - 32
            End If

' ...
Appears to be checking bits of the byte. The first bit represents a value of 64, the second 32, so on. If you aren't familiar with binary math, you probably aren't prepared to emulate (implement?) Chip 8. If you are, this is the same as
Code:
If datax And 64 = 64 Then ' Is bit set
    DrawScreen()
    DataX = DataX And Not 64 ' Clear bit
End If
I have no idea what DrawScreen() does, and again, I don't know any of the details of Chip 8, so that's about all I can tell you. I can take a guess that i is meant to represent the index of the bit being checked.
__________________
C# _VB.NET _
Reply With Quote
Reply

Tags
chip8, emulator, graphics, pixels, sprite


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->