Skip to content

Commit

Permalink
fixed the render bug
Browse files Browse the repository at this point in the history
  • Loading branch information
skatiyar committed May 14, 2018
1 parent ed92983 commit 0066984
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

A practise project to learn about emulation, implements CHIP-8 in golang.

Note: Current implementation has major bug in rendering, which makes it unusable. Currently in process of hunting and solving.

## Screenshots

**__TODO__**
![Hello Chip8](https://raw.githubusercontent.com/SKatiyar/go-chip8/master/screenshot.png)

## Installing

Expand Down Expand Up @@ -39,6 +37,16 @@ Modifier sets the logical size to pixel. Default resolution supported by `CHIP8`
go run main.go 10 roms/filter.ch8
```

## Key Bindings

```
Chip8 keypad Keyboard mapping
1 | 2 | 3 | C 1 | 2 | 3 | 4
4 | 5 | 6 | D => Q | W | E | R
7 | 8 | 9 | E => A | S | D | F
A | 0 | B | F Z | X | C | V
```

## Sources

- [How to write an emulator chip-8 interpreter](http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/)
Expand Down
12 changes: 7 additions & 5 deletions emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var fontSet = []uint8{
}

type Chip8 struct {
display [64 * 32]uint8 // display size
display [32][64]uint8 // display size

memory [4096]uint8 // memory size 4k
vx [16]uint8 // cpu registers V0-VF
Expand Down Expand Up @@ -59,7 +59,7 @@ func Init() Chip8 {
return instance
}

func (c *Chip8) Buffer() [2048]uint8 {
func (c *Chip8) Buffer() [32][64]uint8 {
return c.display
}

Expand Down Expand Up @@ -89,7 +89,9 @@ func (c *Chip8) Cycle() {
switch c.oc & 0x000F {
case 0x0000: // 0x00E0 Clears screen
for i := 0; i < len(c.display); i++ {
c.display[i] = 0x0
for j := 0; j < len(c.display[i]); j++ {
c.display[i][j] = 0x0
}
}
c.shouldDraw = true
c.pc = c.pc + 2
Expand Down Expand Up @@ -204,10 +206,10 @@ func (c *Chip8) Cycle() {
pixel := c.memory[c.iv+j]
for i = 0; i < 8; i++ {
if (pixel & (0x80 >> i)) != 0 {
if c.display[x+uint8(i)+((y+uint8(j))*64)] == 1 {
if c.display[(y + uint8(j))][x+uint8(i)] == 1 {
c.vx[0xF] = 1
}
c.display[x+uint8(i)+((y+uint8(j))*64)] ^= 1
c.display[(y + uint8(j))][x+uint8(i)] ^= 1
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func main() {

// Get the display buffer and render
vector := c8.Buffer()
for j := 0; j < 32; j++ {
for i := 0; i < 64; i++ {
for j := 0; j < len(vector); j++ {
for i := 0; i < len(vector[j]); i++ {
// Values of pixel are stored in 1D array of size 64 * 32
if vector[(j*64)+i] != 0 {
if vector[j][i] != 0 {
canvas.SetDrawColor(255, 255, 0, 255)
} else {
canvas.SetDrawColor(255, 0, 0, 255)
Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0066984

Please sign in to comment.