Home » Archimedes archive » Acorn User » AU 1995-04.adf » !Internet_StarterPak » SerialDev/h/example

SerialDev/h/example

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1995-04.adf » !Internet_StarterPak
Filename: SerialDev/h/example
Read OK:
File size: 03C2 bytes
Load address: 0000
Exec address: 0000
File contents
/* Maximum driver length - 4k */
int driver_block[1024];

/* The correct driver load prototype so that C doesn't moan */
extern int (*driver_load(char*))(int,...);

/*
   Use driver_init() to build driver list - you can use the text
   to build a driver menu if you want. Note that the #defines
   in the driver.h file assume a global int 'portnumber' which
   defines the current port. You could always alter the defines
   accordingly if you want to pass the portnumber yourself.

   Load a driver like this:

   if ((driver=driver_load("internal"))==NULL)
     {
     error - can't load driver
     }

   driver_initialise();

   You can call the driver either with the defined methods or
   eg: (*driver)(DRIVER_functioncode,portnumber,data,...)

   All the driver functions return in r0, hence are accessible
   by C.

   You may want to munge the driver_load, eg to load to malloc'ed
   buffer space or similar - feel free. This is just an example.

   */
00000000  2f 2a 20 4d 61 78 69 6d  75 6d 20 64 72 69 76 65  |/* Maximum drive|
00000010  72 20 6c 65 6e 67 74 68  20 2d 20 34 6b 20 2a 2f  |r length - 4k */|
00000020  0a 69 6e 74 20 64 72 69  76 65 72 5f 62 6c 6f 63  |.int driver_bloc|
00000030  6b 5b 31 30 32 34 5d 3b  0a 0a 2f 2a 20 54 68 65  |k[1024];../* The|
00000040  20 63 6f 72 72 65 63 74  20 64 72 69 76 65 72 20  | correct driver |
00000050  6c 6f 61 64 20 70 72 6f  74 6f 74 79 70 65 20 73  |load prototype s|
00000060  6f 20 74 68 61 74 20 43  20 64 6f 65 73 6e 27 74  |o that C doesn't|
00000070  20 6d 6f 61 6e 20 2a 2f  0a 65 78 74 65 72 6e 20  | moan */.extern |
00000080  69 6e 74 20 28 2a 64 72  69 76 65 72 5f 6c 6f 61  |int (*driver_loa|
00000090  64 28 63 68 61 72 2a 29  29 28 69 6e 74 2c 2e 2e  |d(char*))(int,..|
000000a0  2e 29 3b 0a 0a 2f 2a 0a  20 20 20 55 73 65 20 64  |.);../*.   Use d|
000000b0  72 69 76 65 72 5f 69 6e  69 74 28 29 20 74 6f 20  |river_init() to |
000000c0  62 75 69 6c 64 20 64 72  69 76 65 72 20 6c 69 73  |build driver lis|
000000d0  74 20 2d 20 79 6f 75 20  63 61 6e 20 75 73 65 20  |t - you can use |
000000e0  74 68 65 20 74 65 78 74  0a 20 20 20 74 6f 20 62  |the text.   to b|
000000f0  75 69 6c 64 20 61 20 64  72 69 76 65 72 20 6d 65  |uild a driver me|
00000100  6e 75 20 69 66 20 79 6f  75 20 77 61 6e 74 2e 20  |nu if you want. |
00000110  4e 6f 74 65 20 74 68 61  74 20 74 68 65 20 23 64  |Note that the #d|
00000120  65 66 69 6e 65 73 0a 20  20 20 69 6e 20 74 68 65  |efines.   in the|
00000130  20 64 72 69 76 65 72 2e  68 20 66 69 6c 65 20 61  | driver.h file a|
00000140  73 73 75 6d 65 20 61 20  67 6c 6f 62 61 6c 20 69  |ssume a global i|
00000150  6e 74 20 27 70 6f 72 74  6e 75 6d 62 65 72 27 20  |nt 'portnumber' |
00000160  77 68 69 63 68 0a 20 20  20 64 65 66 69 6e 65 73  |which.   defines|
00000170  20 74 68 65 20 63 75 72  72 65 6e 74 20 70 6f 72  | the current por|
00000180  74 2e 20 59 6f 75 20 63  6f 75 6c 64 20 61 6c 77  |t. You could alw|
00000190  61 79 73 20 61 6c 74 65  72 20 74 68 65 20 64 65  |ays alter the de|
000001a0  66 69 6e 65 73 0a 20 20  20 61 63 63 6f 72 64 69  |fines.   accordi|
000001b0  6e 67 6c 79 20 69 66 20  79 6f 75 20 77 61 6e 74  |ngly if you want|
000001c0  20 74 6f 20 70 61 73 73  20 74 68 65 20 70 6f 72  | to pass the por|
000001d0  74 6e 75 6d 62 65 72 20  79 6f 75 72 73 65 6c 66  |tnumber yourself|
000001e0  2e 0a 0a 20 20 20 4c 6f  61 64 20 61 20 64 72 69  |...   Load a dri|
000001f0  76 65 72 20 6c 69 6b 65  20 74 68 69 73 3a 0a 0a  |ver like this:..|
00000200  20 20 20 69 66 20 28 28  64 72 69 76 65 72 3d 64  |   if ((driver=d|
00000210  72 69 76 65 72 5f 6c 6f  61 64 28 22 69 6e 74 65  |river_load("inte|
00000220  72 6e 61 6c 22 29 29 3d  3d 4e 55 4c 4c 29 0a 20  |rnal"))==NULL). |
00000230  20 20 20 20 7b 0a 20 20  20 20 20 65 72 72 6f 72  |    {.     error|
00000240  20 2d 20 63 61 6e 27 74  20 6c 6f 61 64 20 64 72  | - can't load dr|
00000250  69 76 65 72 0a 20 20 20  20 20 7d 0a 0a 20 20 20  |iver.     }..   |
00000260  64 72 69 76 65 72 5f 69  6e 69 74 69 61 6c 69 73  |driver_initialis|
00000270  65 28 29 3b 0a 0a 20 20  20 59 6f 75 20 63 61 6e  |e();..   You can|
00000280  20 63 61 6c 6c 20 74 68  65 20 64 72 69 76 65 72  | call the driver|
00000290  20 65 69 74 68 65 72 20  77 69 74 68 20 74 68 65  | either with the|
000002a0  20 64 65 66 69 6e 65 64  20 6d 65 74 68 6f 64 73  | defined methods|
000002b0  20 6f 72 0a 20 20 20 65  67 3a 20 28 2a 64 72 69  | or.   eg: (*dri|
000002c0  76 65 72 29 28 44 52 49  56 45 52 5f 66 75 6e 63  |ver)(DRIVER_func|
000002d0  74 69 6f 6e 63 6f 64 65  2c 70 6f 72 74 6e 75 6d  |tioncode,portnum|
000002e0  62 65 72 2c 64 61 74 61  2c 2e 2e 2e 29 0a 0a 20  |ber,data,...).. |
000002f0  20 20 41 6c 6c 20 74 68  65 20 64 72 69 76 65 72  |  All the driver|
00000300  20 66 75 6e 63 74 69 6f  6e 73 20 72 65 74 75 72  | functions retur|
00000310  6e 20 69 6e 20 72 30 2c  20 68 65 6e 63 65 20 61  |n in r0, hence a|
00000320  72 65 20 61 63 63 65 73  73 69 62 6c 65 0a 20 20  |re accessible.  |
00000330  20 62 79 20 43 2e 0a 0a  20 20 20 59 6f 75 20 6d  | by C...   You m|
00000340  61 79 20 77 61 6e 74 20  74 6f 20 6d 75 6e 67 65  |ay want to munge|
00000350  20 74 68 65 20 64 72 69  76 65 72 5f 6c 6f 61 64  | the driver_load|
00000360  2c 20 65 67 20 74 6f 20  6c 6f 61 64 20 74 6f 20  |, eg to load to |
00000370  6d 61 6c 6c 6f 63 27 65  64 0a 20 20 20 62 75 66  |malloc'ed.   buf|
00000380  66 65 72 20 73 70 61 63  65 20 6f 72 20 73 69 6d  |fer space or sim|
00000390  69 6c 61 72 20 2d 20 66  65 65 6c 20 66 72 65 65  |ilar - feel free|
000003a0  2e 20 54 68 69 73 20 69  73 20 6a 75 73 74 20 61  |. This is just a|
000003b0  6e 20 65 78 61 6d 70 6c  65 2e 0a 0a 20 20 20 2a  |n example...   *|
000003c0  2f 0a                                             |/.|
000003c2