# HG changeset patch # User Paul Boddie # Date 1435499129 -7200 # Node ID c9cc853003d339d4fe204cc25b2f3366509de441 # Parent caa80f526ae6b3df5d11538276a850677a3aaed5 Added user stack operations and updated the example tasks to maintain registers. diff -r caa80f526ae6 -r c9cc853003d3 macros.oph --- a/macros.oph Sun Jun 28 14:08:35 2015 +0200 +++ b/macros.oph Sun Jun 28 15:45:29 2015 +0200 @@ -183,4 +183,34 @@ jmp copy_from_user_stack .macend +; push A onto the "user space" stack +; +; affects: USER (gains A), TEMP + +.macro pushA + sei + pha + sty TEMP + ldy #0 + sta (USER), y + .invoke sub16 1, USER + ldy TEMP + pla + cli +.macend + +; pull A from the "user space" stack +; +; affects: A, USER (loses A), TEMP + +.macro pullA + sei + sty TEMP + .invoke add16 1, USER + ldy #0 + lda (USER), y + ldy TEMP + cli +.macend + ; vim: tabstop=4 expandtab shiftwidth=4 diff -r caa80f526ae6 -r c9cc853003d3 switcher.oph --- a/switcher.oph Sun Jun 28 14:08:35 2015 +0200 +++ b/switcher.oph Sun Jun 28 15:45:29 2015 +0200 @@ -26,6 +26,8 @@ .alias CURRENT $74 .alias CURRENTH $75 .alias USER $76 +.alias USERH $77 +.alias TEMP $78 .alias ARG0 $80 .alias ARG0H $81 .alias ARG1 $82 @@ -407,8 +409,11 @@ .byte 0 ; saved flags .word first_task_start ; saved PC first_task_start: - .invoke add16 1, $7000 - jmp first_task_start + lda #1 +first_task_continue: + sta $7000 + adc #1 + jmp first_task_continue @@ -418,8 +423,11 @@ .byte 0 ; saved flags .word second_task_start ; saved PC second_task_start: - .invoke add16 1, $7008 - jmp second_task_start + lda #1 +second_task_continue: + sta $7008 + adc #1 + jmp second_task_continue @@ -429,20 +437,25 @@ .byte 0 ; saved flags .word third_task_start ; saved PC third_task_start: - .invoke store16 0, $7010 ldx #0 + ldy #0 _loop: - lda $7010 - cmp #$ff + cpy #$ff bne _continue + inc $7011 lda $7011 cmp #$ff bne _continue + tya + .invoke pushA txa .invoke call remove_task + .invoke pullA + tay inx _continue: - .invoke add16 1, $7010 + iny + sty $7010 jmp _loop third_task_stack: .word 0