Newton Framework

Newton.framework

Use the framework to debug native Newton C++ modules using lldb within Xcode; it provides all the RefVar stuff and lets you breakpoint/examine your own code without the pain of downloading to a Newton device and testing using Hammer.

Download

System Requirements

The framework targets Mac OS X 10.10 (Yosemite), but is largely standalone so should run on earlier systems too.

Update: The framework has evolved over the years and is now 64-bit. This may make for some incompatibilities with NewtonInterfaceLib.o. For example, Refs are now 64-bit so allow a greater range of values than in the original Newton OS. If you need a 32-bit version of the framework, look here.


Installation

Copy Newton.framework to ~/Library/Frameworks or your project folder.

Add Newton.framework to your Xcode project.

The only change you need to make to your NCT sources is to include a modified Objects.h when building for Xcode:
#if defined(__NCT__)
#include "Objects.h"
#else
#include "Newton/Objects.h"
#endif

The framework initializes itself the first time you access any function within it. You don't need explicitly to call anything or otherwise modify your Newton code to run on Mac instead of Newton device.

Modified Newton Headers

The framework includes a small number of header files. These are meant to replace those that ship with Newton C++ Tools, which you should have already installed. You need only be concerned directly with two:

  • Objects.h which must be included in your sources as described opposite
  • NewtonQD.h which you should copy to your NCT Includes directory if you intend using QuickDraw and don't already have the necessary declarations.

Objects.h

This must be used when building for Xcode; it includes other modified Newton headers.

Newton.h

This simply includes other modified Newton headers.

NewtonExceptions.h

Uses setjmp instead of __xxx_XS001_.

NewtonMemory.h

There is no DisposPtr() in the Carbon library; that disappeared years ago. It should be renamed FreePtr().

NewtonQD.h

There are no QuickDraw declarations in the standard NCT Includes. Copy this file from the framework to your NCT Includes folder if necessary.

Use

Newton.framework provides the API declared in the NCT headers. In other words, if you can link with NewtonInterfaceLib.o, you can use the Newton.framework. It includes an interpreter and many (but not all) magic pointers, global functions and variables. If you want to call a global function, for example:

RefVar bitmap = NSCallGlobalFn(SYM(MakeBitmap), MAKEINT(width), MAKEINT(height), options);

Or if you want to execute your own NewtonScript:

extern "C" Ref	DoBlock(RefArg codeBlock, RefArg args);
extern "C" Ref	DoMessage(RefArg rcvr, RefArg msg, RefArg args);

RefVar cmdRcvr(GetArraySlot(cmdFrame, 2));
RefVar cmdFunc(GetArraySlot(cmdFrame, 0));
RefVar cmdArg(GetArraySlot(cmdFrame, 1));
if (EQRef(ClassOf(cmdFrame), SYMundo))
{
   if (IsFunction(cmdFunc))
      DoBlock(cmdFunc, cmdArg);
   else
      DoMessage(cmdRcvr, cmdFunc, cmdArg);
}

There is a NewtonScript compiler within the framework, but you should use NTK to create NewtonScript codeblocks.

The frames heap size is fixed at 256K. This has been plenty in my experience, but if you need more let me know.


Sample Code

Imager

The Imager native C++ module decodes the following image types into Newton pixelmaps for display by the Image Stationery:

GIF based on versit vCard sample code
JPEG based on the Independent JPEG Group’s JPEG software release 6b
PNG based on libpng 1.2.4
TIFF based on Sam Leffler’s tifflib version 3.4beta037

Also required:

ZLIB based on zlib 1.1.4

It uses the open source libraries as indicated, each of which has its own license.

Imager is copyright ©2002-2004 by Simon Bell,
licensed under the Open Software License version 2.1.

Download Imager

Installation

Copy the contents of the NCT_Projects folder in the Image Stationery archive to your own NCT_Projects folder (or whatever you have called it on your system). The zlib folder is at the same level as Imager_NCT so it can be shared by other projects.

You can build using MPW in the normal way; or if you have the Newton.framework installed you can build a desktop version for debugging within Xcode.