diff --git a/build/aseparse65/png65.js b/build/aseparse65/png65.js index d39584c..375bb5d 100644 --- a/build/aseparse65/png65.js +++ b/build/aseparse65/png65.js @@ -96,75 +96,109 @@ function getFCMData(png, palette) { function sortNCMDataForSprites(png, sw, sh, palette, charData) { let spriteData = [] - let numSprites = (png.width / (sw*16) * (png.height / (sh*8))) - let spritesPerRow = (png.width / (sw*16)) + + let charNewColors = [] + + +console.log(charData.originalPalIndex.length, sw, sh, png.width, png.height) + for(var y = 0; y< png.height/8; y+=sh) { + for(var x=0; x<(png.width / 16); x+=sw) { + let cols=[] + for(var ty=0; ty a-b) for(var k=0; k { + return ( + png.data[i+0] === a.red && + png.data[i+1] === a.green && + png.data[i+2] === a.blue + ); + }) + + + originalPalIndex.push(col1) + if(charCols.indexOf(col1) === -1) charCols.push(col1) + let nyb1 = charCols.indexOf(col1) + + + let col2 = palette.findIndex(a => { + return ( + png.data[j+0] === a.red && + png.data[j+1] === a.green && + png.data[j+2] === a.blue + ); + }) + originalPalIndex.push(col2) + if(charCols.indexOf(col2) === -1) charCols.push(col2) + let nyb2 = charCols.indexOf(col2) + + //push colors in this order so they can be turned into bytes easily alter + + + + + // if(nyb1 > 0xf || nyb2 > 0xf) { + // throw(new Error(`Too many colors in this char: $${(y * hei + x * wid).toString(16)} ${x},${y},${charCols}`)) + // } + data.push(( nyb2 << 4 ) + nyb1) + } + } + } + } + charCols = charCols.sort((a,b) => a-b) + charColors.push(charCols) + } + } + + // console.log(charColors) + // console.log("===================") + // console.log(originalPalIndex) + + return { data, charColors, originalPalIndex } +} + + + function getPaletteData(png) { let palette = []; for (var c = 0; c < png.palette.length; c++) { @@ -306,7 +422,9 @@ function findBestFitForCharColors(inp, out) { return out } -function sortNCMPalette(charData, paletteData) { +function sortNCMPalette(charData, paletteData, wid, hei) { + wid = wid || 1 + hei = hei || 1 let sortedArray = new Array(16).fill([0]) // console.log(charData.charColors) @@ -373,6 +491,7 @@ function sortNCMPalette(charData, paletteData) { } + console.log(charData.slices) //with the palette found and the color table and slice array done, //now need to change every pixels data to //reflect the new color indices changing each nybble @@ -381,8 +500,8 @@ function sortNCMPalette(charData, paletteData) { //get old value let orig = charData.originalPalIndex[i] //find its new index - var s= charData.slices[Math.floor(i/128)] - // console.log("CCC",i,Math.floor(i/128),charData.slices.length,s,sortedArray[ s ]) + var s= charData.slices[Math.floor(i/(128*wid*hei))] + // console.log("CCC",i,Math.floor(i/128),charData.slices.length,s,charData.originalPalIndex.length) var palSlice = sortedArray[ s ] var index = palSlice.indexOf(orig) @@ -391,7 +510,7 @@ function sortNCMPalette(charData, paletteData) { //get next value orig = charData.originalPalIndex[i+1] //find its new index - s= charData.slices[Math.floor(i/128)] + s= charData.slices[Math.floor(i/(128*wid*hei))] palSlice = sortedArray[ s ] index = palSlice.indexOf(orig) @@ -510,18 +629,32 @@ async function runSpriteMapper(argv) { if(argv.fcm) { convertedPal = paletteData.pal charData = getFCMData(png, paletteData.palette) + charData = sortFCMDataForSprites(png, spriteWidth/8, spriteHeight/8, paletteData.palette, charData) console.log("Building sprites in FCM mode") } if(argv.ncm) { - charData = getNCMData(png, paletteData.palette, spriteWidth/16, spriteHeight/8) - sortedPalette = sortNCMPalette(charData, paletteData) - paletteData = sortedPalette.paletteData - convertedPal = paletteData.pal - // charData = sortNCMDataForSprites(png, spriteWidth / 16, spriteHeight / 8, paletteData.palette, charData) - charData = sortFCMDataForSprites(png, spriteWidth/8, spriteHeight/8, paletteData.palette, charData, 2) + // charData = getNCMDataForSprites(png, paletteData.palette, spriteWidth/16, spriteHeight/8) + // sortedPalette = sortNCMPalette(charData, paletteData) + // paletteData = sortedPalette.paletteData + // convertedPal = paletteData.pal + // // charData = sortNCMDataForSprites(png, spriteWidth / 16, spriteHeight / 8, paletteData.palette, charData) + // charData = sortFCMDataForSprites(png, spriteWidth/8, spriteHeight/8, paletteData.palette, charData, 2) + + + charData = getNCMDataForSprites(png, paletteData.palette, spriteWidth/16, spriteHeight/8) + // charData.charColors = sortNCMDataForSprites(png, spriteWidth / 16, spriteHeight / 8, paletteData.palette, charData).charColors + sortedPalette = sortNCMPalette(charData, paletteData, spriteWidth/16, spriteHeight/8) + + // charData = getNCMData(png, paletteData.palette, spriteWidth/16, spriteHeight/8) + // paletteData = sortedPalette.paletteData + charData = sortNCMDataForSprites(png, spriteWidth/16, spriteHeight/8, paletteData.palette, charData, false) + + convertedPal = paletteData.pal + + //save NCM color table fs.writeFileSync(path.resolve(outputPath, inputName+"_ncm.bin"), Buffer.from(sortedPalette.charColors)) console.log("Building sprites in NCM mode") diff --git a/includes/s65/layer/Layer_Macros.s b/includes/s65/layer/Layer_Macros.s index 420d36e..16c74f7 100644 --- a/includes/s65/layer/Layer_Macros.s +++ b/includes/s65/layer/Layer_Macros.s @@ -293,7 +293,7 @@ //Set border and text positions for this resolution .var ncmMult = 1//Layer_LayerList.get(0).get("ncm") ? 2 : 1 .var adjust = S65_VISIBLE_SCREEN_CHAR_HEIGHT * 8 - .var borderTop = $130 - adjust + .var borderTop = $12e - adjust .var borderBottom = borderTop + S65_VISIBLE_SCREEN_CHAR_HEIGHT * 8 * 2 .var textYpos = borderTop - 1 @@ -313,11 +313,11 @@ ora #>borderTop sta $d049 - lda #<[borderBottom - 1] + lda #<[borderBottom-1] sta $d04a lda $d04b and #%11110000 - ora #>[borderBottom -1] + ora #>[borderBottom-1] sta $d04b lda #<[textYpos -3] diff --git a/includes/s65/start.s b/includes/s65/start.s index 4769c29..3d06586 100644 --- a/includes/s65/start.s +++ b/includes/s65/start.s @@ -110,7 +110,7 @@ System_BasicUpstart65(S65_InitComplete) /** * .var ScreenRamPointer * - * S65 BasePage pointer into screen ram. It is guaranteed to have the upper two bytes set + * {dword} S65 BasePage pointer into screen ram. It is guaranteed to have the upper two bytes set * at all times so can be used to access the screen ram using 32bit indirect z addressing. * DO NOT change bytes 2 and 3!

* @@ -126,7 +126,7 @@ System_BasicUpstart65(S65_InitComplete) /** * .var ColorRamPointer * - * S65 BasePage pointer into color ram. It is guaranteed to have the upper two bytes set + * {dword} S65 BasePage pointer into color ram. It is guaranteed to have the upper two bytes set * at all times so can be used to access the color ram using 32bit indirect z addressing. * DO NOT change bytes 2 and 3!

* Note: Requires S65_SetBasePage or @@ -161,10 +161,18 @@ System_BasicUpstart65(S65_InitComplete) S65_SpriteRowTablePtr: .word $0000 S65_SpriteFlags: .byte $00 +/** +* .var LastImportPtr +* +* {dword} S65 Basepage pointer that contains the address at which the last S65_Import +* macro finished importing +*/ + S65_LastImportPtr: .dword $00000000 + /** * .var ReturnValue * - * S65 BasePage value that is used as a return for many commands + * {word} S65 BasePage value that is used as a return for many commands * when the result is a word rather than a byte. */ S65_ReturnValue: .word $0000 @@ -172,7 +180,7 @@ System_BasicUpstart65(S65_InitComplete) /** * .var LastSpriteIOPointer * - * S65 BasePage pointer into to the IO data for the last sprite that was + * {word} S65 BasePage pointer into to the IO data for the last sprite that was * fetched using Sprite_Get */ S65_LastSpriteIOPointer: .word $0000 @@ -180,7 +188,7 @@ System_BasicUpstart65(S65_InitComplete) /** * .var LastLayerIOPointer * - * S65 BasePage pointer into to the IO data for the last layer that was + * {word} S65 BasePage pointer into to the IO data for the last layer that was * fetched using Layer_Get */ S65_LastLayerIOPointer: .word $0000 @@ -195,7 +203,7 @@ System_BasicUpstart65(S65_InitComplete) * .var SpareBasePage * * 16 bytes of spare storage free for use when the S65 base page is active - * to assist with using commands that expect to be in base page + * to assist with using commands that expect to be in S65 base page */ S65_SpareBasePage: .fill 16, 0 diff --git a/png65examples.bat b/png65examples.bat new file mode 100644 index 0000000..0bdd02f --- /dev/null +++ b/png65examples.bat @@ -0,0 +1,39 @@ +rem This file is not inteded to be run but instead serve as an example of how to use PNG65.js + + +set PNG65=node %S65PATH%\build\aseparse65\png65.js + + +rem Generates an FCM charset and palette from the input image +rem +rem files output: +rem assets\bin\charsfcm_chars.bin - The chars data +rem assets\bin\charsfcm_palette.bin - The FCM palette +%PNG65% chars --fcm --input "assets\source\charsfcm.png" --output "assets\bin" + + +rem Generates an NCM charset, palette and color table from the input image +rem +rem files output: +rem assets\bin\tileset1_chars.bin - The chars data +rem assets\bin\tileset1_palette.bin - The NCM sorted palette data +rem assets\bin\tileset1_ncm.bin - The NCM color table for the charset +%PNG65% chars --ncm --input "assets\source\tileset1.png" --output "assets\bin" + + +rem Generates an FCM RRB spriteset and palette from the input image, RRB sprites defined as 32x32px +rem Sprite char data will be arranged in the correct order for RRB sprites +rem +rem files output: +rem assets\bin\sprites_chars.bin - The chars data +rem assets\bin\sprites_palette.bin - The FCM palette +%PNG65% sprites --fcm --size 32,32 --input "assets\source\sprites.png" --output "assets\bin" + + +rem Generates an NCM RRB spriteset and sorted palette from the input image, RRB sprites defined as 16x32px +rem Sprite char data will be arranged in the correct order for RRB sprites +rem +rem files output: +rem assets\bin\spritesncm_chars.bin - The chars data +rem assets\bin\spritesncm_palette.bin - The NCM sorted palette +%PNG65% sprites --ncm --size 16,32 --input "assets\source\sprites.png" --output "assets\bin" \ No newline at end of file