From d98337bd11caa44222eb6e06caa5c9a353902e98 Mon Sep 17 00:00:00 2001 From: alpine9000 Date: Sat, 16 Apr 2016 14:35:24 +1000 Subject: [PATCH] setup board --- 028.game2/Makefile | 2 +- 028.game2/game1.s | 137 +++++++++++++++++------------- 028.game2/init.s | 12 +-- 028.game2/tilemap-grey-table.s | 25 ++++++ 028.game2/tilemap-palette-table.s | 25 ++++++ tools/imagecon/palette.c | 22 +++++ 6 files changed, 159 insertions(+), 64 deletions(-) create mode 100644 028.game2/tilemap-grey-table.s create mode 100644 028.game2/tilemap-palette-table.s diff --git a/028.game2/Makefile b/028.game2/Makefile index 8c0979c..88237b3 100644 --- a/028.game2/Makefile +++ b/028.game2/Makefile @@ -35,7 +35,7 @@ out/background.bin: assets/tilemap.png $(IMAGECON) --use-palette=assets/background.pal --input $< $(IMAGECON_ARGS) --colors $(NUM_COLORS) --output-bitplanes --output-palette --full-color-palette-file --output-palette-asm --output-grey-palette --output-palette --output-png --output out/background out/tilemap-palette.s: assets/tilemap.png - $(IMAGECON) --use-palette=assets/palette.pal --full-color-palette-file --input=assets/tilemap.png --output-palette-asm --output=out/tilemap --output-copperlist + $(IMAGECON) --use-palette=assets/palette.pal --full-color-palette-file --input=assets/tilemap.png --output-palette-asm --output=out/tilemap --output-copperlist --output-grey-palette out/panel.bin: assets/panel.png $(IMAGECON) --input $< $(IMAGECON_ARGS) --colors 16 --output-bitplanes --output-palette --full-color-palette-file --output-palette-asm --output-palette --output-png --output-copperlist --output out/panel --use-palette=assets/panel.pal diff --git a/028.game2/game1.s b/028.game2/game1.s index f0e7e31..de117ce 100644 --- a/028.game2/game1.s +++ b/028.game2/game1.s @@ -22,10 +22,6 @@ Entry: move #$7ff,DMACON(a6) ; disable all dma move #$7fff,INTENA(a6) ; disable all interrupts - ;; jsr InstallPalette - ;; move.w #$09e,COLOR00(a6) - ;; move.w #$09e,COLOR08(a6) - lea Level3InterruptHandler,a3 move.l a3,LVL3_INT_VECTOR @@ -43,20 +39,29 @@ Entry: jsr PokePanelBitplanePointers jsr Init ; enable the playfield + jsr InstallGreyPalette Reset: move.l #0,foregroundScrollX move.l #0,backgroundScrollX jsr BlueFill move.l #-1,frameCount - + MainLoop: + add.l #1,frameCount + move.l frameCount,d6 + cmp.l #32,frameCount + bge GameLoop + bra SetupBoardLoop + +GameLoop: + ;; bsr FadeToPalette + bsr InstallColorPalette + move.l #FOREGROUND_SCROLL_PIXELS,foregroundScrollPixels jsr WaitVerticalBlank bsr HoriScrollPlayfield jsr SwitchBuffers ; takes bitplane pointer offset in d0 - jsr ReadJoystick - move.l foregroundScrollX,d0 lsr.l #FOREGROUND_SCROLL_SHIFT_CONVERT,d0 ; convert to pixels and.b #$f,d0 @@ -69,21 +74,25 @@ MainLoop: bne .s1 move.w #1,moving .s1: - - ;; move.w #$000,COLOR00(a6) - ;; move.w #$000,COLOR08(a6) - - bsr Update - bsr RenderNextForegroundFrame - bsr RenderNextBackgroundFrame - - ;; move.w #$09e,COLOR00(a6) - ;; move.w #$09e,COLOR08(a6) - + bsr RenderNextBackgroundFrame bra MainLoop +SetupBoardLoop: + move.l #FOREGROUND_SCROLL_PIXELS*15,foregroundScrollPixels + ;; jsr WaitVerticalBlank + bsr HoriScrollPlayfield + jsr SwitchBuffers ; takes bitplane pointer offset in d0 + move.l foregroundScrollX,d0 + move.w #1,moving + bsr Update + bsr RenderNextForegroundFrame + bsr RenderNextBackgroundFrame + bra MainLoop + + + Update: .backgroundUpdates: add.l #BACKGROUND_SCROLL_PIXELS,backgroundScrollX @@ -98,7 +107,8 @@ Update: cmp.w #1,moving bne .c1 - add.l #FOREGROUND_SCROLL_PIXELS,foregroundScrollX + move.l foregroundScrollPixels,d0 + add.l d0,foregroundScrollX move.l foregroundScrollX,d0 lsr.l #FOREGROUND_SCROLL_SHIFT_CONVERT,d0 ; convert to pixels @@ -112,8 +122,6 @@ Update: .skipForegroundUpdates: - add.l #1,frameCount - move.l frameCount,d6 rts HoriScrollPlayfield: @@ -198,17 +206,31 @@ RenderNextForegroundFrame: lsr.l #1,d0 and.b #$f0,d0 add.l d0,a2 - move.l #7,d3 + move.l #7,d3 ; 8 tiles per column .loop: move.l d3,d2 - bsr RenderForegroundTile + bsr RenderForegroundTile2 bsr ClearForegroundTile2 add.l #2,a2 dbra d3,.loop rts - + + RenderForegroundTile: + ;; a2 - address of tileIndex + move.l foregroundScrollX,d0 + lsr.w #FOREGROUND_SCROLL_SHIFT_CONVERT,d0 ; convert to pixels + lsr.w #3,d0 ; bytes to scroll + move.l foregroundOffscreen,a0 + add.l d0,a0 + lea tilemap,a1 + add.w (a2),a1 ; source tile + add.l #(BITPLANE_WIDTH_BYTES*SCREEN_BIT_DEPTH*(256-(16*4))/4)+BITPLANE_WIDTH_BYTES-8,a0 + jsr BlitTile + rts + +RenderForegroundTile2: ;; a2 - address of tileIndex move.l foregroundScrollX,d0 lsr.w #FOREGROUND_SCROLL_SHIFT_CONVERT,d0 ; convert to pixels @@ -372,12 +394,37 @@ copperListBpl2Ptr: dc.w DDFSTRT,(RASTER_X_START/2-SCREEN_RES)-8 ; -8 for extra scrolling word dc.w DDFSTOP,(RASTER_X_START/2-SCREEN_RES)+(8*((SCREEN_WIDTH/16)-1)) dc.w BPLCON0,(SCREEN_BIT_DEPTH*2<<12)|COLOR_ON|DBLPF - + +tileMapCopperPalettePtr: include "tilemap-copper-list.s" dc.l $fffffffe + +InstallColorPalette: + lea tileMapCopperPalettePtr,a1 + lea tilemapPalette,a0 + add.l #2,a1 + move.l #15,d0 +.loop: + move.w (a0),(a1) + add.l #2,a0 + add.l #4,a1 + dbra d0,.loop + rts +InstallGreyPalette: + lea tileMapCopperPalettePtr,a1 + lea greyPalette,a0 + add.l #2,a1 + move.l #15,d0 +.loop: + move.w (a0),(a1) + add.l #2,a0 + add.l #4,a1 + dbra d0,.loop + rts + InstallPalette: include "out/tilemap-palette.s" rts @@ -402,6 +449,8 @@ map: backgroundMap: include "out/background-map.s" dc.w $FFFF +foregroundScrollPixels: + dc.l FOREGROUND_SCROLL_PIXELS foregroundScrollX: dc.l 0 backgroundScrollX: @@ -496,6 +545,11 @@ deAnimIndexPattern: dc.l 0 dc.l $ffffffff +greyPalette: + include "tilemap-grey-table.s" + +tilemapPalette: + include "tilemap-palette-table.s" section .bss foregroundBitplanes1: @@ -510,35 +564,4 @@ startUserstack: ds.b $1000 ; size of stack userstack: - - - end - -0: UpdateFG - UpdateBG - RenderFG - RenderBG - SwapBufferFG - SwapBufferBG - -1: RenderFG - SwapBufferFG - -2: UpdateFG - RenderFG - RenderBG - SwapBufferFG - SwapBufferBG - -2: RenderFG - SwapBufferFG - - -000 -001 -010 -011 -100 -101 -110 -111 + end \ No newline at end of file diff --git a/028.game2/init.s b/028.game2/init.s index aa59ac5..2af7cc7 100644 --- a/028.game2/init.s +++ b/028.game2/init.s @@ -6,17 +6,17 @@ Init: movem.l d0-a6,-(sp) ;; move #$7ff,DMACON(a6) ; disable all dma - ;; move #$7fff,INTENA(a6) ; disable all interrupts + ;; move #$7fff,INTENA(a6) ; disable all interrupts - ;; lea Level3InterruptHandler,a3 - ;; move.l a3,LVL3_INT_VECTOR + ;; lea Level3InterruptHandler,a3 + ;; move.l a3,LVL3_INT_VECTOR ;; set up playfield 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)-8,DDFSTRT(a6) ; -8 for extra scrolling word - ;; move.w #(RASTER_X_START/2-SCREEN_RES)+(8*((SCREEN_WIDTH/16)-1)),DDFSTOP(a6) + ;; move.w #(RASTER_X_START/2-SCREEN_RES)-8,DDFSTRT(a6) ; -8 for extra scrolling word + ;; move.w #(RASTER_X_START/2-SCREEN_RES)+(8*((SCREEN_WIDTH/16)-1)),DDFSTOP(a6) ;; enabled 2x the bitplanes as 2x playfields ;; move.w #(SCREEN_BIT_DEPTH*2<<12)|COLOR_ON|DBLPF,BPLCON0(a6) @@ -29,6 +29,6 @@ Init: move.w COPJMP1(a6),d0 move.w #(DMAF_BLITTER|DMAF_SETCLR!DMAF_COPPER!DMAF_RASTER!DMAF_MASTER),DMACON(a6) ;; move.w #PF2PRI,BPLCON2(a6) - ;; move.w #(INTF_SETCLR|INTF_VERTB|INTF_INTEN),INTENA(a6) + ;; move.w #(INTF_SETCLR|INTF_VERTB|INTF_INTEN),INTENA(a6) movem.l (sp)+,d0-a6 rts \ No newline at end of file diff --git a/028.game2/tilemap-grey-table.s b/028.game2/tilemap-grey-table.s new file mode 100644 index 0000000..e13405a --- /dev/null +++ b/028.game2/tilemap-grey-table.s @@ -0,0 +1,25 @@ + dc.w $777 + dc.w $111 + dc.w $333 + dc.w $555 + dc.w $777 + dc.w $888 + dc.w $bbb + dc.w $777 + dc.w $000 + dc.w $999 + dc.w $ccc + dc.w $888 + dc.w $ddd + dc.w $555 + dc.w $999 + dc.w $000 + dc.w $aaa + dc.w $999 + dc.w $444 + dc.w $333 + dc.w $666 + dc.w $aaa + dc.w $777 + dc.w $aaa + dc.w $fff diff --git a/028.game2/tilemap-palette-table.s b/028.game2/tilemap-palette-table.s new file mode 100644 index 0000000..c922644 --- /dev/null +++ b/028.game2/tilemap-palette-table.s @@ -0,0 +1,25 @@ + dc.w $09e + dc.w $500 + dc.w $801 + dc.w $d30 + dc.w $d72 + dc.w $fa1 + dc.w $ed6 + dc.w $18e + dc.w $000 + dc.w $1cf + dc.w $7ef + dc.w $4ac + dc.w $ddd + dc.w $d02 + dc.w $999 + dc.w $000 + dc.w $ea6 + dc.w $f76 + dc.w $a31 + dc.w $037 + dc.w $19a + dc.w $1ef + dc.w $f70 + dc.w $ff0 + dc.w $fff diff --git a/tools/imagecon/palette.c b/tools/imagecon/palette.c index 6f9840f..461d5a7 100644 --- a/tools/imagecon/palette.c +++ b/tools/imagecon/palette.c @@ -57,9 +57,12 @@ palette_output(imagecon_image_t* ic, char* outFilename) FILE* paletteFP = 0; FILE* paletteAsmFP = 0; FILE* paletteGreyFP = 0; + FILE* paletteTableFP = 0; + FILE* paletteGreyTableFP = 0; if (config.outputCopperList) { fp = file_openWrite("%s-copper-list.s", outFilename); + paletteTableFP = file_openWrite("%s-palette-table.s", outFilename); } if (config.outputPalette) { @@ -68,6 +71,7 @@ palette_output(imagecon_image_t* ic, char* outFilename) if (config.outputPaletteGrey) { paletteGreyFP = file_openWrite("%s-grey.s", outFilename); + paletteGreyTableFP = file_openWrite("%s-grey-table.s", outFilename); fprintf(paletteGreyFP, "\tmovem.l d0-a6,-(sp)\n\tlea CUSTOM,a6\n"); } @@ -101,11 +105,29 @@ palette_output(imagecon_image_t* ic, char* outFilename) fprintf(paletteGreyFP, "\tlea COLOR%02d(a6),a0\n\tmove.w #$%03x,(a0)\n", i, grey << 8 | grey << 4 | grey); } + if (paletteGreyTableFP) { + // TODO: this is for compat, can be better + unsigned grey = ((RGB24TORGB12(ic->palette[i].r) + RGB24TORGB12(ic->palette[i].g) + RGB24TORGB12(ic->palette[i].b))/3); + fprintf(paletteGreyTableFP, "\tdc.w\t$%03x\n", grey << 8 | grey << 4 | grey); + } + + if (paletteTableFP) { + fprintf(paletteTableFP, "\tdc.w\t$%03x\n", RGB24TORGB12(ic->palette[i].r) << 8 | RGB24TORGB12(ic->palette[i].g) << 4 | RGB24TORGB12(ic->palette[i].b)); + } + if (fp) { fprintf(fp, "\tdc.w $%x,$%x\n", 0x180+(i*2), RGB24TORGB12(ic->palette[i].r) << 8 | RGB24TORGB12(ic->palette[i].g) << 4 | RGB24TORGB12(ic->palette[i].b)); } } + if (paletteGreyTableFP) { + fclose(paletteGreyTableFP); + } + + if (paletteTableFP) { + fclose(paletteTableFP); + } + if (paletteFP) { fclose(paletteFP); }