home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / rbfhandler.asm < prev    next >
Encoding:
Assembly Source File  |  1992-08-21  |  2.5 KB  |  70 lines

  1. * rbfhandler.asm. Example interrupt handler for rbf.
  2. *
  3. * Assembled with Howesoft Adapt 680x0 Macro Assembler Rel. 1.0
  4. * hx68 from: rbfhandler.asm to rbfhandler.o INCDIR include:
  5. * blink from lib:c.o rbf.o rbfhandler.o to rbf lib lib:lc.lib lib:amiga.lib
  6. *
  7.     INCLUDE "exec/types.i"
  8.     INCLUDE "hardware/custom.i"
  9.     INCLUDE "hardware/intbits.i"
  10.  
  11.         XDEF    _RBFHandler
  12.  
  13. JSRLIB MACRO
  14.        XREF _LVO\1
  15.        JSR  _LVO\1(A6)
  16.        ENDM
  17.  
  18. BUFLEN    EQU    256
  19.  
  20.        STRUCTURE RBFDATA,0
  21.         APTR   rd_task
  22.         ULONG  rd_signal
  23.         UWORD  rd_buffercount
  24.         STRUCT rd_charbuffer,BUFLEN+2
  25.         STRUCT rd_flagbuffer,BUFLEN+2
  26.         STRUCT rd_name,32
  27.         LABEL RBFDATA_SIZEOF
  28.  
  29. * Entered with:
  30. *  D0 == scratch
  31. *  D1 == INTENAT & INTREQR (scratch)
  32. *  A0 == custom chips (scratch)
  33. *  A1 == is_Data which is RBFDATA structure (scratch)
  34. *  A5 == vector to our code (scratch)
  35. *  A6 == pointer to ExecBase (scratch)
  36. *
  37. * Note - This simple handler just receives one buffer full of serial
  38. * input data, signals main, then ignores all subsequent serial data.
  39. *
  40.     section code
  41.  
  42. _RBFHandler:                            ;entry to our interrupt handler
  43.  
  44.         MOVE.W  serdatr(A0),D1          ;get the input word (flags and char)
  45.  
  46.         MOVE.W  rd_buffercount(A1),D0   ;get our buffer index
  47.         CMPI.W  #BUFLEN,D0              ;no more room in our buffer ?
  48.         BEQ.S   ExitHandler             ;yes - just exit (ignore new char)
  49.         LEA.L   rd_charbuffer(A1),A5    ;else get our character buffer address
  50.         MOVE.B  D1,0(A5,D0.W)           ;store character in our character buffer
  51.         LEA.L   rd_flagbuffer(A1),A5    ;get our flag buffer address
  52.         LSR.W   #8,d1                   ;shift flags down
  53.         MOVE.B  D1,0(A5,D0.W)           ;store flags in flagbuffer
  54.  
  55.         ADDQ.W  #1,D0                   ;increment our buffer index
  56.         MOVE.W  D0,rd_buffercount(A1)   ;   and replace it
  57.         CMPI.W  #BUFLEN,D0              ;did our buffer just become full ?
  58.         BNE.S   ExitHandler             ;no - we can exit
  59.         MOVE.L  A0,-(SP)                ;yes - save custom
  60.         MOVE.L  rd_signal(A1),D0        ;get signal allocated in main()
  61.         MOVE.L  rd_task(A1),A1          ;and pointer to main task
  62.         JSRLIB  Signal                  ;tell main we are full
  63.         MOVE.L  (SP)+,A0                ;restore custom
  64.                                         ;Note: system call trashed D0-D1/A0-A1
  65. ExitHandler:
  66.         MOVE.W  #INTF_RBF,intreq(A0)    ;clear the interrupt
  67.         RTS                             ;return to exec
  68.  
  69.         END
  70.