I had thought that I could get away with just making a few small changes to the code written in part 3 but in the end I decided a complete rewrite was in order. The old version was designed for colour output since this is only going to be black/white we only need 1 bit for each pixel and can fit 8 pixels into each byte. The output code ended up looking like as follows:

vidOut:	
	out VGAPORT,r7 ;1 - 1	
	bst r8,1 ;1
	bld r7,BWHITE ;1
	bst r8,2 ;1
	nop ;1
	out VGAPORT,r7 ;1 - 2
	lpm r6,Z+ ;3
	bld r7,BWHITE ;1
	out VGAPORT,r7 ;1 - 3
	bst r8,3 ;1
	bld r7,BWHITE ;1
	nop ;1
	nop ;1
	out VGAPORT,r7 ;1 - 4
	bst r8,4 ;1
	bld r7,BWHITE ;1

The above is just an extract of the final code. The rest can be found on the github page. It works by loading the current pixel into the T flag. This is then loaded into r7 which is our output register. This only takes 3 cycles since we need to output every 5 cycles it gives us a bit of room for getting ready for the next pixel. It might actually be possible to shorten this to 4 cycles per pixel but I didn’t need anything better. When a tile has ended we add on the current tile line offset onto the tile position and repeat. It ended up producing a good simple B/W output with room for improvement. For example more tiles could be displayed each frame vertically and vertical resolution could be improved.

The next stage was to introduce input courtesy of the USI.

Advertisements