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