Skip to content

3.5 Input Output

6502Nerd edited this page Mar 20, 2023 · 13 revisions

Basic Input/Output

This section is about input and output with keyboard/screen.

Keyboard and screen

dflat provides two ways to get keyboard input;

  • reading a line of input, terminated by a return
  • reading a raw key input

Reading a line

As per many dialects of BASIC, dflat offers input as the main way to get input from the keyboard, which takes one parameter that can be integer or string. The program halts and echoes typed characters to the screen and continues with the return key. If it is an integer variable then the normal number formats for decimal, hex and binary are allowed e.g.;

  • input a:println a expects a number then prints it out. For example entering '16', '0x10', or '0xb1000'will all print 16 to the screen
  • input a$:println a$ puts all the characters to the string a$ including a zero terminator, but not including the return key

Reading and sensing single characters

To just get a single key input, the 'get' command can be used, which returns the ascii code of the key pressed or 0 if no key was pressed;

  • c=get(<sync:<int>>) - if sync is 0 then this command returns immediately, else it will wait for a key to be pressed. Note that this function is not great for real-time key sensing need for games as it is subject to repeat and repeat-delay controls

For games and real-time needs, the stick() function simulates the four directions and fire button of a joystick;

  • c=stick() returns a bit mask where bit 0,1,2,3,4 are left, right, up, down and space keys
  • multiple keys can be detected as the same time e.g. to check for diagonal movement inputs
  • if an IJK interface is present on the printer port, then this command uses the IJK joystick rather than Oric keyboard automatically

Printing output to screen

dflat has println as the main way to do regular output to the screen;

  • println <expr>[,<expr>] prints any number of comma separated expressions (which can be string or numeric) and terminates with a carriage return

For flexibility, the following variations are provided;

  • print suppresses the carriage return (you'll recognise this as a Pascal kind of approach)
  • printat <int:x>,<int:y> first move the cursor to position x,y and then prints without a carriage return

Special keys and characters

As per Oric BASIC, some codes below ASCII 32 are treated as special characters which affect the behaviour of keyboard and screen;

  • ctrl-t toggles the caps lock setting
  • ctrl-l clears the screen
  • ctrl-h moves the cursor left
  • ctrl-i moves the cursor right
  • ctrl-j moves the cursor down
  • ctrl-k moves the cursor up
  • ctrl-a copies the current character under the cursor as if it was a key press (useful in editing situations)
  • ctrl-c breaks out of a running program
  • ctrl-z jumps to the monitor