File: example.py

package info (click to toggle)
hatari 2.5.0%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 12,744 kB
  • sloc: ansic: 164,630; cpp: 8,685; python: 6,251; objc: 1,899; asm: 1,742; sh: 1,668; javascript: 146; makefile: 86; xml: 32
file content (56 lines) | stat: -rwxr-xr-x 1,453 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
#
# This is an example of scripting hatari using hconsole
#
# Run with (using correct EmuTOS path):
#   PATH=../../build/src/:$PATH ./example.py --tos etos1024k.img
# Or if Hatari and hconsole are installed to the system:
#   /usr/share/hatari/hconsole/example.py --tos etos1024k.img

import os
import sys

sys.path.append("/usr/share/hatari/hconsole")

import hconsole

# path for this script
path = os.path.dirname(sys.argv[0])
# current work directory
cwd = os.path.abspath(os.path.curdir)

# shortcuts to hconsole stuff
#
# GEMDOS emulation dir is given because without
# a disk, EmuTOS console invocation is ~8s
main = hconsole.Main(sys.argv + ["."])
code = hconsole.Scancode

# execute commands from external file in current directory
main.script(path + "/example-commands")

# define shortcut functions for entering specific key presses
def backspace():
    main.run("keypress %s" % code.Backspace)
def enter():
    main.run("keypress %s" % code.Return)

# loop removing some of previously script output
for i in range(25):
    backspace()
enter()

# output some text to EmuTOS console in a loop
for i in range(3):
    main.run("text echo Welcome to 'hconsole'")
    enter()

# ask Hatari debugger to parse breakpoint etc commands from file
main.run("parse %s/example-debugger" % path)

# hit a Getdrv() breakpoint when EmuTOS prompt is redrawn
enter()

# wait few secs and kill Hatari
main.run("sleep 3")
main.run("kill")