chiark / gitweb /
correct points which were all noted backwards
[trains.git] / detpic / misc.asm
1 ;======================================================================
2
3   include common.inc
4
5   udata_acs
6 dsave_w         res     1
7 dsave_fsr0      res     2
8 debugp  res     1
9
10 debug_section udata 0x100
11 debug   res     256
12
13   code
14 ;======================================================================
15 ; GENERALLY USEFUL ROUTINES
16
17 ;----------
18 read_pic_no @
19 ; read pic no from ID locations and return it
20 ;       W               undefined               pic number from ID loc 0
21 ;       status Z        undefined               1 iff master PIC
22 ;       TBLPTR*         undefined               points to 20001
23
24         mov_lw  0x20
25         mov_wf  TBLPTRU
26         clr_f   TBLPTRH
27         clr_f   TBLPTRL
28
29         tblrd_postinc_fixup
30         mov_fw  TABLAT
31         return
32
33 ;----------
34 idlocs_init @
35 ; read id locations and store in canonical place
36 ;       W               undefined               undefined
37 ;       picno           undefined               pic number (from 20000)
38 ;       idloc1          undefined               idloc1 (from 20001)
39
40         rcall   read_pic_no
41         mov_wf  picno
42
43         tblrd_postinc_fixup
44         mov_fw  TABLAT
45         mov_wf  idloc1
46
47         return
48
49 ;----------
50 bitnum2bit_init @
51 ; populate bitnum2bit
52         mov_lw  0x80
53         mov_lfsr bitnum2bit,0
54 init_bitnum2bit_loop
55         rl_w
56         mov_wf  POSTINC0
57         bra_nn  init_bitnum2bit_loop
58         return
59
60 ;----------
61 memory_erase @
62 ;  picno                        preserved
63 ;  idloc1                       preserved
64 ;  other GPRs                   overwritten with 0xbb
65         mov_ff  picno, FSR1L
66         mov_ff  idloc1, TABLAT
67         mov_lfsr 0, 0
68 memory_erase_pageloop
69         mov_lw  0xbb
70 memory_erase_byteloop
71         mov_wf  POSTINC0
72         mov_wf  POSTINC0
73         mov_wf  POSTINC0
74         mov_wf  POSTINC0
75         mov_wf  POSTINC0
76         mov_wf  POSTINC0
77         mov_wf  POSTINC0
78         mov_wf  POSTINC0
79         tst_f_ifnz FSR0L
80         bra     memory_erase_byteloop
81         ; new page:
82
83         mov_lw  0x06
84         xor_wfw FSR0H
85         bra_nz  memory_erase_pageloop
86         ; done!
87
88         mov_ff  FSR1L, picno
89         mov_ff  TABLAT, idloc1
90         return
91
92 ;----------
93 debugbyte @
94 ; Adds a byte to debug
95 ;  W            message byte            preserved
96 ;  STATUS       any                     trashed
97 ;  all others   any                     preserved
98 ; Not for use in High ISR
99         mov_ff  FSR0L, dsave_fsr0
100         mov_ff  FSR0H, dsave_fsr0+1
101         mov_lfsr debug, 0
102         mov_ff  debugp, FSR0L
103         mov_wf  INDF0
104         inc_f   debugp
105         mov_ff  dsave_fsr0,   FSR0L
106         mov_ff  dsave_fsr0+1, FSR0H
107         return
108
109   include final.inc