     1 000000           ; > FindCSR searches through the top 8K of memory (the I/O page)
     2 000000           ;   for valid addresses.  Invalid addresses cause a trap to location
     3 000000           ;   4, from which the program recovers. Valid addresses are printed.
     4 000000           ;
     5 000000                   ORG      O1000
     6 001000 012706            MOV     #O1000,R6       ; init stack
     6 001002 001000    
     7 001004 012737            MOV     #trap,@#4       ; set bus timeout trap vector at 4
     7 001006 001120    
     7 001010 000004    
     8 001012 012737            MOV     #O340,@#6       ; set new PSW
     8 001014 000340    
     8 001016 000006    
     9 001020 012705            MOV     #O160000,R5     ; start of I/O page
     9 001022 160000    
    10 001024 011500    loop:   MOV     (R5),R0         ; read location
    11 001026 004737    exists: JSR     R7,@#CRLF       ; move these 2 lines (NOT the label) past...
    11 001030 001164    
    12 001032 004737            JSR     R7,@#PRTO       ; ...the MOV if you want only real addresses
    12 001034 001226    
    13 001036 004337            JSR     R3,@#MSSG       ; if we get here, no trap - so tell console
    13 001040 001316    
    14 001042 000040            DEF     32              ; pretend it's R/O
    15 001044 000122            DEF     ASC("R")
    16 001046 100117            DEF     ASC("O")+&8000
    17 001050 010015            MOV     R0,(R5)         ; write location
    18 001052 004337            JSR     R3,@#MSSG       ; if here - no trap, so really was R/W
    18 001054 001316    
    19 001056 000010            DEF     8               ; backspace
    20 001060 000057            DEF     ASC("/")
    21 001062 100127            DEF     ASC("W")+&8000
    22 001064 005205    next:   INC     R5
    23 001066 005205            INC     R5              ; twice to stay on even address
    24 001070 020527            CMP     R5,#O177560
    24 001072 177560    
    25 001074 100403            BMI     test
    26 001076 020527            CMP     R5,#O177570
    26 001100 177570    
    27 001102 100411            BMI     consol          ; don't test the console, just include it
    28 001104 005705    test:   TST     R5
    29 001106 001346            BNE     loop
    30 001110 004737            JSR     R7,@#CRLF
    30 001112 001164    
    31 001114 000000    stop:   HALT                    ; stop when R5 wraps round
    32 001116 000776            BR      stop
    33 001120 062706    trap:   ADD     #4,R6           ; "remove" old (pre-trap) PC and PSW from stack
    33 001122 000004    
    34 001124 000757            BR      next
    35 001126           ;
    36 001126 004737    consol: JSR     R7,@#CRLF
    36 001130 001164    
    37 001132 004737            JSR     R7,@#PRTO
    37 001134 001226    
    38 001136 004337            JSR     R3,@#MSSG
    38 001140 001316    
    39 001142 000040            DEF     32
    40 001144 000103            DEF     ASC("C")
    41 001146 000157            DEF     ASC("o")
    42 001150 000156            DEF     ASC("n")
    43 001152 000163            DEF     ASC("s")
    44 001154 000157            DEF     ASC("o")
    45 001156 000154            DEF     ASC("l")
    46 001160 100145            DEF     ASC("e")+&8000
    47 001162 000740            BR      next        
    48 001164           ;
    49 001164 010501    CRLF:   MOV     R5,R1
    50 001166 012705            MOV     #13,R5          ; print <CR> and <LF> on console
    50 001170 000015    
    51 001172 004737            JSR     R7,@#PRTA
    51 001174 001212    
    52 001176 012705            MOV     #10,R5
    52 001200 000012    
    53 001202 004737            JSR     R7,@#PRTA
    53 001204 001212    
    54 001206 010105            MOV     R1,R5
    55 001210 000207            RTS     R7
    56 001212           ;
    57 001212 105737    PRTA:   TSTB    @#O177564       ; wait for console XBUFF to be ready
    57 001214 177564    
    58 001216 100375            BPL     PRTA
    59 001220 010537            MOV     R5,@#O177566
    59 001222 177566    
    60 001224 000207            RTS     R7
    61 001226           ;
    62 001226 010046    PRTO:   MOV     R0,-(R6)        ; save R0,R4,R5 on stack
    63 001230 010446            MOV     R4,-(R6)
    64 001232 010546            MOV     R5,-(R6)
    65 001234 010504            MOV     R5,R4
    66 001236 012705            MOV     #O30,R5         ; R4 will be 6x after shifts
    66 001240 000030    
    67 001242 006104            ROL     R4              ; rotate 1 bit from R4 to R5
    68 001244 006105            ROL     R5
    69 001246 004737            JSR     R7,@#PRTA       ; print - as ASCII since it's 6x
    69 001250 001212    
    70 001252 012700            MOV     #5,R0           ; set to do five octets
    70 001254 000005    
    71 001256 012705    CLOOP:  MOV     #6,R5           ; 6>>3 becomes octal 60, ie "0"
    71 001260 000006    
    72 001262 006104            ROL     R4              ; rotate R4>R5: 3 bits of octal number
    73 001264 006105            ROL     R5              ; could use ASHC R4,#3 if we have EIS
    74 001266 006104            ROL     R4
    75 001270 006105            ROL     R5
    76 001272 006104            ROL     R4
    77 001274 006105            ROL     R5
    78 001276 004737            JSR     R7,@#PRTA       ; print a digit
    78 001300 001212    
    79 001302 005300            DEC     R0              ; one less digit to do
    80 001304 001364            BNE     CLOOP
    81 001306 012605            MOV     (R6)+,R5        ; restore caller's R5,R4,R0
    82 001310 012604            MOV     (R6)+,R4
    83 001312 012600            MOV     (R6)+,R0
    84 001314 000207            RTS     R7
    85 001316           ;
    86 001316 105737    MSSG:   TSTB    @#O177564       ; prints message at word following call
    86 001320 177564    
    87 001322 100375            BPL     MSSG
    88 001324 011337            MOV     (R3),@#O177566  ; print char just past where we were
    88 001326 177566    
    89 001330 005723            TST     (R3)+           ; see if it was last, and point to next
    90 001332 100371            BPL     MSSG            ; top bit set = finished
    91 001334 000203            RTS     R3
