
 1010  *--------------------------------
 1020  *      IMPLEMENTING BSR, BRA, AND LEA OPCODES
 1030  *      USING THE 'BRK' VECTOR WITH THE
 1040  *      AUTOSTART ROM
 1050  *
 1060  *      ADAPTED FROM AN ARTICLE IN "LAB LETTERS"
 1070  *           BY A. SATO
 1080  *--------------------------------
 1090  MON.PC     .EQ $3A,3B
 1100  MON.XREG   .EQ $46
 1110  MON.YREG   .EQ $47
 1120  *--------------------------------
 1130  BRK.VECTOR .EQ $3F0,3F1
 1140  *--------------------------------
 1150  MON.BRK     .EQ $FA59
 1160  MON.RESTORE .EQ $FF3F
 1170  *--------------------------------
 1180  SETUP
 1190         LDA #BREAK.INTERPRETER
 1200         STA BRK.VECTOR
 1210         LDA /BREAK.INTERPRETER
 1220         STA BRK.VECTOR+1
 1230         RTS
 1240  *--------------------------------
 1250  BREAK.INTERPRETER
 1260         LDY MON.PC+1     PICK UP ADDRESS OF THIRD BYTE
 1270         LDX MON.PC
 1280         BNE .1       BACK UP TO SECOND BYTE
 1290         DEY
 1300  .1     DEX
 1310         STX PNTR     MODIFY ADDRESS IN GET.THIS.BYTE SUBROUTINE
 1320         STY PNTR+1
 1330         JSR GET.THIS.BYTE
 1340         TAY          OPCODE BYTE
 1350         JSR GET.NEXT.BYTE
 1360         PHA          ADDR-LOW BYTE
 1370         JSR GET.NEXT.BYTE
 1380         TAX
 1390         PLA
 1400         SEC          ADDR-HIGH BYTE
 1410         ADC PNTR     COMPUTE EFFECTIVE ADDRESS
 1420         STA EFF.ADDR
 1430         TXA
 1440         ADC PNTR+1
 1450         STA EFF.ADDR+1
 1460  *--------------------------------
 1470         CPY #$20     CLASSIFY OPCODE
 1480         BEQ BSR
 1490         CPY #$4C
 1500         BEQ BRA
 1510         CPY #$AE
 1520         BEQ LEA
 1530         STY MON.YREG
 1540         JMP MON.BRK
 1550  *--------------------------------
 1560  BSR    LDA PNTR+1   PUSH RETURN ADDRESS ON STACK
 1570         PHA
 1580         LDA PNTR
 1590         PHA          AND DO BRA
 1600  *--------------------------------
 1610  BRA    JSR MON.RESTORE
 1620         JMP *-*
 1630  EFF.ADDR   .EQ *-2
 1640  *--------------------------------
 1650  LEA    JSR GET.NEXT.BYTE  POINT AT NEXT INSTRUCTION
 1660         JSR MON.RESTORE   RESTORE A-REG AND STATUS
 1670         LDY EFF.ADDR      ADDR-LO IN Y
 1680         LDX EFF.ADDR+1    ADDR-HI IN X
 1690         JMP (PNTR)
 1700  *--------------------------------
 1710  GET.NEXT.BYTE
 1720         INC PNTR
 1730         BNE GET.THIS.BYTE
 1740         INC PNTR+1
 1750  GET.THIS.BYTE
 1760         LDA $FFFF    (FILLED IN)
 1770  PNTR   .EQ *-2
 1780         RTS
 1790  *--------------------------------
 1800  MSG    .EQ 0,1
 1810  JMP.COUT JMP $FDED
 1820         .MA LEA
 1830         >BRK LDX,]1
 1840         .EM
 1850         .MA BSR
 1860         >BRK JSR,]1
 1870         .EM
 1880         .MA BRA
 1890         >BRK JMP,]1
 1900         .EM
 1910         .MA BRK
 1920         BRK
 1930         ]1 ]2-:1
 1940  :1
 1950         .EM
 1960  TEST   >LEA MESSAGE
 1970         STX MSG+1
 1980         STY MSG
 1990         LDY #0
 2000  .1     LDA (MSG),Y
 2010         PHA
 2020         ORA #$80
 2030         >BSR JMP.COUT
 2040         INY
 2050         PLA
 2060         BPL .1
 2070         LDA #$8D     CARRIAGE RETURN
 2080         >BRA JMP.COUT
 2090  MESSAGE .AT /THIS IS MY MESSAGE/

