1.1 --- a/switcher.oph Sat Jun 27 20:01:40 2015 +0200
1.2 +++ b/switcher.oph Sat Jun 27 20:35:31 2015 +0200
1.3 @@ -36,8 +36,10 @@
1.4 jsr new_task
1.5 .invoke store16 second_task, $76
1.6 jsr new_task
1.7 -test:
1.8 - jmp test
1.9 + .invoke store16 third_task, $76
1.10 + jsr new_task
1.11 +wait:
1.12 + jmp wait ; wait for the switcher to take over
1.13
1.14
1.15
1.16 @@ -209,6 +211,8 @@
1.17 ; check the MSB of each task table entry
1.18
1.19 ldy #1
1.20 +
1.21 +check_new_task:
1.22 lda tasks, y
1.23 cmp #0
1.24 beq add_new_task
1.25 @@ -219,16 +223,19 @@
1.26
1.27 cpy #TASK_TABLE_LENGTH
1.28 bpl no_new_task
1.29 + jmp check_new_task
1.30
1.31 add_new_task:
1.32
1.33 ; copy the task structure location to the table
1.34
1.35 + sei
1.36 lda $77
1.37 sta tasks, y
1.38 dey
1.39 lda $76
1.40 sta tasks, y
1.41 + cli
1.42
1.43 lda #0
1.44 rts
1.45 @@ -239,6 +246,25 @@
1.46
1.47
1.48
1.49 +; remove a task from the table
1.50 +;
1.51 +; A: task offset
1.52 +; affects: A, Y
1.53 +
1.54 +remove_task:
1.55 +
1.56 + ; zero out the table entry
1.57 +
1.58 + tay
1.59 + sei
1.60 + lda #0
1.61 + sta tasks, y
1.62 + iny
1.63 + sta tasks, y
1.64 + cli
1.65 + rts
1.66 +
1.67 +
1.68 ; example tasks
1.69
1.70 first_task:
1.71 @@ -263,4 +289,29 @@
1.72 .invoke add16 1, $7008
1.73 jmp second_task_start
1.74
1.75 +
1.76 +
1.77 +third_task:
1.78 + .byte 0 ; currently unused
1.79 + .byte 0 ; currently unused
1.80 + .byte 0 ; currently unused
1.81 + .byte 0 ; saved flags
1.82 + .word third_task_start ; saved PC
1.83 +third_task_start:
1.84 + .invoke store16 0, $7010
1.85 + ldx #0
1.86 +_loop:
1.87 + lda $7010
1.88 + cmp #$ff
1.89 + bne _continue
1.90 + lda $7011
1.91 + cmp #$ff
1.92 + bne _continue
1.93 + txa
1.94 + jsr remove_task
1.95 + inx
1.96 +_continue:
1.97 + .invoke add16 1, $7010
1.98 + jmp _loop
1.99 +
1.100 ; vim: tabstop=4 expandtab shiftwidth=4