From: user Date: Mon, 25 Dec 2023 02:12:56 +0000 (-0600) Subject: Move interp to high mem and add untested aout X-Git-Url: https://git.the-white-hart.net/?a=commitdiff_plain;h=e83772469ea3cba0082b9ec0f8d7d703b94eb3f8;p=atmega%2Fsiggen.git Move interp to high mem and add untested aout --- diff --git a/asm_2/build.sh b/asm_2/build.sh deleted file mode 100755 index 51602be..0000000 --- a/asm_2/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -avra interp.asm diff --git a/asm_2/bytecode.txt b/asm_2/bytecode.txt index 73fbb22..912f46b 100644 --- a/asm_2/bytecode.txt +++ b/asm_2/bytecode.txt @@ -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 diff --git a/asm_2/interp.asm b/asm_2/interp.asm index fe3a7e1..423df3c 100644 --- a/asm_2/interp.asm +++ b/asm_2/interp.asm @@ -40,14 +40,23 @@ ; 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 @@ -102,22 +111,19 @@ 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 diff --git a/asm_2/program.asm b/asm_2/program.asm index b9306d5..23ca3e0 100644 --- a/asm_2/program.asm +++ b/asm_2/program.asm @@ -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 @@ -18,7 +22,11 @@ .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 diff --git a/asm_2/program.sh b/asm_2/program.sh index 5a3d2f5..cb93a17 100755 --- a/asm_2/program.sh +++ b/asm_2/program.sh @@ -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 diff --git a/asm_2/tbc.inc b/asm_2/tbc.inc index 0809eca..4035615 100644 --- a/asm_2/tbc.inc +++ b/asm_2/tbc.inc @@ -546,6 +546,16 @@ .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