*
.   memory examine and change processing
.
lemex:     proc

           bsr     getladdr            get the memory address
           bcs     exit                if not hex, just exit
*
.   display contents of memory location
.
gotadr     leax    =(13," - ",etx),pc  start new memory cycle
           bsr     pdata               output the hyphen stuff
           tfr     y,d                 transfer the data address
           bsr     hexword             convert it to hex output
           bsr     outsp               dump a trailing space
           lda     0,y                 pick up the data byte
           bsr     hexbyte             dump it out as hex
           bsr     outsp               dump another trailing space
           bsr     getbyte             get a new data value
           bcs     decode              if not hex, we have a command
*
.   alter the byte in memory and check for compliance
.
           sta     0,y                 store the data byte into memory
           clrb                        provide a delay
memdel     decb                        to allow floating lines to float
           bne     memdel              thus inhibiting false equal
           cmpa    0,y                 compare against the stored data
           beq     incadr              if equal, go increment
           leax    =(" ?",etx),pc      tell dude memory doesn't match
           bsr     pdata
*
.   memory command decoding
.
incadr     leay    1,y                 increment address by one
           bra     gotadr
decadr     leay    -1,y                decrement address by one
           bra     gotadr
decode     cmpa    #"^"                check for decrement
           beq     decadr
           cmpa    #cr                 or end of memory examine
           bne     incadr
exit       rts

*
.   getladdr -- get logical address
.
getladdr   pshs    d
           bsr     getbyte             go get high byte
           bcs     endladdr
           pshs    a
           bsr     getbyte
           puls    b
           bcs     endladdr
           exg     a,b                 swap halves
           tfr     d,y
           clc
endladdr   ret     d

           end
