Jump to content
IGNORED

Can you INC a BCD number?


Recommended Posts

Just started playing with MAC/65, OMG I wish I had this as a kid! DDT is amazeballs! Anyway, check this out:

10 .ORG $4000
20 .FLOAT 123456789
30 SED
40 INC $4005

When you ASM this and look at $4000, you have:

44 01 23 45 67 89

Now G 4006. This will SED into BCD mode and then increment the last number. The result is:

 

44 01 23 45 67 8A

THAT'S interesting! Did I miss a step here? Or does the 6502 simply not consider BCD in INC?

 

 

Link to comment
Share on other sites

12 hours ago, Maury Markowitz said:

44 01 23 45 67 8A

THAT'S interesting! Did I miss a step here? Or does the 6502 simply not consider BCD in INC?

 

 

Yup, reading the 6502 specifications for one thing. (-; The decimal flag is only honored by ADC and SBC, and thus not by INC and DEC. If you want to increment a BCD number, the only option is ADC. Or performing a half-carry check manually.

Link to comment
Share on other sites

Another thing - you're generally working on numbers greater than 2 figures so would want to carry over to the next significant set of digits.

 

INC works OK there since you can just do a BEQ to INC the next significant byte.

But with DEC you don't have a single flag to indicate you've underflowed from 00 to FF - so you'd probably end up doing more work than the SEC/SBC operation (for subtracting single-byte constants at least).  With SBC of a single byte value you could do a BCS to skip the next significant byte.

Link to comment
Share on other sites

4 hours ago, thorfdbg said:

Yup, reading the 6502 specifications for one thing. (-; The decimal flag is only honored by ADC and SBC, and thus not by INC and DEC. If you want to increment a BCD number, the only option is ADC. Or performing a half-carry check manually.

Instead I first check if the number is less than 99, at which point a carry is impossible and INC works fine.

Link to comment
Share on other sites

10 hours ago, Rybags said:

But alternatively you could just use binary then look for quick unsigned bin->BCD conversion routines.

If speed is not too much of an issue, use the internal FP routines, I wrote a couple of disk copiers bitd

and wrote the current sector to screen using FP routines which were fast enough to update the

screen between sectors.

 

The current Sector was in DAUX1 and DAUX2, copy them to $D4  and $D5

call IFP to convert to FP

call FASC to convert to ASCII

if you want to put the ASCII directly to screen subtract $20 from each character,

last character has high bit set, so AND #$7f, then subtract $20

 

Link to comment
Share on other sites

 

BCD INC in baroque style

 

 

     lax BCD
     jsr Baroque_BCD_INC
     sax BCD

     jmp *

 

BCD .HE 89

 

Baroque_BCD_INC
     and #$F0
     cmp #$90
     php
     txa
     and #$0F
     cmp #$09
     php
     txa
     sbx #$100-$01
     plp
     txa
     bcs @+
     plp
     rts
@    sbx #$100-$06
     txa
     plp
     bne @+
     ldx #$00
@    rts
 

Edited by xxl
  • Like 1
Link to comment
Share on other sites

1 hour ago, ivop said:

Why? All official Atari 8-bit computers run that code just fine. Even Bill Mensch calls them undocumented opcodes. They are not illegal or not allowed or something.

 

https://ataripodcast.libsyn.com/antic-interview-96-bill-mensch-6502-chip

 

Upgraded computers may not run properly, though.

Link to comment
Share on other sites

5 hours ago, ivop said:

Why? All official Atari 8-bit computers run that code just fine. Even Bill Mensch calls them undocumented opcodes. They are not illegal or not allowed or something.

 

https://ataripodcast.libsyn.com/antic-interview-96-bill-mensch-6502-chip

 

 

3 hours ago, David_P said:

Upgraded computers may not run properly, though.

That's the joke!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...