home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol071 / bitbang.src < prev    next >
Encoding:
Text File  |  1984-04-29  |  3.1 KB  |  73 lines

  1. ; Routines to set, test and reset a bit within a byte
  2. ;
  3. ; Declarations are as follows:
  4. ;
  5. ;    type       byte = 0..255;
  6. ;
  7. ;    procedure  bset( var x: byte; y: byte ); external;
  8. ;    procedure reset( var x: byte; y: byte ); external;
  9. ;    function   test(     x: byte; y: byte ): boolean; external;
  10. ;
  11. ; If these routines are passed an integer instead of a byte (reference
  12. ; parameters only) these routines will set/reset the low order byte.
  13. ;
  14.         entry    bset,reset,test
  15.  
  16. bset:   pop      d              ; get return address
  17.         pop      b              ; get variable size & bit to set
  18.         pop      h              ; get variable address
  19.         dcr      b              ; check for var of size 1
  20.         cnz      sizpatch       ; otherwise fix the pointer
  21.         xra      a              ; clear acc
  22.         stc                     ; set carry
  23.         mov      b,c            ; counter (0..7) to b
  24.         inr      b              ; increment counter ( now between 1 & 8 )
  25. setloop:adc      a              ; shift left 1 bit
  26.         djnz     setloop        ; now A has the bit in the correct position
  27.         ora      m              ; set the new bit
  28.         mov      m,a            ; return to the var
  29.         xchg                    ; hl <- return address
  30.         xra      a              ; clear acc
  31.         pchl                    ; return
  32.  
  33. reset:  pop      d              ; get return address
  34.         pop      b              ; get variable size & bit to reset
  35.         pop      h              ; get variable address
  36.         dcr      b              ; check for var of size 1
  37.         cnz      sizpatch       ; otherwise fix the pointer
  38.         xra      a              ; clear acc
  39.         stc                     ; set carry
  40.         mov      b,c            ; counter (0..7) to b
  41.         inr      b              ; increment counter ( now between 1 & 8 )
  42. rstloop:adc      a              ; shift left 1 bit
  43.         djnz     rstloop        ; now A has the bit in the correct position
  44.         cma                     ; complement accumulator
  45.         ana      m              ; set the new bit
  46.         mov      m,a            ; return to the var
  47.         xchg                    ; hl <- return address
  48.         xra      a              ; clear acc
  49.         pchl                    ; return
  50.  
  51. test:   pop      h              ; get return address
  52.         pop      d              ; get variable and bit to test
  53.         xra      a              ; clear acc
  54.         stc                     ; set carry
  55.         mov      b,e
  56.         inr      b              ; increment counter ( now between 1 & 8 )
  57. tstloop:adc      a              ; shift left 1 bit
  58.         djnz     tstloop        ; now A has the bit in the correct position
  59.         ana      d              ; set the new bit
  60.         jrz      testdone       ; test is done if we have a zero
  61.         xra      a              ; clear acc
  62.         stc                     ; and set carry to indicate true
  63. testdone:
  64.         pchl                    ; return
  65.  
  66.  
  67.  
  68. sizpatch:
  69.         dcx      h              ; point to the low byte of a two byte number
  70.         ret                     ; and return.
  71.  
  72.         end
  73.