Skip to content

Commit bd67c36

Browse files
committed
changed dropped files channel to Blob (filename and data)
we lose the path information but that's not important. the advantage of this method is that it works cross platform
1 parent 8690acf commit bd67c36

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

debugger/debugger.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type debugger struct {
4444
// argument
4545
state chan gui.State
4646
cmds chan gui.Command
47+
blob chan gui.Blob
4748

4849
console *hardware.Console
4950
breakpoints map[uint16]bool
@@ -249,6 +250,8 @@ func (m *debugger) runLoop() error {
249250
return endRunErr
250251
case <-m.guiQuit:
251252
return quitErr
253+
case d := <-m.blob:
254+
m.loadBlob(d)
252255
default:
253256
}
254257

@@ -417,6 +420,15 @@ func (m *debugger) runLoop() error {
417420
return runStop
418421
}
419422

423+
func (m *debugger) loadBlob(blob gui.Blob) {
424+
loader, err := external.FingerprintBlob(blob.Filename, blob.Data, "AUTO")
425+
if err != nil {
426+
return
427+
}
428+
m.loader = loader
429+
m.reset()
430+
}
431+
420432
func (m *debugger) loop() {
421433
for {
422434
fmt.Printf("%s> ", m.console.MARIA.Coords.ShortString())
@@ -426,6 +438,8 @@ func (m *debugger) loop() {
426438
select {
427439
case cmd = <-m.cmds:
428440
fmt.Print("\r")
441+
case d := <-m.blob:
442+
m.loadBlob(d)
429443
case input := <-m.input:
430444
if input.err != nil {
431445
fmt.Println(m.styles.err.Render(input.err.Error()))
@@ -587,6 +601,7 @@ func Launch(guiQuit chan bool, g *gui.GUI, args []string) error {
587601
guiQuit: guiQuit,
588602
state: g.State,
589603
cmds: g.Commands,
604+
blob: g.Blob,
590605
sig: make(chan os.Signal, 1),
591606
input: make(chan input, 1),
592607
loader: loader,

gui/ebiten/input.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package ebiten
22

33
import (
44
"fmt"
5-
"strings"
5+
"io"
6+
"io/fs"
67

78
"github.com/hajimehoshi/ebiten/v2"
89
"github.com/hajimehoshi/ebiten/v2/inpututil"
@@ -11,17 +12,36 @@ import (
1112

1213
func (eg *guiEbiten) inputDragAndDrop() error {
1314
df := ebiten.DroppedFiles()
14-
if df != nil {
15-
f := fmt.Sprintf("%#v", df)
16-
s := strings.Split(f, "\"")
17-
if len(s) > 1 {
15+
if df == nil {
16+
return nil
17+
}
18+
19+
if dfs, ok := df.(fs.ReadDirFS); ok {
20+
fls, err := dfs.ReadDir(".")
21+
if err != nil {
22+
return err
23+
}
24+
if len(fls) > 0 {
25+
f, err := df.Open(fls[0].Name())
26+
if err != nil {
27+
return err
28+
}
29+
defer f.Close()
30+
b, err := io.ReadAll(f)
31+
if err != nil {
32+
return err
33+
}
1834
select {
19-
case eg.g.Commands <- []string{"INSERT", s[1]}:
35+
case eg.g.Blob <- gui.Blob{
36+
Filename: fls[0].Name(),
37+
Data: b,
38+
}:
2039
default:
21-
return nil
40+
return fmt.Errorf("couldn't drop file")
2241
}
2342
}
2443
}
44+
2545
return nil
2646
}
2747

gui/gui.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ type AudioSetup struct {
3838

3939
type Command []string
4040

41+
type Blob struct {
42+
Filename string
43+
Data []uint8
44+
}
45+
4146
type GUI struct {
4247
SetImage chan Image
4348
UserInput chan Input
4449
Commands chan Command
50+
Blob chan Blob
4551

4652
// implementations of UI should default to StateRunning
4753
State chan State
@@ -60,6 +66,7 @@ func NewGUI() *GUI {
6066
SetImage: make(chan Image, 1),
6167
UserInput: make(chan Input, 10),
6268
Commands: make(chan Command, 10),
69+
Blob: make(chan Blob, 1),
6370
State: make(chan State, 1),
6471
AudioSetup: make(chan AudioSetup, 1),
6572
}

hardware/memory/external/fingerprint.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ func Fingerprint(filename string, mapper string) (CartridgeInsertor, error) {
6565
if err != nil {
6666
return CartridgeInsertor{}, err
6767
}
68+
return FingerprintBlob(filename, d, mapper)
69+
}
6870

71+
func FingerprintBlob(filename string, d []uint8, mapper string) (CartridgeInsertor, error) {
6972
// normalise mapper string
7073
mapper = strings.ToUpper(mapper)
7174

0 commit comments

Comments
 (0)