• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión1310ff8c398b9ba440430383dc9b9ea53ff00ac2 (tree)
Tiempo2015-12-27 16:37:39
AutorYoshinori Sato <ysato@user...>
CommiterYoshinori Sato

Log Message

TPU simulation

Cambiar Resumen

Diferencia incremental

--- a/sim/rx/mem.c
+++ b/sim/rx/mem.c
@@ -592,10 +592,21 @@ mem_get_content_type (int address)
592592 #define TMRI_CMB (1<<1)
593593 #define TMRI_OVF (1<<0)
594594
595+#define TPU_CH 6
596+#define TPU_TSTR (tpubase[0])
597+#define TPU_TCR(ch) (tpubase[(ch+1) * 0x10 + 0])
598+#define TPU_TSR(ch) (tpubase[(ch+1) * 0x10 + 5])
599+#define TPU_TCNTH(ch) (tpubase[(ch+1) * 0x10 + 7])
600+#define TPU_TCNTL(ch) (tpubase[(ch+1) * 0x10 + 6])
601+#define TPU_GRAH(ch) (tpubase[(ch+1) * 0x10 + 9])
602+#define TPU_GRAL(ch) (tpubase[(ch+1) * 0x10 + 8])
603+#define TPU_GRBH(ch) (tpubase[(ch+1) * 0x10 + 11])
604+#define TPU_GRBL(ch) (tpubase[(ch+1) * 0x10 + 10])
605+
595606 static unsigned char get_tmrisr(int ch)
596607 {
597608 unsigned char *irptr = rx_mem_ptr(IRADR(174 + ch * 3), MPA_READING);
598- unsigned char isr;
609+ unsigned char isr = 0;
599610 unsigned int i;
600611 for (i = 0; i < 3; i++)
601612 {
@@ -757,6 +768,80 @@ cmt_update(int cycles_diff)
757768 }
758769 }
759770
771+static void
772+tpu_update(unsigned int cycles_diff)
773+{
774+ static int prescale[4]={1,4,16,64};
775+ const int prescale_div[4]={1,4,16,64};
776+ int tm, cnt, pcnt, gr, pulse;
777+ unsigned char *tpubase = rx_mem_ptr(0x00088100, MPA_WRITING);
778+
779+ for (pcnt = 0; pcnt < 4; pcnt++) {
780+ prescale[pcnt] -= cycles_diff;
781+ pulse = -prescale[pcnt] / prescale_div[pcnt] + 1;
782+ if (prescale[pcnt]<=0)
783+ {
784+ /* input time pulse */
785+ for(tm=0; tm < TPU_CH; tm++) {
786+
787+ /* Timer enable check */
788+ if (!(TPU_TSTR & (1 << tm)))
789+ continue;
790+
791+ /* update counter */
792+ if ((TPU_TCR(tm) & 0x0f) == pcnt)
793+ {
794+ cnt = ((TPU_TCNTH(tm) << 8) | TPU_TCNTL(tm));
795+ cnt += pulse;
796+
797+ /* CNT overflow check */
798+ if (cnt>=0x10000)
799+ {
800+ int cascade_low = tm % 3;
801+ cnt -= 0x10000;
802+ if (cascade_low == 2)
803+ {
804+ int cascade_high = tm - cascade_low + 1;
805+ if ((TPU_TCR(cascade_high) & 0x0f) == 0x0f)
806+ {
807+ int cascade_cnt;
808+ cascade_cnt = ((TPU_TCNTH(cascade_high) << 8) |
809+ TPU_TCNTL(cascade_high));
810+ cascade_cnt++;
811+ TPU_TCNTH(cascade_high) = (cascade_cnt >> 8);
812+ TPU_TCNTL(cascade_high) = cascade_cnt & 0xff;
813+ }
814+ }
815+ }
816+
817+ /* GRA compare match check*/
818+ gr = (TPU_GRAH(tm) << 8) | TPU_GRAL(tm);
819+ if (cnt >= gr)
820+ {
821+ if ((TPU_TCR(tm) & 0xe0) == 0x20)
822+ cnt = 0;
823+ }
824+
825+ /* GRB compare match check*/
826+ gr = (TPU_GRBH(tm) << 8) | TPU_GRBL(tm);
827+ if (cnt >= gr)
828+ {
829+ if ((TPU_TCR(tm) & 0xe0) == 0x40)
830+ cnt = 0;
831+ }
832+
833+ /* update TCNT */
834+ TPU_TCNTH(tm) = (cnt >> 8);
835+ TPU_TCNTL(tm) = cnt & 0xff;
836+ }
837+
838+ }
839+ prescale[pcnt]+=prescale_div[pcnt];
840+ /* update TSR */
841+ }
842+ }
843+}
844+
760845 #define SMR(ch) (scibase[(ch) * 8 + 0])
761846 #define BRR(ch) (scibase[(ch) * 8 + 1])
762847 #define SCR(ch) (scibase[(ch) * 8 + 2])
@@ -1117,6 +1202,7 @@ int io_simulation(cpupri)
11171202 prev_pcycle = pcycles;
11181203 tmr_update(3, pcycle_diff);
11191204 cmt_update(pcycle_diff);
1205+ tpu_update(pcycle_diff);
11201206 sci(pcycle_diff);
11211207 return icu(cpupri);
11221208 }