MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Pages: 1

palindrome
MAME Fan
Reged: 05/15/09
Posts: 14
Loc: NSW, Australia
Send PM


Aristocrat Mark 4 - need help with DS1302
#190801 - 05/18/09 03:10 PM Attachment: enchanted forest2.JPG 167 KB (4 downloads)


I've started a preliminary driver for the above platform and have a game up and running. I am currently working on the RTC, the board uses a DS1287 Dallas RTC chip.

There is a PIA-6821 adapter which provides various output signals to other devices including the RTC. I've discovered the address mapping for the RTC 0x5380 - 0x5381. If I simply just return 0x01 from my read_handler it sets the time,date and year to 01:01:01 01 JAN 01.

I may need to implement a proper handler for the RTC so that the random number generator will generate the correct reel stops.

MAME has a ds1302 driver but I have no idea how to use it and nobody seems to be using it for anything.

Available functions are.

extern void DS1302_RST(UINT8 val);
extern void DS1302_DAT(UINT8 val);
extern void DS1302_CLK(running_machine *machine, UINT8 val);
extern UINT8 DS1302_RD(void);

I could always get the time/date from the PC system and return that from my read handler but I guess that is almost cheating ?

Would appreciate any input.

[ATTACHED IMAGE - CLICK FOR FULL SIZE]

Attachment

Edited by palindrome (05/18/09 04:00 PM)



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


Re: Aristocrat Mark 4 - need help with DS1302 new [Re: palindrome]
#190844 - 05/19/09 01:25 AM


> extern void DS1302_RST(UINT8 val);
> extern void DS1302_DAT(UINT8 val);
> extern void DS1302_CLK(running_machine *machine, UINT8 val);
> extern UINT8 DS1302_RD(void);

That means the DS1302 has 3 input lines ("reset", "data in", and "clock") and 1 output (probably shared with "data in" in real life). Sounds like a bog-stock serial setup common for RTCs and EEPROMs. You need to figure out which lines on the PIA those are connected to and just wire it up. "Clock" should be obvious since it'll pulse 0-1-0-1 during reads and writes.

Edited by R. Belmont (05/19/09 01:55 AM)



palindrome
MAME Fan
Reged: 05/15/09
Posts: 14
Loc: NSW, Australia
Send PM


Re: Aristocrat Mark 4 - need help with DS1302 new [Re: R. Belmont]
#190906 - 05/19/09 03:58 PM


Hi. Thanks for the reply.

I made an incorrect assumption that the DS1302 was similar to the DS1287, a little research revealed that I should be using the mc146818, as it is a drop in replacement for the DS1287.

How could I wire this up to the PIA ? There does not seem to be an interface that will allow for that.



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


Re: Aristocrat Mark 4 - need help with DS1302 new [Re: palindrome]
#191008 - 05/20/09 08:13 PM


Looks like the PIA isn't even involved. Just hook up the read/write ports of the RTC at the two addresses you gave and it should work in theory.



byuu
MAME Fan
Reged: 03/17/06
Posts: 41
Send PM


Re: Aristocrat Mark 4 - need help with DS1302 new [Re: palindrome]
#191030 - 05/21/09 01:18 AM



Quote:


I could always get the time/date from the PC system and return that from my read handler but I guess that is almost cheating ?




If you're asking for how to emulate an RTC in general, there's caveats no matter what you do.

1. Use gettimeofday(), etc (eg use PC time):
Pros:
- no external files to keep track of time
- easy for user to adjust the time shown in-game

Cons:
- cannot simulate running emulation too fast or slow
- in-game clock setting / adjustment tools do nothing
- games that set the clock to test if its working fail
- libc functions break when you try and go before or after the platform epoch (eg pre-1970 and such)

2. Keep a time_t stamp as a diff. Each time the RTC is accessed, get a new time_t, determine the difference, update the emulated time, and sync the time_t values.
Pros:
- can set time in-game, test and adjust functions work

Cons:
- have to save the last time_t stamp to a file
- still can't simulate running fast or slow, or emulated time will desync with real time

3. Do not store a diff, increment counter along with running emulation.
Pros:
- again, no file on disk
- can properly simulate emulated time even during fast forward and rewind
- only option that is fully safe for save states

Cons:
- time does not pass with emulator closed. Trying to use a time_t diff only when the emulator is closed will only help a little, as time will still desync from PC time very easily.

----------

Bottom line is time adjust functions and RTC chips do not mix well together, and there's no bullet-proof solution to that.

So, it's really up to you. I prefer option 2, so long as users don't fast forward / rewind during hardware tests, and avoid save states, they get very accurate time passage that stays in sync with the PC time properly.

Option 3 is required if you want to make emulation completely invisible to the emulated hardware no matter what, but absolutely sucks to end users who are trying to keep the time in sync with their PCs.

Option 1 is just lazy :P
Only use that on games that do absolutely nothing with the RTC but show the time.



palindrome
MAME Fan
Reged: 05/15/09
Posts: 14
Loc: NSW, Australia
Send PM


Re: Aristocrat Mark 4 - need help with DS1287 new [Re: byuu]
#191639 - 05/28/09 11:48 AM


Hi.. thanks for the reply. I got it working properly at last and used method 2. I use MAME systime to get the basetime, it initially gets the time from the RTC simulator that I wrote, stores it to 3 different locations in NVRAM ( there are 3 copies of audit info [3-way memory] as a requirement for some jurisdictions) but then updates it internally by some other means.. not sure how it does it but it seems to be working like that. If I pause the emulation for a period of time or change the clock settings it does not update or sync based on my PC's time.

The game is still stuck in audit mode, the audit screen will appear when the audit key is turned 90 degrees clockwise. I am currently trying to map the input so I can go through all the modes of operation but finding them is proving to be difficult



palindrome
MAME Fan
Reged: 05/15/09
Posts: 14
Loc: NSW, Australia
Send PM


Re: Aristocrat Mark 4 - need help with DS1287 new [Re: R. Belmont]
#191640 - 05/28/09 11:51 AM


Yes the RTC is tied to PortA of the PIA, PortB us used for the output of signals to the mechanical meters.



Sune
Connected
Reged: 09/21/03
Posts: 5648
Loc: Lagoa Santa, Brasil
Send PM


Re: Aristocrat Mark 4 - need help with DS1302 new [Re: palindrome]
#193937 - 06/22/09 08:36 AM


> I could always get the time/date from the PC system and return that from my read
> handler but I guess that is almost cheating ?

In MAME, enter test mode in any Neo Geo game and visit the calendar, time and date is accurate.

Is that cheating?

S


Pages: 1

MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

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