[comp.sources.atari.st] v01i074: achlib -- Memory management and other routines for MadMac part01/02

koreth@ssyx.ucsc.edu (Steven Grimm) (09/27/88)

Submitted-by: achowe@watmsg.waterloo.edu (Anthony C. Howe)
Posting-number: Volume 1, Issue 74
Archive-name: achlib/part01

#! /bin/sh
# This is a shell archive.  Remove anything before the "#! /bin/sh" line,
# then unpack it by saving it in a file and typing "sh file."
#
# Wrapped by Steven Grimm (koreth) at ssyx on Mon Sep 26 21:23:57 1988
#
# unpacks with default permissions
#
# Contents : ACHACC.S ACHAPP.S ACHSLIB.H ACHSLIB.S LIST.C MAKEFILE
#	MEMORY.C MTEST.C MTEST.LNK README RUNTIME.H
#
if `test ! -s ACHACC.S`
then
echo "x - ACHACC.S"
cat > ACHACC.S << '@\Rogue\Monster\'
;*** achacc.s
;
;    871124


;*** Long Stack Space

STACK     =         $200


;*** Accessory Start

          .text
          .extern   _main
          .even

          move.l    #U_STACK, sp 
          jsr       _main
          move.w    #0, (sp)
          trap      #1


;*** Save Menu Line

          .text
_MENUSAV::
          movea.l   _scrloc, a0
          lea       MENULINE, a1
          move.w    #$1e0, d0
.1:
          move.l    (a0)+, (a1)+
          dbf       d0, .1
          rts

          .bss
          .even
MENULINE: .ds.l     $1f0


;*** Restore menu line

          .text
_MENURES::
          movea.l   _scrloc, a0
          lea       MENULINE, a1
          move.w    #$1e0, d0
.1:
          move.l    (a1)+, (a0)+
          dbf       d0, .1
          rts


;*** AES Call
;
; e  long pointer to AES parameter block

          .text
_crystal::
          move.l    4(sp), d1
          move.w    #200, d0
          trap      #2
          rts


          .bss
          .even
retsav:   .ds.l     1
          .ds.l     STACK
U_STACK:  .ds.l     1



;*** Control Array Settings
;
;
;    This .data is used to set entrys 1, 2 and 3 in the control
;    array.

        .data
        .even
_ctrl_cnts::

;    Application Manager
        .dc.b   0, 1, 0                 ; func 010              
        .dc.b   2, 1, 1                 ; func 011              
        .dc.b   2, 1, 1                 ; func 012              
        .dc.b   0, 1, 1                 ; func 013              
        .dc.b   2, 1, 1                 ; func 014              
        .dc.b   1, 1, 1                 ; func 015              
        .dc.b   0, 0, 0                 ; func 016              
        .dc.b   0, 0, 0                 ; func 017              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 1, 0                 ; func 019              
;    Event Manager
        .dc.b   0, 1, 0                 ; func 020              
        .dc.b   3, 5, 0                 ; func 021              
        .dc.b   5, 5, 0                 ; func 022              
        .dc.b   0, 1, 1                 ; func 023              
        .dc.b   2, 1, 0                 ; func 024              
        .dc.b   16, 7, 1                ; func 025              
        .dc.b   2, 1, 0                 ; func 026              
        .dc.b   0, 0, 0                 ; func 027              
        .dc.b   0, 0, 0                 ; func 028              
        .dc.b   0, 0, 0                 ; func 009              
;    Menu Manager
        .dc.b   1, 1, 1                 ; func 030              
        .dc.b   2, 1, 1                 ; func 031              
        .dc.b   2, 1, 1                 ; func 032              
        .dc.b   2, 1, 1                 ; func 033              
        .dc.b   1, 1, 2                 ; func 034              
        .dc.b   1, 1, 1                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Object Manager
        .dc.b   2, 1, 1                 ; func 040              
        .dc.b   1, 1, 1                 ; func 041              
        .dc.b   6, 1, 1                 ; func 042              
        .dc.b   4, 1, 1                 ; func 043              
        .dc.b   1, 3, 1                 ; func 044              
        .dc.b   2, 1, 1                 ; func 045              
        .dc.b   4, 2, 1                 ; func 046              
        .dc.b   8, 1, 1                 ; func 047              
        .dc.b   0, 0, 0                 ; func 048              
        .dc.b   0, 0, 0                 ; func 049              
;    Form Manager
        .dc.b   1, 1, 1                 ; func 050              
        .dc.b   9, 1, 1                 ; func 051              
        .dc.b   1, 1, 1                 ; func 002              
        .dc.b   1, 1, 0                 ; func 003              
        .dc.b   0, 5, 1                 ; func 004              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Dialog Manager
        .dc.b   0, 0, 0                 ; func 060              
        .dc.b   0, 0, 0                 ; func 061              
        .dc.b   0, 0, 0                 ; func 062              
        .dc.b   0, 0, 0                 ; func 003              
        .dc.b   0, 0, 0                 ; func 004              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Graphics Manager
        .dc.b   4, 3, 0                 ; func 070              
        .dc.b   8, 3, 0                 ; func 071              
        .dc.b   6, 1, 0                 ; func 072              
        .dc.b   8, 1, 0                 ; func 073              
        .dc.b   8, 1, 0                 ; func 074              
        .dc.b   4, 1, 1                 ; func 075              
        .dc.b   3, 1, 1                 ; func 076              
        .dc.b   0, 5, 0                 ; func 077              
        .dc.b   1, 1, 1                 ; func 078              
        .dc.b   0, 5, 0                 ; func 009              
;    Scrap Manager
        .dc.b   0, 1, 1                 ; func 080              
        .dc.b   0, 1, 1                 ; func 081              
        .dc.b   0, 0, 0                 ; func 082              
        .dc.b   0, 0, 0                 ; func 083              
        .dc.b   0, 0, 0                 ; func 084              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    fseler Manager
        .dc.b   0, 2, 2                 ; func 090              
        .dc.b   0, 0, 0                 ; func 091              
        .dc.b   0, 0, 0                 ; func 092              
        .dc.b   0, 0, 0                 ; func 003              
        .dc.b   0, 0, 0                 ; func 004              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Window Manager
        .dc.b   5, 1, 0                 ; func 100              
        .dc.b   5, 1, 0                 ; func 101              
        .dc.b   1, 1, 0                 ; func 102              
        .dc.b   1, 1, 0                 ; func 103              
        .dc.b   2, 5, 0                 ; func 104              
        .dc.b   6, 1, 0                 ; func 105              
        .dc.b   2, 1, 0                 ; func 106              
        .dc.b   1, 1, 0                 ; func 107              
        .dc.b   6, 5, 0                 ; func 108              
        .dc.b   0, 0, 0                 ; func 009              
;    Resource Manger
        .dc.b   0, 1, 1                 ; func 110              
        .dc.b   0, 1, 0                 ; func 111              
        .dc.b   2, 1, 0                 ; func 112              
        .dc.b   2, 1, 1                 ; func 113              
        .dc.b   1, 1, 1                 ; func 114              
        .dc.b   0, 0, 0                 ; func 115              
        .dc.b   0, 0, 0                 ; func 006
        .dc.b   0, 0, 0                 ; func 007
        .dc.b   0, 0, 0                 ; func 008
        .dc.b   0, 0, 0                 ; func 009
;    Shell Manager
        .dc.b   0, 1, 2                 ; func 120
        .dc.b   3, 1, 2                 ; func 121
        .dc.b   1, 1, 1                 ; func 122
        .dc.b   1, 1, 1                 ; func 123
        .dc.b   0, 1, 1                 ; func 124
        .dc.b   0, 1, 2                 ; func 125




@\Rogue\Monster\
else
  echo "shar: Will not over write ACHACC.S"
fi
if `test ! -s ACHAPP.S`
then
echo "x - ACHAPP.S"
cat > ACHAPP.S << '@\Rogue\Monster\'
;*** achstart.s
;
;    871121


;*** Stack & Heap Sizes
; 
;    The stack sits below the heap and has STACK long words 
;    allocated. The heap size (memory kept after a shrink)
;    is set by EXTRA. _brk monitors heap space r=  ests.

STACK     =         $200
EXTRA     =         $2500


;*** Basepage Structure

LOTPA     =         $00       ; Low TPA address
HITPA     =         $04       ; High TPA address
CODEBASE  =         $08       ; Code segment start
CODELEN   =         $0c       ; Code segment length
DATABASE  =         $10       ; Data segment start
DATALEN   =         $14       ; Data segment length
BSSBASE   =         $18       ; Bss  segment start
BSSLEN    =         $1c       ; Bss  segment length
DTA       =         $20       ; Disk Transfer Address
PARENT    =         $24       ; parent's basepage
RESERVE1  =         $28       ; resevered
ENVIRON   =         $2c       ; environment string
FCB2      =         $38       ; 2nd parsed fcb
FCB1      =         $5c       ; 1st parsed fcb
COMMAND   =         $80       ; Command tail



          .globl    _FUBAR

;*** Start here

          .text
          .globl    __main
          .globl    __exit
          .globl    __sovf
          .even
_FUBAR:
          move.l    4(sp),a5
          move.l    a5,__base
          move.l    #U_STACK,sp 

          move.l    CODELEN(a5),d0
          add.l     DATALEN(a5),d0
          add.l     BSSLEN(a5),d0
          add.l     #EXTRA,d0

          move.l    d0,-(sp)
          move.l    a5,-(sp)
          clr.w     -(sp)
          move      #$4a,-(sp)          ; do Mshrink
          trap      #1
          add.l     #12,sp

          move.l    __base,a0           ; Load C external
          move.l    BSSBASE(a0),a1      ; a1 -> .bss region
          adda.l    BSSLEN(a0),a1       ; a1 -> 1st heap loc
          move.l    a1,__break          ; Put in "break" loc

          lea.l     COMMAND(a0),a2      ; a2 -> command line
          move.b    (a2)+,d0            ; d0 = byte count
          andi.l    #$ff,d0             ; clear junk
          move.w    d0,-(a7)            ; push length
          move.l    a2,-(a7)            ; Push commnd
          clr.l     a6                  ; Clear frame pointer
          jsr       __main
          jmp       __exit



          .globl    _brk

;*** brk

          .text
_brk:           
          move.l   4(sp),a0             ; new break r=  est
          move.l    #-1,d0
          move.l   __base,a1            ; basepage address
          move.l   HITPA(a1),a1         ; get MAX break
          cmpa.l    a0,a1               ; return -1 if 
          ble.s     BRKX                ;  r=  est >= TOP
          move.l    a0,__break
          clr.l     d0
BRKX:
          rts         


__sovf:
          move.w    #9,d0               ; String print
          lea       ovf,a0              ; a0-> message
          move.l    a0,d1               ; load proper reg
          trap      #2                  ; Issue message
__exit:
          move.w    #0,d0               ; Exit
          trap      #2



          .globl    _blkfill

;*** Block Fill function:
;
;    blkfill (dest, char, count);
;
; e  BYTE    *dest 
;    BYTE    char to fill
;    WORD    count
;
          .text
_blkfill:
          move.l    4(a7),a0       ; -> Output area
          move.w    8(a7),d1       ; =  output char
          move.w    10(a7),d0      ; =  output count
          ext.l     d0             ; make it long
          subq.l    #1,d0          ; decrement
          ble.s     filldone       ; Done if le
fillit:   move.b    d1,(a0)+       ; move a byte
          dbra      d0,fillit      ; Continue
filldone: clr.l     d0             ; always return 0
          rts 



          .globl    _index
          .globl    _strchr

;*** Index function to find out if a particular
;    character is in a string.
;
; e  long pointer to string
;    short character to find
;
; x  D0.L = pointer to character else NULL if failed

          .text
_index:
_strchr:
          move.l    4(a7),a0       ; a0 -> String
          move.w    8(a7),d0       ; D0 = desired character
xindex: 
          tst.b     (a0)           ; EOS?
          bne.s     notend         ; No, continue to look
          clr.l     d0             ; Not found
          rts 
notend: 
          cmp.b     (a0)+,d0       ; check for character
          bne.s     xindex
          move.l    a0,d0          ; Found it
          subq.l    #1,d0          ; set return pointer
          rts



          .globl    ___pname 
          .globl    ___tname
          .globl    ___lname
          .globl    ___xeof 

;*** Runtime Data

          .data
          .even
ovf:      .dc.b     'Stack Overflow$'   ; Error message
___pname: .dc.b     'C runtime',0       ; Program name
___tname: .dc.b     'CON:',0            ; Console name
___lname: .dc.b     'LST:',0            ; List device name
___xeof:  .dc.b     $1a                 ; Control-Z



          .globl    __base
          .globl    __break
          .globl    ___cpmrv

;*** BSS Data

          .bss
          .even
__base:   .ds.l     1              ; Base Page
__break:  .ds.l     1              ; Break function
___cpmrv: .ds.w     1              ; Last CP/M return val

          .ds.l     STACK
U_STACK:  .ds.l     1



          .globl    _crystal
          
;*** AES Call
;
; e  long pointer to AES parameter block

          .text
_crystal:
          move.l    4(sp),d1
          move.w    #200,d0
          trap      #2
          rts



          .globl    _control

;*** AES Arrays
;
;    short control [] =
;         {
;              op code,
;              size in words of _int_in,
;              size in words of _int_out,
;              size in longs of _addr_in,
;              size in longs of _addr_out,
;         }

          .bss
          .even
_control: .ds.w     4



          .globl    _ctrl_cnts

;*** Control Array Settings
;
;
;    This .data is used to set entrys 1, 2 and 3 in the control
;    array.

        .data
        .even
_ctrl_cnts:

;    Application Manager
        .dc.b   0, 1, 0                 ; func 010              
        .dc.b   2, 1, 1                 ; func 011              
        .dc.b   2, 1, 1                 ; func 012              
        .dc.b   0, 1, 1                 ; func 013              
        .dc.b   2, 1, 1                 ; func 014              
        .dc.b   1, 1, 1                 ; func 015              
        .dc.b   0, 0, 0                 ; func 016              
        .dc.b   0, 0, 0                 ; func 017              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 1, 0                 ; func 019              
;    Event Manager
        .dc.b   0, 1, 0                 ; func 020              
        .dc.b   3, 5, 0                 ; func 021              
        .dc.b   5, 5, 0                 ; func 022              
        .dc.b   0, 1, 1                 ; func 023              
        .dc.b   2, 1, 0                 ; func 024              
        .dc.b   16, 7, 1                ; func 025              
        .dc.b   2, 1, 0                 ; func 026              
        .dc.b   0, 0, 0                 ; func 027              
        .dc.b   0, 0, 0                 ; func 028              
        .dc.b   0, 0, 0                 ; func 009              
;    Menu Manager
        .dc.b   1, 1, 1                 ; func 030              
        .dc.b   2, 1, 1                 ; func 031              
        .dc.b   2, 1, 1                 ; func 032              
        .dc.b   2, 1, 1                 ; func 033              
        .dc.b   1, 1, 2                 ; func 034              
        .dc.b   1, 1, 1                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Object Manager
        .dc.b   2, 1, 1                 ; func 040              
        .dc.b   1, 1, 1                 ; func 041              
        .dc.b   6, 1, 1                 ; func 042              
        .dc.b   4, 1, 1                 ; func 043              
        .dc.b   1, 3, 1                 ; func 044              
        .dc.b   2, 1, 1                 ; func 045              
        .dc.b   4, 2, 1                 ; func 046              
        .dc.b   8, 1, 1                 ; func 047              
        .dc.b   0, 0, 0                 ; func 048              
        .dc.b   0, 0, 0                 ; func 049              
;    Form Manager
        .dc.b   1, 1, 1                 ; func 050              
        .dc.b   9, 1, 1                 ; func 051              
        .dc.b   1, 1, 1                 ; func 002              
        .dc.b   1, 1, 0                 ; func 003              
        .dc.b   0, 5, 1                 ; func 004              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Dialog Manager
        .dc.b   0, 0, 0                 ; func 060              
        .dc.b   0, 0, 0                 ; func 061              
        .dc.b   0, 0, 0                 ; func 062              
        .dc.b   0, 0, 0                 ; func 003              
        .dc.b   0, 0, 0                 ; func 004              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Graphics Manager
        .dc.b   4, 3, 0                 ; func 070              
        .dc.b   8, 3, 0                 ; func 071              
        .dc.b   6, 1, 0                 ; func 072              
        .dc.b   8, 1, 0                 ; func 073              
        .dc.b   8, 1, 0                 ; func 074              
        .dc.b   4, 1, 1                 ; func 075              
        .dc.b   3, 1, 1                 ; func 076              
        .dc.b   0, 5, 0                 ; func 077              
        .dc.b   1, 1, 1                 ; func 078              
        .dc.b   0, 5, 0                 ; func 009              
;    Scrap Manager
        .dc.b   0, 1, 1                 ; func 080              
        .dc.b   0, 1, 1                 ; func 081              
        .dc.b   0, 0, 0                 ; func 082              
        .dc.b   0, 0, 0                 ; func 083              
        .dc.b   0, 0, 0                 ; func 084              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    fseler Manager
        .dc.b   0, 2, 2                 ; func 090              
        .dc.b   0, 0, 0                 ; func 091              
        .dc.b   0, 0, 0                 ; func 092              
        .dc.b   0, 0, 0                 ; func 003              
        .dc.b   0, 0, 0                 ; func 004              
        .dc.b   0, 0, 0                 ; func 005              
        .dc.b   0, 0, 0                 ; func 006              
        .dc.b   0, 0, 0                 ; func 007              
        .dc.b   0, 0, 0                 ; func 008              
        .dc.b   0, 0, 0                 ; func 009              
;    Window Manager
        .dc.b   5, 1, 0                 ; func 100              
        .dc.b   5, 1, 0                 ; func 101              
        .dc.b   1, 1, 0                 ; func 102              
        .dc.b   1, 1, 0                 ; func 103              
        .dc.b   2, 5, 0                 ; func 104              
        .dc.b   6, 1, 0                 ; func 105              
        .dc.b   2, 1, 0                 ; func 106              
        .dc.b   1, 1, 0                 ; func 107              
        .dc.b   6, 5, 0                 ; func 108              
        .dc.b   0, 0, 0                 ; func 009              
;    Resource Manger
        .dc.b   0, 1, 1                 ; func 110              
        .dc.b   0, 1, 0                 ; func 111              
        .dc.b   2, 1, 0                 ; func 112              
        .dc.b   2, 1, 1                 ; func 113              
        .dc.b   1, 1, 1                 ; func 114              
        .dc.b   0, 0, 0                 ; func 115              
        .dc.b   0, 0, 0                 ; func 006
        .dc.b   0, 0, 0                 ; func 007
        .dc.b   0, 0, 0                 ; func 008
        .dc.b   0, 0, 0                 ; func 009
;    Shell Manager
        .dc.b   0, 1, 2                 ; func 120
        .dc.b   3, 1, 2                 ; func 121
        .dc.b   1, 1, 1                 ; func 122
        .dc.b   1, 1, 1                 ; func 123
        .dc.b   0, 1, 1                 ; func 124
        .dc.b   0, 1, 2                 ; func 125



@\Rogue\Monster\
else
  echo "shar: Will not over write ACHAPP.S"
fi
if `test ! -s ACHSLIB.H`
then
echo "x - ACHSLIB.H"
cat > ACHSLIB.H << '@\Rogue\Monster\'
/*
     achslib.h

     871203    A C Howe       Implementation
     880109                   Deque stuff
*/

#define achslib_header

/* AES Exports */
extern short   gl_apid;
extern short   global [];
extern short   control [];

/* System Variables */
extern char DEFRES;
extern char MONITOR;  
extern char CONTERM;

/* Anthony's Stuff */
extern char    TERM [][3];
extern short   XMAX;
extern short   YMAX;
extern short   TABLEN;
extern void    GOTOXY ();     /* short, short */

extern void memmove();
extern void	strcat();
extern void strncpy();
extern unsigned strlen();
extern void strnput();

extern char *  STRTOK ();     /* char *, char * */
extern char *  NEXTTOK;
extern void    PUTDEC ();     /* short */
extern void    PUTLONG ();    /* long */
extern void    ULTOA ();      /* long, char * */
extern long    ULD ();        /* long , long */
extern long    FINDI ();      /* char *, short */
extern long    LFINDI ();     /* char *, short */

extern long gemdos ();
extern long xbios ();


/*   Atari System Variables (supervisor only) */
#define   SHOW_SHIFT     (CONTERM |= 0x08)
#define   HIDE_SHIFT     (CONTERM &= 0xf7)


/*   Basic Terminal Functions */
#define   BEEP           (Cconws (&TERM[0]))
#define   SET_TERMINAL   (Cconws (&TERM[1]))
#define   RST_TERMINAL   (Cconws (&TERM[2]))
#define   HOME_CURSOR    (Cconws (&TERM[3]))
#define   SCREEN_CLEAR   (Cconws (&TERM[4]))
#define   EOL_CLEAR      (Cconws (&TERM[5]))
#define   EOP_CLEAR      (Cconws (&TERM[6]))
#define   ON_CURSOR      (Cconws (&TERM[7]))
#define   OFF_CURSOR     (Cconws (&TERM[8]))
#define   HI_LITE        (Cconws (&TERM[9]))
#define   LO_LITE        (Cconws (&TERM[10]))
#define   INS_LINE       (Cconws (&TERM[11]))
#define   DEL_LINE       (Cconws (&TERM[12]))
#define   UP_CURSOR      (Cconws (&TERM[13]))
#define   DOWN_CURSOR    (Cconws (&TERM[14]))
#define   RIGHT_CURSOR   (Cconws (&TERM[15]))
#define   LEFT_CURSOR    (Cconws (&TERM[16]))

#define NULL        0
#define LNULL       0L
#define BLOCK       128            /* must be powers of 2 */
#define DBLOCK      256            /* double block */
#define CTRLZ       0x1a
#define RUB         0x7f

#define FILES       0x00
#define READONLY    0x01
#define HIDDEN      0x02
#define SYSTEM      0x04
#define VOLUME      0x08
#define DIRECTORY   0x10
#define ARCHIVE     0x20


typedef union cbuffer
{
     struct template
     {
          char max_line;
          char length;
          char line [BLOCK - 2 * sizeof (char)];
     } c;
     char buf [BLOCK];
} 
     CBUFFER;


typedef struct command_entry
{
     char *name;
     void (*function) ();
}
     COMMAND;


typedef struct dta_buf
{
     char dummy[21];      /* first 21 bytes not used */
     char attr;           /* file attribute */
     short ftime;         /* file time stamp */
     short fdate;         /* file date stamp */
     long fsize;          /* file size in bytes */
     char fname[14];      /* file name and extension */
}
     DTA;


typedef struct deque
{
     long *base;
     long *left;
     long *right;
     long *end;
}
     DEQUE;

#define   LEFT      0
#define   RIGHT     1

extern DEQUE * MKDEQ ();      /* long */
extern void    DEQADD ();     /* DEQUE *, short, long */
extern long    DEQDEL ();     /* DEQUE *, short */
extern void    RMDEQ ();      /* DEQUE * */


@\Rogue\Monster\
else
  echo "shar: Will not over write ACHSLIB.H"
fi
if `test ! -s ACHSLIB.S`
then
echo "x - ACHSLIB.S"
cat > ACHSLIB.S << '@\Rogue\Monster\'
;*** achslib.s
;
;    880507

;*** ASCII Code Equates

BS        ==        $08
HT        ==        $09
LF        ==        $0a
VT        ==        $0b
FF        ==        $0c
CR        ==        $0d
ZEOF      ==        $1a
ESC       ==        $1b
SPACE     ==        $20

;*** Atari ST Key Equates

;    Shift Bits
KRSHIFT   ==        $01
KLSHIFT   ==        $02
KCTRL     ==        $04
KALT      ==        $08
KCAPS     ==        $10
KRMOUSE   ==        $20
KLMOUSE   ==        $40

;    Function Keys
KF1       ==        $003b0000
KF2       ==        $003c0000
KF3       ==        $003d0000
KF4       ==        $003e0000
KF5       ==        $003f0000
KF6       ==        $00400000
KF7       ==        $00410000
KF8       ==        $00420000
KF9       ==        $00430000
KF10      ==        $00440000
 
KESC      ==        $0001001b
KRETURN   ==        $001c000d
KENTER    ==        $0072000d
KBS       ==        $000e0008
KDEL      ==        $0053007f

KCTLDEL   ==        $0053001f
KCTLLEFT  ==        $00730000
KCTLRIGHT ==        $00740000

KHOME     ==        $00470000
KUP       ==        $00480000          
KLEFT     ==        $004b0000
KRIGHT    ==        $004d0000
KDOWN     ==        $00500000
KTAB      ==        $000f0009
 
KINSERT   ==        $00520000
KUNDO     ==        $00610000
KHELP     ==        $00620000

;*** GEMDOS Equates

CCONIN    ==        1    ; standard console in       
CCONOUT   ==        2    ; standard console out
CAUXIN    ==        3    ; auxilary in
CAUXOUT   ==        4    ; auxilary out
CPRNOUT   ==        5    ; standard printer out
CRAWIO    ==        6    ; Raw I/O to standard I/O
CRAWIN    ==        7    ; Raw console in, no echo, no ctrl interpret
CNECIN    ==        8    ; Raw console in, no echo, ctrl interpreted
CCONWS    ==        9    ; write NULL terminated string to standard output 
CCONRS    ==        10   ; read edited string from standard input   
CCONIS    ==        11   ; check status of standard input


;*** Atari System Variables
;
;    NOTE: must be in Supervisor mode to modify.

_DEFRES   ==        $44a      ; default monitor resolution
_MONITOR  ==        $44c      ; monitor type
_CONTERM  ==        $484      ; attributes for the console system


;*** Terminal Definition Area

          .data
          .even
_TERM::
bell:     .dc.b     7,0,0           ; bell code string

tset:     .dc.b     0,0,0			; terminal init

trst:     .dc.b     0,0,0			; terminal de-init
                     
curhome:  .dc.b     ESC,'H',0      ; cursor home

clrscr:   .dc.b     ESC,'E',0      ; clear screen

clreol:   .dc.b     ESC,'K',0      ; clear to EOL

clreop:   .dc.b     ESC,'J',0      ; clear to EOP

curon:    .dc.b     ESC,'e',0      ; cursor on

curoff:   .dc.b     ESC,'f',0      ; cursor off

hilite:   .dc.b     ESC,'p',0      ; inverse on

lolite:   .dc.b     ESC,'q',0      ; inverse off

insline:  .dc.b     ESC,'L',0      ; insert line

delline:  .dc.b     ESC,'M',0      ; delete line

curup:    .dc.b     ESC,'A',0      ; cursor up

curdn:    .dc.b     ESC,'B',0      ; cursor down

currt:    .dc.b     ESC,'C',0      ; cursor right

curlt:    .dc.b     ESC,'D',0      ; cursor left



;*** GotoXY for VT-52 terminal
;
; e  short X coord
;    short Y coord
;
; x  none
;
;    Position cursor at .text coords (X,Y).

          .data
          .even
     
curaddr:  .dc.b     ESC,'Y',0      ; cursor addressing lead in

_XMAX::   .dc.w     80             ; max number of columns
_YMAX::   .dc.w     25             ; max number of rows
_TABLEN:: .dc.w     4              ; tab length to use
     
          .text
_GOTOXY:: 
          link      a6,#0
          movea.l   #curaddr,a0    ; pnt to cursor addressing string
          move.l    a0,-(sp)       ; put on stack
          move.w    #CCONWS,-(sp)  ; send string to terminal
          trap      #1             ;   do GEMDOS call
          addq.l    #6,sp          ; correct stack

          move.w    _YMAX,d1       ; point to ymax value
          move.w    10(a6),d0      ; get y argument
          bsr.s     GOTOXY1

          move.w    _XMAX,d1       ; point to xmax value
          move.w    8(a6),d0       ; get x argument
          bsr.s     GOTOXY1
          unlk      a6
          rts
GOTOXY1:
          ext.l     d0
          divu      d1,d0
          swap      d0             ; q = q mod max
          addi.w    #32,d0         ; q = q + offset

          move.w    d0,-(sp)
          move.w    #CCONOUT,-(sp)
          trap      #1
          addq.l    #4,sp
          rts



;void memmove( char* dest, char* source, long length )

          	.text 
_memmove::
			.cargs		.dest.l, .source.l, .len.l
          	movea.l   	.source(sp),a0      ; get source
          	movea.l   	.dest(sp),a1        ; get target
          	move.l    	.len(sp),d0      	; get length
          	beq.s     	.x             		; exit if length is zero 
          	cmpa.l    	a1,a0          		; check  for s < t
          	blt.s     	.2             		; move tail first
.1:       
          	move.b    	(a0)+,(a1)+    		; move source byte to target
          	subq.l    	#1,d0          		; decrement length
          	bne       	.1             		; loop till zero
          	bra.s		.x
.2:    
          	adda.l    	d0,a0          		; do tail first
          	adda.l    	d0,a1
.3:
          	move.b    	-(a0),-(a1)
          	subq.l    	#1,d0
          	bne       	.3
.x:
   		    rts
          


;void strnput( char* s, unsigned n )
          .text
_strnput::
          link      a6,#0
          movem.l   d3/a3, -(sp)
          movea.l   8(a6), a3
          adda.w    12(a6), a3
          cmpa.l    8(a6), a3
          beq.s     STRNPUT1
          move.b    (a3), d3
          clr.b     (a3)
STRNPUT1:
          move.l    8(a6), -(sp)
          move.w    #CCONWS, -(sp)
          trap      #1
          addq.l    #6, sp
          cmpa.l    8(a6), a3
          beq.s     STRNPUT2
          move.b    d3, (a3)
STRNPUT2:
          movem.l   (sp)+, d3/a3
          unlk      a6
          rts



;void strncpy( char* s1, char* s2, unsigned n )

		.text
_strncpy::      
		.cargs		.s1.l, .s2.l, .n.l
        movea.l		.s2(sp),a0 
        movea.l   	.s1(sp),a1 
        move.w    	.n(sp),d0  
        beq.s     	.X         
.1: