10
20
30
40
50 :
60 fname$="NVRAM"
70 DIM mcode% &200
80 BYTEV=&20A:lptr=&A8:OSARGS=&FFDA
90 load%=&FFFF0A86
100 NVMREG =&FC38:
110 NVMDATA=&FC3C:
120 NVMSIZE=128 :
130 NVMRAM =14 :
140 :
150 FOR P=0 TO 1
160 P%=load%:O%=mcode%
170 [OPT P*3+4
180 .go%
190 LDX #2 :\ Two vector bytes to check
200 .switchLp1
210 LDA BYTEV-1,X:CMP newvec-1,X
220 BNE switchChk:DEX:BNE switchLp1
230 .switchChk:PHP
240 :
250 LDA #1:LDX #lptr:LDY #0:JSR OSARGS :\ ptr=>command line
260 LDA (lptr),Y:CMP #13:BEQ switchOn :\ NVRAM<cr> -> turn on
270 INY:LDA (lptr),Y:AND #&DF :\ NVRAM ON -> turn on
280 CMP #ASC"N":BEQ switchOn :\ NVRAM OFF -> turn off
290 :
300 .switchOff
310 PLP:BEQ switchVector:RTS :\ Already off, exit
320 .switchOn
330 PLP:BEQ switchExit:CLC :\ Already on, exit
340 .switchVector
350 LDX #1:PHP:SEI :\ Swap vectors over
360 .switchLp2
370 LDA oldvec,X:BCS switch2 :\ CS=restore vector
380 LDA BYTEV,X:STA oldvec,X:LDA newvec,X :\ CC=Claim vector
390 .switch2
400 STA BYTEV,X:DEX:BPL switchLp2:PLP
410 .switchExit
420 RTS
430 .newvec
440 EQUW newbyte
450 :
460 .newbyte
470 CMP #161:BEQ nvm :\ A=161, read
480 CMP #162:BEQ nvm :\ A=162, write
490 .oldbyte
500 JMP (oldvec)
510 .nvm
520 CPX #255:BEQ nvmsz
530 PHA:TXA:ADC #NVMRAM:CPX #NVMSIZE-NVMRAM
540 CLV:TAX:PLA:BCS nvmov
550 STX NVMREG:CMP #162:BCC nvmrd
560 .nvmwr:STY NVMDATA:CLC:RTS
570 .nvmrd:LDY NVMDATA:RTS
580 .nvmsz:LDY #NVMSIZE-NVMRAM-1:CLC
590 .nvmov:RTS
600 .oldvec :\ Old vector outside loaded binary
610 ]NEXT
620 PRINT"*SAVE ";fname$;" ";~mcode%;" ";~O%;" ";~go%OR&FFFF0000;" ";~load%