WOOKIE: A 68HC11 Emulator
by Kalle Anderson, Jason Buttron, Paul Clarke, Matt Enwald


Listing One
class PortConnection {
public:
    virtual void Write(byte_t) = 0;
};


Listing Two
// BRA instruction
void HC11:op_20h(HC11 *hc11) // HC11 passed in
{                            // because function is static
   signed char offset;
   hc11->_clock();
   offset = (signed)hc11->memory[hc11->PC];
   hc11->PC++;
   hc11->_clock();
   hc11->PC = hc11->PC + offset;
}


Listing Three
        ldaa    #%00000011  ; Set up RTI to 32 ms
        staa    $1026       ; PACTL
        ldaa    #%01000000
        staa    $1024       ; TMSK2 - enable RTI interrupts
        staa    $1025       ; TFLG2 - clear RTI flag

        rti_isr:

        inc   $1008         ; increment PORT D
        ldaa    #%01000000  ; re-enables the RTI
        staa    $1025       ; TFLG2 - 
        rti                 ; return


Listing Four
xirqstr  fcc     'XIRQ'

XIRQ_ISR:
    ldx     #xirqstr
    ldaa    #3
    staa    $1003   ;PORT C
    ldaa    0,x     
    staa    $1004   ;PORT B
    ldaa    #2       
    staa    $1003   ;PORT C
    ldaa    1,x     
    staa    $1004   ;PORT B
    ldaa    #1       
    staa    $1003   ;PORT C
    ldaa    2,x     
    staa    $1004   ;PORT B
    ldaa    #0       
    staa    $1003   ;PORT C
    ldaa    3,x     
    staa    $1004   ;PORT B                  
    rti


Listing Five
PULSE_ACCUMULATOR_RTI: 
    inc     $1008           ; increment PORT D
    bclr    $1025 %00010000 ; TFLG2 - Clear pulse accumulator flag
    rti


Listing Six
    
    LDX     #$1000            ;Base address for registers
    BSET    $20,x %00000011   ;TCTL1: OC5 set high at TCNT=TOC5=0
    BSET    $23,x %10000000   ;TFLG1: Clear OC1F flag
    BSET    $0C,x %00001000   ;OC1M: Have OC1 control OC5
    BSET    $0D,x %10000000   ;OC1D: Force OC5 pin low at OC1 compare
    LDD     #$7FFF            ;Since TOC5=0, setting TOC1 = $7FFF 
    STD     $16,x             ;     would give a 50% duty cycle






2


