Chapter Sixteen

Initialization

When the Atari computer is powered up with the BASIC cartridge in place, the operating system does some processing and then jumps to a BASIC routine. Between the time that BASIC first gets control and the time it prints the READY message, initialization takes place. This initialization is called a cold start. No data or tables are preserved during a cold start. Initialization is repeated if things go terribly awry. For example, if there is an I/O error while executing a LOAD statement, BASIC is totally confused. It gives up and begins all over again with the COLDSTART routine. Sometimes a less drastic partial initialization is necessary. This process is handled by the WARMSTART routine, in which some tables are preserved. Entering the NEW statement, simulated by the XNEW routine, has almost the same effect as a cold start. COLDSTART ($A000) Two flags, LOADFLG and WARMFLG, are used to determine if a cold or warm start is required. The load flag, LOADFLG ($CA), is zero except during the execution of a LOAD statement. The XLOAD routine sets the flag to non-zero when it starts processing and resets it to zero when it finishes. If an I/O error occurs during that interval, IOTEST notes that LOADFLG is non-zero and jumps to COLDSTART. The warm-start flag, WARMFLG ($08), is never set by BASIC. It is set by some other routine, such as the operating system or DOS. If WARMFLG is zero, a cold start is done. If it is non-zero, a warm start is done. During its power-up processing, before BASIC is given control, OS sets WARMFLG to zero to request a cold start. During System Reset processing, OS sets the flag to non-zero, indicating a warm start is desired. If DOS has loaded any data into BASIC's program area during its processing, it will request a cold start. The COLDSTART routine checks both WARMFLG and LOADFLG to determine whether to do a cold or warm start. If a cold start is required, COLDSTART initializes the 6502 CPU 109


Chapter Sixteen stack and clears the decimal flag. The rest of its processing is exactly the same as if the NEW statement had been entered. XNEW ($A00C) The NEW statement is simulated by the XNEW routine. XNEW resets the load flag, LOADFLG, to zero. It initializes the zero- page pointers to BASIC's RAM tables. It reserves 256 bytes at the loW memory address for the multipurpose buffer and stores its address in the zero-page pointer located at $80. Since none of the RAM tables are to retain any data, their zero- page pointers ($82 through $90) are all set to lOW memory plus 256. The Variable Name Table is expanded by one byte, which is set to zero. This creates a dummy end-of-table entry. The Statement Table is expanded by three bytes. The line number of the direct statement ($8000) is stored there along with the length (three). This marks the end of the Statement Table. A default tab value of 10 is set for the PRINT statement. WARMSTART ($A04D) A warm start is the least drastic of the three types of initialization. Everything the WARMSTART routine does is also done by COLDSTART and XNEW. The stop line number (STOPLN), the error number (ERRNUM), and the DATA parameters (DATALN and DATAD) are all set to zero. The RADFLG flag is set to zero, indicating that transcendental functions are working in radians. The break byte (BRKBYT) is set off and $FF is stored in TRAPLN to indicate that errors are not being trapped. All IOCBs (devices and files) are closed. The enter and list devices (ENTDTD and LISTDTD) are set to zero to indicate the keyboard and the screen, respectively. Finally, the READY message is printed and control passes to the Program Editor. 110

<-Chapter 15back to start