Acorn Computers BBC Micro Model B w/8271 — Acorn BBC Micro Model B w/8271 User Guide Manual PDF

456 Faults, events and BRK handling It is necessary to provide some means to enable programs to deal with faults such as Illegal command or Division by zero . BASIC uses the 6502 BRK instruction when dealing with faults like this and user written programs can also use the same facility. In BASIC (for example), a BRK instruction is followed by a sequence of bytes giving the following information: BRK instruction, value &00. – Fault number. – Fault message (may contain any non-zero character). – &00 to terminate message. When the 6512 encounters a BRK instruction the operating system places the address following the BRK instruction in locations &FD and &FE.

Thus these locations point to the ‘fault number’. The operating system then indirects via location &202. In other words control is transferred to a routine whose address is given in locations &202 (low byte) and &203 (high byte). The default routine, whose address is given at the location, prints the default message. The BRK handling outline above enables the user to intercept normal procedures and to generate his or her own special messages and error numbers in user written machine code routines. The CALL demonstration program towards the beginning of this chapter shows this in practice. See also IRQ at the end of this chapter.

While faults are in general, ‘fatal’, there is another class of events, called ‘events’, which are informative rather than fatal. This class of events includes, for example, a key being pressed on the keyboard. The user may wish to detect such an operation or may be happy to ignore it. When the operating system detects an ‘event’ then, if that event is enabled (by using *FX14 ) it indirects via &220 with an event code in the accumulator. The contents of X and Y depend on the event. The event codes in A indicate the following:

Accumulator description 0 Buffer empty X = buffer identity X = buffer identity 1 Buffer full Y = character that could not be stored 2 Keyboard interrupt 3 ADC conversion complete 4 Start of TV field pulse (vertical sync) 5 Interval timer crossing zero 6 ESCAPE condition detected