Protocols for Niche Area Networks
by Jaromir Chocholac

Listing One
        LDA     #M_PRIOR                ;Get message priority
        ORA     DL_control              ;Combine DL_SYNC and message priority
        STA     DL_control              ;Store result
        LDA     #SWNODE                 ;Get Switch node address
        STA     DL_push_buffer          ;Store node address
        LDX     #SW_ON                  ;Get switch on command
        STX     DL_push_buffer+1        ;Store command
        CLR     DL_push_buffer+2        ;No data is needed
        LDA     #DL_CMD_NEXT            ;Get command send message 
        STA     DL_command              ;Issue command & start sending
        BRSET   DL_BUSY,DL_command,*    ;Wait here until command completed


Listing Two
app_loop:       
        SEI                             ;Prevent interrupts
        BRSET   DL_BUSY,DL_command,MAIN_continue ;Branch if no new
*                                                Push field arrived
        LDX     DL_push_buffer+1        ;Fetch application command value
        LSLX                            ;Scale jump vector
        LSLX                            ;Entries scaled by 4
        TXA                             ;Prepare vector for checking
        SUB     #START-app_table        ;Check if command is in the range
        BMI     command_ok              ;Branch if command is OK
        CLRX                            ;Clear vector if not
command_ok:
        LDA     DL_push_buffer+2        ;Fetch Push data
        BSET    DL_BUSY,DL_command      ;Set waiting flag
*                                        (cleared by new Push field arrival)
        CLI                             ;Allow interrupts
        JMP     app_table,X             ;Jump using received control
*                                                field as an index
*
app_table:
        JMP     service_000             ;Service control value %000
        SWI                             ;Dummy byte to align jump entry
        JMP     service_001             ;Service control value %001
        SWI                             ;Dummy byte to align jump entry
        JMP     service_010             ;Service control value %010
        SWI                             ;Dummy byte to align jump entry
*
START  EQU     *
                
********************************************************************
*                            No action (%000)                       *
*********************************************************************
service_000:    
        JMP     >app_loop               ;No action, resume looping...
*********************************************************************
*                        SWITCH ON (%001)                           *
*********************************************************************
service_001:
        LDX     #1                      ;Get command to be returned
        CLRA                            ;Get data to be returned
        BSET    LOAD_ON,PORTA           ;Load switch on
update_link:
        SEI                             ;Prevent interrupts    
        STX     DL_pull_buffer+1        ;Update Pull command field
        STA     DL_pull_buffer+2        ;Update Pull data field
        CLI                             ;Allow interrupts
        JMP     >app_loop               ;Resume looping...
*********************************************************************
*                       SWITCH OFF (%010)                           *
*********************************************************************
service_010:
        LDX     #2                      ;Get command to be returned
        CLRA                            ;Get data to be returned
        BCLR    LOAD_ON,PORTA           ;Load switch off
        BRA     update_link             ;Update date link 







2


