Add /deps.sh, in /linapple remove full-screen mode to make it run properly on recent...
[applesoft_basic.git] / applesoft_basic.py
1 #!/usr/bin/env python3
2
3 # Copyright (C) 2022 Nick Downing <nick@ndcode.org>
4 # SPDX-License-Identifier: GPL-2.0-only
5 #
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; version 2.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
19 import apple_io
20 import element
21 import lex_yy
22 import apple_joystick
23 import sys
24 import t_def
25 import y_tab
26
27 EXIT_SUCCESS = 0
28 EXIT_FAILURE = 1
29
30 #print('yylex()', lex_yy.yylex())
31 #print('yytext', f'"{lex_yy.yytext:s}"')
32 #assert False
33
34 beep_styles = {
35   'alsa': apple_io.BEEP_STYLE_ALSA,
36   'vt100': apple_io.BEEP_STYLE_VT100,
37 }
38
39 while len(sys.argv) >= 2:
40   if sys.argv[1][:7] == '--beep-style=':
41     apple_io.beep_style = beep_styles[sys.arg[1][7:]]
42   elif sys.argv[1] == '--hrcg':
43     apple_io.hrcg = True
44   elif sys.argv[1][:24] == '--inter-statement-delay=':
45     t_def.inter_statement_delay = float(sys.argv[1][24:])
46   elif sys.argv[1][:11] == '--joystick=':
47     fields = sys.argv[1][11:].split(',')
48     apple_joystick.input_path = fields[0]
49     for i in fields[1:]:
50       if i == 'flip_x':
51         apple_joystick.flip_x = True
52       elif i == 'flip_y':
53         apple_joystick.flip_y = True
54       elif i == 'swap_axes':
55         apple_joystick.swap_axes = True
56       elif i == 'swap_buttons':
57         apple_joystick.swap_buttons = True
58       else:
59         assert False
60   else:
61     break
62   del sys.argv[1]
63 if len(sys.argv) < 2:
64   print(f'usage: {sys.argv[0]:s} [--beep-style=alsa|vt100] [--inter-statement-delay=secs] [--joystick=/dev/input/eventNN[,flip_x|flip_y|swap_axes|swap_buttons,...]] program.tok')
65   sys.exit(EXIT_FAILURE)
66 program_bas = sys.argv[1]
67
68 with open(program_bas) as fin:
69   lex_yy.yyin = fin
70   program = y_tab.yyparse(t_def.Program)
71 #element.serialize(program, sys.stdout)
72
73 program.post_process(program)
74 #element.serialize(program, sys.stdout)
75
76 apple_io.init()
77 try:
78   apple_joystick.init()
79   #print('context.run()')
80   context = t_def.Context(program)
81   context.run()
82 finally:
83   #print('apple_io.deinit()')
84   apple_io.deinit()
85   apple_joystick.deinit()