Short: JRH's useful E modules
Type: dev/e
Author: m88jrh@ecs.ox.ac.uk (Jason R. Hulance)
Uploader: m88jrh@ecs.ox.ac.uk (Jason R. Hulance)

JRH's Useful Modules
====================

These modules are Copyright (C) 1995, Jason R. Hulance.

You are free to use these modules in your programs, whether they are freeware
or commercial.  However, if you want to distribute any of this archive you
must include it all, unmodified, together with this file.

Contents
--------

Various modules:

  ecode.m:
    PROC eCode(func)
    PROC eCodePreserve(func)
    PROC eCodeTask(func)
    PROC eCodeASLHook(func)
    PROC eCodeCxCustom(func)
    PROC eCodeIntHandler(func)
    PROC eCodeIntServer(func)
    PROC eCodeSoftInt(func)
    PROC eCodeDispose(addr)

  split.m:
    PROC argSplit(str=0)


Amiga E does not support Resources (at least, not up to v3.1a, anyway).
These modules rectify this.

  battclock.m:
    DEF battclockbase
    PROC readBattClock()
    PROC resetBattClock()
    PROC writeBattClock(time)

  battmem.m:
    DEF battmembase
    PROC obtainBattSemaphore()
    PROC readBattMem(buffer,offset,length)
    PROC releaseBattSemaphore()
    PROC writeBattMem(buffer,offset,length)

  cia.m:
    PROC ableICR(resource,mask)
    PROC addICRVector(resource,iCRBit,interrupt)
    PROC remICRVector(resource,iCRBit,interrupt)
    PROC setICR(resource,mask)

  disk.m:
    DEF diskbase
    PROC allocUnit(unitNum)
    PROC freeUnit(unitNum)
    PROC getUnit(unitPointer)
    PROC getUnitID(unitNum)
    PROC giveUnit()
    PROC readUnitID(unitNum)

  misc.m:
    DEF miscbase
    PROC allocMiscResource(unitNum,name)
    PROC freeMiscResource(unitNum)

  potgo.m:
    DEF potgobase
    PROC allocPotBits(bits)
    PROC freePotBits(bits)
    PROC writePotgo(word,mask)


Documentation
-------------

The standard documentation on the Resource functions suffices for the
Resource modules.  All the other functions (eCodeXXX and split) return NIL
if an error occurred, which is normally "out of memory".

  ecode.m:
    o   eCode() takes the address of an E function (or a label) and wraps it
      so that it can be called from other tasks/processes and still access
      the global variables of the main program.  This function was created
      for use with createTask(), but has other uses.
    o   eCodePreserve() is similar, but it also protects the function by
      preserving the non-scratch registers on the stack.  This means the
      function can retrieve (and change) registers D2-D7/A2-A6 as local
      variables.  For instance,
        PROC fun(a6,a5,a4,a3,a2,d7,d6,d5,d4,d3,d2) IS d2:=d3+a3
      will have the effect of changing register D2 (and D0) when the
      function returns.  Note: you do not need to specify all registers,
      just the suffix of the above that you are actually interested in.
        PROC fun(a3,a2,d7,d6,d5,d4,d3,d2) IS d2:=d3+a3
      would have done...
    o   eCodeTask() is just eCode() with a more suggestive name.
    o   eCodeASLHook() takes the address of an E function (or a label) and
      returns something usable as an ASL hook function (nothing to do with
      the utility library hooks, more's the pity).
    o   eCodeCxCustom() does the same for CX custom functions.
    o   eCodeIntHandler() is for interrupt handlers: you get A1 and D1 as
      arguments (in that order) to your function.  (A1 is the data element
      of your interrupt, and D1 contains the interrupt flags.)
    o   eCodeIntServer() is for interrupt servers: you get A1 (the data
      element of your interrupt) as an argument.
    o   eCodeSoftInt() is the same, but for software interrupts.
    o   eCodeDispose() is passed the result of the one of the above
      functions, and will to dispose the memory used by the special wrapper.
      You will rarely need to use this, as the memory will be freed
      automatically at the end of the program.
    o   eCodeASLHook(), eCodeCxCustom(), eCodeIntHandler(), eCodeIntServer()
      and eCodeSoftInt() all use their own private scratch area to preserve
      registers, thus saving crucial stack space.  This has the disadvantage
      of making the code non-reentrant, so if you need to use the same
      function as multiple interrupt servers you must use eCodeIntServer()
      multiple times.  Apart from that they should be OK, since they do
      not get called from multiple tasks.  (If you find this a problem then
      you can use eCodePreserve()...)
    o   eCodePreserve() uses a big bit of stack to store registers, so be
      careful...

  split.m:
    o   argSplit(str=NIL) splits a string of arguments like "arg" (which is
      the default), handling quoted arguments correctly.  The result is an
      E-list of strings, or NIL if an error occurred.  The list is also
      NIL-terminated so you have a choice of ways to manipulate it.  The
      string passed to this function (or "arg" by default) is *altered* by
      this function, so you shouldn't try using it directly.  You can
      DisposeLink() the resulting list if you want to free it before the end
      of the program.  (You are also responsible for freeing the string when
      you are done with it, unless it was the default "arg", of course.)

The main reason for the creation of these modules was my translations of the
RKRM examples.  These provide many examples of the use of these functions.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       7     &( &                   %נ "ݘ                       7   0            &DD   H Hq& D@F   v $ 3 ?2V (| 
DF $2,& Q6   Dh "M "&  ? DM	 "$I,& !ٙ ~f 1	 f   Pa4,. # 0&    DD  jH Ȑy1& @ B ! Jr p&$ 2R )A
 @B &2," і2  
   h K     "" >  K
` 
 $Fc ffb ff 0@ff
  ff ǐffj a  , Q0"              7                "      HF $  	?V ~ * }Ȇ }Dd" }t }   4B %b  I MFn '   s̲ ̆ M̲ c 1 W @    ">  j $ Hv  D $ A P d 	 T م( ̕  Ȅ Dd  t ɀ      4@ $ `    H LFl &0  5 330 r33   33 L33  c@334 0` эT  @             :c/MuchMore       % Icon by Martin Huttenloher                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               EMOD                 	        NU   ,N]NuNU  ,lNp N]NuNU  ,lNN]NuNU   - ,lNp N]Nu  writeBattClock     .       time   readBattClock              resetBattClock                    battclockbase                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        EMOD                 	        NU   ,N]NuNU  ,lNp N]NuNU  ,lNp N]NuNU   m  - "- ,lNN]NuNU   m  - "- ,lNN]Nu  releaseBattSemaphore               obtainBattSemaphore              writeBattMem     L       buffer,offset,length   readBattMem    0       buffer,offset,length        battmembase                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  a(PqƤR}axNybI6Ք_/x"٦ApWd>P| !Z'3Z/\B1in,_]9ᭈ}ssL%Bqdzc?i.Y\VE3,
G2գ9֍K>Pv&[{Mu&ʚ+Hh6nPM5 ^8j-ɴV~ƠR=x}⡉fſ0C(1ޔXoz#=њkJ7֏KFr"YCńS#}kN4Ap^8{R}u.C)XSz1fj/)^Ҹ]5"jE³w
BqybiIّkE3%HvfɿSC}HcvW>e+O4
G.u>ʐW,>i.NZ{M5-iLGu3!_2U9E9g%+DsH%Bq$o[l;mmK47WVpD$3[U` N4`h|caNδTwf*z#Ɗ&+LX5.`Y:Γmm-]9]yᅈc& [@;pdEs$%[{KcwiW@`0P=$8000009B,
      WA_HELPGROUPWINDOW=$8000009C,
      HC_GADGETHELP=1

OBJECT remember
  nextremember:PTR TO remember
  remembersize:LONG
  memory:PTR TO CHAR
ENDOBJECT     /* SIZEOF=12 */

OBJECT colorspec
  colorindex:INT
  red:INT  -> This is unsigned
  green:INT  -> This is unsigned
  blue:INT  -> This is unsigned
ENDOBJECT     /* SIZEOF=8 */

OBJECT easystruct
  structsize:LONG
  flags:LONG
  title:PTR TO CHAR
  textformat:PTR TO CHAR
  gadgetformat:PTR TO CHAR
ENDOBJECT     /* SIZEOF=20 */

#define MENUNUM(n) (n AND $1F)
#define ITEMNUM(n) (Shr(n,5) AND $3F)
#define SUBNUM(n) (Shr(n,11) AND $1F)

#define SHIFTMENU(n) (n AND $1F)
#define SHIFTITEM(n) (Shl(n AND $3F,5))
#define SHIFTSUB(n) (Shl(n AND $1F,11))

#define FULLMENUNUM(menu,item,sub) (SHIFTSUB(sub) OR SHIFTITEM(item) OR SHIFTMENU(menu))

#define SRBNUM(n) (8-Shr(n,4))
#define SWBNUM(n) (8-(n AND $F))
#define SSBNUM(n) (1+Shr(n,4))
#define SPARNUM(n) (Shr(n,4))
#define SHAKNUM(n) (n AND $F)

CONST NOMENU=31,
      NOITEM=$3F,
      NOSUB=31,
      MENUNULL=$FFFF,
      CHECKWIDTH=19,
      COMMWIDTH=27,
      LOWCHECKWIDTH=13,
      LOWCOMMWIDTH=16,
      ALERT_TYPE=$80000000,
      RECOVERY_ALERT=0,
      DEADEND_ALERT=$80000000,
      AUTOFRONTPEN=0,
      AUTOBACKPEN=1,
      AUTODRAWMODE=1,
      AUTOLEFTEDGE=6,
      AUTOTOPEDGE=3,
      AUTOITEXTFONT=0,
      AUTONEXTTEXT=0,
      SELECTUP=$E8,
      SELECTDOWN=$68,
      MENUUP=$E9,
      MENUDOWN=$69,
      MIDDLEUP=$EA,
      MIDDLEDOWN=$6A,
      ALTLEFT=16,
      ALTRIGHT=$20,
      AMIGALEFT=$40,
      AMIGARIGHT=$80,
      AMIGAKEYS=$C0,
      CURSORUP=$4C,
      CURSORLEFT=$4F,
      CURSORRIGHT=$4E,
      CURSORDOWN=$4D,
      KEYCODE_Q=16,
      KEYCODE_Z=$31,
      KEYCODE_X=$32,
      KEYCODE_V=$34,
      KEYCODE_B=$35,
      KEYCODE_N=$36,
      KEYCODE_M=$37,
      KEYCODE_LESS=$38,
      KEYCODE_GREATER=$39,
      TABLETA_DUMMY=$8003A000,
      TABLETA_TABLETZ=$8003A001,  -> Data for this tag is unsigned INT
      TABLETA_RANGEZ=$8003A002,
      TABLETA_ANGLEX=$8003A003,
      TABLETA_ANGLEY=$8003A004,
      TABLETA_ANGLEZ=$8003A005,
      TABLETA_PRESSURE=$8003A006,
      TABLETA_BUTTONBITS=$8003A007,
      TABLETA_INPROXIMITY=$8003A008,
      TABLETA_RESOLUTIONX=$8003A009,
      TABLETA_RESOLUTIONY=$8003A00A

OBJECT tabletdata
  xfraction:INT  -> This is unsigned
  yfraction:INT  -> This is unsigned
  tabletx:LONG
  tablety:LONG
  rangex:LONG
  rangey:LONG
  taglist:PTR TO tagitem
ENDOBJECT     /* SIZEOF=24 */

OBJECT tablethookdata
  screen:PTR TO screen
  width:LONG
  height:LONG
  screenchanged:LONG
ENDOBJECT     /* SIZEOF=16 */
