MaxCoderz

for your 1 bit pleasure!

All times are UTC




Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Wed 14 Nov, 2007 3:06 pm 
Offline
Maxcoderz Staff
User avatar

Joined: Thu 16 Dec, 2004 10:06 pm
Posts: 3064
Location: Croydon, England
(This is a copy of a journal post).

My work with the VDP in the Sega Master System made me more aware of how video signals are generated, so thought it would be an interesting exercise to try and generate them in software. This also gives me a chance to test Brass 3, by actively developing experimental programs.

Image

I'm using a simple 2-bit DAC based on a voltage divider, using the values listed here. This way I can generate 0V (sync), ~0.3V (black), ~0.6V (grey) and 1V (white).

My first test was to output a horizontal sync pulse followed by black, grey, then white, counting clock cycles (based on a 6MHz CPU clock). That's 6 clock cycles per µs.

Image

The fastest way to output data to hardware ports on the Z80 is the outi instruction, which loads a value from the address pointed to by hl, increments hl, decrements b and outputs the value to port c. This takes a rather whopping 16 clock cycles (directly outputting to an immediate port address takes 11 clock cycles, but the overhead comes from loading an immediate value into a which takes a further 7). The time spent creating the picture in PAL is 52µs, which is 312 clock cycles. That's 19.5 outi instructions, and by the time you've factored in the loop overhead that gives you a safe 18 pixel horizontal resolution - which is pretty terrible.

Even with this technique, in the best case scenario you output once every 16 clock cycles which gives you a maximum time resolution of 2.67µs. This is indeed a problem as vertical sync is achieved by transmitting two different types of sync pulse, made of either a 2µs sync followed by 30µs black (short) or 30µs sync followed by 2µs black (long). In my case I plumped for the easiest to time 4µs/28µs and hoped it would work.

Anyhow, I made a small three-colour image for testing: Image

Of course, as I need to output each scanline anyway I end up with a resolution of 304 lines, which gives me rather irregular pixels, so I just stretch the above image up to 20×304. Eagle-eyed readers would have noticed that the horizontal resolution is only 18 pixels, but somewhere in the development process I forgot how to count and so made the image two pixels too wide.

Image

As you can see, it shows (the entire image is shunted to the right). TVs crop the first and last few scanlines (they aren't wasted, though, and can be used for Teletext) so that's why that's missing. :) A widescreen monitor doesn't help the already heavily distorted pixels either, but it does (somewhat surprisingly) work.

With a TI-83+ SE (or higher) you have access to a much faster CPU (15MHz) and more accurate timing (crystal timers rather than an RC circuit that changes speed based on battery levels) as well as better interrupt control, so on an SE calculator you could get at least double the horizontal resolution and output correct vertical sync patterns. You also have better control over the timer interrupts, so you could probably drive hsync via a fixed interrupt, leaving you space to insert a game (the only code I had space for checks to see if the On key is held so you can quit the program - more clock cycle counting). I only have the old 6MHz calculator, though, so I'm pleased enough that it works at all, even if the results are useless!


Last edited by benryves on Wed 14 Nov, 2007 4:08 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 14 Nov, 2007 3:19 pm 
Offline
Maxcoderz Staff
User avatar

Joined: Thu 16 Dec, 2004 10:06 pm
Posts: 4094
Location: I cant seem to get out of this cryogenic chamber!
You have got to be kidding me Ben, this is an all new milestone for you ... when will you stop!

The knowledge you possess is amazing, this is truely amazing.

:worship:

_________________
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 14 Nov, 2007 3:41 pm 
Offline
Calc King

Joined: Sat 05 Aug, 2006 7:22 am
Posts: 1513
This is awesome! I didn't even know it was possible..
Ben always makes the impossible possible it seems :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 14 Nov, 2007 7:33 pm 
Offline
Calc King
User avatar

Joined: Mon 20 Dec, 2004 6:47 pm
Posts: 2286
Location: Quebec (Canada)
post removed

_________________
ImageImage
Bandcamp|FB|Youtube|Twitter


Last edited by DJ_O on Fri 11 Jan, 2008 9:55 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 14 Nov, 2007 10:50 pm 
Offline
Calc Master

Joined: Mon 20 Dec, 2004 10:01 pm
Posts: 1110
Location: In the state of Roo Fearing
If it's playable at 18x304 with little CPU time for game processing, then yes...

_________________
ImageImage
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 14 Nov, 2007 11:25 pm 
Offline
Calc Guru

Joined: Thu 27 Oct, 2005 8:28 pm
Posts: 962
o.o sick i wouldn't know where to begin w/ messing w/ hardware

_________________
Image Image Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 14 Nov, 2007 11:54 pm 
Offline
Calc King
User avatar

Joined: Mon 20 Dec, 2004 6:47 pm
Posts: 2286
Location: Quebec (Canada)
post removed

_________________
ImageImage
Bandcamp|FB|Youtube|Twitter


Last edited by DJ_O on Fri 11 Jan, 2008 9:55 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu 15 Nov, 2007 12:41 am 
Offline
Calc King
User avatar

Joined: Sat 18 Dec, 2004 6:46 am
Posts: 2932
At least the bear came in clear ;)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu 15 Nov, 2007 2:23 am 
Offline
New Member

Joined: Sun 19 Nov, 2006 11:31 pm
Posts: 6
I am your slave. :P

I have an 84+, and access to a TV(I musta missed it, that is RCA, correct?) and a basic understanding of circuts/access to stuff. If you can get my schematics, I can try this on my 84+, willingly. :)

E-Mail me at Netham45 (DIE SPAMBOTS) at (DIE SPAMBOTS) gmail.com

Mabye it would be possible to couple this with MSD8x and get video output?

Edit: Missed the PAL part, the TV I have is NTSC.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu 15 Nov, 2007 4:54 am 
Offline
Maxcoderz Staff
User avatar

Joined: Thu 16 Dec, 2004 10:06 pm
Posts: 4094
Location: I cant seem to get out of this cryogenic chamber!
Well i have an 84+SE and live in PAL territory :). But i think this is best left up to the master.

You could try the old 'overclock your calc' move?

_________________
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu 15 Nov, 2007 11:36 am 
Offline
Maxcoderz Staff
User avatar

Joined: Thu 16 Dec, 2004 10:06 pm
Posts: 3064
Location: Croydon, England
Cheers, gents. :)

DJ Omnimaga wrote:
oh wait i missed the 18x304 part then x.x I wish it could be any res
As do I. :) The problem comes from not being able to change the voltage levels quickly enough; a scanline (the image is scanned from left-to-right, top-to-bottom) has 52µs worth of time for image data. An outi instruction (for reading a value to memory and dumping it out of the link port) takes 16 CPU clock cycles, which comes to about 2.67µs per outi, giving us 19.5 pixels per scanline. By factoring in a bit of extra CPU time to handle the loop you come to the 18 pixel horizontal resolution answer.

A 15MHz SE (15 clock cycles per µs) would only take 1.067µs per outi, 48.75 pixels horizontal. 48 pixels wide would be pretty decent. :)

The 304 pixel vertical resolution is simply because I trace every scanline. I only sync one field (I use the same vertical sync pattern every frame) so the resolution is half that of what it could be (interlaced). I don't think anyone would complain about 304 pixels high resolution, anyway.

The problem is getting usable software into there. I don't know much about the 83+SE and higher's interrupt system, but if you could trigger an interrupt every 64µs (that's once a scanline) you could very easily mix in some game logic.

The logic behind that would be that you wouldn't have to draw every scanline. You could, say, take the central 192* scanlines and treat those as the active display (ie, write out a signal for those lines). For the scanlines above and below you could just output the hsync pulse (4µs at sync level) then output black then return prematurely, leaving you with 60µs free (minus loop overhead) for some game logic out of every 64µs scanline.

netham45 wrote:
I have an 84+, and access to a TV(I musta missed it, that is RCA, correct?) and a basic understanding of circuts/access to stuff. If you can get my schematics, I can try this on my 84+, willingly. :)
I'll release the source soon. Sorry, I would have done earlier but I'm trying to get Brass out at the same time and would like to do a couple more tests first. This project is more "look, it can be badly done on an 83+, maybe some nice person with an SE can turn it into something usable". ;)

Quote:
Edit: Missed the PAL part, the TV I have is NTSC.
I believe that the timing is much the same on NTSC. The colour format is different, but that doesn't matter as I'm not outputting colour signals anyway. Also, whilst NTSC is a lower vertical resolution, it has a higher refresh rate to compensate. My tests (inputting a PAL signal to an NTSC device) just crop the image.

I'd like to develop this on an SE, but don't have one (and they're rather expensive here on eBay). :(

* Master System Resolution = 192 active scanlines.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu 15 Nov, 2007 11:55 am 
Offline
Calc King

Joined: Sat 05 Aug, 2006 7:22 am
Posts: 1513
I don't think you could do it exactly with interrupts on a SE
disclaimer: I have no idea what I'm talking about really :P
the fastest normal rate (cpu speed independent) is about 1.43 times too slow and the slowest cpu-clock-divider rate is almost 23 times too fast (at 15MHz)
Combining 2 timers may not be accurate enough, so that leaves skipping 22 interrupts out of 23


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu 15 Nov, 2007 12:32 pm 
Offline
Maxcoderz Staff
User avatar

Joined: Thu 16 Dec, 2004 10:06 pm
Posts: 4094
Location: I cant seem to get out of this cryogenic chamber!
Crystal timers can generate interrupts on the SE's, you can check out the frequencies here: http://wikiti.denglend.net/index.php?ti ... s:Ports:30

_________________
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 21 Nov, 2007 10:58 am 
Offline
Maxcoderz Staff
User avatar

Joined: Thu 16 Dec, 2004 10:06 pm
Posts: 3064
Location: Croydon, England
PAL.zip

It's an experiment, so the timing is wrong but it "works on my machine". ;)

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed 21 Nov, 2007 6:21 pm 
Offline
Maxcoderz Staff
User avatar

Joined: Thu 16 Dec, 2004 10:06 pm
Posts: 4094
Location: I cant seem to get out of this cryogenic chamber!
Wow Ben, this has got me so excited!

Im going to whip the schematic up *digs through parts draw*

Have you uploaded this to ticalc.org? I think this would gain a lot of interest :).

_________________
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB ® Forum Software © phpBB Group | DVGFX2 by: Matt