Mouse In A Hole, the platform game the course builds in Xtal BASIC 4.2, running on the Tatung Einstein: the mouse mid-jump between platforms, two cats and the cheese
← Back to Courses
module
5

Changing Your Mind

Introduction

You will mistype things. Everybody does, and on a machine where a program is typed in by hand it matters more than it sounds: a forty-line program is a lot of typing to repeat because of one wrong letter.

Xtal BASIC is better equipped for this than you might expect. There is a real editor built into it, and three commands that take the tedium out of numbering.

Fixing A Line While You Type It

Before you press ENTER, the line is just characters on the screen and you can change them.

KeyWhat it does
DELETErubs out the character to the left
CTRL-Hmoves left without rubbing out, so you can type over
CTRL-Uclears from the cursor to the end of the line
CTRL-Xclears the whole line and starts again

In MAME: DELETE is Backspace, and CTRL is Ctrl (Control on a Mac, not Command).

The arrow keys do not move the cursor. On this machine the left, right and up arrows type the characters [, ] and ^. If you press one by accident you will see it appear. CTRL-H is the left arrow you wanted.

Fixing A Line That Is Already Stored

This is the part worth learning properly, because it turns a retype into three keystrokes.

LIST your program. The lines are on the screen. Now move the cursor onto one of them and change it:

KeyWhat it does
CTRL-Kmoves the cursor up a row
CTRL-J, or the DOWN keymoves it down a row
CTRL-Dmoves it right a column
CTRL-Hmoves it left a column

Move to the wrong character, type the right one over it, and press ENTER. BASIC reads the whole line off the screen - wherever the cursor happens to be on it - and stores it in place of the old one.

It does not matter that the line on screen was put there by LIST rather than by you. What is on the screen is what gets stored.

Afterwards, clear the screen with CTRL-L. The cursor is left sitting on the listing, and anything you type next lands on top of it. Typing LIST there does not list - it merges with the text under it and gives you a Syntax Error about a line you did not write. CTRL-L wipes the screen and leaves the program alone.

Numbering Lines For You

Typing 10, 20, 30 at the start of every line gets dull. AUTO does it:

AUTO

BASIC prints 10 and waits. Type the rest of the line and press ENTER, and it prints 20. And so on.

AUTO 100,5 starts at 100 and goes up in fives.

Getting out of AUTO is the awkward bit. ESC does not do it - everything you type afterwards still becomes a program line, overwriting whatever is already there. The way out is to rub out the number BASIC just offered (CTRL-X clears the line) and press ENTER.

Be careful with an empty line at an offered number, too: pressing ENTER on its own deletes any line that already has that number.

Renumbering

Once you have squeezed lines into 21, 22 and 23 and run out of room, RENUM tidies the whole program up:

RENUM

renumbers from 10 in tens. RENUM 100,5 starts at 100 and steps by 5.

It fixes the jumps as well. A GOTO 20 pointing at the line that has just become 105 is rewritten to GOTO 105, and the same for GOSUB, IF ... THEN and ON ... GOTO. You have not met those yet - they are S11 and S13 - but when you do, this is one less thing to worry about.

Deleting Several Lines

A number on its own deletes one line, as S4 showed. For a range:

DEL 110,115

deletes lines 110 to 115 inclusive. DEL 110,110 deletes just that one.

Two traps. DEL 110 with a single number is a Range Error - it will not guess what you meant. And DEL on its own, with no numbers at all, deletes the first line of your program, silently. It is an easy thing to type by accident.

The Code

Type these three lines, deliberately getting line 10 wrong:

10 PRINT "THE CAT SAT"
20 PRINT "ON THE MAT"
30 PRINT "THE END"

Now LIST, and make it a bat instead of a cat without retyping the line:

  1. CTRL-K four times, to get up to the listed line 10.
  2. CTRL-D eighteen times, to get across to the C of CAT.
  3. Type BAT.
  4. Press ENTER.
  5. Press CTRL-L to clear the screen.

Starting from

A fresh boot, or NEW.

What you should see

After the edit, LIST shows line 10 changed and the other two untouched, and RUN gives:

THE BAT SAT
ON THE MAT
THE END
Ready

Line 10 corrected in place with the screen editor

Change One Thing

  • Do the same edit, but press ENTER while the cursor is still in the middle of the word. Does it matter where on the line the cursor is?
  • Type RENUM 100,5 and LIST. What have the line numbers become? Add 40 GOTO 20 to the original program first, and look at what line 40 says after the renumber.
  • Type AUTO, put two lines in, and get out of it again. Then try getting out with ESC instead and see what happens to the next thing you type.

Exercises

5.1 Type a four-line program using AUTO, then get out of AUTO cleanly.

5.2 Renumber that program to start at 1000 in steps of 10, and check with LIST.

5.3 Use the screen editor to change one word in the middle of line 1020 without retyping the line. Then delete lines 1010 and 1020 in one command.

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
[, ] or ^ appears when you press an arrow keyThe arrow keys type those characters on this machine. Use CTRL-H, CTRL-D, CTRL-K and CTRL-J to move the cursor.
A command you typed after editing gives a strange Syntax ErrorYou typed it on top of listed text and the two ran together. CTRL-L to clear the screen first.
You are still getting line numbers offered after ESCESC does not leave AUTO. Clear the offered number with CTRL-X and press ENTER.
A line vanished while you were using AUTOAn empty line at an offered number deletes the line with that number.
Range Error from DELDEL wants two numbers: DEL 110,115, or DEL 110,110 for one line.
The first line of your program has goneYou typed DEL with no numbers.
The line you edited did not changeENTER has to be pressed while the cursor is on that line.

Summary

Before ENTER: DELETE, CTRL-H, CTRL-U, CTRL-X. After ENTER: LIST, move to the line with CTRL-K and CTRL-D, type over it, press ENTER, then CTRL-L. AUTO numbers lines for you and is left by rubbing out the offered number. RENUM tidies the numbers and fixes the jumps. DEL a,b deletes a range - and bare DEL eats your first line.

Next

S6, Keeping Your Work - putting a program on the disc so that switching the machine off stops being a disaster.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.