The RESET Key: Warm Start, Cold Start and Writing RESET-Proof Programs
Every Atari program has to decide what the RESET key should do. On some it should return to a menu, on others restart the game, and on protected software it may reboot the whole machine. Doing any of this properly means knowing what the operating system does when RESET is pressed: what it wipes, what it keeps, and which vectors it calls. This guide covers those mechanics on both the 400/800 and the XL/XE, then builds a small machine-language program that survives RESET with its interrupt routine intact.
What you'll learn: the cold-start and warm-start sequences, what memory each clears, the flags WARMST, COLDST and BOOT?, the DOSINI/DOSVEC/CASINI vectors, the XL/XE hardware differences, BASIC-level tricks, and a tested DOSINI hook.
What you need: for the assembly example, MADS and an emulator. The example was assembled with MADS and tested in atari800 (800XL mode) under Atari DOS 2.5 and as a stand-alone executable.
1. Two kinds of start
The OS has two initialisation routines, with entry vectors you can also call yourself: WARMSV at $E474 (58484) for a warm start and COLDSV at $E477 (58487) for a cold start.
A cold start (power-up) is the full sequence. It disables IRQs, sets WARMST ($08) to 0, sizes RAM 4K at a time, zeroes the hardware register pages at $D000, $D200, $D300 and $D400 and clears all RAM from $0008 upwards. It then initialises the interrupt vectors, the device table and the resident handlers, initialises any cartridges, opens the screen editor, attempts the cassette and disk boots, clears COLDST ($0244) to say it finished, and finally hands control to a cartridge or jumps through DOSVEC.
A warm start (RESET) is a subset. It sets WARMST to $FF and zeroes only OS RAM: $0010–$007F and $0200–$03FF. It reinitialises the handlers and reopens the screen. Instead of booting again, it calls CASINI ($02) if a cassette boot succeeded at power-up, and DOSINI ($0C) if a disk boot did. It then initialises cartridges and passes control as before.
So after a warm start:
- Your program and data survive, as do BASIC programs, anything in page 6 ($0600) and the zero-page area $80–$FF.
- Everything in OS RAM is gone. That includes the VBI and DLI vectors (VVBLKI, VVBLKD, VDSLST), the display-list pointer SDLSTL ($230), the colour shadows at 704–712, CHBAS (756) and the cursor settings. A custom screen, character set, player graphics or interrupt routine is switched off.
- The screen is reopened in GRAPHICS 0.
Software that must survive RESET therefore has to put all of that back, and DOSINI is the place to do it.
2. The flags that steer it
| Address | Name | Meaning |
|---|---|---|
| $08 (8) | WARMST | 0 during power-up, $FF after RESET. Test it in an init routine to tell the two apart |
| $09 (9) | BOOT? | Bit 0 set means a disk boot succeeded (call DOSINI on RESET); bit 1 a cassette boot (call CASINI) |
| $0A (10) | DOSVEC | Where control goes if no cartridge takes over: DOS's menu, the booted program, or the "blackboard" memo pad by default |
| $0C (12) | DOSINI | Disk-boot init routine, called at power-up and on every RESET |
| $02 (2) | CASINI | The same for cassette-booted software |
| $0244 (580) | COLDST | Non-zero makes RESET do a full cold start (reboot) |
Locations 8 to 15 are cleared only on a cold start, so DOSVEC and DOSINI survive RESET. DOS 2's own init routine sets DOSVEC back to the DUP menu on every RESET. We saw exactly that while testing the example below.
3. 400/800 versus XL/XE
On the 400 and 800, the RESET key is wired to ANTIC's RNMI input and produces a non-maskable interrupt, synchronised to the start of vertical blank. The NMI handler sees bit 5 of NMIST and runs the warm start. The 6502 itself is never reset, which is why the OS manual warns that RESET cannot free a processor that has locked up completely.
From the 1200XL on, RESET pulls the real reset lines of the 6502, ANTIC, FREDDIE and the PIA. The CPU restarts at the reset vector, and the OS has to work out for itself whether this is a warm or a cold start. The XL OS keeps three validation bytes, PUPBT1–3 at $033D–$033F (829–831), holding $5C, $93 and $25. If they are intact after a reset it warm starts, and otherwise it cold starts. Because the PIA is reset as well, PORTB returns to its power-on state: the OS ROM is enabled, the BASIC and self-test ROMs are disabled, and on a 130XE the CPU is back in main memory. Any bank switching or "OS in RAM" trick has to be redone in your init routine.
4. BASIC-level tricks
From BASIC, two POKEs change what RESET does:
POKE 580,1
This makes the next RESET a cold start, so the machine reboots and memory is wiped. It is a popular final touch for protected disk software, because there is nothing left in memory to examine. We confirmed it with the example program: with COLDST set to 1, RESET rebooted the disk and the program loaded again from scratch.
POKE 9,255
Mapping the Atari and Atari Software Protection Techniques both describe this as making the machine lock up on RESET. Use it only if that is truly what you want.
Hooking DOSINI needs machine code. In plain BASIC, a warm start hands control back to the BASIC cartridge with your program still in memory, but anything the program set up in OS RAM (colours, the character set pointer, player graphics, cursor inhibit) has been undone. Keep that setup together at the start of the program so a fresh RUN restores it.
5. A RESET-proof machine-language program
The program below:
- Saves the current DOSINI (DOS's init routine) and installs its own.
- Points DOSVEC at its main entry, so the OS restarts it after RESET.
- Sets bit 0 of BOOT?, so the OS calls DOSINI on RESET even when the program was not booted from a disk (for example, run from an emulator or a menu).
- Sets COLDST to 0, so RESET is a warm start.
- Installs a deferred vertical-blank routine that shows a running frame counter.
On every RESET, the init routine first calls DOS's own init, then takes DOSVEC back, counts the reset and reinstalls the VBI. The OS then jumps through DOSVEC to main, which redraws the screen text.
; RESET-proof program: survives [RESET] by hooking DOSINI and DOSVEC
WARMST = $08
BOOTQ = $09
DOSVEC = $0A
DOSINI = $0C
SAVMSC = $58
COLDST = $0244
SETVBV = $E45C
XITVBV = $E462
org $3000
start lda DOSINI ; remember the previous init routine
sta oldini
lda DOSINI+1
sta oldini+1
lda #<init ; our init runs on every RESET
sta DOSINI
lda #>init
sta DOSINI+1
lda #<main ; and the OS restarts us through DOSVEC
sta DOSVEC
lda #>main
sta DOSVEC+1
lda BOOTQ ; claim a successful disk boot,
ora #1 ; so the OS calls DOSINI on RESET
sta BOOTQ
lda #0
sta COLDST ; RESET = warm start, not reboot
jsr setup ; install the VBI now (DOS is already set up)
main jsr show ; print the message (screen was reopened)
forever jmp forever
show clc ; point a zero-page pointer at row 2
lda SAVMSC
adc #80
sta $CB
lda SAVMSC+1
adc #0
sta $CC
ldy #0
s1 lda text,y
sta ($CB),y
iny
cpy #textlen
bne s1
lda resets
ora #$10
sta ($CB),y
rts
init lda oldini ; chain to the old DOSINI (DOS, if any)
ora oldini+1
beq noold
jsr callold
noold lda #<main ; DOS's init just reset DOSVEC
sta DOSVEC ; to its menu, so claim it again
lda #>main
sta DOSVEC+1
inc resets ; we only get here on RESET
setup ldy #<vbi ; (re)install the deferred VBI
ldx #>vbi
lda #7
jsr SETVBV
rts
callold jmp (oldini)
vbi inc frames ; show a running frame counter on row 4
clc
lda SAVMSC
adc #160
sta $CD
lda SAVMSC+1
adc #0
sta $CE
lda frames
lsr
lsr
lsr
lsr
tax
lda hex,x
ldy #0
sta ($CD),y
lda frames
and #$0F
tax
lda hex,x
iny
sta ($CD),y
jmp XITVBV
text dta d'RESETS SURVIVED: '
textlen = *-text
hex dta d'0123456789ABCDEF'
oldini dta a(0)
resets dta 0
frames dta 0
run start
Assemble with mads reset.asm -o:reset.xex, copy it to a DOS 2.5 disk as AUTORUN.SYS, and boot. Press RESET a few times. The count goes up and the frame counter keeps running, which shows the VBI was reinstalled. The zero-page bytes $CB–$CE are among the few that neither BASIC nor the Assembler Editor uses. The text is written straight into screen memory in the internal character code (dta d'...').
What we learned while testing:
- Don't call the old DOSINI when you install the hook. Our first version called the whole init routine, chain included, at start-up. Under DOS 2.5 that re-ran DOS's initialisation in the middle of loading the AUTORUN file, and the machine hung. The installation code should call only its own setup.
- Take DOSVEC back after chaining. Without the extra store after
noold, the first RESET dropped into the DOS 2.5 menu, because DOS's init had reset DOSVEC. - Only chain to a real routine. Run under atari800's own executable loader instead of DOS, chaining to whatever happened to be in DOSINI sent the emulator into BASIC. If a program might start without DOS, check that the old vector is valid or skip the chain.
6. Doing it properly in a larger program
- Keep all setup that touches OS RAM or hardware registers in one routine (display list, colours, character set, PMBASE and GRACTL, NMIEN for DLIs, POKEY, PORTB banks), and call it from both power-up and DOSINI.
- Use WARMST in shared code to tell power-up from RESET. The OS manual recommends exactly this. A game might restart the level on RESET but show the title screen at power-up.
- To raise MEMLO for your own buffers (a resident handler, for example), set it again in your DOSINI routine, because the OS recalculates it at every reset. Writing Your Own CIO Device Handler shows that pattern.
- If RESET should simply reboot, set COLDST to 1. If it should restart a cartridge, the cartridge's init and run vectors are called again anyway.
Troubleshooting
- RESET goes to the DOS menu: DOS's init reset DOSVEC. Store your address in DOSVEC again after chaining.
- Screen comes back in plain GRAPHICS 0: expected. Rebuild the display in your init or main routine.
- Music or animation stops after RESET: the VBI vectors were zeroed and reinitialised. Call SETVBV again from DOSINI.
- Hangs while the program loads: an init routine is being run at the wrong moment. Don't chain to DOS's init during installation.
- RESET reboots although you didn't ask: COLDST is non-zero, usually because the program jumped away from a boot routine before the OS finished the cold start. Clear it yourself.
Further reading
- Atari, Inc., Operating System User's Manual (1982), Section 7 "System Initialization" and Section 10 "Program Environment and Initialization".
- Ian Chadwick, Mapping the Atari: locations 2–13, 580 and 829–831, and the vectors at 58484 and 58487.
- Avery Lee, Altirra Hardware Reference Manual: the System Reset button and the PIA's reset behaviour.
- On this site: Writing a Bootable Disk Program, AUTORUN.SYS and Auto-Booting Programs, Vertical Blank Interrupts.
Credits
- Picture: The example program after two presses of RESET under DOS 2.5: it has restarted itself and reinstalled its vertical-blank routine each time. — Program authors; screenshot by the site
- Atari Operating System User's Manual (1982), Section 7 System Initialization (coldstart/warmstart procedures) — ksquiggle, 1982
- Mapping the Atari — 2-13 (CASINI, WARMST, BOOT?, DOSVEC, DOSINI), 203-209, 580 COLDST, 829-831 PUPBT1-3, 58460/58466, 58484/58487 — AtariArchives.org
- Altirra Hardware Reference Manual — 2.4 System Reset button, PIA reset behaviour and PORTB pull-ups, System Reset NMI — Avery Lee (Altirra)
