Make GR graphics single width by default, use --gr-width=2 for old behaviour
authorNick Downing <nick@ndcode.org>
Sun, 22 May 2022 00:19:53 +0000 (10:19 +1000)
committerNick Downing <nick@ndcode.org>
Sun, 22 May 2022 00:21:37 +0000 (10:21 +1000)
apple_io.py
applesoft_basic.py

index 16d47da..ff6c09a 100755 (executable)
@@ -182,7 +182,8 @@ NICK_FREQL = 0x30d
 NICK_FREQH = 0x314
 
 # global state
-attr = None
+gr_width = 1 # set by command line
+termios_attr = None
 fd_in = sys.stdin.fileno()
 fd_out = sys.stdout.fileno()
 poll_in = select.poll()
@@ -212,22 +213,22 @@ pcm = alsaaudio.PCM(
 )
 
 def init():
-  global attr
+  global termios_attr
 
-  if attr is None and os.isatty(fd_in):
-    attr = termios.tcgetattr(fd_in)
+  if termios_attr is None and os.isatty(fd_in):
+    termios_attr = termios.tcgetattr(fd_in)
     atexit.register(deinit)
     tty.setraw(fd_in)
     write('\x1b[?25l\x1b[0m') # hide cursor, reset attributes
 
 def deinit():
-  global attr
+  global termios_attr
 
-  if attr is not None:
+  if termios_attr is not None:
     write('\x1b[?25h\x1b[0m') # show cursor, reset attributes
-    termios.tcsetattr(fd_in, termios.TCSADRAIN, attr)
+    termios.tcsetattr(fd_in, termios.TCSADRAIN, termios_attr)
     atexit.unregister(deinit)
-    attr = None
+    termios_attr = None
 
 def pr_hash(n):
   pass
@@ -430,7 +431,7 @@ def gr_update(x0, y0, x1, y1):
   fg = -1
   br = -1
   for i in range(y0, y1):
-    write(f'\x1b[{i + 1:d};{x0 * 2 + 1:d}H')
+    write(f'\x1b[{i + 1:d};{x0 * gr_width + 1:d}H')
     for j in range(x0, x1):
       new_bg = colors[gr_mem[i * 2][j]]
       new_fg = colors[gr_mem[i * 2 + 1][j]]
@@ -463,8 +464,8 @@ def gr_update(x0, y0, x1, y1):
         bg = new_bg
         fg = new_fg
         br = new_br
-      write(ch * 2)
-  write('\x1b[u\x1b[0m') # restore cursor and attrs
+      write(ch * gr_width)
+  write('\x1b[u\x1b[0m') # restore cursor and attributes
   #time.sleep(.05)
 
 def color(n):
index 41f110d..b7b3f3b 100755 (executable)
@@ -30,8 +30,11 @@ EXIT_FAILURE = 1
 #print('yytext', f'"{lex_yy.yytext:s}"')
 #assert False
 
+if len(sys.argv) >= 2 and sys.argv[1][:11] == '--gr-width=':
+  apple_io.gr_width = int(sys.argv[1][11:])
+  del sys.argv[1]
 if len(sys.argv) < 2:
-  print(f'usage: {sys.argv[0]:s} program.tok')
+  print(f'usage: {sys.argv[0]:s} [--gr-width=n] program.tok')
   sys.exit(EXIT_FAILURE)
 program_bas = sys.argv[1]