> EELoad/src v2.11 " Load file to AT28C256 EEPROM ) Syntax: EELOAD |<@> (: 21 v2.10 27-Nov-2015 JGH: rewritten, tidied up , PH runs on Electron and non-Electron, corrected error messages, ZF write tests version byte so doesn't trash ROM entry point. dF v2.11 23-Jan-2016 JGH: Changes to small screen MODE on Electron. n: x! mcode% &200:load%=&FFFF0900 7OSARGS=&FFDA:OSFILE=&FFDD:OSBYTE=&FFF4:OSWRCH=&FFEE lptr=&A8:buf=&A8:dst=&AA 2rambuf=&2000 : Use &2000-&5FFF as file buffer ,nbytes=64 : Write 64 bytes at a time ver$="2.11" : P=0 1 P%=load%:O%=mcode% [OPT P*2+4 .errSyntax 9BRK:EQUB 220:EQUS "Syntax: EELOAD |@ ":BRK : .exec% ;LDA #0:LDX #1:JSR OSBYTE :\ Read machine type TXA:BNE InitNotElectron =LDA #&05:STA ROMSEL+1 :\ Use Electron ROMSEL "@DEC ROMTABLE+1 :\ Use Electrom ROM table ,.InitNotElectron 6: @JLDA #1:LDX #lptr:JSR OSARGS :\ Get command line, Y=0 from above J7LDA (lptr),Y:CMP #13:BEQ errSyntax :\ No parameters T: ^.\ (lptr),Y => filename, skip past to h.\ ---------------------------------------- r>DEY :\ Prepare for next INY |.SkipToSpace INY:LDA (lptr),Y :CMP #"!":BCS SkipToSpace :\ Step past filename >DEY :\ Prepare for next INY .SkipSpace INY:LDA (lptr),Y 8CMP #" ":BEQ SkipSpace :\ Step past spaces  \ --------------------- 3LDA (lptr),Y :\ Get 4CMP #"0":BCC errSyntax :\ <'0' - error ?CMP #"9"+1:BCC decnum :\ '0'-'9' - decimal digit 9CMP #"A":BCC errSyntax :\ >'9' <'A' - error  #&DF 4CMP #"G":BCS errSyntax :\ >'F' - error &NSBC #6 :\ Convert hex digit to offset from '9' 0 .decnum :9 #15:TAX :\ Convert to binary DCCMP #1:BNE romnumber :\ Not 1, don't check for 1x NAINY:LDA (lptr),Y :\ Look for a second digit XKCMP #"!":BCC romnumber :\ Single digit, use as decimal number b=CMP #"0":BCC errSyntax :\ Can only be '10'-'15' lCMP #"6":BCS errSyntax v9 #15:ADC #10:TAX :\ Convert to binary .romnumber B :\ X=ROM number to write to : C\ First, test the device is writable before we overwrite memory C\ ------------------------------------------------------------- :LDA &F4:PHA :\ Save current ROM KPHP:SEI :\ Prevent accidently calling EEPROM CJSR SelectRom :\ Page in the requested ROM ALDA &8008: #&AA:TAX:STA &8008 :\ Try toggling version byte MNOP:CMP &8008:BEQ testOK :\ Written immediately, it must be RAM BLDA &8008:CMP &8008 :\ Try two successive reads JBNE testEEP :\ If not the same, probably EEPROM DBRK:EQUB 135:EQUS "Device is ROM":BRK :\ Error 135='Not SRAM'  .testEEP  HLDA &8008:CMP &8008:BNE testEEP :\ Loop until two identical reads JCPX &8008:BEQ testOK :\ Settled at correct data, it's ok  FBRK:EQUB 134:EQUS "Device is locked":BRK :\ Error 134='ROM in use' * .testOK 4>TXA: #&AA:STA &8008 :\ Restore original value > .testOKlp HHLDA &8008:CMP &8008:BNE testOKlp :\ Loop until two identical reads RH\ Need to wait until data settles as while it is settling the EEPROM \G\ returns status data instead of its actual contents. Need to avoid fL\ accidently trying to execute that status data via a sideways ROM call. p: z\ Now load the file \ ----------------- KLDY #0:LDA (lptr),Y :\ Check first character of filename 8CMP #"@":BNE loadfile :\ Not *EELOAD @... CINY:LDA (lptr),Y :\ Check for following space ICMP #" ":BEQ copyimage :\ *EELOAD @ , use image in RAM  .loadfile OLDA lptr+0:STA file+0 :\ Copy filename pointer to OSFILE block LDA lptr+1:STA file+1 LDA ROMSEL+1 @CMP #&05:BNE loadfile2 :\ Not Electron, continue ALDA #132:JSR OSBYTE :\ Read top of user memory BCPY #&60:BCS loadfile2 :\ Small screen , continue DLDA #22:JSR OSWRCH :\ Change to a small screen LDA #7:JSR OSWRCH .loadfile2 #LDX #file 255:LDY #file 256 $7LDA #255:JSR OSFILE :\ Load the file .: 85\ Now program the device from the image in memory B5\ ----------------------------------------------- L.copyimage VLDA #0:LDX &F4 ` .ROMTABLE jCSTA &2A1,X :\ Remove ROM from ROM table tSTA buf+0:STA dst+0 ~rambuf at &2000 3LDA #&80:STA dst+1 :\ dst=&8000  .proglp1  LDY #0  .proglp2 8LDA (buf),Y:STA (dst),Y :\ Copy to EEPROM ;INY:CPY #nbytes:BNE proglp2 :\ Loop for 'nbytes' : .\ Now check the data has written correctly .\ ---------------------------------------- LDX #0:LDY #0  .proglp3 FLDA (dst),Y:CMP (dst),Y :\ Read twice to see if matches GBNE proglp3 :\ Keep testing until it matches  JCMP (buf),Y :\ Has it settled to correct value? EBEQ progmatch:INX :\ If it doesn't match, inc. X .progmatch (KINY:CPY #nbytes:BNE proglp3 :\ X now holds number of differences 2TXA:BEQ write_ok LDA #nbytes:ADC dst+0:STA dst+0 :\ Update dest. address LDA #0:ADC dst+1:STA dst+1 KCMP #&C0:BNE proglp1 :\ Keep going until end of ROM space : "\ All done, restore and return "\ ---------------------------- 6PLP :\ Restore IRQs 5PLA:TAX :\ Restore ROM : .SelectRom ALDA #12:JSR SelectRom2:TXA :\ Electron ROM pre-select .SelectRom2  STA &F4  .ROMSEL STA &FE30:RTS :  .file ")EQUW 0 :\ Filename ,3EQUD &FFFF0000+rambuf :\ Address to load to 68EQUD 0:EQUD 0:EQUD 0 :\ 0=use specified address @ EQUS ver$ J]: TE" *SAVE EELOAD ";~mcode%;" ";~O%;" ";~exec%&FFFF0000;" ";~load%