void read_joy_responses(u8 resp[8*5]);
+void test_joy_read_log(u8 *dest, int size);
+void test_joy_read_log_vsync(u8 *dest, int size);
void run_game(u16 mapper, int tas_sync);
rts
+.global test_joy_read_log /* u8 *dest, int size */
+test_joy_read_log:
+ ldarg 0, 0, a1
+ ldarg 1, 0, d0
+ movem.l d2-d7, -(sp)
+ movea.l #0xa10003, a0
+ move.l d0, d7
+
+.macro joy_read_log_prep
+ move.l #0x40, d1
+ moveq.l #0, d0
+ move.b d1, (6,a0)
+ move.b d1, (a0)
+
+0: /* wait for special code */
+ move.b d1, (a0)
+ move.b (a0), d2
+ move.b d0, (a0)
+ move.b (a0), d3
+ and.b #0x3f, d2
+ cmp.b d2, d3
+ bne 0b
+ cmp.b #0x25, d2
+ bne 0b
+
+0: /* wait for special code to end */
+ cmp.b (a0), d2
+ beq 0b
+
+ move.b d1, (a0)
+ move.l #8000000/50/18, d2
+
+0: /* wait enough for teensy to setup it's stuff */
+ subq.l #1, d2 /* 8 */
+ bgt.s 0b /* 10 */
+.endm
+.macro nop_
+ /*
+ * when communicating with 3.3V teensy:
+ * - no nops: see old value on multiple pins randomly
+ * - 1 nop: only TR often shows old value
+ * - 2 nops: ?
+ */
+ nop
+ nop
+.endm
+
+ joy_read_log_prep
+
+2: /* save data */
+ move.b d0, (a0)
+ nop_
+ move.b (a0), d2
+ move.b d1, (a0)
+ nop_
+ move.b (a0), d3
+ move.b d0, (a0)
+ nop_
+ move.b (a0), d4
+ move.b d1, (a0)
+ nop_
+ move.b (a0), d5
+.if 0
+ /* broken on Mega-ED v9?? */
+ move.b d2, (a1)+
+ move.b d3, (a1)+
+ move.b d4, (a1)+
+ move.b d5, (a1)+
+.else
+ lsl.w #8, d2
+ move.b d3, d2
+ move.w d2, (a1)+
+ lsl.w #8, d4
+ move.b d5, d4
+ move.w d4, (a1)+
+.endif
+
+ /* delay for teensy, 128 not enough.. */
+ move.l #256, d2
+0:
+ dbra d2, 0b
+
+ subq.l #4, d7
+ bgt.s 2b
+
+ movem.l (sp)+, d2-d7
+ rts
+
+
+.global test_joy_read_log_vsync /* u8 *dest, int size */
+test_joy_read_log_vsync:
+ ldarg 0, 0, a1
+ ldarg 1, 0, d0
+ movem.l d2-d7/a2, -(sp)
+ movea.l #0xa10003, a0
+ movea.l #0xc00005, a2
+ move.l d0, d7
+
+ /* syncs, sets d0=0, d1=0x40 */
+ joy_read_log_prep
+
+2: /* save data */
+ move.b d0, (a0)
+ move.b (a0), d2
+ move.b d1, (a0)
+ move.b (a0), d3
+ move.b d2, (a1)+
+ move.b d3, (a1)+
+
+ /* wait for next vsync */
+ moveq.l #3, d2
+0:
+ btst d2, (a2)
+ bne.s 0b
+0:
+ btst d2, (a2)
+ beq.s 0b
+
+ subq.l #2, d7
+ bgt.s 2b
+
+ movem.l (sp)+, d2-d7/a2
+ rts
+
+
.global run_game /* u16 mapper, int tas_sync */
run_game:
move.w #0x2700, sr
ldarg 0, 0, d7
ldarg 1, 0, d6
- move.l #0xa10000, a6
- move.l #0xc00000, a5
- move.l #0xc00005, a4
- move.l #0xc00004, a3
+ movea.l #0xa10000, a6
+ movea.l #0xc00000, a5
+ movea.l #0xc00005, a4
+ movea.l #0xc00004, a3
moveq.l #0x00, d2
move.b #0xff, d3
move.b #0x40, d4
switch (b3)
{
+ case '0':
+ printf("reading..\n");
+ test_joy_read_log((void *)0x200000, 0x20000);
+ //test_joy_read_log((void *)0xff0200, 0x0f000);
+ printf("done\n");
+ return 0;
+ case '1':
+ printf("reading w/vsync..\n");
+ test_joy_read_log_vsync((void *)0x200000, 3600 * 2);
+ printf("done\n");
+ return 0;
case 'j':
test_joy_latency(&min, &max);
printf("latency: %d - %d\n\n", min, max);