Forum Replies Created
You can see the interference that I am getting in this image.
Here timer2 is generating a sawtooth wave at approx 30hz. PWM is at 62,5 kHz
I’m thinking of 2 solutions:
1) filter the sound signal in hardware (wouldn’t like to do this, because its incompatible with Hackvision)
2) increase frequency of PWM dramatically by using fast PWM mode 7 and setting TOP lower. I could get 125 kHz by setting top to 128, but naturally I will lose half the resolution.
3) it is also possible that duty = 0 % and/or duty=100% is causing the interference, because they are such extreme cases.
Well, yes and no. I’m trying it out on the Hackvision at the moment.
As for the square waves, the concept is as follows:
Timer2 is fastPWM’ing at 62,5 kHz, mode 3 (counting to fixed 0xFF)
A function is hooked to horizontal blank interrupt (TV.set_hbihook). This function manipulates the duty cycle OCR2A of timer2, allowing the output voltage of the pin11 to be between 0 (0 duty) to 4,92V (OCR2A = 255 = 100% duty). Hbi fires at 7811 hz, meaning I get to choose the output PWM duty at that resolution = allows to make rudimentary sawtooth, triangle etc waves. In effect, the timer2 PWM is a DAC. This is a well known concept with Arduino audio, but I haven’t seen anyone combine it with TV_out. One reason for this is that you get a much quieter signal level out than with the method used by tv.tone. But since Hackvision is connected to a TV with possibility of amplification, I thought it just might work.
You can see the PWM (sawtooth wave) overflowing from 255 to 0 in this image from my USB scope
Apologies for lecturing on a subject you´re probably much more familiar with than I am.
The real problem, however, is that I have troubling interference with the video signal (horizontal stripes and image cutting at the last row), I’ll post an image of it soon.
When I started this, I had a hunch that I need to be able to develop in a smarter and faster way. Porting the TVout to PC was a very good first move.
– The whole road algorithm is now done using 3 integer lookup tables. All the rest is done by combining the lookup values with multipliers and modifiers.
– The alpha bitmap was a pain to develop because I needed to come up with a logical operation that would combine the screen, the bitmap and the alpha channel in such a way, that all 7 different logical states would result in the correct output. All “simple” solutions ended in 1 state inverting a pixel or some other misery.
If I would have had to do all that tweaking by uploading to Arduino it wouldn’t have been slow, it would have been impossible. I only have a couple of hours now and then to work on this.
To give others the opportunity to do the same, I have opened a git repository for my SFML port of the TVout library. I have also shifted over to Linux for the development. In Linux its plug-and-play.
for git clone:
and a lousy instructional video:
If you wish to share this information on your Hackvision page, you are more than welcome to do so.
The OutRunduino work-in-progress files are also under my account, but those I do not wish to be linked or announced, as the code is far from stable.
Let’s hope we will see more sophisticated Arduino games in the future ! I have been directly contacted by at least two people, that’s what made me put the code on github.
Thanks for the compliment Michael.
I don’t know what it is about having to deal with limited resources that really appeals to me. I also play around with ARM Cortex processors and I have Olinuxino embedded Linux boards, but … the more memory and processing power I get, the less it seems to interest me 😉
You will not see a finished game soon. I want the end result to look impressive and be genuinely fun to play – in a way that people will be amazed that they can get so much game out of a measly atmega328. If I get twisty winding roads with altitude changes, various landscapes and most of all a similar “crossroads” system as in Outrun then it will be mission accomplished. Lets see how far this can go.
My real concern now, as I put in another post on the bulletin board, is sound. I am wondering how to create engine and screeching type sounds. I’ve thought about distorting the sound output by involving some other pin, or perhaps even involving some external circuitry. It’s stretching the Hackvision format a bit, but I think that’s what hacking is about, adding bits and pieces, not just by coding but also by soldering. I want to generate the kind of saw-tooth wave (?) rough sounds that the games of yore had. TVout.tone might be good for melodies, but I want effects: crackling, buzzing, popping crap that is more noise than sound.
What would you do, if hypothetically you were a coin-op game designer circa 1982 and had to improve the sound capabilities of your arcade driving game – as cheaply as possible ?
I’d appreciate just a pointer to some direction to start looking & experimenting. Sound (unlike graphics) has never been my domain.
Update 5: 1st run on real hardware
This was my first attempt to take the game from SFML on Windows to real HW. It took about 1 hour, I need to put #define switches into the code for enabling/disabling Arduino specific code (progmem access, random, inclusion of Arduino.h and some types)
Flash remaining: 15 kB
RAM remaining: 614 B
Speed is very good, in fact its too fast as you can see from the Z count running over rather quickly on the left hand screen corner.
Also, unoptimized road curvature (30 x float) and road edges lookup tables (3 x 30 ints) are still in RAM !
So basically I have 15 kB to add game graphics and gameplay and around 900 B remaining for game variables.
The screen buffer is now only 728 B, so perhaps in the end I can even crank up the resolution.
I am pretty amazed at what the tiny atmega 328 can actually do.
Work-in-progress video episode 4 … palms and pesky Porsches !!
I’m very confident in this game idea. I made the engine resolution independent. I was able to run at very low res and yet maintain a good feeling. Linked here is a video of running in 104×56 res. This means I have ways of cranking up speed and freeing memory for traffic and other gameplay improvements!
Yes. Memory is going to be tight. I need to test on a real Arduino very soon.
I use as much hard coded constants and progmem lookup tables as possible (<-might be too slow tho). While it looks like a lot is moving on screen, in reality there are not so many variables in play. I can also cut down on vertical framebuffer height (sky) if I run out of stack. I want to scroll the background by using TV.shift. I have tested it and it could give a big speed boost. The road gets shifted also, but since its updated per every frame, it doesn’t matter. I could really use a version of the Asteroids overlay bitmap routine that draws vertical column of a bitmap extracted from a given point in the bitmap data – even described in pseudocode… 😉 And, on another note: Just think about the possibilities here, Hackvision Special Edition Kickstarter, with Outrunduino firmware, bundled with airbrush art poster and a C-cassette with game music tracks …. oh the coolness! *grin* O0 <- its a joke, no need to get worried.
Hey, thanks for the comment.
SFML = simple and fast media library and is also available for Linux & Mac & iOs & Android. You do not need to know anything about the OS. This was the first time I ever used this toolchain.
I bypassed the TVout timing because it relied on PAL/NTSC timing. SFML provides a similar frame-based timing. Mind you, its still running a bit too fast. Making sounds is going to be way more difficult: that would require multitasking and a dedicated thread for sound.
However, 1:1 emulation is not my goal. This tool is already proving valuable. I am working on a pseudo-3d game for Hackvision, and boy is it so much easier to catch errors when you can set breakpoints and watch variables.
My code is extremely quick & dirty and I am always ashamed to show it because I have no clue about proper C or C++. But if you want, Michael, I can send you this source. You should be able to install SFML easily on Linux. I don’t want to publish a lib just yet.
Old thread but we’ve just discovered your game. Never too late to give kudos for a job well done.
My “testing team” is 8 and 10 yr boys.
Congrats to Trodoss, you’ve nailed the playability & difficulty. First they were struggling to get past the first snake, now they’re trying to get to the end.
BTW, my 8-year old doesn’t want to play Elventure… its too scary 😉 ! Goes to show 3d gimmicks isn’t always needed for a game to have an atmosphere.