From cc767eafd0cfd58f27d6ab7a2af8df5509af1a63 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Fri, 22 Mar 2019 20:26:47 -0400 Subject: [PATCH] cc65: fixed errors in include files; minor fixes, preset updates --- doc/notes.txt | 2 + presets/nes/attributes.c | 2 +- presets/nes/chr_generic.s | 2 +- presets/nes/monobitmap.c | 105 +++++++++++++++++++++++++++++++++++ src/pixed/pixeleditor.ts | 29 ++++++---- src/platform/nes.ts | 1 + src/views.ts | 2 +- src/worker/workermain.ts | 15 ++--- test/cli/testpixelconvert.js | 2 +- tss | 2 +- 10 files changed, 139 insertions(+), 23 deletions(-) create mode 100644 presets/nes/monobitmap.c diff --git a/doc/notes.txt b/doc/notes.txt index 79dbbaff..d8ef5349 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -101,6 +101,8 @@ TODO: - editor: select palette for chr, select charmap for map (dependencies?) - global undo/redo at checkpoints (when rom changes) - asset editor still refreshes twice +- pulldown shows wrong file if preset not present +- landscape mode for arcade ports WEB WORKER FORMAT diff --git a/presets/nes/attributes.c b/presets/nes/attributes.c index 408e14db..0f0d6b2e 100644 --- a/presets/nes/attributes.c +++ b/presets/nes/attributes.c @@ -22,7 +22,7 @@ unsigned int nt2attraddr(unsigned int a) { ((a >> 4) & 0x38) | ((a >> 2) & 0x07); } -#define ATTRADR_A(x,y) (NAMETABLE_A|0x3c0|((((y)>>2)<<3)|((x)>>2))) +#define ATTRADR_A(x,y) (NAMETABLE_A|0x3c0|((((y)>>2)<<3)|((x)>>2))) void put_pixel(unsigned char px, unsigned char py, char color) { int ntaddr, attraddr; diff --git a/presets/nes/chr_generic.s b/presets/nes/chr_generic.s index 23dbbdab..5fd70339 100644 --- a/presets/nes/chr_generic.s +++ b/presets/nes/chr_generic.s @@ -1,6 +1,6 @@ -.segment "CHARS" ;;{w:8,h:8,bpp:1,count:256,brev:1,np:2,pofs:8,remap:[0,1,2,4,5,6,7,8,9,10,11,12]}*/ +.segment "CHARS" .byte $00,$00,$00,$00,$00,$00,$00,$00 .byte $00,$00,$00,$00,$00,$00,$00,$00 .byte $00,$00,$00,$00,$00,$00,$00,$00 diff --git a/presets/nes/monobitmap.c b/presets/nes/monobitmap.c new file mode 100644 index 00000000..d7e5ccb3 --- /dev/null +++ b/presets/nes/monobitmap.c @@ -0,0 +1,105 @@ + +#include "neslib.h" +#include "nes.h" + +#define NES_MAPPER 2 // UxROM mapper +#define NES_CHR_BANKS 0 // CHR RAM + +void set_pixel(byte x, byte y, byte color) { + // compute pattern table address + word a = (x/8)*16 + ((y&63)/8)*(16*32) + (y&7); + byte b; + if (y & 64) a |= 8; + if (y & 128) a |= 0x1000; + // read old byte + vram_adr(a); + vram_read(&b, 1); + if (color) { + b |= 128 >> (x&7); // set pixel + } else { + b &= ~(128 >> (x&7)); // clear pixel + } + // write new byte + vram_adr(a); + vram_put(b); +} + +// write values 0..255 +void vram_put_256inc() { + word i; + for (i=0; i<256; i++) + vram_put(i); +} + +void vram_put_attrib() { + vram_fill(0x00, 0x10); // first palette + vram_fill(0x55, 0x10); // second palette +} + +void setup_monobitmap() { + // clear pattern table + vram_adr(0x0); + vram_fill(0x0, 0x2000); + // setup nametable A and B + vram_adr(NAMETABLE_A); + vram_put_256inc(); + vram_put_256inc(); + vram_put_256inc(); + vram_put_256inc(); + vram_adr(NAMETABLE_B); + vram_put_256inc(); + vram_put_256inc(); + vram_put_256inc(); + vram_put_256inc(); + vram_adr(NAMETABLE_A + 0x3c0); + vram_put_attrib(); + vram_put_attrib(); + vram_adr(NAMETABLE_B + 0x3c0); + vram_put_attrib(); + vram_put_attrib(); + bank_bg(0); + // setup sprite 0 + oam_clear(); + oam_size(0); + oam_spr(255, 125, 255, 0, 0); + bank_spr(1); + // make sprite 255 = white square + vram_adr(0x1ff0); + vram_fill(0xff, 0x10); +} + +/*{pal:"nes"}*/ +const byte MONOBMP_PALETTE[16] = { + 0x03, + 0x30, 0x03, 0x30, 0x00, + 0x03, 0x30, 0x30, 0x00, + 0x30, 0x03, 0x30, 0x00, + 0x03, 0x30, 0x30 +}; + +void demo() { + byte i; + for (i=16; i<220; i++) { + set_pixel(i,16,1); + set_pixel(16,i,1); + set_pixel(i,220,1); + set_pixel(220,i,1); + set_pixel(i,i,1); + } +} + +void main(void) +{ + byte ctrl; + setup_monobitmap(); + pal_bg(MONOBMP_PALETTE); + demo(); + ppu_on_all();//enable rendering + while(1) { + ppu_wait_nmi(); + // split screen at line 128 + ctrl = PPU.control; + split(0,0); + PPU.control = ctrl ^ 0x10; // bg bank 1 + } +} diff --git a/src/pixed/pixeleditor.ts b/src/pixed/pixeleditor.ts index 79e93856..ade0ce70 100644 --- a/src/pixed/pixeleditor.ts +++ b/src/pixed/pixeleditor.ts @@ -38,6 +38,7 @@ export type PixelEditorImageFormat = { brev?:boolean destfmt?:PixelEditorImageFormat xform?:string + skip?:number }; export type PixelEditorPaletteFormat = { @@ -352,6 +353,7 @@ function convertWordsToImages(words:UintArray, fmt:PixelEditorImageFormat) : Uin var wordsperline = fmt.sl || Math.ceil(width * bpp / bitsperword); var mask = (1 << bpp)-1; var pofs = fmt.pofs || wordsperline*height*count; + var skip = fmt.skip || 0; var images = []; for (var n=0; n>(bitsperword-shift-bpp) : byte>>shift) & mask) << (p*bpp); } imgdata.push(color); @@ -389,6 +391,7 @@ function convertImagesToWords(images:Uint8Array[], fmt:PixelEditorImageFormat) : var wordsperline = fmt.sl || Math.ceil(fmt.w * bpp / bitsperword); var mask = (1 << bpp)-1; var pofs = fmt.pofs || wordsperline*height*count; + var skip = fmt.skip || 0; var words; if (bitsperword <= 8) words = new Uint8Array(wordsperline*height*count*nplanes); @@ -405,7 +408,7 @@ function convertImagesToWords(images:Uint8Array[], fmt:PixelEditorImageFormat) : var ofs = remapBits(ofs0, fmt.remap); for (var p=0; p> (p*bpp)) & mask; - words[ofs + p*pofs] |= (fmt.brev ? (c << (bitsperword-shift-bpp)) : (c << shift)); + words[ofs + p*pofs + skip] |= (fmt.brev ? (c << (bitsperword-shift-bpp)) : (c << shift)); } shift += bpp; if (shift >= bitsperword) { @@ -622,20 +625,24 @@ var PREDEF_PALETTES = { 0xC4D5E7, 0xFF4000, 0xDC0E22, 0xFF476B, 0xD7009F, 0x680AD7, 0x0019BC, 0x0054B1, 0x006A5B, 0x008C03, 0x00AB00, 0x2C8800, 0xA47200, 0x000000, 0x000000, 0x000000, 0xF8F8F8, 0xFFAB3C, 0xFF7981, 0xFF5BC5, 0xFF48F2, 0xDF49FF, 0x476DFF, 0x00B4F7, 0x00E0FF, 0x00E375, 0x03F42B, 0x78B82E, 0xE5E218, 0x787878, 0x000000, 0x000000, 0xFFFFFF, 0xFFF2BE, 0xF8B8B8, 0xF8B8D8, 0xFFB6FF, 0xFFC3FF, 0xC7D1FF, 0x9ADAFF, 0x88EDF8, 0x83FFDD, 0xB8F8B8, 0xF5F8AC, 0xFFFFB0, 0xF8D8F8, 0x000000, 0x000000 - ] + ], + 'ap2lores':[ + (0x000000), (0xff00ff), (0x00007f), (0x7f007f), (0x007f00), (0x7f7f7f), (0x0000bf), (0x0000ff), + (0xbf7f00), (0xffbf00), (0xbfbfbf), (0xff7f7f), (0x00ff00), (0xffff00), (0x00bf7f), (0xffffff), + ], }; var PREDEF_LAYOUTS : {[id:string]:PixelEditorPaletteLayout} = { 'nes':[ ['Screen Color', 0x00, 1], - ['Background 1', 0x01, 3], - ['Background 2', 0x05, 3], - ['Background 3', 0x09, 3], - ['Background 4', 0x0d, 3], - ['Sprite 1', 0x11, 3], - ['Sprite 2', 0x15, 3], - ['Sprite 3', 0x19, 3], - ['Sprite 4', 0x1d, 3] + ['Background 0', 0x01, 3], + ['Background 1', 0x05, 3], + ['Background 2', 0x09, 3], + ['Background 3', 0x0d, 3], + ['Sprite 0', 0x11, 3], + ['Sprite 1', 0x15, 3], + ['Sprite 2', 0x19, 3], + ['Sprite 3', 0x1d, 3] ], }; diff --git a/src/platform/nes.ts b/src/platform/nes.ts index 6577d8dd..4c85fbf7 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -26,6 +26,7 @@ const JSNES_PRESETS = [ {id:'statusbar.c', name:'Split Status Bar'}, {id:'horizmask.c', name:'Offscreen Scrolling'}, {id:'attributes.c', name:'Attribute Table + Pixels'}, + {id:'monobitmap.c', name:'Monochrome Bitmap'}, {id:'aputest.c', name:'Sound Tester'}, {id:'music.c', name:'Music Player'}, {id:'siegegame.c', name:'Siege Game'}, diff --git a/src/views.ts b/src/views.ts index 7941357c..3988d15a 100644 --- a/src/views.ts +++ b/src/views.ts @@ -1122,7 +1122,7 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext { aeditor.appendTo(adual); // make default layout if not exists if (!layout) { - var imgsperline = palette.length > 32 ? 8 : 4; + var imgsperline = palette.length > 32 ? 8 : 4; // TODO: use 'n'? var len = allcolors.length; layout = []; for (var i=0; i