.TITLE BINARY FORMATTING .IDENT /V1.01/ .NLIST TOC,SYM .ENABL LC ; Part of Sira Paper Tape Punch Despooler. ; ; COPYRIGHT(C) 1981,1982 Sira Institute Ltd., ; South Hill, Chislehurst, Kent, BR7 5EH, England. ; ; Author: C.J. Doran ; ; Assemble as: ; >MAC PPPBINARY=PPPBINARY ;+ ; Convert buffer to formatted binary. ; On entry: %3-> start of buffer, ; %4 is no of bytes, ; %2-> end of buffer. ; Adjust these on exit to describe the new buffer. ; ; Binary format bytes are: ; 1 ; 0 ; byte count lo ; byte count hi ; data 1 ; ... ; data n ; checksum ; ; Where checksum = -(sum of bytes from starting 1 to data byte n) ; Byte count includes the 4 prefix bytes. ;- .PSECT CODE,I,RO BINARY::TST %4 ; Check for zero-length record BEQ 20$ ; requiring no action ADD #4,%4 ; Add 4 prefix bytes to count MOV %4,%1 ; Copy count SWAB %1 ; Select hi byte MOVB %1,-(%3) ; Last prefix byte SWAB %1 ; Count lo byte MOVB %1,-(%3) ; Precedes it CLRB -(%3) ; Then starting word MOVB #1,-(%3) ; 0000001 first MOV %3,%0 ; Copy pointer CLR -(SP) ; Make space for checksum 10$: MOVB (%0)+,%5 ; Get byte ADD %5,@SP ; Add into checksum SOB %1,10$ ; Through buffer NEG @SP ; Negate MOVB (SP)+,(%2)+ ; For final checksum byte INC %4 ; Note checksum byte 20$: RTS PC ; Done .END