# HG changeset patch # User John Tsiombikas # Date 1497848571 -10800 # Node ID 72ab63f262bfab7d9c2abd8c0b3f9bb79298c06e # Parent b22bc95f0cc005a0f007ac36feb3565bc6f11100 tiles diff -r b22bc95f0cc0 -r 72ab63f262bf src/intr.s --- a/src/intr.s Tue Mar 14 09:11:18 2017 +0200 +++ b/src/intr.s Mon Jun 19 08:02:51 2017 +0300 @@ -1,4 +1,4 @@ -| vi:filetype=asm68k: +| vi:filetype=gas68k: | the following will go into the .vect section which will be placed at the very | begining of the binary at address 0 by the linker (see lnkscript). .section .vect,"a" @@ -92,15 +92,15 @@ .extern palval intr_hblank: - move.l #0xc0020000, VDP_PORT_CTL - - move.w testcol, %d0 - move.w %d0, VDP_PORT_DATA - rol.b #4, %d0 - move.w %d0, testcol - +| move.l #0xc0020000, VDP_PORT_CTL +| +| move.w testcol, %d0 +| move.w %d0, VDP_PORT_DATA +| rol.b #4, %d0 +| move.w %d0, testcol +| rte intr_vblank: - jsr vblank_handler + |jsr vblank_handler rte diff -r b22bc95f0cc0 -r 72ab63f262bf src/main.c --- a/src/main.c Tue Mar 14 09:11:18 2017 +0200 +++ b/src/main.c Mon Jun 19 08:02:51 2017 +0300 @@ -1,25 +1,100 @@ #include #include "vdp.h" +uint32_t pat0[] = { + 0x00000000, + 0x00000000, + 0x00000000, + 0x00010000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x00000000 +}; + +uint32_t pat1[] = { + 0x11111111, + 0x11000011, + 0x10100101, + 0x10011001, + 0x10011001, + 0x10100101, + 0x11000011, + 0x11111111 +}; + +uint32_t pat2[] = { + 0x11111111, + 0x10011001, + 0x10011001, + 0x11111111, + 0x11111111, + 0x10011001, + 0x10011001, + 0x11111111 +}; + +void load_pattern(int idx, void *data); +void set_tile(int x, int y, int tile_idx, int palidx); + int main(void) { + int i, j; + vdp_init(); vdp_set_pal_entry(0, 0, 0, 0, 0); - vdp_set_pal_entry(0, 1, 7, 0, 3); - vdp_set_bgcolor(0, 1); + vdp_set_pal_entry(0, 1, 7, 1, 3); + vdp_set_bgcolor(0, 0); - vdp_enable_hintr(12); - vdp_enable_vintr(); + load_pattern(0, pat0); + load_pattern(1, pat1); + load_pattern(2, pat2); + + vdp_set_nametab_idx(VDP_PLANE_A, 6); + + for(i=0; i<20; i++) { + for(j=0; j<20; j++) { + set_tile(j, i, 1, 0); + } + } + + //vdp_enable_hintr(12); + //vdp_enable_vintr(); for(;;); return 0; } +/* uint16_t testcol = 0x00c0; void vblank_handler(void) { testcol = 0x00c0; } +*/ + +void load_pattern(int idx, void *data) +{ + int i; + uint32_t *ptr = data; + uint16_t addr = idx << 5; + vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM); + + for(i=0; i<16; i++) { + VDP_PORT_DATA32 = *ptr++; + } +} + +void set_tile(int x, int y, int tile_idx, int palidx) +{ + uint16_t tile_ent, addr; + + tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO); + + addr = vdp_nametab_addr(6) + (y * 64 + x) * 2; + vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM); + VDP_PORT_DATA = tile_ent; +} diff -r b22bc95f0cc0 -r 72ab63f262bf src/startup.s --- a/src/startup.s Tue Mar 14 09:11:18 2017 +0200 +++ b/src/startup.s Mon Jun 19 08:02:51 2017 +0300 @@ -1,4 +1,4 @@ -| vi:filetype=asm68k: +| vi:filetype=gas68k: .text .extern main diff -r b22bc95f0cc0 -r 72ab63f262bf src/vdp.h --- a/src/vdp.h Tue Mar 14 09:11:18 2017 +0200 +++ b/src/vdp.h Mon Jun 19 08:02:51 2017 +0300 @@ -47,6 +47,19 @@ VDP_MEM_VSRAM = 4 /* CD5->CD0: 0 0 0 1 0 0 */ }; +enum { + VDP_PLANE_A, + VDP_PLANE_B, + VDP_PLANE_WIN +}; + +enum { + VDP_TILE_LOW_PRIO = 0, + VDP_TILE_HFLIP = 0x0800, + VDP_TILE_VFLIP = 0x1000, + VDP_TILE_HIGH_PRIO = 0x8000 +}; + static inline void vdp_setup_access(uint16_t addr, int rw, int memid) { uint32_t type; @@ -173,6 +186,41 @@ vdp_setreg(VDP_REG_MODE1, vdp_getreg(VDP_REG_MODE1) & ~VDP_MODE1_HINTR); } +static inline void vdp_set_nametab_addr(int plane, uint16_t addr) +{ + int reg; + switch(plane) { + case VDP_PLANE_A: + reg = VDP_REG_NAMETAB_A; + break; + case VDP_PLANE_B: + reg = VDP_REG_NAMETAB_B; + break; + case VDP_PLANE_WIN: + reg = VDP_REG_NAMETAB_WIN; + break; + default: + return; + } + + vdp_setreg(reg, (addr >> 10) & 0x38); +} + +static inline uint16_t vdp_nametab_addr(int idx) +{ + return (uint16_t)idx << 13; +} + +static inline void vdp_set_nametab_idx(int plane, int idx) +{ + vdp_set_nametab_addr(plane, vdp_nametab_addr(idx)); +} + +static inline uint16_t vdp_nametab_entry(int tileidx, int palidx, uint16_t flags) +{ + return tileidx | (((uint16_t)palidx & 0x3) << 13) | flags; +} + void vdp_init(void); #endif /* VDP_H_ */ diff -r b22bc95f0cc0 -r 72ab63f262bf tools/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/Makefile Mon Jun 19 08:02:51 2017 +0300 @@ -0,0 +1,12 @@ +CFLAGS = -pedantic -Wall -g +LDFLAGS = -lm + +.PHONY: all +all: tunnel ppm2md + +tunnel: tunnel.o +ppm2md: ppm2md.o + +.PHONY: clean +clean: + rm -f *.o tunnel diff -r b22bc95f0cc0 -r 72ab63f262bf tools/ppm2md.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/ppm2md.c Mon Jun 19 08:02:51 2017 +0300 @@ -0,0 +1,97 @@ +#include +#include +#include +#include + +unsigned char *read_image(int *xsz, int *ysz, int *maxval); + +int main(void) +{ + int i, j, width, height, maxval; + unsigned char *pixels; + + if(!(pixels = read_image(&width, &height, &maxval))) { + return 1; + } + fprintf(stderr, "read image %dx%d (maxval: %d)\n", width, height, maxval); + + /* reduce colors */ + + /* slice tiles */ + for(i=0; i +#include +#include + +#define XSZ 512 +#define YSZ 512 + +int main(void) +{ + int i, j; + unsigned char *pixels, *pptr; + + pixels = malloc(XSZ * YSZ); + pptr = pixels; + + for(i=0; i