1.1 --- a/macros.oph Sun Jun 28 23:20:20 2015 +0200
1.2 +++ b/macros.oph Sun Jun 28 23:30:02 2015 +0200
1.3 @@ -174,15 +174,15 @@
1.4
1.5 .macro pushA
1.6 sei
1.7 - php
1.8 - pha
1.9 + php ; F -> stack
1.10 + pha ; A -> stack
1.11 sty TEMP
1.12 ldy #0
1.13 sta (USER), y
1.14 .invoke sub16 2, USER
1.15 ldy TEMP
1.16 - pla
1.17 - plp
1.18 + pla ; stack -> A
1.19 + plp ; stack -> F
1.20 cli
1.21 .macend
1.22
1.23 @@ -192,13 +192,13 @@
1.24
1.25 .macro pullA
1.26 sei
1.27 - php
1.28 + php ; F -> stack
1.29 sty TEMP
1.30 .invoke add16 2, USER
1.31 ldy #0
1.32 lda (USER), y
1.33 ldy TEMP
1.34 - plp
1.35 + plp ; stack -> F
1.36 cli
1.37 .macend
1.38
1.39 @@ -211,8 +211,8 @@
1.40
1.41 .macro call
1.42 sei
1.43 - php
1.44 - pha
1.45 + php ; F -> stack
1.46 + pha ; A -> stack
1.47 sty TEMP
1.48 ldy #0
1.49 lda #<_2
1.50 @@ -222,8 +222,8 @@
1.51 sta (USER), y
1.52 .invoke sub16 2, USER
1.53 ldy TEMP
1.54 - pla
1.55 - plp
1.56 + pla ; stack -> A
1.57 + plp ; stack -> F
1.58 cli
1.59 jmp _1
1.60 .macend
1.61 @@ -234,12 +234,12 @@
1.62
1.63 .macro return
1.64 sei
1.65 - php
1.66 - pha
1.67 + php ; F -> stack
1.68 + pha ; A -> stack
1.69 .invoke add16 2, USER
1.70 .invoke mov16_from_ref USER, ABSTEMP
1.71 - pla
1.72 - plp
1.73 + pla ; stack -> A
1.74 + plp ; stack -> F
1.75 cli
1.76 jmp (ABSTEMP)
1.77 .macend
2.1 --- a/switcher.oph Sun Jun 28 23:20:20 2015 +0200
2.2 +++ b/switcher.oph Sun Jun 28 23:30:02 2015 +0200
2.3 @@ -70,33 +70,32 @@
2.4 * .invoke store16 second_task, ARG0
2.5 .invoke call new_task, +
2.6 * .invoke store16 third_task, ARG0
2.7 - .invoke call new_task, wait
2.8 + .invoke call new_task, main_wait
2.9
2.10 ; loop while other tasks exist
2.11
2.12 -wait:
2.13 +main_wait:
2.14 ldx #7
2.15 sei
2.16 lda tasks, x ; check for the third task
2.17 cli
2.18 cmp #0
2.19 - bne wait
2.20 + bne main_wait
2.21
2.22 ; where no other tasks exist, remove this task by updating its PC to the
2.23 ; end label and removing its entry
2.24
2.25 - .invoke store16 end, main_task+6
2.26 + .invoke store16 main_end, main_task+6
2.27 lda #0
2.28 - .invoke call remove_task, shutdown
2.29 + .invoke call remove_task, +
2.30
2.31 ; wait for shutdown
2.32
2.33 -shutdown:
2.34 - jmp shutdown
2.35 +* jmp -
2.36
2.37 ; return here with the initial main program stack
2.38
2.39 -end:
2.40 +main_end:
2.41 rts
2.42
2.43
2.44 @@ -146,8 +145,6 @@
2.45 .invoke push16 NEXT
2.46 .invoke push16 CURRENT
2.47
2.48 -init_sp:
2.49 -
2.50 ; initialise the stack frame pointer
2.51
2.52 dex ; make the frame compatible with the task structure
2.53 @@ -156,8 +153,6 @@
2.54 lda #$01 ; $01xx
2.55 sta SPH
2.56
2.57 -test_pc:
2.58 -
2.59 ; test PC for execution of ROM routines
2.60 ; these are probably not re-entrant
2.61
2.62 @@ -171,9 +166,7 @@
2.63 cmp #$80
2.64
2.65 ; exit if PC MSB & $80 != 0
2.66 - beq exit_handler
2.67 -
2.68 -evict_task:
2.69 + beq handler_exit
2.70
2.71 ; obtain the current task using the task offset
2.72
2.73 @@ -197,7 +190,7 @@
2.74 cpy #2
2.75 bpl -
2.76
2.77 -load_task:
2.78 +handler_load_task:
2.79
2.80 ; examine the next task
2.81
2.82 @@ -207,21 +200,19 @@
2.83 ; reset the task index if necessary
2.84
2.85 cpx #TASK_TABLE_LENGTH
2.86 - bne test_task
2.87 + bne +
2.88 ldx #0
2.89
2.90 -test_task:
2.91 -
2.92 ; obtain task location MSB
2.93
2.94 - inx
2.95 +* inx
2.96 lda tasks, x
2.97 sta NEXTH
2.98
2.99 ; install if not a null task (tasks do not reside in zero page)
2.100
2.101 cmp #0
2.102 - bne restore_task
2.103 + bne handler_restore_task
2.104
2.105 ; test against the start index
2.106 ; where a complete circuit of the task table has not been performed,
2.107 @@ -230,7 +221,7 @@
2.108 dex
2.109 txa
2.110 cmp task_offset
2.111 - bne load_task
2.112 + bne handler_load_task
2.113
2.114 ; where a complete circuit has been performed without finding any tasks
2.115 ; uninstall the handler and install the details of the end handler
2.116 @@ -246,7 +237,7 @@
2.117 lda tasks, x
2.118 sta NEXTH
2.119
2.120 -restore_task:
2.121 +handler_restore_task:
2.122
2.123 dex
2.124 lda tasks, x
2.125 @@ -265,7 +256,7 @@
2.126
2.127 .invoke mov16_from_ref NEXT, USER
2.128
2.129 -exit_handler:
2.130 +handler_exit:
2.131
2.132 ; restore zero-page locations used in the handler
2.133
2.134 @@ -315,20 +306,20 @@
2.135
2.136 ldy #1
2.137
2.138 -check_new_task:
2.139 +new_task_check:
2.140 lda tasks, y
2.141 cmp #0
2.142 - beq add_new_task
2.143 + beq new_task_add
2.144 iny
2.145 iny
2.146
2.147 ; if no space is found by the end of the table, exit
2.148
2.149 cpy #TASK_TABLE_LENGTH
2.150 - bpl no_new_task
2.151 - jmp check_new_task
2.152 + bpl new_task_failed
2.153 + jmp new_task_check
2.154
2.155 -add_new_task:
2.156 +new_task_add:
2.157
2.158 ; copy the task structure location to the table
2.159
2.160 @@ -343,7 +334,7 @@
2.161 lda #0
2.162 .invoke return
2.163
2.164 -no_new_task:
2.165 +new_task_failed:
2.166 lda #1
2.167 .invoke return
2.168
2.169 @@ -412,21 +403,21 @@
2.170 .word third_task_start ; saved PC
2.171 third_task_start:
2.172 ldx #2
2.173 -_begin:
2.174 +third_task_begin:
2.175 ldy #0 ; reset counter LSB
2.176 lda #0 ; reset counter MSB
2.177 sta $7021
2.178 -_loop:
2.179 +third_task_loop:
2.180 stx $7028
2.181 sty $7020
2.182 cpy #$ff
2.183 - bne _continue
2.184 + bne third_task_continue
2.185 clc
2.186 lda $7021 ; next MSB
2.187 adc #1
2.188 sta $7021
2.189 cmp #$ff
2.190 - bne _continue
2.191 + bne third_task_continue
2.192 txa
2.193 .invoke pushA
2.194 .invoke call remove_task, +
2.195 @@ -435,14 +426,13 @@
2.196 inx ; move to next offset
2.197 inx ; which is 2 locations away
2.198 cpx #TASK_TABLE_LENGTH
2.199 - beq _next
2.200 - jmp _begin
2.201 -_next:
2.202 - ldx #0
2.203 - jmp _begin
2.204 -_continue:
2.205 + beq +
2.206 + jmp third_task_begin
2.207 +* ldx #0
2.208 + jmp third_task_begin
2.209 +third_task_continue:
2.210 iny
2.211 - jmp _loop
2.212 + jmp third_task_loop
2.213 third_task_stack:
2.214 .word 0
2.215 .word 0