]> git.the-white-hart.net Git - atmega/siggen.git/commitdiff
Add DDIR digital port direction instruction
authoruser <none>
Fri, 1 Sep 2023 09:43:42 +0000 (04:43 -0500)
committeruser <none>
Fri, 1 Sep 2023 09:43:42 +0000 (04:43 -0500)
This should be useful for switching between output and pull-up input,
which can be useful for scanning switch matrices.

asm_2/bytecode.txt
asm_2/interp.asm
asm_2/tbc.inc

index 08eb179ad7ddbe3b8e407e065fc2956842a60bda..69069c6c930ca5c073f833b12275e2b50099b8f9 100644 (file)
@@ -67,10 +67,10 @@ FXYN
 2XY5   shra
 2XY6   rol
 2XY7   ror
-2XY8
-2XY9   spi
-2XYA   mft
-2XYB   mtt
+2XY8   spi
+2XY9   mft
+2XYA   mtt
+2XYB   ddir
 2XYC   din
 2XYD   dout
 2XYE   ain
index 8ad4d7fc525a929d6b698700aebd49e072325eeb..6589817f677c352d332f51f46fba691d72a640b8 100644 (file)
@@ -542,10 +542,10 @@ imm4_dispatch_jumptable:
        rjmp    exec_shra
        rjmp    exec_rol
        rjmp    exec_ror
-       rjmp    exec_nop
        rjmp    exec_spi
        rjmp    exec_mft
        rjmp    exec_mtt
+       rjmp    exec_ddir
        rjmp    exec_din
        rjmp    exec_dout
        rjmp    exec_ain
@@ -1343,6 +1343,49 @@ exec_mtt:
        rjmp    _dispatch_done
 
 
+exec_ddir:
+       ; Restrict operand to 0-f
+       ldi     r25, 0x0f
+       and     r10, r25
+
+       ; Extract LSB from first operand
+       ldi     r23, 0x01
+       and     r6, r23
+       clr     r7
+
+       ; Mask of all bits except LSB
+       ldi     r24, 0xfe
+       ldi     r25, 0xff
+
+       ; Rotate LSB and mask into position specified by second operand
+_ddir_loop:
+       dec     r10
+       brlt    _din_loop_done
+
+       sec
+       rol     r24
+       rol     r25
+
+       clc
+       rol     r6
+       rol     r7
+
+       rjmp    _ddir_loop
+_ddir_loop_done:
+
+       ; Read-modify-write
+       in      r22, DDRB
+       in      r23, DDRC
+       and     r22, r24
+       and     r23, r25
+       or      r22, r6
+       or      r23, r7
+       out     DDRB, r22
+       out     DDRC, r23
+
+       rjmp    _dispatch_done
+
+
 exec_din:
        ; Restrict operand to 0-f
        ldi     r25, 0x0f
index d0898c1a3ea7bcd31b11727431e53351d8eacc65..40356152f04015907d4e8c0d094c9c7ce299747f 100644 (file)
        .if @1 < 1 || @1 > 0x10
        .error "Tortoise Bytecode: SPI immediate value outside 4-bit range"
        .endif
-       .dw     (0x2 << 12) | (@0 << 8) | ((@1 & 0xf) << 4) | (0x9)
+       .dw     (0x2 << 12) | (@0 << 8) | ((@1 & 0xf) << 4) | (0x8)
 .endmacro
 
 .macro T_MFT
        .if @1 < 0 || @1 > 0xf
        .error "Tortoise Bytecode: immediate value outside 4-bit range"
        .endif
-       .dw     (0x2 << 12) | (@0 << 8) | (@1 << 4) | (0xa)
+       .dw     (0x2 << 12) | (@0 << 8) | (@1 << 4) | (0x9)
 .endmacro
 
 .macro T_MTT
+       .if @0 < 0 || @0 > 0xf
+       .error "Tortoise Bytecode: invalid variable register"
+       .endif
+       .if @1 < 0 || @1 > 0xf
+       .error "Tortoise Bytecode: immediate value outside 4-bit range"
+       .endif
+       .dw     (0x2 << 12) | (@0 << 8) | (@1 << 4) | (0xa)
+.endmacro
+
+.macro T_DDIR
        .if @0 < 0 || @0 > 0xf
        .error "Tortoise Bytecode: invalid variable register"
        .endif