6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 10, 2024 2:52 pm

All times are UTC




Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: A program for today
PostPosted: Fri Jul 22, 2011 8:20 pm 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
Just supply an OUTPUT routine, which outputs the character in the accumulator (like pretty much every other output routine ever).

Try it!

Code:
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jul 22, 2011 9:09 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1746
Location: Sacramento, CA
Simple as pie.

Nice work!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 24, 2011 11:04 am 
Offline

Joined: Wed Oct 06, 2010 9:05 am
Posts: 95
Location: Palma, Spain
That's great! But I have absolutely no idea how it works...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 24, 2011 2:43 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
ah, another well-timed post (not that I've quite got there yet) - marvellous!


Top
 Profile  
Reply with quote  
 Post subject: Re: A program for today
PostPosted: Sun Jul 24, 2011 4:06 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8479
Location: Midwestern USA
dclxvi wrote:
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. :D

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 24, 2011 4:36 pm 
Offline

Joined: Sun Nov 28, 2010 6:35 am
Posts: 48
Location: Newcastle Australia
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 24, 2011 10:09 pm 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
RichTW wrote:
But I have absolutely no idea how it works...


Believe it or not, the program just converts from one base to another.

BigDumbDinosaur wrote:
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 :P.) 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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 24, 2011 10:25 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
dclxvi wrote:
...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.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 25, 2011 4:14 am 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
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:
; ***********************************************
; *                                             *
; *              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
   

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 25, 2011 4:15 am 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
Had gotten some help toward getting those going, forgot names but thanks!

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 25, 2011 10:12 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 25, 2011 11:05 am 
Offline

Joined: Wed Oct 06, 2010 9:05 am
Posts: 95
Location: Palma, Spain
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 :lol:
(bit 5 of the status register for example...)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 25, 2011 11:26 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 25, 2011 7:17 pm 
Offline

Joined: Sun May 08, 2011 7:39 am
Posts: 104
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)

:)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 25, 2011 7:18 pm 
Offline

Joined: Sun May 08, 2011 7:39 am
Posts: 104
Oh, I see...


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

All times are UTC


Who is online

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