Skip to content

Commit

Permalink
add: audio firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbuick committed May 21, 2024
1 parent edae02c commit 41efc71
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 22 deletions.
30 changes: 30 additions & 0 deletions zss/firmware/audio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createfirmware } from 'zss/firmware'
import { isstring } from 'zss/mapping/types'
import { memoryreadcontext } from 'zss/memory'

import { ARG_TYPE, readargs } from './wordtypes'

export const AUDIO_FIRMWARE = createfirmware({
get() {
return [false, undefined]
},
set() {
return [false, undefined]
},
shouldtick() {},
tick() {},
tock() {},
}).command('play', (chip, words) => {
const memory = memoryreadcontext(chip, words)
const [buffer] = readargs(memory, 0, [ARG_TYPE.STRING])

// see if we've been given a flag
const maybebuffer = chip.get(buffer)
if (isstring(maybebuffer)) {
chip.emit('pcspeaker:play', [-1, maybebuffer])
} else {
chip.emit('pcspeaker:play', [-1, buffer])
}

return 0
})
23 changes: 20 additions & 3 deletions zss/firmware/cli.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { maptostring } from 'zss/chip'
import { tape_info } from 'zss/device/api'
import { createfirmware } from 'zss/firmware'
import { memoryreadchip } from 'zss/memory'

export const CLI_FIRMWARE = createfirmware({
get(chip, name) {
// player chip ?
return [false, undefined]
},
set(chip, name, value) {
// player chip ?
return [false, undefined]
},
shouldtick(chip) {
shouldtick() {
//
},
tick(chip) {
Expand All @@ -16,6 +21,18 @@ export const CLI_FIRMWARE = createfirmware({
tock(chip) {
//
},
}).command('stub', (chip, words) => {
return 0
})
.command('text', (chip, words) => {
// const memory = memoryreadchip(chip.id())
const text = words.map(maptostring).join('')
tape_info('cli', 'player>', text)
return 0
})
.command('hyperlink', (chip, args) => {
// package into a panel item
const [labelword, inputword, ...words] = args
const label = maptostring(labelword)
const input = maptostring(inputword)
console.info('hyperlink', label, input, words)
return 0
})
8 changes: 5 additions & 3 deletions zss/firmware/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ import { FIRMWARE } from 'zss/firmware'
import { CODE_PAGE_TYPE } from 'zss/memory/codepage'

import { ALL_FIRMWARE } from './all'
import { AUDIO_FIRMWARE } from './audio'
import { CLI_FIRMWARE } from './cli'
import { GADGET_FIRMWARE } from './gadget'
import { OBJECT_FIRMWARE } from './object'

const firmwares: Record<string, FIRMWARE> = {
all: ALL_FIRMWARE,
cli: CLI_FIRMWARE,
audio: AUDIO_FIRMWARE,
gadget: GADGET_FIRMWARE,
object: OBJECT_FIRMWARE,
}

export const CODE_PAGE_FIRMWARE = {
[CODE_PAGE_TYPE.ERROR]: [],
[CODE_PAGE_TYPE.CLI]: ['all', 'cli'],
[CODE_PAGE_TYPE.BOARD]: ['all', 'gadget'],
[CODE_PAGE_TYPE.OBJECT]: ['all', 'object', 'gadget'],
[CODE_PAGE_TYPE.CLI]: ['all', 'audio', 'cli'],
[CODE_PAGE_TYPE.BOARD]: ['all', 'audio', 'gadget'],
[CODE_PAGE_TYPE.OBJECT]: ['all', 'audio', 'object', 'gadget'],
[CODE_PAGE_TYPE.TERRAIN]: ['all'],
[CODE_PAGE_TYPE.CHARSET]: ['all'],
[CODE_PAGE_TYPE.PALETTE]: ['all'],
Expand Down
15 changes: 0 additions & 15 deletions zss/firmware/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,21 +510,6 @@ export const OBJECT_FIRMWARE = createfirmware({
// if blocked, return 1
return memory.object.x !== dest.x && memory.object.y !== dest.y ? 1 : 0
})
.command('play', (chip, words) => {
const [buffer] = readargs(memoryreadcontext(chip, words), 0, [
ARG_TYPE.STRING,
])

// see if we've been given a flag
const maybebuffer = chip.get(buffer)
if (isstring(maybebuffer)) {
chip.emit('pcspeaker:play', [-1, maybebuffer])
} else {
chip.emit('pcspeaker:play', [-1, buffer])
}

return 0
})
.command('put', (chip, words) => {
const memory = memoryreadchip(chip.id())

Expand Down
3 changes: 2 additions & 1 deletion zss/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ export function memorycli(
cli: string,
) {
// player id + unique id fo run
const id = `${player}_func`
const id = `${player}_cli`

// create / update context
const context = memoryreadchip(id)

context.book = undefined
context.board = undefined
context.inputcurrent = undefined
Expand Down

0 comments on commit 41efc71

Please sign in to comment.