MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Pages: 1

dma.request
MAME Fan
Reged: 10/14/10
Posts: 17
Send PM


How to get real offset
#346832 - 11/09/15 12:08 PM


Hi again .

If I have for example:
AM_RANGE(0x1000, 0x1FFF) AM_MIRROR(0x3FC) AM_WRITE (test_w)

WRITE8_MEMBER (test_state :: test_w)
{
int real_ofs = ??? (offset);
printf ("0x%04X\n", real_ofs);
}

How to get the real offset (e.g. excluding the mirror address 'effect') into the test_w handler?

Additionally, what exactly AM_MIRROR does?

Is it a module of 0x3FC of the address, perhaps?



AWJ
Reged: 03/08/05
Posts: 936
Loc: Ottawa, Ontario
Send PM


Re: How to get real offset new [Re: dma.request]
#346834 - 11/09/15 07:56 PM


> Hi again .
>
> If I have for example:
> AM_RANGE(0x1000, 0x1FFF) AM_MIRROR(0x3FC) AM_WRITE (test_w)
>
> WRITE8_MEMBER (test_state :: test_w)
> {
> int real_ofs = ??? (offset);
> printf ("0x%04X\n", real_ofs);
> }
>
> How to get the real offset (e.g. excluding the mirror address 'effect') into the
> test_w handler?
>
> Additionally, what exactly AM_MIRROR does?
>
> Is it a module of 0x3FC of the address, perhaps?

That's not how you use AM_MIRROR and that address map entry doesn't make any sense. AM_MIRROR causes the specified mirror bits to be ORed with the AM_RANGE bits. For example,

AM_RANGE(0x1000, 0x1003) AM_MIRROR (0x03fc) AM_WRITE(foo_w)

causes foo_w to be mapped at every address from 0x1000 to 0x13ff.

Your use of AM_MIRROR doesn't make any sense because the range 0x1000, 0x1fff already contains all the bits in 0x3fc.

I think what you actually want is AM_MASK, but it isn't clear to me what you're trying to do. Can you try to explain better what you mean by "real offset"?



Haze
Reged: 09/23/03
Posts: 5245
Send PM


Re: How to get real offset new [Re: dma.request]
#346835 - 11/09/15 07:57 PM


you're not meant to, if something has AM_MIRROR the assumption is that all mirrored addresses behave the same, if that isn't the case, don't use AM_MIRROR

also your use or AM_MIRROR is incorrect anyway.



dma.request
MAME Fan
Reged: 10/14/10
Posts: 17
Send PM


Re: How to get real offset new [Re: Haze]
#346839 - 11/09/15 09:30 PM


Thank you both for the answers!

...Then let's see... your example:

AM_RANGE(0x1000, 0x1003) AM_MIRROR (0x03fc) AM_WRITE(foo_w)

is equivalent to (linear code):

if ((addr >= 0x1000) && (addr <= (0x1003 | 0x03fc)))
foo_w (...);

???

With 'real offset' or better 'real address' I mean the 'original' address...

For example:

Again in your example:
if real_address = 0x1002, foo_w will be called with offset = 0x1002 - 0x1000 = 0x0002...

But, is there a way inside the foo_w handler to get this value (0x1002) instead of offset 0x0002 ?

Another question: if real_address = 0x1234, then a mirror address..., how to calculate offset? (0x1234 - 0x1000) & 3 = 0x0002 ???

Thanks again.



dma.request
MAME Fan
Reged: 10/14/10
Posts: 17
Send PM


Re: How to get real offset new [Re: dma.request]
#346880 - 11/10/15 08:33 PM


No more answers? :/
Please..., I need to know.



Haze
Reged: 09/23/03
Posts: 5245
Send PM


Re: How to get real offset new [Re: dma.request]
#346902 - 11/11/15 11:03 AM


you've already been told, you can't.

the reason for this is simple, a device (on a PCB) does not know about address lines that are not connected to it.

MAME isn't a project where we can hold your hand at every step, it's a project where you need to search through what's already there and learn from it. The approach you're trying to use for whatever you're trying to do is incorrect.



dma.request
MAME Fan
Reged: 10/14/10
Posts: 17
Send PM


Re: How to get real offset new [Re: Haze]
#346904 - 11/11/15 01:07 PM


Ok, gotcha about the offset.

...Sorry, what do you mean exactly? I can't ask anything about MAME programming because I have to learn it by myself?

If not so (and you can continue to answer to my questions)...
Can you be more specific about use of AM_MIRROR (some examples)?

It is equivalent to the statement i wrote above?
If so, why I have to use:
AM_RANGE(0x1000, 0x1003) AM_MIRROR(0x3FC)

and not:
AM_RANGE(0x1000, 0x13FF)
therefore without AM_MIRROR usage?



Haze
Reged: 09/23/03
Posts: 5245
Send PM


Re: How to get real offset new [Re: dma.request]
#346906 - 11/11/15 06:02 PM


> Ok, gotcha about the offset.
>
> ...Sorry, what do you mean exactly? I can't ask anything about MAME programming
> because I have to learn it by myself?
>
> If not so (and you can continue to answer to my questions)...
> Can you be more specific about use of AM_MIRROR (some examples)?
>
> It is equivalent to the statement i wrote above?
> If so, why I have to use:
> AM_RANGE(0x1000, 0x1003) AM_MIRROR(0x3FC)
>
> and not:
> AM_RANGE(0x1000, 0x13FF)
> therefore without AM_MIRROR usage?

you can use the first statement and the offset will automatically be masked for you (the entire range of 0x1000-0x13ff is covered, but only 0x0-0x3 will be passed as an offset to the handler)

if you use the 2nd statement 0x000-0x3ff will be passed to the handler, so you might have to do masking in the actual handler.

quite a lot of the devices in MAME don't do their own masking, so the 2nd case wouldn't work for them whereas the first case would.

I'm not saying you can't ask any questions about MAME, but this is fairly basic stuff you're having to ask about, which doesn't really bode well as the majority of working on MAME is about self-learning and understanding things for which there is no documentation so I'm just advising you that you're going to encounter far more difficult tasks than this.



dma.request
MAME Fan
Reged: 10/14/10
Posts: 17
Send PM


Re: How to get real offset new [Re: Haze]
#346914 - 11/11/15 08:45 PM


Thanks, It makes sense now! :-)

I'm aware that this is a simple thing, but i'm just learning something basic indeed.
And yes, I know that there are more difficult things in mame, but I'm just a beginner, so I need lots of clarifications.



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: How to get real offset new [Re: dma.request]
#346915 - 11/11/15 08:54 PM


> Additionally, what exactly AM_MIRROR does?
>
> Is it a module of 0x3FC of the address, perhaps?

AM_MIRROR is a bit-inverted inverted mask against the address.

So for 0x3FC, it's inverted to 0xFFFFFC03, and that's ANDed with the address to see if it matches.



dma.request
MAME Fan
Reged: 10/14/10
Posts: 17
Send PM


Re: How to get real offset new [Re: R. Belmont]
#346928 - 11/12/15 03:25 AM


Thanks for giving further details.

I tested it and of course it works , but what's the advantage of use this compared to the 'direct' OR method with AM_MIRROR value?



Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4462
Loc: Melbourne, Australia
Send PM


Re: How to get real offset new [Re: dma.request]
#346935 - 11/12/15 05:25 AM


> Thanks, It makes sense now! :-)
>
> I'm aware that this is a simple thing, but i'm just learning something basic indeed.
> And yes, I know that there are more difficult things in mame, but I'm just a
> beginner, so I need lots of clarifications.

You also have to be aware that in some cases, you're just going to have to do the masking yourself in your handler function. For example look at this one:
https://github.com/mamedev/mame/blob/master/src/mame/machine/osborne1.cpp#L65
There is logic on the mainboard to identify I/O requests in the 0x2000-0x3fff range, but each peripheral only checks two additional address bits. This means that it's possible to select an address that will write to multiple peripherals at once, e.g. 0x2e00-0x2eff will write to both the video PIA and serial ACIA. MAME caters for common cases, but there are a lot of ways you can hook physical hardware up.


Pages: 1

MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 35 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 2569