Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit/AppGameKit Studio Showcase / The first ever chip8 emulator/interpeter in agk. ( Open source )

Author
Message
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 30th Jul 2016 11:40 Edited at: 9th Aug 2016 09:04
Agk Chip8


Switch 2d<>3d at runtime.


latest version 0.15


version 0.14


version 0.13.

version 0.12.

version 0.11.

version 0.1.



I used this to experiment and trying to get back at programming again and is a emulator/interpeter of the virtual machine chip8.
Always wanted to code a emulator and this is the one they all say is recomended to start with.
It have glitches as most games does it render but only a few works as they should like missiles.
Enjoy and share any progress here that you make.............
You have links to a bunch of sources to get you started in the file sources.

Chip8 have a small qwerty keyboard.
keys used.
1-4
q-r
a-f
z-v

All included roms are free and from the sources sites.

Project started here....
https://forum.thegamecreators.com/thread/217645

TOOLS
I will add a few small tools i make while writing the emulator that makes things easy.

This small thing converts hex numbers to integers in a small window with a inpput box.
Yes its plain but usefull when converting java/python code etc.
Kevin picone pointed out to me that its not a good thing to have alot of string conversions and that where very true
Now can we instead of val("0xf000",16) write 3840.


Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz

Attachments

Login to view attachments
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 30th Jul 2016 14:13
Programming king
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 30th Jul 2016 16:20 Edited at: 30th Jul 2016 16:24
Thanks
Marcus a forum regular cleaned it up as i left it in a bit off a mess
Also some smaller changes in version 0.11.

I think there is a base for more experienced coders to find the error now so we can have a first community emulator

Would be cool with some spectrum,gameboy emulators later on in agk
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 30th Jul 2016 17:32

Well done ! - Only had a quick look over some of the code and there seems to be lot of string operations inside the inner loops ? - Strings have allocations and memory copies behind them, so It's well worth getting rid of those where you can.




PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 30th Jul 2016 17:48
Thanks kevin
Ok i will experiment by converting all hex to integers and see wath happens???
I will write a simple checker app and convert them all
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 31st Jul 2016 03:36
Ok i have solved a toon of bugs now so more games work and you can set emulation speed etc

It showed that one of the bugs where that the stack pointer had to be increased after it where used and not before etc

Update later today i have to sleep now
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 31st Jul 2016 15:41 Edited at: 31st Jul 2016 15:44
So had a closer skim through at Main.AGK file , and it seems the code is using the val() function (at runtime) to convert Hex formatted strings. By which i mean, this stuff.. val("0xF00",Read_as_Hex)) . Now, If Read_as_Hex was a constant, AppGameKit might be able to compute those values at compile time, where it wouldn't really matter then.

None the less, If VAL() understands hex formatted strings, then you'd assume you can use hex literals and avoid the conversion completely.

So code like this,




becomes,




Edit:

See-> Numerical Bases

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 31st Jul 2016 15:53
it actually seams agk have issues with many bitwise operations at runtime ?

After i started doing this so did more roms work
local Opc_F000 as integer
Opc_F000 = gl.opcode && 61440 // 0xF000 = 61440

So now is it done once and i simply use Opc_F000

So i dont do so many bitwise checks at runtime

You will be suprised at the later release as i solved alot

I dont dare to experiment with hex right now as things start to work when i started using integers

Putting together the help file so will i upload wath i have so far

But when you mention it so is the font loaded as hex with no conversions where agk transforms them to integers.
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 31st Jul 2016 16:33
Latest is up on the first post her
Let me know wath you guys think
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 31st Jul 2016 16:34

Quote: "I dont dare to experiment with hex right now as things start to work when i started using integers"


you can mix and match them, it doesn't matter as the parser (in the compiler) will convert any hex / binary and common decimal literals, etc into same binary format anyway. So it doesn't matter what the source format is.

eg
print 255 = 0xFF


PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 31st Jul 2016 16:36
Will go thru it again later on
Tired of the project right now and nead some rest from it
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 1st Aug 2016 15:32
Ok kevin i had a go at clean writing the main op code call function so it now looks like this

Alot cleaner and faster

Thanks for the tip as i thought i had to convert the hex

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 1st Aug 2016 20:53
Added support for eti 600 computers also.

Found that chip8 and eti 600 is exactly the same but eti 600 start there roms at memory location 0x600 while chip8 do it at memory location 0x200
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Scene Commander
Support Manager
15
Years of Service
User Offline
Joined: 3rd May 2008
Location:
Posted: 2nd Aug 2016 07:32
Excellent work. Very impressive.
i7-4770s 3.10ghz (Passmark 9599) - Geforce GTX 650ti (Passmark 2708)
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 2nd Aug 2016 13:35
Thanks

rewriting the rom loader to use this as i belive its the error with the games??

15.5.1 x-user-defined decoder

x-user-defined's decoder's handler, given a stream and byte, runs these steps:

1.If byte is end-of-stream, return finished.


2.If byte is an ASCII byte, return a code point whose value is byte.


3.Return a code point whose value is 0xF780 + byte − 0x80.


will be in next update...
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 2nd Aug 2016 16:00

hmmm, before running off down that rabbit hole, can you post a link to the somewhere that shows the ROM format ? I suspect it's just a raw dump.




PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 2nd Aug 2016 20:46 Edited at: 2nd Aug 2016 20:48
pong looks like this


This is a bit over my head as readbyte works but some numbers gets wrong ?

I belive the java command sorts out stuff and converts it with some specific values ???
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 3rd Aug 2016 15:45
Kevin started adding a opcode checker on the loaded rom
I have to add super chip8/chip48 so we also can check for its commands on the roms
Latest files are in the top post.
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 8th Aug 2016 09:28 Edited at: 8th Aug 2016 09:33
0.14 is a fully working now and all original chip 8 games and files work now.
next update will have more games and even super chip 8 that have scrolling and a bunch off other cool stuff.
Added a bunch off small bits so alot easier if you download and check it out
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz

Attachments

Login to view attachments
Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th Aug 2016 19:33
0.15 from me,i changed the programm flow at reset (before the main was called itself inside run) and edit something else
from the rom selector you can exit the emulator now via escape


AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)

Attachments

Login to view attachments
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 9th Aug 2016 09:01
Ok downloading and adding my latest changes
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 12th Aug 2016 18:40 Edited at: 12th Aug 2016 18:59
Cliff,

Looks like it coming along.. Congrats ! - Had another peek through the V015 code noticed a few tidbits, but the one that pops out is there's a extra loop in the function opcode_DXYN() block. The inner loop is for xline = 0 to 8, so it's counting 9 times, or bits in this case ( For/next loops ranges are inclusive->inclusive).




Looking at this routine, Are the Sprites meant to wrap in the screen memory ? in terms of performance it'd be easier on the AppGameKit runtime to have two versions of the blitter routine. One with wrapping in it and other without.







What is this compare doing ?

if gfx[ b ] = 1 then v[ F ] = 1

I suspect it's collision detection

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 13th Aug 2016 14:25
Iam pretty much not started optimizing so far and more trying to get it to work

Without the screen wrapping so do some games throw errors so it where a quick hack

I havent had the time to look so much this week on it because i work night shift this and next week and are pretty tired

But looking in to hires and chip 48 aka super chip8
But its painfull to get working in agk so far.
Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz

Login to post a reply

Server time is: 2024-03-29 05:26:12
Your offset time is: 2024-03-29 05:26:12