******************************************************************************* * Test file for exercising buf.x68 in easy68k. The buffer is initialized to * hold at most three values. * * To operate, type a number followed by enter: * 0 - perform a get, printing the result * -1 - exit * n - (other than 0 or -1), attempt to put * If a put is attempted on a full buffer, the message, 'Out of space' is * printed; if a get is attempted on an empty buffer, the message 'Empty' is * printed. * * For example: * 1 put a 1 * 2 put a 2 * 3 put a 3 * 4 put a 4 (fails) * Out of space * 0 get * 1 * 4 put a 4 * 0 get * 2 * 0 get * 3 * 0 get * 4 * 0 get (fails) * Empty * -1 exit ******************************************************************************* org $3000 START *********************************** MACROS ************************************ * macro for reading number read MACRO move.l #4,d0 ; read long from keyboard trap #15 ENDM * macro for printing (d1.l) as long print MACRO move.l #3,d0 ; print long trap #15 move.l #0,d0 ; print newline move.w #0,d1 trap #15 ENDM * macro for print string pstr MACRO lea \1,a1 move.l #13,d0 trap #15 ENDM ******************************************************************************* _main: move.w #(E_SPACE-SPACE),-(sp) pea SPACE jsr _new ; create a buffer in SPACE adda.l #6,sp ; user input-output loop loop read ; get number from user cmp.l #-1,d1 ; exit? beq exit tst.l d1 ; get? beq get ; otherwise, put put move.w d1,-(sp) ; call _put pea SPACE jsr _put adda.l #6,sp tst.l d0 ; output according to return beq loop pstr OUS ; nonzero return, so out of space bra loop get suba.l #2,sp ; make space on stack for return value move.l sp,a0 move.l a0,-(sp) ; push address of return value space pea SPACE jsr _get adda.l #8,sp tst.l d0 ; output according to return bne empty move.w (sp)+,d1 ; got a value, so print it andi.l #$FFFF,d1 print bra loop empty adda.l #2,sp ; empty, so print error message pstr MT bra loop exit move.l #9,d0 ; exit trap #15 ******************************************************************************* include "buf.x68" ; include entire source file ; (a limitation of easy68k) SPACE ds.b 20 ; for buffer; length of space is E_SPACE-SPACE E_SPACE ; error messages OUS dc.b 'Out of space',0 MT dc.b 'Empty',0 end START