From: ian Date: Fri, 2 Dec 2005 02:48:24 +0000 (+0000) Subject: points more wip X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=14616c573ccc11a1a9adc298dfa5bef0047205a1;p=trains.git points more wip --- diff --git a/detpic/points.asm b/detpic/points.asm index 20d72a6..f58745c 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -1,37 +1,116 @@ ;====================================================================== ; POINTS +; +; Expected layout of data at data_points in flash: +; 4 bytes for each point number +; byte 0 +; pic number for this point +; ff indicates unassigned point number +; byte 1 +; index number for this point on relevant pic +; byte 2 +; address of relevant LAT* +; byte 3 +; bit in LAT (eg 0x40 for bit 6) +; bytes 1-3 are not defined if number is not assigned +; address of data_points is guaranteed to be multiple of 256 udata_acs -point res 1 - code - -obj_set_up_start macro - clr_f TBLPTRU - clr_f TBLPTRL - endm + udata 0x300 +our_point_table_ctln2 equ 6 +our_point_table_count equ (1 << our_point_table_ctln2) +our_point_table res our_point_table_count * 2 +; 2 bytes for each point, indexed by index number on this pic +; 1st byte: LAT* address, or 0 for unassigned +; 2nd byte: bit in LAT -obj_select macro -; W object number - - mov_wf TBLPTRL - endm - -obj_setfsr0 macro obj_pic_data, obj_port_data, obj_bit_data, PORTRISLATA - mov_lw pt_pic_data >> 8 - mov_wf TBLPTRH - + code ;---------------------------------------------------------------------- points_init ; Clears TRIS* bits for all points and sets the ; pin to `not triggering' - mov_lw pt_num_max - mov_wf point + mov_lfsr our_point_table, 0 ; FSR0 points to point lookup table + mov_lw our_point_table_count * 2 - obj_set_up_start +points_init_clear_loop + clr_f POSTINC1 + dec_w_ifnz + bra points_init_clear_loop + ; otherwise, done: + + ; During this loop: + clr_wf TBLPTRU + mov_lw (data_points >> 8) + mov_wf TBLPTRH + clr_f TBLPTRL ; TBLPTR* -> to point data + + set_f FSR1H ; FSR1 -> LAT*, TRIS* + + mov_lfsr our_point_table, 0 ; FSR0 -> point lookup table points_init_loop + mov_lw (data_points_end >> 8) + cmp_fw_ifge TBLPTRH + bra points_init_loop_exit + + tblrd *+ + dw 0xffff ; TABLAT = pic number + + mov_fw picno + cmp_fw_ifne TABLAT + bra points_init_loop_ifnot_ours + + tblrd *+ + dw 0xffff ; TABLAT = index number + + mov_lw 0xff << our_point_table_ctln2 + and_wfw TABLAT + bra_nz bad_pointtable_index + + rl_fw TABLAT + mov_wf FSR0L ; FSR0 -> our table entry + + tst_f_ifnz INDF0 + bra_nz bad_pointtable_clash + + tblrd *+ + dw 0xffff ; TABLAT = LAT* address + + mov_fw TABLAT + mov_wf POSTINC0 ; store LAT* address; FSR0 -> bit + mov_wf FSR1L ; FSR1 -> LAT* + + tblrd *+ + dw 0xffff ; TABLAT = bit value + + mov_fw TABLAT + mov_wf INDF0 ; store bit value + + com_w ; W = ~bit + and_wff INDF1 ; clear the LAT* bit (point inactive) + pin_vh pall_pt0reverse ; except pt0 which is backwards + + mov_lw TRISA-LATA + add_wf FSR1L ; FSR1 -> TRIS* + com_fw TABLAT ; W = ~bit + and_wff INDF1 ; make the pin an output + + bra points_init_loop + +points_init_loop_ifnot_ours + tblrd *+ + tblrd *+ + tblrd *+ + bra points_init_loop + + + + + clr_f INDF1 + ;----------------------------------------------------------------------