Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
c79f043529 | |||
3a676c7151 | |||
0023710209 | |||
0756091e8c | |||
39b30c8ae1 | |||
1c5d6316cc | |||
6d4d681898 | |||
7053fd1490 | |||
e7a49acac0 | |||
d76cfb6e2e | |||
538f08052d |
@ -23,7 +23,7 @@ To remove a package, click on the garbage button in the file list next to the pa
|
||||
|
||||
## Publishing packages
|
||||
|
||||
Packages can be published from the pxt command line. We are still sorting out the details.
|
||||
Packages can be published from the pxt command line. Check out [the docs](https://www.pxt.io/packages).
|
||||
|
||||
## Localizing packages
|
||||
|
||||
|
@ -261,36 +261,6 @@ namespace pxtrt {
|
||||
r->unref();
|
||||
}
|
||||
|
||||
//%
|
||||
uint32_t ldglb(int idx) {
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
return globals[idx];
|
||||
}
|
||||
|
||||
//%
|
||||
uint32_t ldglbRef(int idx) {
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
uint32_t tmp = globals[idx];
|
||||
incr(tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// note the idx comes last - it's more convenient that way in the emitter
|
||||
//%
|
||||
void stglb(uint32_t v, int idx)
|
||||
{
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
globals[idx] = v;
|
||||
}
|
||||
|
||||
//%
|
||||
void stglbRef(uint32_t v, int idx)
|
||||
{
|
||||
check(0 <= idx && idx < numGlobals, ERR_OUT_OF_BOUNDS, 7);
|
||||
decr(globals[idx]);
|
||||
globals[idx] = v;
|
||||
}
|
||||
|
||||
// Store a captured local in a closure. It returns the action, so it can be chained.
|
||||
//%
|
||||
RefAction *stclo(RefAction *a, int idx, uint32_t v)
|
||||
@ -306,6 +276,34 @@ namespace pxtrt {
|
||||
microbit_panic(code);
|
||||
}
|
||||
|
||||
//%
|
||||
int stringToBool(StringData *s) {
|
||||
if (s == NULL) return 0;
|
||||
if (s->len == 0) {
|
||||
s->decr();
|
||||
return 0;
|
||||
}
|
||||
s->decr();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//%
|
||||
StringData* emptyToNull(StringData *s) {
|
||||
if (!s || s->len == 0)
|
||||
return NULL;
|
||||
return s;
|
||||
}
|
||||
|
||||
//%
|
||||
int ptrToBool(uint32_t p) {
|
||||
if (p) {
|
||||
decr(p);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Debugger
|
||||
//
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.3.44",
|
||||
"version": "0.3.47",
|
||||
"description": "micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.3.48"
|
||||
"pxt-core": "0.3.53"
|
||||
}
|
||||
}
|
||||
|
19
sim/state.ts
19
sim/state.ts
@ -470,7 +470,7 @@ namespace pxsim {
|
||||
radio: RadioBus;
|
||||
|
||||
// display
|
||||
image = createImage(5);
|
||||
image = createInternalImage(5);
|
||||
brigthness = 255;
|
||||
displayMode = DisplayMode.bw;
|
||||
font: Image = createFont();
|
||||
@ -608,14 +608,19 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
export class Image {
|
||||
export class Image extends RefObject {
|
||||
public static height: number = 5;
|
||||
public width: number;
|
||||
public data: number[];
|
||||
constructor(width: number, data: number[]) {
|
||||
super()
|
||||
this.width = width;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public print() {
|
||||
console.log(`Image id:${this.id} refs:${this.refcnt} size:${this.width}x${Image.height}`)
|
||||
}
|
||||
public get(x: number, y: number): number {
|
||||
if (x < 0 || x >= this.width || y < 0 || y >= 5) return 0;
|
||||
return this.data[y * this.width + x];
|
||||
@ -650,6 +655,12 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
export function createInternalImage(width: number): Image {
|
||||
let img = createImage(width)
|
||||
pxsim.noLeakTracking(img)
|
||||
return img
|
||||
}
|
||||
|
||||
export function createImage(width: number): Image {
|
||||
return new Image(width, new Array(width * 5));
|
||||
}
|
||||
@ -661,7 +672,7 @@ namespace pxsim {
|
||||
export function createImageFromString(text: string): Image {
|
||||
let font = board().font;
|
||||
let w = font.width;
|
||||
let sprite = createImage(6 * text.length - 1);
|
||||
let sprite = createInternalImage(6 * text.length - 1);
|
||||
let k = 0;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let charCode = text.charCodeAt(i);
|
||||
@ -685,7 +696,7 @@ namespace pxsim {
|
||||
|
||||
let nb = data.length;
|
||||
let n = nb / 5;
|
||||
let font = createImage(nb);
|
||||
let font = createInternalImage(nb);
|
||||
for (let c = 0; c < n; c++) {
|
||||
for (let row = 0; row < 5; row++) {
|
||||
let char = data[c * 5 + row];
|
||||
|
Reference in New Issue
Block a user