megadrive_test2

diff src/main.c @ 4:72ab63f262bf

tiles
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 19 Jun 2017 08:02:51 +0300
parents 1d35c3b3a525
children ea70f3da150f
line diff
     1.1 --- a/src/main.c	Tue Mar 14 09:11:18 2017 +0200
     1.2 +++ b/src/main.c	Mon Jun 19 08:02:51 2017 +0300
     1.3 @@ -1,25 +1,100 @@
     1.4  #include <stdint.h>
     1.5  #include "vdp.h"
     1.6  
     1.7 +uint32_t pat0[] = {
     1.8 +	0x00000000,
     1.9 +	0x00000000,
    1.10 +	0x00000000,
    1.11 +	0x00010000,
    1.12 +	0x00000000,
    1.13 +	0x00000000,
    1.14 +	0x00000000,
    1.15 +	0x00000000
    1.16 +};
    1.17 +
    1.18 +uint32_t pat1[] = {
    1.19 +	0x11111111,
    1.20 +	0x11000011,
    1.21 +	0x10100101,
    1.22 +	0x10011001,
    1.23 +	0x10011001,
    1.24 +	0x10100101,
    1.25 +	0x11000011,
    1.26 +	0x11111111
    1.27 +};
    1.28 +
    1.29 +uint32_t pat2[] = {
    1.30 +	0x11111111,
    1.31 +	0x10011001,
    1.32 +	0x10011001,
    1.33 +	0x11111111,
    1.34 +	0x11111111,
    1.35 +	0x10011001,
    1.36 +	0x10011001,
    1.37 +	0x11111111
    1.38 +};
    1.39 +
    1.40 +void load_pattern(int idx, void *data);
    1.41 +void set_tile(int x, int y, int tile_idx, int palidx);
    1.42 +
    1.43  int main(void)
    1.44  {
    1.45 +	int i, j;
    1.46 +
    1.47  	vdp_init();
    1.48  
    1.49  	vdp_set_pal_entry(0, 0, 0, 0, 0);
    1.50 -	vdp_set_pal_entry(0, 1, 7, 0, 3);
    1.51 -	vdp_set_bgcolor(0, 1);
    1.52 +	vdp_set_pal_entry(0, 1, 7, 1, 3);
    1.53 +	vdp_set_bgcolor(0, 0);
    1.54  
    1.55 -	vdp_enable_hintr(12);
    1.56 -	vdp_enable_vintr();
    1.57 +	load_pattern(0, pat0);
    1.58 +	load_pattern(1, pat1);
    1.59 +	load_pattern(2, pat2);
    1.60 +
    1.61 +	vdp_set_nametab_idx(VDP_PLANE_A, 6);
    1.62 +
    1.63 +	for(i=0; i<20; i++) {
    1.64 +		for(j=0; j<20; j++) {
    1.65 +			set_tile(j, i, 1, 0);
    1.66 +		}
    1.67 +	}
    1.68 +
    1.69 +	//vdp_enable_hintr(12);
    1.70 +	//vdp_enable_vintr();
    1.71  
    1.72  	for(;;);
    1.73  
    1.74  	return 0;
    1.75  }
    1.76  
    1.77 +/*
    1.78  uint16_t testcol = 0x00c0;
    1.79  
    1.80  void vblank_handler(void)
    1.81  {
    1.82  	testcol = 0x00c0;
    1.83  }
    1.84 +*/
    1.85 +
    1.86 +void load_pattern(int idx, void *data)
    1.87 +{
    1.88 +	int i;
    1.89 +	uint32_t *ptr = data;
    1.90 +	uint16_t addr = idx << 5;
    1.91 +	vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
    1.92 +
    1.93 +	for(i=0; i<16; i++) {
    1.94 +		VDP_PORT_DATA32 = *ptr++;
    1.95 +	}
    1.96 +}
    1.97 +
    1.98 +void set_tile(int x, int y, int tile_idx, int palidx)
    1.99 +{
   1.100 +	uint16_t tile_ent, addr;
   1.101 +
   1.102 +	tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO);
   1.103 +
   1.104 +	addr = vdp_nametab_addr(6) + (y * 64 + x) * 2;
   1.105 +	vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
   1.106 +	VDP_PORT_DATA = tile_ent;
   1.107 +}