chiark / gitweb /
test harness monitor thingum
authorian <ian>
Sun, 1 May 2005 15:11:55 +0000 (15:11 +0000)
committerian <ian>
Sun, 1 May 2005 15:11:55 +0000 (15:11 +0000)
iwjpictest/harness.asm

index 90b85048f6d6a26fbef3cd57252545849fb07c19..1b97e6d38ccb35d5faf085fc2762cbcd42fe78ad 100644 (file)
 ;
 ; state kept
 ;   E   current entry
-;   A   current address
+;   R   current address for reading  (Al = low byte; Ah = high_nybble)
+;   S   current address for setting  (Bl = low byte; Ah = high_nybble)
+;   T   top address nybble for next address set
+;   B   bitmask for bit operations
+;   F   flags: flag name   weight in FT
+;              printset    0x80           print every value we write into *S
 ;
-; prompt is `>'
+; prompt is NL CR > SPC initially, then SPC after each command
 ;
 ;  data entry
-;   0-9a-f    hex digit                      E := E<<4 | (digit value)
+;   0-9a-f    hex digit                      E := (E & 0x0f)<<4 | (digit value)
+;   =         confirm value                  print "=", E
+;   &         set bitmask                    B := E; print "&", B
+;
+;  address operations
+;   .         set setting address (low byte)   S := TE; print R, ",", S
+;   ,         set reading address (low byte)   R := TE; print R, ",", S
+;   '         set top address nybble           T := E & 0x0f
+;   `         set flags                        F := E; print "`", F
+;   @         confirm addresses and bitmask    print R, ",", S, "&", B
+;   ~         confirm flags and high nybble    print "`", F, "'", T
 ;
 ;  byte operations
-;   CR        enter address                  A := E
-;   =         confirm value                  print E
-;   @         confirm address                print A
-;   ?         read and display               print *A
-;   !         set whole byte                 *A := E
+;   SPC       read and display                 print *R
+;   RET, NL   set whole byte                   printset "S", (*S := E)
+;   TAB       read from setting address        print "s", *S
+;
 ;  bitwise operations
-;   SPC       read and mask                  print (*A & E)
-;   +         bitwise or (set bits)          *A := *A | E
-;   -         bitwise and-not (clear bits)   *A := *A & ~E
-;   ^         bitwise xor (toggle bits)      *A := *A ^ E
+;   ?         read and mask                    print "?", (*R & B)
+;   _         read and mask from setting addr  printset "_", (*S & B)
+;   +         bitwise or (set bits)            printset "+", (*S := *S | B)
+;   -         bitwise and-not (clear bits)     printset "-", (*S := *S & ~B)
+;   ^         bitwise xor (toggle bits)        printset "^", (*S := *S ^ B)
+;
+; `printset' means print if `printset' flag is set, otherwise just evaluate
 
+       nolist
        include         /usr/share/gputils/header/p18f458.inc
        include         insn-aliases.inc
+;      list
        radix           dec
 
-e              equ     0x70
-a              equ     FSR1L
-star_a         equ     INDF1
-hex_temp       equ     0x72
+;------------------------------------------------------------
+; variable declarations and RAM memory map
+
+r              equ     FSR0L
+rh             equ     FSR0H
+star_r         equ     INDF0
+
+s              equ     FSR1L
+sh             equ     FSR1H
+star_s         equ     INDF1
+
+perpicled_bit  equ     2
+
+e              equ     0x30
+t              equ     0x31
+b              equ     0x32
+f              equ     0x33
+
+hex_temp       equ     0x38
+original_op    equ     0x39
+value_temp     equ     0x3a
+
+f_printset_bit equ     7
+
+test_loc_a5    equ     0x40
+test_loc_5a    equ     0x42
+
+;----------------------------------------
+serial_literal macro char
+;      transmits char through the serial port
+; W            undefined       undefined
+       mov_lw          char
+       rcall           serial_write_char
+       endm
 
        code
 
 start
        rcall           led_green
        rcall           serial_setup
-       set_f           FSR1H
+
+       clr_f           e
+       mov_lw          0x80 ; PORTA
+       mov_wf          r
+       set_f           rh
+       mov_wf          s
+       set_f           sh
+       set_f           t
+       mov_lw          (1<<f_printset_bit)
+       mov_wf          f
+
+       mov_lw          0x5a
+       mov_wf          test_loc_5a
+       mov_lw          0xa5
+       mov_wf          test_loc_a5
+
+       serial_literal  10
+       serial_literal  13
+       serial_literal  '>'
+
 command_loop
-       mov_lw          '>'
-       rcall           serial_write_char
+       serial_literal  ' '
        rcall           serial_read_char
 
+       mov_wf          original_op
+
 check_last set 0
 checkequal macro value, label
        add_lw          check_last-value
@@ -57,16 +126,27 @@ checkatleast macro minvalue, label ; if it takes, W gets char-minvalue
 check_last set minvalue
        endm
 
-       checkequal      10, command_return
-       checkequal      13, command_return
-       checkequal      '=', command_confirm_entry
-       checkequal      '@', command_confirm_address
-       checkequal      '?', command_byte_read
-       checkequal      '!', command_byte_write
-       checkequal      ' ', command_bitwise_read_mask
-       checkequal      '+', command_bitwise_or
-       checkequal      '-', command_bitwise_and_not
-       checkequal      '^', command_bitwise_xor
+       ; data entry
+       checkequal      '=',    command_byte_confirm
+       checkequal      '&',    command_byte_bitmask_set
+       ; address operations
+       checkequal      '.',    command_address_set_setting
+       checkequal      ',',    command_address_set_reading
+       checkequal      39,     command_address_set_high
+       checkequal      '`',    command_flags_set
+       checkequal      '@',    command_address_confirm
+       checkequal      '~',    command_confirm_flags_highnyb
+       ; byte operations
+       checkequal      ' ',    command_byte_read
+       checkequal      10,     command_byte_set
+       checkequal      13,     command_byte_set
+       checkequal      9,      command_byte_read_fromset
+       ; bit operations
+       checkequal      '?',    command_bitwise_read_mask
+       checkequal      '_',    command_bitwise_read_mask_fromset
+       checkequal      '+',    command_bitwise_or
+       checkequal      '-',    command_bitwise_and_not
+       checkequal      '^',    command_bitwise_xor
 
        checkatleast    'f'+1, command_wrong
        checkatleast    'a', command_letterhexdigit
@@ -79,6 +159,9 @@ command_wrong
 command_endswitch
        bra             command_loop
 
+;--------------------
+; command digits
+
 command_letterhexdigit
        add_lw          10
 command_digit
@@ -89,56 +172,156 @@ command_digit
        mov_wf          e
        bra             command_loop
 
+;--------------------
+; common routines for command loop
+
+command_endswitch_set
+       mov_wf          star_s
+       bt_f_if0        f, f_printset_bit
+       bra             command_endswitch_set_ifnot_print
+       mov_wf          value_temp
+       mov_fw          original_op
+       rcall           serial_write_char
+       mov_fw          value_temp
 command_endswitch_phex
        rcall           serial_write_hex
+command_endswitch_set_ifnot_print
        bra             command_endswitch
 
-command_return
-       mov_ff          a,e
+;--------------------
+; address commands
+
+command_address_set_setting
+       mov_ff          t,sh
+       mov_ff          e,s
+       bra             command_address_confirm
+
+command_address_set_reading
+       mov_ff          t,rh
+       mov_ff          e,r
+       bra             command_address_confirm
+
+command_address_set_high
+       mov_ff          e,t
+       bra             command_endswitch
+
+command_flags_set
+       mov_ff          e,f
+       rcall           confirm_flags
        bra             command_endswitch
 
-command_confirm_entry
+command_address_confirm
+       rcall           confirm_address
+       rcall           confirm_bitmask
+       bra             command_endswitch
+
+;----------
+confirm_address
+;      prints R, ",", S
+; W            undefined       undefined
+; hex_temp     undefined       undefined
+       mov_fw          rh
+       rcall           serial_write_hex_digit
+       mov_fw          r
+       rcall           serial_write_hex
+       mov_lw          ','
+       rcall           serial_write_char
+       mov_fw          sh
+       rcall           serial_write_hex_digit
+       mov_fw          s
+       rcall           serial_write_hex
+       bra             command_endswitch
+
+command_confirm_flags_highnyb
+       rcall           confirm_flags
+       serial_literal  39
+       mov_fw          t
+       rcall           serial_write_hex_digit
+       bra             command_endswitch
+
+;----------
+confirm_bitmask
+;      prints "&", B
+; W            undefined       undefined
+; hex_temp     undefined       undefined
+       serial_literal  '&'
+       mov_fw          b
+       rcall           serial_write_hex
+       return
+
+;----------
+confirm_flags
+;      prints "`", F
+; W            undefined       undefined
+; hex_temp     undefined       undefined
+       serial_literal  '`'
+       mov_fw          f
+       rcall           serial_write_hex
+       return
+
+;--------------------
+; byte operations
+
+command_byte_confirm
+       serial_literal  '='
        mov_fw          e
        bra             command_endswitch_phex
 
-command_confirm_address
-       mov_fw          a
-       bra             command_endswitch_phex
+command_byte_bitmask_set
+       mov_ff          e, b
+       rcall           confirm_bitmask
+       bra             command_endswitch
 
 command_byte_read
-       mov_fw          star_a
+       mov_fw          star_r
        bra             command_endswitch_phex
 
-command_byte_write
+command_byte_set
+       mov_lw          'S'
+       mov_wf          original_op
        mov_fw          e
-       mov_wf          star_a
-       bra             command_endswitch
+       bra             command_endswitch_set
+
+command_byte_read_fromset
+       serial_literal  's'
+       mov_fw          star_s
+       bra             command_endswitch_phex
+
+;--------------------
+; bit operations
 
 command_bitwise_read_mask
+       serial_literal  '?'
        mov_fw          e
-       and_wfw         star_a
+       and_wfw         star_r
+       bra             command_endswitch_phex
+
+command_bitwise_read_mask_fromset
+       serial_literal  '_'
+       mov_fw          e
+       and_wfw         star_s
        bra             command_endswitch_phex
 
 command_bitwise_or
        mov_fw          e
-       ior_wff         star_a
-       bra             command_endswitch
+       ior_wfw         star_s
+       bra             command_endswitch_set
 
 command_bitwise_xor
        mov_fw          e
-       xor_wff         star_a
-       bra             command_endswitch
+       xor_wfw         star_s
+       bra             command_endswitch_set
 
 command_bitwise_and_not
        mov_fw          e
        com_w
-       and_wff         e
-       bra             command_endswitch
+       and_wfw         star_s
+       bra             command_endswitch_set
 
 ;----------------------------------------
 led_green
-       bc_f            TRISD, 2        ; enable per-pic led output
-       bs_f            LATD, 2         ; set per-pic led output
+       bc_f            TRISD, perpicled_bit
+       bs_f            LATD, perpicled_bit
        return
 
 
@@ -146,20 +329,20 @@ led_green
 serial_setup
 ; W            undefined       undefined
 ; TXSTA                undefined       }
-       mov_lw          0x26    ; asynch xmit enabled, high baud rate, 8-bit,
-       mov_wf          TXSTA   ;
-       mov_lw          129     ; 9600bps (with BRGH)
-       mov_wf          SPBRG
+       mov_lw          (1<<TXEN) | (1<<BRGH) | (1<<TRMT)
+       mov_wf          TXSTA   ; asynch xmit enabled, high baud rate, 8-bit,
+       mov_lw          129
+       mov_wf          SPBRG   ; 9600bps (with BRGH)
 serial_receive_reset ;from serial_read_if_error
-       mov_lw          0x90    ; enable serial port, continuous rx, 8-bit,
-       mov_wf          RCSTA   ;       no pending errors etc.
+       mov_lw          (1<<SPEN) | (1<<CREN)
+       mov_wf          RCSTA   ; enable serial port, continuous rx, 8-bit
        return
 
 ;----------------------------------------
 serial_write_char
 ; W            character       undefined
 serial_write_char_loop
-       bt_f_if0        PIR1,TXIF
+       bt_f_if0        PIR1, TXIF
        bra             serial_write_char_loop
        mov_wf          TXREG
        return
@@ -169,11 +352,11 @@ serial_read_char
 ; on errors, sets LED red and transmits *
 ; W            undefined       character read
 serial_read_char_loop
-       bt_f_if0        PIR1,RCIF
+       bt_f_if0        PIR1, RCIF
        bra             serial_read_char_loop
        mov_fw          RCSTA
-       and_lw          CREN | FERR | OERR
-       xor_lw          CREN
+       and_lw          (1<<CREN) | (1<<FERR) | (1<<OERR)
+       xor_lw          (1<<CREN)
        bra_nz          serial_read_if_error
        mov_fw          RCREG
        return
@@ -191,12 +374,12 @@ serial_write_hex
 ; W            value           undefined
 ; hex_temp     undefined       undefined
        mov_wf          hex_temp
-       rcall           serial_write_hex_digit
-       rcall           serial_write_hex_digit
+       rcall           serial_write_hex_1digit_for_both
+       rcall           serial_write_hex_1digit_for_both
        return
 
 ;--------------------
-serial_write_hex_digit
+serial_write_hex_1digit_for_both
 ;      transmits top nybble of hex_temp in hex
 ;      through serial port, as above, and swaps nybbles
 ;              Before          After
@@ -204,6 +387,11 @@ serial_write_hex_digit
 ; hex_temp     BBBBaaaa        aaaaBBBB        (BBBB was sent)
        swap_f  hex_temp
        mov_fw  hex_temp
+;...
+;--------------------
+serial_write_hex_digit
+;      transmits bottom nybble of W in hex
+; W            ????VVVV        undefined
        and_lw  0x0f
        sub_lw  10
        sub_lw  0
@@ -211,55 +399,6 @@ serial_write_hex_digit
        add_lw  'a'-('0'+10)
 serial_write_hex_digit_ifnot_ge10
        add_lw  '0'+10
-       rcall   serial_write_char
-
-       end
-
-
-       end
-
-       add_lw          -13
-       bra_z           
-                                             ; '2'     '0'-1   '9'+1
-       add_lw          -('9'+1)              ; 256-C   256-11  0C
-       bra_c           command_ifgtdecdigit
-       add_lw          ('9'+1)-('0')         ; 2       
-       bra_nc          command_ifltdecdigit
-       
-
-       bcf             TRISC, 6, 0     ; enable TXD output (RC6)
-
-
-
-       bcf             TRISC, 5, 0     ; enable FCO output (RC5)
-
-
-loop
-
-       ; set a bit which says how fast the led
-       ; should flash and count down from 2^(that bit)
-       bsf             COUNTOUTER, OUTEREXP, 0
-delayouter_loop
-
-delayinner_loop
-       copybit         PORTB, 3, LATA,  0x08           ; A data
-       copybiti        PORTD, 7, TRISA, 0x08           ; A enable
-       copybiti        PORTA, 6, LATD,  0x10           ; D
-       copybit         PORTB, 4, LATC,  0x20           ; serial FC
-       copybit         PORTC, 7, LATC,  0x40           ; serial data
-                                               ; 6 x copybit @6 = 24cy
-
-       decfsz          COUNTINNER, 1, 0        ; 1 cycle
-       goto            delayinner_loop         ; 2 cycles (skipped or not)
-; exited delayinner_loop                       ; total: 27cy * 256 = 6912cy
-
-                                               ; each cycle 0.2us
-                                               ; so each inner loop is ~1.4ms
-
-       decfsz          COUNTOUTER, 1, 0
-       goto            delayouter_loop
-; exited delayouter_loop
-
-       goto            loop
+       bra     serial_write_char
 
        end