# HG changeset patch # User Paul Boddie # Date 1435527002 -7200 # Node ID c3c68373ee6d07f24ca24687c058dd9934fa32af # Parent a0b9ea4264242ab2e8acbf2deebbc7bd3334fd15 Added comments and tidied label usage. diff -r a0b9ea426424 -r c3c68373ee6d macros.oph --- a/macros.oph Sun Jun 28 23:20:20 2015 +0200 +++ b/macros.oph Sun Jun 28 23:30:02 2015 +0200 @@ -174,15 +174,15 @@ .macro pushA sei - php - pha + php ; F -> stack + pha ; A -> stack sty TEMP ldy #0 sta (USER), y .invoke sub16 2, USER ldy TEMP - pla - plp + pla ; stack -> A + plp ; stack -> F cli .macend @@ -192,13 +192,13 @@ .macro pullA sei - php + php ; F -> stack sty TEMP .invoke add16 2, USER ldy #0 lda (USER), y ldy TEMP - plp + plp ; stack -> F cli .macend @@ -211,8 +211,8 @@ .macro call sei - php - pha + php ; F -> stack + pha ; A -> stack sty TEMP ldy #0 lda #<_2 @@ -222,8 +222,8 @@ sta (USER), y .invoke sub16 2, USER ldy TEMP - pla - plp + pla ; stack -> A + plp ; stack -> F cli jmp _1 .macend @@ -234,12 +234,12 @@ .macro return sei - php - pha + php ; F -> stack + pha ; A -> stack .invoke add16 2, USER .invoke mov16_from_ref USER, ABSTEMP - pla - plp + pla ; stack -> A + plp ; stack -> F cli jmp (ABSTEMP) .macend diff -r a0b9ea426424 -r c3c68373ee6d switcher.oph --- a/switcher.oph Sun Jun 28 23:20:20 2015 +0200 +++ b/switcher.oph Sun Jun 28 23:30:02 2015 +0200 @@ -70,33 +70,32 @@ * .invoke store16 second_task, ARG0 .invoke call new_task, + * .invoke store16 third_task, ARG0 - .invoke call new_task, wait + .invoke call new_task, main_wait ; loop while other tasks exist -wait: +main_wait: ldx #7 sei lda tasks, x ; check for the third task cli cmp #0 - bne wait + bne main_wait ; where no other tasks exist, remove this task by updating its PC to the ; end label and removing its entry - .invoke store16 end, main_task+6 + .invoke store16 main_end, main_task+6 lda #0 - .invoke call remove_task, shutdown + .invoke call remove_task, + ; wait for shutdown -shutdown: - jmp shutdown +* jmp - ; return here with the initial main program stack -end: +main_end: rts @@ -146,8 +145,6 @@ .invoke push16 NEXT .invoke push16 CURRENT -init_sp: - ; initialise the stack frame pointer dex ; make the frame compatible with the task structure @@ -156,8 +153,6 @@ lda #$01 ; $01xx sta SPH -test_pc: - ; test PC for execution of ROM routines ; these are probably not re-entrant @@ -171,9 +166,7 @@ cmp #$80 ; exit if PC MSB & $80 != 0 - beq exit_handler - -evict_task: + beq handler_exit ; obtain the current task using the task offset @@ -197,7 +190,7 @@ cpy #2 bpl - -load_task: +handler_load_task: ; examine the next task @@ -207,21 +200,19 @@ ; reset the task index if necessary cpx #TASK_TABLE_LENGTH - bne test_task + bne + ldx #0 -test_task: - ; obtain task location MSB - inx +* inx lda tasks, x sta NEXTH ; install if not a null task (tasks do not reside in zero page) cmp #0 - bne restore_task + bne handler_restore_task ; test against the start index ; where a complete circuit of the task table has not been performed, @@ -230,7 +221,7 @@ dex txa cmp task_offset - bne load_task + bne handler_load_task ; where a complete circuit has been performed without finding any tasks ; uninstall the handler and install the details of the end handler @@ -246,7 +237,7 @@ lda tasks, x sta NEXTH -restore_task: +handler_restore_task: dex lda tasks, x @@ -265,7 +256,7 @@ .invoke mov16_from_ref NEXT, USER -exit_handler: +handler_exit: ; restore zero-page locations used in the handler @@ -315,20 +306,20 @@ ldy #1 -check_new_task: +new_task_check: lda tasks, y cmp #0 - beq add_new_task + beq new_task_add iny iny ; if no space is found by the end of the table, exit cpy #TASK_TABLE_LENGTH - bpl no_new_task - jmp check_new_task + bpl new_task_failed + jmp new_task_check -add_new_task: +new_task_add: ; copy the task structure location to the table @@ -343,7 +334,7 @@ lda #0 .invoke return -no_new_task: +new_task_failed: lda #1 .invoke return @@ -412,21 +403,21 @@ .word third_task_start ; saved PC third_task_start: ldx #2 -_begin: +third_task_begin: ldy #0 ; reset counter LSB lda #0 ; reset counter MSB sta $7021 -_loop: +third_task_loop: stx $7028 sty $7020 cpy #$ff - bne _continue + bne third_task_continue clc lda $7021 ; next MSB adc #1 sta $7021 cmp #$ff - bne _continue + bne third_task_continue txa .invoke pushA .invoke call remove_task, + @@ -435,14 +426,13 @@ inx ; move to next offset inx ; which is 2 locations away cpx #TASK_TABLE_LENGTH - beq _next - jmp _begin -_next: - ldx #0 - jmp _begin -_continue: + beq + + jmp third_task_begin +* ldx #0 + jmp third_task_begin +third_task_continue: iny - jmp _loop + jmp third_task_loop third_task_stack: .word 0 .word 0