# HG changeset patch # User Paul Boddie # Date 1435430131 -7200 # Node ID 67e61de96a24c8fb5d099bd09ab70ee371547342 # Parent d7d91332b0aa73a7cffe57cfeeef04559042f13f Fixed new task addition, actually scanning the table. Added locks around table modification operations. Added task removal support. diff -r d7d91332b0aa -r 67e61de96a24 switcher.oph --- a/switcher.oph Sat Jun 27 20:01:40 2015 +0200 +++ b/switcher.oph Sat Jun 27 20:35:31 2015 +0200 @@ -36,8 +36,10 @@ jsr new_task .invoke store16 second_task, $76 jsr new_task -test: - jmp test + .invoke store16 third_task, $76 + jsr new_task +wait: + jmp wait ; wait for the switcher to take over @@ -209,6 +211,8 @@ ; check the MSB of each task table entry ldy #1 + +check_new_task: lda tasks, y cmp #0 beq add_new_task @@ -219,16 +223,19 @@ cpy #TASK_TABLE_LENGTH bpl no_new_task + jmp check_new_task add_new_task: ; copy the task structure location to the table + sei lda $77 sta tasks, y dey lda $76 sta tasks, y + cli lda #0 rts @@ -239,6 +246,25 @@ +; remove a task from the table +; +; A: task offset +; affects: A, Y + +remove_task: + + ; zero out the table entry + + tay + sei + lda #0 + sta tasks, y + iny + sta tasks, y + cli + rts + + ; example tasks first_task: @@ -263,4 +289,29 @@ .invoke add16 1, $7008 jmp second_task_start + + +third_task: + .byte 0 ; currently unused + .byte 0 ; currently unused + .byte 0 ; currently unused + .byte 0 ; saved flags + .word third_task_start ; saved PC +third_task_start: + .invoke store16 0, $7010 + ldx #0 +_loop: + lda $7010 + cmp #$ff + bne _continue + lda $7011 + cmp #$ff + bne _continue + txa + jsr remove_task + inx +_continue: + .invoke add16 1, $7010 + jmp _loop + ; vim: tabstop=4 expandtab shiftwidth=4