6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Sep 25, 2024 2:28 am

All times are UTC




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Mon Jun 23, 2014 8:42 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
BigDumbDinosaur wrote:
BigEd wrote:
Note that the original 6502 and the 65816 both honour RDY only during read cycles.

Actually, the 65C816 stops when RDY is asserted on both read and write cycles.

How odd - the current datasheet does indeed say that on p54. I checked the first doc I found - this document (Programmer's manual, WDC, 2007) or something very like it, before I wrote what I did.

Thanks for the correction. The moral is: don't believe everything you read even in a recent WDC document. Plan for the worst!

Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 6:56 pm 
Offline
User avatar

Joined: Sun Oct 13, 2013 2:58 pm
Posts: 491
Location: Switzerland
Hi lordbubsy,

I think you have a serious memory bandwidth problem. 320 Pixels aka 320 bytes per line and 400 display lines means that you consume more than 50% of the memory bandwidth for your VGA signal. As you are stealing the cycles from the CPU during VGA display you more or less block the CPU for 50% of the time. Worse during the display of a line, that is during 320*67.8ns which is more than 21usec, you completely stop the CPU from doing virtually anything. So your computer performance will be that of a 6502 running at 3.8MHz. I'm convinced nyef is right. You need to create a 16-bit data path from RAM to the FPGA. I hope you have some pins (you need at least 9) left on the FPGA then you could piggy-pack a second AS6C4008 onto the existing SRAM and connect the the data bus and the /CE of the SRAM to the additional Pins of the FPGA. Use A0 from the CPU to select between the existing and the piggy-packed SRAM and then you can nicely use the old and proven interleave access to RAM (during PHI1 VGA reads and during PHI2 memory belongs to the CPU).

In fact that is what I did about twenty years ago, when a 4MHz G65SC816 was the fastest I could get hold on but Video Bandwidth required a throughput of about 7Mbyte with just some GALs and it works perfect.

Cheers

Peter


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 7:33 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8395
Location: Midwestern USA
BigEd wrote:
BigDumbDinosaur wrote:
BigEd wrote:
Note that the original 6502 and the 65816 both honour RDY only during read cycles.

Actually, the 65C816 stops when RDY is asserted on both read and write cycles.

How odd - the current datasheet does indeed say that on p54. I checked the first doc I found - this document (Programmer's manual, WDC, 2007) or something very like it, before I wrote what I did.

Thanks for the correction. The moral is: don't believe everything you read even in a recent WDC document. Plan for the worst!

Actually, your mistake is completely understandable, as the Eyes and Lichty manual doesn't correctly clarify this with the '816. They discuss the 6502 and 65C02 but neglect to mention that the '816 will respond to RDY on a write cycle.

Also, according to E-mail that I have exchanged with Bill Mensch on the '816's response to ABORTB, this statement on page 446 in the Eyes and Lichty manual is incorrect:

    The ABORT’ input pin, when it is asserted, causes the current instruction to be aborted. Unlike an interrupt, none of the registers are updated and the instruction quits execution from the cycle where the ABORT’ signal was received.

As stated, the computational results of the instruction are not saved, but the instruction executes to completion—it does not terminate.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Last edited by BigDumbDinosaur on Mon Jun 23, 2014 7:42 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 7:35 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8395
Location: Midwestern USA
cbscpe wrote:
Hi lordbubsy,

I think you have a serious memory bandwidth problem...

The use of 55ns RAM is also a limiting factor, as it effectively prohibits clcking the '816 much faster than about 10 Mhz without resorting to wait-stating memory accesses.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 7:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
What does seem odd is that changing the timing of RDY got things to work a bit better, even though we now think writes are not non-stalling.

If the CPU can stall on a write, that adds a requirement that the DMA is able to do a read from the RAM even when the CPU is holding RnW low. Clearly the RnW for the RAM needs to be muxed between two sources: the VGA system and the CPU.

Ed


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 8:45 pm 
Offline
User avatar

Joined: Sun Oct 13, 2013 2:58 pm
Posts: 491
Location: Switzerland
The 65C816 will definitively stall on writes when RDY is pulled low. And it does not matter if he is in a series of writes (pushing a return address), he will just continue with the task he was doing when RDY is released again. That MARC-2 is crashing when accessing IO (UART) is for me like an indication, that the same location is accessed twice. That is the CPU is halted but read and/or write and/or chip-select enable signals are created twice for the same memory address the CPU is trying to access. For a memory this does not impose any problem. On IO devices this is not ok. Pulling RDY low is not enough, you must make sure that during this time you do not select a device. Just an idea what could be the problem. I have not gone through the ABEL files in detail so far (by the way are those attached in the first post the current ones?)

Peter


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 8:47 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
My best guess is still the pipelining - RDY affects the following cycle.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 8:57 pm 
Offline

Joined: Wed Sep 11, 2013 8:43 pm
Posts: 207
Location: The Netherlands
cbscpe wrote:
I think you have a serious memory bandwidth problem...
I know, the original plan was for composite video which only needs one byte per PHI2 clock cycle. I'm certainly not willing to sacrifice the '816 CPU time for VGA.

cbscpe wrote:
You need to create a 16-bit data path from RAM to the FPGA.
Let's see if I understand what you're suggesting:

CPU to SRAM, even addresses are used in one SRAM and odd addresses in the other SRAM?
CPLD to SRAM, read 16 bit at once while both SRAM's are selected. How could I select both addresses at the same time while reading with the CPLD?

cbscpe wrote:
I hope you have some pins (you need at least 9) left on the FPGA
I've got 16 unused, and it's actually a CPLD XC95288XL.

cbscpe wrote:
(during PHI1 VGA reads and during PHI2 memory belongs to the CPU)
That's indeed the plan, regardless of choosing to need one or two bytes per PHI2 clock cycle. I'm also considering 16 colors or using composite video. But for now I'd like to understand the 16 bit data path option.

The irony is that I need to write each line twice to get 200 lines per screen. :-/

BigDumbDinosaur wrote:
The use of 55ns RAM is also a limiting factor, as it effectively prohibits clcking the '816 much faster than about 10 Mhz without resorting to wait-stating memory accesses.
I think you're referring to 18.18MHz / 2? During reset the ATMega1284P writes to the SRAM with 14.7456MHz, and reading from it for the VGA happens also at that speed.



To pursue the problem I have with stopping the CPU:

BigEd wrote:
Could you put it into an idle loop and somehow see that it doesn't crash?
I made a simple loop which toggles a VIA pin to visually check if the computer keeps on running.

Dividing the problem into a few smaller ones, I'll first try to halt the system and release it after a given time, and see if the program keeps on running.

BigEd wrote:
Do you have means of diagnosing what happens when the CPU crashes?
with the analyzer I'll monitor A0, D0, PHI2, a VIA pin, RDY and R/W.

I made a 10 bit counter to test with PHI2.

Code:
DCLK      = [DIV9..DIV0];

when DIV9 then PHI2 = 1
  else         PHI2 = DIV3;


This will halt the clock and release it alternatively. I've tested this with the VIA toggle program, which seems to have no problem with it.
Attachment:
1.png
1.png [ 62.56 KiB | Viewed 1137 times ]








Now that it's clear that I don't have to wait three cycles before I can use the bus, I'm trying to halt the system using RDY. RDY is synced with the rising edge of PHI2. However, that works for about two seconds.

Code:
RDY.clk = PHI2;
when DIV9  then RDY := 0
  else          RDY := 1;

Attachment:
4.png
4.png [ 60.42 KiB | Viewed 1137 times ]

What could I try next?

_________________
Marco


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 9:10 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
I wonder if RDY is changing too quickly on the phi2 clock edge. It's sampled by the CPU on phi2 so it should be stable shortly before and remain stable for a little while.

Are you able to clock out RDY on the opposite edge?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 23, 2014 10:59 pm 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
lordbubsy wrote:
cbscpe wrote:
You need to create a 16-bit data path from RAM to the FPGA.
Let's see if I understand what you're suggesting:

CPU to SRAM, even addresses are used in one SRAM and odd addresses in the other SRAM?
CPLD to SRAM, read 16 bit at once while both SRAM's are selected. How could I select both addresses at the same time while reading with the CPLD?


When fetching for the CPU, CPU A0 indicates which SRAM output-enable to trigger, along with which set of 8 data lines to use. When fetching for the VGA, both SRAM output-enables get triggered, and all 16 data lines get used. You feed the same address (A1 and up) to both SRAMs. Similar logic for writing to RAM as well.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 24, 2014 3:54 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8395
Location: Midwestern USA
BigEd wrote:
I wonder if RDY is changing too quickly on the phi2 clock edge. It's sampled by the CPU on phi2 so it should be stable shortly before and remain stable for a little while.

Specifically, the '816 timing diagram indicates that RDY is sampled on the fall of the clock. The '816 halts with all buses held in their current state (ditto for RWB) and stays that way until RDY is released. This smacks of a basic timing problem.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 24, 2014 6:56 am 
Offline
User avatar

Joined: Sun Oct 13, 2013 2:58 pm
Posts: 491
Location: Switzerland
lordbubsy wrote:
cbscpe wrote:
You need to create a 16-bit data path from RAM to the FPGA.
Let's see if I understand what you're suggesting:

CPU to SRAM, even addresses are used in one SRAM and odd addresses in the other SRAM?
CPLD to SRAM, read 16 bit at once while both SRAM's are selected. How could I select both addresses at the same time while reading with the CPLD?


As far as I read your ABEL equations the CPU databus and the RAM databus are separate, that is the data-pins of the CPU or not connected to the data-pins of the RAM. What you need to do is change mapping of CPU addresses (CA0...CA15) to your RAM addresses. Today you map CA0...CA15 to RA0..RA15, now you need to map CA1...C15 to RA0...RA14 of both RAMs. And the latched CA16..CA19 to RA15..RA18 of both RAMs. So both RAMs share addresses A1...A19 of the CPU (and VGA controller) and the A0 (even/odd) selects which RAM is holding the correct byte. CA0 will now be a select signal for a 2:1 8-bit wide MUX with the inputs being the now 16-bit wide data of your RAM, this is just for reads. So when the CPLD reads from the RAM (regardless whether it is reading video data or passes data to the CPU) it always reads 16-bits but only one depending on CA0 is sent to the CPU. On writes you just send the same data of the CPU to both RAMs but only assert /WE resp. /CE of one of them (again using A0 to decide, make sure you take the same as when reading :) ). As you now read 16-bits at a clock rate of 7.6MHz you have enough video data for a complete PHI2 cycle. Of course you need to latch all 16-bits internally and use another 8-bit wide 2:1 MUX to output the lower or upper byte to the RAMDAC, here you can use PHI2 as the select signal. So the difference to your current setup is that the data-path between RAM and CPLD is 16-bit.

Peter


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 24, 2014 1:38 pm 
Offline

Joined: Wed Sep 11, 2013 8:43 pm
Posts: 207
Location: The Netherlands
cbscpe wrote:
That MARC-2 is crashing when accessing IO (UART) is for me like an indication, that the same location is accessed twice. That is the CPU is halted but read and/or write and/or chip-select enable signals are created twice for the same memory address the CPU is trying to access. For a memory this does not impose any problem. On IO devices this is not ok.
OK, I just tried a test program which doesn’t use I/O. The program toggles A12 0.7s high and 0.7s low.
Attachment:
no-io.png
no-io.png [ 58.39 KiB | Viewed 1093 times ]

You can see that RDY toggles at ca. 2.2s high and 2.2s low. At the third time, A12 goes mad.

BigEd wrote:
My best guess is still the pipelining - RDY affects the following cycle.
OK, but I'm still don't know what I could do about it.

BigEd wrote:
I wonder if RDY is changing too quickly on the phi2 clock edge. It's sampled by the CPU on phi2 so it should be stable shortly before and remain stable for a little while.

Are you able to clock out RDY on the opposite edge?


This is the ABEL code responsible for RDY:
Code:
RDY.clk = PHI2;
when DIV25  then RDY := 0
  else           RDY := 1;


I've tried with PHI2 on the rising edge, falling edge and even on a quarter period.
Attachment:
half-phi2.png
half-phi2.png [ 16.48 KiB | Viewed 1093 times ]

This is the little test program:

Code:
*   =   $c000
init      ldx #0
-      lda start2,x
      beq start1
      sta $1000,x
      inx
      bne -

start1      lda #$1
loop0      ldy #$ff
loop1      ldx #$ff
loop2      dex
      bne loop2
      dey
      bne loop1
      sec
      sbc #1
      bne loop0
      jmp $1000


start2      lda #$1
loop3      ldy #$ff
loop4      ldx #$ff
loop5      dex
      bne loop5
      dey
      bne loop4
      sec
      sbc #1
      bne loop3
      jmp start1
      !byte 0

*   =   $fffa
!word      $d000      ; nmi vector
!word      $c000      ; reset vector
!word      $d000      ; irq vector




nyef wrote:
When fetching for the CPU, CPU A0 indicates which SRAM output-enable to trigger, along with which set of 8 data lines to use. When fetching for the VGA, both SRAM output-enables get triggered, and all 16 data lines get used. You feed the same address (A1 and up) to both SRAMs. Similar logic for writing to RAM as well.
Still not clear how to get 16 bit at once, I guess I'm not Vulcan enough :oops:

cbscpe wrote:
As far as I read your ABEL equations the CPU databus and the RAM databus are separate, that is the data-pins of the CPU or not connected to the data-pins of the RAM. What you need to do is change mapping of CPU addresses (CA0...CA15) to your RAM addresses. Today you map CA0...CA15 to RA0..RA15, now you need to map CA1...C15 to RA0...RA14 of both RAMs. And the latched CA16..CA19 to RA15..RA18 of both RAMs. So both RAMs share addresses A1...A19 of the CPU (and VGA controller) and the A0 (even/odd) selects which RAM is holding the correct byte. CA0 will now be a select signal for a 2:1 8-bit wide MUX with the inputs being the now 16-bit wide data of your RAM, this is just for reads. So when the CPLD reads from the RAM (regardless whether it is reading video data or passes data to the CPU) it always reads 16-bits but only one depending on CA0 is sent to the CPU. On writes you just send the same data of the CPU to both RAMs but only assert /WE resp. /CE of one of them (again using A0 to decide, make sure you take the same as when reading :) ). As you now read 16-bits at a clock rate of 7.6MHz you have enough video data for a complete PHI2 cycle. Of course you need to latch all 16-bits internally and use another 8-bit wide 2:1 MUX to output the lower or upper byte to the RAMDAC, here you can use PHI2 as the select signal. So the difference to your current setup is that the data-path between RAM and CPLD is 16-bit.
Thanks for your thorough explanation! I think I got it now for 98%. This could work, but first I have to get working: reading a byte while PHI2 is low.

I'll keep on trying different timings. Perhaps getting BE involved?

_________________
Marco


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 24, 2014 1:43 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Hmm, can you show just a half-dozen clock cycles centered around the leading edge of that third RDY pulse?


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 24, 2014 2:05 pm 
Offline

Joined: Wed Sep 11, 2013 8:43 pm
Posts: 207
Location: The Netherlands
BigEd wrote:
Hmm, can you show just a half-dozen clock cycles centered around the leading edge of that third RDY pulse?


Sure:
This is a little bit zoomed in at the rise of the third pulse.
Attachment:
6.png
6.png [ 63.65 KiB | Viewed 1088 times ]


This is what you asked.
Attachment:
7.png
7.png [ 58.8 KiB | Viewed 1088 times ]


This is the rise of the second pulse.
Attachment:
8.png
8.png [ 62.09 KiB | Viewed 1088 times ]

_________________
Marco


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: