Skip to content

Commit

Permalink
Handle vblank interrupts on the master SH2
Browse files Browse the repository at this point in the history
Using the m68k for that was prone to race conditions: occasionally
the ticcount would go backwards
  • Loading branch information
viciious committed Apr 30, 2021
1 parent cf67e91 commit 427cf1a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion 32x.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
#define MARS_SYS_COMM6 (*(volatile unsigned short *)0x20004026)
#define MARS_SYS_COMM8 (*(volatile unsigned short *)0x20004028) /* controller 1 current value */
#define MARS_SYS_COMM10 (*(volatile unsigned short *)0x2000402A) /* controller 2 current value */
#define MARS_SYS_COMM12 (*(volatile unsigned long *)0x2000402C) /* vcount current value */
#define MARS_SYS_COMM12 (*(volatile unsigned short *)0x2000402C)
#define MARS_SYS_COMM14 (*(volatile unsigned short *)0x2000402C)

#define MARS_PWM_CTRL (*(volatile unsigned short *)0x20004030)
#define MARS_PWM_CYCLE (*(volatile unsigned short *)0x20004032)
Expand Down
6 changes: 6 additions & 0 deletions crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ master_vbi:
nop

! handle V IRQ
mov.l vblank_count_ptr,r1
mov.l @r1,r0
add #1,r0
mov.l r0,@r1

mov.l @r15+,r1
mov.l @r15+,r0
Expand All @@ -465,6 +469,8 @@ master_vbi:
.align 2
mvi_mars_adapter:
.long 0x20004000
vblank_count_ptr:
.long _vblank_count

!-----------------------------------------------------------------------
! Master H Blank IRQ handler
Expand Down
6 changes: 5 additions & 1 deletion marsnew.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const int COLOR_WHITE = 0x04;
int activescreen = 0;
short *dc_colormaps;

int vblank_count = 0;

extern int debugmode;

static volatile pixel_t *framebuffer = &MARS_FRAMEBUFFER + 0x100;
Expand Down Expand Up @@ -107,6 +109,8 @@ void Mars_Init(void)
palette[i] = 0;
palette[COLOR_WHITE] = 0x7fff;

MARS_SYS_INTMSK |= 1 << 3; // enable vblank interrupts

MARS_SYS_COMM4 = 0;
}

Expand Down Expand Up @@ -300,7 +304,7 @@ int I_ReadControls(void)

int I_GetTime (void)
{
return MARS_SYS_COMM12;
return vblank_count;
}

/*
Expand Down
5 changes: 0 additions & 5 deletions src-md/crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ init_hardware:
beq.b 3f /* no mouse */
move.w #0xF001,0xA1512A /* mouse in port 2 */
3:
move.l #0,0xA1512C /* clear the vblank count */

| allow the 68k to access the FM chip
move.w #0x0100,0xA11100 /* Z80 assert bus request */
Expand Down Expand Up @@ -389,10 +388,6 @@ vert_blank:
bsr.b get_pad
move.w d2,0xA1512A /* controller 2 current value */
1:
move.l 0xA1512C,d0
addq.l #1,d0
move.l d0,0xA1512C /* increment the vblank count */

tst.w gen_lvl2
beq.b 2f
lea 0xA12000,a0
Expand Down

0 comments on commit 427cf1a

Please sign in to comment.