]> git.the-white-hart.net Git - atmega/siggen.git/commitdiff
Move interp to high mem and add untested aout
authoruser <none>
Mon, 25 Dec 2023 02:12:56 +0000 (20:12 -0600)
committeruser <none>
Mon, 25 Dec 2023 02:12:56 +0000 (20:12 -0600)
asm_2/build.sh [deleted file]
asm_2/bytecode.txt
asm_2/interp.asm
asm_2/program.asm
asm_2/program.sh
asm_2/tbc.inc

diff --git a/asm_2/build.sh b/asm_2/build.sh
deleted file mode 100755 (executable)
index 51602be..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env bash
-
-avra interp.asm
index 73fbb2284c66ad8368187479cdf9c1fd5af6da5d..912f46b8c4d39a66a9d79159de671b14ea04b881 100644 (file)
@@ -67,14 +67,14 @@ FXYN
 2XY5   shra
 2XY6   rol
 2XY7   ror
-2XY8   spi
+2XY8   spi/i2c/stx/srx
 2XY9   mft
 2XYA   mtt
 2XYB   ddir
 2XYC   din
 2XYD   dout
 2XYE   ain
-2XYF
+2XYF   aout
 
                v[x], v[y]+n
 3XYn   ldb
index fe3a7e1aa4be38cdda3befad66d18f17289d7e44..423df3ce791c13b48d93a9b6917dc5b7472c8aa6 100644 (file)
 ; r31 h/
 
 
+; ------------------------------------------------------------------------------
+; Locations
+
+.equ   TORTOISE_CODE_START = 0x0000
+.equ   TORTOISE_DATA_START = SRAM_START
+.equ   IVT_INIT_START      = SMALLBOOTSTART  ; Must be at bootloader start
+.equ   INTERPRETER_START   = 0x3800
+
 
 ; ------------------------------------------------------------------------------
-; Interrupt vector table
+; Interrupt vector table and reset code
 
 .cseg
 
-; FIXME: move everything to the bootloader section, let bytecode take low mem
-.org 0x0000
+; Put in the bootloader section to leave low memory for bytecode
+.org IVT_INIT_START
+
        rjmp    reset     ; RESET
        reti
        reti              ; INT0
        reti
 
 
-; ------------------------------------------------------------------------------
-; Bytecode
-
-.include "./program.asm"
-
-
-; ------------------------------------------------------------------------------
-; Reset entry point
-
-.cseg
-
+       ; ----- Reset entry point
 reset:
-       ; ----- Disable interrupts and set stack pointer to top of SRAM
-
+       ; Make sure interrupts are disabled
        clr     r25
        out     SREG, r25
+
+       ; Move IVT to the bootloader section
+       ldi     r25, (1 << IVCE)
+       out     MCUCR, r25
+       ldi     r25, (1 << IVSEL)
+       out     MCUCR, r25
+
+       ; Set stack pointer to top of SRAM
        ldi     r25, HIGH(RAMEND)
        out     SPH, r25
        ldi     r25, LOW(RAMEND)
@@ -180,13 +186,18 @@ _zreg_done:
        st      Z+, r25
 
        ; Instruction pointer
-       ldi     r25, LOW(entry)
+       ldi     r25, LOW(TORTOISE_CODE_START)
        mov     r2, r25
-       ldi     r25, HIGH(entry)
+       ldi     r25, HIGH(TORTOISE_CODE_START)
        mov     r3, r25
 
-       ; --------------------------------------------------------------
-       ; Main loop
+       rjmp    loop
+
+
+; ------------------------------------------------------------------------------
+; Main loop
+
+.org INTERPRETER_START
 loop:
        ; Check for countdown events
        in      r25, TIFR0
@@ -549,7 +560,7 @@ imm4_dispatch_jumptable:
        rjmp    exec_din
        rjmp    exec_dout
        rjmp    exec_ain
-       rjmp    exec_nop
+       rjmp    exec_aout
 
 branch_dispatch_jumptable:
        rjmp    exec_jtab
@@ -1489,6 +1500,59 @@ _ain_wait:
        rjmp    _dispatch_done_writeback_reg
 
 
+exec_aout:
+       ; Restrict operand to 0-7
+       ldi     r25, 0x07
+       and     r10, r25
+
+       clr     r25
+
+       ldi     ZL, LOW(_aout_jtab)
+       ldi     ZH, HIGH(_aout_jtab)
+       add     ZL, r10
+       adc     ZH, r25
+       ijmp
+
+_aout_jtab:
+       rjmp    _aout_ocr0a
+       rjmp    _aout_ocr0b
+       rjmp    _aout_ocr1a
+       rjmp    _aout_ocr1b
+       rjmp    _aout_ocr2a
+       rjmp    _aout_ocr2b
+       rjmp    _aout_done
+       rjmp    _aout_done
+
+_aout_ocr0a:
+       out     OCR0A, r6
+       rjmp    _aout_done
+
+_aout_ocr0b:
+       out     OCR0B, r6
+       rjmp    _aout_done
+
+_aout_ocr1a:
+       sts     OCR1AH, r7
+       sts     OCR1AL, r8
+       rjmp    _aout_done
+
+_aout_ocr1b:
+       sts     OCR1BH, r7
+       sts     OCR1BL, r8
+       rjmp    _aout_done
+
+_aout_ocr2a:
+       sts     OCR2A, r6
+       rjmp    _aout_done
+
+_aout_ocr2b:
+       sts     OCR2B, r6
+       rjmp    _aout_done
+
+_aout_done:
+       rjmp    _dispatch_done
+
+
 exec_ldb:
        ; Load byte
        movw    ZL, r10
@@ -1678,16 +1742,18 @@ exec_jmp:
 
 .dseg
 
-; 16 general purpose 32-bit "registers" (V0-VF)
+; Place data at the top of memory
 .org   RAMEND+1 - (16*4) - (16*2) - 16
 
+; Top-of-stack (used by bytecode program) just below interpreter state
 stack:
-       .byte   16         ; Guard against accidentally clobbering regs
-
+       .byte   16         ; Guard against accidental underflows clobbering regs
 
+; 16 individual countdown timers
 interp_clocks:
        .byte   16*2
 
+; 16 general purpose 32-bit "registers" (V0-VF)
 interp_regs:
        .byte   16*4
 
index b9306d519d656beb6b0fe54251125fa94b6623c5..23ca3e05fc974b91d9b8b518e70003c3b556914d 100644 (file)
@@ -1,8 +1,12 @@
 ; ------------------------------------------------------------------------------
-; Bytecode program, to be included with interpreter
+; Bytecode program, interpreter included
 ; ------------------------------------------------------------------------------
+.include "interp.asm"
 
 
+; ------------------------------------------------------------------------------
+; Definitions
+
 ; Pins for Nokia 5110 LCD
 .equ   P_LED  = 0x8
 .equ   P_SCLK = 0x5
 .equ   STEP_MAX = 2560
 
 
+; ------------------------------------------------------------------------------
+; Code section
+
 .cseg
+.org TORTOISE_CODE_START
 
 entry:
        ; Set up ports and SPI
@@ -337,6 +345,10 @@ ext_init:
        ori     r25, (1 << ADC1D)
        sts     DIDR0, r25
 
+       ; Set up timer/counter 2 for pwm
+       ; ldi   r25, ()
+       ; sts   TCCR2A, r25
+
        ijmp
 
 font:
@@ -357,7 +369,11 @@ font:
        .db     0b11111110, 0b10010010, 0b10010010, 0b10000010, 0b00000000, 0xe
        .db     0b11111110, 0b00010010, 0b00010010, 0b00000010, 0b00000000, 0xf
 
+
+; ------------------------------------------------------------------------------
+
 .dseg
+.org TORTOISE_DATA_START
 
 spi_buf:
        .byte   16
index 5a3d2f52983ce8f68d353f311bece237c3bfe946..cb93a17a5431d65094d718f65a69cd97b08dc634 100755 (executable)
@@ -5,5 +5,7 @@ TARGET="atmega328p"
 PORT="/dev/ttyUSB0"
 PROGRAMMER="-P ${PORT} -b 19200 -c avrisp"
 
-avrdude ${PROGRAMMER} -p ${TARGET} -U flash:w:interp.hex
+# This HFUSE value (0xde) uses the smallest bootloader (256 bytes) and places
+# the reset vector within it.  The interpreter places the IVT there as well.
+avrdude ${PROGRAMMER} -p ${TARGET} -U hfuse:w:0xde:m -U flash:w:$1
 
index 0809ecaa9a5c12d562f260e48e8b3cadafd91a1f..40356152f04015907d4e8c0d094c9c7ce299747f 100644 (file)
        .dw     (0x2 << 12) | (@0 << 8) | (@1 << 4) | (0xe)
 .endmacro
 
+.macro T_AOUT
+       .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) | (0xf)
+.endmacro
+
 .macro T_NEG
        T_NOT   @0
        T_ADDS  @0, 1