Classic Computer Magazine Archive PROGRAM LISTING: 86-03/BITZ.M65


10 ; BITZ, LISTING 2
20 ; BY DON LEBOW
30 ; (c) 1985, ANTIC PUBLISHING
40 ;
50       *=  $0600
60 ;
70 ;EQUATES...z page free bytes
80 ;
90 FIRST =   $CB     ;first number
0100 SECOND = $CC    ;optional mask
0110 RESULT = $CD    ;what we got
0120 FLAGS = $CE     ;status register
0130 FLAGOPT = $CF   ;user option
0140 STRING = $D0    ;string address pointer
0150 ;
0160 ;MODULE 1 (USR 1536....)
0170 ;The Bit Shifter
0180 ;
0190     PLA         ;Pop argument count
0200     CMP #2      ;2 means 2 parameters passed
0210     BEQ DOUBLE  ;so go to double byte routine
0220 ;
0230 ;One byte routine
0240 ;
0250     LDA FLAGOPT ;carry option
0260     BEQ CLEAR   ;0 means user has specified 'clear carry'
0270     LDA FLAGS   ;otherwise, get the old status register
0280     PHA         ;push it
0290     PLP         ;pull it to current status
0300     JMP DOTARGET ;detour around the CLC instruction
0310 ;
0320 CLEAR
0330     CLC 
0340 ;
0350 DOTARGET
0360     PLA 
0370     PLA         ;target byte
0380     NOP         ;opcode poked from Basic:  'accumulator' mode
0390     STA RESULT  ;save new byte
0400 ;
0410 ;Get the flags and return
0420 ;
0430 RETURN
0440     PHP         ;push Status Register
0450     PLA         ;get it back
0460     STA FLAGS   ;put it where we can get at it
0470     RTS         ;done
0480 ;
0490 ;
0500 ;Double byte routine
0510 ;
0520 ;
0530 DOUBLE
0540     CLC         ;default clear
0550     PLA 
0560     PLA 
0570     STA FIRST   ;target
0580     PLA 
0590     PLA 
0600     STA SECOND  ;mask
0610     LDA FIRST
0620     NOP         ;opcode poked from Basic:'Zero Page' mode
0630     .BYTE SECOND ;z page mask
0640     STA RESULT  ;save result
0650     JMP RETURN  ;common return
0660 ;
0670 ;
0680 ;MODULE 2 (USR 1581,ADR(B$),NUM)
0690 ;Byte to Binary String for Basic
0700 ;
0710     PLA         ;pop argument count
0720     PLA 
0730     STA STRING+1 ;hi byte of string address
0740     PLA 
0750     STA STRING  ;and lo
0760     PLA 
0770     PLA         ;number to convert
0780     LDY #7      ;index string
0790 ROTATE
0800     LSR A       ;shift right to carry
0810     PHA         ;save current value
0820     BCC ZERO    ;zero in carry flag
0830 ;
0840 ;Put "1" in string
0850 ;
0860 ONE
0870     LDA #'1
0880     STA (STRING),Y
0890     JMP NEXT
0900 ;
0910 ;Put "O" in string
0920 ;
0930 ZERO
0940     LDA #'O
0950     STA (STRING),Y
0960 ;
0970 ;Next bit
0980 ;
0990 NEXT
1000     PLA         ;get the current value back
1010     DEY         ;decrement index
1020     BPL ROTATE  ;done all 8 bits?
1030 ;
1040 ;All finished
1050 ;
1060     RTS 

Back to previous page