Using an ATmega644 as an ANTIC/GTIA-style video display?

Programming the 6502 microprocessor and its relatives in assembly and other languages.
whartung
Posts: 1004
Joined: 13 Dec 2003

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by whartung »

pw132 wrote:
To clarify, the idea of the project is not to emulate ANTIC and the GTIA, but produce a chip of similar capability with a micro-controller program.
What capabilities do you want from the ANTIC/GTIA?

Looks like ANTIC handled the display list and pixel vs character parts, and the GTIA handled the actual video signals and things like the player/missile sprites.

The ANTIC was amazing for its day.
User avatar
cbmeeks
Posts: 1254
Joined: 17 Aug 2005
Location: Soddy-Daisy, TN USA
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by cbmeeks »

By all means, certainly go with what you know.

The Propeller can be a tricky beast sometimes. I just really like to recommend it for all video work if I can because I believe it excels in this department. I've seen the ULA from the ZX Spectrum emulated, basic C64-like screens for NTSC and even SVGA come out of that chip. Not to mention near perfect emulation of the SID, AY3-8910 and SN76489 sound chips. It is no sweat for the Propeller to host VGA and a SID in the same chip.

Anyway...just thought I would mention it. ;-D (no, I'm not paid by Parallax but I should considering how often I recommend their chip...lol).
Cat; the other white meat.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by BigEd »

I get the impression the Propeller is a whole new adventure, and a very worthwhile one, but if you want an easy path and there's a microcontroller you already know well, go with that. But note that the Propeller has some hardware support to produce video, and is almost surely able to do what you want, whereas another microcontroller might or might not be able to do it.
User avatar
jac_goudsmit
Posts: 229
Joined: 23 Jun 2011
Location: Rancho Cucamonga, California
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by jac_goudsmit »

I second the idea of using a Propeller but I understand if you've never worked with one, it can be a difficult challenge because its native language is something called "Spin" which sort of looks like a simplified version of Pascal with objects. There is a GCC port for the Propeller but because it wasn't designed for C/C++ (it has no stack, for example), the most efficient way to do things with a Prop is to use Propeller Assembler, aka PASM.

Indeed the Propeller is very good at generating (standard definition) video signals, even if the main clock frequency is at a totally different rate than the video frequency. The disadvantage is that it has only digital pins, so an analog video signal is simulated by using resistor networks that serve as D/A converters. Also, with only 32KB of "hub RAM" on board, the screen size for a graphics screen would be limited, so most video drivers use "tiles" in the same way as the Commodore PET or the UK101/Superboard used graphics characters.

There are many tricks to work around problems such as pin shortage or RAM shortage. For example, you could design a system where the Propeller generates the hsync and vsync signals but where a large SRAM chip stores the pixels. The SRAM could either be mapped into the 6502 address space somehow (which would require clock synchronization so that the pixels are extracted to the video generator during Phi1 when the 6502 doesn't use the databus) or you could design a system that's similar to the TMS9918A chip that was used in MSX systems to generate video by way of indirect commands. I know cbmeeks knows more about those.

In my L-Star project, I use a video driver from the Parallax Object Exchange (which is where Propeller enthusiasts can post their software to share) which uses a trick to generate a monochrome video signal with only one digital pin: it generates a high-frequency PWM signal to simulate the "black" level in a video signal, and it sets the pin to LOW for sync/blanking and HIGH for white.

I've also thought of using Teletext decoder chips for video output. They are still available on places like eBay, and on a Propeller it would be trivial to generate a monochrome video signal with Teletext information in it. In fact it would be possible to generate up to 7 Teletext streams (one per cog, plus an eighth cog to load the pages from e.g. a high-speed serial connection to another system, or an SD card or whatever). Each stream could have different information like you would switch channels on old Teletext TVs. And a teletext stream can have up to 800 directly accessible 40x23 character pages, and unlimited "rotating" pages (i.e. pages that refresh every few seconds to show different information without interaction). Unfortunately I live in a country where Teletext was never a thing, and I have a few other projects I'm working on, so this is one of those "if I ever get to it" things.

===Jac
pw132
Posts: 13
Joined: 10 Nov 2016

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by pw132 »

Back again. To clarify again about the ANTIC-GTIA comparison... according to my spec the AVR uses display lists/non maskable interrupts very similarly to the way ANTIC does it, and the color palette (a 256 color YUV palette) and operation of sprites will be very similar to GTIA. It's not identical by any means because I'm only using one chip and sixteen "registers." But the Atari 8-bit setup was definitely the starting point for how I decided the AVR (if I still use an AVR) would operate.

I did more ROM coding but my emulator is hitting a snag because I keep screwing up the branch instructions. My emulator gets stuck on the opcode "$FA" (which is probably actually a relative vector for a branch) and I'm not positive on why. Here's the C/C++ code for the BCS instruction, the other four I have implemented are basically identical.

Code: Select all

int bcs_relative_func(unsigned char dat1, unsigned char dat2)
{
	if (CHECK_BIT(*&sr, 0) != 0)
	{
		printf("BCS branch\n");
		*&cycles_used += 1;
		if (abs(*&pc - dat1) > 255)
		{
			*&cycles_used += 1;
		}
		if (dat1 > 127)
		{
			*&pc -= (256 - dat1);
		}
		else
		{
			*&pc += dat1;
		}
	}
	*&pc += 2;

	return 0;
}
pc is program counter, dat1 and dat2 are the bytes following the branch opcode, check_bit... checks bits, and cycles_used is just making sure the CPU timing is relatively true to life. Any idea what's wrong? It's probably something really dumb because I'm used to scripting languages and C was a bit of a mindscrew at first for me.

EDIT: I also just looked into Propeller and Spin. Programming doesn't seem to be an issue as much as the fact that NTSC on Propeller is basically a solved problem. Wikipedia has screenshots of high-color displays coded by the Parallax themselves. It has dedicated video generation hardware. What worries me
about that is it might not be as flexible. I don't know whether or not the Propellor video frame can be modified during refresh for example. A 40-pin DIP AVR has no dedicated video generation hardware yes, but if I dedicated it to the task of only making video it might be better for interfacing with an external processor. I could be completely talking out my behind though.
Last edited by pw132 on Fri Sep 22, 2017 7:27 pm, edited 1 time in total.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by BigEd »

A branch offset should not be added to the PC of the branch instruction, but to the PC of the following instruction.

If you can (persuade your compiler to) sign-extend the offset byte, you won't need to treat forward and backward branches any differently.
pw132
Posts: 13
Joined: 10 Nov 2016

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by pw132 »

BigEd wrote:
A branch offset should not be added to the PC of the branch instruction, but to the PC of the following instruction.

If you can (persuade your compiler to) sign-extend the offset byte, you won't need to treat forward and backward branches any differently.
I thought I had implemented that because the branch instruction still adds two to the program counter when executed, even if it does perform a branch. Therefore the branch should be operating on the PC of the next instruction. I guess I don't really understand.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by BigEd »

Oh, I see, so you have. I didn't quite get that. Can you print out an example of what happens to any particular branch that's taken? Perhaps worth checking both a forward and a backward branch.
pw132
Posts: 13
Joined: 10 Nov 2016

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by pw132 »

I've discovered the problem. My branch implementation is fine (I did add your suggestion of adding a sign to the relative vector in C though), it was the preceding operation that was messed up. The opcodes for the two versions of the BIT instruction were swapped, so the ZP BIT acted like an Absolute BIT and skipped a byte, leading to it reading $fa as the next instruction. Branching works again. Time to work on some actual display code I suppose :V
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by BigEd »

ah!
User avatar
jac_goudsmit
Posts: 229
Joined: 23 Jun 2011
Location: Rancho Cucamonga, California
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by jac_goudsmit »

pw132 wrote:
What worries me about that is it might not be as flexible. I don't know whether or not the Propellor video frame can be modified during refresh for example.
As Doc Brown would say: You're not thinking 2-dimensional enough! :D

If you would implement a memory-mapped video driver on the Propeller, your video "driver" would run on one cog, generating video from hub memory.

At the same time, another cog would use the pins that are connected to the CPU clock, address bus, data bus, R/~W and optionally an address decoder to store data in the hub memory area that the video cog uses to generate video.

There is no need to synchronize the two cogs at all (e.g. wait for a frame sync or line sync). The Propeller has intrinsic synchronization (each cog can get access to the hub every 16 clock pulses; that's once every 200ns at 80MHz). So the CPU bus can run completely asynchronous to the video.

As I mentioned before, graphics are a bit of a problem because you only have 32KB hub memory, but there are tricks to do things. For example if you want 64K of video memory, just run two Propellers in parallel from the same clock generator. The top half of the screen could be generated by one Prop and the bottom by the other.

===Jac
User avatar
cbmeeks
Posts: 1254
Joined: 17 Aug 2005
Location: Soddy-Daisy, TN USA
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by cbmeeks »

^ what he said.
Cat; the other white meat.
User avatar
cbmeeks
Posts: 1254
Joined: 17 Aug 2005
Location: Soddy-Daisy, TN USA
Contact:

Re: Using an ATmega644 as an ANTIC/GTIA-style video display?

Post by cbmeeks »

jac_goudsmit wrote:
For example if you want 64K of video memory, just run two Propellers in parallel from the same clock generator. The top half of the screen could be generated by one Prop and the bottom by the other.
Sorry to bring up an old thread.

But that comment got me to thinking....using two Propellers in an LFQP package on a small board wouldn't be too much larger than a standard DIP40. Might be kinda cool to make something that basically had 38 pins of I/O (more on the sides) and 16 cores running at 320 MIPS that didn't cost much.

Hmmm.
Cat; the other white meat.
Post Reply