Skip to content

Commit

Permalink
fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Feb 5, 2024
1 parent d3faf5b commit f5c9594
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 45 deletions.
12 changes: 5 additions & 7 deletions libs/microcode/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ namespace microcode {

constructor() {
// One interval delay to ensure all static constructors have executed.
setTimeout(() => {
reportEvent("app.start")

this.sceneManager = new SceneManager()
const home = new Home(this)
this.pushScene(home)
}, 1)
basic.pause(1)
reportEvent("app.start")
this.sceneManager = new SceneManager()
const home = new Home(this)
this.pushScene(home)
}

public saveBuffer(slot: string, buf: Buffer) {
Expand Down
4 changes: 2 additions & 2 deletions libs/microcode/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ namespace icondb {
f c c .
`
export function melodyToImage(melody: microcode.Melody) {
const ret = image.create(16, 16)
const ret = simage.create(16, 16)
ret.fill(1)
for (let col = 0; col < microcode.MELODY_LENGTH; col++) {
if (melody.notes[col] === ".") continue
Expand All @@ -311,7 +311,7 @@ namespace icondb {

// - upscale 5x5 image to 16 x 16, add halo
export function renderMicrobitLEDs(led55: SImage) {
const ret = image.create(16, 16)
const ret = simage.create(16, 16)
ret.fill(15)
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 5; col++) {
Expand Down
2 changes: 1 addition & 1 deletion libs/microcode/fieldeditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace microcode {
}
fromBuffer(br: BufferReader) {
const buf = br.readBuffer(4)
const img = image.create(5, 5)
const img = simage.create(5, 5)
for (let index = 0; index < 25; index++) {
let byte = index >> 3
let bit = index & 7
Expand Down
3 changes: 1 addition & 2 deletions libs/microcode/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ namespace microcode {
/* override */ activate() {
super.activate()
this.color = 15
docs.setup(this.app)
}

private drawVersion() {
const font = image.font5
const font = simage.font5
Screen.print(
microcode.VERSION,
Screen.RIGHT_EDGE - font.charWidth * microcode.VERSION.length,
Expand Down
55 changes: 26 additions & 29 deletions libs/microcode/jacs_topwriter.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
namespace jacs {
export let debugOut = false

function scToName(sc: ServiceClass) {
if (sc == ServiceClass.Button) return "but"
if (sc == ServiceClass.DotMatrix) return "dot"
if (sc == ServiceClass.SoundLevel) return "snd"
if (sc == ServiceClass.Temperature) return "tmp"
if (sc == ServiceClass.SoundPlayer) return "mus"
if (sc == ServiceClass.Buzzer) return "buz"
if (sc == ServiceClass.Accelerometer) return "acc"
if (sc == ServiceClass.Radio) return "rad"
if (sc == ServiceClass.Potentiometer) return "pot"
if (sc == ServiceClass.LightLevel) return "lit"
if (sc == ServiceClass.MagneticFieldLevel) return "mag"
if (sc == ServiceClass.RotaryEncoder) return "rot"
if (sc == ServiceClass.Led) return "led"
if (sc == ServiceClass.Servo) return "srv"
return "unknown"
export const SRV_JACSCRIPT_CONDITION = 0x1196796d
export const CMD_CONDITION_FIRE = 0x80

export const CMD_GET_REG = 0x1000
export const CMD_SET_REG = 0x2000

export const JD_REG_STREAMING_SAMPLES = 3
export const JD_REG_INTENSITY = 1
export const JD_REG_READING = 0x101

// delay on sending stuff in pipes and changing pages
export const ANTI_FREEZE_DELAY = 50

export enum NumFmt {
U8 = 0b0000,
U16 = 0b0001,
U32 = 0b0010,
U64 = 0b0011,
I8 = 0b0100,
I16 = 0b0101,
I32 = 0b0110,
I64 = 0b0111,
F8 = 0b1000, // not supported
F16 = 0b1001, // not supported
F32 = 0b1010,
F64 = 0b1011,
}

export enum ServiceClass {
Expand All @@ -35,17 +45,4 @@ namespace jacs {
Led = 0x1609d4f0,
Servo = 0x12fc9103,
}

export const SRV_JACSCRIPT_CONDITION = 0x1196796d
export const CMD_CONDITION_FIRE = 0x80

export const CMD_GET_REG = 0x1000
export const CMD_SET_REG = 0x2000

export const JD_REG_STREAMING_SAMPLES = 3
export const JD_REG_INTENSITY = 1
export const JD_REG_READING = 0x101

// delay on sending stuff in pipes and changing pages
export const ANTI_FREEZE_DELAY = 50
}
205 changes: 205 additions & 0 deletions libs/microcode/keymap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
namespace keymap {
export const PLAYER_OFFSET = 7
export const Up2 = new controller.Button(
ControllerButton.Up + PLAYER_OFFSET,
undefined
)
export const Down2 = new controller.Button(
ControllerButton.Down + PLAYER_OFFSET,
undefined
)
export const Left2 = new controller.Button(
ControllerButton.Left + PLAYER_OFFSET,
undefined
)
export const Right2 = new controller.Button(
ControllerButton.Right + PLAYER_OFFSET,
undefined
)
export const A2 = new controller.Button(
ControllerButton.A + PLAYER_OFFSET,
undefined
)

//% shim=keymap::_setPlayerKeys
declare function _setPlayerKeys(
player: number, // player number is 1-based
up: number,
down: number,
left: number,
right: number,
A: number,
B: number
): void

//% shim=TD_NOOP
export function setupKeys(): void {
_setPlayerKeys(
1,
keymap.KeyCode.UpArrow,
keymap.KeyCode.DownArrow,
keymap.KeyCode.LeftArrow,
keymap.KeyCode.RightArrow,
keymap.KeyCode.Enter,
keymap.KeyCode.Backspace
)
_setPlayerKeys(
2,
keymap.KeyCode.PageUp,
keymap.KeyCode.PageDown,
keymap.KeyCode.OpenBracket,
keymap.KeyCode.ClosedBracket,
keymap.KeyCode.Space,
keymap.KeyCode.Delete
)

Up2.onEvent(ControllerButtonEvent.Pressed, () => {
control.raiseEvent(
ControllerButtonEvent.Pressed,
ControllerButton.Up + PLAYER_OFFSET
)
})
Down2.onEvent(ControllerButtonEvent.Pressed, () => {
control.raiseEvent(
ControllerButtonEvent.Pressed,
ControllerButton.Down + PLAYER_OFFSET
)
})
Left2.onEvent(ControllerButtonEvent.Pressed, () => {
control.raiseEvent(
ControllerButtonEvent.Pressed,
ControllerButton.Left + PLAYER_OFFSET
)
})
Right2.onEvent(ControllerButtonEvent.Pressed, () => {
control.raiseEvent(
ControllerButtonEvent.Pressed,
ControllerButton.Right + PLAYER_OFFSET
)
})
A2.onEvent(ControllerButtonEvent.Pressed, () => {
control.raiseEvent(
ControllerButtonEvent.Pressed,
ControllerButton.A + PLAYER_OFFSET
)
})
}

export enum KeyCode {
None = 0,

Backspace = 8,
Tab = 9,
Enter = 13,
Shift = 16,
Ctrl = 17,
Alt = 18,
PauseBreak = 19,
CapsLock = 20,
Escape = 27,
Space = 32,
PageUp = 33,
PageDown = 34,
End = 35,
Home = 36,

LeftArrow = 37,
UpArrow = 38,
RightArrow = 39,
DownArrow = 40,

Insert = 45,
Delete = 46,

Zero = 48,
One = 49,
Two = 50,
Three = 51,
Four = 52,
Five = 53,
Six = 54,
Seven = 55,
Eight = 56,
Nine = 57,

A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,

LeftWindowsKey = 91,
RightWindowsKey = 92,

Numpad0 = 96,
Numpad1 = 97,
Numpad2 = 98,
Numpad3 = 99,
Numpad4 = 100,
Numpad5 = 101,
Numpad6 = 102,
Numpad7 = 103,
Numpad8 = 104,
Numpad9 = 105,

Multiply = 106,
Add = 107,
Subtract = 109,
DecimalPoint = 110,
Divide = 111,

F1 = 112,
F2 = 113,
F3 = 114,
F4 = 115,
F5 = 116,
F6 = 117,
F7 = 118,
F8 = 119,
F9 = 120,
F10 = 121,
F11 = 122,
F12 = 123,

NumLock = 144,
ScrollLock = 145,

SemiColon = 186,
Equals = 187,
Comma = 188,
Dash = 189,
Period = 190,
ForwardSlash = 191,
Tilde = 192,

OpenBracket = 219,
ClosedBracket = 221,
SingleQuote = 222,

// Mouse
MouseLeftButton = -1,
MouseRightButton = -2,
MouseCenterButton = -3,
}
}
5 changes: 2 additions & 3 deletions libs/microcode/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
setTimeout(() => {
const app = new microcode.App()
}, 1)
basic.pause(1)
const app = new microcode.App()
Loading

0 comments on commit f5c9594

Please sign in to comment.