1.1 --- a/switcher.oph Sun Jun 28 23:20:20 2015 +0200
1.2 +++ b/switcher.oph Sun Jun 28 23:30:02 2015 +0200
1.3 @@ -70,33 +70,32 @@
1.4 * .invoke store16 second_task, ARG0
1.5 .invoke call new_task, +
1.6 * .invoke store16 third_task, ARG0
1.7 - .invoke call new_task, wait
1.8 + .invoke call new_task, main_wait
1.9
1.10 ; loop while other tasks exist
1.11
1.12 -wait:
1.13 +main_wait:
1.14 ldx #7
1.15 sei
1.16 lda tasks, x ; check for the third task
1.17 cli
1.18 cmp #0
1.19 - bne wait
1.20 + bne main_wait
1.21
1.22 ; where no other tasks exist, remove this task by updating its PC to the
1.23 ; end label and removing its entry
1.24
1.25 - .invoke store16 end, main_task+6
1.26 + .invoke store16 main_end, main_task+6
1.27 lda #0
1.28 - .invoke call remove_task, shutdown
1.29 + .invoke call remove_task, +
1.30
1.31 ; wait for shutdown
1.32
1.33 -shutdown:
1.34 - jmp shutdown
1.35 +* jmp -
1.36
1.37 ; return here with the initial main program stack
1.38
1.39 -end:
1.40 +main_end:
1.41 rts
1.42
1.43
1.44 @@ -146,8 +145,6 @@
1.45 .invoke push16 NEXT
1.46 .invoke push16 CURRENT
1.47
1.48 -init_sp:
1.49 -
1.50 ; initialise the stack frame pointer
1.51
1.52 dex ; make the frame compatible with the task structure
1.53 @@ -156,8 +153,6 @@
1.54 lda #$01 ; $01xx
1.55 sta SPH
1.56
1.57 -test_pc:
1.58 -
1.59 ; test PC for execution of ROM routines
1.60 ; these are probably not re-entrant
1.61
1.62 @@ -171,9 +166,7 @@
1.63 cmp #$80
1.64
1.65 ; exit if PC MSB & $80 != 0
1.66 - beq exit_handler
1.67 -
1.68 -evict_task:
1.69 + beq handler_exit
1.70
1.71 ; obtain the current task using the task offset
1.72
1.73 @@ -197,7 +190,7 @@
1.74 cpy #2
1.75 bpl -
1.76
1.77 -load_task:
1.78 +handler_load_task:
1.79
1.80 ; examine the next task
1.81
1.82 @@ -207,21 +200,19 @@
1.83 ; reset the task index if necessary
1.84
1.85 cpx #TASK_TABLE_LENGTH
1.86 - bne test_task
1.87 + bne +
1.88 ldx #0
1.89
1.90 -test_task:
1.91 -
1.92 ; obtain task location MSB
1.93
1.94 - inx
1.95 +* inx
1.96 lda tasks, x
1.97 sta NEXTH
1.98
1.99 ; install if not a null task (tasks do not reside in zero page)
1.100
1.101 cmp #0
1.102 - bne restore_task
1.103 + bne handler_restore_task
1.104
1.105 ; test against the start index
1.106 ; where a complete circuit of the task table has not been performed,
1.107 @@ -230,7 +221,7 @@
1.108 dex
1.109 txa
1.110 cmp task_offset
1.111 - bne load_task
1.112 + bne handler_load_task
1.113
1.114 ; where a complete circuit has been performed without finding any tasks
1.115 ; uninstall the handler and install the details of the end handler
1.116 @@ -246,7 +237,7 @@
1.117 lda tasks, x
1.118 sta NEXTH
1.119
1.120 -restore_task:
1.121 +handler_restore_task:
1.122
1.123 dex
1.124 lda tasks, x
1.125 @@ -265,7 +256,7 @@
1.126
1.127 .invoke mov16_from_ref NEXT, USER
1.128
1.129 -exit_handler:
1.130 +handler_exit:
1.131
1.132 ; restore zero-page locations used in the handler
1.133
1.134 @@ -315,20 +306,20 @@
1.135
1.136 ldy #1
1.137
1.138 -check_new_task:
1.139 +new_task_check:
1.140 lda tasks, y
1.141 cmp #0
1.142 - beq add_new_task
1.143 + beq new_task_add
1.144 iny
1.145 iny
1.146
1.147 ; if no space is found by the end of the table, exit
1.148
1.149 cpy #TASK_TABLE_LENGTH
1.150 - bpl no_new_task
1.151 - jmp check_new_task
1.152 + bpl new_task_failed
1.153 + jmp new_task_check
1.154
1.155 -add_new_task:
1.156 +new_task_add:
1.157
1.158 ; copy the task structure location to the table
1.159
1.160 @@ -343,7 +334,7 @@
1.161 lda #0
1.162 .invoke return
1.163
1.164 -no_new_task:
1.165 +new_task_failed:
1.166 lda #1
1.167 .invoke return
1.168
1.169 @@ -412,21 +403,21 @@
1.170 .word third_task_start ; saved PC
1.171 third_task_start:
1.172 ldx #2
1.173 -_begin:
1.174 +third_task_begin:
1.175 ldy #0 ; reset counter LSB
1.176 lda #0 ; reset counter MSB
1.177 sta $7021
1.178 -_loop:
1.179 +third_task_loop:
1.180 stx $7028
1.181 sty $7020
1.182 cpy #$ff
1.183 - bne _continue
1.184 + bne third_task_continue
1.185 clc
1.186 lda $7021 ; next MSB
1.187 adc #1
1.188 sta $7021
1.189 cmp #$ff
1.190 - bne _continue
1.191 + bne third_task_continue
1.192 txa
1.193 .invoke pushA
1.194 .invoke call remove_task, +
1.195 @@ -435,14 +426,13 @@
1.196 inx ; move to next offset
1.197 inx ; which is 2 locations away
1.198 cpx #TASK_TABLE_LENGTH
1.199 - beq _next
1.200 - jmp _begin
1.201 -_next:
1.202 - ldx #0
1.203 - jmp _begin
1.204 -_continue:
1.205 + beq +
1.206 + jmp third_task_begin
1.207 +* ldx #0
1.208 + jmp third_task_begin
1.209 +third_task_continue:
1.210 iny
1.211 - jmp _loop
1.212 + jmp third_task_loop
1.213 third_task_stack:
1.214 .word 0
1.215 .word 0