;
; EXTENDED REL MODULE WITH DEPENDENCIES, BYTECODE SEGMENT, AND INIT
;
 INCLUDE INC/PLASMA.INC
OPPAGE EQU FETCHOP+7
;
; EXT REL HEADER
;
RESFLAGS EQU 0
 INCLUDE INC/EXTHEADER.INC
;
; ADD MODULE DEPENDENCIES
; (DCI BACKWARDS HI/LO BIT FROM REL FILE)
;
 MSB ON
 ASC "CMDSY"
 MSB OFF
 ASC "S"
;
; EXTERNALS USED FROM CMDSYS
;
 EXTRN PUTS
 EXTRN PUTLN
;
; TERMINATE DEPENDENCY LIST WITH ZERO
;
 DB 0
;
; ROM ROUTINES
;
PRBYTE EQU $FDDA
COUT EQU $FDED
CROUT EQU $FD8E
;
; LANGUAGE CARD SWITCHES
;
LCRDEN EQU $C080
LCWTEN EQU $C081
ROMEN EQU $C082
LCRWEN EQU $C083
LCBNK2 EQU $00
LCBNK1 EQU $08
;
; BRK HANDLER REGISTER SAVE LOCATIONS
;
BRKA EQU $45
BRKX EQU $46
BRKY EQU $47
BRKP EQU $48
BRKS EQU $49
BRKPCL EQU $3A
BRKPCH EQU $3B
BRKVEC EQU $3F0
CTRLY EQU $3F8
;
; DATA AND 6502 CODE SEGMENT
; ==========================
;
; PRINT INLINE STRINGZ
;
SAVETMP DW 0
PRSTR LDA TMPL
 STA SAVETMP
 LDA TMPH
 STA SAVETMP+1
 PLA
 STA TMPL
 PLA
 STA TMPH
 LDY #$01
 LDA (TMP),Y
PRLOOP ORA #$80
 JSR COUT
 INY
 LDA (TMP),Y
 BNE PRLOOP
 TYA
 CLC
 ADC TMPL
 STA TMPL
 LDA #$00
 ADC TMPH
 PHA
 LDA TMPL
 PHA
 LDA SAVETMP+1
 STA TMPH
 LDA SAVETMP
 STA TMPL
 RTS
;
; DUMP INTERPRETER STATE
;
VMDUMP JSR CROUT
 JSR PRSTR
 ASC " XP="
 DB 0
 LDA BRKX
 JSR PRBYTE
 JSR PRSTR
 ASC " IP"
 DB 0
 LDA OPPAGE
 CMP #$D0
 BEQ NOTAUX
 LDA #'X'+$80
 JSR COUT
NOTAUX LDA #'='+$80
 JSR COUT
 LDA BRKY
 CLC
 ADC FETCHOP+1
 PHA
 LDA #$00
 ADC FETCHOP+2
 JSR PRBYTE
 PLA
 JSR PRBYTE
 JSR PRSTR
 ASC " FP="
 DB 0
 LDA IFPH
 JSR PRBYTE
 LDA IFPL
 JMP PRBYTE
;
; SYSTEM BRK HANDLER
;
SYSBRK DB $4C ; JMP OPCODE
SYSBRKVEC DW 0 ; SYS BRK HANDLER ADDRESS
;
; CHECK BRK ADDRESS FOR NEXTOP
;
BRKCHK LDA BRKPCH
 BNE SYSBRK
 LDA BRKPCL
 CMP #NEXTOP+2
 BNE SYSBRK
 LDA BRKX ; CHECK FOR ESTK PTR VALID
 CMP #$21
 BCS MON
 LDA $C000
 CMP #$83 ; CTRL-C
 BNE BRKRET
 LDA $C010
MON JSR VMDUMP
 JMP -151 ; JUMP INTO MONITOR
YCONT PLA
 PLA
BRKRET BIT LCRDEN+LCBNK2
 LDA BRKP
 PHA
 LDY BRKY
 INY
 LDX BRKX
 LDA OPPAGE
 CMP #$D0
 BNE XOP
 LDA BRKA
 PLP
 JMP FETCHOP
XOP LDA BRKA
 PLP
 JMP $F9
;
; INITIALIZE MODULE AND RETURN MOD KEEP STATUS
;
INITMSG STR "DEBUGGER INSTALLED."
INIT LDA BRKVEC ; SAVE CURRENT BRK VECTOR TO SYS VECTOR
 STA SYSBRKVEC
 LDA BRKVEC+1
 STA SYSBRKVEC+1
 LDA #>BRKCHK
 STA BRKVEC
 LDA #<BRKCHK ; INSERT BRK_CHK ROTUINE INTO BRK VECTOR
 STA BRKVEC+1
 LDA #$00 ; BRK INSTRUCTION
 STA NEXTOP ; OVERWRITE NEXTOP
;
; SET ALT RD MEM ENABLE ENTRYPOINT
;
 LDA #$8D ; STA $C003
 STA $F9
 LDA #$03
 STA $FA
 LDA #$C0
 STA $FB
 LDA #$4C ; JMP FETCHOP
 STA $FC
 LDA #FETCHOP
 STA $FD
 LDA #$00
 STA $FE
;
; SET CTRL-Y TO RESUME VM
;
 LDA #$4C ; JMP OPCODE
 STA CTRLY
 LDA #>YCONT
 STA CTRLY+1
 LDA #<YCONT
 STA CTRLY+2
;
; PRINT INIT MESSAGE THROUGH CMDSYS
;
 LDA #>INITMSG
 LDY #<INITMSG
 DEX
 STA ESTKL,X
 STY ESTKH,X
 JSR PUTS
 JSR PUTLN
;
; RETURN MODKEEP TO LEAVE THE MODULE IN MEMORY
;
 LDA #>MODKEEP
 LDY #<MODKEEP
 DEX
 STA ESTKL,X
 STY ESTKH,X
 RTS
;
; EXT REL DEFSEG
;
 INCLUDE INC/EXTDEFSEG.INC
