AWindow.h

Copyright © 2004 Dave Bayer. Subject to the terms and conditions of the MIT License.

#include <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>

@interface AWindow : NSWindow
{
    long gmtDelta;
    SInt8 dlsDelta;

    IBOutlet NSTextField *gmtTextField;
    IBOutlet NSTextField *dlsTextField;
 }
@end

AWindow.m

Copyright © 2004 Dave Bayer. Subject to the terms and conditions of the MIT License.

#import "AWindow.h"

@implementation AWindow

awakeFromNib

- (void) awakeFromNib
{
    MachineLocation loc;
    NSString *s;

Carbon defines MachineLocation as

struct MachineLocation {
    Fract   latitude;
    Fract   longitude;
    union {
    #if TARGET_RT_BIG_ENDIAN
        SInt8 dlsDelta;
    #endif
        long    gmtDelta;           /* use low 24-bits only */
        struct {
        #if TARGET_RT_LITTLE_ENDIAN
            SInt8   pad[3];
        #endif
            SInt8   Delta;          /* signed byte; daylight savings delta */
        } dls;
    } u;
};
typedef struct MachineLocation MachineLocation;
It helps to know that the intent of this C jawbreaker is to pack a 3 byte quantity and a 1 byte quantity into the same word, independent of machine byte order, while maintaining backward compatibility with its previous version. It doesn't help that the documentation version of this struct is neither correct nor indented; the above is copied from the actual header file. One needs to take care in both reading from and writing to this struct, to achieve desired results.

Read MachineLocation from parameter ram:

    ReadLocation ( &loc );

Unpack signed 24 bit integer:

    gmtDelta = loc.u.gmtDelta & 0x00ffffff;
    if ( gmtDelta & 0x00800000)
        gmtDelta = gmtDelta | 0xff000000;
    dlsDelta = loc.u.dls.Delta;

Write values to window:

    s = [ NSString stringWithFormat: @"%d", gmtDelta ];
    [ gmtTextField setStringValue: s ];
    s = [ NSString stringWithFormat: @"0x%02x", dlsDelta ];
    [ dlsTextField setStringValue: s ];
}

@end