Skip to content

Commit

Permalink
Update analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Dec 5, 2024
1 parent e51e275 commit ecfdbef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions nodejs/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MyApp {

async loadController(filename: string) {
try {
const jsCode = await fs.readFile(filename, 'utf8')
const jsCode = await fsPromises.readFile(filename, 'utf8')
const jsCodeFn = `'use strict'; return (() => { ${jsCode} })()`
this.controller = Function('app', jsCodeFn)(this)
} catch (error) {
Expand Down Expand Up @@ -260,7 +260,7 @@ class MyApp {
}
}

await png.pack().pipe(fs.createWriteStream(fn))
await png.pack().pipe(fsPromises.createWriteStream(fn))
}

private setupAudioManager(): void {
Expand Down Expand Up @@ -374,10 +374,10 @@ async function main(argv: string[]) {
}

const myApp = new MyApp()
if (opts.controller != null)
myApp.loadController(opts.controller)
if (args.length > 0)
await MyApp.loadRom(myApp, args[0])
if (opts.controller != null)
myApp.loadController(opts.controller)
}

main(process.argv)
20 changes: 10 additions & 10 deletions tools/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class Analyzer {
private startAdr = 0
private endAdr = 0
private entryPoints = new Array<number>()
private stopPoints = new Set<number>()
private stopAnalyze = new Set<number>()
private jumpRoutines = new Set<number>()
private stopAnalyzeAdrs = new Set<number>()
private labels = new Map<number, Label>()
private blocks = new Array<Block>()
private labelNameTable: Record<number, string> = {}
Expand All @@ -78,12 +78,12 @@ class Analyzer {
insert(this.entryPoints, adr, (e: number) => adr < e)
}

public addStopPoint(adr: number): void {
this.stopPoints.add(adr)
public addJumpRoutine(adr: number): void {
this.jumpRoutines.add(adr)
}

public addStopAnalyze(adr: number): void {
this.stopAnalyze.add(adr)
this.stopAnalyzeAdrs.add(adr)
}

public addJumpTable(adr: number, count: number): void {
Expand Down Expand Up @@ -194,7 +194,7 @@ class Analyzer {
this.addLabel(adr, true)
const block = this.createBlock(adr)
while (adr <= 0xffff) {
if (this.stopAnalyze.has(adr))
if (this.stopAnalyzeAdrs.has(adr))
break

const op = this.read8(adr)
Expand Down Expand Up @@ -227,7 +227,7 @@ class Analyzer {
if (inst.opType === OpType.JMP ||
inst.opType === OpType.RTS ||
inst.opType === OpType.RTI ||
(inst.opType === OpType.JSR && this.stopPoints.has(this.read16(adr + 1)))) {
(inst.opType === OpType.JSR && this.jumpRoutines.has(this.read16(adr + 1)))) {
adr += inst.bytes
break
}
Expand Down Expand Up @@ -390,9 +390,9 @@ async function main(): Promise<void> {
const data = await fs.readFile(options.config)
const str = String.fromCharCode.apply('', data as any)
const json = eval(`(${str})`)
if (json.stopPoints) {
for (let adr of json.stopPoints) {
analyzer.addStopPoint(adr)
if (json.jumpRoutines) {
for (let adr of json.jumpRoutines) {
analyzer.addJumpRoutine(adr)
}
}
if (json.stopAnalyze) {
Expand Down

0 comments on commit ecfdbef

Please sign in to comment.