Design challenge: 6502-based EPROM programmer
- Alarm Siren
- Posts: 363
- Joined: 25 Oct 2016
Re: Design challenge: 6502-based EPROM programmer
On the subject of the instruction stream, you'll also need to deal with the fact that the reset process itself is a pseudo-interrupt which will read (and discard) a certain number of bytes before it gets to reading the reset vector. It may be that those reads will all fall outside the FT245 area, in which case no problem, but I suspect that is not the case - however I cannot remember the exact details off hand. There is a thread here on 6502.org somewhere where someone did some research into exactly what happens during reset, so that'll be worth a read.
Want to design a PCB for your project? I strongly recommend KiCad. Its free, its multiplatform, and its easy to learn!
Also, I maintain KiCad libraries of Retro Computing and Arduino components you might find useful.
Also, I maintain KiCad libraries of Retro Computing and Arduino components you might find useful.
Re: Design challenge: 6502-based EPROM programmer
Hi Bill (plasmo) and gang:
Seems you're attempting a type of "blind interface" with the FT245? Not sure if this will help but here's a few basic microcontroller "blind interface" functions where the microcontroller controls the clock, memory, and reset on the 6502 system and uses push() and pull() clock cycle functions to convey instructions and data to/from the 6502 over the data bus;
Basically, a pull() clock cycle turns memory on for a 6502 memory read or write operation while a push() clock cycle turns memory off and allows the microcontroller to supply an instruction or data to the 6502. A clock cycle always starts and ends in the high state. Of course after using the microcontroller & "blind interface" to load RAM or burn a Flash ROM via hex file or X-modem, it can completely disconnect from the 6502 system.
I've been trying to figure out how to implement something similar with the FT245 but "no joy", so far.
I won't bore you or other members with details unless you feel it may help...
Regards...
Seems you're attempting a type of "blind interface" with the FT245? Not sure if this will help but here's a few basic microcontroller "blind interface" functions where the microcontroller controls the clock, memory, and reset on the 6502 system and uses push() and pull() clock cycle functions to convey instructions and data to/from the 6502 over the data bus;
Code: Select all
void cpu_reset(); // **************************************
{ reset_pin = 0; // R65C02 reset sequence *
pull(); // *
pull(); // *
reset_pin = 1; // *
pull(); // *
pull(); // *
pull(); // *
pull(); // *
pull(); // *
push(0x00); // FFFC:00 reset vector lo *
push(0xC0); // FFFD:C0 reset vector hi *
} // **************************************
void Wr_Byte(u16 addr, u8 data) // **************************************
{ push(0xA9); // lda <imm> *
push(data); // " *
push(0x8D); // sta <abs> *
push(addr.lo); // " abs address lo *
push(addr.hi); // " abs address hi *
pull(); // " 6502 write op *
} // **************************************
byte Rd_Byte(u16 addr) // **************************************
{ push(0x4C); // jmp <abs> avoid page boundary *
push(0x00); // " abs address lo *
push(0xC0); // " abs address hi *
push(0xAD); // lda <abs> *
push(addr.lo); // " abs address lo *
push(addr.hi); // " abs address hi *
return pull(); // " return value on bus *
} // **************************************
I've been trying to figure out how to implement something similar with the FT245 but "no joy", so far.
I won't bore you or other members with details unless you feel it may help...
Regards...
Re: Design challenge: 6502-based EPROM programmer
GARTHWILSON wrote:
WDC's 65816 data sheet has a table of exactly what's on the buses in every cycle of every instruction, and applies to the '02 as well, using footnotes to separate the various conditions.
Rule #1 of cycle-by-cycle operation is, every opcode fetch gets followed by another cycle that reads the byte at PC+1 (or the byte at PC is read again if an interrupt is being recognized). Reading the byte at PC+1 is somewhat of a shot in the dark, given that the opcode is still being decoded while the read occurs. But it's a good guess, because often the opcode will be followed by one or more operand bytes.
GARTHWILSON wrote:
Two-cycle instructions like TAX don't care what's on the data bus in the second cycle.
Alarm Siren wrote:
On the subject of the instruction stream, you'll also need to deal with the fact that the reset process itself is a pseudo-interrupt which will read (and discard) a certain number of bytes before it gets to reading the reset vector.
-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
https://laughtonelectronics.com/Arcana/ ... mmary.html
Re: Design challenge: 6502-based EPROM programmer
I breadboard up a FT245 and captured bootstrap program execution with logic analyzer. I used 6502's SYNC output as the reference. I see some noisy signals around the reset that can cause extra read of FT245 FIFO and throw it out of synchronization. This may be an artifact of my breadboard, but to work around that I use a sequence of NOP (0xEA) followed by an illegal instruction 0x3 prior to normal program. This way the reset vector is at 0xEAEA which is still within the memory region of FT245. The illegal instruction 0x3 will execute in one clock so if the instruction stream is offset by one byte due to spurious read, it will realign and fetch the correct instruction after the illegal instruction.
I also use the illegal instruction 0x3 as padding. I find the single byte instruction, INX, needs padding, but STA addr,x instruction does not need padding. Here is a simple program that successfully assembles a "NOP, NOP, JUMP to NOP" loop in RAM and jump into RAM to execute it.
Bill
I also use the illegal instruction 0x3 as padding. I find the single byte instruction, INX, needs padding, but STA addr,x instruction does not need padding. Here is a simple program that successfully assembles a "NOP, NOP, JUMP to NOP" loop in RAM and jump into RAM to execute it.
Bill
Code: Select all
; 11/8/21
;Instructions to be loaded into FT245 that assembles
;toNOP:
; NOP
; NOP
; JMP toNOP
; in RAM and execute it
;STA index by X does not need dummy pad
;INX does need dummy pad
;RAM from 0x8000- 0xBFFF
;FT245 from 0xC000-0xFFFF
.pc02
.org $c000 ;FT245 occupies space from 0xc000-0xffff
NOP ;reset vector plus extra padding
NOP
NOP
NOP
NOP
.byte 3 ;illegal instruction executed in 1 cycle
;for synchronization purpose
LDA #$ea ;NOP instruction
LDX #0
STA $8000,x ;put a small program in RAM
INX
.byte 3 ; dummy instruction for two-cycle INX execution
STA $8000,x
INX
.byte 3
LDA #$4c ;JMP instruction
STA $8000,x
INX
.byte 3
LDA #0
STA $8000,x
INX
.byte 3
LDA #$80
STA $8000,x
JMP $8000
JMP $8000
- BigDumbDinosaur
- Posts: 9425
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Design challenge: 6502-based EPROM programmer
Dr Jefyll wrote:
GARTHWILSON wrote:
WDC's 65816 data sheet has a table of exactly what's on the buses in every cycle of every instruction, and applies to the '02 as well, using footnotes to separate the various conditions.
Page 32 of the attached details the 65C02's behavior.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: Design challenge: 6502-based EPROM programmer
plasmo wrote:
I breadboard up a FT245 and captured bootstrap program execution with logic analyzer.
Code: Select all
push(0x9D); // sta %8000,x
push(0x00); // "
push(0x80); // "
pull(); // "
pull(); // "
TIA. Mike
Last edited by Michael on Thu Nov 11, 2021 10:04 am, edited 2 times in total.
Re: Design challenge: 6502-based EPROM programmer
6502's clock is 7.37MHz, but the RDY input of 6502 is connected to the invert of FT245's RXF#, so it is single-stepping each data provided by FT245. The data sequence for "STA $8000,X" is "0x9D 0x00 0x80" The two other cycles are in $8000 memory region so do not generate read pulses to FT245.
Instead of understanding many different instructions' cycle-by-cycle characteristic, I focus on few instructions like "STA abs,X", "INX", "LDA #imm", and "JMP abs" to build a simple bootloader program in RAM and then jump into RAM to load bigger and better loader that loads the application software.
Bill
Instead of understanding many different instructions' cycle-by-cycle characteristic, I focus on few instructions like "STA abs,X", "INX", "LDA #imm", and "JMP abs" to build a simple bootloader program in RAM and then jump into RAM to load bigger and better loader that loads the application software.
Bill
Re: Design challenge: 6502-based EPROM programmer
plasmo wrote:
6502's clock is 7.37MHz, but the RDY input of 6502 is connected to the invert of FT245's RXF#, so it is single-stepping each data provided by FT245. The data sequence for "STA $8000,X" is "0x9D 0x00 0x80" The two other cycles are in $8000 memory region so do not generate read pulses to FT245.
Instead of understanding many different instructions' cycle-by-cycle characteristic, I focus on few instructions like "STA abs,X", "INX", "LDA #imm", and "JMP abs" to build a simple bootloader program in RAM and then jump into RAM to load bigger and better loader that loads the application software.
Bill
Instead of understanding many different instructions' cycle-by-cycle characteristic, I focus on few instructions like "STA abs,X", "INX", "LDA #imm", and "JMP abs" to build a simple bootloader program in RAM and then jump into RAM to load bigger and better loader that loads the application software.
Bill
(2) Send character to FT245. /RXF goes low to indicate RX char available which takes RDY high.
(3) 6502 reads character from FT245. /RXF goes high after reading the character which takes RDY low again.
I can see how sending 0x9D, 0x00, and 0x80 to the FT245 are accepted by the 6502 but after sending the 0x80 the 6502 RDY is low again. Don't you need to send another character to the FT245 to make /RXF low and take RDY high to allow the 6502 to perform the next clock cycle of the STA $8000,X instruction?
Re: Design challenge: 6502-based EPROM programmer
Hey guys... Is it correct that the STA abs,x instruction is 4 cycles on the W65C02 and 5 cycles on the R65C02 & G65SC02?
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Design challenge: 6502-based EPROM programmer
If you're in full control of the data bus, why not get rid of indexed addressing altogether and just feed the ascending absolute addresses yourself? I know they're four cycles ...
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!
Mike B. (about me) (learning how to github)
Mike B. (about me) (learning how to github)
Re: Design challenge: 6502-based EPROM programmer
Quote:
Hey guys... Is it correct that the STA abs,x instruction is 4 cycles on the W65C02 and 5 cycles on the R65C02 & G65SC02?
What causes you to suspect the WDC chip takes 4 cycles, Michael? I'm not able to run a test ATM, but I'd be astonished to learn of a timing difference between the WDC and Rockwell C02's. I've successfully used both in my KK Computer, whose external circuitry is timing-sensitive in a way that'd almost certainly make any timing discrepancy inescapably obvious.
-- Jeff
Edit: oops, you asked about W65C02, and my datasheet pertains to W65C02S.
PS- good point, Mike B.
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
https://laughtonelectronics.com/Arcana/ ... mmary.html
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Design challenge: 6502-based EPROM programmer
Table 4-1 of the 2/25/20 data sheet says the abs,X addressing mode takes 4 cycles, with footnotes saying, "add 1 cycle if page boundary is crossed when forming address. Add 1 cycle for STA abs,X regardless of boundary crossing," and "Read-Modify-Write, add 2 cycles" (obviously not applying to STA). My Rockwell, Synertek, and GTE Microcircuits books all say 5 also, with no footnotes about adding a cycle for page boundary crossing.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Design challenge: 6502-based EPROM programmer
Michael wrote:
I can see how sending 0x9D, 0x00, and 0x80 to the FT245 are accepted by the 6502 but after sending the 0x80 the 6502 RDY is low again. Don't you need to send another character to the FT245 to make /RXF low and take RDY high to allow the 6502 to perform the next clock cycle of the STA $8000,X instruction?
Received my PC boards from JLCPCB this afternoon (5-day turn around!) and built up a Prog65. I've already found a mistake that requires adding a 74LS10 in the prototype area. Right now it can receive bootstrap program from FT245 and execute simple program in RAM but having problem putting data out on FT245. Picture of it on my bench; putting all 16 channels of logic analyzer plus 2 channel of analog scopes to work, it looks like an open-heart surgery...
Bill
-
kernelthread
- Posts: 166
- Joined: 23 Jun 2021
Re: Design challenge: 6502-based EPROM programmer
plasmo wrote:
Received my PC boards from JLCPCB this afternoon (5-day turn around!) and built up a Prog65. I've already found a mistake that requires adding a 74LS10 in the prototype area. Right now it can receive bootstrap program from FT245 and execute simple program in RAM but having problem putting data out on FT245.
Re: Design challenge: 6502-based EPROM programmer
plasmo wrote:
Michael wrote:
I can see how sending 0x9D, 0x00, and 0x80 to the FT245 are accepted by the 6502 but after sending the 0x80 the 6502 RDY is low again. Don't you need to send another character to the FT245 to make /RXF low and take RDY high to allow the 6502 to perform the next clock cycle of the STA $8000,X instruction?
Since the fifth clock cycle of that STA $8000,x instruction is a 6502 write operation to $8000+x, how does the FT245 reset its /RXF flag? The FT245 won't get a /RD strobe from the 6502 for that fifth instruction clock cycle if the 6502 is writing to $8000+x so /RXF won't get reset high and RDY won't go low. That fifth character that initiated the fifth instruction clock cycle is still sitting in the FT245 unread.
Thank you for your patience. Mike
<added>
ok, wait a minute. after the 6502 performs the write clock cycle to $8000+x it will go back to read at PC in the FT245 region during the next clock cycle and that's when it will read that fifth character from the FT245. So that fifth character could actually be the opcode portion of the next instruction you'd like to send to the 6502. very cool!