[mod.computers.68k] A solution to the Command buffer problem?

RDROYA01@ULKYVX.BITNET.UUCP (07/06/86)

Hello again,

I think the bugs are worked out of the command window function I wrote about
yesterday.  I have been able to compile and link a module from within the
editor and save all compiler linker screen output in a window on the screen.
This means that errors in line XX can be found quite fast.  I also
discovered that DDT will run in one of these windows.  Screen output is a
little slower than normal because the editor is allocating space as it
prints, but the slowdown is only in printing and is not that great.  I'm
still interested in hearing from anyone who has been working on a similar
function or anyone interested in how I got this to work.  I'm sure I could
improve the char output code but probably won't if it doesn't break.

The solution to the problem in my last message hinged on the two stack
pointers and the status register.  First the outchar routine needed to run
in user mode, but I discovered that for my machine I needed to dissable
interrupts. Second the routine needed to exit in supervisor mode.  Third
the loaded program needed its own user stack, but the line allocation
routines also needed their own user stack.  The following routine is called
whenever a bios conout is requested.  It sends the char in d1 to _outchar
in the uEmacs program, which interprets the char as a command or an
insertable character, then allocates space for the char as necessary and
inserts it into the built-in [Command] buffer.

        .globl  _outchar        * C code to negotiate allocation in uEmacs

* brk() tests to see whether the (sp) is greater than the requested memory
* space.  It returns an error (to sbrk()) if it is not.

conout: move.l  a7,ra7s * save ssp for later
        link    a6,#-6  * is this stack frame necessary?
        move    d1,-2(a6)
        move.w  #$0700,sr       * set user mode without interrupts
        move.l  a7,ra7u * save current user (sp)
        move.l  _usp,a7 * replace old usp saved on entry to background ccp
        move    -2(a6),(a7)
        jsr     _outchar
        move.l  ra7u,a7 * replace background program's usp
        move.l  d0,rd0  * save returned value for later
        move.w  #62,d0  * back to superviser state
        trap    #2      * so the rte in fix or at the end won't bomb
        move.w  ra7s,a7 * replace entering ssp
        move.l  rd0,d0  * put returned value from _outchar back in d0
        cmp     #$ff,d0 * _outchar could not allocate space
        beq     fix     * cleanup and exit
        unlk    a6
        rte

        .bss
        .even
rd0:    ds.l    1
ra7u:   ds.l    1       * storage for register user a7 in conout
ra7s:   ds.l    1       * storage for register system a7 in conout
_usp:   ds.l    1       * value of USP for _ccp and fix

Any suggestions for improvement would be appreciated.  I still think it's
better to negotiate with the existing ccp for service than to rewrite it.
The ccp on my system cannot be rewritten since the bios is hardwired to a
specific address and can only be merged into a new system, not linked.  The
code to parse a line, load a file, expand wildcards, run a submit file,
supply built-in commands, or allow a multiple command line would take up
much more space than the trick procedure above which depends on the
existing ccp to do the work.