Skip to content

Commit ec95d71

Browse files
committed
Improvements to the interactive terminal
Added terminal command editing and autocomplete support on non-Windows platforms.
1 parent 52710c3 commit ec95d71

20 files changed

+2004
-579
lines changed

.travis.yml

-15
This file was deleted.

asm/asm.go

+51
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"io"
1414
"io/ioutil"
1515
"os"
16+
"path/filepath"
1617
"strconv"
1718
"strings"
1819

@@ -340,6 +341,56 @@ const (
340341
Verbose Option = 1 << iota // verbose output during assembly
341342
)
342343

344+
// AssembleFile reads a file containing 6502 assembly code, assembles it,
345+
// and produces a binary output file and a source map file.
346+
func AssembleFile(path string, options Option, out io.Writer) error {
347+
inFile, err := os.Open(path)
348+
if err != nil {
349+
return err
350+
}
351+
defer inFile.Close()
352+
353+
assembly, sourceMap, err := Assemble(inFile, path, out, options)
354+
if err != nil {
355+
for _, e := range assembly.Errors {
356+
fmt.Fprintln(out, e)
357+
}
358+
return err
359+
}
360+
361+
ext := filepath.Ext(path)
362+
prefix := path[:len(path)-len(ext)]
363+
binPath := prefix + ".bin"
364+
binFile, err := os.OpenFile(binPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
365+
if err != nil {
366+
return err
367+
}
368+
defer binFile.Close()
369+
370+
_, err = assembly.WriteTo(binFile)
371+
if err != nil {
372+
return err
373+
}
374+
375+
mapPath := prefix + ".map"
376+
mapFile, err := os.OpenFile(mapPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
377+
if err != nil {
378+
return err
379+
}
380+
defer mapFile.Close()
381+
382+
_, err = sourceMap.WriteTo(mapFile)
383+
if err != nil {
384+
return err
385+
}
386+
387+
fmt.Fprintf(out, "Assembled '%s' to produce '%s' and '%s'.\n",
388+
filepath.Base(path),
389+
filepath.Base(binPath),
390+
filepath.Base(mapPath))
391+
return nil
392+
}
393+
343394
// Assemble reads data from the provided stream and attempts to assemble it
344395
// into 6502 byte code.
345396
func Assemble(r io.Reader, filename string, out io.Writer, options Option) (*Assembly, *SourceMap, error) {

go.mod

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/beevik/go6502
33
go 1.18
44

55
require (
6-
github.com/beevik/cmd v0.1.1
7-
github.com/beevik/prefixtree v0.1.1
6+
github.com/beevik/cmd v0.2.0
7+
github.com/beevik/prefixtree v0.3.0
8+
golang.org/x/sys v0.9.0
89
)

go.sum

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
github.com/beevik/cmd v0.1.1 h1:PC4xoLefEr8ZpmqBSjRfmHrk0SHkbINgkaF3wKoxJB4=
2-
github.com/beevik/cmd v0.1.1/go.mod h1:b2WLULHig7E5Hfi62RoteKhCdWgKF70aasKzsfNHtPQ=
3-
github.com/beevik/prefixtree v0.1.1 h1:Gu3eJhm8kPGsVK5HScNN341QtvrIx1YIZlez4FXimLU=
4-
github.com/beevik/prefixtree v0.1.1/go.mod h1:ZlIK0SfqXT3KN3A22iY+aN6Kt/scvGDx0iYzK9ijn1M=
1+
github.com/beevik/cmd v0.2.0 h1:hF8OjBGkaSig01upnKOX3Gv/I2+fSU4gZPv+9X2tAkM=
2+
github.com/beevik/cmd v0.2.0/go.mod h1:4FhajmCR0XjQanKhv+9TxFnXPYPHaf7PmhG8OaV0N5o=
3+
github.com/beevik/prefixtree v0.3.0 h1:X8HA4v10I1xaaCAALFg+JBgvMvVjIs9ZkwjFSwPK3So=
4+
github.com/beevik/prefixtree v0.3.0/go.mod h1:fRm/Aykn4/iqlmGeA2p1HQdQFOV33boGuK+43GRSZvE=
5+
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
6+
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)