-
1st Bit of Progress
08/21/2015 at 15:49 • 0 commentsI find C programming really frustrating! I'm not sure if it's because I'm past it or if C is just to damn abstract but I have real problems with it. Anyway, today, I made a little progress. Originally, my thoughts on how to set the AVRs ports to pass data on to SRAM were based around comparing each bit of a databyte (from the Z80 program bytes in an array) and setting the AVR ports literally bit-by-bit. However, I have found that you can set the entire port with one PORTx = y command! How simple is that. You have to set the port's direction first but that's also easier with DDRx = B11111111 so I have wired up 8 LEDs with resistors on my trusty Arduino UNO and run this:
unsigned char Z80_CODE[]={0x21,0x00,0x00,0x11,0x01,0x00,0x01,0xff,0x1a,0x36,0xaa,0xed,0xb0,0xc3,0x0d,0x00,0xff}; int b = 0; void setup() { // put your setup code here, to run once: DDRD = B11111111; // set PORTD (digital 7~0) to outputs Serial.begin(9600); } void loop() { for (int l = 0; l < sizeof(Z80_CODE); ++l) { for (int i = 0; i < 8; ++i) { Serial.print((Z80_CODE[l] >> i) & 1); b = Z80_CODE[l]; PORTD = b; } Serial.print('\n'); delay (500); } while(true) {} }
It picks up each byte from the array in turn, prints it in binary to the serial port and then sets port D accordingly. There is a delay of half a second just so you can see it working. FAB!OK, Next up is to write functions to set the Data and Address ports and pulse the /CE and /WR lines on the SRAM so that the data is stored.
-
Programming Idea
08/20/2015 at 12:31 • 0 commentsThe AVR will act as the supervisor chip and it will be programmed with static Z80 machine code in an array (possibly in Flash using the PROGMEM variable modifier). Upon startup, the AVR will initialise it's ports for output and bring the Z80's /WAIT line low to suspend it's operation. The AVR will then load the SRAM, byte-by-byte from the array.
After this process is complete, the AVR will set the ports dealing with the data and address buses as inputs, therefore making them high impedance (suggested by Bill Rowe - Thanks). Then, the AVR will bring the Z80's /RESET line low to initiate reset, make the /WAIT line high and finally make the /RESET line high to start the Z80 running the program now in SRAM.
The challenge at the moment is to take each of the characters in the array and load them on to the data bus one bit at a time.
-
Prototyping the ZAViouR
08/20/2015 at 11:41 • 0 commentsSo far, I have had prototype boards fabricated by the excellent www.hackvana.com and have built the first one. I tested it in stages, adding first the Z80 oscillator chip (7404), then the AVR, Then the Z80 and lastly the SRAM. The two other chips are on order and aren't necessary for testing.
I was going to use a cheap eBay serial to USB module for uploading, however, therein lies a problem. Because the Z80 is connected to the same pins that the serial port uses on the AVR, whilst the Z80 is free running, the serial port shows garbage. If I hold the Z80 in reset with the on-board switch, the Arduino IDE freezes and doesn't upload either. Ideas on a post card....
So, to temporarily work around this, I'm programming the AVR with ICSP instead. This works fine since I have dedicated the relevant pins for this purpose.
Whilst thinking about the serial issue, I will be writing a simple Z80 routine to fill a block of SRAM with a number using the LDIR trick:
start: LD HL, DESTINATION LD DE, DESTINATION + 1 LD BC, SIZE - 1 LD (HL), 170 ;Specific binary pattern 1010101010 LDIR
Ah, the memories...Z80 is easy. I also discovered ZMAC and bin2h on Domipheus's site blogging about his TeensyZ80. It's a simple task to write Z80 machine code in a text editor and after compiling with ZMAC, use bin2h to convert the .CIM file produced to an array declaration for use in the Arduino IDE.
const char TEST[] = { 0x21,0x00,0x00,0x11,0x01,0x00,0x01,0xff,0x1a,0x36,0xaa,0xed,0xb0,0xc3,0x0d,0x00};
Excellent! At least I have some progress. Now, I'm looking at ways of converting each of those characters in the array to binary and loading them on to the databus, after which I will make the /CE and /WR lines active (Low) and load the code into the SRAM.