PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Vertical blanking interrupt

Hi,
Many years ago when I used to program on a CBM 64 I used a technique that involved the vertical blanking interrupt (at least that's what I remember it was called). The idea being that when the visible part of the screen had been drawn an interrupt was triggered. This was an ideal time to trigger updates to the display buffer without any tearing of the moving graphics. It was also an ideal way of timing a game.

My question is: is there anything like this on a pocketpc? Is there any information about how the LCD displays are updated? Using a fast copy from a working buffer to display buffer (like easyCE) should reduce tearing but it's still likely and seems a shame when there is more than enough power in the machine to create very smooth graphics.

If there are other solutions, I'd love to hear about them. This is one of the many big holes in my knowledge of pocketpcs (and PCs in general) and I'd really like to understand more about it.

Thanks for your help,

Pawpoise
As far as I know, nobody has yet found a way to get this info.

Did anyone experimented something to find it? I remember discussions about updating the screen with certain patterns until the refresh rate was matched. But then... How do you know when the refresh starts?

I have the impression that this will be highly display-dependant and that there is no API to expose the functionality needed.
Orpe · 01 Mar 2002, 01:33 UTC — VSync for iPAQs
Since there's no API for detecting when the refresh starts it's probably hard to use what I just tried, but it works for iPAQs (at least for the 3660 that I've tested on so far).

On this model (and probably most of the others) the LCD controller which comes "built in" with the processor is used. It uses DMA to transfer data from the internal DRAM buffer to a small internal buffer (something like 5 DWORDS in size). This data is then used to drive the display. So, basically it does many short DMA transfers and the start address of these transfers can be read from a memory mapped register. (This requires some tinkering).

But, by reading this register you will know the approximate line it's currently refreshing and when this counter wraps around, you know that the refresh restarts at the top of the screen.

The time it takes for a wraparound to occur (approx 16687 microseconds) on my device indicates that the refresh rate is probably 60Hz (if you do the computation based on that single number you get 59.92Hz).

However, I'm not sure that having the vsync helps anything when it comes to vertical tearing (as you get from rotating blits). On a CRT there is actually a pause after the last line has been refreshed during which the ray is moved back up to the top again. This probably isn't the case on LCDs, they may just start at the top again straight away... but I don't really know how they work.

OTOH, when you're playing around with hardware registers like this, you may as well do things properly. It's actually possible to change the location from where the LCD controller reads data which means that the blit can be removed altogether. I haven't tried this yet but I probably will tomorrow. It doesn't seem very difficult. In this case you can do a rotating blit to a backbuffer and then switch/flip to this backbuffer by changing where the LCD reads data from.

/Orpe
I was pretty sure the PPC refresh rate was 24 Hz
If you can find out how to change the start address of the display, then there is indeed no need for vsync information.

Concerning rotation blits... Well I don't use any so this is not a concern for me...
I was just browsing through some old discussions and saw that I never reported back to this one about what happened with my attempts to avoid blits altogether by programming the LCD controller directly.

Well.. It turned out to be very hard because of a limitation in WCE 3.0. Programming the LCD controller is actually very easy but since it uses DMA you need to allocate some contigous physical memory to use for the video data. You cannot do this on WCE3.0 however, so that's where the experiments ended.

If anyone knows how to allocate a suitable buffer for this purpose I would be very happy to know about it. From what I've read, the only way to reserve contigous physical memory is to write some statements in a special config file when you actually build the WCE platform for your particular device.

/Roland
You cannot do this on WCE3.0 however, so that's where the experiments ended.


In theory, you can. It's just not easy. I keep trying to get time to have a hack at it, but I'm rather pressed with work right now :(

My main problem at the moment is that the MSDN/WinCE documentation is full of inaccuracies :( I'll try and have a hack at it over the weekend.

Cheers,

Ref.
you need to allocate some contigous physical memory to use for the video data. You cannot do this on WCE3.0 however, so that's where the experiments ended.


I've followed this thread with interest but have stranded here on this remark. Isn't all memory you allocate contiguous by default? If I do a malloc() of say 80kb, i'm pretty sure that the end is 80kb further than the beginning. Isn't that the definition of contiguous? Please enlighten me...


On the Gameboy advance they emulated the Crt on the lcd. they even implemented a vertical blank sequence where the lcd was not written. You could also ask the hardware where the 'beam' currenty was writing. Hopefully we'll be able to come up with something similar for the PPC since it results in much smoother screenupdates!

R

I've followed this thread with interest but have stranded here on this remark. Isn't all memory you allocate contiguous by default? If I do a malloc() of say 80kb, i'm pretty sure that the end is 80kb further than the beginning. Isn't that the definition of contiguous? Please enlighten me...


Well, yes that memory i contigous, but it is so in the virtual address space. That contigous block of virtual memory is then mapped to physical pages which are probably not contigous in the physical memory space (which is used when doing DMA transfers).

Also, the contiguos portion of virtual memory can correspond to different physical memory at different times because of paging.

Hmm.. hope that explanation makes some sense...

Orpe
Orpe is correct.

When you malloc an area of memory, you're requesting a block of virtual (aka logical ) memory, which is in the address space that the application "knows". So, the application thinks it has, say, 10, pages allocated to it, in a nice 0 to 9 set.

However, on the lower, physical, level, the pages could be all over the place.

What looks like:

0 1 2 3 4 5 6 7 8 9

to the application (logical memory) might actually be:

18 53 88 23 06 66 51 103 34 28
(i.e. all over the place)

in physical memory. The problem is that the DMA channel that's used to transfer the screen to the LCD must be contiguous at a *physical* level, as well as a logical level. So, you want to find a block of memory that's something like:

0 1 2 3 4 5 6 7 8 9 in logical memory
and
15 16 17 18 19 20 21 22 23 24 in physical memory

Unfortunately, PPC 2000 has nothing to do that, so you have to poke about, beat your head against the wall and try a hit-and-miss approach using Microsoft functions that lie to you.

IIRC .net has a function to do it.

(P.s. as Orpe says, virtual mappings can also map over the same physical pages:

0 1 2 3 4 5 6 7 8 9 logical
could map over
1 1 1 1 1 1 1 1 1 1 physical
if you were that way inclined ... i.e. mad)

Cheers,

Ref.
Okay,

I thought that the ARM processor didn't have a memorymanagement unit. I based that conclusion on the fact that CE doesn't support "memory mapped files". Or maybe that is because one of the other processors (sh3/mips) doesn't support it and it has to allow only the common denominator?

R
I thought that the ARM processor didn't have a memorymanagement unit.


It does have one, not all ARM processors do since it's optional (I think) but the StrongARM and XScale do have one. In fact, I don't think you can build a Pocket PC without supporting virtual memory.


I based that conclusion on the fact that CE doesn't support "memory mapped files". Or maybe that is because one of the other processors (sh3/mips) doesn't support it and it has to allow only the common denominator?


Windows CE does support memory mapped files. Check the documentation for MapViewOfFile, that function together with two or three other ones can be used to map a file into memory. I have used that myself and it's been supported since Windows CE 1.01.

Orpe
It does have one, not all ARM processors do since it's optional (I think)


Yep, it's optional. The first ARMs (the 2s and 3s) had to have external MMUs (IIRC), and you can use (all?) the ARM cores without an MMU (IIRC the ARM7TDMI core of the GBA doesn't have an MMU).

Almost every device that is supposed to run a "real" OS (WinCE, Linux, etc) will have an MMU on-board. Smaller devices like telephones with their own OSs or something like uLinux don't need an MMU. With the ARMs, it's up to the vendor to decide whether they need an MMU or not. For system-on-a-chip solutions like the StrongARM and XScale, an MMU is a must.

Cheers,

Ref.
I think you then have your solution there: I bet you can code the MMU from the Arm directly in assembly. It worked that way on the 680x0 too. Or is this image i have too simple?

R

I think you then have your solution there: I bet you can code the MMU from the Arm directly in assembly. It worked that way on the 680x0 too. Or is this image i have too simple?


It is possible to program the MMU but Windows CE wouldn't like it. It would probably crash WCE and cause all sorts of strange things. The main problem is that you really need to have one single manager of the memory (in this case the WCE OS). If you went in and changed memory mappings etc. WCE would just write them over etc. because it wouldn't know that you put them there...

However, with some amount of luck, when you do for example a VirtualAlloc (sort of like a malloc), the memory will be contigous both in the virtual and physical address spaces. Probably happens more often when the system is newly started. This could be verified by inspecting the memory map tables etc. but it probably wouldn't work often enough.. Haven't tried it though. Perhaps, if you VirtualAlloc say 4Mb of virtual memory, the chance of there being a section of contigous physical memory mapped in to it which is 128k or so is quite large. I think I'm going to try this actually.

On the ARM there are performance advantages associated with mapping quite large blocks of contigous physical memory into the virtual address space since it will make TLB hits more frequent in the processor. If WCE 3.0 tries to do this is another question though. It probably doesn't...

Orpe