Skip to content

System

System is the xt6502 process-control class. It has one method, exit, which terminates the program and returns control to DOS from anywhere in the program, not only by returning from main.

#import <System.xc> // or the Foundation umbrella

System is a static utility class. Call exit on the class (System.exit(0)); the init is class boilerplate you never use.

Process control · exit


static void exit(i16 value)

Terminates the program by jumping through the platform DOSVEC at $0A/$0B, which returns control to DOS. The 16-bit value is stored at $02FD/$02FE (otherwise unused OS page-2 bytes) for any cooperating caller. DOS itself ignores it; the OS has no process-status mechanism.

Unlike returning from main, exit works from anywhere, so you do not have to unwind the call stack back to main first.

void main(void)
{
if (load("data") == 0) {
Stdio.print("missing data file\n");
System.exit(1);
}
// …normal path…
System.exit(0);
}

If you never call exit, returning from main ends the program. On xt6502 it returns to the loader (DOS) with main’s value in A, and xcc-sim-6502 exits with that value as its status; with -Q loop the program jumps to itself instead.

↑ Topics