Page 1 of 1

Printing float numbers in Hex using USR()

Posted: Sat Dec 16, 2017 8:52 pm
by CurtisP
It just so happens I've been playing around in assembly with the USR function and Floating Point, so I wrote a little program to print the actual binary representation of any floating point number.

The program is assembled into the cassette buffer, so load it using

Code: Select all

LOAD "FPHEX.PRG",8,1
NEW
Then setup the USR vector with

Code: Select all

SYS 828
After that you can display the binary and ascii representation using

Code: Select all

PRINT USR(expression)
DASM Source Code is included.

Re: Printing float numbers in Hex using USR()

Posted: Tue Dec 19, 2017 3:25 am
by wimoos
Hello CurtisP

A (USR-)function should not print by itself, it should return a result that could be printed (or assigned to a variable or used in another expression).
Also, setting the USR vector can be done by just POKEing the low and high byte of the address into 1 and 2.

Because the string processing routines also use fac #1, first you should save contents of fac #1 in another location, e.g. $57 - $5B

Hence:

Code: Select all

LOAD"FPHEX.PRG",8,1
POKE1,60:POKE2,3
A$=USR(3.1416)
PRINTA$

Code: Select all

		.ORG $033C
;
	JSR  $DBCA	; copy fac #1 to $57 - $5B
	LDA  #15	
	JSR  $D47D	; allocate string buffer of 15 bytes
	LDY  #0		; index into string buffer
	LDX  #0		; index into fac #1
LA8A0	LDA  $57,X	; get byte from fac #1
	JSR  LA8A6	; convert and put in result buffer
	LDA  #$20	; put space in buffer
	STA  ($62),Y	
	INY		
	INX		; bump index in fac #1
	CPX  #6		; all done ?
	BNE  LA8A0
	JMP  $D6FB	; return string as function result
;
LA8A6	PHA            	 
	LSR  A         	 
	LSR  A         	 
	LSR  A         	 
	LSR  A         	 
	JSR  LA8B1     	 
	PLA            	 
	AND  #$0F      	 
LA8B1	ORA  #'0'
	CMP  #'9'+1     	 
	BCC  LA8B9     	 
	ADC  #('A'-1)-('9'+1)
LA8B9	STA  ($62),Y   	 
	INY
	RTS            	 

	.end

Re: Printing float numbers in Hex using USR()

Posted: Tue Dec 19, 2017 9:25 pm
by CurtisP
Sorry for wasting your time with my ignorance. I'm done posting here.

Re: Printing float numbers in Hex using USR()

Posted: Wed Dec 20, 2017 12:01 pm
by Mike
CurtisP wrote:Sorry for wasting your time with my ignorance. I'm done posting here.
Sometimes fair criticism gets down the wrong throat, me guesses.

Two people (wimoos and me) independently told you that there's something wrong with what you coded, and you should be able to cope with that. I suppose you could be content with your solution, if your program was the only one running on the VIC-20, and no other program depended on the details of its function.

I could quite as well not only have wondered what exchanging the BASIC ROM should have to do with the exact details of writing a BASIC extension (wedge) - a topic you intermingled while you wrote into the thread "ML design patterns (calling ROM subroutines)". But in the same view, you also posted your USR() function into that hardware thread I started concerning the actual replacement of my BASIC ROM. That was in follow-up to an error I found in the BASIC interpreter 4 years ago. Me moving your misplaced post to a new topic in the Programming section (on your own suggestion!) should have been in order.

If you got fed up with all this, I can't do much more than shake my head. Don't let the door hit you on the way out.

Re: Printing float numbers in Hex using USR()

Posted: Mon Jan 08, 2018 9:00 pm
by CurtisP
I don't mind constructive criticism, and being corrected here bother me as much as also being chastised in a whole other thread

This was really just a quick hack that I came up with while working on another more involved project.

When I posted it, it was I'm response to the original thread about the error, but then your more recent reply read split off into a new topic arms my reply went with it, which is why I asked for it to be spilt off into yet another post.

As of now I've lost all interest in Vic-20 programming. It's good to know that I won't be missed.

Re: Printing float numbers in Hex using USR()

Posted: Wed Jan 10, 2018 12:30 am
by malcontent
CurtisP wrote:I don't mind constructive criticism
Maybe it is that your definition of "constructive" that's flawed.