mirror of
https://github.com/zellyn/goapple2.git
synced 2024-11-30 00:49:24 +00:00
all: updates for new gonuts/commander API
This commit is contained in:
parent
b58a64c48d
commit
c737f264a3
13
a2/disasm.go
13
a2/disasm.go
@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/gonuts/commander"
|
||||
@ -24,23 +24,24 @@ func init() {
|
||||
cmdDisasm.Flag.UintVar(&disasmAddress, "a", 0, "The starting memory address.")
|
||||
}
|
||||
|
||||
func runDisasm(cmd *commander.Command, args []string) {
|
||||
func runDisasm(cmd *commander.Command, args []string) error {
|
||||
if len(args) != 1 {
|
||||
cmd.Usage()
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
bytes, err := ioutil.ReadFile(args[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil
|
||||
}
|
||||
if len(bytes) > 0x10000 {
|
||||
log.Fatalf("File %s is %04X bytes long, which is more than $10000.", args[0], len(bytes))
|
||||
return fmt.Errorf("File %s is %04X bytes long, which is more than $10000.", args[0], len(bytes))
|
||||
}
|
||||
if int(disasmAddress)+len(bytes) > 0x10000 {
|
||||
log.Fatalf("Starting address ($%04X) + file length ($%04X) = $%X, which is > $10000",
|
||||
return fmt.Errorf("Starting address ($%04X) + file length ($%04X) = $%X, which is > $10000",
|
||||
disasmAddress, len(bytes), int(disasmAddress)+len(bytes))
|
||||
}
|
||||
|
||||
asm.DisasmBlock(bytes, uint16(disasmAddress), os.Stdout)
|
||||
return nil
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
|
||||
"github.com/gonuts/commander"
|
||||
"github.com/zellyn/goapple2/disk"
|
||||
@ -22,19 +22,21 @@ func init() {
|
||||
cmdDiskConvert.Flag.UintVar(&diskVolume, "v", 0, "The volume of the disk, or 0 for default.")
|
||||
}
|
||||
|
||||
func runDiskConvert(cmd *commander.Command, args []string) {
|
||||
func runDiskConvert(cmd *commander.Command, args []string) error {
|
||||
if len(args) != 2 {
|
||||
cmd.Usage()
|
||||
return
|
||||
return nil
|
||||
}
|
||||
if diskVolume > 254 {
|
||||
log.Fatalf("disk volume must be 0-254, got %d", diskVolume)
|
||||
return fmt.Errorf("disk volume must be 0-254, got %d", diskVolume)
|
||||
}
|
||||
nyb, err := disk.DiskFromFile(args[0], byte(diskVolume))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
if err = disk.DiskToFile(args[1], nyb); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
16
a2/main.go
16
a2/main.go
@ -8,25 +8,21 @@ import (
|
||||
"github.com/gonuts/flag"
|
||||
)
|
||||
|
||||
var a2cmd *commander.Commander
|
||||
var a2cmd *commander.Command
|
||||
|
||||
func init() {
|
||||
a2cmd = &commander.Commander{
|
||||
Name: os.Args[0],
|
||||
Commands: []*commander.Command{
|
||||
a2cmd = &commander.Command{
|
||||
UsageLine: "a2",
|
||||
Subcommands: []*commander.Command{
|
||||
cmdDisasm,
|
||||
cmdDiskConvert,
|
||||
},
|
||||
Flag: flag.NewFlagSet("a2", flag.ExitOnError),
|
||||
Flag: *flag.NewFlagSet("a2", flag.ExitOnError),
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := a2cmd.Flag.Parse(os.Args[1:]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
args := a2cmd.Flag.Args()
|
||||
if err := a2cmd.Run(args); err != nil {
|
||||
if err := a2cmd.Dispatch(os.Args[1:]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user