Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
AtomicZombie
PostPosted: Apr 05, 2012 - 10:34 AM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

One of my personal challenges came together finally. A single XMega generates 256 NTSC colors and 4 channel sample playback all in software.

[https://www.youtube.com/watch?v=CXFOTpM2Jn4

Only 6 IO pins used along with 9 resistors and 1 capacitor!

The screen is fully bitmapped, and the video core includes routines for sprite generation, alpha color, collision, lines, circles, text, and a lot more.

I know... this uploaded vid has bad quality and the test program is boring, but the actual image is rock solid and looks great. I intend to detail this project next time I have the chance and include a few arcade classic conversions. I am waiting for the XMega384 to come available so I can double the screen resolution.

Looks like an XMega can keep up to an ARM after all!

Thanks again to all those who had advice when asked.

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com


Last edited by AtomicZombie on Jan 07, 2013 - 02:33 AM; edited 1 time in total
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
indianajones11
PostPosted: Apr 05, 2012 - 06:08 PM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

Man that's beyond outstanding ! Smile What's the cpu speed ?

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 05, 2012 - 06:33 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Thanks!... a lot of "hacking" went into making that work.

I wrote the video engine in 3 speeds, but each runs from an external 3.579MHz (color burst) clock.

- 28.636MHz ( PLL x 8 ) This yields 8 colors with 32 shades each, and does not overclock.

- 35.795MHz ( PLL x 10 ) This has selectable 8 colors out of 10 x 32 shades, but overclocks only a small amount so that non USB XMegas can push the limit.

- 57.262MHz ( PLL x 16 ) This works great on any USB XMega, and does warp speed on graphics routines. This allows 16 colors with 16 shades each for a great range of colors.

The chroma phase routine was a lot of work, but I actually had it working on an AVR644p running at 28.626 MHz, so I knew the XMega would be easy.

All drawing routines happen during the vblank, and it is easy to write code for this system. Even the 4 channel sound mixer happens in vsync time, so the user just has to set a few regs to point to the samples stored in program memory then the engine sends out the mixed sound at whatever frequency chosen and with a few effects as well.

There is so much power here that I think a port of Wolf3D using a raycaster would be easy.

I hope to have more time to really document this project and get it out soon. It's warm here now, so I am building more bikes for my other site. Electronics is now a rainy day deal!

Cheers!
Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
indianajones11
PostPosted: Apr 05, 2012 - 09:07 PM
Raving lunatic


Joined: Nov 28, 2004
Posts: 3552
Location: San Diego, Ca

Quote:
Electronics is now a rainy day deal!
Well Brad, you need some coolant after doing such a project in asm anyway !

Edit: But I'm remembering that you recently learned to use Winavr . So do you plan to try this using a mix of C and asm, for your curiousity to see impact on performance and how well the compiler might do on the C part ?

_________________
1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 06, 2012 - 05:40 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

I have been messing around with Winavr, but have not had the time to learn the art of making ASM libraries as of yet. It's funny, I sometimes start a program in C thinking "this will be so much easier" and within the hour am coding ASM out of frustration! ASM just seems so much easier to me, and with C it always feels like fighting the compiler to get what I really want or having to swim through a torrent of confusing and wordy definitions to simply write a few registers.

Eventually, I would like to have the video engine included as a library and then try some C programming in the "main loop". But when I release this project, I am going to create an assembly tutorial to show how easy it really is to code AVR assembly.

The way I made the graphics routines, it is just as easy to call them in assembly as in C....

Code:

ldi ZL,low(2*CheckerBall)
ldi ZH,high(2*CheckerBall)
ldi X,100
ldi Y,100
ldi A,16
call DRAWSPRITE


Easy. Draw the checkered ball sprite at location 100,100 on the screen and ignore (alpha) all pixels with color 16. Just as easy as C, and loads faster.

I guess this turned into a C vs ASM rant! Oh well, I will always find assembly so much easier when it comes to uC programming, but will most likely release this project with C examples for more exposure.

Now where is my XMega384 Atmel??? I am waiting.....

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Apr 06, 2012 - 05:54 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62281
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

The way I made the graphics routines, it is just as easy to call them in assembly as in C....


Why not adopt the compiler's ABI and you could make a direct:
Code:
extern void DRAWSPRITE(char * data, uint16_t X, uint16_t Y, uint8_t colour);

DRAWPSRITE(checkerball, 100, 100, 16);

anyway?

R25:24 = &checkerball
R23:22 = 'X'
R21:20 = 'Y'
R18 = colour (R19 = 0)

http://www.nongnu.org/avr-libc/user-man ... _reg_usage

In particular:
Quote:
Arguments - allocated left to right, r25 to r8. All arguments are aligned to start in even-numbered registers (odd-sized arguments, including char, have one free register above them). This allows making better use of the movw instruction on the enhanced core.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 06, 2012 - 06:21 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

I have a lot to learn in order to make my assembly routines work in C, no doubt! Next rainy day, i will take a stab at getting Winavr up and running. I am currently using CodeVision, but since it does not talk to my AVRISP-II, I am going to switch.

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
MarioRivas
PostPosted: Apr 06, 2012 - 09:33 PM
Hangaround


Joined: Dec 29, 2010
Posts: 466


That's nice, but can it handle Crysis!!!

lol, seriously though, what's the resolution on the demo?
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 06, 2012 - 09:41 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

I don't think my workstation could even push that many polys. The demo is running at 150x100 as that is as much SRAM could be used for the frame buffer. It leaves plenty for game code variables.

I can get 640x400 out of it though by using tiled mode, but frame buffer mode allows the most bang for the cycle.

Once I have the XMega384 in hand, I will either double the buffer space or up the resolution.

150x100 is not much, but with 256 colors, it looks ok, and games using large sprites look great. The goal was to pump color NTSC out of software only, and I think it will be a great exercise to write games and demos for this engine now and push it to the limits.

I also did a version that used an external 512K SRAM and pushed 320x200 out to a logic based chroma phase system, but it wasn't as fun because it was too easy! Doing it all inside the XMega is more of a challenge.

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
MarioRivas
PostPosted: Apr 07, 2012 - 12:08 AM
Hangaround


Joined: Dec 29, 2010
Posts: 466


I think for NTSC, a resolution of 320x240 is more than respectable. Most 16 bit consoles seem to have made this standard.

The trick to getting vibrant graphics is pushing the number of on screen colors.

If you can make your engine push 64 on screen colors you'll have some thing rivaling the 16bit console era!

Having said that, what you have done is simply amazing.
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 07, 2012 - 01:00 AM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Thanks.

Currently I am getting 256 onscreen colors. The chroma phase is split into 16 equal divisions, giving a nice spread of 16 colors. The 4 bit resistor DAC gives 16 shades of each of the 16 colors.

The sound samples are fetched from program memory (same as sprites and images) and then mixed during the hsync period as 4 channels to be sent to the onboard DAC.

I have optimized the video engine so much now that there will be enough free cycles to add a text overlay bitplane as well, further freeing up the work needed to be done in the main loop.

Really enjoying this XMega - especially at 57.272 MHz!
Who needs an FPGA when you have a 60MIPs AVR?

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
MarioRivas
PostPosted: Apr 07, 2012 - 09:45 AM
Hangaround


Joined: Dec 29, 2010
Posts: 466


Great job!
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 08, 2012 - 05:53 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Thanks for the positive feedback!

I added a rainbow scroller and put a little more color in the sprites to show the number of colors possible...

http://youtu.be/kkFCd7E_2ow

I captured this directly with a USB capture stick, so the frame rate and quality are not so good. The real video is crisp and 100% smooth at 60 frames per second.

This test throws 13 sprites around, draws the background, does music, and only works about 20% of the free cycle time in the main loop.

Now that the video engine is working the way I want, all of the drawing routines will be added.

If a few more rainy days come my way then this project may get fully documented and uploaded to my site soon.

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
MarioRivas
PostPosted: Apr 09, 2012 - 02:03 AM
Hangaround


Joined: Dec 29, 2010
Posts: 466


How difficult is it to implement parallax scrolling?

I wonder if some soul could undertake the porting of a NES/Genesis/GBA emu once you make the project available.

Your engine exceeds those requirements.
 
 View user's profile Send private message  
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 09, 2012 - 03:01 AM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

It would be a breeze. In fact, with this power, every single line could be shifted and even scaled to implement something like the 3D mode on the SNES.

I am going to finish cleaning up the GFX routines and if the XMega384 is not available by fall, will probably just release this version with the lower resolution.

It's so cool to see a single AVR spewing out full color and sound with only a few resistors and no external SRAM or color processing hardware.

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
DocJC
PostPosted: Apr 09, 2012 - 03:06 AM
Raving lunatic


Joined: Dec 11, 2007
Posts: 6848
Location: Cleveland, OH

Brad,

Did you see Dean's comment in the other Thread where he has been overclocking the newer Xmega(s) at 72 MHz, (albeit with limited testing)?

JC
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
AtomicZombie
PostPosted: Apr 09, 2012 - 03:21 AM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

Indeed, and I tried mine to 71.59 MHz (ColorBurst x 20) and it worked as well. Ironically, it generated too many colors that way!

At 57.272 MHz it's like a dream. In the horizontal back porch time, I was squeezed on the 14.318MHz AVR to 46 free cycles and now I have over 300!

In fact, there are so many free cycles in the blanking period that I ran out of things to jam in there. I could easily mix 16 sound samples, but there is no point as program memory would be eaten up so fast.

I am adding everything from SIN tables to audio filters in there and my even cram a floating point process in as well so complex real time 3D can be done with minimal effort.

So many possibilities now.

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
MarioRivas
PostPosted: Apr 09, 2012 - 03:55 AM
Hangaround


Joined: Dec 29, 2010
Posts: 466


I hate to be the bearer of bad news, but from a stand point of emulation, even at 75MHZ, we have hit a steep barrier.

We're going to need at least twice the speed for emulating more complex hardware like SNES in real time.

Native applications should scream though.

I predict your engine will make one serious tool for the creation of GUIs.
 
 View user's profile Send private message  
Reply with quote Back to top
hpinfotech
PostPosted: May 01, 2012 - 02:55 PM
Rookie


Joined: Feb 26, 2004
Posts: 48
Location: Bucharest, Romania

AtomicZombie wrote:
I am currently using CodeVision, but since it does not talk to my AVRISP-II, I am going to switch.
Brad


CodeVisionAVR fully supports AVRISP MkII for several years.
This is achieved by calling the STK500.EXE (from AVR Studio 4.xx) or ATPROGRAM.EXE (from AVR Studio 5.1 or 6.0) command line utilities.
Starting with CodeVisionAVR V2.05.7, it is important that you select the correct version of AVR Studio in the Tools|Debugger menu so that it matches the AVRISP MkII firmware.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
AtomicZombie
PostPosted: May 02, 2012 - 08:11 PM
Posting Freak


Joined: Feb 13, 2007
Posts: 1025
Location: Gillies, Ontario

hpinfotech wrote:

CodeVisionAVR fully supports AVRISP MkII for several years.
This is achieved by calling the STK500.EXE (from AVR Studio 4.xx) or ATPROGRAM.EXE (from AVR Studio 5.1 or 6.0) command line utilities.
Starting with CodeVisionAVR V2.05.7, it is important that you select the correct version of AVR Studio in the Tools|Debugger menu so that it matches the AVRISP MkII firmware.


Thanks, I may try it one day. I thought I did that, but it did not show any XMega devices. At this point, I have so many ASM code bits done that it is far quicker for me to just code in assembly than screw with all of this yak shaving just to get a compiler set up.

Next rainy day....

Brad

_________________
I Like to Build Bikes : http://www.AtomicZombie.com
I Like to Hack Stuff : http://www.LucidScience.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits