Maury Markowitz Posted January 28, 2022 Share Posted January 28, 2022 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? Quote Link to comment Share on other sites More sharing options...
shanti77 Posted January 28, 2022 Share Posted January 28, 2022 You must use ADC or SBC for BCD. 1 Quote Link to comment Share on other sites More sharing options...
thorfdbg Posted January 29, 2022 Share Posted January 29, 2022 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. Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 29, 2022 Share Posted January 29, 2022 The extra logic probably would have been too much. And the usage case - it's fairly rare to do BCD operations in a direct way - it's usually a subroutine that's operating on two "variables" rather than constants. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted January 29, 2022 Share Posted January 29, 2022 Also remember FLOAT constants can only really be used by the ROM floating point routines Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 29, 2022 Share Posted January 29, 2022 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. Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted January 29, 2022 Share Posted January 29, 2022 Rybags: try loading the LSB and decrementing the MSB only if the LSB is 0. Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 29, 2022 Share Posted January 29, 2022 You can but it gets to the point of why not just use the SBC anyway? The feeling I have about it is it might have just came down to bloating out the component count just to provide seldom needed shortcut. Quote Link to comment Share on other sites More sharing options...
Maury Markowitz Posted January 29, 2022 Author Share Posted January 29, 2022 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. Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted January 29, 2022 Share Posted January 29, 2022 Are you sure? We are talking hex $99 here? If you have $09 then an INC will give you $0A and not $10 as you would want. Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 30, 2022 Share Posted January 30, 2022 Why the need for BCD anyway? It can be handy for stuff like a game score. But alternatively you could just use binary then look for quick unsigned bin->BCD conversion routines. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted January 30, 2022 Share Posted January 30, 2022 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 Quote Link to comment Share on other sites More sharing options...
xxl Posted January 30, 2022 Share Posted January 30, 2022 (edited) 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 January 30, 2022 by xxl 1 Quote Link to comment Share on other sites More sharing options...
+Stephen Posted January 30, 2022 Share Posted January 30, 2022 OMG - you do realize that by using LAX and SAX, you are in danger of having a class action lawsuit brought against you? 4 Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted January 30, 2022 Share Posted January 30, 2022 Don't forget he used 'sbx' too, that's 3 strikes, he's out 1 Quote Link to comment Share on other sites More sharing options...
ivop Posted January 30, 2022 Share Posted January 30, 2022 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 Quote Link to comment Share on other sites More sharing options...
+David_P Posted January 30, 2022 Share Posted January 30, 2022 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. Quote Link to comment Share on other sites More sharing options...
xxl Posted January 30, 2022 Share Posted January 30, 2022 1 hour ago, David_P said: Upgraded computers may not run properly, though. so what was the point of modifying if the standard stuff doesn't work anymore? 1 3 Quote Link to comment Share on other sites More sharing options...
+DjayBee Posted January 30, 2022 Share Posted January 30, 2022 1 hour ago, David_P said: Upgraded computers may not run properly, though. Oh Kyle22, where art thou? 3 Quote Link to comment Share on other sites More sharing options...
ClausB Posted January 30, 2022 Share Posted January 30, 2022 Another thing that doesn't work as you might expect in BCD mode is the Z flag. My last BCD project was frustrated by that for a while: Quote Link to comment Share on other sites More sharing options...
+Stephen Posted January 31, 2022 Share Posted January 31, 2022 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.