From: stevev@miser.uoregon.edu (Steve VanDevender)
Newsgroups: comp.sys.hp48
Subject: HP 48 Tricorder: The Next Generation
Date: 10 Jan 93 07:22:29 GMT
Article-I.D.: miser.STEVEV.93Jan9232229
Distribution: world
Organization: University of Oregon Chemistry Stores
NNTP-Posting-Host: miser.uoregon.edu

Inspired by the recent tricorder simulator, I decided to make a
minor improvement on it.

IRECHO is another program that detects proximity to the HP 48's
IR transmitter/receiver pair.  The main difference in this
program is that it returns 0 or 1 to the stack rather than
requiring that a single-character string be on the stack to be
overwritten.  This also makes the program significantly shorter.

I have also included some slightly modified versions of the
tricorder program that was previously posted.  One simply beeps
each time proximity is detected, while the other keeps track of
the time interval between detection of echos and makes
higher-pitched beeps for smaller intervals.

My HP 48's port cover happens to have just the right amount of
reflectivity to cause intermittent beeping with the port cover
on, and seems to increase the detection range of IRECHO as well.
Your mileage may vary.  Polishing the inside of the port cover in
front of the IR transmitter/receiver may possibly help, since
that is what has happened to mine.

A particularly devious application of IRECHO would be to make a
theft alarm for the HP 48; you could leave it out on a desk,
possibly next to something that returned an echo, and if that
object or the HP 48 is moved it would set off an alarm with the
beeper.  I'm still working on it.

Here's IRECHO in \->ASC format:

%%HP: T(3)A(R)F(.);
"CCD20750008FB97601BA11001FC1100D0158030815D015E0159090EC0344B2A2
590349C2A2068F2D76007DA808C04C5C"

And uuencoded:

begin 644 irecho
M2%!(4#0X+5C,+7`%`/B;9Q"K$0#Q'`'0$(4P@%$-40Y1"0G.,$0K*I4PE"PJ
)8/C29P#7BH`,
`
end

This is the modified version of the original, simple tricorder
program:

%%HP: T(3)A(R)F(.);
\<<
  DO
    IF IRECHO
    THEN 1000 .01 BEEP
    END
  UNTIL KEY
  END DROP
\>>

This is the version that beeps higher when echoes are detected
more frequently:

%%HP: T(3)A(R)F(.);
\<< 1
  DO
    IF IRECHO
    THEN 5000 SWAP 5 + / .01 BEEP 0
    END 1 +
  UNTIL KEY
  END DROP DROP
\>>

Let me know if you have any problems with these programs.

Below is the STAR source for IRECHO.  It uses a trick that I have
not seen before, but which is also simple enough that I doubt I
am the first to invent it.  However, the explanation of how it
returns RPL objects on the stack might be of interest to HP 48
machine language programmers.

IRECHO returns values on the RPL stack essentially by faking
object execution to both push the object on the stack and return
to normal RPL execution.  This is done by loading the address of
the desired RPL return object in the A register, then doing a
indirect jump through A.  If this is done when the RPL registers
are properly initialized, then the desired object is executed,
pushing it on the stack, and RPL execution resumes in the stream
that originally called the code object.

---begin irecho.star---
;irecho.star

;this file uses definitions in hp48.star and stdsyms.star

;check for proximity to the HP 48 IR transmitter/receiver pair by pulsing
;the IR transmitter and looking for echo on the receiver.  Pushes %0
;(real 0) on the RPL stack if no echo, %1 if an echo was detected.

	header `x'

	code

	call	save_regs	;save RPL registers

	move.5	#0011a, d0	;get address of IR receiver in d0
	move.5	#0011c, d1	;get address of IR transmitter in d1
	clr.a	a
	move.1	a, @d0		;clear receiver status
	move.p1	#8, c
	move.1	c, @d1		;turn on transmitter
	move.1	@d0, c		;get receiver status
	move.1	a, @d1		;turn off transmitter
	brnz.p	c, echo		;check receiver status

noecho:	move.p5	#2a2b4, c	;put pointer to %0 in c
	brcc	return
	
echo:	move.p5	#2a2c9, c	;put pointer to %1 in c

return:	push	c		;save return value pointer
	call	restore_regs	;restore RPL regs
	pop	c		;get return value
	move.a	c, a		;copy to a
	jump.a	@a		;execute RPL object at a, and continue RPL

	endcode
---end irecho.star
--
Steve VanDevender 	stevev@greylady.uoregon.edu
"Bipedalism--an unrecognized disease affecting over 99% of the population.
Symptoms include lack of traffic sense, slow rate of travel, and the
classic, easily recognized behavior known as walking."

--
Steve VanDevender 	stevev@greylady.uoregon.edu
"Bipedalism--an unrecognized disease affecting over 99% of the population.
Symptoms include lack of traffic sense, slow rate of travel, and the
classic, easily recognized behavior known as walking."
Newsgroups: comp.sys.hp48