Skip to content

Commit

Permalink
Add behaviour for exporting an ELF file
Browse files Browse the repository at this point in the history
  • Loading branch information
1whatleytay committed Sep 25, 2023
1 parent 07f1603 commit 66e0fd0
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
selectSaveDestination,
writeFile
} from './query/select-file'
import { consoleData, ConsoleType, pushConsole } from '../state/console-data'
import { assembleWithBinary, assembleWithHex } from './mips'
import { consoleData, ConsoleType, openConsole, pushConsole } from '../state/console-data'
import { assembleWithBinary, assembleWithHex, BinaryResult } from './mips'
import { closeTab, createTab, find, loadElf, showSettings, suggestions, tab, tabsState } from '../state/state'
import { appWindow } from '@tauri-apps/api/window'
import { watch } from 'vue'
Expand Down Expand Up @@ -183,22 +183,37 @@ export async function setupEvents() {
await listen('export', async () => {
const current = tab()

const result = await assembleWithBinary(collectLines(current?.lines ?? []), current?.path ?? null)
if (!current) {
return
}

let binary: Uint8Array | null = null
let result: BinaryResult | null = null

if (current.profile && current.profile.kind === 'elf') {
binary = Uint8Array.from(window.atob(current.profile.elf), c => c.charCodeAt(0))
} else {
result = await assembleWithBinary(collectLines(current.lines), current.path)
binary = result.binary
}

let destination: SelectedFile<undefined> | null = null

if (result.binary !== null) {
if (binary !== null) {
destination = await selectSaveDestination('Save File', elfFilter)

if (!destination) {
return
}

await writeBinaryFile(destination.path, result.binary)
await writeBinaryFile(destination.path, binary)
}

consoleData.showConsole = true
postBuildMessage(result.result)

if (result !== null) {
postBuildMessage(result.result)
}

if (destination !== null) {
pushConsole(`ELF file written to ${destination.path}`, ConsoleType.Info)
Expand All @@ -208,6 +223,20 @@ export async function setupEvents() {
await listen('export-hex', async () => {
const current = tab()

if (!current) {
return
}

if (current.profile && current.profile.kind !== 'asm') {
consoleData.showConsole = true

openConsole()
pushConsole('Generating hex regions directly from an elf file is not supported.', ConsoleType.Info)
pushConsole('Use an un-assembled assembly file, or submit a feature request at https://github.com/1whatleytay/saturn.', ConsoleType.Info)

return
}

const result = await assembleWithHex(collectLines(current?.lines ?? []), current?.path ?? null)

let destination: SelectedFile<undefined> | null = null
Expand Down

0 comments on commit 66e0fd0

Please sign in to comment.