home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Lattice 4.0 C startup under ARP
- ;
- ; Copyright (c) 1988, Scott Ballantyne
- ; May be freely used by users/supporters of ARP.
- ;
- ; Use at your own risk, of course.
- ;
- ; This code provides an arp 'wrapper' for Lattice, which opens arp,
- ; does some arp stuff, and calls an arp specific _main routine which does
- ; CLI processing using GADS() and WBench processing as usual for lattice.
- ; SDB
- ;
- INCLUDE "exec/types.i"
- INCLUDE "exec/alerts.i"
- INCLUDE "exec/nodes.i"
- INCLUDE "exec/lists.i"
- INCLUDE "exec/ports.i"
- INCLUDE "exec/libraries.i"
- INCLUDE "exec/tasks.i"
- INCLUDE "exec/ables.i"
- INCLUDE "libraries/dos.i"
- INCLUDE "libraries/dosextens.i"
- INCLUDE "libraries/arpbase.i"
- INCLUDE "workbench/startup.i"
- INCLUDE "exec/exec_lib.i"
- INCLUDE "libraries/dos_lib.i"
-
- AbsExecBase EQU 4
-
- xdef _XCEXIT ; exit(code)
- xref _LinkerDB ; a4 bias
- xref __BSSBAS ; start of BSS
- xref __BSSLEN ; length of BSS
-
- csect text,0,0,1,2 ; xref's now are 16-bit relocatable
-
- xref __main
- xref _MemCleanup
-
- start: move.l sp,a5 ; save old stack pointer
- movem.l d1-d6/a0-a6,-(sp) ; Seems lattice depends on this?
- move.l a0,a2 ; command
- move.l d0,d2 ; length
- lea.l _LinkerDB,a4 ; this is base register.
- lea.l __BSSBAS,a1 ; this is start of BSS
- moveq.l #0,d1
- move.l #__BSSLEN,d0 ; this is in long words
- bne.s start2
- bra.s cont
- start1: move.l d1,(a1)+ ; clear BSS
- start2: dbra d0,start1
- cont:
- move.l sp,__StackPtr(a4) ; save altered stack pointer
- move.l 4,a6
- move.l a6,_SysBase(a4) ; save exec base
- clr.l _WBenchMsg(a4)
- lea ARPNAME(pc),a1 ; get name of arp.library
- moveq.l #ArpVersion,d0
- SYSCALL OpenLibrary ; open it
- move.l d0,_ArpBase(a4) ; set up arp library pointer
- move.l d0,_DOSBase(a4) ; also as DOS pointer
- beq AhOhNoARP
- move.l d0,a0
- move.l GfxBase(a0),_GfxBase(a4) ; give free graphics.library
- move.l IntuiBase(a0),_IntuitionBase(a4) ; and free intuition.library
-
- move.l ThisTask(a6),a3 ; get task in A3
- move.l pr_CurrentDir(A3),_curdir(A4)
- tst.l pr_CLI(a3)
- beq fromWorkbench
- *******************
- * CLI startup
- * d0 = a0 = arpbase.
- * d2/a2 = length/command
- * a3 = *Process
- * a5 = initial SP
- *
- *******************
- move.l a5,d0 ; stack top
- sub.l 4(a5),d0 ; bottom
- add.l #128,d0 ; parms overflow
- move.l d0,__base(a4) ; save for stack checking
- move.l pr_CLI(a3),a0
- add.l a0,a0
- add.l a0,a0
- move.l cli_CommandName(a0),a1
- add.l a1,a1
- add.l a1,a1
-
- *------- build arg list
- *------- lattice wants "name arg1 arg2 arg3" etc.
- move.l d2,d0
- moveq.l #0,d1
- move.b (a1)+,d1 ; length of program name
- add.l d1,d0 ; add it to command name
- addq.l #1,d0 ; and allow for space
- clr.w -(sp) ; slop
- addq.l #1,d0 ; force even # bytes
- and.w #-2,d0 ; round up
- sub.l d0,a7 ; make space
- clr.w -2(a7,d0.w)
- *--------------
- * copy command to stack
- *--------------
- move.l d2,d0
- add.l d1,d2
- bra.s fixnul ; fix lattice NOCMD bug
- fixnul1:
- move.b 0(a2,d0.w),0(sp,d2.w)
- subq.l #1,d2
- fixnul: dbra d0,fixnul1
- move.b #' ',0(sp,d2.w)
- subq.l #1,d2
- copy_cmd:
- move.b 0(a1,d2.w),0(sp,d2.w)
- dbra d2,copy_cmd
- move.l sp,-(sp)
- bra main
- *=========================
- * Workbench version
- *=========================
-
- fromWorkbench:
- move.l TC_SPLOWER(a3),__base(a4) ; base for workbench
- add.l #128,__base(a4) ; parms overflow
- lea.l pr_MsgPort(a3),a0
- SYSCALL WaitPort ; wait for startup message
- lea pr_MsgPort(a3),a0
- SYSCALL GetMsg
- move.l _ArpBase(a4),a6 ; nuther lattice bug fix
- move.l d0,_WBenchMsg(a4)
- move.l d0,a2 ; get first argument
- move.l sm_ArgList(a2),d0
- beq.s do_cons
- move.l d0,a0
- move.l wa_Lock(a0),d1
- move.l d1,_curdir(A4)
- SYSCALL CurrentDir
- do_cons:
- move.l sm_ToolWindow(a2),d1 ; get the window argument
- beq.s do_main
- move.l #MODE_OLDFILE,d2
- SYSCALL Open
- move.l d0,_stdin(a4)
- beq.s do_main
- lsl.l #2,d0
- move.l d0,a0
- move.l fh_Type(a0),pr_ConsoleTask(a3)
- do_main:
- move.l _WBenchMsg(a4),a0
- pea _NULL(a4) ; argument to _main
- move.l sm_ArgList(a0),a0
- move.l wa_Name(a0),__ProgramName(a4)
- main: jsr __main(pc)
- moveq.l #0,d0
- bra.s exit2
-
- _XCEXIT:
- move.l 4(sp),d0 ; this is program rc
- exit2:
- move.l d0,-(sp)
- move.l __ONEXIT(a4),d0 ; somebody set a trap?
- beq.s exit21
- move.l d0,a0
- jsr (a0) ; call user def
- exit21: jsr _MemCleanup(pc) ; lattice function
- move.l 4,a6
- move.l _MathBase(a4),d0
- beq.s exit22
- move.l d0,a1
- SYSCALL CloseLibrary
- exit22:
- move.l _MathTransBase(a4),d0
- beq.s exit23
- move.l d0,a1
- SYSCALL CloseLibrary
- exit23: move.l _MathIeeeDoubBasBase(a4),d0
- beq.s wbp
- move.l d0,a1
- SYSCALL CloseLibrary
- wbp: tst.l _WBenchMsg(a4)
- beq.s shellrts
- move.l _ArpBase(a4),a6
- move.l _console_dev(a4),d1
- beq.s wbp1
- SYSCALL Close
- wbp1: move.l _stdin(a4),d1
- beq.s wbp2
- SYSCALL Close
- wbp2: move.l 4,a6
- FORBID
- move.l _WBenchMsg(a4),a1
- SYSCALL ReplyMsg
- shellrts:
- move.l _ArpBase(a4),a1
- SYSCALL CloseLibrary ; free ARP resources
- move.l (sp)+,d0 ; get exit code
- move.l __StackPtr(a4),sp
- movem.l (sp)+,d1-d6/a0-a6
- rts
-
- ************************
- * Called if no ARP
- ************************
- AhOhNoARP:
- lea.l dosname(pc),a1
- SYSCALL OpenLibrary
- tst.l d0
- beq.s noarp1
- move.l d0,a6
- SYSCALL Output
- move.l d0,d1
- beq.s noarp1
- lea.l alibmsg(pc),a0
- move.l a0,d2
- * move.l #alibmsg,d2 ; appears lattice asm can't handle this.
- * move.l #aliblng,d3 ; or this either.
- move.l #28,d3
- SYSCALL Write
- noarp1: move.l a5,sp
- rts
-
- dosname: dc.b 'dos.library',0
- alibmsg: dc.b 'you need '
- ARPNAME: ArpName
- dc.b ' V34+',10
- aliblng EQU *-alibmsg
-
- csect __MERGED,1,,2,2
-
- xref _DOSBase
- xref _MathBase
- xref _MathTransBase
-
- xdef _GfxBase
- xdef _IntuitionBase
-
- xdef _NULL,_SysBase,_LoadAddress,_console_dev,_WBenchMsg
- xdef _curdir,__mbase,__mnext,__msize,__tsize
- xdef __oserr,__OSERR,__FPERR,__SIGFPE,__ONERR,__ONEXIT,__ONBREAK
- xdef __SIGINT,__ECS
- xdef __ProgramName,__StackPtr,__base
- xdef _MathIeeeDoubBasBase
- xdef _ArpBase
- *
- _NULL dc.l 0
- __base: dc.l 0 ; base of stack
- __mbase: dc.l 0 ; base of memory pool
- __mnext: dc.l 0 ; next available memory location
- __msize: dc.l 0 ; size of memory pool
- __tsize: dc.l 0 ; total size
- __oserr: equ *
- __OSERR: dc.l 0
- __FPERR: dc.l 0
- __SIGFPE: dc.l 0
- __SIGINT: dc.l 0
- __ONERR: dc.l 0
- __ONEXIT: dc.l 0
- __ONBREAK: dc.l 0
- __ECS: dc.l 0 * extended character set flag
- _curdir: dc.l 0
- _console_dev: dc.l 0
- _SysBase: dc.l 0
- _ArpBase: dc.l 0 ; ARP library base pointer
- _GfxBase: dc.l 0 ; Graphics library base pointer
- _IntuitionBase: dc.l 0 ; Intuition library base pointer
- _LoadAddress: dc.l 0 * program load address
- _WBenchMsg: dc.l 0
- __StackPtr: dc.l 0
- _stdin: dc.l 0
- __ProgramName: dc.l 0
- _MathIeeeDoubBasBase: dc.l 0
-
- END
-
-