Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!cbmvax!phillip From: phillip@cbmvax.UUCP Newsgroups: comp.sys.amiga Subject: Re: Parallel port direct access Message-ID: <1685@cbmvax.cbmvax.cbm.UUCP> Date: Thu, 16-Apr-87 08:07:06 EST Article-I.D.: cbmvax.1685 Posted: Thu Apr 16 08:07:06 1987 Date-Received: Sat, 18-Apr-87 04:36:37 EST References: <236@rocky.STANFORD.EDU> Distribution: world Organization: Commodore Technology, West Chester, PA Lines: 233 in article <236@rocky.STANFORD.EDU>, stergios@rocky.STANFORD.EDU (Stergios Marinopoul) says: > > > I'm trying to figure out how to access the parallel port directly > through hardware, rather than the device handlers. I know that the --------***************[trimmed to make net people happy...] > > Stergios Marinopoulos > S&M Engineering We have resources for the parallel port (ciaa.resource and misc.resource). If it isn't too much trouble I would like to see you use them.:-> What follows is an example the uses the system resources to access the parallel port directly. -phil ============================================================================== Phillip Lindsay - Commodore Business Machines - Amiga Technical Support UUCP: {ihnp4|seismo|caip}!cbmvax!phillip - Phone: (215) 431-9180 No warranty is implied or otherwise given in the form of suggestion or example. Any opinions found here are of my making. ---cut---here------------------------------------------------------------------ #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # parout.c # getfreemisc.asm # This archive created: Thu Apr 16 07:52:57 1987 export PATH; PATH=/bin:$PATH echo shar: extracting "'parout.c'" '(3812 characters)' if test -f 'parout.c' then echo shar: will not over-write existing file "'parout.c'" else sed 's/^ X//' << \SHAR_EOF > 'parout.c' X/* parout.c - Parallel port resource example. X * X * Phillip Lindsay (c) Commodore-Amiga, Inc. X * Unlimited use granted as long as copyright notice remains intact. X * X */ X#include X#include X#include X#include X#include X#include X#include X#include X#include /* this header has defines for hardware addresses */ X X#define CIAA_DDRPBOUT 0xff /* CIAA port B all "ouputs" */ X X#define MANX /* using MANX Aztec C */ X X#ifdef MANX X#include X#endif X Xextern CPTR GetMiscResource(); Xextern VOID FreeMiscResource(); Xextern ULONG CIAARoutine(); X Xstruct MiscResource *MiscResource=NULL; XCPTR CIAAResource=NULL; X Xchar *myname = "myparallel"; Xchar *teststr= "This is a test line being sent to a parallel device.\n"; X Xstruct Task *mytask; XLONG mysignal; XULONG mysigmask; X Xmain() X{ X struct Interrupt CIAAInterrupt; X register count=0; X X MiscResource = (struct MiscResource *) OpenResource(MISCNAME); X if(!MiscResource) exit(10); Xputs("after open misc.resource"); X X CIAAResource = (CPTR) OpenResource(CIAANAME); X if(!CIAAResource) exit(20); Xputs("after open ciaa.resource"); X X/* this is where we get our 8bits for parallel transfer */ X if(GetMiscResource(MiscResource,MR_PARALLELPORT,myname)) exit(30); Xputs("after GetMiscResource PARALLELPORT (CIAA Port B)"); X X/* this is where we get busy(bit 0), pout(bit 1), sel(bit 2) */ X if(GetMiscResource(MiscResource,MR_PARALLELBITS,myname)) X { X FreeMiscResource(MiscResource,MR_PARALLELPORT); X exit(40); X } Xputs("after GetMiscResource PARALLELBITS BUSY/POUT/SEL (CIAB Port A bits 0,1,2)"); X X if((mysignal = AllocSignal(-1L)) == -1L) X { X FreeMiscResource(MiscResource,MR_PARALLELPORT); X FreeMiscResource(MiscResource,MR_PARALLELBITS); X exit(50); X } Xputs("after AllocSignal()"); X X mysigmask = 1L << mysignal; X X /* now we own the parallel port, next handshake interrupt ACK */ X setmem(&CIAAInterrupt,(ULONG)sizeof(CIAAInterrupt),(ULONG)'\0'); Xputs("after setmem()"); X CIAAInterrupt.is_Data = (APTR) CIAAResource; X CIAAInterrupt.is_Code = (VOID(*)()) CIAARoutine; X CIAAInterrupt.is_Node.ln_Type = NT_INTERRUPT; X CIAAInterrupt.is_Node.ln_Name = myname; Xputs("after interrupt init"); X if(AddICRVector(CIAAResource,CIAICRB_FLG,&CIAAInterrupt)) X { X FreeMiscResource(MiscResource,MR_PARALLELPORT); X FreeMiscResource(MiscResource,MR_PARALLELBITS); X FreeSignal(mysignal); X exit(50); X } Xputs("after AddICRVector()"); X X /* disable ACK interrupt */ X AbleICR(CIAAResource,CIAICRF_FLG); Xputs("after AbleICR() disable flag interrupt"); X X /* set up direction for i/o ports used */ X ciaa.ciaddrb = CIAA_DDRPBOUT; /* make CIAA port B all "ouputs" */ X X /* make BUSY, SEL, POUT "inputs" on CIAA port A */ X ciab.ciaddra &= ( ~CIAF_PRTRBUSY | ~CIAF_PRTRPOUT | ~CIAF_PRTRSEL ); X X /* clear any pending interrupts */ X SetICR(CIAAResource,CIAICRF_FLG); Xputs("after SetICR() clear pending flag interrupts"); X X /* enable ACK interrupt */ X AbleICR(CIAAResource,CIAICRF_SETCLR|CIAICRF_FLG); Xputs("after AbleICR() enable flag interrupt"); X X while(teststr[count]) X { X if(ciab.ciapra & CIAF_PRTRBUSY) /* make sure device is not busy */ X continue; X ciaa.ciaprb = teststr[count++]; /* write data to port */ X wait(mysigmask); /* wait for ack */ X } X X AbleICR(CIAAResource,CIAICRF_FLG); /* disable interrupt */ X /* remove interrupt */ X RemICRVector(CIAAResource,CIAICRB_FLG,&CIAAInterrupt); X /* free resources */ X FreeMiscResource(MiscResource,MR_PARALLELPORT); X FreeMiscResource(MiscResource,MR_PARALLELBITS); X FreeSignal(mysignal); X} X/* end of main() */ X X XULONG CIAARoutine() X{ X#ifdef MANX X geta4(); X#endif X Signal(mytask,mysigmask); X return(0L); X} X X/* eof */ X SHAR_EOF if test 3812 -ne "`wc -c < 'parout.c'`" then echo shar: error transmitting "'parout.c'" '(should have been 3812 characters)' fi fi # end of overwriting check echo shar: extracting "'getfreemisc.asm'" '(1013 characters)' if test -f 'getfreemisc.asm' then echo shar: will not over-write existing file "'getfreemisc.asm'" else sed 's/^ X//' << \SHAR_EOF > 'getfreemisc.asm' X****************************************************************************** X* getfreemisc.asm - interface routines for misc.resource X* X* Phillip Lindsay (c) 1987 Commodore-Amiga, Inc. X* Unlimited use granted as long as copyright notice remains intact. X* X****************************************************************************** X X INCLUDE 'exec/types.i' X INCLUDE 'exec/libraries.i' X INCLUDE 'resources/misc.i' X X XDEF _GetMiscResource X XDEF _FreeMiscResource X X_GetMiscResource: X movem.l a4/a6,-(sp) X move.l 20(sp),a1 ; name X move.l 16(sp),d0 ; unit X move.l 12(sp),a6 ; misc resource pointer X jsr MR_ALLOCMISCRESOURCE(a6) X movem.l (sp)+,a4/a6 X rts X X_FreeMiscResource: X movem.l a4/a6,-(sp) X move.l 12(sp),a6 ; misc resource pointer X move.l 16(sp),d0 ; unit X jsr MR_FREEMISCRESOURCE(a6) X movem.l (sp)+,a4/a6 X rts X X end X***************************************************************************** X* X* end of getfreemisc.asm X* X***************************************************************************** SHAR_EOF echo shar: a missing newline was added to "'getfreemisc.asm'" if test 1013 -ne "`wc -c < 'getfreemisc.asm'`" then echo shar: error transmitting "'getfreemisc.asm'" '(should have been 1013 characters)' fi fi # end of overwriting check # End of shell archive exit 0