Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!cmcl2!husc6!rutgers!ucla-cs!sdcrdcf!burdvax!bpa!cbmvax!carolyn
From: carolyn@cbmvax.cbm.UUCP (Carolyn Scheppner)
Newsgroups: comp.sys.amiga
Subject: Re: Wanted: Good Debugger (hopefully PD)
Message-ID: <1234@cbmvax.cbmvax.cbm.UUCP>
Date: Wed, 14-Jan-87 17:46:04 EST
Article-I.D.: cbmvax.1234
Posted: Wed Jan 14 17:46:04 1987
Date-Received: Thu, 15-Jan-87 22:32:56 EST
References: <2846@gitpyr.gatech.EDU>
Reply-To: carolyn@cbmvax.UUCP (Carolyn Scheppner)
Organization: Commodore Technology, West Chester, PA
Lines: 248
Keywords: Broke Desperate Frustrated

In article <2846@gitpyr.gatech.EDU> wutka@gitpyr.gatech.EDU (Mark Wutka) writes:
>Anybody know of a good debugger that is inexpensive (VERY inexpensive) ?
>
>I have been toying around with the Macro Assembler and I can't even open
>the Intuition Library. It bombs when I jump to OpenLibrary and I can't
>figure out why. I can't even tell if it is the jump that does it or if
>it bombs within OpenLibrary since I can't tell where my program is
>loaded into memory so I can't track it very well. Anybody know of a debugger
>that would help ?
>

   Metascope by Metadigm is good.  Meanwhile, here is one of my clumsy
assembler examples.  It really didn't need an OpenLibrary since it
only uses Exec and Dos calls and both of those libraries are opened
by the startup code it is linked with.  But I added code to open
and close graphics.library just to show you how to do it.

   The example is meant to demo how to Open a file (PRT: in this case),
Write() to it, fprintf() to it, and Close it.  It also shows how to use
printf() and getchar() from assembler. (Handy for debugging)

   Please excuse any stupid code.  I use 68000 assembler very little and
I don't yet know all of the instructions. 

   carolyn

*-------------------------------------------------------------------------
*
* assorted.asm  ---  Simple printer output using PRT: file
*    Shows use of Open(), Write(), Close() and also
*       interfaces with Amiga.lib's printf(),fprintf(), and getchar()
*    Also shows use of OpenLibrary()
* Must be linked with startup code (AStartup.obj)
*

           INCLUDE  "exec/types.i"
           INCLUDE  "libraries/dos.i"


* Macros *

LREF        MACRO
            XREF     _LVO\1
            ENDM

* This one calls a library routine
* You must place the library's base in a6 before using this

LJSR        MACRO
            JSR      _LVO\1(a6)
            ENDM


* Imported Labels *

   XREF     _AbsExecBase
   XREF     _DOSBase              * Opened by startup code
   XREF     _printf
   XREF     _fprintf
   XREF     _getchar

   LREF     OpenLibrary
   LREF     CloseLibrary
   LREF     Open
   LREF     Write
   LREF     Close
   LREF     Delay


* Exported Labels *

   XDEF     _main               * AStartup.obj does JSR to this label
   XDEF     _GfxBase            * For demo of OpenLibrary

            CODE

* Code *

_main:
            movem.l   d0/a6,-(a7)        Save the registers
            move.l    a7,myInitSP        Save initial stack pointer

* Demo Opening a Library *
            move.l    _AbsExecBase,a6    Exec Base to a6
            move.l    #0,d0              Version to d0
            lea       GfxName,a1         Ptr to library name in a1
            LJSR      OpenLibrary        Call OpenLibrary
            move.l    d0,_GfxBase        Ptr to _GfxBase
            bne       gfxOK              Valid base - continue

            lea.l     erOpenLib,a0       Else ptr to error message
            move.l    a0,erStr           Store in erStr
            bra       cleanup            Abort

* Demo _printf the base address *
gfxOK:
            move.l    a7,tempSP          Save stack pointer
            move.l    _GfxBase,-(a7)     Push _GfxBase
            pea.l     libstr             Push address of format string
            jsr       _printf            Print it
            move.l    tempSP,a7          Fix stack
            

            move.l    #1,d0              Print debugging variables
            jsr       mydebug

            move.l    _DOSBase,a6        Was opened by AStartup.obj
            lea.l     prName,a0          Addr of file name PRT:
            move.l    a0,d1              Place in d1
            move.l    #MODE_NEWFILE,d2   New file
            LJSR      Open               Attempt Open
            move.l    d0,prFile          Store filehandle
            bne.s     dowrite            Branch if OK

            lea.l     erOpenPr,a0        Addr of Open error msg
            move.l    a0,erStr           Store in erStr
            bra       cleanup            Go to cleanup

dowrite:

       ;--- Try a simple Write() to printer file
            move.l    _DOSBase,a6        (not really needed - still there)
            move.l    prFile,d1          File handle
            lea.l     testStr,a0         Address of string or buffer
            move.l    a0,d2              Put in d2
            move.l    #12,d3             Length of testStr
            LJSR      Write              Write string to file
            move.l    d0,wLen            Write Length (-1 = error)
            bpl       dofprintf          Branch if OK

            lea.l     erWrite,a0         Ptr to error message
            move.l    a0,erStr           Store in erStr
            bra       cleanup            Abort

dofprintf:

       ;--- Try formatted write to printer using _fprintf()

            move.l    testNum2,-(a7)     Push variable 2 on stack
            move.l    testNum1,-(a7)     Push variable 1 on stack
            pea.l     testFStr           Push addr of format string
            move.l    prFile,-(a7)       Push printer file handle
            jsr       _fprintf           Formatted print to printer
            addq.l    #8,a7              Fix the stack (8 + 8 = 4 longs)
            addq.l    #8,a7               (could have saved/restored instead)


            move.l    #0,erStr           All OK - error string ptr = NULL
cleanup:
            move.l    erStr,d0           Any errors ?
            beq.s     cleanup2           No

            move.l    erStr,-(a7)        Push ptr in erStr on stack
            jsr       _printf            Print error string
            addq.l    #4,a7              Fix stack

cleanup2:
            move.l    #2,d0              Print debugging variables
            jsr       mydebug

            move.l    prFile,d1          If printer file was not opened
            beq.s     cleanup3              skip the Close
            move.l    _DOSBase,a6        Else Close it
            LJSR      Close

            movea.l   _GfxBase,a1        If graphics.library was not opened
            beq.s     cleanup3              skip the CloseLibrary
            move.l    _AbsExecBase,a6    Else ExecBase to a6
            LJSR      CloseLibrary          and CloseLibrary

cleanup3:
            move.l    #3,d0              Print debugging variables
            jsr       mydebug

            pea.l     pressStr           Push addr of pressStr
            jsr       _printf            Print prompt string
            addq.l    #4,a7              Fix stack

            jsr       _getchar           Waits for a 
            addq.l    #4,a7              Throw away char returned on stack

            move.l    myInitSP,a7        Restore initial stack pointer
            movem.l   (a7)+,d0/a6        Restore registers
            rts


mydebug:
            move.l    a7,tempSP          Save stack pointer
            move.l    a7,-(a7)           Push stack
            move.l    prFile,-(a7)       Push prFile
            move.l    _DOSBase,-(a7)     Push _DOSBase
            move.l    d0,-(a7)           Push checkpoint
            pea.l     debugStr           Push debug string
            jsr       _printf            Print the pushed variables
            move.l    tempSP,a7          Restore stack pointer
            rts


            DATA

            CNOP  0,4
prFile      DC.L  0
            CNOP  0,2
_GfxBase    DC.L  0
            CNOP  0,2
testNum1    DC.L  1
            CNOP  0,2
testNum2    DC.L  2
            CNOP  0,2
testStr     DC.B  'Test string',10,0
            CNOP  0,2
testFStr    DC.B  'num1 = %ld  num2 = %ld',10,0
            CNOP  0,2
pressStr    DC.B  'Press  to exit.',10,0
            CNOP  0,2
libstr      DC.B  'The library base is $%lx',10,0
            CNOP  0,2
debugStr    DC.B  'checkpoint=%ld  stack=%ld  prFile=%ld  _DOSBase=%ld',10,0
            CNOP  0,2
prName      DC.B  'PRT:',0
            CNOP  0,2
GfxName     DC.B  'graphics.library',0

* Error messages *
            CNOP  0,2
erOpenPr    DC.B  'Can not open printer',10,0
            CNOP  0,2
erWrite     DC.B  'Error writing to printer',10,0
            CNOP  0,2
erOpenLib   DC.B  'Can not open library',10,0

* Uninitialized variables *
            CNOP  0,2
wLen        DS.L  1
            CNOP  0,2
erStr       DS.L  1
            CNOP  0,2
myInitSP    DS.L  1
            CNOP  0,2
tempSP      DS.L  1

            END
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CBM   >>Amiga Technical Support<<
                     UUCP  ...{allegra,caip,ihnp4,seismo}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=