6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Oct 06, 2024 9:13 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu May 27, 2004 12:23 pm 
Offline

Joined: Thu May 27, 2004 12:12 pm
Posts: 1
Hello i am a newbie with the 6502.Is the first year im associated with this.I want to make a program(using a 6502 simulator) which adds two time periods which have this format: hh:mm:ss.The program must add hours with hours,minutes with minutes and seconds with seconds.Minutes and seconds must not be greater t han 60.Anyone who can help?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu May 27, 2004 2:57 pm 
Offline

Joined: Wed Dec 18, 2002 3:20 am
Posts: 113
Hi Absolut,

First off, you're gonna need to learn the instruction set for the processor, or at least enough of it to perform your task. There is a ton of good material here on this site that will get you going, as well as many, many resources on the net available for instruction set, coding techniques and flaws to watch out for on the 6502.

Then you're gonna need to learn and understand your simulator - ie: how does it handle input? Are you just going to set memory locations with the appropriate data or is it keyed in? What about output? How is memory organized? How do you call the simulator's built in functions (ie: output, assuming there is one)

Then I'd recommend a much simpler program as your initial program - something that just inputs and displays, or inputs two numbers, add's them and displays, or heck, just takes two fixed numbers and adds them and stores it in ram (and not worry about input/output and just looks at contents of ram)

Then you ned to come up with whether you are going to do 12 hour or 24 hour periods, which does change the math.

Then you might want to come up with a flow chart or pseudo code to represent what you want it to do when - not everyone does this, but many if not most do it (at least for large programs)

It sounds like you are going to need to have some sort of input, store your 2 hour minutes and second numbers, if it were me, I'd check the entries to make sure they are valid times, ie: that minutes and seconds are both <60, that the hours is <13 or <24 (depending on format), then you're gonna need to add the numbers, and do a compare and then some branching if they are to do some other math to get seconds, minutes or hours generated from the math and store them.

The program you need to write (I'm saying need to because it almost looks like a homework assignment type, if it isn't I appologize) isn't a very difficult one, the most difficult part will be learning the instruction set and understanding it - which in itself is not terribly difficult as the 6502 is a fairly simple processor.

If you come up with some code, and are having trouble, I'm sure just about anyone here would be more then happy to help if they can, but you're gonna have to come up with the first steps...

_________________
-Tony
KG4WFX


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jun 08, 2004 2:35 pm 
Offline

Joined: Sun Aug 24, 2003 7:17 pm
Posts: 111
Hello

I fully agree with Tancor, what he writes is certainly right! But I think that the central code remaining when the I/O piece has been dealt with could be a quite elegant demonstration of BCD arithmetics, CARRY flag and of the SBC operation. These concepts are discussed in this forum right now on other places!

Assume that after I/O one has the two sequences HH1,MM1,SS1 and HH2,MM2,SS2 BCD coded in 3 byte, respectively.

Compute first SS1 + SS2 with BCD arithmetics.

If the sum is greater or equal to 100 then carry will be set. The 60 can be subtracted and then carry again be set. This will then be added for the next sum which is MM1 + MM2.

If the sum is less then 100 carry will be unset. One then tries to subtract 60 checking if the result is positive, i.e. that carry is set. Or better leave carry unset and subtract 59 instead. If then carry is set one is set to compute MM1 + MM2 taking this carry into account. If carry is unset the sum SS1 + SS2 was less then 60 and the old value must be restored. No carry for the sum MM1 + MM2.

The complete code:

Code:
T1 = $50    ;FIRST INPUT SEQUENCE
T2 = $53    ;SECOND INPUT SEQUENCE
DT = $56    ;OUTPUT
       *=$6000
       SED
       LDX #$02   ;LOOP 2,1,0 FOR SEC, MINUTES, HOURS
       CLC
L1     LDA T1,X   ;GET TIME ELEMENT
       ADC T2,X   ;ADD MATCHING TIME ELEMENT
       BCC L2
       SBC #$60   ;THE SUM WAS LARGER THEN 100
       SEC        ;CARRY TO NEXT TIME ELEMENT AS 60 WAS SUBTRACTED
       BRA L3
L2     TAY        ;SAVE OLD VALUE FOR POSSIBLE RETRIVAL
       SBC #$59   ;INSTEAD OF SETTING CARRY, REDUCE 60 TO 59
       BCS L3
       TYA        ;ORIGINAL VALUE LESS THEN 60
L3     STA DT,X   ;SAVE RESULT
       DEX
       BPL L1
       CLD
       BRK


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

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