converted CRLF, tweaked homepage, fixed tests

This commit is contained in:
Steven Hugg 2019-03-20 22:49:44 -04:00
parent 61290e09f8
commit 21bc4fd1e5
6 changed files with 60 additions and 23 deletions

View File

@ -28,10 +28,10 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<span class="navbar-brand"><a target="_new" href="https://twitter.com/8bitworkshop" class="twitter-follow-button" data-show-count="false">Follow @8bitworkshop</a></span>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<a class="navbar-brand" target="_new" href="https://twitter.com/8bitworkshop">@8bitworkshop</a>
<!-- <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> -->
<a class="navbar-brand" href="./blog/">Blog</a>
<a class="navbar-brand" href="https://www.amazon.com/default/e/B01N7J10NF/ref=dp_byline_cont_pop_book_1" onclick="ga('send', 'event', 'books', 'click');">Books</a>
<a class="navbar-brand" href="#books" onclick="ga('send', 'event', 'books', 'click');">Books</a>
</div>
<div id="navbar" class="hidden-sm hidden-xs">
<form class="navbar-form navbar-right">
@ -108,6 +108,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
</div>
</div>
<a name="books"/>
<h1 class="text-center">Learn More With a Book!</h1>
<div class="container">

View File

@ -91,12 +91,10 @@ TODO:
- profiler restarts when paused
- it's pretty easy to add a new file named like a library file (bcd.c)
- put globals into view/controller objects
- cr/lf in uploaded files?
- upload binary files doesn't do what's expected, changing pulldown and whatnot
- chrome autostart audio: https://github.com/processing/p5.js-sound/issues/249
- show player controls for each platform, allow touch support, navigator.getGamepads
- better undo/diff for mistakes?
- get rid of "illegal PC" instruction, replace with status msg
- ide bug/feature visualizer for sponsors
- optimization flags for sdcc (oldralloc)

View File

@ -1,7 +1,7 @@
"use strict";
import { hex } from "../util";
import { current_project } from "../ui";
import { CodeProject } from "../project";
export type PixelEditorImageFormat = {
w:number
@ -19,8 +19,9 @@ export type PixelEditorImageFormat = {
};
export type PixelEditorPaletteFormat = {
pal?:number
pal?:number|string
n?:number
layout?:string
};
type PixelEditorMessage = {
@ -430,7 +431,7 @@ export var allthumbs;
function convertPaletteFormat(palbytes: number[]|Uint8Array, palfmt: PixelEditorPaletteFormat) : number[] {
var pal = palfmt.pal;
var newpalette;
if (pal > 0) {
if (typeof pal === 'number') {
var rr = Math.floor(Math.abs(pal/100) % 10);
var gg = Math.floor(Math.abs(pal/10) % 10);
var bb = Math.floor(Math.abs(pal) % 10);
@ -594,6 +595,20 @@ var PREDEF_PALETTES = {
]
};
var PREDEF_LAYOUTS = {
'nes_full':[
['Screen Color', 1],
['Background 1', 3], [null, 1],
['Background 2', 3], [null, 1],
['Background 3', 3], [null, 1],
['Background 4', 3], [null, 1],
['Sprite 1', 3], [null, 1],
['Sprite 2', 3], [null, 1],
['Sprite 3', 3], [null, 1],
['Sprite 4', 3]
],
};
/////
export abstract class PixelNode {
@ -626,8 +641,12 @@ export abstract class PixelNode {
}
}
export class PixelFileDataNode extends PixelNode {
abstract class PixelCodeProjectDataNode extends PixelNode {
fileid : string;
project : CodeProject;
}
export class PixelFileDataNode extends PixelCodeProjectDataNode {
output : Uint8Array;
constructor(fileid, data) {
@ -636,14 +655,15 @@ export class PixelFileDataNode extends PixelNode {
this.output = data;
}
updateLeft() {
current_project.updateFile(this.fileid, this.output);
if (this.project) {
this.project.updateFile(this.fileid, this.output);
}
}
updateRight() {
}
}
export class PixelTextDataNode extends PixelNode {
fileid : string;
export class PixelTextDataNode extends PixelCodeProjectDataNode {
text : string;
start : number;
end : number;
@ -658,7 +678,9 @@ export class PixelTextDataNode extends PixelNode {
}
updateLeft() {
// TODO: reload editors?
current_project.updateFile(this.fileid, this.text);
if (this.project) {
this.project.updateFile(this.fileid, this.text);
}
}
updateRight() {
var datastr = this.text.substring(this.start, this.end);
@ -709,6 +731,21 @@ export class PixelPalettizer extends PixelNode {
}
}
function dedupPalette(cols : number[]) : Uint32Array {
var dup = new Map();
var res = new Uint32Array(cols.length);
var ndups = 0;
for (var i=0; i<cols.length; i++) {
var n = cols[i];
while (dup[n]) {
n ^= ++ndups;
}
res[i] = n;
dup[n] = 1;
}
return res;
}
export class PixelPaletteFormatToRGB extends PixelNode {
input : Uint8Array;
@ -721,7 +758,7 @@ export class PixelPaletteFormatToRGB extends PixelNode {
}
updateRight() {
this.input = this.left.output;
this.palette = new Uint32Array(convertPaletteFormat(this.input, this.palfmt));
this.palette = dedupPalette(convertPaletteFormat(this.input, this.palfmt));
this.output = [];
this.palette.forEach( (rgba:number) => {
this.output.push(new Uint32Array([rgba]));
@ -729,7 +766,7 @@ export class PixelPaletteFormatToRGB extends PixelNode {
}
}
export class PixelViewer {
export class PixelViewer { // TODO: make PixelNode
width : number;
height : number;

View File

@ -334,7 +334,7 @@ function handleFileUpload(files: File[]) {
if (isProbablyBinary(path, data)) {
gotoMainFile = false;
} else {
data = byteArrayToUTF8(data);
data = byteArrayToUTF8(data).replace('\r\n','\n'); // convert CRLF to LF
}
// store in local forage
store.setItem(path, data, function(err, result) {

View File

@ -1045,7 +1045,7 @@ export class AssetEditorView implements ProjectView {
});
}
addPixelEditor(filediv:JQuery, firstnode:PixelFileDataNode|PixelTextDataNode, fmt?) {
addPixelEditor(filediv:JQuery, firstnode:PixelFileDataNode|PixelTextDataNode, fmt:PixelEditorImageFormat) {
// data -> pixels
var mapper = new PixelMapper();
fmt.xform = 'scale(2)';
@ -1097,7 +1097,8 @@ export class AssetEditorView implements ProjectView {
else if (frag.fmt && frag.fmt.pal) {
let node = new PixelTextDataNode(fileid, data, frag.start, frag.end);
this.addPaletteEditor(filediv, node, frag.fmt);
} else {
}
else {
// TODO: other kinds of resources?
}
}

View File

@ -97,13 +97,9 @@ describe('Worker', function() {
compile('plasm', 'word x = ', 'apple2', done, 0, 0, 1);
});
*/
// TODO: test NES bank switching, mapper
it('should compile CC65', function(done) {
compile('cc65', 'int main() {\nint x=1;\nreturn x+2;\n}', 'nes', done, 40976, 3);
});
it('should compile CC65 banked', function(done) {
compile('cc65', '#define NES_MAPPER 4\nint main() {\nint x=1;\nreturn x+2;\n}', 'nes', done, 131088, 3);
});
it('should NOT compile CC65 (compile error)', function(done) {
compile('cc65', 'int main() {\nint x=1;\nprintf("%d",x);\nreturn x+2;\n}', 'nes', done, 0, 0, 1);
});
@ -226,7 +222,7 @@ describe('Worker', function() {
});
/*
it('should compile XASM6809', function(done) {
compile('xasm6809', '\tasld\n\tasld\n', 'mw8080bw', done, 4, 2, 0);
compile('xasm6809', '\tasld\n\tasld\n', 'williams', done, 4, 2, 0);
});
*/
it('should link two files with SDCC', function(done) {
@ -315,5 +311,9 @@ describe('Worker', function() {
compile('cc65', csource, 'apple2', done, 17349, 4, 0);
});
// TODO: test if compile, errors, then compile same file
// TODO: params persist because of fixParamsWithDefines()
it('should compile CC65 banked', function(done) {
compile('cc65', '#define NES_MAPPER 4\nint main() {\nint x=1;\nreturn x+2;\n}', 'nes', done, 131088, 3);
});
});