1

I think the answer will be no but I wanted to ask anyway. I just thought it would be a good way to find out how long a piece of code takes to execute.

Thank you smile

EDIT : I have another question. Can you set both Timer-high and Timer-Low by writing to Timer-Low *only* with a longword? Or do you have to set them both seperately?

2

...a good way to find out how long a piece of code takes to execute.

You should check Job_meter

Can you set both Timer-high and Timer-Low by writing to Timer-Low *only* with a longword?

I'm not sure... just give it a try.

3

Hey blastar. Good to see you back here. I was actually just talking about you on a Neo Geo forum! Was wondering how your robot platformer is going?

I actually found some code yesterday that Razoola had posted in your ChunkyMode thread that waited for a particular display line. So I used that (Thanks Razoola!). Then I ran my code segment and then I made another function to read the display line number after the code had finished. So I will probably use that now. I think this might be more accurate than using colors (it can be hard to count lines with colors). I do like the Job Meter idea though - shows a good representation of how long each task takes,

BTW Is it possible to change background color in middle of a line on real hardware? Because on MAME it only seems to update a line at a time

4

Reading the timer and displaying the difference is of course more accurate but this number can change with every frame which makes reading a bit difficult... displaying the colours is a bit less accurate but gives a good indication of the screen time used. you should definitely try both options to see what works better for you, might depend on what you want to do.... personally I prefer colours... mostly!

BTW Is it possible to change background color in middle of a line on real hardware? Because on MAME it only seems to update a line at a time

in theory it is possible but very hard to time. also, writing to the palRam creates artefacts during screen access (random white pixels like snow)... this is also discussed in the chunkymode thread. MAME is somewhat inaccurate at this point (but far better than any other emulator) and the snow is also not visible.

5

So can you actually read the timer on the Neo Geo then? It didn't work when I tried it. I checked the tech wiki and it implies you can't read it. It says that reads on Timer-Low and Timer-High are instead mirrors of REG_VRAMADDR and REG_VRAMRW. I was wondering if there is another way to do it?

I have a piece of C code in a loop that could get run maybe 700 times a frame. Eventually i will need to make it fast as possible. So just thinking ahead to when I have to optimize it.

I thought the background color could be used to get an exact reading of how many screen lines it takes up - since it would show partial lines too. It's a shame MAME can't do that, then there wouldn't be that palette ram issue. Oh well...

6

If it's not possible to read the actual Timer. I thought of a way to get the exact time taken by a piece of code. I *think* this would work

First REG_LSPCMODE could be used get the number of complete display lines taken

Then at the end of the piece of code to be tested set a value in memory to 1. Then repeatedly (over successive frames) run a timer interrupt that interrupts the code at different points on the final display line to check if this memory location has been set to 1 yet. It could be done it in smart way - e.g. first check halfway through the line, then half that distance and so on.

It would be a bit over-kill to program but for very time sensitive routines it would be useful to measure small incremental gains when optimizing them

7

If the code needs to run 700 times per frame, then it must run in (much) less than the time required to draw one scanline, since there are only 262 or 288 total scanlines per frame. So counting scanlines isn't going to work in this case.

The other technique is interesting and sounds like it could work.

I assume the emulators either don't have a cycle counter, or it isn't accurate? Because otherwise, it'd be both the most precise and the easiest option.

You can also post your code here and get feedback on how to optimize it smile
avatar
Zeroblog

« Tout homme porte sur l'épaule gauche un singe et, sur l'épaule droite, un perroquet. » — Jean Cocteau
« Moi je cherche plus de logique non plus. C'est surement pour cela que j'apprécie les Ataris, ils sont aussi logiques que moi ! » — GT Turbo

8

Yes that's true! I didn't even think about that smile

I suppose I could just run it a lot of times (1000 for example) and measure that overall time and optimize it based on that it.

I will definitely post it here when I get to that optimization stage. I want to get my whole program working first and then I will work on speeding the individual parts up. I've done a little optimization on it already by using bit shifts and by avoiding divides/multiplies where possible.

I will look into the cycle counter. I don't really know the advanced features of MAME. I used the debugger once to check some C code was compiling correctly but that's the limit of my expertise so far.