megadrive_test2

changeset 1:2560a8be8cb8

hblank interrupt test
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 14 Mar 2017 09:02:43 +0200
parents ce1b05082ac4
children 1d35c3b3a525
files Makefile src/intr.s src/main.c src/startup.s src/vdp.h src/vdpdefs.inc
diffstat 6 files changed, 83 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Tue Mar 14 05:59:33 2017 +0200
     1.2 +++ b/Makefile	Tue Mar 14 09:02:43 2017 +0200
     1.3 @@ -10,7 +10,7 @@
     1.4  warn = -pedantic -Wall
     1.5  dbg = -g
     1.6  def = -DGAMENAME=\"testgame\" -DVERSTR=\"01\" -D__NO_CTYPE
     1.7 -inc = -Isrc/libc
     1.8 +inc = -Isrc -Isrc/libc
     1.9  
    1.10  tool_prefix = m68k-linux-gnu-
    1.11  
    1.12 @@ -21,7 +21,7 @@
    1.13  
    1.14  CFLAGS = -m68000 -ffreestanding -fno-builtin $(warn) $(dbg) $(opt) $(def) $(inc)
    1.15  CPPFLAGS = $(def)
    1.16 -ASFLAGS = -m68000
    1.17 +ASFLAGS = -m68000 $(inc)
    1.18  LDFLAGS = -T megadrive.ldscript -print-gc-sections \
    1.19  		  -L/usr/lib/gcc-cross/m68k-linux-gnu/6 -lgcc
    1.20  
     2.1 --- a/src/intr.s	Tue Mar 14 05:59:33 2017 +0200
     2.2 +++ b/src/intr.s	Tue Mar 14 09:02:43 2017 +0200
     2.3 @@ -71,12 +71,36 @@
     2.4  | from here on we continue in the regular .text section since we don't care
     2.5  | where this code ends up.
     2.6  	.text
     2.7 +
     2.8 +.global enable_intr
     2.9 +enable_intr:
    2.10 +	andi.w #0xf8ff, %sr
    2.11 +	rts
    2.12 +
    2.13 +.global disable_intr
    2.14 +disable_intr:
    2.15 +	ori.w #0x0300, %sr
    2.16 +	rts
    2.17 +
    2.18  | interrupt handlers
    2.19  intr_fatal:
    2.20  	stop #0x2700
    2.21  
    2.22 -| TODO hblank/vblank code
    2.23 +	.include "vdpdefs.inc"
    2.24 +	.extern hblank_handler
    2.25 +	.extern vblank_handler
    2.26 +	.extern palval
    2.27 +
    2.28  intr_hblank:
    2.29 +	move.l #0xc0020000, VDP_PORT_CTL
    2.30 +
    2.31 +	move.w testcol, %d0
    2.32 +	move.w %d0, VDP_PORT_DATA
    2.33 +	rol.b #4, %d0
    2.34 +	move.w %d0, testcol
    2.35 +
    2.36  	rte
    2.37 +
    2.38  intr_vblank:
    2.39 +	jsr vblank_handler
    2.40  	rte
     3.1 --- a/src/main.c	Tue Mar 14 05:59:33 2017 +0200
     3.2 +++ b/src/main.c	Tue Mar 14 09:02:43 2017 +0200
     3.3 @@ -1,13 +1,31 @@
     3.4 +#include <stdint.h>
     3.5  #include "vdp.h"
     3.6  
     3.7  int main(void)
     3.8  {
     3.9  	vdp_init();
    3.10  
    3.11 +	vdp_set_pal_entry(0, 0, 0, 0, 0);
    3.12  	vdp_set_pal_entry(0, 1, 7, 0, 3);
    3.13  	vdp_set_bgcolor(0, 1);
    3.14  
    3.15 +	vdp_enable_hintr(12);
    3.16 +	vdp_enable_vintr();
    3.17 +
    3.18  	for(;;);
    3.19  
    3.20  	return 0;
    3.21  }
    3.22 +
    3.23 +uint16_t testcol = 0x00c0;
    3.24 +
    3.25 +void hblank_handler(void)
    3.26 +{
    3.27 +	vdp_set_pal_entry(0, 1, ~testcol, 0, testcol);
    3.28 +	testcol = ~testcol;
    3.29 +}
    3.30 +
    3.31 +void vblank_handler(void)
    3.32 +{
    3.33 +	testcol = 0x00c0;
    3.34 +}
     4.1 --- a/src/startup.s	Tue Mar 14 05:59:33 2017 +0200
     4.2 +++ b/src/startup.s	Tue Mar 14 09:02:43 2017 +0200
     4.3 @@ -4,7 +4,7 @@
     4.4  	.global start
     4.5  	.global halt_cpu
     4.6  start:
     4.7 -	bsr.s disable_intr
     4.8 +	jsr disable_intr
     4.9  
    4.10  	| copy .data section from ROM to RAM
    4.11  	move.l #_data_lma, %a0
    4.12 @@ -30,18 +30,8 @@
    4.13  	| setup the stack pointer stack
    4.14  	move.l #_stacktop, %sp
    4.15  	| now that we have a stack, we can enable interrupts
    4.16 -	bsr.s enable_intr
    4.17 +	jsr enable_intr
    4.18  
    4.19  	jsr main
    4.20  halt_cpu:
    4.21  	stop #0x2700
    4.22 -
    4.23 -.global enable_intr
    4.24 -enable_intr:
    4.25 -	andi.w #0xf8ff, %sr
    4.26 -	rts
    4.27 -
    4.28 -.global disable_intr
    4.29 -disable_intr:
    4.30 -	ori.w #0x0300, %sr
    4.31 -	rts
     5.1 --- a/src/vdp.h	Tue Mar 14 05:59:33 2017 +0200
     5.2 +++ b/src/vdp.h	Tue Mar 14 09:02:43 2017 +0200
     5.3 @@ -20,7 +20,7 @@
     5.4  	VDP_REG_NAMETAB_B		= 4,
     5.5  	VDP_REG_SPRITE_TAB		= 5,
     5.6  	VDP_REG_BGCOL			= 7,
     5.7 -	VDP_REG_INTR			= 10,
     5.8 +	VDP_REG_HINTR			= 10,
     5.9  	VDP_REG_MODE3			= 11,
    5.10  	VDP_REG_MODE4			= 12,
    5.11  	VDP_REG_SCROLL_TAB		= 13,
    5.12 @@ -120,7 +120,7 @@
    5.13  
    5.14  static inline void vdp_setreg(int reg, uint8_t value)
    5.15  {
    5.16 -	/*vdp_reg_shadow[reg] = value;*/
    5.17 +	vdp_reg_shadow[reg] = value;
    5.18  	VDP_PORT_CTL = (uint16_t)value | (reg << 8) | (uint16_t)0x8000;
    5.19  }
    5.20  
    5.21 @@ -152,6 +152,27 @@
    5.22  	VDP_PORT_DATA = VDP_PACK_RGB(r, g, b);
    5.23  }
    5.24  
    5.25 +static inline void vdp_enable_vintr(void)
    5.26 +{
    5.27 +	vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_VINTR);
    5.28 +}
    5.29 +
    5.30 +static inline void vdp_disable_vintr(void)
    5.31 +{
    5.32 +	vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) & ~VDP_MODE2_VINTR);
    5.33 +}
    5.34 +
    5.35 +static inline void vdp_enable_hintr(int counter)
    5.36 +{
    5.37 +	vdp_setreg(VDP_REG_HINTR, counter);
    5.38 +	vdp_setreg(VDP_REG_MODE1, vdp_getreg(VDP_REG_MODE1) | VDP_MODE1_HINTR);
    5.39 +}
    5.40 +
    5.41 +static inline void vdp_disable_hintr(void)
    5.42 +{
    5.43 +	vdp_setreg(VDP_REG_MODE1, vdp_getreg(VDP_REG_MODE1) & ~VDP_MODE1_HINTR);
    5.44 +}
    5.45 +
    5.46  void vdp_init(void);
    5.47  
    5.48  #endif	/* VDP_H_ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/vdpdefs.inc	Tue Mar 14 09:02:43 2017 +0200
     6.3 @@ -0,0 +1,13 @@
     6.4 +| vi:filetype=asm68k:
     6.5 +	.equ VDP_PORT_DATA, 0xc00000
     6.6 +	.equ VDP_PORT_CTL, 0xc00004
     6.7 +
     6.8 +	.equ VDP_REG_MODE1, 0
     6.9 +	.equ VDP_REG_MODE2, 1
    6.10 +
    6.11 +	.equ VDP_WRITE_VRAM, 0x40000000
    6.12 +	.equ VDP_WRITE_CRAM, 0xc0000000
    6.13 +	.equ VDP_WRITE_VSRAM, 0x40000010
    6.14 +	.equ VDP_READ_VRAM, 0
    6.15 +	.equ VDP_READ_CRAM, 0x00000020
    6.16 +	.equ VDP_READ_VSRAM, 0x00000010