BRL102@psuvm.psu.edu (Ben Liblit) (02/06/90)
In article <9541.infoapple.net@pro-generic>, ericmcg@pro-generic.cts.com (Eric Mcgillicuddy) says: > [Hyper C allows the creation of] anchored variables, [so] you can >specify a variable to occupy a specific memory location. Very useful for >twiddling bits in softswitches. Could someone post an illustrative exaple of the proper syntax for such a declaration? Also, what's the most efficient way of using such a variable to get at a softswitch? Assign it to a dummy variable? Assign a dummy value to it? Ben Liblit BRL102 @ psuvm.bitnet -- BRL102 @ psuvm.psu.edu "Fais que tes reves soient plus longs que la nuit."
gwyn@smoke.BRL.MIL (Doug Gwyn) (02/07/90)
>> [Hyper C allows the creation of] anchored variables, [so] you can >>specify a variable to occupy a specific memory location. Very useful for >>twiddling bits in softswitches. This is a fine example of an unnecessary feature, because one can access specified absolute addresses using normal C facilities. I did it in a printer utility I wrote using Aztec C on my old //e.
fadden@cory.Berkeley.EDU (Andy McFadden) (02/07/90)
In article <90037.000759BRL102@PSUVM.BITNET> BRL102@psuvm.psu.edu (Ben Liblit) writes: >In article <9541.infoapple.net@pro-generic>, ericmcg@pro-generic.cts.com (Eric >Mcgillicuddy) says: >> [Hyper C allows the creation of] anchored variables, [so] you can >>specify a variable to occupy a specific memory location. Very useful for >>twiddling bits in softswitches. > >Could someone post an illustrative exaple of the proper syntax for such a >declaration? Also, what's the most efficient way of using such a variable to >get at a softswitch? Assign it to a dummy variable? Assign a dummy value to >it? Why not the following? [ I just typed this in; can't say whether or not it really it's bug-free ] /* * Returns 0 if nothing has been hit (so this will miss ctrl-@). * Otherwise returns the key value (0-127). If Open-Apple is pressed, * returns with the high bit set (128-255). * * Normal usage (blocking I/O): * while (!(c = GetKbd())) * ; */ unsigned char GetKbd() { unsigned char *kbd = (char *) 0xc000, *kbdstrb = (char *) 0xc010, *open_apple = (char *) 0xc061; unsigned char keyval; if (*kbd > 127) { keyval = *kbd - 128; keyval |= ((*open_apple) & (unsigned char) 0x80); *kbdstrb = (unsigned char) 0; return (keyval); } else { return (0); } } [ this is one of the reasons why I like C so much... ] Under APW, you would use something like 0xe0c000L for the constants. -- fadden@cory.berkeley.edu (Andy McFadden) ...!ucbvax!cory!fadden
pnakada@oracle.com (Paul Nakada) (02/07/90)
In article <21842@pasteur.Berkeley.EDU> fadden@cory.Berkeley.EDU (Andy McFadden) writes: In article <90037.000759BRL102@PSUVM.BITNET> BRL102@psuvm.psu.edu (Ben Liblit) writes: >In article <9541.infoapple.net@pro-generic>, ericmcg@pro-generic.cts.com (Eric >Mcgillicuddy) says: >> [Hyper C allows the creation of] anchored variables, [so] you can >>specify a variable to occupy a specific memory location. Very useful for >>twiddling bits in softswitches. > >Could someone post an illustrative exaple of the proper syntax for such a >declaration? Also, what's the most efficient way of using such a variable to >get at a softswitch? Assign it to a dummy variable? Assign a dummy value to >it? Why not the following? [ I just typed this in; can't say whether or not it really it's bug-free ] /* * Returns 0 if nothing has been hit (so this will miss ctrl-@). * Otherwise returns the key value (0-127). If Open-Apple is pressed, * returns with the high bit set (128-255). * * Normal usage (blocking I/O): * while (!(c = GetKbd())) * ; */ unsigned char GetKbd() { unsigned char *kbd = (char *) 0xc000, *kbdstrb = (char *) 0xc010, *open_apple = (char *) 0xc061; ======================================================================== LOOK OUT HERE, Hyper C seems to have some problems with initializing variables in the declaration. It appears to be much happier with separate declarations if you want to initialize them in the decalration: unsigned char *kbd = (char *) 0xc000; unsigned char *kbdstrb = (char *) 0xc010; unsigned char *open_apple = (char *) 0xc061; I think it may have something to do with the comma operator (is the comma acting as an operator even in the declaration? ) ======================================================================= unsigned char keyval; if (*kbd > 127) { keyval = *kbd - 128; keyval |= ((*open_apple) & (unsigned char) 0x80); *kbdstrb = (unsigned char) 0; return (keyval); } else { return (0); } } [ this is one of the reasons why I like C so much... ] Under APW, you would use something like 0xe0c000L for the constants. -- fadden@cory.berkeley.edu (Andy McFadden) ...!ucbvax!cory!fadden -Paul Nakada pnakada@oracle.com