PDA

View Full Version : Homemade project: Z80 interfacing MS Excel, via 82C55 through the Parallel



ygg-it
April 13th, 2009, 09:16 AM
Hello!
I'm building a Z80 interfacing a PC IBM MS Excel via PIO 8255 through the Standard Parallel Port

Here some details:

(#) Homemade Z80 training board

(#) PIO interface: 82C55 in Mode 0, Control Code: 98H
- Port A : input 4 bit
- Port B : output 4 bit
- Port C (hi): 1 bit input handshaking
- Port C (low): 1 bit output handshaking

(#) PC Interface: printer port SPP (Standard Parallel Port - 25 pin)

(#) IBM PC frontend GUI Interface: MS Excel, VBA programs

(#) IBM PC laguage: Visual Basic 6

(#) Z80 frontend interface: hexadecimal keyboard, 6 digits hex displays, assembly routines

(#) Z80 language: machine code/assembly

(#) DLL needed for Windows XP: INPOUT32.DLL

(#) Electronic HW protection: optoisolator (NEC PS2502) between 82C55 and the IBM PC

(#) Cable interface: 25 pin Parallel Printer Flat Cable.

pin 02 : PC_Out / Z80_In - Data Bit 0 (680 ohm-5ma)
pin 03 : PC_Out / Z80_In - Data Bit 1 (680 ohm-5ma)
pin 04 : PC_Out / Z80_In - Data Bit 2 (680 ohm-5ma)
pin 05 : PC_Out / Z80_In - Data Bit 3 (680 ohm-5ma)
pin 06 : PC_Out / Z80_In - Nibble Mode Handshake Signal (680 ohm-5ma) (Host_busy or Ack_to_host)
pin 07 : PC_Out - 5V Optocoupler # 1 PowerSupply (4700 ohm-5ma)
pin 08 : PC_Out - 5V Optocoupler # 2 PowerSupply (4700 ohm-5ma)
pin 09 : PC_Out - 5V Optocoupler # 3 PowerSupply (4700 ohm-5ma)
pin 16 : PC_Out - 5V Optocoupler # 4 PowerSupply (4700 ohm-5ma)
pin 17 : PC_Out - 5V Optocoupler # 5 PowerSupply (4700 ohm-5ma) (!HW inverted)
pin 15 : PC_In / Z80_Out - Data Bit 0
pin 13 : PC_In / Z80_Out - Data Bit 1
pin 12 : PC_In / Z80_Out - Data Bit 2
pin 10 : PC_In / Z80_Out - Data Bit 3
pin 11 : PC_In / Z80_Out - Nibble Mode Handshake Signal (Ack_to_host or Host_busy ) (!HW inverted)
pin 18 : Return Optocoupler Ground (Common Gnd)
...
pin 25 : Return Optocoupler Ground (Common Gnd)


(#) Communication Protocol: bi-directional one byte (8 bit data tranfer) by sending 2 nibbles (4-bits) of information in two data transfer cycles.
The software must read the Handshake Signal and then manipulate the bits in order to get a correct byte.
The major advantage of this protocol is the ability to operate on all PCs that have a parallel port.
But there is a severe limitation of bytes per second for this type of data transfer. I'm also thinking about a simple error-checking scheme

(#) Error detection and Error correction scheme: I will probably choose the Repetition codes in FEC mode (forward error correction). The 8 bit word is sent three number of times. The receiver choose the value that occurs more frequently. This allows the receiver to detect and correct errors without the need to ask the sender for additional data. Repetition codes generally offer very poor data transfer rate but is very easy to implement.

The HW is done and working 100% :p , now i'm writing the protocol and the programs/routines for both the PC (in Visual Basic) and Z80 (Assembly). :sneaky:
First project: download into Excel the Z80 ROM data content.
Z80 BOARD INTERFACE (http://www.flickr.com/photos/32893012@N08/3435033943/)

Please let me know any yr comment if you like. ;)

ygg-it
April 14th, 2009, 03:28 PM
From Z80 to PC: data transmission successfull !:p:p:p

With both the SW codes (assembly and VBA) not optimized at all, I got a transfer rate of 0.21KB/sec ! (or 220 byte per second):rolleyes:

For me is enough for my purposes since I prefer now to have an easy clean code and error-free transmission...

barythrin
April 14th, 2009, 04:05 PM
Good work. So I'm curious, do you have a project in mind that would utilize this or are you more interested in showing the technique in how one could make a simple GUI/terminal out of an application like that?

- John

ygg-it
April 19th, 2009, 02:41 PM
Hi! The main project was and remains to build a complete Z80 clone training machine for pure fun and personal satisfaction.
One important thing missing was a true interface with the external world.
It is easy to work via VBA inside Excel.
Here the front-end LTP intarface I built.

I'm still continuing to program both the machines. I'm on this project since months (you may see in my album the back of the veroboard to get an idea) but now close to the end. The electronic part is done and working.

:p

ziloo
June 5th, 2009, 02:30 AM
Hello ygg,

"It is easy to work via VBA inside Excel...."

Would you please provide more information about implementing
VBA (is that Visual Basic?) inside Excel?

Thank you

ziloo

Dr_Acula
June 5th, 2009, 07:07 AM
That looks fun.

I'm happily in the middle of Z80 assembly myself, building up a library of useful routines like math and strings.

Is the board wirewrap on the underside?

RickNel
June 6th, 2009, 05:54 AM
Very impressive work!

Another possible use for this parallel interface would be to provide debug access to Z80 S-100 machines at hardware level (see thread on Front Panel emulators, also various threads on comp.os.cpm)

Have you thought about how either your Z80 board (quite like a Front Panel or monitor device) or your PC-based interface could connect to a standalone z80 machine via the parallel port, and take read/write control? A 40-line data-monitor-style patch from your Z80 CPU to the CPU socket on the target machine might be enough? Or not? Probably would require at least a special boot EPROM to set up the parallel port and bypass normal boot on the target.

MikeS
June 6th, 2009, 11:48 PM
Hi! The main project was and remains to build a complete Z80 clone training machine for pure fun and personal satisfaction.
One important thing missing was a true interface with the external world.
It is easy to work via VBA inside Excel.
Here the front-end LTP intarface I built.

I'm still continuing to program both the machines. I'm on this project since months (you may see in my album the back of the veroboard to get an idea) but now close to the end. The electronic part is done and working.

:p
---
Great stuff, but we want to see some code!
;-)

kiyotewolf
June 13th, 2009, 01:01 AM
To get to the programming window (Macro Editor as it's called), press ALT -F11 on a blank Excel spreadsheet page.

Click "INSERT - module"

Click "INSERT - userform"

There is an XML styled connection window that shows your SHEET1.XLS and such. The ""userform1 & ""module1 are now a part of your spreadsheet.

Double click in that XML window on the module you just created, and you will bring up the code listing (which would be blank at this point) for the module.

Type this into the editor.

Private Sub Auto_Open()
Load Userform1
Userform1.Show
END SUB

Now, double click on the XML window for Userform1.

You will see ""Toolbox.

Click on the tool key for a button. The hover msg window calls it a ""Command button.

Click and drag a button onto the graph paper like area of the userform. Click once and wait a half second, and you can type to change the name of the txt listed in the button.

Fill the button in like this. [SAY HELLO]

Now click on the graph paper area to de-select the button.

Now, quickly double click on the button you just made.

It auto-generates a line of code which is instigated when the button is clicked.

Private Sub CommandButton1_Click()

End Sub

Obviously, the name ""COMMANDBUTTON1 is the button's name, and the _Click() is the delimiter which means you want to act on the action of clicking. There are other actions of course.

If you have your MS.Office install CD, make sure it's handy. If you type in keywords, you press the F1 key, it will try to attempt to install the programming help file if it's not already installed. WARNING Find it just in case. Sometimes it wants crap you don't really need, but it's better to let it install it anyways.

Type in msgbox, like this.

Private Sub CommandButton1_Click()
msgbox
End Sub

Put the cursor over the msgbox keyword and press F1.

You get an example (after clicking the hyperlink to the example).

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action.
End If

Copy that between the existing code.

Private Sub CommandButton1_Click()


Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action.
End If
End Sub


Now, press the [> button on the top menu to run.

Click the [X] to stop the program and return to the editor.

NOTICE: If you ever get to where it won't run, either press the [] stop button, or just double click on the XML window on your userform. Sometimes, it gets into a mode where the toolbox window is invisible. Usually at those times, it will try to ask you which routine to run and not do anything. Just double click a userform and then press the [> button.

Now, close the editor, close Excel, say YES to save changes, and re-open the Excel document.

It will ask you ENABLE MACROS? Unfortunately, this is almost impossible to avoid dealing with unless you have a special product id key validator that you can only get from someplace fancy I don't know about.

If it doesn't run, and doesn't ask you to enable macros, check your security settings and try again.

Because of the code in the module, the Auto_Open stuff, your code should run once it's been given permission. (Enable macros)



Other things, such as TextBoxes, you deal with like this.

Make a textbox, it will be called TextBox1.

Private Sub CommandButton1_Click()
textbox1.value="hello world"
end sub

That's all there is to it.

When you use TextBoxes for things like fancy word entry, create the textbox, name it, by changing it under the properties, and do things like this as follows.

Double click in properties ~ enterkeybehaviour ~ TRUE
Also..

Font ~ select one and it stays on that font
Multiline ~ true or false ~ depends on the usage
TabKeyBehavior ~ true or false ~ your choice ~ enables or disables tab characters within the textbox.. if false, you will tab to the next object in the userform. If true, you will tab over within the textbox as if typing in Notepad.
TabIndex ~ number your userform pieces to TAB in a certain order when moving around your userform by keyboard
Value ~ the data contained in the textbox ~ can be read from and written to





This is a line of code from my diary program in VBA/Excel.

Sheet1.Cells(Countx1 + 1, Ofs) = CVar(DateTxt.Text)

The spreadsheet, Sheet1 , the Cells (for storage of data), and the Y then X, = CVar (convert to variant data type which is in the spreadsheet cells) a textbox DateTxt it's value .Text .

The x & y coordinates of the Cells begin at 1,1. Do not use 0,0 or it will fail.

My diary program is over 4 years old and is 1MB+ of mainly TXT data from my daily mischevious activities.

You can tell how redundant using spreadsheet cells must be to be that reliable.



NOTICE.

I don't know how he's accessing COM ports under this type of coding. I'd personally like to know. I know there are add-ins and DLL stuffs and other hooks into the API you can get into, but I haven't wet my feet that far yet. I get into FreeBasic for stuff that goes that much deeper into real I/O.

I hope this helps!

It's a bit winded of an explaination, but it's necessary to get enough clarity to even start with since it's hidden under Excel in the first place.



Kiyote!

ziloo
June 13th, 2009, 01:17 AM
Great tutorial Kiyote...thank you very much :clap: :clap2: :-D!!!

Now ...., what does VBA stand for?

ziloo

kiyotewolf
June 13th, 2009, 01:40 AM
V(isual)BA(sic)

There is plain jane visual basic which runs as a real EXE, there is VBScript which runs only on Internet Explorer web pages, and there are ""macros, V(isual)B(asic) which is the same stuff just circumscribed to work with the objects and thingies that you expect to find in Excel.

Because Excel has alot of clout in Windows eyes, you can get away with some more mischief with it.

(Avoiding Vista that is.. ugh.. vista wants you to have the privilages of a government agent to do ANYTHING.)

My diary program has various sections for types of writing, it has a web page generator which creates a webpage out of a directory of images, (Win2000 doesn't have the preview thingy XP does),..

I can create a TXT file from a diary entry and it will bring up Wordpad for you so you can print it out, or it can output to a file multiple times to put lots of entries in at once.

It's a bit involved, but there are books out there that actually say on then, VBA for Excel. You have to go through alot of them to find the best juicy parts, but just taking a notebook to a book store and write down the code without having to buy the book is awesome. (Barnes & Noble)

It takes some figuring out, and some things I've had to hammer at for awhile before they worked.

If anyone wants more ideas/help/etc, let me know.



Kiyote!

[EDIT]

His original post says Excel VBA & Visual Basic 6. Those are not the same. Yes they are coded the same, but you can't say a VB6 program is an Excel macro. Is he (you person you) using both? I'm confused..