Page 1 of 3

Beholder project

Posted: Wed Sep 23, 2015 6:13 am
by beholder
Hi there.
Not sure if that's the right place, but I'm going to post my updates on my 6502 project here.
Hope that's okay :roll:

Got my 65c02 running! did both a "free run" and a "tight loop" using logic ics and the arduino.
https://www.youtube.com/watch?v=YmNbVczc618
https://www.youtube.com/watch?v=qPJ2ZzTwDSk

I have now my arduino monitoring the 65c02 and setting opcodes on the data bus. It also reads the data bus when RW pin is writing.
Haven't connected RAM yet, but hope to get it done soon :)

I wrote a simple program and so far it's working:

LDA #$03 ($A9, $03)
STA $05 ($85, $05)
JMP $0000 ($4C, $00, $00)

The program does the loading and storing, then repeats the jump. When it gets to the jump I have the arduino repeating the jump so it ends on an infinite loop. You can see the A0, A1 and A2 leds light on/off one after the other just like the version using logic ics.

When it sets the STA part I can read the 65c02 trying to store the value on address $05. The address bus shows $05, but the data bus shows $FE instead of $03 (which should be the value stored in the A register, right?) I'm almost sure its $FE... or maybe $7F

Doesn't seems like the 6502 is reseting/interrupting, it moves forward fine and the VectorPull pin doesn't trigger.
My arduino generates the clock, detects vectorpull and RW. Sets data in the dataBus when RW is reading and reads the data bus when RW is writing.
I use the RW pin to switch the 8 digital ports from input to outputs, to create a tristate. So when RW is reading the 8 ports are outputs and can send + or - Voltage. When the RW is writing, the 8 ports are set to input, thus having impedance.

Any ideas why data bus is writing this value?
Thanks for your awesome support!
Playing with a 6502 is addictive :twisted:

Re: Beholder project

Posted: Wed Sep 23, 2015 7:35 am
by BigEd
The only idea I have is that the write is OK but you're looking at the bus at the wrong time, and not seeing the value which actually goes to RAM. By reading back, we'll see what did get written.
That is, assuming you have some RAM connected... perhaps you don't?

Might be a good idea to add a
LDA $05
to see what was written.

(If this is the wrong forum, Garth can move the thread to Hardware)

Re: Beholder project

Posted: Wed Sep 23, 2015 7:40 am
by beholder
Hi BigEd.
You're right, I got some bad timing when reading the data bus.
At the moment I dont have RAM connected. Im using some LEDs and the arduino to see what the 6502 spits out.
Cleaned some code and got that data bus reading bug sorted out
Now it works 100%
I can see the leds, and also read on arduino when the data bus sets the correct value after STA :)

I went ahead and added some more code for fun.
I tried:
INX ($E8)
STX $00 ($86,$00)

That worked as well!
But I did noticed something strange. After a restart, when the 6502 goes through the program again, the X register still hold the old data from before. It accumulates the data over, even when I hold reset for a while :shock:
The X register only gets back to 0 when I turn off the arduino power by disconnecting the USB cable.
Is it normal for the X register to hold data after a reset?

Sounds like another dirty bug I must fix :D
Anyhow, time to go to bed.
Thanks!

Re: Beholder project

Posted: Wed Sep 23, 2015 8:28 am
by BigEd
Good news!

Yes, I think it's normal for reset to leave the registers unchanged. Only the decimal flag and the stack pointer, I think, are actually defined at reset. Maybe some other flags??

Edit: Oops, I am reliably informed that I have this wrong! Checking the datasheets confirms it - unless someone has some evidence to the contrary, we should take it that the stack pointer is not initialised.

Re: Beholder project

Posted: Wed Sep 23, 2015 6:41 pm
by GARTHWILSON
and the interrupt-disable flag

Re: Beholder project

Posted: Wed Sep 23, 2015 9:15 pm
by Dr Jefyll
BigEd wrote:
Yes, I think it's normal for reset to leave the registers unchanged. Only the decimal flag and the stack pointer, I think, are actually defined at reset. Maybe some other flags??
yes, the interrupt-disable flag AND THE PROGRAM COUNTER! :!: :!: :!: :lol:

Re: Beholder project

Posted: Wed Sep 23, 2015 9:18 pm
by BigEd
!!!

Re: Beholder project

Posted: Wed Sep 23, 2015 11:52 pm
by beholder
Hi Guys.
Quick question.

I've added some LEDs to both data and address bus, so I can monitor what the 6502 is doing.
I have all the LEDs negative side connected to the same 1 resistor (1K ohms), then the resistor to ground.
Is that a bad way to do it? should I have a resistor to each LED?
I works fine, but makes me wonder if it should be avoided.

Thanks!

Re: Beholder project

Posted: Thu Sep 24, 2015 12:17 am
by GARTHWILSON
The more LEDs that are turned on, the dimmer they'll be.

Re: Beholder project

Posted: Thu Sep 24, 2015 10:54 pm
by jac_goudsmit
BigEd wrote:
Good news!

Yes, I think it's normal for reset to leave the registers unchanged. Only the decimal flag and the stack pointer, I think, are actually defined at reset. Maybe some other flags??
The stack pointer is undefined after a reset.
Actually S gets decremented by 3 during the reset procedure because it works like an interrupt that doesn't write anything.

===Jac

Re: Beholder project

Posted: Fri Sep 25, 2015 9:17 am
by BigEd
That's true for the NMOS 6502, Jac, but in this case we have a 65C02. So the stack pointer (and other bits) are initialised.
Edit: Oops, I now believe that I have this wrong! Sorry. Checking the datasheets confirms it - unless someone has some evidence to the contrary, we should take it that the stack pointer is not initialised.

Re: Beholder project

Posted: Thu Oct 01, 2015 2:28 am
by beholder
Hi again.
Ran out of cables last week. Got some more cables yesterday and added SRAM to my board.
Have everything connected according to the potpourri schematic.
Not yet working, so im troubleshooting it with my arduino, which lead me to this question:

if I use the opcode LDA($A5) $00, which has 2 bytes of length and 3 cycles... does it mean that I need to tick the 6502 3 cycles?
1 for the opcode LDA, 1 for the address $00 and an extra last one? Like, using a NOP to have the 3rd cycle?
Sorry if that sounds confusing.

So far it looks like the 6502 is resetting at the end of my code instead of falling into an infinite loop.
Here's what I got:

LDA($A9) #$03
STA($85) $00
LDA($A5) $00
JMP($4C) $00 $80 (Jump is at $8000)

the 2nd LDA is what is causing the 6502 t reset.
If I remove it, the code works and it will fall into the infinite loop.

Wondering if you guys might spot an error in my code that might be triggering the reset.

Have 6502 A15 and +v into a NAND gate. Have that output into a second NAND gate + 6502 Phase2 out. Have that output into the SRAM cs(ce) pin.
Got the 6502 R/W connected to SRAM we pin.
Have 6502 A14 connected to SRAM oe pin.
All address and data buses connected.

Will keep testing and see if I can get it to work.
Thanks!

Re: Beholder project

Posted: Thu Oct 01, 2015 2:47 am
by barrym95838
beholder wrote:
... if I use the opcode LDA($A5) $00, which has 2 bytes of length and 3 cycles... does it mean that I need to tick the 6502 3 cycles?
1 for the opcode LDA, 1 for the address $00 and an extra last one? Like, using a NOP to have the 3rd cycle? ...
I believe that all three read cycles are necessary. Cycle one reads the op-code, cycle two reads the address operand, and cycle three reads the contents at that address, so it can be copied to the accumulator.

Mike B.

Re: Beholder project

Posted: Thu Oct 01, 2015 2:57 am
by beholder
Thanks Barry.

So does that means that I need a NOP there?
I've added a NOP and it made my code kinda work... it doesn't reset anymore. It goes into the loop.

LDA #$03
STA $00
LDA $00
NOP
STA $00
JMP $8000

Now, the weird thing is that on the second STA I can see the values in the data bus when the 6502 is outputting.
Instead of being the value #$03 it's the NOP opcode :(

Thanks for the feedback!

Re: Beholder project

Posted: Thu Oct 01, 2015 3:17 am
by barrym95838
beholder wrote:
... Now, the weird thing is that on the second STA I can see the values in the data bus when the 6502 is outputting.
Instead of being the value #$03 it's the NOP opcode :( ...
Hmm ... is it possible that your Arduino code is buggy? I suspect that there are some Arduino users who could check it for you and give you some friendly advice, if you're brave enough to upload it for them to see.

Mike B.