hl08+@andrew.cmu.edu (Howard D. Look) (05/02/89)
How do I open a device driver from within Allegro Common Lisp v1.2 ???
We have written a device driver in LSC 3.0 which talks to MIDI devices through
the serial port. I am able to successfully open and use the driver from
within a LSC application. The code that works is shown below.
However, I would like to be able to open and use the driver from within an
Allegro Lisp application. My biggest problem is that the OpenDriver() call
within LSC is not a trap; it simply expands into an Open call, which I cannot
seem to translate properly into Lisp.
The Lisp code below is as close as I've gotten. It seems to open the resource
just fine, but returns an error code -43 (File not found) when it tries to
access the driver.
What am I doing wrong??? My whole notion of how a device driver fits into
a resource file is kind of screwy, so any clarifications would be appreciated.
Thanks,
Howard Look
Carnegie Mellon University
hl08+@andrew.cmu.edu
/**********************************
The Lightspeed C code that works...
***********************************/
#define DEV_NAME ".Midi"
#define RES_NAME "Midi"
main()
{
int driver_ref, resource_ref;
open_res(RES_NAME, &resource_ref);
open_ints(DEV_NAME, &driver_ref);
/* ... */
close_ints(driver_ref);
}
open_res(name, ref_num)
char name[];
int *ref_num;
{
char res_name[STRING_LEN];
strcpy(res_name, CtoPstr(name));
*ref_num = OpenResFile(res_name);
if(*ref_num == -1)
exit(ResError());
}
open_ints(name, ref_num)
char name[];
int *ref_num;
{
char dev_name[STRING_LEN];
OSErr error;
strcpy(dev_name, CtoPstr(name));
if(error = OpenDriver(dev_name, ref_num))
exit(error);
else printf("Opened ints.\n");
}
close_ints(ref_num)
int ref_num;
{
OSErr error;
if(error = CloseDriver(ref_num))
exit(error);
else printf("Closed ints\n");
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; The Allegro Lisp code that doesn't work ...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar *device-name* ".MIDI")
(defvar *device-reference-number*)
(defvar *driver-pb*) ; driver parameter block
(defvar *resource-name* "Midi")
(defvar *resource-reference-number*)
;;; Offsets into the parameter block
(defconstant $IOCOMPLETION 12)
(defconstant $IORESULT 16)
(defconstant $IOFILENAME 18)
(defconstant $IOVREFNUM 22)
(defconstant $IOREFNUM 24)
(defconstant $CSCODE 26)
(defconstant $IOPERMSSN 27)
(defconstant $IOMISC 28)
(defconstant $CSPARAM 28)
(defconstant $IOBUFFER 32)
(defconstant $IOREQCOUNT 36)
; with pstrs coerces the lisp string into a pascal string
; the Mac OS can understand.
(defun open-resource ()
(with-pstrs ((resource-name *resource-name*))
(setf *resource-reference-number* (_OpenResFile :ptr resource-name
:long))
(if (= *resource-reference-number* -1)
(signal-error "Couldn't open resource file.")
(format t "Resource file opened, ref-num = ~D" *resource-reference-number*))))
(defun open-driver ()
(let ((error))
(with-pstrs ((device-name *device-name*))
(%put-ptr *driver-pb* device-name $IOFILENAME)
(setq error (_Open ;:check-error
:a0 *driver-pb*
:d0)))
(setf *driver-reference-number* (%get-word *driver-pb* $IOREFNUM))
(format t "~%Driver maybe opened with error = ~D, ref = ~D" error *driver-reference-number*)))
(defun init-Midi-device ()
(open-resource)
; define a parameter block for the driver and initialize it
(setf *driver-pb* (_NewPtr :check-error
:d0 80
:a0))
(%put-word *driver-pb* 0 $IOREFNUM)
(%put-byte *driver-pb* 1 $IOPERMSSN) ; request read only
(open-driver))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
End of Message