I wrote this out in my senior economics class. The notes are sometimes cryptic, and there were bugs. I tried to fix some as I typed it up though. These are just the parts that I feel like trying to understand.

Code:
;EventQueue structure
;.dw address, message; the message can be an address, a value, or nothing at all
EventHandlerHalt:;this section was added 5/21/10
   halt
EventHandler:
   ld a,(EventQueueSize)
   or a
   ;jp z,EventHandler;/upon rereading, I should halt to save battery
   jp z,EventHandlerHalt
   ld hl,(EventQueue+2)
   ex de,hl
   ld hl,ReturnToHere
   push hl
   ld hl,(EventQueue)
   ;call hl;/not a valid instruction
   jp (hl);will return to ReturnToHere
ReturnToHere:;added later because call hl is not real
   ld hl,(EventQueue+4)
   ld de,(EventQueue)
   ld bc,(EventQueueSize)
   ldir
   ld a,(EventQueueSize)
   sub 4
   ld (EventQueueSize),a
   jp EventHandler
   
ScheduleEvent:
   push af
   ld c,4;b=0 /that's what the notes said
   add hl,bc
   ld de, EventQueue
   ld a,(EventQueueSize)
   push hl
   ld l,a \ ld h,0
   add hl,de
   ex de,hl,hl
   pop hl; hl=addr, bc = 4 /I can only assume hl is the address of the event
   add a,4
   jp c,EQoverflowHandler
   ldir
   ld c,8
   pop af
   ret
   
;TaskScheduleSize
;.db size
;TaskSchedule
;.dw timer, maxtimer, address, message
TaskManager:;although not marked in the notes, this is called from the interrupt
   ld a,(ScheduleSize)
   ld hl,TaskSchedule
   ld b,0; added later to fix the bc enigma
TaskManagerLoop:;just called it loop in the notes
   ld de,1;to begin with, the notes are cryptic, and it's barely legible on this line.  it was added as an afterthought and I have no idea what it is
   ;ld bc,8 ;the notes are cryptic about this one.  The event scheduler that it calls seems to need b to be 0
   ;I think I may have figured out what the bc is, so I'm commenting out the line to fix the bug
   dec (hl)
   push hl;added later to fix obvious bug
   call z,ScheduleEvent
   pop hl;added to match the push
   sub 8;
   ret z
   ld bc,8 ; this fixes that bc enigma
   add hl,bc
   jp TaskManagerLoop
   
ScheduleEventHL: ;schedule event for code other than the task manager

EQoverflowHandler:
;remove all tasks in the removable task list
;remove all events in the removable event list
;move tasks together (condense them)
;move events together
;if recovery was successful, schedule the recovery event and return
;if recovery was a failure, try to preserve data in RAM then display a panic screen, then soft reset and try to determine the cause
My Z80 is rusty - are you going for a cooperative or preemptive multitasking? If the later, is that even possible with Z80?
Kllrnohj wrote:
My Z80 is rusty - are you going for a cooperative or preemptive multitasking? If the later, is that even possible with Z80?

Presumably cooperative if he's writing an event handler and task manager.
elfprince13 wrote:
Presumably cooperative if he's writing an event handler and task manager.


You still need event handlers and task managers for preemptive as well. Wink
Kllrnohj wrote:
elfprince13 wrote:
Presumably cooperative if he's writing an event handler and task manager.


You still need event handlers and task managers for preemptive as well. Wink


Yeah, but based on his comments it looks like he's setting it up for the running applications to schedule the events, meaning he's relying on their cooperation.
A small tip: An easier way to call HL is

Code:
...code here...
 call call_hl
...code here...

call_hl:
 jp (hl)
I was going for cooperative. I could do preemptive by having the interrupt keep track of how long the current event has been running, and if it goes on for too long, store the state of it somewhere, schedule an event that would resume the halted event, and then move the halted event off of the queue. I plan to implement none of this of course, I just wrote this so I wouldn't be bored in class.
Also, I just noticed this:

Code:
   ld hl,(EventQueue+4)
   ld de,(EventQueue)
   ld bc,(EventQueueSize)
   ldir

First of all, are those HL and DE loads supposed to be from memory? Second, isn't (EventQueueSize) an 8-bit variable? You might want to load B with 0.
Good catch. I believe EventQueueSize is an 8 bit value.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement