1

I would like to save some type of passphrase from user input in MARS. When the user types, I would like it to display * instead of the typed character.

As the user types, I would save each character into an array. I already have the code that saves each character into a buffer but I have trouble figuring out how to hide what the user types.

How would I go about doing so?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
weezyBee
  • 11
  • 2
  • 1
    I don't think you can do that. The best you can try is erasing the char somehow, e.g. by printing a CR and overwriting the input by stars or maybe just backspace/cursor left if that works in MARS. – Jester May 05 '19 at 23:31

1 Answers1

-1

This isn't possible with MARS, as far as I can tell. The toy system calls it provides don't allow you to even move the cursor position or enable/disable terminal echo.

(It does have a "bitmap graphics" mode, so I guess you could hand-draw * glyphs on that display while reading keyboard input. But it has no functions for drawing text in the bitmap.)


In POSIX on a text terminal you'd do that by disabling TTY echo and putting the terminal in raw mode (with an ioctl system call).

Then read() system calls will return as soon as any input is ready instead of a full line, so you'd have your program print * after reading a character. (And you'd have to manually support backspace line-editing).


I don't see MARS support for any of that in its list of system calls. http://courses.missouristate.edu/KenVollmar/mars/Help/SyscallHelp.html

You'd have to add new system calls: http://courses.missouristate.edu/KenVollmar/mars/Help/MarsHelpTools.html documents how you can write a Java class to handle a new system call and hook it into MARS.

SPIM does have MMIO access to a "terminal" device where you can read keyboard input separately from it being echoed on the screen, but MARS doesn't document anything like that. I think MARS keyboard / screen I/O is only available through system calls, and the complete set covered by the documentation doesn't allow it.


It appears that printing a '\b' (ASCII backspace) character doesn't work to move the cursor backward over something the user typed. You just get a white box with a black outline.

Maybe if you run MARS in non-GUI mode from the command line inside XTerm (or Gnome-terminal or Konsole) on a Linux desktop, or a MacOS X terminal window, you could get MARS output going to a terminal that does process cursor-movement escape sequences and codes.

The last hope (that I haven't tried) is if carriage-return (\r) moves the character to the start of the line without advancing to the next line. In that case, you could maybe print over what the user typed by re-printing the whole line of enough * characters.

But even if that works, it will probably flash on screen as its typed, at least momentarily before your program overwrites it.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thanks for the reply, but whenever I use the "\b" function I get white boxes and I'm not sure why – weezyBee May 06 '19 at 01:30
  • @weezyBee: presumably MARS doesn't do terminal emulation, it just prints it. (But it's an unprintable character with no real font glyph for that codepoint, so we get an empty box. So no, you can't backspace after all. That's why we said "*might*", and "*if that works*".) OTOH it might work if you ran MARS from the command-line inside a terminal window (like Konsole or Gnome-terminal under Linux), instead of in the MARS GUI's built-in output pane. – Peter Cordes May 06 '19 at 01:54