Skip to content

Commit

Permalink
feat: code execution requires a codepage type
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbuick committed Apr 30, 2024
1 parent c7fb52f commit 6d2b631
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
21 changes: 21 additions & 0 deletions zss/firmware/all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createfirmware } from 'zss/firmware'

export const ALL_FIRMWARE = createfirmware({
get(chip, name) {
return [false, undefined]
},
set(chip, name, value) {
return [false, undefined]
},
shouldtick(chip) {
//
},
tick(chip) {
//
},
tock(chip) {
//
},
}).command('stub', (chip, words) => {
return 0
})
18 changes: 16 additions & 2 deletions zss/firmware/loader.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { CHIP } from 'zss/chip'
import { FIRMWARE } from 'zss/firmware'
import { CODE_PAGE_TYPE } from 'zss/memory/codepage'

import { ALL_FIRMWARE } from './all'
import { ZSS_FIRMWARE } from './zss'
import { ZZT_FIRMWARE } from './zzt'

const firmwares: Record<string, FIRMWARE> = {
all: ALL_FIRMWARE,
zzt: ZZT_FIRMWARE,
zss: ZSS_FIRMWARE,
}

export type FIRMWARE_NAME = keyof typeof firmwares
export const CODE_PAGE_FIRMWARE = {
[CODE_PAGE_TYPE.ERROR]: [],
[CODE_PAGE_TYPE.FUNC]: ['all'],
[CODE_PAGE_TYPE.BOARD]: ['all'],
[CODE_PAGE_TYPE.OBJECT]: ['all', 'zss', 'zzt'],
[CODE_PAGE_TYPE.TERRAIN]: ['all'],
[CODE_PAGE_TYPE.CHARSET]: ['all'],
[CODE_PAGE_TYPE.PALETTE]: ['all'],
}

export type FIRMWARE_NAME = keyof typeof CODE_PAGE_FIRMWARE

export function loadfirmware(chip: CHIP, items: FIRMWARE_NAME[]) {
export function loadfirmware(chip: CHIP, firmware: CODE_PAGE_TYPE) {
const items = CODE_PAGE_FIRMWARE[firmware] ?? []
items.forEach((name) => chip.install(firmwares[name]))
}
3 changes: 2 additions & 1 deletion zss/memory/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ export function bookboardtick(
target: BOARD_ELEMENT,
id: string,
code: string,
type: CODE_PAGE_TYPE,
) => void,
) {
if (!ispresent(book) || !ispresent(board)) {
Expand Down Expand Up @@ -506,7 +507,7 @@ export function bookboardtick(
}

// signal id & code
oncode(book, board, target, target.id, code)
oncode(book, board, target, target.id, code, CODE_PAGE_TYPE.OBJECT)
}

// cleanup objects flagged for deletion
Expand Down
5 changes: 4 additions & 1 deletion zss/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
bookreadboard,
bookreadobject,
} from './book'
import { CODE_PAGE_TYPE } from './codepage'
import {
FRAME_STATE,
FRAME_TYPE,
Expand Down Expand Up @@ -183,6 +184,7 @@ export function memorytick(os: OS, timestamp: number) {
target: BOARD_ELEMENT,
id: string,
code: string,
type: CODE_PAGE_TYPE,
) {
// set context
const context = memoryreadchip(id)
Expand All @@ -191,7 +193,8 @@ export function memorytick(os: OS, timestamp: number) {
context.target = target
context.inputcurrent = undefined
// run chip code
os.tick(id, timestamp, code, ['zss', 'zzt'])
//
os.tick(id, timestamp, code, type)
}

// update boards / build code / run chips
Expand Down
9 changes: 5 additions & 4 deletions zss/os.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CHIP, createchip } from './chip'
import { MESSAGE_FUNC, parsetarget } from './device'
import { FIRMWARE_NAME, loadfirmware } from './firmware/loader'
import { loadfirmware } from './firmware/loader'
import { GeneratorBuild, compile } from './lang/generator'
import { ispresent } from './mapping/types'
import { CODE_PAGE_TYPE } from './memory/codepage'

export type OS = {
ids: () => string[]
Expand All @@ -12,7 +13,7 @@ export type OS = {
id: string,
timestamp: number,
code: string,
firmwares: FIRMWARE_NAME[],
type: CODE_PAGE_TYPE,
) => boolean
message: MESSAGE_FUNC
}
Expand Down Expand Up @@ -47,7 +48,7 @@ export function createos() {
}
return !!chip
},
tick(id, timestamp, code, firmwares) {
tick(id, timestamp, code, type) {
let chip = chips[id]

if (!ispresent(chips[id])) {
Expand All @@ -63,7 +64,7 @@ export function createos() {
chip = chips[id] = createchip(id, result)

// load chip firmware
loadfirmware(chip, firmwares)
loadfirmware(chip, type)
}

return !!chip?.tick(timestamp)
Expand Down

0 comments on commit 6d2b631

Please sign in to comment.