Basic CHIP-8 full implemented
This commit is contained in:
parent
835f969963
commit
be61d2cedf
BIN
Display.pdf
BIN
Display.pdf
Binary file not shown.
Binary file not shown.
|
|
@ -1,205 +0,0 @@
|
|||
:alias x0 v8
|
||||
:alias x1 v9
|
||||
:alias x2 vA
|
||||
:alias y vB
|
||||
: imageok
|
||||
0xEA 0xAC 0xAA 0xEA
|
||||
: imagefalse
|
||||
0xCE 0xAA 0xAA 0xAE
|
||||
: im0
|
||||
0xE0 0xA0 0xA0 0xE0
|
||||
: im1
|
||||
0xC0 0x40 0x40 0xE0
|
||||
: im2
|
||||
0xE0 0x20 0xC0 0xE0
|
||||
: im3
|
||||
0xE0 0x60 0x20 0xE0
|
||||
: im4
|
||||
0xA0 0xE0 0x20 0x20
|
||||
: im5
|
||||
0x60 0x40 0x20 0x40
|
||||
: im6
|
||||
0xE0 0x80 0xE0 0xE0
|
||||
: im7
|
||||
0xE0 0x20 0x20 0x20
|
||||
: im8
|
||||
0xE0 0xE0 0xA0 0xE0
|
||||
: im9
|
||||
0xE0 0xE0 0x20 0xE0
|
||||
: imA
|
||||
0x40 0xA0 0xE0 0xA0
|
||||
: imE
|
||||
0xE0 0xC0 0x80 0xE0
|
||||
: imF
|
||||
0xE0 0x80 0xC0 0x80
|
||||
: imX
|
||||
0xA0 0x40 0xA0 0xA0
|
||||
|
||||
:macro drawop A B {
|
||||
i := A
|
||||
sprite x0 y 4
|
||||
i := B
|
||||
sprite x1 y 4
|
||||
}
|
||||
|
||||
: testAX
|
||||
#test Ax
|
||||
i := imageok
|
||||
sprite x2 y 4
|
||||
return
|
||||
|
||||
: test1x
|
||||
i := imageok
|
||||
sprite x2 y 4
|
||||
jump endtest
|
||||
|
||||
: main
|
||||
x0 := 1
|
||||
x1 := 5
|
||||
x2 := 10
|
||||
y := 1
|
||||
v5 := 42
|
||||
v6 := 43
|
||||
#test 3x
|
||||
drawop im3 imX
|
||||
i := imageok
|
||||
if v6 != 43 then i := imagefalse
|
||||
sprite x2 y 4
|
||||
#test 4x
|
||||
y := 6
|
||||
drawop im4 imX
|
||||
i := imagefalse
|
||||
if v5 == 42 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 5x
|
||||
y := 11
|
||||
drawop im5 imX
|
||||
i := imagefalse
|
||||
if v5 != v6 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 7x
|
||||
y := 16
|
||||
drawop im7 imX
|
||||
i := imagefalse
|
||||
v6 += 255
|
||||
if v6 == 42 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 9x
|
||||
y := 21
|
||||
drawop im9 imX
|
||||
i := imagefalse
|
||||
if v5 == v6 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test AX
|
||||
y := 26
|
||||
drawop imA imX
|
||||
testAX
|
||||
#test 0E
|
||||
x0 := 23
|
||||
x1 := 27
|
||||
x2 := 32
|
||||
y := 1
|
||||
drawop im0 imE
|
||||
i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xy0
|
||||
y := 6
|
||||
drawop im8 im0
|
||||
i := imagefalse
|
||||
v7 := v5
|
||||
if v7 == 42 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xy1
|
||||
y := 11
|
||||
drawop im8 im1
|
||||
i := imagefalse
|
||||
v7 := 42
|
||||
v7 |= y
|
||||
if v7 == 43 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xy2
|
||||
y := 16
|
||||
drawop im8 im2
|
||||
i := imagefalse
|
||||
v6 := 120
|
||||
v7 := 31
|
||||
v7 &= v6
|
||||
if v7 == 24 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xy3
|
||||
y := 21
|
||||
drawop im8 im3
|
||||
i := imagefalse
|
||||
v6 := 120
|
||||
v7 := 31
|
||||
v7 ^= v6
|
||||
if v7 == 103 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xy4
|
||||
y := 26
|
||||
drawop im8 im4
|
||||
i := imagefalse
|
||||
v6 := 140
|
||||
v7 := 140
|
||||
v7 += v6
|
||||
if v7 == 24 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xy5
|
||||
x0 := 44
|
||||
x1 := 48
|
||||
x2 := 52
|
||||
y := 1
|
||||
drawop im8 im5
|
||||
i := imagefalse
|
||||
v6 := 140
|
||||
v7 := 120
|
||||
v7 -= v6
|
||||
if v7 == 236 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xy6
|
||||
y := 6
|
||||
drawop im8 im6
|
||||
i := imagefalse
|
||||
v6 := 224
|
||||
v6 <<= v6
|
||||
if v6 == 192 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test 8xyE
|
||||
y := 11
|
||||
drawop im8 imE
|
||||
i := imagefalse
|
||||
v6 := 15
|
||||
v6 >>= v6
|
||||
if v6 == 7 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test Fx55,Fx65
|
||||
y := 16
|
||||
drawop imF im5
|
||||
i := 1000
|
||||
v0 := 0
|
||||
v1 := 48
|
||||
save v1
|
||||
i := 1001
|
||||
load v0
|
||||
i := imagefalse
|
||||
if v0 == 48 then i := imageok
|
||||
sprite x2 y 4
|
||||
#test Fx33
|
||||
y := 21
|
||||
drawop imF im3
|
||||
i := 1000
|
||||
v6 := 137
|
||||
bcd v6
|
||||
load v2
|
||||
i := imageok
|
||||
if v0 != 1 then i := imagefalse
|
||||
if v1 != 3 then i := imagefalse
|
||||
if v2 != 7 then i := imagefalse
|
||||
sprite x2 y 4
|
||||
#test 1x
|
||||
y := 26
|
||||
drawop im1 imX
|
||||
jump test1x
|
||||
: endtest
|
||||
loop
|
||||
again
|
||||
22
src/chip8.v
22
src/chip8.v
|
|
@ -95,17 +95,18 @@ fn (mut chip Chip8) decode_and_run(instruction u16) {
|
|||
mut is_jump := false
|
||||
chip.is_draw = false
|
||||
|
||||
//println(opcode_lsb)
|
||||
match opcode_msb{
|
||||
|
||||
0x0000 {
|
||||
|
||||
match opcode_msb {
|
||||
0x00EE {
|
||||
match opcode_lsb {
|
||||
0xEE {
|
||||
chip.pc = chip.stack.pop() or { panic(err) }
|
||||
// Returns from a subroutine
|
||||
}
|
||||
|
||||
0x00E0 {
|
||||
0xE0 {
|
||||
chip.is_draw = true
|
||||
for i := 0; i < chip.screen.display_height; i++{
|
||||
for j := 0; j < chip.screen.display_width; j++ {
|
||||
|
|
@ -114,9 +115,13 @@ fn (mut chip Chip8) decode_and_run(instruction u16) {
|
|||
}
|
||||
}
|
||||
|
||||
else {
|
||||
nnn = instruction & 0x0FFF
|
||||
//0NNN {
|
||||
// nnn = instruction & 0x0FFF
|
||||
// Calls machine code routine
|
||||
//}
|
||||
|
||||
else{
|
||||
panic('Invalid instruction! 0x${instruction.hex()}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -260,7 +265,7 @@ fn (mut chip Chip8) decode_and_run(instruction u16) {
|
|||
}
|
||||
|
||||
else{
|
||||
panic('Invalid instruction!')
|
||||
panic('Invalid instruction! 0x${instruction.hex()}')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -313,10 +318,9 @@ fn (mut chip Chip8) decode_and_run(instruction u16) {
|
|||
|
||||
for x_coord := 0; x_coord < 8; x_coord++ {
|
||||
|
||||
if pixel & (0x80 >> x_coord) == 1 {
|
||||
if (pixel & (0x80 >> x_coord)) != 0 {
|
||||
if chip.screen.display[regvy + y_coord][regvx + x_coord] == 1 {
|
||||
chip.v[f] = 1
|
||||
//chip.screen.display[regvy + y_coord][regvx + x_coord] = 0
|
||||
}
|
||||
|
||||
chip.screen.display[regvy + y_coord][regvx + x_coord] ^= 1
|
||||
|
|
@ -385,7 +389,7 @@ fn (mut chip Chip8) decode_and_run(instruction u16) {
|
|||
//},
|
||||
|
||||
else {
|
||||
panic('Invalid instruction!')
|
||||
panic('Invalid instruction! 0x${instruction.hex()}')
|
||||
}
|
||||
}
|
||||
if !is_jump { chip.pc += 2 }
|
||||
|
|
|
|||
25
src/main.v
25
src/main.v
|
|
@ -39,7 +39,11 @@ fn (mut emulator Emulator) load_rom() !{
|
|||
}
|
||||
}
|
||||
|
||||
fn draw_screen(mut emulator Emulator){
|
||||
fn frame(mut emulator Emulator){
|
||||
|
||||
emulator.graphic.begin()
|
||||
|
||||
emulator.chip8.run()
|
||||
|
||||
display_height := emulator.chip8.screen.display_height
|
||||
display_width := emulator.chip8.screen.display_width
|
||||
|
|
@ -54,6 +58,7 @@ fn draw_screen(mut emulator Emulator){
|
|||
}
|
||||
}
|
||||
}
|
||||
emulator.graphic.end()
|
||||
}
|
||||
|
||||
fn (mut emulator Emulator) show_display(){
|
||||
|
|
@ -138,10 +143,6 @@ fn is_graphic() bool{
|
|||
return os.environ()['DISPLAY'] != ''
|
||||
}
|
||||
|
||||
fn frame(){
|
||||
print('oi')
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
mut emulator := &Emulator{
|
||||
|
|
@ -158,23 +159,11 @@ fn main() {
|
|||
width: 1280
|
||||
height: 640
|
||||
window_title: 'V CHIP-8 Emulator'
|
||||
frame_fn : draw_screen
|
||||
frame_fn : frame
|
||||
user_data: emulator
|
||||
)
|
||||
|
||||
|
||||
|
||||
for{
|
||||
emulator.chip8.run()
|
||||
|
||||
emulator.graphic.quit()
|
||||
if emulator.chip8.is_draw {
|
||||
emulator.graphic.begin()
|
||||
emulator.show_display()
|
||||
emulator.graphic.end()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
panic('System is not graphic!')
|
||||
|
|
|
|||
Loading…
Reference in New Issue