6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 11:34 am

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sun Mar 05, 2006 3:30 pm 
Offline

Joined: Sun Mar 05, 2006 3:03 pm
Posts: 5
Location: zhuhai city Guangdong,China
I want to writing a calendar,Using 6502 assembler,but i am a freshman in 6502.Now ,i think hardly,but i don't know how to writing.My freind ,help me ,i am very confused!
help me ,help me ,thanx.
Note:the calendar includes: year,month,day,hour,min,and week.
:oops:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Mar 05, 2006 4:01 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Much of what you want is already done for you, here.  This is part of my 6502 interrupts primer, with the RTC (real-time clock) being given as an example, along with code.

_________________
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: thanx
PostPosted: Mon Mar 06, 2006 1:31 am 
Offline

Joined: Sun Mar 05, 2006 3:03 pm
Posts: 5
Location: zhuhai city Guangdong,China
But i can't using the 6502 core'hardware,for example:RTC,or interrupt.
my boss want to using 6502 assemble language to writing! can u help me again... thanx too.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 06, 2006 4:48 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
The address shown above does have the assembly language code, and what is shown is implemented on my own workbench on 6502 hardware.  The RTC is not a special piece of hardware.  It is software being run on the 6502, timed by the interrupts generated by a 6522 (or anything capable of generating the interrupts at the appropriate time interval).  If you can make your question or situation more clear, perhaps I we can help you further.

_________________
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: Hmmm....
PostPosted: Mon Mar 06, 2006 8:58 am 
Offline

Joined: Sun Mar 05, 2006 3:03 pm
Posts: 5
Location: zhuhai city Guangdong,China
do u have a ICQ or MSN, i want to asking u.


Top
 Profile  
Reply with quote  
 Post subject: i am very hurry!
PostPosted: Mon Mar 06, 2006 9:02 am 
Offline

Joined: Sun Mar 05, 2006 3:03 pm
Posts: 5
Location: zhuhai city Guangdong,China
i am very hurry,But some question i don't how to express.
i mean is :i want to using 6502 assembler but don't using other internal hardwares.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 06, 2006 12:18 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
I don't have ICQ or MSN but you can E-mail me at wilsonmines@dslextreme.com .  I check this forum as often as I check my E-mail though (which is many times per day), and there may be others who would be interested to learn from the discussion here.

Trying to keep accurate time of day and calendar without any hardware timer of any kind would be nearly impossible—certainly extremely impractical; and if the processor did anything else besides keep time, that would upset the cycle counts and your time-keeping would not be accurate.  You could do it without interrupts if you had a counter of some type that the program could poll and increment the clock and calendar variables once each time that the count rolled over.  But this counter must keep consistent time regardless of what the processor does.  I've even seen the powerline frequency (50Hz or 60Hz) divided down through multi-megohm resistors, filtered by a capacitor (forming an RC filter), and fed to a gate with a Schmitt-trigger input, with its output connected to a port pin to serve as a 1-bit counter for keeping time.

Interrupts are extremely valuable, but not difficult.  That's what the whole 6502 interrupts primer is about.  I hope you can get it translated, because it thoroughly explains, in simple terms, what interrupts are, how they work, shows how easy they are to use, and why they are they only practical way to do certain things.  The code in the primer is in 6502 assembly, which is what you are asking for.

_________________
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: Thanx again!
PostPosted: Mon Mar 06, 2006 12:56 pm 
Offline

Joined: Sun Mar 05, 2006 3:03 pm
Posts: 5
Location: zhuhai city Guangdong,China
Thanx a lots ! i'll trying ,i think ,i'll make it...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 10, 2006 4:02 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
I met a handycapped man 24 years ago who did this with his Apple II for a timeclock for a hired helper to clock in & out once per day.  It was accurate enough for the application, but he couldn't do other things with it while it was busy doing that since the cycle counts would immediately be out of control.

_________________
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: Fri Mar 10, 2006 5:43 am 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
dclxvi wrote:
I'm not bashing using interrupts, it's just my personal preference to use delays and exact timing in lieu of interrupts, and it's now that I've gotten the hang of how to do it, I find it to be an elegant and highly underrated technique.


This is good only when you know a priori what the CPU's clock speed is, that it'll never change for the lifetime of the application, and that nothing else will be running on the hardware -- in short, this is great for deep embedded use with very restricted resources.

For more general purpose applications, you'll want to use event-driven coding techniques, where interrupts are virtually a necessity. The 6502 makes a great event-driven programming architecture (don't believe me? Witness the success of the GEOS operating system which artifically kept the Commodore 64 alive way longer than it probably would have otherwise) -- through careful design of the code, you can get performance that meets or exceeds that of cooperative multitasking (known to be superior to preemptive multitasking when it comes to raw task-switching speed), since there is no CPU state to be saved between "task switches." Of course, the disadvantage is that the application now needs to maintain its own state, but guess what -- that is precisely what object oriented coding is. If you don't believe me, check out this link for a great write-up equating event-driven and object oriented programming techniques. I could try to explain it myself, but I just wouldn't do it justice. http://eventdrivenpgm.sourceforge.net/ -- starting on page 14 (at least of the PDF version).

For event-driven programming to work well, it is important that no event handler take longer than, say, 10ms to run (this is roughly equivalent to 100 task switches per second, in preemptive multitasking circles). Obviously, on 1MHz machines, this means individual functions won't be doing very much, but on faster CPUs, real work starts to pile up. Therefore, . . .

Quote:
1. Even out the timing as you go along.


This rule changes to Limit the amount of time your handlers take.

Quote:
2. Modularize!


This is an abject and absolute requirement for event-driven programming, since the only way to get anything of value done in response to any stimulus (real or otherwise) is to call a subroutine.

Quote:
3. Get the timing evened out before trying to meet any tight timing requirements.


This is true of event-driven programming as well, and for all the same reasons. If your CPU cannot handle multitasking, but must otherwise be responsive to multiple input stimuli, yet you still can't get the thing to work with the right timing, you probably need a faster CPU. Most event dispatcher main loops are very streamlined, and therefore, "optimizing out" the "OS" will offer very little. Witness Contiki for a great example. And, yes, GEOS too.

Quote:
4. Make it easy to change the delay time


This unfortunately is death to an event-driven program, so this rule has its analogistic equivalent: always use hardware interrupts with wall-clock times. This allows the software to be CPU clock-speed (and if necessary, even family) independent.

The disadvantage is maintaining the timer count-down list adds some overhead. Amiga-style and VMS-style timers could support an indefinite number of registered timers because of how it worked internally, thus yielding a very accurate timer resource. However, adding and removing a time request could be expensive since it required performing arithmetic to fragment and re-order the timeout queue. The timer code was smart enough to take this into consideration of course. But, it's something you've got to be aware of when writing the timer drivers.

Quote:
5. Know the instruction set.


This is important for ensuring that event handlers conform to the "no-longer-than-10ms" rule of thumb.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 27, 2006 4:37 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362


Last edited by dclxvi on Tue Mar 28, 2006 12:49 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 27, 2006 5:18 am 
Offline

Joined: Mon Mar 20, 2006 2:03 am
Posts: 24
GARTHWILSON wrote:
...But this counter must keep consistent time regardless of what the processor does. I've even seen the powerline frequency (50Hz or 60Hz) divided down through multi-megohm resistors, filtered by a capacitor (forming an RC filter), and fed to a gate with a Schmitt-trigger input, with its output connected to a port pin to serve as a 1-bit counter for keeping time.



The Commodore 64 did something like this, they took 9VAC from the power supply and ran it through a schmitt trigger to create 60Hz clock pulses for the 6526 TOD counter.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 27, 2006 7:09 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
Quote:
it seems like posting unconventional approaches accomplishes little but filling message boards with debate.

That's constructive though, as long as it does not deteriorate to name-calling and irrelevant insults (or any insults for that matter) like I've seen happen on less-civil forums.

_________________
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: Mon Mar 27, 2006 3:24 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
The one thing nice about us as 6502 lovers is that we ARE non conventional and carry the seed of hacking outside the box with us at all times. That si also why there are so many creative approchaes to programming problems in here...

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Mar 27, 2006 7:26 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
dclxvi wrote:
By using a 16-bit counter instead of an 8-bit counter you can extend the range, but the minimum number of cycles increases. With a 24-bit counter, the minimum will be far less 1283 but you can hit over beyond a million cycles exactly, which will be sufficient for most applications (I've never needed more than a 24-bit counter). So with an assembler macro that covers a handful of cases (including cases like using a pair of NOPs to delay 4 cycles, PHA PLA or PHP PLP to delay 7 cycles, etc.), you can easily hit any number of cycles you need. You can add register and/or flag preservation too, as that can be useful.


The Kestrel is intended to be a general purpose pseudo-replacement for my desktop computer. As such, the CPU may start out at 4MHz because that's what every piece of logic around it can handle, or later on when I move to FPGAs, it may go up to 16MHz or 20MHz. The problem is, if *you* write a program for the Kestrel, and I upgrade, why would/should I have to come to you to recompile some binary that I received from you?

Or, why should I have to recompile literally everything that I've ever compiled for it from day one?

It doesn't make sense from a usability point of view.

I stand by my comments.

Quote:
million cycles) this single subroutine might be all you ever need. For very short delays, say 5-10 cycles, you'll probably have to use self-modifying code that pre-modifies the code.


Again, it's all you need if and only if you're running precisely one and only one program on the CPU at any given time. Otherwise, while burning cycles in an idle loop, you're denying other programs the right to run. In a multitasking environment (even event-driven and cooperative!), this is performance suicide.

Quote:
So it IS possible to add and delete routines on the fly without disturbing your timing.


Yes, and the program logic to make this magic happen will more than dwarf the time spent by most subroutines that interface to this mechanism. So to mitigate, you end up with time slices allocated in hundreds of milliseconds, thus limiting your multitasking capabilities at best to 10 tasks or so. Most mutlitasking engines are capable of handling more than 100 task switches per second before you even begin to notice sluggishness. Note that the limit of human perception is 100ms, so with 10 task switches per second, you're going to notice it being dog slow anyway.

Quote:
An interesting point to note is that once you've built the central "time manager" you really don't have rewrite any extant subroutines, just add the cycle count as a value returned.


Unless said extant subroutine returns something else in its registers or whatever. Unless I'm misunderstanding your definition of extant subroutine?

Quote:
Now all of this may be far more exotic than anyone (me included) needs, but I find this sort of approach absolutely fascinating. There is vast amount of unexplored territory because many people are of the mindset that interrupts are the only way to go. I should mention that one reason it hasn't been explored is because there are usually very few places where exact timing is a necessity.


Don't tell the folks of QNX, Inc. that, where their *entire business* is built around QNX, a hard real-time, interrupt-driven microkernel that supports POSIX API (in fact, it is the world's first microkernel to do so). I'm sure they had a very good rationale for not going the cycle-counting route, and that route is explained above -- software overhead, pure and simple.

Quote:
Even languages like C and Forth that are closely related to low level code tend to obscure cycle counts.


This is false. They never even considered cycle counts to begin with, but if they did, managing cycle counts would be trivial for each.

Quote:
Alas, it seems like posting unconventional approaches accomplishes little but filling message boards with debate. :)


But this type of banter is precisely how people learn new things. However, you need to recognize, that the learning goes both directions. :)

What you're describing is essentially how pure-event-driven architectures work, where you have a centralized main loop that is responsible for scheduling units of functionality (I'm going to use the term callback since that is what they really are). However, instead of the message target being the primary scheduling parameter, it is instead based on execution delay heuristics, passing whatever messages happens to be waiting for that callback at that time.

Doable? You bet! I'm not saying it's not. And it's something I've thought about.

But the overhead involved with using interrupts is minimal, compared to the scheduling overhead of a pure delay-based model. Interrupts work so well because it is *truely* a parallel environment (you have an external timing source that is operating independently of the CPU itself). Indeed, interrupts are the core of inter-processor communications. You cannot get true inter-processor communications with a delay-based approach -- at least, not without very expensive polling operations.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 5 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: