Results 1 to 3 of 3
  1. #1
    EmuTalk Member
    Join Date
    Jan 2017
    Posts
    1
    Mentioned
    0 Post(s)

    Exclamation I have a problem with display rendering - Chip8 Emu

    Hello, thanks for read, ok, my problem is my first emulator don't working. Just in the final stage, when i think is al ready finished, appears this problem.

    don't know how fix it, i try different algorithms, but none worked. This is the code:

    i using c#.

    CPU:

      Spoiler:

    Code:
    int opcode = this.memory[this.PC] << 8 | this.memory[this.PC+ 1];
    
    this.X = (opcode & 0x0F00) >> 8;
    this.Y = (opcode & 0x00F0) >> 4;
    
    switch(opcode & 0xF000) {
       case 0xD000:
                        int spr;
                        int h = opcode & 0x000F;
    
                        this.V[0xF] = 0;
    
                        for (var y = 0; y < h; y++)
                        {
                            spr = this.memory.read(this.I + y);
    
                            for (var x = 0; x < 8; x++)
                            {
                                if ((spr & 0x80) > 0)
                                {
                                    x = this.V[this.X] + x;
                                    y = this.V[this.Y] + y;
    
                                    if (this.display.setPixel(x, y) == 1)
                                    {
                                        this.V[0xF] = 1;
                                    }
                                }
    
                                spr <<= 1;
                            }
                        }
    
                        this.DRAW_FLAG = true;
    
                        break;
    }


    Display:
      Spoiler:

    Code:
    public int setPixel(int x, int y)
            {
                if (x > 64)
                {
                    x -= this.primitiveWidth;
                }
                else if (x < 0)
                {
                    x += this.primitiveWidth;
                }
    
                if (y > 32)
                {
                    y -= this.primitiveHeight;
                }
                else if (y < 0)
                {
                    y += this.primitiveHeight;
                }
    
                var pos = x + (y * this.primitiveWidth);
    
                this.display[pos] ^= 1;
    
                return this.display[pos];
            }


    Render Display:
      Spoiler:

    Code:
    public void renderDisplay(int[] display)
            {
                Bitmap flag = new Bitmap(pic1.Width, pic1.Height);
                Graphics flagGraphics = Graphics.FromImage(flag);
    
                flagGraphics.Clear(Color.Black);
    
                for (int i = 0; i < display.Length; i++)
                {
                    double x = (i % 64) * 8;
                    double y = Math.Floor((double)i / 64) * 8;
    
                    if (display[i] == 1)
                    {
                        flagGraphics.FillRectangle(Brushes.White, (float)x, (float)y, 8, 8);
                    }
                }
    
                pic1.Image = flag;
            }


    - - - Updated - - -

    Last edited by smcd; January 10th, 2017 at 06:17. Reason: Tried to make sure image shows up

  2. #2
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    25
    Mentioned
    0 Post(s)
    Hi, I've noticed you are not fetching the right number of sprites per drawing call. A Sprite is an 8bit entity which in this case translates into an 8 pixel line. the I index actually is telling you how many sprites does the drawing routine fetch

    You are almost there you are using the I memory index in an absolute way. While in reality you have to fetch every Sprite till you reach number I

    A simple for loop will do, then process the whole array one Sprite at a time

    This is how I do it c++

    nSprites = (opcode & 0x000F);

    for (int i = 0; i < nSprites; i++)
    {
    byteSprite[i] = (memory[I + i]);
    }


    Good luck
    Last edited by ]-[ D X; January 27th, 2017 at 21:30.

  3. #3
    EmuTalk Member
    Join Date
    Aug 2016
    Posts
    25
    Mentioned
    0 Post(s)
    BTW maximum number of sprites per drawing routine is 16 so remember reseting containers (logic 0) in every pixel before processing


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •