kinda slow and no input but we good
This commit is contained in:
parent
e10a937bd1
commit
2c01f9e603
@ -1,8 +1,8 @@
|
||||
package chip8
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const graphicsBufferSize = 64 * 32
|
||||
@ -47,7 +47,8 @@ func NewCHIP8(prog []byte) *Chip8 {
|
||||
cpu := Chip8{pc: 0x200}
|
||||
memory_slice := cpu.memory[:80]
|
||||
copy(memory_slice, getLetters())
|
||||
memory_slice = cpu.memory[200:]
|
||||
memory_slice = cpu.memory[0x200:]
|
||||
fmt.Printf("%d\n", prog[0])
|
||||
copy(memory_slice, prog)
|
||||
|
||||
// Do some extra checking to ensure the right
|
||||
@ -235,7 +236,7 @@ func (cpu *Chip8) displaySprite() {
|
||||
pixel := cpu.memory[int(cpu.addressRegister)+row]
|
||||
for column := 0; column < 8; column++ {
|
||||
if pixel&(0x80>>column) != 0 {
|
||||
graphicsPosition := x + column + ((y + row) * 60)
|
||||
graphicsPosition := x + column + ((y + row) * 64)
|
||||
if cpu.graphics[graphicsPosition] == 1 {
|
||||
cpu.registers[0xF] = 1
|
||||
}
|
||||
@ -332,9 +333,9 @@ func (cpu *Chip8) fifteenIndexOpcodes() {
|
||||
}
|
||||
|
||||
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
|
||||
switch opcode >> 12 {
|
||||
switch cpu.opcode >> 12 {
|
||||
case 0:
|
||||
cpu.zeroIndexOpcodes()
|
||||
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)
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ import (
|
||||
func main() {
|
||||
prog := make([]byte, 6)
|
||||
cpu := chip8.NewCHIP8(prog)
|
||||
cpu.PerformCycle()
|
||||
fmt.Printf("This should print out zero: %d!\n", cpu.GetGraphicsBuffer()[0])
|
||||
}
|
@ -19,7 +19,6 @@ var width, height float64 = 64, 32
|
||||
var sizeMultiplier = 8
|
||||
var drawBuf = [64 * 32]byte{}
|
||||
var graphicsLock sync.Mutex
|
||||
var sleeptime = 2000
|
||||
|
||||
func main() {
|
||||
println("CHIP8 IS HERE!")
|
||||
@ -30,23 +29,7 @@ func main() {
|
||||
height = float64(cvs.Height())
|
||||
width = float64(cvs.Width())
|
||||
|
||||
|
||||
// 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)
|
||||
cpu := chip8.NewCHIP8(getSpaceInvaders())
|
||||
|
||||
cvs.Start(60, Render)
|
||||
i := 0
|
||||
@ -63,13 +46,14 @@ func main() {
|
||||
if i > 7 {
|
||||
cpu.TickTimers()
|
||||
i = 0
|
||||
//println("here!")
|
||||
}
|
||||
<-c
|
||||
}
|
||||
}
|
||||
|
||||
func timeCycle(c chan int) {
|
||||
time.Sleep(sleeptime * time.Microsecond)
|
||||
time.Sleep(2000 * time.Microsecond)
|
||||
c <- 0
|
||||
}
|
||||
|
||||
@ -94,6 +78,6 @@ func Render(gc *draw2dimg.GraphicContext) bool {
|
||||
}
|
||||
gc.FillStroke()
|
||||
gc.Close()
|
||||
|
||||
//println("drawing")
|
||||
return true
|
||||
}
|
5
cmd/web/spaceinvaders.go
Normal file
5
cmd/web/spaceinvaders.go
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user