Printing float numbers in Hex using USR()

Basic and Machine Language

Moderator: Moderators

Post Reply
CurtisP
Vic 20 Dabbler
Posts: 99
Joined: Tue Mar 08, 2005 8:24 pm

Printing float numbers in Hex using USR()

Post 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.
Attachments
fphex.zip
(932 Bytes) Downloaded 86 times
wimoos
Vic 20 Afficionado
Posts: 345
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Printing float numbers in Hex using USR()

Post 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
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
CurtisP
Vic 20 Dabbler
Posts: 99
Joined: Tue Mar 08, 2005 8:24 pm

Re: Printing float numbers in Hex using USR()

Post by CurtisP »

Sorry for wasting your time with my ignorance. I'm done posting here.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Printing float numbers in Hex using USR()

Post 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.
CurtisP
Vic 20 Dabbler
Posts: 99
Joined: Tue Mar 08, 2005 8:24 pm

Re: Printing float numbers in Hex using USR()

Post 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.
malcontent
Vic 20 Hobbyist
Posts: 129
Joined: Sun Dec 26, 2010 1:51 pm

Re: Printing float numbers in Hex using USR()

Post by malcontent »

CurtisP wrote:I don't mind constructive criticism
Maybe it is that your definition of "constructive" that's flawed.
Post Reply