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 has the same effect as exit(0) on default xcc builds: the runtime emits an RTS back into DOS. The -Q loop switch makes the program enter an infinite loop after main instead of an RTS. In that mode System.exit(...) is the only way to return to DOS.

↑ Topics