Page 1 of 3
A program for today
Posted: Fri Jul 22, 2011 8:20 pm
by dclxvi
Just supply an OUTPUT routine, which outputs the character in the accumulator (like pretty much every other output routine ever).
Try it!
Code: Select all
P DS 104
Q DS 1
R DS 1
CLD
JSR INIT
LDX #31
L1 TXA
PHA
LDA #0
STA Q
LDX #104
L2 TXA
JSR MUL
PHA
LDA Q
PHA
LDA #10
STA Q
LDA P-1,X
JSR MUL
STA R
PLA
ADC Q
STA Q
PLA
ADC R
STX R
ASL R
DEC R
JSR DIV
STA P-1,X
DEX
BNE L2
LDA #10
STA R
LDA #0
JSR DIV
STA P
LDA Q
EOR #48
JSR OUTPUT
PLA
TAX
CPX #31
BNE L3
LDA #46
JSR OUTPUT
L3 DEX
BNE L1
RTS
INIT
LDA #2
LDX #103
I1 STA P,X
DEX
BPL I1
RTS
MUL
STA R
LDA #0
LDY #8
LSR Q
M1 BCC M2
CLC
ADC R
M2 ROR
ROR Q
DEY
BNE M1
RTS
DIV
LDY #8
ASL Q
D1 ROL
BCS D2
CMP R
BCC D3
D2 SBC R
SEC
D3 ROL Q
DEY
BNE D1
RTS
Posted: Fri Jul 22, 2011 9:09 pm
by 8BIT
Simple as pie.
Nice work!
Posted: Sun Jul 24, 2011 11:04 am
by RichTW
That's great! But I have absolutely no idea how it works...
Posted: Sun Jul 24, 2011 2:43 pm
by BigEd
ah, another well-timed post (not that I've quite got there yet) - marvellous!
Re: A program for today
Posted: Sun Jul 24, 2011 4:06 pm
by BigDumbDinosaur
Just supply an OUTPUT routine, which outputs the character in the accumulator (like pretty much every other output routine ever).
Try it!
A comment would die from sheer loneliness in that code.

Posted: Sun Jul 24, 2011 4:36 pm
by HouseHarris
Ohh I see , excellent. Oh well thats now a demo binary for the Symbiosys operating system. I had most trouble finding out the SYM1 RAE rol and ror work on the accumulator.
Posted: Sun Jul 24, 2011 10:09 pm
by dclxvi
But I have absolutely no idea how it works...
Believe it or not, the program just converts from one base to another.
A comment would die from sheer loneliness in that code.
In this case, it was intentionally uncommented. (Everything else I've written is uncommented because I didn't feel like it

.) I intended for it to be in the spirit of the old BASIC one and two liner programs that you'd see in magazines back in the day -- short, cryptic, a little mysterious, and hopefully amusing. I wanted people to see what it did by trying it rather than looking at the code.
Posted: Sun Jul 24, 2011 10:25 pm
by ElEctric_EyE
...Believe it or not, the program just converts from one base to another....
It does convert without using decimal mode?...
I would like to try this on the 65Org16 when I/we get it up and running...
1 week for the boards. Maybe 1 more week for the parts, if the boards check out when I get them on 8/1.
Posted: Mon Jul 25, 2011 4:14 am
by Nightmaretony
Ok, will be a brat and post a library. The pinball I threw some light code. All the routines arent tested yet, but some do work, I just forget which ones. Enjoy!
Code: Select all
; ***********************************************
; * *
; * LIGHTS LIBRARY *
; * *
; ***********************************************
*= $F100
.ASCII "Lights Library "
; prep the light bits, store in the TempLightResult
PackLightBitsForHardwarePush
LDA TempLight0 ; d0
AND #$01
STA MatrixTemp
LDA TempLight1 ; d1
AND #$01
ASL
ORA MatrixTemp
STA MatrixTemp
LDA TempLight2 ; d2
AND #$01
ASL
ASL
ORA MatrixTemp
STA MatrixTemp
LDA TempLight3 ; d3
AND #$01
ASL
ASL
ASL
ORA MatrixTemp
ASL ; Ok. all 4 bits in low nibble, shift to d4-d7
ASL
ASL
ASL
STA TempLightResult ; done here
RTS
; Takes bytes LightPackBytes0 to LightPackBytes3 and unpacks them to LightHardware bits
; 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
; d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
; Byte 3 Byte 2 Byte 1 Byte 0
UnpackLights
LDY #$00 ; hardware 1-8
LDX LightPackByte3
UnpackLights1
TXA
AND #$01
STA LightHardware1,y
TXA
LSR
TAX
INY
CPY #$08
BNE UnpackLights1
LDY #$00 ; hardware 9-16
LDX LightPackByte2
UnpackLights2
TXA
AND #$01
STA LightHardware9,y
TXA
LSR
TAX
INY
CPY #$08
BNE UnpackLights2
LDY #$00 ; hardware 17-24
LDX LightPackByte1
UnpackLights3
TXA
AND #$01
STA LightHardware17,y
TXA
LSR
TAX
INY
CPY #$08
BNE UnpackLights3
LDY #$00 ; hardware 25-32
LDX LightPackByte0
UnpackLights4
TXA
AND #$01
STA LightHardware25,y
TXA
LSR
TAX
INY
CPY #$08
BNE UnpackLights4
RTS
; PackLightBits
; places LightHardware into LightBytes 0-3
; 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
; d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
; Byte 3 Byte 2 Byte 1 Byte 0
PackLightBits
STZ LightPackByte0
STZ LightPackByte1
STZ LightPackByte2
STZ LightPackByte3
LDY #$08
PackLightBits1
LDA LightHardware1,y
ORA LightPackByte0
ASL
DEY
CPY #$00
BNE PackLightBits1
LDY #$10
PackLightBits2
LDA LightHardware1,y
ORA LightPackByte1
ASL
DEY
CPY #$00
BNE PackLightBits2
LDY #$18
PackLightBits3
LDA LightHardware1,y
ORA LightPackByte2
ASL
DEY
CPY #$00
BNE PackLightBits3
LDY #$20
PackLightBits4
LDA LightHardware1,y
ORA LightPackByte3
ASL
DEY
CPY #$28
BNE PackLightBits4
RTS
LightOn
TAY
LDA #$01
STA LightHardware1,y
RTS
LightOff
TAY
LDA #$00
STA LightHardware1,y
RTS
LightInvert
TAY
LDA LightHardware1,y
EOR #$ff
AND #$01
STA LightHardware1,y
RTS
QueryLight
TAY
LDA LightHardware1,y
RTS
AllLightsOn
LDY #$01
AllLightsOn1
LDA #$01
STA LightHardware1,y
INY
CPY #$20 ; is it count 32?
BNE AllLightsOn1
RTS
AllLightsOff
LDY #$01
AllLightsOff1
LDA #$00
STA LightHardware1,y
INY
CPY #$20 ; is it count 32?
BNE AllLightsOff1
RTS
GroupLightsOn
GroupLightsOff
GroupLightsInvert
; and the indivdual lights as calls here)
.END
Posted: Mon Jul 25, 2011 4:15 am
by Nightmaretony
Had gotten some help toward getting those going, forgot names but thanks!
Posted: Mon Jul 25, 2011 10:12 am
by BigEd
It
takes a few minutes to produce the first output character on visual6502 - I've arranged it so the working variables are in the first few lines of memory and therefore visible. You'll need to press the FastForward button to run the simulation at reasonable speed. The program is located at &1372 because I assembled it on a BBC emulator and that's where it landed.
There's a (somewhat mathematical) paper
here explaining the algorithm - which also gives us a clue as to how far we can get with 8-bit bytes, and how much further we might get with 16-bit bytes. The mul and div routines would need some 8-counts adjusting to 16, at least.
Don't read the paper if you don't want a spoiler!
Well done Bruce!
Cheers
Ed
Posted: Mon Jul 25, 2011 11:05 am
by RichTW
Crikey! Cheers Ed! I don't think I'd've had a chance in hell of reverse engineering that and getting any closer to how it worked.
Very clever though... and a technique I've never heard of before.
And there was me thinking that it must use some previously unknown secret feature of the 6502 that made it start doing arithmetic in base pi
(bit 5 of the status register for example...)
Posted: Mon Jul 25, 2011 11:26 am
by BigEd
I wouldn't have found that paper either, if it weren't for some happy coincidences and a very long-running conversation with a friend I see about every ten years! I didn't do any reversing, just some baffled gazing and some battling with an emulator which, it turns out, was working perfectly but just not bothering to flush its output. I recognised the paper as the right stuff when I saw the line of 2's.
I notice, I think, that Bruce cut off the output just before the point where the algorithm needs an extra wrinkle. Which is only fair - he had a deadline!
Jeremy Gibbons has
more ideas on this topic, but it's a bit lofty.
Posted: Mon Jul 25, 2011 7:17 pm
by jonb
What does it do then? I feel like a 10 year old trying to mingle with my older brother's mates who are all talking in code so they can exclude me...
(Hint : I don't read 6502 m/c)

Posted: Mon Jul 25, 2011 7:18 pm
by jonb
Oh, I see...