What's new

Chip 8

Shonumi

EmuTalk Member
Maybe I am kind of biased in favor of using the GB as an intro to new emu-programmers (it was the first emulator I every programmed) but I must say that, having looked at some of the things the NES has to deal with (largely mapper support, the fact that some games are very sensitive to timing issues, and to a lesser extent unofficial opcodes that are used anyway) I think the NES is more for those on an intermediate level. You can certainly jump into it, but there's a lot to learn. There was a discussion about NES vs GB emulation on NESdev, but I can't find it at the moment. Anyway, personally, I think the GB is much more forgiving than the NES.

I recommend looking up Imram Nazar's GB emu tutorials (GB emulator in Javascript). He goes through all of the basics and, it really helped me understand how emulators worked at all. Plus, he has pictures and examples. Drop by the Game Boy thread here in emutalk if you want some help some time.

EDIT: Here is that discussion from NESdev -> http://forums.nesdev.com/viewtopic.php?f=3&t=11280
 

Danny

Programmer | Moderator
I'm currently writing a Chip-8 emulator in Swift (Apple's Swift).

Will post my progress as I go :>
 

Danny

Programmer | Moderator
So I started my Chip8 emulator last night, and also did about 4 hours on it today.

I have some progress to share (see screens).

Opcodes are about 50% (give or take) implemented, along with graphics. I have some obvious bugs in my opcode handling along with my drawing code (i'm sure).
But nice to see something on the screen :)

EDIT: Making progress! See the Pong screenshot below (Far right). Far left picture was it's state earlier.
Back to squashing my opcode bugs :p
 

Attachments

  • 1.jpg
    1.jpg
    18.4 KB · Views: 107
  • 3.jpg
    3.jpg
    20.4 KB · Views: 94
  • 2.jpg
    2.jpg
    18.3 KB · Views: 98
  • progress1.jpg
    progress1.jpg
    18.5 KB · Views: 93
Last edited:

fleroviux

Member
Yesterday I began to write a small recompiler for CHIP-8. It will be extendable so it can target to multiple architectures. For now I can only disassemble ROMs (with code and data detection) but I'll write an assembler with an extendable code generator :)

Disassembly of INVADERS (example) (not sure how accurate it's yet):
Code:
sub_200:
	jp sub_225
data_202:
	.byte 0x53
	.byte 0x50
	.byte 0x41
	.byte 0x43
	.byte 0x45
	.byte 0x20
	.byte 0x49
	.byte 0x4E
	.byte 0x56
	.byte 0x41
	.byte 0x44
	.byte 0x45
	.byte 0x52
	.byte 0x53
	.byte 0x20
	.byte 0x30
	.byte 0x2E
	.byte 0x39
	.byte 0x31
	.byte 0x20
	.byte 0x42
	.byte 0x79
	.byte 0x20
	.byte 0x44
	.byte 0x61
	.byte 0x76
	.byte 0x69
	.byte 0x64
	.byte 0x20
	.byte 0x57
	.byte 0x49
	.byte 0x4E
	.byte 0x54
	.byte 0x45
	.byte 0x52
sub_225:
	ld v0, 0x00
	ld v1, 0x00
	ld v2, 0x08
	ld i, data_3DD
sub_22D:
	drw v0, v1, 0x8
	add v1, 0x08
	add i, v2
	se v1, 0x20
	jp sub_22D
	add v0, 0x08
	ld v1, 0x00
	se v0, 0x40
	jp sub_22D
	ld v9, 0x05
	ld vC, 0x15
	ld vE, 0x00
sub_245:
	call sub_391
	ld v0, 0x0A
	ld dt, v0
sub_24B:
	ld v0, dt
	se v0, 0x00
	jp sub_24B
	call sub_391
	add vE, 0x01
	jp sub_245
sub_257:
	ld v6, 0x00
	ld v8, 0x1C
	ld v9, 0x00
	ld vA, 0x04
	ld vB, 0x0A
	ld vC, 0x04
	ld vD, 0x3C
	ld vE, 0x0F
	cls
	call sub_375
	call sub_351
	ld dt, vD
sub_26F:
	ld v0, 0x04
	skp v0
	jp sub_27D
data_275:
	.byte 0x23
	.byte 0x75
	.byte 0x38
	.byte 0x00
	.byte 0x78
	.byte 0xFF
	.byte 0x23
	.byte 0x75
sub_27D:
	ld v0, 0x06
	skp v0
	jp sub_28B
data_283:
	.byte 0x23
	.byte 0x75
	.byte 0x38
	.byte 0x39
	.byte 0x78
	.byte 0x01
	.byte 0x23
	.byte 0x75
sub_28B:
	se v6, 0x00
	jp sub_29F
	ld v0, 0x05
	skp v0
	jp sub_2E9
data_295:
	.byte 0x66
	.byte 0x01
	.byte 0x65
	.byte 0x1B
	.byte 0x84
	.byte 0x80
	.byte 0xA3
	.byte 0xD9
	.byte 0xD4
	.byte 0x51
sub_29F:
	ld i, data_3D9
	drw v4, v5, 0x1
	add v5, 0xFF
	se v5, 0xFF
	jp sub_2AD
	ld v6, 0x00
	jp sub_2E9
sub_2AD:
	drw v4, v5, 0x1
	se vF, 0x01
	jp sub_2E9
	drw v4, v5, 0x1
	ld v6, 0x00
	ld v3, v4
	add v3, 0x03
	sub v3, vB
	ld v2, 0xF8
	and v3, v2
	ld v2, 0x08
	se v3, 0x00
	jp sub_2C9
	call sub_37D
sub_2C9:
	shr v2, {, vX}
	sne v3, 0x08
	jp sub_2D3
	se v3, 0x10
	jp sub_2D5
sub_2D3:
	call sub_37D
sub_2D5:
	shr v2, {, vX}
	se v3, 0x18
	jp sub_2DD
	call sub_37D
sub_2DD:
	shr v2, {, vX}
	sne v3, 0x20
	jp sub_2E7
	se v3, 0x28
	jp sub_2E9
sub_2E7:
	call sub_37D
sub_2E9:
	se vE, 0x00
	jp sub_307
	add v9, 0x06
	sne v9, 0x18
	ld v9, 0x00
	ld vA, 0x04
	ld vB, 0x0A
	ld vC, 0x04
	add vD, 0xF4
	ld vE, 0x0F
	cls
	call sub_351
	call sub_375
	ld dt, vD
	jp sub_26F
sub_307:
	ld v7, dt
	se v7, 0x00
	jp sub_26F
	ld dt, vD
	call sub_351
	add vB, vA
	se vB, 0x12
	jp sub_31B
	add vC, 0x02
	ld vA, 0xFC
sub_31B:
	se vB, 0x02
	jp sub_323
	add vC, 0x02
	ld vA, 0x04
sub_323:
	call sub_351
	se vC, 0x18
	jp sub_26F
	cls
	ld i, data_4DD
	ld v0, 0x14
	ld v1, 0x08
	ld v2, 0x0F
sub_333:
	drw v0, v1, 0xF
	add v0, 0x08
	add i, v2
	se v0, 0x2C
	jp sub_333
	ld v0, 0xFF
	ld dt, v0
sub_341:
	ld v0, dt
	se v0, 0x00
	jp sub_341
	ld v0, k
	cls
	ld i, data_706
	ld vE, [i]
	jp sub_225
sub_351:
	ld i, data_3C1
	add i, v9
	ld v1, 0x08
	call sub_369
	shr v1, {, vX}
	call sub_369
	shr v1, {, vX}
	call sub_369
	shr v1, {, vX}
	call sub_369
	add vB, 0xD0
	ret
sub_369:
	ld v0, vE
	and v0, v1
	se v0, 0x00
	drw vB, vC, 0x6
	add vB, 0x0C
	ret
sub_375:
	ld i, data_3D9
	ld v0, 0x1C
	drw v8, v0, 0x4
	ret
sub_37D:
	call sub_351
	xor vE, v2
	call sub_351
	ld v0, 0x05
	ld st, v0
	ld dt, v0
sub_389:
	ld v0, dt
	se v0, 0x00
	jp sub_389
	ret
sub_391:
	ld vA, 0x00
	ld vD, vE
	ld vB, 0x04
	sknp v9
	jp sub_257
data_39B:
	.byte 0xA6
	.byte 0x0C
	.byte 0xFD
	.byte 0x1E
	.byte 0xF0
	.byte 0x65
	.byte 0x30
	.byte 0xFF
	.byte 0x13
	.byte 0xAF
	.byte 0x6A
	.byte 0x00
	.byte 0x6B
	.byte 0x04
	.byte 0x6D
	.byte 0x01
	.byte 0x6E
	.byte 0x01
	.byte 0x13
	.byte 0x97
	.byte 0xA5
	.byte 0x0A
	.byte 0xF0
	.byte 0x1E
	.byte 0xDB
	.byte 0xC6
	.byte 0x7B
	.byte 0x08
	.byte 0x7D
	.byte 0x01
	.byte 0x7A
	.byte 0x01
	.byte 0x3A
	.byte 0x07
	.byte 0x13
	.byte 0x97
	.byte 0x00
	.byte 0xEE
data_3C1:
	.byte 0x3C
	.byte 0x7E
	.byte 0xFF
	.byte 0xFF
	.byte 0x99
	.byte 0x99
	.byte 0x7E
	.byte 0xFF
	.byte 0xFF
	.byte 0x24
	.byte 0x24
	.byte 0xE7
	.byte 0x7E
	.byte 0xFF
	.byte 0x3C
	.byte 0x3C
	.byte 0x7E
	.byte 0xDB
	.byte 0x81
	.byte 0x42
	.byte 0x3C
	.byte 0x7E
	.byte 0xFF
	.byte 0xDB
data_3D9:
	.byte 0x10
	.byte 0x38
	.byte 0x7C
	.byte 0xFE
data_3DD:
	.byte 0x00
	.byte 0x00
	.byte 0x7F
	.byte 0x00
	.byte 0x3F
	.byte 0x00
	.byte 0x7F
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x01
	.byte 0x01
	.byte 0x01
	.byte 0x03
	.byte 0x03
	.byte 0x03
	.byte 0x03
	.byte 0x00
	.byte 0x00
	.byte 0x3F
	.byte 0x20
	.byte 0x20
	.byte 0x20
	.byte 0x20
	.byte 0x20
	.byte 0x20
	.byte 0x20
	.byte 0x20
	.byte 0x3F
	.byte 0x08
	.byte 0x08
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFE
	.byte 0x00
	.byte 0xFC
	.byte 0x00
	.byte 0xFE
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x7E
	.byte 0x42
	.byte 0x42
	.byte 0x62
	.byte 0x62
	.byte 0x62
	.byte 0x62
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x7D
	.byte 0x00
	.byte 0x41
	.byte 0x7D
	.byte 0x05
	.byte 0x7D
	.byte 0x7D
	.byte 0x00
	.byte 0x00
	.byte 0xC2
	.byte 0xC2
	.byte 0xC6
	.byte 0x44
	.byte 0x6C
	.byte 0x28
	.byte 0x38
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0xF7
	.byte 0x10
	.byte 0x14
	.byte 0xF7
	.byte 0xF7
	.byte 0x04
	.byte 0x04
	.byte 0x00
	.byte 0x00
	.byte 0x7C
	.byte 0x44
	.byte 0xFE
	.byte 0xC2
	.byte 0xC2
	.byte 0xC2
	.byte 0xC2
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0xEF
	.byte 0x20
	.byte 0x28
	.byte 0xE8
	.byte 0xE8
	.byte 0x2F
	.byte 0x2F
	.byte 0x00
	.byte 0x00
	.byte 0xF9
	.byte 0x85
	.byte 0xC5
	.byte 0xC5
	.byte 0xC5
	.byte 0xC5
	.byte 0xF9
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0xBE
	.byte 0x00
	.byte 0x20
	.byte 0x30
	.byte 0x20
	.byte 0xBE
	.byte 0xBE
	.byte 0x00
	.byte 0x00
	.byte 0xF7
	.byte 0x04
	.byte 0xE7
	.byte 0x85
	.byte 0x85
	.byte 0x84
	.byte 0xF4
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0x7F
	.byte 0x00
	.byte 0x3F
	.byte 0x00
	.byte 0x7F
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xEF
	.byte 0x28
	.byte 0xEF
	.byte 0x00
	.byte 0xE0
	.byte 0x60
	.byte 0x6F
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFF
	.byte 0x00
	.byte 0x00
	.byte 0xFE
	.byte 0x00
	.byte 0xFC
	.byte 0x00
	.byte 0xFE
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0xC0
	.byte 0x00
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0x00
	.byte 0x00
	.byte 0xFC
	.byte 0x04
	.byte 0x04
	.byte 0x04
	.byte 0x04
	.byte 0x04
	.byte 0x04
	.byte 0x04
	.byte 0x04
	.byte 0xFC
	.byte 0x10
	.byte 0x10
	.byte 0xFF
data_4DD:
	.byte 0xF9
	.byte 0x81
	.byte 0xB9
	.byte 0x8B
	.byte 0x9A
	.byte 0x9A
	.byte 0xFA
	.byte 0x00
	.byte 0xFA
	.byte 0x8A
	.byte 0x9A
	.byte 0x9A
	.byte 0x9B
	.byte 0x99
	.byte 0xF8
	.byte 0xE6
	.byte 0x25
	.byte 0x25
	.byte 0xF4
	.byte 0x34
	.byte 0x34
	.byte 0x34
	.byte 0x00
	.byte 0x17
	.byte 0x14
	.byte 0x34
	.byte 0x37
	.byte 0x36
	.byte 0x26
	.byte 0xC7
	.byte 0xDF
	.byte 0x50
	.byte 0x50
	.byte 0x5C
	.byte 0xD8
	.byte 0xD8
	.byte 0xDF
	.byte 0x00
	.byte 0xDF
	.byte 0x11
	.byte 0x1F
	.byte 0x12
	.byte 0x1B
	.byte 0x19
	.byte 0xD9
	.byte 0x7C
	.byte 0x44
	.byte 0xFE
	.byte 0x86
	.byte 0x86
	.byte 0x86
	.byte 0xFC
	.byte 0x84
	.byte 0xFE
	.byte 0x82
	.byte 0x82
	.byte 0xFE
	.byte 0xFE
	.byte 0x80
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0xFE
	.byte 0xFC
	.byte 0x82
	.byte 0xC2
	.byte 0xC2
	.byte 0xC2
	.byte 0xFC
	.byte 0xFE
	.byte 0x80
	.byte 0xF8
	.byte 0xC0
	.byte 0xC0
	.byte 0xFE
	.byte 0xFE
	.byte 0x80
	.byte 0xF0
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0xFE
	.byte 0x80
	.byte 0xBE
	.byte 0x86
	.byte 0x86
	.byte 0xFE
	.byte 0x86
	.byte 0x86
	.byte 0xFE
	.byte 0x86
	.byte 0x86
	.byte 0x86
	.byte 0x10
	.byte 0x10
	.byte 0x10
	.byte 0x10
	.byte 0x10
	.byte 0x10
	.byte 0x18
	.byte 0x18
	.byte 0x18
	.byte 0x48
	.byte 0x48
	.byte 0x78
	.byte 0x9C
	.byte 0x90
	.byte 0xB0
	.byte 0xC0
	.byte 0xB0
	.byte 0x9C
	.byte 0x80
	.byte 0x80
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0xFE
	.byte 0xEE
	.byte 0x92
	.byte 0x92
	.byte 0x86
	.byte 0x86
	.byte 0x86
	.byte 0xFE
	.byte 0x82
	.byte 0x86
	.byte 0x86
	.byte 0x86
	.byte 0x86
	.byte 0x7C
	.byte 0x82
	.byte 0x86
	.byte 0x86
	.byte 0x86
	.byte 0x7C
	.byte 0xFE
	.byte 0x82
	.byte 0xFE
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0x7C
	.byte 0x82
	.byte 0xC2
	.byte 0xCA
	.byte 0xC4
	.byte 0x7A
	.byte 0xFE
	.byte 0x86
	.byte 0xFE
	.byte 0x90
	.byte 0x9C
	.byte 0x84
	.byte 0xFE
	.byte 0xC0
	.byte 0xFE
	.byte 0x02
	.byte 0x02
	.byte 0xFE
	.byte 0xFE
	.byte 0x10
	.byte 0x30
	.byte 0x30
	.byte 0x30
	.byte 0x30
	.byte 0x82
	.byte 0x82
	.byte 0xC2
	.byte 0xC2
	.byte 0xC2
	.byte 0xFE
	.byte 0x82
	.byte 0x82
	.byte 0x82
	.byte 0xEE
	.byte 0x38
	.byte 0x10
	.byte 0x86
	.byte 0x86
	.byte 0x96
	.byte 0x92
	.byte 0x92
	.byte 0xEE
	.byte 0x82
	.byte 0x44
	.byte 0x38
	.byte 0x38
	.byte 0x44
	.byte 0x82
	.byte 0x82
	.byte 0x82
	.byte 0xFE
	.byte 0x30
	.byte 0x30
	.byte 0x30
	.byte 0xFE
	.byte 0x02
	.byte 0x1E
	.byte 0xF0
	.byte 0x80
	.byte 0xFE
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x06
	.byte 0x06
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x60
	.byte 0x60
	.byte 0xC0
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x18
	.byte 0x18
	.byte 0x18
	.byte 0x18
	.byte 0x00
	.byte 0x18
	.byte 0x7C
	.byte 0xC6
	.byte 0x0C
	.byte 0x18
	.byte 0x00
	.byte 0x18
	.byte 0x00
	.byte 0x00
	.byte 0xFE
	.byte 0xFE
	.byte 0x00
	.byte 0x00
	.byte 0xFE
	.byte 0x82
	.byte 0x86
	.byte 0x86
	.byte 0x86
	.byte 0xFE
	.byte 0x08
	.byte 0x08
	.byte 0x08
	.byte 0x18
	.byte 0x18
	.byte 0x18
	.byte 0xFE
	.byte 0x02
	.byte 0xFE
	.byte 0xC0
	.byte 0xC0
	.byte 0xFE
	.byte 0xFE
	.byte 0x02
	.byte 0x1E
	.byte 0x06
	.byte 0x06
	.byte 0xFE
	.byte 0x84
	.byte 0xC4
	.byte 0xC4
	.byte 0xFE
	.byte 0x04
	.byte 0x04
	.byte 0xFE
	.byte 0x80
	.byte 0xFE
	.byte 0x06
	.byte 0x06
	.byte 0xFE
	.byte 0xC0
	.byte 0xC0
	.byte 0xC0
	.byte 0xFE
	.byte 0x82
	.byte 0xFE
	.byte 0xFE
	.byte 0x02
	.byte 0x02
	.byte 0x06
	.byte 0x06
	.byte 0x06
	.byte 0x7C
	.byte 0x44
	.byte 0xFE
	.byte 0x86
	.byte 0x86
	.byte 0xFE
	.byte 0xFE
	.byte 0x82
	.byte 0xFE
	.byte 0x06
	.byte 0x06
	.byte 0x06
	.byte 0x44
	.byte 0xFE
	.byte 0x44
	.byte 0x44
	.byte 0xFE
	.byte 0x44
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0x6C
	.byte 0x5A
	.byte 0x00
	.byte 0x0C
	.byte 0x18
	.byte 0xA8
	.byte 0x30
	.byte 0x4E
	.byte 0x7E
	.byte 0x00
	.byte 0x12
	.byte 0x18
	.byte 0x66
	.byte 0x6C
	.byte 0xA8
	.byte 0x5A
	.byte 0x66
	.byte 0x54
	.byte 0x24
	.byte 0x66
	.byte 0x00
	.byte 0x48
	.byte 0x48
	.byte 0x18
	.byte 0x12
	.byte 0xA8
	.byte 0x06
	.byte 0x90
	.byte 0xA8
	.byte 0x12
	.byte 0x00
	.byte 0x7E
	.byte 0x30
	.byte 0x12
	.byte 0xA8
	.byte 0x84
	.byte 0x30
	.byte 0x4E
	.byte 0x72
	.byte 0x18
	.byte 0x66
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0x90
	.byte 0x54
	.byte 0x78
	.byte 0xA8
	.byte 0x48
	.byte 0x78
	.byte 0x6C
	.byte 0x72
	.byte 0xA8
	.byte 0x12
	.byte 0x18
	.byte 0x6C
	.byte 0x72
	.byte 0x66
	.byte 0x54
	.byte 0x90
	.byte 0xA8
	.byte 0x72
	.byte 0x2A
	.byte 0x18
	.byte 0xA8
	.byte 0x30
	.byte 0x4E
	.byte 0x7E
	.byte 0x00
	.byte 0x12
	.byte 0x18
	.byte 0x66
	.byte 0x6C
	.byte 0xA8
	.byte 0x72
	.byte 0x54
	.byte 0xA8
	.byte 0x5A
	.byte 0x66
	.byte 0x18
	.byte 0x7E
	.byte 0x18
	.byte 0x4E
	.byte 0x72
	.byte 0xA8
	.byte 0x72
	.byte 0x2A
	.byte 0x18
	.byte 0x30
	.byte 0x66
	.byte 0xA8
	.byte 0x30
	.byte 0x4E
	.byte 0x7E
	.byte 0x00
	.byte 0x6C
	.byte 0x30
	.byte 0x54
	.byte 0x4E
	.byte 0x9C
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0x48
	.byte 0x54
	.byte 0x7E
	.byte 0x18
	.byte 0xA8
	.byte 0x90
	.byte 0x54
	.byte 0x78
	.byte 0x66
	.byte 0xA8
	.byte 0x6C
	.byte 0x2A
	.byte 0x30
	.byte 0x5A
	.byte 0xA8
	.byte 0x84
	.byte 0x30
	.byte 0x72
	.byte 0x2A
	.byte 0xA8
	.byte 0xD8
	.byte 0xA8
	.byte 0x00
	.byte 0x4E
	.byte 0x12
	.byte 0xA8
	.byte 0xE4
	.byte 0xA2
	.byte 0xA8
	.byte 0x00
	.byte 0x4E
	.byte 0x12
	.byte 0xA8
	.byte 0x6C
	.byte 0x2A
	.byte 0x54
	.byte 0x54
	.byte 0x72
	.byte 0xA8
	.byte 0x84
	.byte 0x30
	.byte 0x72
	.byte 0x2A
	.byte 0xA8
	.byte 0xDE
	.byte 0x9C
	.byte 0xA8
	.byte 0x72
	.byte 0x2A
	.byte 0x18
	.byte 0xA8
	.byte 0x0C
	.byte 0x54
	.byte 0x48
	.byte 0x5A
	.byte 0x78
	.byte 0x72
	.byte 0x18
	.byte 0x66
	.byte 0xA8
	.byte 0x66
	.byte 0x18
	.byte 0x5A
	.byte 0x54
	.byte 0x66
	.byte 0x72
	.byte 0x6C
	.byte 0xA8
	.byte 0x72
	.byte 0x2A
	.byte 0x00
	.byte 0x72
	.byte 0xA8
	.byte 0x72
	.byte 0x2A
	.byte 0x18
	.byte 0xA8
	.byte 0x30
	.byte 0x4E
	.byte 0x7E
	.byte 0x00
	.byte 0x12
	.byte 0x18
	.byte 0x66
	.byte 0x6C
	.byte 0xA8
	.byte 0x00
	.byte 0x66
	.byte 0x18
	.byte 0xA8
	.byte 0x30
	.byte 0x4E
	.byte 0x0C
	.byte 0x66
	.byte 0x18
	.byte 0x00
	.byte 0x6C
	.byte 0x30
	.byte 0x4E
	.byte 0x24
	.byte 0xA8
	.byte 0x72
	.byte 0x2A
	.byte 0x18
	.byte 0x30
	.byte 0x66
	.byte 0xA8
	.byte 0x1E
	.byte 0x54
	.byte 0x66
	.byte 0x0C
	.byte 0x18
	.byte 0x9C
	.byte 0xA8
	.byte 0x24
	.byte 0x54
	.byte 0x54
	.byte 0x12
	.byte 0xA8
	.byte 0x42
	.byte 0x78
	.byte 0x0C
	.byte 0x3C
	.byte 0xA8
	.byte 0xAE
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xA8
	.byte 0xFF
data_706:
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
	.byte 0x00
 

Danny

Programmer | Moderator
Ok, so I ported my emulator from Swift to Objective-c, since the majority of it is C based I figure I might be able to get more advice going with a more common language (the C part at least ;)).

EDIT: NVM, i'm an idiot....
After fixing my idiocy... compatibility has taken a huge boost. With some games playable now too!

See below screenshots for some chip 8 goodness :icecream:
 

Attachments

  • O-Chip_and_ViewController_m_1.png
    O-Chip_and_ViewController_m_1.png
    15.1 KB · Views: 104
  • O-Chip_and_ViewController_m_2.png
    O-Chip_and_ViewController_m_2.png
    10 KB · Views: 100
  • O-Chip_and_ViewController_m_3.png
    O-Chip_and_ViewController_m_3.png
    11.7 KB · Views: 105
  • O-Chip_and_ViewController_m_4.png
    O-Chip_and_ViewController_m_4.png
    12 KB · Views: 108
  • O-Chip_and_ViewController_m_5.png
    O-Chip_and_ViewController_m_5.png
    10.6 KB · Views: 94
  • O-Chip_and_ViewController_m_6.png
    O-Chip_and_ViewController_m_6.png
    11.9 KB · Views: 93
  • O-Chip_and_ViewController_m.png
    O-Chip_and_ViewController_m.png
    7.8 KB · Views: 103
Last edited:
F

Fanatic 64

Guest
Remember Objetive-C is not portable outside of Mac and iOS.
 

Danny

Programmer | Moderator
Progress!

So I had another silly issue. I was setting *I* to vx instead of adding vx to *I* for opcode: FX1E.

After fixing that, most games seem playable now. But my sprites are flipped in all games? (see screenshots).
Has anyone else experienced this? And if so, what was the cause?
I'll post code up again if necessary.

Thanks in advance.
[MENTION=86296]Fanatic 64[/MENTION]: Yeah, I know. The majority is C anyway, with some Objective-C glue to tie it together.
 

Attachments

  • O-Chip_and_ViewController_m_1.png
    O-Chip_and_ViewController_m_1.png
    17.2 KB · Views: 96
  • O-Chip_and_ViewController_m_2.png
    O-Chip_and_ViewController_m_2.png
    10.2 KB · Views: 88
  • O-Chip_and_ViewController_m_3.png
    O-Chip_and_ViewController_m_3.png
    11.9 KB · Views: 95
  • O-Chip_and_ViewController_m_4.png
    O-Chip_and_ViewController_m_4.png
    10.5 KB · Views: 99
  • O-Chip_and_ViewController_m_5.png
    O-Chip_and_ViewController_m_5.png
    12.6 KB · Views: 94
  • O-Chip_and_ViewController_m_6.png
    O-Chip_and_ViewController_m_6.png
    15.9 KB · Views: 93
  • O-Chip_and_ViewController_m_7.png
    O-Chip_and_ViewController_m_7.png
    10.7 KB · Views: 98
  • O-Chip_and_ViewController_m_8.png
    O-Chip_and_ViewController_m_8.png
    11.3 KB · Views: 93
  • O-Chip_and_ViewController_m_9.png
    O-Chip_and_ViewController_m_9.png
    12.2 KB · Views: 94
  • O-Chip_and_ViewController_m.png
    O-Chip_and_ViewController_m.png
    12.8 KB · Views: 88
Last edited:

CyanPrime

New member
Hi, all.
I'm making a Chip 8 Emulator in Javascript, and progress is going great, but I ran into a problem that renders games unplayable.

Opcode 0.
This Opcode 0x0000 seems to not have any function mapped to it.
Maybe it's for idling, but I don't know how to make the emulator idle properly if that's the case.

I have no idea what it is, or what to do with it, but it seems to freeze games solid.

Here's the link to my Github of the emulator.
https://github.com/CyanPrime/Chip-8-Emu-JS

Can anyone help me understand what to do here? Any help would be very appreciated.
 

Danny

Programmer | Moderator
Hi, all.
I'm making a Chip 8 Emulator in Javascript, and progress is going great, but I ran into a problem that renders games unplayable.

Opcode 0.
This Opcode 0x0000 seems to not have any function mapped to it.
Maybe it's for idling, but I don't know how to make the emulator idle properly if that's the case.

I have no idea what it is, or what to do with it, but it seems to freeze games solid.

Here's the link to my Github of the emulator.
https://github.com/CyanPrime/Chip-8-Emu-JS

Can anyone help me understand what to do here? Any help would be very appreciated.

Your handling an opcode incorrectly, resulting in that incorrect address.
--

I took a quick glance through your source...

This:

//8XYE
//Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift.
case 0x000E:
this.V[0xF] = this.V[(this.opcode & 0x0F00) >> 8] & 0x7;
this.V[(this.opcode & 0x0F00) >> 8] >>= 1;
this.pc += 2;
break;

Should be:

//8XYE
//Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift.
case 0x000E:
this.V[0xF] = ( this.V[(this.opcode & 0x0F00) >> 8] & 0x80) >> 7; // CHANGED
this.V[(this.opcode & 0x0F00) >> 8] <<= 1; // CHANGED
this.pc += 2;
break;

--
I'll take another look tomorrow (3am here) but that is one fix at least :)
 

CyanPrime

New member
Your handling an opcode incorrectly, resulting in that incorrect address.
--

I took a quick glance through your source...

This:

//8XYE
//Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift.
case 0x000E:
this.V[0xF] = this.V[(this.opcode & 0x0F00) >> 8] & 0x7;
this.V[(this.opcode & 0x0F00) >> 8] >>= 1;
this.pc += 2;
break;

Should be:

//8XYE
//Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift.
case 0x000E:
this.V[0xF] = ( this.V[(this.opcode & 0x0F00) >> 8] & 0x80) >> 7; // CHANGED
this.V[(this.opcode & 0x0F00) >> 8] <<= 1; // CHANGED
this.pc += 2;
break;

--
I'll take another look tomorrow (3am here) but that is one fix at least :)

Thank you very much for seeing that. It didn't seem to have any effect on the current problem, but I'm sure it saved me a headache down the line, lol.

I found out my error was from not having my font loaded into memory.

However, now I get a unknown opcode of F090 after the screen clearing opcode.

I've updated Github with current source (throwing the F090 error). ...or not, because Github keeps crashing on me now :<

Here's the change:

var memory = new ArrayBuffer(0x1000);
this.memory = new Uint8Array(memory);

// Reset memory.
for (i = 0; i < this.memory.length; i++) {
this.memory = 0;
}

this.chip8_fontset =
[
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
0x20, 0x60, 0x20, 0x20, 0x70, // 1
0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3
0x90, 0x90, 0xF0, 0x10, 0x10, // 4
0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5
0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6
0xF0, 0x10, 0x20, 0x40, 0x40, // 7
0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8
0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9
0xF0, 0x90, 0xF0, 0x90, 0x90, // A
0xE0, 0x90, 0xE0, 0x90, 0xE0, // B
0xF0, 0x80, 0x80, 0x80, 0xF0, // C
0xE0, 0x90, 0x90, 0x90, 0xE0, // D
0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
0xF0, 0x80, 0xF0, 0x80, 0x80 // F
];

for (i = 0; i < this.chip8_fontset.length; i++) {
this.memory = this.chip8_fontset;
}

this.V = new Array(16);


Sorry about not being able to make this easier via github...

- - - Updated - - -

Your handling an opcode incorrectly, resulting in that incorrect address.
--

I took a quick glance through your source...

This:

//8XYE
//Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift.
case 0x000E:
this.V[0xF] = this.V[(this.opcode & 0x0F00) >> 8] & 0x7;
this.V[(this.opcode & 0x0F00) >> 8] >>= 1;
this.pc += 2;
break;

Should be:

//8XYE
//Shifts VX left by one. VF is set to the value of the most significant bit of VX before the shift.
case 0x000E:
this.V[0xF] = ( this.V[(this.opcode & 0x0F00) >> 8] & 0x80) >> 7; // CHANGED
this.V[(this.opcode & 0x0F00) >> 8] <<= 1; // CHANGED
this.pc += 2;
break;

--
I'll take another look tomorrow (3am here) but that is one fix at least :)

Thank you very much for seeing that. It didn't seem to have any effect on the current problem, but I'm sure it saved me a headache down the line, lol.

I found out my error was from not having my font loaded into memory.

However, now I get a unknown opcode of F090 after the screen clearing opcode.

I've updated Github with current source (throwing the F090 error). ...or not, because Github keeps crashing on me now :<

Here's the change:

var memory = new ArrayBuffer(0x1000);
this.memory = new Uint8Array(memory);

// Reset memory.
for (i = 0; i < this.memory.length; i++) {
this.memory = 0;
}

this.chip8_fontset =
[
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
0x20, 0x60, 0x20, 0x20, 0x70, // 1
0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3
0x90, 0x90, 0xF0, 0x10, 0x10, // 4
0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5
0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6
0xF0, 0x10, 0x20, 0x40, 0x40, // 7
0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8
0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9
0xF0, 0x90, 0xF0, 0x90, 0x90, // A
0xE0, 0x90, 0xE0, 0x90, 0xE0, // B
0xF0, 0x80, 0x80, 0x80, 0xF0, // C
0xE0, 0x90, 0x90, 0x90, 0xE0, // D
0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
0xF0, 0x80, 0xF0, 0x80, 0x80 // F
];

for (i = 0; i < this.chip8_fontset.length; i++) {
this.memory = this.chip8_fontset;
}

this.V = new Array(16);


Sorry about not being able to make this easier via github...


I FIGURED IT OUT!
I was missing a break in my switch statement. >_>

Now my only problem is that my button input seems to be not working.

If anyone can help me with that that'd be great. :D
 

Danny

Programmer | Moderator
Thank you very much for seeing that. It didn't seem to have any effect on the current problem, but I'm sure it saved me a headache down the line, lol.

I found out my error was from not having my font loaded into memory.

However, now I get a unknown opcode of F090 after the screen clearing opcode.

I've updated Github with current source (throwing the F090 error). ...or not, because Github keeps crashing on me now :<

Here's the change:



Sorry about not being able to make this easier via github...

- - - Updated - - -



Thank you very much for seeing that. It didn't seem to have any effect on the current problem, but I'm sure it saved me a headache down the line, lol.

I found out my error was from not having my font loaded into memory.

However, now I get a unknown opcode of F090 after the screen clearing opcode.

I've updated Github with current source (throwing the F090 error). ...or not, because Github keeps crashing on me now :<

Here's the change:



Sorry about not being able to make this easier via github...


I FIGURED IT OUT!
I was missing a break in my switch statement. >_>

Now my only problem is that my button input seems to be not working.

If anyone can help me with that that'd be great. :D

Awesome!

Do you happen to have the flipped graphics issue I described above?
If not, maybe you can see where i'm going wrong? I'm stumped :S

You can see how i handle control input also, to help you.
Relevant code: https://gist.github.com/DannyGlover/331078ceedfee12732f8
 

CyanPrime

New member
Awesome!

Do you happen to have the flipped graphics issue I described above?
If not, maybe you can see where i'm going wrong? I'm stumped :S

You can see how i handle control input also, to help you.
Relevant code: https://gist.github.com/DannyGlover/331078ceedfee12732f8

I'd try replacing your drawing function with this:
// Draw
- (void)draw: (id)sender {
for(int x = 0; x < 64; x++){
for(int y = 0; y < 32; y++){
// Set the pixel's color
int i = (y * 64) + x;
screen.layer.backgroundColor = ( graphics == 0 ) ? [NSColor blackColor].CGColor : [NSColor whiteColor].CGColor;
}
}
// Turn off the draw flag
drawFlag = false;
}

In my experience developing [half finished indie] games I've learned that trying to do a graphical thing without a x and y is never a good idea, lol.



Also, as for my emulator, I can't tell if it's a input problem or if the thing is just freezing, but I'm leaning towards the latter because on some games I can go past the title screen before it freezes in a black screen.

It's sending the opcode 6040. Here's what my debugging is saying about whats going on when I load BRIX.
"this.sp;2: 1" main.js:197
"this.pc1: 544" main.js:198
"this.pc2: 758" main.js:200
"set I to: 788" main.js:372
"call opcode: 6XNN" main.js:227
"full opcode: 6337" main.js:228
"this.V[x] =0" main.js:229
"(this.opcode & 0x00FF) =55" main.js:230
"(this.opcode & 0x00FF) 16 =37" main.js:231
"call opcode: 6XNN" main.js:227
"full opcode: 6400" main.js:228
"this.V[x] =0" main.js:229
"(this.opcode & 0x00FF) =0" main.js:230
"(this.opcode & 0x00FF) 16 =0" main.js:231
"call opcode 0xDXYN" main.js:386
"full opcode: d345" main.js:387
"call opcode 0xDXYN" main.js:386
"full opcode: d345" main.js:387
"Returns from subroutine" main.js:159
"this.sp;1: 1" main.js:160
"this.sp;2: 0" main.js:162
"this.pc: 778" main.js:163
"this.stack[this.sp]: 544" main.js:164
"this.pc: 544" main.js:166
"call opcode: 6XNN" main.js:227
"full opcode: 6000" main.js:228
"this.V[x] =0" main.js:229
"(this.opcode & 0x00FF) =0" main.js:230
"(this.opcode & 0x00FF) 16 =0" main.js:231
"call opcode: 6XNN" main.js:227
"full opcode: 6100" main.js:228
"this.V[x] =0" main.js:229
"(this.opcode & 0x00FF) =0" main.js:230
"(this.opcode & 0x00FF) 16 =0" main.js:231
"set I to: 786" main.js:372
"call opcode 0xDXYN" main.js:386
"full opcode: d011" main.js:387
"set I to: 782" main.js:372
"call opcode 0xDXYN" main.js:386
"full opcode: d011" main.js:387
"call opcode: 6XNN" main.js:227
"full opcode: 6040" main.js:228
"this.V[x] =8" main.js:229
"(this.opcode & 0x00FF) =64" main.js:230
"(this.opcode & 0x00FF) 16 =40" main.js:231
"jump to addr: 564"

So yeah, I'm still in need of help, lol.
 

mendus

New member
[MENTION=29773]_Zack_[/MENTION] Could it be that the Chip 8 orders pixels from left to right and top to bottom while the library you use to output does it from left to right and bottom to top? Anyway, that is not standard, so there's is probably an error in the code outputting the array screen, not in the gist you linked.
 

Danny

Programmer | Moderator
[MENTION=29773]_Zack_[/MENTION] Could it be that the Chip 8 orders pixels from left to right and top to bottom while the library you use to output does it from left to right and bottom to top? Anyway, that is not standard, so there's is probably an error in the code outputting the array screen, not in the gist you linked.

I could kiss you. That was exactly it.
I'm used to UIView's (iOS side) coordinate system of left to right, top to bottom, but NSView (on the mac side) uses left to right, bottom to top... which i didn't know of until I googled after reading your comment.

That's one more problem out of the way.
Cheers!

EDIT: See some new screens with the latest fixes below.

Todo list:

- Some games crash (2 games).
- Graphical glitches in certain games.
- Ingame bugs.
- SChip support.
- Sound/buzzer playing a sound when requested.
 

Attachments

  • BLITZ_and_ViewController_m.png
    BLITZ_and_ViewController_m.png
    14.9 KB · Views: 108
  • BRIX_and_ViewController_m.png
    BRIX_and_ViewController_m.png
    11.8 KB · Views: 93
  • INVADERS_and_ViewController_m.png
    INVADERS_and_ViewController_m.png
    17 KB · Views: 99
  • MERLIN_and_ViewController_m.png
    MERLIN_and_ViewController_m.png
    11.7 KB · Views: 87
  • PONG_and_ViewController_m.png
    PONG_and_ViewController_m.png
    11.3 KB · Views: 82
  • TETRIS_and_ViewController_m.png
    TETRIS_and_ViewController_m.png
    17.7 KB · Views: 91
  • TICTAC_and_ViewController_m.png
    TICTAC_and_ViewController_m.png
    10.7 KB · Views: 87
  • VBRIX_and_ViewController_m.png
    VBRIX_and_ViewController_m.png
    10.5 KB · Views: 86
Last edited:

Danny

Programmer | Moderator
Has anyone else ever had (or ever seen) this issue with invaders title screen? (see screenshot). That is all it draws.

The game itself works fine (after the title screen). This seems to be the only game that has this particular issue... some other games don't draw much or have missing sprites.. i would say 50% of games work as expected though (graphically).

Been digging through my source for hours now, and haven't made any headway. Kind of perplexed...:down:

Pointers welcome! (an idea what could be causing this would be most helpful).
PS: Can post updated code again if needed. Not a problem.

Cheers

EDIT: For anyone else who may experience this issue... my rom files were not being read correctly. I have a feeling that the api i was using (an obj-c api) was reading the files in text mode, instead of binary mode.
After using standard C FILE api's, the problem is solved and my compatibility is nearly 100%
 

Attachments

  • INVADERS_and_ViewController_m.png
    INVADERS_and_ViewController_m.png
    17.5 KB · Views: 582
Last edited:

CyanPrime

New member
Hi, I got my emulator working really well. The only bug I can see is that moving objects in games flicker the whole time. If anyone has had this bug, and fixed it could you let me know how?
There's a github link with my current code at the top of this page.
 

Danny

Programmer | Moderator
Hi, I got my emulator working really well. The only bug I can see is that moving objects in games flicker the whole time. If anyone has had this bug, and fixed it could you let me know how?
There's a github link with my current code at the top of this page.
[MENTION=94827]CyanPrime[/MENTION] Do you happen to have my space invaders bug?

The flickering issue is standard behaviour of the Chip8, not a bug in your emu :)

The flow for the Invaders title screen goes like this (most of the title screen ops below) - (does your output match this?)

Code:
1NNN	Jump to NNN
6XKK 	VX = KK
6XKK	        VX = KK
6XKK	        VX = KK
ANNN	I = NNN
DXYN	Draws a sprite at (VX,VY) starting at M(I). VF = collision.
7XKK	        VX = VX + KK
FX1E 	I = I + VX
3XKK	        Skip next instruction if VX == KK
1NNN	Jump to NNN
DXYN	Draws a sprite at (VX,VY) starting at M(I). VF = collision.
7XKK	        VX = VX + KK
FX1E	        I = I + VX
3XKK	        Skip next instruction if VX == KK
1NNN	Jump to NNN
DXYN	Draws a sprite at (VX,VY) starting at M(I). VF = collision.
7XKK	        VX = VX + KK
FX1E	        I = I + VX
3XKK	        Skip next instruction if VX == KK
1NNN	Jump to NNN
DXYN	Draws a sprite at (VX,VY) starting at M(I). VF = collision.
7XKK	        VX = VX + KK
FX1E	I = I + VX

And so on...
 
Last edited:

Top