$BASE 10T
$PAGELENGTH 64T
$PAGEWIDTH 132T

;
; MC68705K1 POD "J2" SOFTWARE
;
;
; MC68HC805J2 MCU PROGRAM
;

;
; SYSTEM EQUATES HERE
;

PORTA     EQU       $00                 ;PORT A DATA REG
PORTB     EQU       $01                 ;PORT B DATA REG

DDRA      EQU       $04                 ;PORT A DATA DIRECTION REG
DDRB      EQU       $05                 ;PORT B DATA DIRECTION REG

TCSR      EQU       $08                 ;TIMER CONTROL & STATUS REG
TCR       EQU       $09                 ;TIMER COUNTER REG

COP       EQU       $FF0                ;COP REGISTER

;
; RAM EQUATES
;
          ORG       $0090

;
; EPROM STARTS HERE
;
          ORG       $0700

          FCB       "This code is Copyright (C) 1991 "
          FCB       "by P&E Microcomputer Systems, Inc. "
          FCB       "All rights reserved. "

DATA      FCB       $10

;
; EXTERNAL INTERRUPTS HERE
;

IRQ       BIH       IRQX
          LDX       #$10
IRQ1      CLC
          BRCLR     5,PORTB,IRQ2
          SEC
IRQ2      ROL       $91
          ROL       $90
          BCLR      4,PORTB
          BCC       IRQ3
          BSET      4,PORTB
IRQ3      DECX
          BEQ       IRQ6
IRQ4      BIL       IRQ4
IRQ5      BIH       IRQ5
          BRA       IRQ1
IRQ6      LDX       $90
          LDA       $91
          CPX       #$01
          BEQ       IRQ7
          CPX       #DDRB
          BNE       IRQ8
IRQ7      AND       #$03
          ORA       #$10
IRQ8      STA       ,X
          LDA       $92
          STA       $90
          LDA       $93
          STA       $91
IRQ9      BIL       IRQ9
          BSET      4,PORTB
IRQX      RTI

;
; PORT & VARIABLE INITIALIZATION HERE
;

INIT      CLRA
          STA       PORTA
          STA       DDRA
          STA       PORTB
          BSET      4,PORTB
          BSET      4,DDRB
          STA       $92
          STA       $90
          LDA       DATA
          STA       $93
          STA       $91
          CLRX
          RTS

;
; PROGRAM STARTS HERE
;

RESET     RSP
          BSR       INIT
          CLI
RESET1    LDA       PORTA
          CMP       $92
          BEQ       RESET2
          STA       $90
          STA       $92
          BCLR      4,PORTB
RESET2    LDA       PORTB
          AND       #$0F
          ORA       DATA
          CMP       $93
          BEQ       RESET3
          STA       $91
          STA       $93
          BCLR      4,PORTB
RESET3    BRA       RESET1


; MASK OPTION REGISTER
;
          ORG       $0F00
          FCB       %00000000           ;J2 NATIVE MODE, EDGE SENSITIVE IRQ
                                        ;COP TIMER DISABLED

;
; INTERRUPT VECTORS HERE
;
          ORG       $0FF8
          FDB       RESET               ;TIMER INTERRUPT
          FDB       IRQ                 ;EXTERNAL INTERRUPT
          FDB       RESET               ;SOFTWARE INTERRUPT
          FDB       RESET               ;RESET

          END
