chiark / gitweb /
make points_local_init core code into subroutine, for future wagglers
authorian <ian>
Tue, 6 May 2008 23:37:56 +0000 (23:37 +0000)
committerian <ian>
Tue, 6 May 2008 23:37:56 +0000 (23:37 +0000)
detpic/common.inc
detpic/misc.asm
detpic/morse.messages
detpic/points.asm

index 6fd5d7787f0f2c061971f17cc1667eff239153c4..afbd0556f6899858863b6dfc1c541416f1d788ea 100644 (file)
@@ -292,6 +292,28 @@ load_perpic_tblptr macro flash_map_base, perpic_entry_size
        clr_f   TBLPTRU         ; TBLPTR* -> our point data
        endm
 
+;----------------------------------------
+; invocation macro for outpins_local_init_part{1,2}, see misc.asm
+outputs_local_init macro picno2thingmap, maxthings, thingix2latbit, bkthingix2portnumbitnum
+
+       load_perpic_tblptr picno2thingmap, maxthings/8
+       mov_lfsr thingix2latbit-1, 0
+       mov_lw  maxthings/8
+
+       call    outpins_local_init_part1
+
+       mov_lw  bkthingix2portnumbitnum >> 8
+       mov_wf  TBLPTRH         ; TBLPTR* -> point port/bit data
+       mov_lw  bkthingix2portnumbitnum & 0xff
+       mov_wf  TBLPTRL
+
+       mov_lfsr thingix2latbit-1, 0 ; FSR0 -> last bit (and previous LAT*)
+       mov_lw  maxthings
+
+       call    outpins_local_init_part2
+
+       endm
+
 ;----------------------------------------------------------------------
 ; PINSPECS stuff
 ;
index dfb3d69ae84115c220498b0c74c219e12a3b58f6..0e209a81def110e600771e2970b68c493ca3a3e5 100644 (file)
@@ -106,4 +106,116 @@ debugbyte @
        mov_ff  dsave_fsr0+1, FSR0H
        return
 
+;------------------------------------------------------------
+outpins_local_init_part1 @
+; Initialises a table of output pins
+;      TBLPTR          picno2<thing>map        (presence bitmap)
+;      FSR0            <thing>ix2latbit - 1    (start of output table)
+;      W               max<thing>s / 8         (table sizes)
+; outpins_local_init_part2 @
+;      TBLPTR          bk<thing>ix2portnumbitnum       (phys pins)
+;      FSR0            <thing>ix2latbit - 1    (start of output table)
+;      W               max<thing>s             (table sizes)
+; Caller must use both, and set variables as above on each entry.
+;
+; Input table is as made by writeasm_outpin
+; Result table is series of 2-byte entries,
+;   0th byte is  bottom byte of LAT* address
+;   1st byte is  single-bit mask for the relevant pin
+
+;  Internals:
+;      We do this in two stages.
+;      Firstly, we scan the bitmap for this pic, setting
+;       <thing>ix2latbit to 0xff,0x00 for used points and 0x00,0x00
+;       to unused ones.
+;      Secondly, we scan the bk<thing>ix2portnumbitnum, adjusting
+;       <thing>ix2latbit to have actually correct data.
+;      Doing it like this avoids having to constantly recompute
+;       individual TBLPTR*'s.
+
+;       On entry FSR0 -> this bit and LAT*
+;        points just at last thing we've filled in
+
+       mov_wf  t               ; t = byte counter
+;...
+outpins_init_byte_loop
+       mov_lw  8               ; W = bit counter
+       tblrd_postinc_fixup     ; TABLAT = bitmap data being processed
+;...
+outpins_init_bit_loop
+       clr_f   PREINC0         ; FSR0 -> LAT*[current] := 0
+       rrc_f   TABLAT
+       bt_f_if1 STATUS,C
+       set_f   INDF0           ; FSR0 -still-> LAT*[current] := 0xff
+
+       clr_f   PREINC0         ; FSR0 -> bit[current] := 0
+
+       dec_w_ifnz
+       bra     outpins_init_bit_loop
+       dec_f_ifnz t
+       bra     outpins_init_byte_loop
+;... end of loop:
+
+
+;      We've scanned for points used on this board;
+;      now find the actual pins.
+
+       return             ; caller will reset
+outpins_local_init_part2 @ ;  TBLPTR, FSR0 and W (see above)
+
+       bt_f_if1 idloc1,idloc1_boarddet
+       add_wff TBLPTRL
+
+       set_f   FSR2H           ; FSR2 -> some SFR, will point to LAT/TRIS
+       mov_lfsr bitnum2bit+7, 1 ; FSR1 -> bitnum2bit+7
+
+       mov_wf  t               ; t = loop counter
+;...
+outpins_init_portbit_loop
+       tblrd_postinc_fixup     ; TABLAT = portnum4 || bitnum4
+
+       bt_f_if0 PREINC0,7      ; zero?, FSR0 -> LAT*[this]
+       bra     outpins_init_portbit_endif_used
+;...
+outpins_init_portbit_if_used
+       mov_fw  TABLAT
+       bra_n   outpins_initing_bad_object
+
+       ior_lw  0xf8            ; W -> bit value for bit
+       mov_wf  FSR1L           ; FSR1 -> bit value for bit
+
+       swap_fw TABLAT          ; W = bitnum4 || portnum4
+       and_lw  0x0f            ; W = portnum4
+       add_lw  LATA & 0xff     ; W = LAT*
+       mov_wf  POSTINC0        ; LAT*[this] := LAT, FSR0 -> bit[this]
+       mov_wf  FSR2L           ; FSR2 -> LAT*
+
+       mov_fw  INDF1           ; W = bit
+       mov_wf  POSTDEC0        ; bit[this] = bit, FSR0 -> LAT*[this]
+       com_w                   ; W = ~bit
+       and_wff INDF2           ; LAT* &= ~bit, ie pin set to L (still Z)
+
+       pin_vh  pall_pt0reverse ; but pt0 pin is backwards, set to H
+                               ;  (still Z, unless we've done this already)
+                               ;  (we don't care about doing this far too
+                               ;   many times here.)
+       mov_lw  TRISA-LATA
+       add_wff FSR2L           ; FSR2 -> TRIS*
+       com_fw  INDF1           ; W = ~bit
+       and_wff INDF2           ; TRIS* &= ~bit, ie pin set to not Z
+
+       set_f   FSR1L           ; FSR1 -> bitnum2bit+7, again
+outpins_init_portbit_endif_used
+       ; so now we move on to the next one
+       mov_fw  POSTINC0        ; FSR0 -> bit[this]
+
+       dec_f_ifnz t
+       bra     outpins_init_portbit_loop
+
+       return
+
+;----------
+outpins_initing_bad_object
+       panic   morse_OF
+
   include final.inc
index 823df326ca835724c078df4d9873b905325916df..5a23384d0061bd2e24dfb52dbb4d41d27fbd116b 100644 (file)
@@ -34,6 +34,7 @@ TI9                           ; for iwj
 # Miscellaneous
 E                              ; `expected'; we were told to panic
 T                              ; master paniced because slave paniced
+OF     ::t,TBLPTRH             ; Flash mentions object not on board
 
 # Regarding communications from the host
 HX     ::t                     ; host sent unknown command
@@ -94,6 +95,5 @@ PI    points:pointmsg,T3CON           ; Unexpected Timer 3 interrupt
 PU     points:pointmsg                 ; Firing nonexistent point
 PC                                     ; Firing point when CDU empty
 PS     points:pointslave,points:pointmsg ; Firing point on nonexistent board
-PF     ::t                             ; Flash mentions point not on board
 PX                                     ; Host sent >2-byte POINT command
 PA                                     ; POINTED when already firing
index 1c5be4a25a33dc3cf65ee27053e233c138d77b68..8f711a19b84a824270af3e4381ce1459affe96f3 100644 (file)
@@ -27,8 +27,7 @@ cdu_inittimeout       equ     750 ; ms
 
 ptix2latbit equ 0x300 ; has to be a multiple of 0x100
 ptix2latbit_section udata ptix2latbit
-  res maxpoints * 2    ; LAT* and bit
-                       ; for unused point, 0x00 and 0x00
+  res maxpoints * 2    ; as produced by outpin_local_init
 
   udata_acs
 pointslave             res     1
@@ -131,103 +130,10 @@ points_local_init @
 
        rcall   point_timer_init
 
-;      We do this in two stages.
-;      Firstly, we scan the bitmap for this pic, setting
-;       ptix2latbit to 0xff,0x00 for used points and 0x00,0x00
-;       to unused ones.
-;      Secondly, we scan the bkptix2portnumbitnum, adjusting
-;       ptix2latbit to have actually correct data.
-;      Doing it like this avoids having to constantly recompute
-;       individual TBLPTR*'s.
-
-       mov_lfsr ptix2latbit-1, 0 ; FSR0 -> this bit and LAT*
-                                 ;  points just at last thing we've filled in
-
-       load_perpic_tblptr picno2ptmap, maxpoints/8
-
-       mov_lw  maxpoints/8
-       mov_wf  t               ; t = byte counter
-;...
-points_init_byte_loop
-       mov_lw  8               ; W = bit counter
-       tblrd_postinc_fixup     ; TABLAT = bitmap data being processed
-;...
-points_init_bit_loop
-       clr_f   PREINC0         ; FSR0 -> LAT*[current] := 0
-       rrc_f   TABLAT
-       bt_f_if1 STATUS,C
-       set_f   INDF0           ; FSR0 -still-> LAT*[current] := 0xff
-
-       clr_f   PREINC0         ; FSR0 -> bit[current] := 0
-
-       dec_w_ifnz
-       bra     points_init_bit_loop
-       dec_f_ifnz t
-       bra     points_init_byte_loop
-;... end of loop:
-
-;      We've scanned for points used on this board;
-;      now find the actual pins.
-
-       mov_lw  bkptix2portnumbitnum & 0xff
-       bt_f_if1 idloc1,idloc1_boarddet
-       add_lw  maxpoints
-       mov_wf  TBLPTRL
-
-       mov_lw  bkptix2portnumbitnum >> 8
-       mov_wf  TBLPTRH         ; TBLPTR* -> point port/bit data
-
-       set_f   FSR2H           ; FSR2 -> some SFR, will point to LAT/TRIS
-       mov_lfsr bitnum2bit+7, 1 ; FSR1 -> bitnum2bit+7
-       mov_lfsr ptix2latbit-1, 0 ; FSR0 -> last bit (and previous LAT*)
-
-       mov_lw  maxpoints
-       mov_wf  t               ; t = loop counter
-;...
-points_init_portbit_loop
-       tblrd_postinc_fixup     ; TABLAT = portnum4 || bitnum4
-
-       bt_f_if0 PREINC0,7      ; zero?, FSR0 -> LAT*[this]
-       bra     points_init_portbit_endif_used
-;...
-points_init_portbit_if_used
-       mov_fw  TABLAT
-       bra_n   point_initing_bad_point
-
-       ior_lw  0xf8            ; W -> bit value for bit
-       mov_wf  FSR1L           ; FSR1 -> bit value for bit
-
-       swap_fw TABLAT          ; W = bitnum4 || portnum4
-       and_lw  0x0f            ; W = portnum4
-       add_lw  LATA & 0xff     ; W = LAT*
-       mov_wf  POSTINC0        ; LAT*[this] := LAT, FSR0 -> bit[this]
-       mov_wf  FSR2L           ; FSR2 -> LAT*
-
-       mov_fw  INDF1           ; W = bit
-       mov_wf  POSTDEC0        ; bit[this] = bit, FSR0 -> LAT*[this]
-       com_w                   ; W = ~bit
-       and_wff INDF2           ; LAT* &= ~bit, ie pin set to L (still Z)
-       pin_vh  pall_pt0reverse ; but pt0 pin is backwards, set to H
-                               ;  (still Z, unless we've done this already)
-       mov_lw  TRISA-LATA
-       add_wff FSR2L           ; FSR2 -> TRIS*
-       com_fw  INDF1           ; W = ~bit
-       and_wff INDF2           ; TRIS* &= ~bit, ie pin set to not Z
-
-       set_f   FSR1L           ; FSR1 -> bitnum2bit+7, again
-points_init_portbit_endif_used
-       ; so now we move on to the next one
-       mov_fw  POSTINC0        ; FSR0 -> bit[this]
-
-       dec_f_ifnz t
-       bra     points_init_portbit_loop
+ outputs_local_init picno2ptmap, maxpoints, ptix2latbit, bkptix2portnumbitnum
 
        return
 
-;----------
-point_initing_bad_point
-       panic   morse_PF
-
 ;----------
 point_timer_init
        bt_f_if1 idloc1,idloc1_master