Advertisement
Eeems

Untitled

Jul 2nd, 2011
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Creates a new task to be run
  2. ; inputs:   de = pointer to filename
  3. ; outputs:  a  = status value
  4. NewThread:
  5.     call SafeInterruptDI
  6.     push af
  7.     push de
  8.         call LoadExecutableToRAM
  9.         if(SUCCESS)
  10.             jr nz,_ ; failed to load
  11.         call GetNextFreeThread
  12.         if(OPEN_THREAD_SPACE)
  13.             jr nz,_ ; no space for new threads to go
  14.         ld (hl),STATE_STARTED
  15.         inc hl      ; load the thread's state
  16.         ld (hl),e
  17.         inc hl
  18.         ld (hl),d
  19.         inc hl      ; load the exacutable address
  20.         ex de,hl
  21.         add hl,bc
  22.         ex de,hl
  23.         ld (hl),e
  24.         inc hl
  25.         ld (hl),d
  26.         inc hl      ; load the stack address
  27.     pop de
  28.     ld (hl),e
  29.     inc hl
  30.     ld (hl),d       ; load the pointer to the filename into the thread entry
  31.     pop af
  32.     call SafeInterruptEI
  33.     ld a,SUCCESS
  34.     ret
  35. _   pop de
  36.     ld b,a
  37.     pop af
  38.     call SafeInterruptEI
  39.     ld a,b
  40.     ret
  41.  
  42. SafeInterruptDI:
  43.     xor a       ;Set nc (interrupts)
  44.     push af     ;Check interrupts
  45.     pop af
  46.     ld a,i      ;pe if interrupt
  47.     di
  48.         ret pe      ;Return if interrupts on
  49.     dec sp      ;Otherwise, robust test
  50.     dec sp
  51.     pop af
  52.     or a        ;Set nc (interrupts)
  53.         ret nz      ;Return if interrupts on
  54.     scf         ;Set c (no interrupts)
  55.     ret         ;Return
  56. ; safely returns interrupts
  57. ; inputs    af = state flags
  58. SafeInterruptEI:
  59.     ret c
  60.     ei
  61.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement