1.1 --- a/macros.oph Sat Jun 27 20:35:31 2015 +0200
1.2 +++ b/macros.oph Sun Jun 28 14:08:35 2015 +0200
1.3 @@ -52,6 +52,51 @@
1.4 sta _2+1
1.5 .macend
1.6
1.7 +; copy word from location to indirect location
1.8 +;
1.9 +; _1: source
1.10 +; _2: target reference
1.11 +;
1.12 +; affects: A, Y
1.13 +
1.14 +.macro mov16_to_ref
1.15 + ldy #0
1.16 + lda _1
1.17 + sta (_2), y
1.18 + iny
1.19 + lda _1+1
1.20 + sta (_2), y
1.21 +.macend
1.22 +
1.23 +; copy word from indirect location to location
1.24 +;
1.25 +; _1: source reference
1.26 +; _2: target
1.27 +;
1.28 +; affects: A, Y
1.29 +
1.30 +.macro mov16_from_ref
1.31 + ldy #0
1.32 + lda (_1), y
1.33 + sta _2
1.34 + iny
1.35 + lda (_1), y
1.36 + sta _2+1
1.37 +.macend
1.38 +
1.39 +; copy byte between indirect locations
1.40 +;
1.41 +; _1: source reference
1.42 +; _2: target reference
1.43 +;
1.44 +; Y: offset
1.45 +; affects: A
1.46 +
1.47 +.macro mov8_refs
1.48 + lda (_1), y
1.49 + sta (_2), y
1.50 +.macend
1.51 +
1.52 ; copy word from location to stack
1.53 ;
1.54 ; _1: source
1.55 @@ -95,4 +140,47 @@
1.56 sta _2+1
1.57 .macend
1.58
1.59 +; subtract word from locations
1.60 +;
1.61 +; _1: valueW
1.62 +; _2: {valueL, valueH} -> {valueL', valueH'}
1.63 +
1.64 +.macro sub16
1.65 + sec
1.66 + lda _2
1.67 + sbc #<_1
1.68 + sta _2
1.69 + lda _2+1
1.70 + sbc #>_1
1.71 + sta _2+1
1.72 +.macend
1.73 +
1.74 +; negate accumulator
1.75 +;
1.76 +; affects: A, C
1.77 +
1.78 +.macro negate
1.79 + clc
1.80 + eor #$ff
1.81 + adc #1
1.82 +.macend
1.83 +
1.84 +; push PC onto a "user space" stack and jump to subroutine
1.85 +;
1.86 +; _1: target
1.87 +
1.88 +.macro call
1.89 + sei ; prevent CPU stack disturbance
1.90 + jsr copy_to_user_stack
1.91 + cli ; permit CPU stack access again
1.92 + jmp _1
1.93 + nop
1.94 +.macend
1.95 +
1.96 +; pull PC from a "user space" stack and return from subroutine
1.97 +
1.98 +.macro return
1.99 + jmp copy_from_user_stack
1.100 +.macend
1.101 +
1.102 ; vim: tabstop=4 expandtab shiftwidth=4