Decoding the Gameboy LCD output.

ZeroWalker
Posts: 57
Joined: Wed Nov 01, 2017 6:17 pm

Re: Decoding the Gameboy LCD output.

Post by ZeroWalker » Thu Nov 09, 2017 10:38 am

the Gameboy can reset the frame whenever it wants to by code (which is luckily almost never used).
then the DMA couldn't be trusted as it could be 20% of one frame and 80% of a new frame.

Same when the Gameboy resets or boots.

So using the DMA after setting it once is not flawless, and is more like a "should work most of the time",
but there is no way to know if it fails or not.

The only way to know when the frame is actually done (excluding VSYNC) is that there is a huge gap between two clock pulses.
But i doubt there would be anyway for the DMA to know about that,
else one could technically do something like "if last pulse was more than X microseconds, reset".

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Decoding the Gameboy LCD output.

Post by stevestrong » Thu Nov 09, 2017 10:44 am

Resetting DAM could be done within the EXT interrupt ISR of the first Vsync edge.
So first reset, then set it for the new stream.

ZeroWalker
Posts: 57
Joined: Wed Nov 01, 2017 6:17 pm

Re: Decoding the Gameboy LCD output.

Post by ZeroWalker » Thu Nov 09, 2017 10:48 am

Yeah that's what i do, or rather kinda did.
Problem there is if i use a circular buffer (which was very nice with the double buffer size trick).
With a normal double buffer the VSYNC could handle it all and just swap,
with circular i can't just reset as that would simply make only ever use the first half of the buffer.
And if i could let it continue where it was from, it would break if the VSYNC was different (cause of reset or similar).

ZeroWalker
Posts: 57
Joined: Wed Nov 01, 2017 6:17 pm

Re: Decoding the Gameboy LCD output.

Post by ZeroWalker » Mon Nov 13, 2017 2:52 pm

hmm, it's kinda weird that enabling DMA via EXT-VSYNC seems to cause a (about 5 pixel) offset or something.
Is the delay between launching the interrupt and enabling DMA that high?

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Decoding the Gameboy LCD output.

Post by stevestrong » Mon Nov 13, 2017 4:07 pm

How long is the vsync pulse?

ZeroWalker
Posts: 57
Joined: Wed Nov 01, 2017 6:17 pm

Re: Decoding the Gameboy LCD output.

Post by ZeroWalker » Mon Nov 13, 2017 6:24 pm

About 16.75 ms, guess from Rise till first CLOCK pulse it's like 2-3ms.

Image

EDIT: wait my bad, wrong measure lo xd, it's 0.1ms.
So like 0.02ms (20us) till first CLOCK pulse. (thought it was weird it would wait an entire frame for the pulse xd).

Image

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Decoding the Gameboy LCD output.

Post by stevestrong » Mon Nov 13, 2017 6:45 pm

20µs is critical, you should really look to minimize the code size within the EXTI (rising edge) ISR. Can you post that critical code?

ZeroWalker
Posts: 57
Joined: Wed Nov 01, 2017 6:17 pm

Re: Decoding the Gameboy LCD output.

Post by ZeroWalker » Mon Nov 13, 2017 6:56 pm

It's barely as small as it gets xd

Code: Select all

// Start DMA on first VSYNC rise (to sync up the frame)
void VsyncOccur()
{

	// enable DMA
	dma_enable(DMA1, DMA_CH2);	// Enable the DMA tube. It will now begin serving requests.
	//dma_enable(DMA1, DMA_CH4);	// Enable the DMA tube. It will now begin serving requests.

	// disable the interrupt
	exti_detach_interrupt(EXTI0);
}
EDIT:

hmm it might be a problem on the decoding side, as it can differ on restart of the application decoding and reading the COM port.
Though normally it's the same.

EDIT2: or wait the decoding probably only messed up when i had VSYNC on for displaying it.
Otherwise it's always that 5 pixel offset going on.

EDIT3:
or...
it's weird, it seems it's always that 5 pixel offset, but after awhile, like 10-20 seconds maybe, it fixes itself, which makes no sense..

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Decoding the Gameboy LCD output.

Post by stevestrong » Mon Nov 13, 2017 8:14 pm

What if you remove both lines?
The DMA can stay enabled, and exti also.
You have plenty of time after the last line before next vsync, that is the best time to reinit what you want.

ZeroWalker
Posts: 57
Joined: Wed Nov 01, 2017 6:17 pm

Re: Decoding the Gameboy LCD output.

Post by ZeroWalker » Tue Nov 14, 2017 6:50 am

Well the Vsync is there to know when the frame started, so i need to start sending at that spot in order for 2880 bytes to be 1 correct frame.
And also i might need to resync with Vsync if it changed the timing (Reset, or game load etc).

Otherwise i would just be able to have it going and just ignore the Vsync.
And yeah you can tell when the Vsync occurs cause of the huge time difference between the CLOCK pulses,
problem is there's no way of knowing that except afterwards.

Post Reply