DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/clockdomain.h
00001 
00002 /* DOSBox-X clock domain class.
00003  * The clock domain implementation allows DOSBox-X to accurately
00004  * track time in clocks instead of less precise floating point
00005  * intervals, and to more accurately emulate hardware in terms of
00006  * the reference clock.
00007  *
00008  * (C) 2014 Jonathan Campbell */
00009 
00010 #include <stdint.h>
00011 #include <assert.h>
00012 #include <math.h>
00013 
00014 #include <string>
00015 #include <vector>
00016 #include <list>
00017 
00018 #ifndef DOSBOX_CLOCKDOMAIN_H
00019 #define DOSBOX_CLOCKDOMAIN_H
00020 
00021 #include "dosbox.h"
00022 /* this code contains support for existing DOSBox code that uses PIC_AddEvent, etc. callbacks */
00023 #include "pic.h"
00024 
00025 class ClockDomain {
00026 public:
00027         ClockDomain() {
00028                 freq = 0;
00029                 freq_div = 1;
00030         counter = 0;
00031         }
00032         ClockDomain(unsigned long long freq_new) {
00033                 freq = freq_new;
00034                 freq_div = 1;
00035         counter = 0;
00036         }
00037         /* we allow non-integer frequencies as integer fractions.
00038          * example: 33.3333333...MHz as 100,000,000Hz / 3 */
00039         ClockDomain(unsigned long long freq_new,unsigned long long div) {
00040                 freq = freq_new;
00041                 freq_div = div;
00042         counter = 0;
00043         }
00044 public:
00045         void set_name(const char *s) {
00046                 name = s;
00047         }
00048         void set_frequency(unsigned long long freq_new,unsigned long long div_new=1) {
00049                 counter = 0;
00050                 freq = freq_new;
00051                 freq_div = div_new;
00052         }
00053         const char *get_name() {
00054                 return name.c_str();
00055         }
00056 public:
00057         /* NTS: Slave clock rules:
00058          *       - Must have the same "freq" value as master
00059          *       - Do not set clock time by floating point time (only the toplevel clocks in the tree should do that)
00060          *       - Must rebase at the same reference time as the master
00061          *       - Must maintain time according to master time divided by master's clock divider */
00062         unsigned long long              freq,freq_div;  /* frequency of clock as integer ratio */
00063         unsigned long long              counter;        /* in units of freq */
00064         std::string                     name;
00065 };
00066 
00067 #endif //DOSBOX_CLOCKDOMAIN_H
00068