MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Pages: 1

DeKay
MAME Fan
Reged: 12/31/12
Posts: 2
Send PM


Advice needed: Atmega 128 support in avr emulator
#301696 - 12/31/12 07:56 PM


Hi. I am working on emulating my weather station console. The console runs an Atmel Atmega 128 processor that supports 128K of flash rather than up to 64K in the AVR88 and AVR644 processors supported now in avr8.c. That was easy to get around with a new constructor and support I added for the ELPM instruction.

The problem I'm hitting now is that the register map for the 128L is very different from the others. I could define a new set of enums for the 128, but that only gets me so far. The READ8 and WRITE8 members are written assuming the AVR8 enums. I could make AVR128 specific routines for that, but then the next problem is that all the SPI, timer, etc routines are also AVR8 register specific.

So, what is the best way to generically handle this? Monster changes within the current code might be tricky given that I'm pretty new to this stuff, don't have commit access, and I didn't write the original code to begin with. A separate emulator for the 128 seems a bit like overkill given the similarity between the two architectures. Some code to generate emulators for each of the individual architectures would be nice but would again be a lot of work.

Any advice?



StilettoAdministrator
They're always after me Lucky ROMS!
Reged: 03/07/04
Posts: 6472
Send PM


Re: Advice needed: Atmega 128 support in avr emulator new [Re: DeKay]
#301700 - 12/31/12 09:41 PM


> Hi. I am working on emulating my weather station console. The console runs an Atmel
> Atmega 128 processor that supports 128K of flash rather than up to 64K in the AVR88
> and AVR644 processors supported now in avr8.c. That was easy to get around with a new
> constructor and support I added for the ELPM instruction.
>
> The problem I'm hitting now is that the register map for the 128L is very different
> from the others. I could define a new set of enums for the 128, but that only gets me
> so far. The READ8 and WRITE8 members are written assuming the AVR8 enums. I could
> make AVR128 specific routines for that, but then the next problem is that all the
> SPI, timer, etc routines are also AVR8 register specific.
>
> So, what is the best way to generically handle this? Monster changes within the
> current code might be tricky given that I'm pretty new to this stuff, don't have
> commit access, and I didn't write the original code to begin with. A separate
> emulator for the 128 seems a bit like overkill given the similarity between the two
> architectures. Some code to generate emulators for each of the individual
> architectures would be nice but would again be a lot of work.
>
> Any advice?

From Ryan Holtz, the primary author of avr8.c:


Quote:


With the recent conversion of the AVR8 core to use C++, it would be fairly simple to handle registers and memory maps differently across different models of the CPU. My advice would be to add a layer of indirection to the register lookups. For example, the OCR1B MSB is defined as:


Code:

#define AVR8_OCR1BH                (m_r[AVR8_REGIDX_OCR1BH])



It might instead be re-worked to something like this:


Code:

#define AVR8_OCR1BH                (m_r[m_model_remap[AVR8_REGIDX_OCR1BH]])



m_model_remap would be a table of UINT8s which re-maps the generic AVR8_REGIDX_* enum into the correct memory location for that particular model of AVR, populated in the device_start() function for that particular derived core.

Similarly, in avr8_device::regs_w and avr8_device::regs_r, you might insert something like this at the top of the write8/read8 members:


Code:

offset = m_model_demap[offset];



With m_model_demap being the inverse table of m_model_remap, which re-maps the device-specific enum into the generic AVR8_REGIDX_* enum so that the switch() statement can continue to switch on const values.

If you have any other questions, don't hesitate to pop by #messdev on EFNet on IRC, or the MESS-specific forums at http://forums.bannister.org/




(Sorry, he's not a member of these forums.)

By the way, provided the weather station isn't newer than early 2010, I'm sure MESS would be happy to see if it could incorporate your emulation, assuming it was one of those mass-produced models out there and not a homebrew.

- Stiletto



DeKay
MAME Fan
Reged: 12/31/12
Posts: 2
Send PM


Re: Advice needed: Atmega 128 support in avr emulator new [Re: Stiletto]
#301701 - 12/31/12 09:51 PM


Thanks Stiletto. This is very helpful.


Pages: 1

MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

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