first draw on screen!
Some checks failed
continuous-integration/drone/push Build is failing

kinda slow and no input but we good
This commit is contained in:
Sid 2020-10-11 22:54:30 +01:00
parent e10a937bd1
commit 2c01f9e603
4 changed files with 16 additions and 31 deletions

View File

@ -1,8 +1,8 @@
package chip8 package chip8
import ( import (
"fmt"
"math/rand" "math/rand"
"fmt"
) )
const graphicsBufferSize = 64 * 32 const graphicsBufferSize = 64 * 32
@ -47,7 +47,8 @@ func NewCHIP8(prog []byte) *Chip8 {
cpu := Chip8{pc: 0x200} cpu := Chip8{pc: 0x200}
memory_slice := cpu.memory[:80] memory_slice := cpu.memory[:80]
copy(memory_slice, getLetters()) copy(memory_slice, getLetters())
memory_slice = cpu.memory[200:] memory_slice = cpu.memory[0x200:]
fmt.Printf("%d\n", prog[0])
copy(memory_slice, prog) copy(memory_slice, prog)
// Do some extra checking to ensure the right // Do some extra checking to ensure the right
@ -235,7 +236,7 @@ func (cpu *Chip8) displaySprite() {
pixel := cpu.memory[int(cpu.addressRegister)+row] pixel := cpu.memory[int(cpu.addressRegister)+row]
for column := 0; column < 8; column++ { for column := 0; column < 8; column++ {
if pixel&(0x80>>column) != 0 { if pixel&(0x80>>column) != 0 {
graphicsPosition := x + column + ((y + row) * 60) graphicsPosition := x + column + ((y + row) * 64)
if cpu.graphics[graphicsPosition] == 1 { if cpu.graphics[graphicsPosition] == 1 {
cpu.registers[0xF] = 1 cpu.registers[0xF] = 1
} }
@ -332,9 +333,9 @@ func (cpu *Chip8) fifteenIndexOpcodes() {
} }
func (cpu *Chip8) PerformCycle() { func (cpu *Chip8) PerformCycle() {
var opcode uint16 = (uint16(cpu.memory[cpu.pc]) << 8) + uint16(cpu.memory[cpu.pc]) cpu.opcode = (uint16(cpu.memory[cpu.pc]) << 8) + uint16(cpu.memory[cpu.pc + 1])
cpu.pc += 2 cpu.pc += 2
switch opcode >> 12 { switch cpu.opcode >> 12 {
case 0: case 0:
cpu.zeroIndexOpcodes() cpu.zeroIndexOpcodes()
case 1: case 1:
@ -370,9 +371,3 @@ func (cpu *Chip8) PerformCycle() {
} }
} }
func main() {
fmt.Printf("Hello world!\n")
prog := []byte{1, 2, 3, 4}
new_cpu := NewCHIP8(prog)
fmt.Printf("%d\n", new_cpu.opcode)
}

View File

@ -8,5 +8,6 @@ import (
func main() { func main() {
prog := make([]byte, 6) prog := make([]byte, 6)
cpu := chip8.NewCHIP8(prog) cpu := chip8.NewCHIP8(prog)
cpu.PerformCycle()
fmt.Printf("This should print out zero: %d!\n", cpu.GetGraphicsBuffer()[0]) fmt.Printf("This should print out zero: %d!\n", cpu.GetGraphicsBuffer()[0])
} }

View File

@ -19,7 +19,6 @@ var width, height float64 = 64, 32
var sizeMultiplier = 8 var sizeMultiplier = 8
var drawBuf = [64 * 32]byte{} var drawBuf = [64 * 32]byte{}
var graphicsLock sync.Mutex var graphicsLock sync.Mutex
var sleeptime = 2000
func main() { func main() {
println("CHIP8 IS HERE!") println("CHIP8 IS HERE!")
@ -30,23 +29,7 @@ func main() {
height = float64(cvs.Height()) height = float64(cvs.Height())
width = float64(cvs.Width()) width = float64(cvs.Width())
cpu := chip8.NewCHIP8(getSpaceInvaders())
// load in a rom!!!
resp, err := http.Get("https://github.com/dmatlack/chip8/raw/master/roms/games/Space%20Invaders%20%5BDavid%20Winter%5D.ch8")
if err != nil {
println("FUCK")
panic()
}
content := make([]byte, resp.ContentLength)
n, err := resp.Body.Read(content)
if err != nil {
println("FUCK")
panic()
}
cpu := chip8.NewCHIP8(content)
cvs.Start(60, Render) cvs.Start(60, Render)
i := 0 i := 0
@ -63,13 +46,14 @@ func main() {
if i > 7 { if i > 7 {
cpu.TickTimers() cpu.TickTimers()
i = 0 i = 0
//println("here!")
} }
<-c <-c
} }
} }
func timeCycle(c chan int) { func timeCycle(c chan int) {
time.Sleep(sleeptime * time.Microsecond) time.Sleep(2000 * time.Microsecond)
c <- 0 c <- 0
} }
@ -94,6 +78,6 @@ func Render(gc *draw2dimg.GraphicContext) bool {
} }
gc.FillStroke() gc.FillStroke()
gc.Close() gc.Close()
//println("drawing")
return true return true
} }

5
cmd/web/spaceinvaders.go Normal file

File diff suppressed because one or more lines are too long