Help with porting Arduboy core?

https://github.com/MiSTer-devel/Main_MiSTer/wiki

Moderators: Mug UK, Zorro 2, spiny, Greenious, Sorgelig, Moderator Team

Locked
User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Help with porting Arduboy core?

Post by uXe »

Hello! Got myself a DE10-Nano, and have put together the beginnings of an Arduboy 'core':

https://github.com/uXeBoy/Arduboy_MiSTer

My reason for posting here is to ask for help converting the Quartus project from being just 'DE10-Nano compatible' into something 'MiSTer compatible' - before I get too far into the weeds, and write any more that will just need to be rewritten / refactored later anyway... I don't have any familiarity with the MiSTer 'wrappers' / ecosystem / pinouts, and the learning curve is a little intimidating!

Help? 8O

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

You can take existing simple core like PET2001.
The glue logic is EMU entity. Everything higher to this entity is system framework where you should not touch anything. Everything instantiated in EMU is core specifics (yours).
You can try to port yourself.
Ask your questions and i will try to answer.

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

OK, will prepare myself for some time spent in the deep end and see how long I can hold my breath... Yellow_Colorz_PDT_47

One question immediately springs to mind - I need serial RX / TX pins, are there specific preferred GPIO pins to use for serial with MiSTer?

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

uXe wrote:I need serial RX / TX pins, are there specific preferred GPIO pins to use for serial with MiSTer?
Yes

Code: Select all

	input   [6:0] USER_IN,
	output  [6:0] USER_OUT,

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

OK... well, it wasn't easy, and it wasn't fun - but have made good progress with porting, at least to the point where it compiles successfully, haven't done any testing on hardware yet though! :D

https://github.com/uXeBoy/Arduboy_MiSTe ... boy_MiSTer

With the USER_IO - the pins are bi-directional, but I just want simple output for TX and input for RX, how would you suggest implementing this?

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

uXe wrote:With the USER_IO - the pins are bi-directional, but I just want simple output for TX and input for RX, how would you suggest implementing this?
you set 1 to output port permanently, so you can always read corresponding input port. For output simply 0/1 is enough. The output is hard 0 and pull-up 1. It's important to keep USER I/O the way it is, so if other device will be connected to the same port, then it won't compete by logic levels.

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

Progressing nicely - the Quartus project is now 'MiSTer-compatible'! (EDIT: still haven't tested the buttons though, waiting for my USB OTG cable)

Compiled Arduino hex files still need to be uploaded over serial for now (via USER_IN[0] and USER_OUT[1]) - there is a sample hex file in the root of the GitHub repo... next steps would be to get them loading from SD? :shrug:

...and then work on the sound!

(PS. THAT MUSIC IS NOT COMING FROM THE ARDUBOY - IT'S YOUTUBE FILLER!)

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

Nice progressing!

Sketches are definitely possible to load from files. It's not hard. ioctl_* signals

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

Sorgelig wrote:Sketches are definitely possible to load from files. It's not hard.
Not hard, for you. :) Hours of scouring through existing projects to figure out and understand how it works and then cobble something together, for me. :lol:

I think I'm going to concentrate on getting sound working first - honestly, it's easier for me to stick to using serial for uploading sketches while developing... but I can see that users would prefer just having pre-compiled sketches available on the SD card.

If you have the time to look at it, I would be eternally grateful to have SD loading implemented - it is not something I will be able to get to for a while...

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

I still need to finish my current tasks, but i can explain:

ioctl_download is active while downloading the file data.
ioctl_wr is activated 1 clock cycle (clk_sys) to generate write together with ioctl_addr and ioctl_dout.
So this is the basic of getting the data from file.
ioctl_addr, ioctl_dout and ioctl_wr can be directly wired to BRAM.

in conf_str you need to have: F0,HEX,Load the sketch;

I will check your project later if you won't make it work.

Indcsion
Atari nerd
Atari nerd
Posts: 44
Joined: Fri Oct 12, 2018 11:48 am

Re: Help with porting Arduboy core?

Post by Indcsion »

Cant wait

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

Still working on this... right now am trying to get a small EEPROM emulated, to be able to have some non-volatile storage for save games etc.

The only 'documentation' I could find for this was here:

http://atari-forum.com/viewtopic.php?f= ... 77#p341977

and I have the block RAM part working fine, can see my data and modify it, but the changes don't seem to be getting saved to the SD card? I have all the signals hooked up as described, but the 'automatic' side of it - where the HPS copies my 512 bytes to the SD card are not working...

Looking at the Atari800 core it seems to slightly differ from the description I linked to above - with sd_wr being immediately zeroed as soon as sd_ack is found high... and watching for a rising edge to set sd_wr / sd_rd on, I have tried to implement this, but not sure of the specifics... looking at the boot.vhd file it seems to get stuck writing just the first couple of bytes over and over, not the whole 512??

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

You need to de-activate sd_wr/sd_rd as soon as sd_ack is raised. sd_buff_* signals are supposed to be connected to BRAM directly. So using dual-port BRAM you can use one port for sd_buff_* to save/load

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

Right, well... after some more troubleshooting, it looks like sd_ack is always LOW?

I have this code in Arduboy.sv to make doubly sure rd / wr immediately go to zero if sd_ack is HIGH:

Code: Select all

assign sd_rd = (sd_ack) ? 0 : sd_rd_in;
assign sd_wr = (sd_ack) ? 0 : sd_wr_in;
and I have code like this on the Arduino side when wanting to read / write the block, to only set rd / wr when sd_ack is already LOW, and then immediately clear rd /wr when sd_ack goes HIGH:

Code: Select all

while (~(*simple_in & SD_ACK_MASK)) {*simple_out |= SD_RD_MASK;}
*simple_out &= ~(SD_RD_MASK); // sd_rd LOW

while (~(*simple_in & SD_ACK_MASK)) {*simple_out |= SD_WR_MASK;}
*simple_out &= ~(SD_WR_MASK); // sd_wr LOW
But these just stall, and the program never progresses - as if sd_ack is always LOW?

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

uXe wrote:I have this code in Arduboy.sv to make doubly sure rd / wr immediately go to zero if sd_ack is HIGH:
assign sd_rd = (sd_ack) ? 0 : sd_rd_in;
assign sd_wr = (sd_ack) ? 0 : sd_wr_in;
this won't work! When sector finishes to transfer , sd_ack will go low, and then your sd_rd/sd_wr will get original values, probably 1 and ARM will send the sector again and again.
I suggest to look the code in console cores where sd_* used for backup load/save

your CONF_STR should include option like: "S0,VHD,Mount file;" Make sure the file exist and has required size.
Or if it acts similar to backup RAM save/load per sketch, then it may act as console backup save/load.
Then you can use the same as in consoles using option "FS,HEX,Load Sketch;" In this case sav file will be created with first save. Make sure you save and load with the same amount of blocks, as file will be created with size when first time it saved.

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

I understand what you are saying, and I have tried every permutation I can think of to make this work - but at some point you have to admit defeat. Right now I feel like it is going to be easier to just write directly to the secondary SD card instead... I don't know if maybe it is just my particular card not cooperating, unless someone can show me a minimal working example that does nothing but successfully write blocks to a VHD? But trying to make sense of existing cores is starting to feel like punishment :cry:

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

OK - a week later, and finally have the sd_buff stuff working for me! :cheers:

Didn't mean to come across as overly negative earlier / above - it's just that the laptop I am using for this takes at least half an hour to compile before I can test any changes made... so working by trial-and-error can quickly turn into hours, which can quickly turn into days!!

Indcsion
Atari nerd
Atari nerd
Posts: 44
Joined: Fri Oct 12, 2018 11:48 am

Re: Help with porting Arduboy core?

Post by Indcsion »

Thanks for working on this. Did I get you into this mess or did you have your eyes on MiSTer already?

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

Ha! :lol: I was already planning on checking out MiSTer, so nobody to blame but myself...

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

OK - now ready to release an alpha work-in-progress core that can run games!

(Note: this is not a 1:1 FPGA based emulation of the ATmega32U4 microcontroller used in the Arduboy - at this stage it is more a 'simulation' of an Arduboy, using a RISC-V 'soft' microcontroller and a modified version of the Arduboy libraries to re-compile games for this platform... so, existing pre-compiled Arduboy hex files are not going to run on this right now! But the majority of Arduboy games are open-source anyway, so it is not a big deal to make any necessary adjustments to the code and then re-compile a compatible hex file.)

The hex files still need to be uploaded to the core over serial right now, but this can be done via the internal UART connection from MiSTer's linux console - just type in 'minicom' to open up a serial terminal to the Arduboy RISC-V core. Then press Ctrl-A to bring up the minicom 'menu bar' and press 'S' to send a file. Arrow down and select 'ascii' upload. Then tag the hex file to be sent using the space bar, and hit enter to send!
minicom1.png
minicom2.png
minicom3.png
(Would be great if sending a file over serial to a core like this could be worked into the MiSTer menu?)

The test hex files I have included are 'The Curse of AstaroK' by Press Play On Tape (see the GitHub page for gameplay instructions!):

https://github.com/Press-Play-On-Tape/T ... Of-AstaroK

and 'Circuit Dude' by Jonathan Holmes:

http://www.crait.net/

There is a bug I haven't nailed down yet where half way down the screen pixels get shifted over by one (can be seen clearly on the borders in Circuit Dude), would be great if anyone else is able to point out what's going on there?! I did initially look at basing this core on Alorium Technology's implementation of an ATmega328 microcontroller on an FPGA - but part of it is closed-source and unfortunately only compatible with the Intel MAX 10, not the Cyclone V:

https://github.com/AloriumTechnology/XLR8Core/issues/1
You do not have the required permissions to view the files attached to this post.

NML32
Atari Super Hero
Atari Super Hero
Posts: 690
Joined: Tue Mar 11, 2014 1:54 am
Location: USA/Florida

Re: Help with porting Arduboy core?

Post by NML32 »

Thank you uXe, I was able to load Circuit Dude. :cheers:

https://youtu.be/EhphYhvF6rU

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

NML32 wrote:Thank you uXe, I was able to load Circuit Dude. :cheers:
Great! Looks like that bug I mentioned with the pixels being shifted over by one did not show up for you, good to know! (Maybe something with my setup then? I have a heatsink but no fan, so maybe running a bit hot and effecting the timing somehow? :? ) EDIT: or to do with using HDMI vs analog??

Also saw that little glitch on the right hand side of the title screen that didn't show up on my end, think I found the fix and have updated the GitHub :D

Thanks!

Sorgelig
Ultimate Atarian
Ultimate Atarian
Posts: 6348
Joined: Mon Dec 14, 2015 10:51 am
Location: Russia/Taiwan

Re: Help with porting Arduboy core?

Post by Sorgelig »

Why not load the sketches from OSD using ioctl_* signals?
If it must use serial then you can convert on the fly.
I don't understand why you need to re-invent the wheel.

User avatar
uXe
Atari freak
Atari freak
Posts: 56
Joined: Thu Nov 21, 2019 1:57 am
Location: Adelaide, South Australia
Contact:

Re: Help with porting Arduboy core?

Post by uXe »

Sorgelig wrote:I don't understand why you need to re-invent the wheel.
Fair enough - not intending to re-invent anything though, this was just the quickest way to get a working demonstration off the ground in the limited 'spare' time I have! :wink: I can imagine other use cases in the computer cores etc. where being able to send in a block of data over the internal UART connection could be a useful option though?

Indcsion
Atari nerd
Atari nerd
Posts: 44
Joined: Fri Oct 12, 2018 11:48 am

Re: Help with porting Arduboy core?

Post by Indcsion »

Would it be easy to convert arduventure?

Locked

Return to “MiSTer”