This is something I and p-lab came up when trying to write the smallest possible test program (the one the prints all the characters on the display).
Our version is only 6 bytes, here it is:
0000: E8 8A 20 EF FF 00
In 6502 assembly:
* = 0
INX
TXA
JSR ECHO
BRK
The trick here is to have a "BRK" instruction in place of "JMP $0" at the end of the program to close the loop.
BRK triggers an IRQ that on the Apple1 is mapped at address $0000, so it has the same effect of a JMP 0 but uses only one byte instead of three.
Very nice and clever! I cobbled one together that was longer at 8 bytes but is relocatable to any valid address.
0300: 18 8A 20 EF FF E8 90 F9
0300- 18 CLC
0301- 8A TXA
0302- 20 EF FF JSR $FFEF
0305- E8 INX
0306- 90 F9 BCC $0301
I like it. Let me see how far I can get...
FA:A2 FF 9A C8 98 60 EE FF F9 0
FAR
In 6502 assembly:
00FA- A2 FF LDX #$FF
00FC- 9A TXS
00FD- C8 INY
00FE- 98 TYA
00FF- 60 RTS
0100- EE FF F9 00
In 10 bytes, not quite as small.
You are not counting the JSR sub-routine and its RTS.
Fair? How much more to bear
BE6:8E 12 D0 E8 2C 12 D0 30 FB 10 F5
BEAR
In 6502 assembly:
0BE6- 8E 12 D0 STX $D012
0BE9- E8 INX
0BEA- 2C 12 D0 BIT $D012
0BED- 30 FB BMI $0AF1
0BEF- 10 F5 BPL $0AF9
Self contained and relocatable in 11 bytes. Bloated!
I like nippur72's 6 byte version because it is less to remember and type:
0:E8 8A 20 EF FF 0
0R
I am counting the number of bytes needed to type the program in the monitor, not the number of CPU instruction executed.
Didn't know about the BRK on the Apple 1. A good test for an emulator to see how thorough the programmer was!
With that in mind, I suppose if you aren't too picky about what characters you see or the order in which they appear, you could type in a semi-useful test program using only four bytes:
00: 20 ED FF 00
Just a jump to two bytes before ECHO, which will add six to whatever's in A before falling through to ECHO.
I originally had written in this post that I thought it would eventually show either just the "odd" or just the "even" characters, depending on what A had it in when run. Forgive my massive post edit, because I later realized it was more complicated than that.
6 mod 255 is odd, so it would normally alternate odds/evens... but the carry flag will cause it to always add seven rather than six after you cross 255
In fact, if you run it with the R command, the A register will have 'R' in it and the carry flag will be initially set. So it will always start by displaying 'Y' (R + 7), and go from there.
So the upshot is that you only wind up seeing about one-third of values 0-255. :-(
BUT... since the character set conveniently repeats several times, I think you still wind up getting every character displayed (anyone care to confirm that?), they're just not being displayed as a result of hitting every possible value.
I think that these little minimalistic programming gems are very useful.
There is this nasty pitfall in the Apple-1 when the 3.5us oneshot pulse gets too long and gets near 3.9us, causing setup and hold time violations in the 6520 PIA (the 6820 seems to be more robust, but also must have the problem under some timing conditions).
So you want to measure the 3.5us pulse at pin #5 of the 74123 at location B-3.
But without any screen output going on you can't measure anything as there is no such pulse.
So this is when these little programs in this thread become useful.
The A1, A2 PROMs which come with my kits of course have a more sophisticated diagnostics page built in, no keyboard required, but enabling the diagnostics page involves bending pin #14 of each PROM a little bit, and this is not recommended more than twice, so only one activation and deactivation of the diagnostics page allowed.
These little programs can help to do the measurements without enabling (or having) the diagnostics page.
Very useful !
- Uncle Bernie
From what I can tell, it looks like two characters are always skipped by my four-byte version. So, if you want all the characters, displayed due to hitting every 8-bit value, in order, the six-byte version still reigns as shortest.
If you're fine with just getting some of the 8-bit values, to display nearly (but not quite) all of the characters, in some order or another, then my four-byte version will fit the bill (and makes for a pretty darn good "test" if I do say so myself).
But what if you want a middle ground? All 8-bit values, generating all the characters, but you don't care about order? It turns out you can do it in five bytes:
00: 38 20 ED FF 00
SEC
JMP ECHO-2
BRK
Ensuring that the carry flag is always set will increment A by 7 each time, which will get it to hit every 8-bit value with equal frequency.