When you need to set the Address to 0 (for example when always writing/reading a buffer from ramdisk's zero Address) you may use this shortcut:
// reset the Address to 0x000000L
inline void resetadr (){
NDATA = 1; // address mode
NRD = 0; NRD = 1;
NDATA = 0; // data mode
}
Moreover, you can stop writing the Address nibbles after any nibble written :P, thus you may write in only "required" number of Address nibbles (1 or 2 or 3 or 4 or 5 or 6).
That allows to speed up with setting the Address, for example you work with 128 blocks 65kB each, so you must not set all 6 nibbles of the 8MB Address, but only top 2:
// Load the BLOCK Address into the RAMDISK
// a BLOCK is a 65kB large chunk of ram starting at 0x0000
inline void ldadr_block65k (unsigned char addr)
{
NDATA = 1; // address mode
// the trick with zeroing the 24bit address
NRD = 0; NRD = 1;
// now load the 2 nibbles of the BLOCK address
DDRA = 0xFF; // sets Data output
PORTA = (addr >> 4); // 6th nibble of the address - the highest
NWR = 0; NWR = 1; //
PORTA = (addr); // 5th nibble of the address
NWR = 0; NWR = 1;
// 4th, 3rd, 2nd, 1st nibble are zero - here we start to read/write
DDRA = 0x00; // sets Data input
NDATA = 0; // data mode
}
With a standard external HW SRAM buses on DUE or PIC32 or others, you may simply write the 24bit Address with A0=1 (when for example you use A0 address line) and then you read/write all the Data bytes from A0=0. You must not mess with bit-banging the /RD and /WR signals, or with the setting of a 8bit Data port direction - that is done by the MCU's external memory bus for you (EMB on DUE, PMP on PIC32, FSMC on STM32, etc.). You have to set the timing of the /RD and /WR signals as required, however.
For example - a pseudo-code:
//write 24bit Address, A0=1
bus_write(1, 6th_nibble); //the highest
bus_write(1, 5th_nibble);
bus_write(1, 4th_nibble);
bus_write(1, 3rd_nibble);
bus_write(1, 2nd_nibble);
bus_write(1, 1st_nibble);
// write 100000 bytes of Data (w/ auto-increment)
for i=1 to 100000
bus_write(0, data[i]);
next i
or
// read 100000 bytes of Data (w/ auto-increment)
for i=1 to 100000
data[i] = bus_read(0);
next i
When working with blocks (see above):
//write 8bit BLOCK Address (up to 128 BLOCKS each BLOCK 65kB large)
dummy = bus_read(1); //resets Address to zero (0L)
bus_write(1, 6th_nibble); //the highest
bus_write(1, 5th_nibble);
// write 65kBytes of Data (w/ auto-increment)
for i=1 to 65536
bus_write(0, data[i]);
next i
or
// read 65kBytes of Data (w/ auto-increment)
for i=1 to 65536
data[i] = bus_read(0);
next i
You may connect the 8MB Ramdisk to your DUE via DUE's External Memory Bus easily:
With Ax = 1 you write in the 24bit starting "Address"
With Ax = 0 you write/read the Data bytes sequentially from the "Address"
You may use any DUE address line.