VT100 Emulator using only a Arduino

Hello my friends,

Im new to this forum and i need some guidance/help. I hope im posting in the right forum.

First, for those who doesnt know the VT100 is an 80's terminal for mainframes built by DEC with a 640x480 monocrome screen (80x24 ASCII chars) and a ASCII keyboard, its controlled by a Serial TTL with 9600 baund rate and it uses ASCII control and characters. It uses a Intel 8080 as main CPU. Basically is the dawn of the Linux terminal... Yeah, i like it alot.

I know that alot of people have done some VT100 emulators using a display and even got colors (something that the original one doesn't have). But i want to display on a real TV.

I know that theres dedicated hardware to do that on a Arduino but they are expensive here and take a long time to arrive, since i need to buy oversea and takes roughly 90 days. So, im decided to do my own implementation.

Well, first i saw the TVOut Library, its awesome but it has only 100 or something pixels wide, and thats its not even close to 640 from VT100. And i know that 2KB is not close to a framebuffer for 640x480 but im thinking about skipping the framebuffer at all.

First of all, i will build a black and white screen, no colors or even grayscale. Because even B&W would be pushing Arduino to the limit.

I read alot about PAL standard, and each horizontal line takes 64us to draw, 12us is the hsync/hblank and 54us is the actuall draw, wich is limited to 650 pixels.

My idea is the follow, hardcoded in the 32KB program ROM i will hard code a character map, with the 256 ASCII characters, since i will use a 8x8 character resolution, each character will use 8 bytes. Using a total of 2048 bytes for character mapping, but that is stored in the ROM, this data is constant, no need to store in RAM.

Insinde the RAM i will just store the 80x24 characters that will be printed on screen, since each character uses 1 byte, i will use 1920 bytes of memory, leaving only 128 bytes free to be used but i think that this is all i need.

On each hsync i will use the free time (12us wich is rougly 200 (12x16) instructions since in the atmega328p datasheet is rougly 1 instruction per cycle) i will load in another 80 bytes of memory (640 bits) the line that will be drawn by using some moving instructions that i previously hardcoded (in the character map).

Then on the 52us i will just do bitshift this 80 bytes data to a pinout that will be doing the white (1v). I think that Arduino cannot bitshift 80 bytes, but it can 1 byte. So every time that i shift a hole byte wich will represent one char i will just load another byte to bitshift, since 52us give me roughly 830 instructions to run, those are 190 more instructions than what is need to draw 640 pixels on screen and i can use that extra instruction to do a byte moving from memory to a "pinout".

Okay, what about keyboard, screen rolling and other stuff that the VT100 does? That will be done while the screen is in vsync, since the vsync take almost 1ms its plenty time to do the rest and if i need a keyboard/screen stack or something i still have those 48 bytes of free memory.

Yes, the controller wont do anything else, im aware of that but the propuse is just to emulate a VT100. Receive commands from the native TTL from arduino (pin 0 and 1), do a simple PS2 keyboard controller and the rest of the pins can be sacrificed to do bitshifting.

Okay, my problems:

  1. I dont know AVR Assembly and i cant find a good material about it, im from Intel Assembly, so 8080, 8086 and 8052 but those are too slow to drive the screen since they arent 1 instruction per cycle.

  2. How is the Atmega RAM mapped? The registers are in memory or they are dedicated? The IO is memory mapped? Because that will be pretty important since i will need to dedicate (if possible) memory from those 48 bytes to that.

  3. I dont know if exists, but i need a document that shows avr instructions and the clock cycles used so i can do the correct timming and optmize the most. Because the datasheet doesnt say that there are one instruction per clock, it says that is close to that. I figure that some instructions would use more than one clock cycle, i just hope that the bitshift one use only one because my hole project depends on that.

  4. MOST IMPORTANT: I need ideas, guidance, anything that you may find it helpful will help me alot. But i dont want to add external hardware because here they are expensive and take too much long time to arrive.

I know that runs a little away from the Arduino instinct because im just trowing away the Arduino C IDE and bootloader. But i will stick with Arduino hardware, the atmega328p and the 16MHz clock crystal.

Im sorry for my bad english because english is not my native language.

1) It's not going to work. Very good people have done their best, and they don't get anywhere near full PAL resolution, much less VT100 resolution. Look on avrfreaks.net for posts by "atomiczombie." Hmm - good summary here: http://www.avrfreaks.net/forum/highest-res-composite-video (also, AVRs are so ... old, and not getting faster. The world would be better served by figuring out how to do this one one of the ARM chips. (which, alas, have relatively non-deterministic instruction timings. That's where the challenge would lie.)

On each hsync i will use the free time (12us wich is rougly 200 (12x16) instructions since in the atmega328p datasheet is rougly 1 instruction per cycle) i will load in another 80 bytes of memory Then on the 52us i will just do bitshift this 80 bytes data to a pin

2.5 cycles/byte is not enough time to translate a character/row# into a linebuffer bitmap. a memory read or write takes two cycles, and minimally you read character from screen map, read row from character data, and write row to linebuffer (6 cycles!) Likewise, 1.3 cycles/bit is not enough to shift and write from a line buffer bit to an IO pin. The "better" implementations use SPI or an external shift register to actually shift the bits, so you're looking at ~10 cycles/byte instead, and that's still not enough.

  1. I dont know AVR Assembly and i cant find a good material about it

It's out there. Start with the datasheet and go to to The AVR Instruction Set manual There are also a lot of tutorials and sample code. http://avrfreaks.net is a good place to start for more technical info and discussions than the arduino forums.

  1. How is the Atmega RAM mapped? The registers are in memory or they are dedicated? The IO is memory mapped?

Registers an IO space all appears in the same address space. Flash is in a separate address space. There are "short" instructions for accessing "some" of the IO space.

  1. I dont know if exists, but i need a document that shows avr instructions and the clock cycles used

Every datasheet has a section "Instruction set summary" near the end that includes the info on clock cycles for each instruction. In general, reg/reg operations take one cycle, load/store takes two cycles, and conditional jumps are variable depending on whether they jump or not.

  1. MOST IMPORTANT: I need ideas, guidance, anything that you may find it helpful will help me alot.

Lancaster's TVT Cookbook has been made available online. Old, but has lots of important theory in it.