Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Creates a new task to be run
- ; inputs: de = pointer to filename
- ; outputs: a = status value
- NewThread:
- call SafeInterruptDI
- push af
- push de
- call LoadExecutableToRAM
- if(SUCCESS)
- jr nz,_ ; failed to load
- call GetNextFreeThread
- if(OPEN_THREAD_SPACE)
- jr nz,_ ; no space for new threads to go
- ld (hl),STATE_STARTED
- inc hl ; load the thread's state
- ld (hl),e
- inc hl
- ld (hl),d
- inc hl ; load the exacutable address
- ex de,hl
- add hl,bc
- ex de,hl
- ld (hl),e
- inc hl
- ld (hl),d
- inc hl ; load the stack address
- pop de
- ld (hl),e
- inc hl
- ld (hl),d ; load the pointer to the filename into the thread entry
- pop af
- call SafeInterruptEI
- ld a,SUCCESS
- ret
- _ pop de
- ld b,a
- pop af
- call SafeInterruptEI
- ld a,b
- ret
- SafeInterruptDI:
- xor a ;Set nc (interrupts)
- push af ;Check interrupts
- pop af
- ld a,i ;pe if interrupt
- di
- ret pe ;Return if interrupts on
- dec sp ;Otherwise, robust test
- dec sp
- pop af
- or a ;Set nc (interrupts)
- ret nz ;Return if interrupts on
- scf ;Set c (no interrupts)
- ret ;Return
- ; safely returns interrupts
- ; inputs af = state flags
- SafeInterruptEI:
- ret c
- ei
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement