6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 7:52 pm

All times are UTC




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
PostPosted: Tue Mar 07, 2000 5:10 am 
Offline
Site Admin
User avatar

Joined: Fri Aug 30, 2002 1:08 am
Posts: 281
Location: Northern California
Welcome to the programming area!
This is the place to discuss your programming problems, or better yet, share useful or interesting programs and subroutines. I'll start the ball rolling by providing this little routine from Frank Kontros. It's for converting a numerical value $00-$0F to ASCII 0-F:

SED
CMP #$0A
ADC #$30
CLD

Pretty simple. Now it's your turn.

_________________
- Mike Naberezny (mike@naberezny.com) http://6502.org


Report this post
Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 15, 2000 10:50 am 
Hello All
I have up loaded a file that contains a keypad routine which takes advantage of the bus holding devices of the WCW65C22.
With this routine, there is no need for any glue logic and it can be modified for any amount of keys up to 64.

Gregqci


Report this post
Top
  
Reply with quote  
PostPosted: Thu Mar 30, 2000 3:11 am 
Offline
Site Admin
User avatar

Joined: Fri Aug 30, 2002 1:08 am
Posts: 281
Location: Northern California
Hi All,

This didn't turn into the mega-thread I expected. :(

Here's one that I use with my LCD display, it is from "6502 Software Design" by Leo J. Scanlon. Its purpose is to convert a byte into a three digit decimal number that gets printed on the display.

[code:1:23a4a2c25a]B2AD: LDX #$00 ;INITIALIZE HUNDREDS COUNTER

C100: CMP #100 ;BINARY VALUE = OR GREATER THAN 100?

BCC OUT1 ;NO. GO PRINT DECIMAL DIGIT

SBC #100 ;YES. SUBTRACT 100

INX ;INCREMENT DECIMAL COUNT

JMP C100 ; AND COMPARE AGAIN

OUT1: JSR PUTOUT ;GO PRINT DECIMAL DIGIT

LDX #00 ;INITIALIZE TENS COUNTER

C10: CMP #10 ;BINARY VALUE = OR GREATER THAN 10?

BCC OUT2 ;NO. GO PRINT DECIMAL DIGIT

SBC #10 ;YES. SUBTRACT 10

INX ;INCREMENT DECIMAL COUNT

JMP C10 ; AND COMPARE AGAIN

OUT2: JSR PUTOUT ;GO PRINT DECIMAL DIGIT

CLC ;CONVERT REMAINDER TO ASCII

ADC #$30 JMP PTROUT ;AND PRINT IT

RTSPUTOUT: PHA ;SAVE REMAINDER ON STACK

TXA ;MOVE DECIMAL COUNT TO ACCUMULATOR,

ADC #$30 ; CONVERT IT TO ASCII,

JSR PTROUT ; AND PRINT IT

PLA ;RETRIEVE REMAINDER

RTS

[/code:1:23a4a2c25a]

To call this routine, load the byte you want printed into the accumulator and JSR B2AD ("Binary to ASCII Decimal"). Theroutine will return three decimal digits in the accumulatorto a routine "PTROUT".

Anyone else have a good subroutine?

_________________
- Mike Naberezny (mike@naberezny.com) http://6502.org


Last edited by Mike Naberezny on Tue Apr 10, 2012 10:28 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 04, 2000 9:21 pm 
Offline

Joined: Thu Jul 24, 2003 8:01 pm
Posts: 24
* Name PrintDecW
* Purpose Print a 16-bit number in decimal
* Input Areg = low byte of num to be printed
* Yreg = high byte of num to be printed
* Xreg = leading char:
* $00 for no leading chars
* (left justified)
* $A0 for leading blank spaces
* (right justified)
* $B0 for leading zeros
* Output Xreg = $FF
* Uses Areg
* Xreg = digit ctr
* Yreg = digit
* ptr0 = num to be printed
* LeadChar = leading char
* LeadZero = leading zeros flag
* pos while finding leading zeros
* neg after end of leading zeros
* Calls MON_COUT
* Reference loosely based on Integer BASIC
* routine by WOZ
* Note handles 0 to 65535 ($0000 to $FFFF)

* variables:
* num (ptr0)
* leading char (LeadChar)
* digit ctr (Xreg)
* digit (Yreg)
* leading zeros flag (LeadZero)

* leading zeros flag := true
* for digit ctr = 4 to 0 step -1
* digit := "0"-1
* while num >= 0
* digit := digit + 1
* num := num - power of tem
* endw
* num := num + power of ten
* print digit or leading char
* endf

PrintDecW
STX LeadChar ;set up leading char

* alternate entry point if leading
* char is already set up

PrintDecW_1
STA ptr0
STY ptr0+1

STZ LeadZero ;init to pos
LDX #4 ;5 bytes to print

*!loop
LDY #"0"-1 ;init digit to print

*! loop
INY
LDA ptr0
SEC
SBC PowerOf10Lo,X
STA ptr0
LDA ptr0+1
SBC PowerOf10Hi,X
STA ptr0+1
*! until <mi>

* compensate for one too many subtractions

LDA ptr0
CLC
ADC PowerOf10Lo,X
STA ptr0
LDA ptr0+1
ADC PowerOf10Hi,X
STA ptr0+1

JSR FrontChar ;print digit

CPX #3 ;just printed thousands?
*! if <eq>
* must preserve Xreg, but can destroy Areg & Yreg
LDY #"," ;print a comma
BIT LeadZero ;are we still printing
; leading zeros?
*! if <pl>
LDY LeadChar ;yes, so print lead char
*! endif
TYA ;Areg := char to print
*! if <ne>
JSR MON_COUT ;print the comma or
; lead char
*! endif
*! endif

DEX
*!until <mi>
RTS

*---------
* Name PrintDecB
* Purpose Print an 8-bit number in decimal
* Input Areg = byte of num to be printed
* Xreg = leading char:
* $00 for no leading chars
* (left justified)
* $A0 for leading blank spaces
* (right justified)
* $B0 for leading zeros
* Note handles 0 to 255 ($00 to $FF)

PrintDecB
STX LeadChar ;set up leading char

PrintDecB_1
STA ptr0
PHY ;save Yreg

STZ LeadZero ;init to pos
LDX #2 ;3 bytes to print

*!loop
LDY #"0"-1 ;init digit to print
LDA ptr0

*! loop
INY ;incr count
SEC ;Areg := Areg - 10^Xreg
SBC PowerOf10Lo,X
*! until <mi>

* correct for one too many subtractions

CLC
ADC PowerOf10Lo,X
STA ptr0

JSR FrontChar ;print digit
DEX
*!until <mi>
PLY ;restore Yreg
RTS

*---------

* if digit ctr <> 0 then
* if digit <> "0" then
* leading zeros flag := false
* else
* if leading zeros flag = true then
* digit := leading char
* endif
* endif
* if digit <> 0 then
* print char in Yreg

FrontChar
TXA ;doing last digit?
*!if <ne>
CPY #"0" ;still doing leading zeros?
*! if <ne>
DEC LeadZero ;no, do not substitute
; leading char
*! else
BIT LeadZero ;substitute leading char?
*! if <pl>
LDY LeadChar ;yes
*! endif
*! endif
*!endif
TYA ;Areg := char to print
*!if <ne>
JSR MON_COUT ;print char
*!endif
RTS

PowerOf10Lo
DB <1
DB <10
DB <100
DB <1000
DB <10000

PowerOf10Hi
DB >1
DB >10
DB >100
DB >1000
DB >10000


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 45 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: