Reset from software
Contents
Causing a Reset in software
- STILL BEING EDITED ***
Note that this code has to run in the I/O processor.
Reset 0 - Soft Reset
A Soft Reset is the simplest to perform. Claim the NMIs, reset the Tube and enter the RESET code. This code will cause a Soft Reset resulting in OSBYTE 253 being set to 0.
.ResetSoft LDA #143 LDX #12:LDY #255:JSR OSBYTE :\ Claim NMIs LDA #&40:STA &D00 :\ Disable NMIs LDA #0:LDX #1:JSR OSBYTE :\ Read machine type TXA:BEQ ResetElk :\ Jump if &00=Electron LDA #&A0:STA &FEE0 :\ Tube Reset LDA #&20:STA &FEE0 :\ Release Tube Reset JMP (&FFFC) :\ Jump to RESET : .ResetElk LDA #&A0:STA &FCE0 :\ Electron Tube Reset LDA #&20:STA &FCE0 :\ Release Electron Tube Reset JMP (&FFFC) :\ Jump to RESET
Reset 1 - PowerOn Reset
A Power-On Reset is only slightly different. Normally, the MOS checks the System VIA interupt bit to test if a RESET is from a power on, so the VIA is reset into a Power-On state.
However, the Electron does not have a System VIA, there is a flag in the System ULA that indicates a power-on state. This causes a problem as this flag read-only, so the only way to cause a Power-On Reset is to do the initial RESET code manually and jump to the rest of it as though the ULA power-on bit has been read.
This code will cause a Power-On Reset resulting in OSBYTE 253 being set to 1.
.ResetPowerOn LDA #143 LDX #12:LDY #255:JSR OSBYTE :\ Claim NMIs LDA #&40:STA &D00 :\ Disable NMIs LDA #0:LDX #1:JSR OSBYTE :\ Read machine type TXA:BEQ ResetElk :\ Jump if &00=Electron LDA #&A0:STA &FEE0 :\ Tube Reset LDA #&20:STA &FEE0 :\ Release Tube Reset LDA #&7F:STA &FE4E:JMP (&FFFC) :\ Turn off SysVIA, jump to RESET : .ResetElk LDA #&A0:STA &FCE0 :\ Electron Tube Reset LDA #&20:STA &FCE0 :\ Release Electron Tube Reset LDA &FFFC:ADC #24:STA &A8 :\ Find RESET+25, note CS from CMP earlier LDA &FFFD:ADC #0:STA &A9 : \ The following is a copy of the first 22 bytes of the Electron RESET code LDA #&40:STA &0D00 :\ Set null NMI routine SEI:CLD:LDX #&FF:TXS :\ Disable IRQs, set to Binary, clear the stack INX:STX &FE00:STX &028D :\ Reset the ULA, set ResetType=PowerOn LDA #&F8:STA LFE05 :\ Set up the ULA : \ Now fake that the ULA is in power-on state LDA #2:JMP (&A8) :\ A='ULA power on', jump into startup code
Reset 2 - Hard Reset
A Hard Reset is the hardest to cause, as it is caused by a test for the physical CTRL key being held down. In a similar way to the Electron Power-On Reset the RESET code has to be threaded through until the CTRL key test, and then entered there in a state as though the CTRL key has been read.
Additional problems are that the Master RESET code is in a sideways ROM and hidden underneath the I/O area, so the memory has to be read indirectly.
This code will cause a Hard Reset resulting in OSBYTE 253 being set to 2.
.ResetHard LDA #143 LDX #12:LDY #255:JSR OSBYTE :\ Claim NMIs LDA #&40:STA &D00 :\ Disable NMIs LDA #0:LDX #1:JSR OSBYTE :\ Read machine type LDY #0:TXA:BEQ ResetElk :\ Jump if &00=Electron LDA #&A0:STA &FEE0 :\ Tube Reset LDA #&20:STA &FEE0 :\ Release Tube Reset LDX #&FF:TXS :\ Reset stack LDX #&0F:STX &FE42 :\ SysVIA PortB=iiiioooo .ResetIO DEX:STX &FE40 :\ Write to I/O latch CPX #&09:BCS ResetIO :\ Loop to set up internal I/O LDA &FFFC:STA &A8 :\ &A8/9=>RESET code LDA &FFFD:STA &A9 LDA &FFDD CMP #&5C:BCC ResetMaster .ResetBBClp LDA (&A8),Y:INY :\ Look for 'ROL zp' CMP #&26:BNE ResetBBClp TYA:ADC &A8:STA &A8 :\ (A8)=>continuation of reset code LDA #0:STA &028D :\ Initialise last BREAK flag ADC &A9:STA &A9 : \ Read keyboard links LDX #&F6 .ResetBBCLinks TXA:PHA LDY #&FF:JSR OSBYTE :\ INKEY-10 to INKEY-2 CPX #&80:ROR &FC :\ Rotate keystate in bit 7 into &FC PLA:TAX:INX:CPX #&FE BNE ResetBBCLinks :\ &FC holds link state, Carry set JMP (&A8) :\ CS=CTRL pressed, jump to RESET code : .ResetElk LDA (&A8),Y:INY CMP #&20:BNE ResetElk :\ Look for JSR INY:INY:LDA (&A8),Y CMP #&08:BNE ResetElk :\ Look for PHP STX &FE00:STX &028D :\ Reset the ULA, set ResetType=0 LDA #&F8:STA LFE05:PHA :\ Set up the ULA, set M=Ctrl Pressed, push NotPowerOn JMP (&A8) :\ CS=CTRL pressed, jump to RESET code : .ResetMaster LDA (&A8),Y:INY :\ Look for JSR CMP #&20:BNE ResetMaster INY:INY:LDA (&A8),Y :\ Check if followed by JMP CMP #&4C:BNE ResetMaster INY:LDA (&A8),Y:STA &F6 :\ (F6)=>reset code in ROM 15 INY:LDA (&A8),Y:STA &F7 .ResetMasterLp2 JSR ResetROMByte :\ Read byte from ROM 15 CMP #&E0:BNE ResetMasterLp2 :\ Look for 'CPX' JSR ResetROMByte :\ Read next byte from ROM 15 CMP #&80:BNE ResetMasterLp2 :\ Look for 'CPX #&80' \ &F6/7 now points to rest of RESET code : LDA #&53:STA &FE8E :\ Write to hardware I/O RESET TRB &0366 :\ Reset VDU 23,16 settings LDX #&FF:STX &FE63 :\ User VIA Port A=output LDA #&CF:STA &FE42 :\ System VIA Port B=ooiioooo LDA #&0D:STA &DC00 :\ Command line = <cr> LDA #&DC:STA &DF05 :\ Point to command line STZ &DF04 STZ &DFDD LDX #(ResetCodeEnd-ResetCode-1) AND &FF .ResetLoop LDA ResetCode,X:STA &100,X DEX:BPL ResetLoop LDA &F7:AND #&40 :\ Test if code is in SROM or I/O area STA &FE34:STA &FC :\ Set memory map according to &F7 LDA #&0F:STA &028E :\ Set keypad SHIFT setting, prepare ROM=15 PHA:SEC:JMP &100 :\ <>0=Not PowerOn, CS=CTRL pressed : .ResetCode STA &FE30 :\ Page in MOS ROM (IRQs are off) JMP (&F6) :\ Jump to RESET code .ResetCodeEnd : .ResetROMByte LDA #&40:STA &FE34 :\ Set memory map LDA (&F6) :\ Read byte manually BIT &F7:BVS ResetByte :\ Exit if in high memory LDY #&0F:JSR &FFB9 :\ Read byte from ROM 15 .ResetByte INC &F6:BNE P%+4:INC &F7 :\ Increment address RTS
See also
- OSBYTE &FD
- OSBYTE &A3,&FD
- [RSTROM] provides OSBYTE 163,253 and *RESET.
- [RESET.src] provides *RESET
Pressing the BREAK key causes a 6502 RESET which jumps via the 6502's RESET vector to the BBC's startup code. Sometimes a program wants to cause a reset to restart the computer.
It is not actually possible to cause a reset without physically pressing the BREAK key or otherwise activating the hardware RESET line. Programs often just jump through the RESET vector to call the startup code, typically with CALL !-4 (or worse, jump directly to the absolute address of the startup code in one particular operating system).
However, this has limitations.
It does not actually reset the computer, as hardware is only reset by the actual hardware RESET line. It leaves hardware in an un-reset state which can cause problems with the startup code that expects to find the hardware already reset by the hardware RESET line.
It hangs second processors as it leaves the two processors out of sync with each other. One has entered its startup code, while the other is still executing its program code.
Also, as the startup code reads the physical state of the CTRL key, just jumping through the RESET vector won't cause a Hard Break unless the user happens to be pressing the CTRL key. A memory-wipe reset can be done by using *FX200,2 or *FX200,3 or a Power-On reset can be performed by resetting the System VIA, but that is more destructive than a Hard Reset as it wipes all memory - not something that may be wanted.
To perform a clean reset, the NMIs must be claimed and the Tube must be reset.
OSBYTE 253 Three types, 0, 1, 2