diff --git a/004.copper_bars/Makefile b/004.copper_bars/Makefile new file mode 100644 index 0000000..721ca4b --- /dev/null +++ b/004.copper_bars/Makefile @@ -0,0 +1,14 @@ +MAKEADF=../tools/makeadf +FLOPPY=bin/image.adf +EXTRA=out/copper-list.s + +MODULE=copper.s + +include ../base.mk + +out/copper-list.s: out/copper_gen + ./out/copper_gen > out/copper-list.s + +out/copper_gen: copper_gen.c + gcc copper_gen.c -o out/copper_gen + diff --git a/004.copper_bars/README.md b/004.copper_bars/README.md new file mode 100644 index 0000000..0523cfb --- /dev/null +++ b/004.copper_bars/README.md @@ -0,0 +1,3 @@ +Copper bars +=========== + diff --git a/004.copper_bars/copper.s b/004.copper_bars/copper.s new file mode 100644 index 0000000..60462c0 --- /dev/null +++ b/004.copper_bars/copper.s @@ -0,0 +1,58 @@ + include "../include/registers.i" + include "hardware/dmabits.i" + include "hardware/intbits.i" + +LVL3_INT_VECTOR equ $6c +SCREEN_WIDTH equ 320 +SCREEN_HEIGHT equ 256 +SCREEN_WIDTH_BYTES equ (SCREEN_WIDTH/8) +SCREEN_BIT_DEPTH equ 1 +SCREEN_RES equ 8 ; 8=lo resolution, 4=hi resolution +RASTER_X_START equ $81 ; Hard coded coordinates from hardware manual +RASTER_Y_START equ $2c +RASTER_X_STOP equ RASTER_X_START+SCREEN_WIDTH +RASTER_Y_STOP equ RASTER_Y_START+SCREEN_HEIGHT + +entry: + ;; custom chip base globally in a6 + lea CUSTOM,a6 + + ;; poke bitplane pointers into the copper list + lea bitplane(pc),a0 + lea copperBitPlanePtr(pc),a1 + move.l a0,d0 + move.w d0,6(a1) ;BPL1PTL + swap d0 + move.w d0,2(a1) ;BPL1PTH + + move.w #(RASTER_Y_START<<8)|RASTER_X_START,DIWSTRT(a6) + move.w #((RASTER_Y_STOP-256)<<8)|(RASTER_X_STOP-256),DIWSTOP(a6) + + move.w #(RASTER_X_START/2-SCREEN_RES),DDFSTRT(a6) + move.w #(RASTER_X_START/2-SCREEN_RES)+(8*((SCREEN_WIDTH/16)-1)),DDFSTOP(a6) + + move.w #(SCREEN_BIT_DEPTH<<12)|$200,BPLCON0(a6) + move.w #SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH-SCREEN_WIDTH_BYTES,BPL1MOD(a6) + + ;; install copper list and enable DMA + lea copper(pc),a0 + move.l a0,COP1LC(a6) + move.w COPJMP1(a6),d0 + move.w #(DMAF_SETCLR!DMAF_COPPER!DMAF_RASTER!DMAF_MASTER),dmacon(a6) + +.mainLoop: + bra.b .mainLoop + +copper: +copperBitPlanePtr: + dc.w BPL1PTH,0 ; address of the bitplane will be poked once we know it + dc.w BPL1PTL,0 + + dc.w COLOR00,$0000 + + include "out/copper-list.s" + + dc.l $fffffffe + +bitplane: + dcb.b (SCREEN_WIDTH*SCREEN_HEIGHT)/8,$00 diff --git a/004.copper_bars/copper_gen b/004.copper_bars/copper_gen new file mode 100755 index 0000000..2963ca9 Binary files /dev/null and b/004.copper_bars/copper_gen differ diff --git a/004.copper_bars/copper_gen.c b/004.copper_bars/copper_gen.c new file mode 100644 index 0000000..297c0f3 --- /dev/null +++ b/004.copper_bars/copper_gen.c @@ -0,0 +1,69 @@ +// http://krazydad.com/tutorials/makecolors.php + +#include +#include + +typedef struct { + float r; + float g; + float b; +} color; + +#define numColors 50 +color colors[numColors]; + +void +makeColorGradient() +{ + float frequencyr = 02; + float frequencyg = 02; + float frequencyb = 02; + float phase1 = 0.1, phase2 = 0.1, phase3 = 0.1; + float center = 0x7; + float width = 0x7; + float len = numColors; + + for (int i = 0; i < len; ++i) { + color* c = &colors[i]; + c->r = sin(frequencyr*i + phase1) * width + center; + c->g = sin(frequencyg*i + phase2) * width + center; + c->b = sin(frequencyb*i + phase3) * width + center; + } +} + +int +main() +{ + makeColorGradient(); + + int lines = 312; + color start = { 0x0, 0x0, 0x0}; + color end = { 0xF, 0xF, 0xF}; + color current = {0}; + int count = lines-0x2c; + int from = 0, to = 1; + int segment = count/((sizeof(colors)/sizeof(color))-1); + + for (int i = 0, y = 0; i < count; i++) { + if (i != 0 && i % segment == 0) { + from++; + to++; + } + + float distance = (float)((i)%segment)/segment; + color* start = &colors[from]; + color* end = &colors[to]; + current.r = start->r + ((end->r-start->r)*distance); + current.g = start->g + ((end->g-start->g)*distance); + current.b = start->b + ((end->b-start->b)*distance); + + if (0x2c+i <= 255) { + printf("\tdc.w $%xdf,$fffe\n\tdc.w COLOR00,$%x%x%x\n",0x2c+i, (int)(current.r+0.5), (int)(current.g+0.5), (int)(current.b+0.5)); + } else { + printf("\tdc.w $%xdf,$fffe\n\tdc.w COLOR00,$%x%x%x\n",y++, (int)(current.r+0.5), (int)(current.g+0.5), (int)(current.b+0.5)); + } + + } + + return 0; +} diff --git a/Makefile b/Makefile index 926bb6a..ec46c57 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SUBDIRS=000.trackdisk 001.simple_image 002.sprite_display 003.music +SUBDIRS=000.trackdisk 001.simple_image 002.sprite_display 003.music 004.copper_bars .PHONY: subdirs $(SUBDIRS)