# HG changeset patch # User John Tsiombikas # Date 1497928138 -10800 # Node ID ea70f3da150fd983ee6f12c57573732367de3bec # Parent 72ab63f262bfab7d9c2abd8c0b3f9bb79298c06e color cycling tunnel diff -r 72ab63f262bf -r ea70f3da150f .hgignore --- a/.hgignore Mon Jun 19 08:02:51 2017 +0300 +++ b/.hgignore Tue Jun 20 06:08:58 2017 +0300 @@ -4,3 +4,7 @@ \.map$ \.elf$ \.bin$ +tools/ppm2md$ +tools/tunnel$ +\.ppm$ +tun_data\.h$ diff -r 72ab63f262bf -r ea70f3da150f Makefile --- a/Makefile Mon Jun 19 08:02:51 2017 +0300 +++ b/Makefile Tue Jun 20 06:08:58 2017 +0300 @@ -9,8 +9,9 @@ warn = -pedantic -Wall dbg = -g +opt = -O2 def = -DGAMENAME=\"testgame\" -DVERSTR=\"01\" -D__NO_CTYPE -inc = -Isrc -Isrc/libc +inc = -I. -Isrc -Isrc/libc tool_prefix = m68k-linux-gnu- @@ -28,12 +29,18 @@ $(bin): $(elf) $(OBJCOPY) -O binary $< $@ -$(elf): $(obj) +$(elf): tun_data.h $(obj) $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS) +tun_data.h: tunnel.ppm + cat $< | tools/ppm2md tun_ >$@ + +tunnel.ppm: + tools/tunnel >$@ + .PHONY: clean clean: - rm -f $(obj) $(elf) $(bin) + rm -f $(obj) $(elf) $(bin) tun_data.h tunnel.ppm .PHONY: run run: $(bin) diff -r 72ab63f262bf -r ea70f3da150f src/intr.s --- a/src/intr.s Mon Jun 19 08:02:51 2017 +0300 +++ b/src/intr.s Tue Jun 20 06:08:58 2017 +0300 @@ -102,5 +102,5 @@ rte intr_vblank: - |jsr vblank_handler + jsr vblank_handler rte diff -r 72ab63f262bf -r ea70f3da150f src/main.c --- a/src/main.c Mon Jun 19 08:02:51 2017 +0300 +++ b/src/main.c Tue Jun 20 06:08:58 2017 +0300 @@ -1,41 +1,29 @@ #include #include "vdp.h" +#include "tun_data.h" -uint32_t pat0[] = { - 0x00000000, - 0x00000000, - 0x00000000, - 0x00010000, - 0x00000000, - 0x00000000, - 0x00000000, - 0x00000000 +#define NAMETAB_A 6 +#define NAMETAB_B 6 + +void load_pattern(int idx, void *data); +void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx); + +#define CYCLE_BEG 1 +#define CYCLE_END 14 +static uint16_t pal[16] = { + VDP_PACK_RGB(0, 0, 0), /* 0: fixed */ + VDP_PACK_RGB(0, 0, 0), /* 1: cycle start */ + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), + VDP_PACK_RGB(0, 0, 0), /* 12: \ */ + VDP_PACK_RGB(7, 0, 3), /* 13: > beam */ + VDP_PACK_RGB(0, 0, 0), /* 14: / cycle end */ + VDP_PACK_RGB(7, 0, 3) /* 15: fixed */ }; -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) { @@ -43,39 +31,35 @@ vdp_init(); - vdp_set_pal_entry(0, 0, 0, 0, 0); - vdp_set_pal_entry(0, 1, 7, 1, 3); + vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_V30CELL); + + vdp_begin_palette(0, 0); + for(i=0; i<16; i++) { + VDP_PORT_DATA = pal[i]; + } vdp_set_bgcolor(0, 0); - load_pattern(0, pat0); - load_pattern(1, pat1); - load_pattern(2, pat2); + for(i=0; i> 10) & 0x38); break; case VDP_PLANE_B: - reg = VDP_REG_NAMETAB_B; + vdp_setreg(VDP_REG_NAMETAB_B, (addr >> 13) & 7); break; case VDP_PLANE_WIN: - reg = VDP_REG_NAMETAB_WIN; + vdp_setreg(VDP_REG_NAMETAB_WIN, (addr >> 10) & 0x7e); + default: break; - default: - return; } - - vdp_setreg(reg, (addr >> 10) & 0x38); } static inline uint16_t vdp_nametab_addr(int idx) @@ -216,11 +216,37 @@ vdp_set_nametab_addr(plane, vdp_nametab_addr(idx)); } +static inline void vdp_disable_layer(int plane) +{ + switch(plane) { + case VDP_PLANE_A: + vdp_setreg(VDP_REG_NAMETAB_A, 0x40); + break; + case VDP_PLANE_B: + vdp_setreg(VDP_REG_NAMETAB_B, 0x08); + break; + case VDP_PLANE_WIN: + vdp_setreg(VDP_REG_NAMETAB_WIN, 0x40); + default: + break; + } +} + static inline uint16_t vdp_nametab_entry(int tileidx, int palidx, uint16_t flags) { return tileidx | (((uint16_t)palidx & 0x3) << 13) | flags; } +static inline void vdp_set_sprite_table(uint16_t addr) +{ + vdp_setreg(VDP_REG_SPRITE_TAB, addr >> 9); +} + +static inline void vdp_set_scroll_table(uint16_t addr) +{ + vdp_setreg(VDP_REG_SCROLL_TAB, addr >> 10); +} + void vdp_init(void); #endif /* VDP_H_ */ diff -r 72ab63f262bf -r ea70f3da150f tools/ppm2md.c --- a/tools/ppm2md.c Mon Jun 19 08:02:51 2017 +0300 +++ b/tools/ppm2md.c Tue Jun 20 06:08:58 2017 +0300 @@ -3,26 +3,92 @@ #include #include +#define RODATA_STR "__attribute__((section(\".rodata\")))" + unsigned char *read_image(int *xsz, int *ysz, int *maxval); -int main(void) +int main(int argc, char **argv) { - int i, j, width, height, maxval; - unsigned char *pixels; + int i, j, width, height, xtiles, ytiles, maxval; + unsigned char *pixels, *tiles, *src, *dest; + const char *prefix = "img_"; + + if(argv[1]) { + prefix = argv[1]; + } if(!(pixels = read_image(&width, &height, &maxval))) { return 1; } fprintf(stderr, "read image %dx%d (maxval: %d)\n", width, height, maxval); - /* reduce colors */ + xtiles = width / 8; + ytiles = height / 8; + /* each tile is 32 bytes, 8 rows of 4 bytes each */ + if(!(tiles = malloc(xtiles * ytiles * 32))) { + free(pixels); + return 1; + } - /* slice tiles */ - for(i=0; i 0) { + printf(",\n"); + } else { + putchar('\n'); + } + printf("\t{"); + for(j=0; j<32; j++) { + if(j == 0) { + printf("%u", (unsigned int)*src++); + } else { + printf(", %u", (unsigned int)*src++); + } + } + printf(" }"); + } + printf("\n};\n"); + + return 0; } diff -r 72ab63f262bf -r ea70f3da150f tools/tunnel.c --- a/tools/tunnel.c Mon Jun 19 08:02:51 2017 +0300 +++ b/tools/tunnel.c Tue Jun 20 06:08:58 2017 +0300 @@ -2,13 +2,14 @@ #include #include -#define XSZ 512 -#define YSZ 512 +#define XSZ 320 +#define YSZ 240 int main(void) { int i, j; unsigned char *pixels, *pptr; + float aspect = (float)XSZ / (float)YSZ; pixels = malloc(XSZ * YSZ); pptr = pixels; @@ -16,15 +17,19 @@ for(i=0; i