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

All times are UTC




Post new topic Reply to topic  [ 32 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Mon Aug 16, 2010 10:28 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
Commodore KERNAL used BIT in this way, dating the technique at least as far back as 1977, the release year for the PET. If you figure it takes about a year to produce a new computer and put it on the market, we can assume 1976 was when it was first used by Commodore.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 17, 2010 7:16 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
kc5tja wrote:
Commodore KERNAL used BIT in this way, dating the technique at least as far back as 1977, the release year for the PET. If you figure it takes about a year to produce a new computer and put it on the market, we can assume 1976 was when it was first used by Commodore.

Certainly first shipped by Commodore. But I had a quick skim through André's disassembly and it looks to me like all these overlapping instruction tricks are found in the BASIC section ($C000-$E1E0) which(*) Microsoft then shipped to several other outfits - and defended their copyright on. (It still could have been a habit or invention of a Commodore engineer, but I'd say it was more likely a Microsoft thing - for density, for copyright or just as a trick.)

On the copyright front, there's an interesting story about an extra egg delivered subsequently by Microsoft to Commodore for tactical reasons.

Cheers
Ed
(*) The BASIC section does contain some Commodore patches, but I don't see the trick used in those.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 17, 2010 10:04 am 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1043
Location: near Heidelberg, Germany
BigEd wrote:
Certainly first shipped by Commodore. But I had a quick skim through André's disassembly and it looks to me like all these overlapping instruction tricks are found in the BASIC section ($C000-$E1E0) which(*) Microsoft then shipped to several other outfits - and defended their copyright on. (It still could have been a habit or invention of a Commodore engineer, but I'd say it was more likely a Microsoft thing - for density, for copyright or just as a trick.)


This article here shows http://www.theregister.co.uk/2001/05/15 ... rite_code/ that Microsoft - even Bill G. himself used that trick already in the first 8080 BASIC version for the Altair.

Quote:
On the copyright front, there's an interesting story about an extra egg delivered subsequently by Microsoft to Commodore for tactical reasons.


Quite an interesting read! Many thanks for the link

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 18, 2010 1:07 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
BigEd wrote:
...and I see now that you mention it in your opcode reference pages


I should point out that that part wasn't written by me. My "update"s were more akin to proofreading, and it was maybe only a couple of sentences of clarification, and I may have fixed a typo or two or some formatting. The example code for wrap around looks rambling and pedantic enough to be mine :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 18, 2010 11:14 pm 
Offline

Joined: Tue Sep 24, 2002 4:56 pm
Posts: 50
Location: Essex, UK
Going a bit OT here - am I right in thinking that Woz's "Integer BASIC" for the Apple and Acorn's "BBC BASIC" were the only "non-Microsoft" BASICs around, or am I mistaken?

--Martin

_________________
Martin Penny

.sig in beta - full release to follow.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 18, 2010 11:17 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
Atari's BASIC was also non-Microsoft. Interestingly, Atari's BASIC was a much closer approximation of Kemeny & Kurtz' BASIC than Microsoft's.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 19, 2010 1:49 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8504
Location: Midwestern USA
mdpenny wrote:
Going a bit OT here - am I right in thinking that Woz's "Integer BASIC" for the Apple and Acorn's "BBC BASIC" were the only "non-Microsoft" BASICs around, or am I mistaken?

--Martin

There are also the Business BASICs, which extended the language well beyond what K&K envisioned.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 19, 2010 2:34 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
Quote:
were the only "non-Microsoft" BASICs around

You do mean 6502 BASICs, right? I got started in BASIC on my handl-held HP-71 computer, then after that, everything else was a huge let-down, including even HP's Rocky Mountain BASIC which came from a different division of HP and took something like half a megabyte when I worked with it. Most of them hardly seemed to be good enough to qualify as toys by comparison to the HP-71's system, especially with the plug-in module extensions and the user-group additions that were published. Lee's EhBASIC though, although I haven't used it, appears to be the best 6502 BASIC I've ever seen.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 19, 2010 4:13 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
I remember loading Tom Pitman's Tiny Basic onto my KIM-1; the distribution medium was paper tape! A newbie, I somehow cobbled together some wiring and some machine-language coding to hook onto a paper-tape reader someone gave me. That was a big deal at the time, but after I got it all working the thrill faded pretty fast, and instead I became interested in Forth... :twisted:

I'm pleased to see that Tom Pitman's Itty Bitty Computers is still around; he's got some good Tiny Basic info -- including disassembled versions of his own source code! -- here. (Anyone care to scan this for the instances of the BIT/CMP skip-a-bye trick?)

-- Jeff


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 19, 2010 4:53 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
BIT was only used once - just after label "LBL087". It was not the BIT trick however, it was actually testing the bits!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 19, 2010 5:22 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
8BIT wrote:
BIT was only used once
Okay, but let's remember there are at least six cases to look for:
- BIT or CMP Zpg (a risky way to skip 1 byte)
- BIT or CMP Immediate (a safe way to skip 1 byte)
- BIT or CMP Absolute (a risky way to skip 2 bytes)

The "risk," of course, is of a Destructive Read of an IO register, as discussed earlier. You can temporarily avoid the hazard if you carefully cross-check your code in regard to IO addresses for a specific computer, but this is utterly the wrong way to go about creating a maintainable, transportable program!

I say "at least six" cases because the number is much higher. Many other address modes will also work; eg: using BIT or CMP Abs, X to skip 2 bytes (risky), or (Ind),Y to skip 1 byte (very risky!) But choices like these are hardly obvious, and I suspect they'll appear only if there's an intentional effort to create disassembly-resistant code. Speaking of which, it could get worse: if there's a free register, a devious programmer could resort to op's other than BIT and CMP. (Eg: using LDX Immediate to skip 1 byte.)

As for the question of BIT vs. CMP, BIT seems to have received more attention, but only by fluke. I bet this skip-a-byte trick has been independently discovered by lots of people. Some hit on the idea of using BIT; for others it was CMP that came to mind. But they're almost interchangeable. About the only significant difference is that BIT Immediate isn't available on the NMOS '02. Therefore you might as well always go with CMP for this trick, and forget BIT. [Edit:] This assumes you're not concerned about preserving the Flags. See below.

-- Jeff


Last edited by Dr Jefyll on Thu Aug 19, 2010 2:43 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 19, 2010 7:23 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
One other case I saw: after a SEC, using a BCC to skip over a CLC (which was an alternate entry point for the subsequent code)

(Or it might have been the other way around)


Top
 Profile  
Reply with quote  
 Post subject: Skip a Bit
PostPosted: Thu Aug 19, 2010 1:27 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8504
Location: Midwestern USA
Dr Jefyll wrote:
8BIT wrote:
BIT was only used once

Okay, but let's remember there are at least six cases to look for:
- BIT or CMP Zpg (a risky way to skip 1 byte)
- BIT or CMP Immediate (a safe way to skip 1 byte)
- BIT or CMP Absolute (a risky way to skip 2 bytes)

In all of the above examples, the use of CMP has the undesirable effect of altering carry, possibly leading to a later program bug.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: Skip a Bit
PostPosted: Thu Aug 19, 2010 1:40 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
BigDumbDinosaur wrote:
the use of CMP has the undesirable effect of altering carry
Absolutely right -- that is worth mentioning.

CMP alters flags N Z and C.
BIT alters flags N Z and V.

To avoid altering any flags, consider using a Conditional Branch op-code whose condition you know to be false (as suggested above by Big Ed). Result: another safe way to skip 1 byte. (The byte "skipped" is the never-used branch offset.)

-- Jeff


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 25, 2010 2:07 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
It's (more or less) a 65C02-only technique, but unused, guaranteed-NOPs can also be used for this purpose, as noted in "Unused opcodes" in section 8 of (the last part):

http://6502.org/tutorials/65c02opcodes.html


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 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: