Search found 7 matches

by Omegamatrix
Sun Oct 25, 2015 6:29 pm
Forum: Programming
Topic: isolate the high bit of a byte
Replies: 11
Views: 2066

Re: isolate the high bit of a byte

Good spot, Omegamatrix -- I missed that! The 2nd instruction tests the high 4 bits, but the test needn't be destructive as in my previous version. CMP and BIT are both capable of doing the test while at the same time preserving the contents of A.

I have only programmed for the 6502, and there's ...
by Omegamatrix
Sat Oct 24, 2015 7:27 am
Forum: Programming
Topic: isolate the high bit of a byte
Replies: 11
Views: 2066

Re: isolate the high bit of a byte

In addition to Dr Jefyll's saving with using TAY and TYA, you can shave 1 cycle off worse case execution in the first part of the routine.

Change this:

Code: Select all

 lda num
 and #$F0
 bne SKIP1
 eor num
SKIP1
To this:

Code: Select all

 lda num
 cmp #$10
 bcc SKIP1
 and #$F0
SKIP1
by Omegamatrix
Thu Mar 19, 2015 1:12 am
Forum: Programming
Topic: Dividing by seven
Replies: 22
Views: 5040

Re: Dividing by seven

Bogax, you can save a byte by eliminating the CLC this way. I tested it against all input values.

lda dividendHigh
and #$F0
sta temp
eor dividendHigh
asl
asl
asl
asl
adc dividendLow
bcc .skipAdd16A
adc #$0F
.skipAdd16A:
adc temp
bcc .skipAdd16B
adc #$0F
.skipAdd16B:
sec
div_loopMod ...
by Omegamatrix
Sat Jan 31, 2015 6:42 pm
Forum: Programming
Topic: Dividing by seven
Replies: 22
Views: 5040

Re: Dividing by seven

Here is a table based version that is under 67 cycles, unless you are using a subroutine. Hope it helps! It's a bugger for bytes I know... :wink:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 16 bit unsigned divide by 40, mod 40 (Ver 3)
; By Omegamatrix
; 45-65 cycles, 581 bytes ...
by Omegamatrix
Sat Jan 31, 2015 10:18 am
Forum: Programming
Topic: Dividing by seven
Replies: 22
Views: 5040

Re: Dividing by seven

I sped up the routine I wrote, slightly. It's now 131 cycles worse case, and 111 cycles best case. It's still at the same 118 bytes too. :)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 16 bit unsigned divide by 40, mod 40 (Ver 2)
; By Omegamatrix
; 111-131 cycles, 118 bytes ...
by Omegamatrix
Fri Jan 30, 2015 5:42 am
Forum: Programming
Topic: Dividing by seven
Replies: 22
Views: 5040

Re: Dividing by seven

I need something similar, a 40/mod word for a Radix-50 and for screen positioning on a 40-column PET. Oh and it should run in less than 47 clock cycles and consume only 15 bytes of RAM.

That's a very fast specification. :shock: Also, I am only familiar with the 2600. Reading what Barry wrote I ...
by Omegamatrix
Sun Jan 25, 2015 9:09 am
Forum: Programming
Topic: Converting byte to hex string
Replies: 15
Views: 12457

Re: Converting byte to hex string

How about this?

; A = entry value

sed ;2 @2
tax ;2 @4
and #$0F ;2 @6
cmp #9+1 ;2 @8
adc #$30 ;2 @10
tay ;2 @12
txa ;2 @14
lsr ;2 @16
lsr ;2 @18
lsr ;2 @20
lsr ;2 @22
cmp #9+1 ;2 @24
adc #$30 ;2 @26
cld ;2 @28

; A = MSN ASCII char
; Y = LSN ASCII char


I ran a short test program ...