]> git.the-white-hart.net Git - atmega/siggen.git/commitdiff
Separate bytecode and utilities to separate files
authoruser <none>
Wed, 16 Aug 2023 22:53:38 +0000 (17:53 -0500)
committeruser <none>
Wed, 16 Aug 2023 22:53:38 +0000 (17:53 -0500)
asm_2/interp.asm
asm_2/program.asm [new file with mode: 0644]
asm_2/tbc.inc
asm_2/util.inc [new file with mode: 0644]

index 7949b8f14acf8da9fcc4d846862061600f3dfeae..aac5c400f1ac179b89fb108a61edd03e57f3f0e5 100644 (file)
@@ -1,5 +1,5 @@
 .include "./m328Pdef.inc"
-
+.include "./util.inc"
 .include "./tbc.inc"
 
 
 ; ------------------------------------------------------------------------------
 ; Bytecode
 
-
-; Pins for Nokia 5110 LCD
-.equ   P_LED  = 0x4
-.equ   P_SCLK = 0x5
-.equ   P_MOSI = 0x3
-.equ   P_DC   = 0x0
-.equ   P_RST  = 0x1
-.equ   P_SCE  = 0x2
-
-
-.cseg
-
-entry:
-       ; Set up ports and SPI
-       T_EXT   ext_init
-
-       ; Reset the LCD
-       T_JAL   lcd_reset
-
-       ; Do something with the LCD
-       T_MOVI  A0, 0x21
-       T_JAL   lcd_cmd
-       T_MOVI  A0, 0xb8
-       T_JAL   lcd_cmd
-       T_MOVI  A0, 0x04
-       T_JAL   lcd_cmd
-       T_MOVI  A0, 0x14
-       T_JAL   lcd_cmd
-       T_MOVI  A0, 0x20
-       T_JAL   lcd_cmd
-       T_MOVI  A0, 0x09
-       T_JAL   lcd_cmd
-
-       ; Idle while blinking the LCD backlight
-       T_MOVS  S0, 0
-       T_MOVS  S1, 1
-led_loop:
-       T_DOUT  S1, P_LED
-       T_MOVI  A0, 20000
-       T_JAL   delay
-
-       T_DOUT  S0, P_LED
-       T_MOVI  A0, 20000
-       T_JAL   delay
-
-       T_JMP   led_loop
-
-
-halt:
-       T_JMP   halt
-
-delay:
-       T_SUBS  A0, 1
-       T_BNZ   delay
-       T_JALR  TM, RA
-
-lcd_reset:
-       T_MOVS  TM, 0
-       T_DOUT  TM, P_RST
-       T_MOVS  TM, 1
-       T_DOUT  TM, P_RST
-       T_JALR  TM, RA
-
-lcd_cmd:
-       T_MOVI  TM, spi_buf
-       T_STB   A0, TM, 0
-
-       T_MOVS  A0, 0
-       T_DOUT  A0, P_DC
-       T_DOUT  A0, P_SCE
-       T_SPI   TM, 1
-       T_MOVS  A0, 1
-       T_DOUT  A0, P_SCE
-
-       T_JALR  TM, RA
-
-ext_init:
-       movw    ZL, r24
-
-       ; Ports B and C all outputs
-       ldi     r25, 0xff
-       out     DDRB, r25
-       out     DDRC, r25
-
-       ; Set up SPI
-       ldi     r25, (0 << SPIE) | \
-                    (1 << SPE)  | \
-                    (0 << DORD) | \
-                    (1 << MSTR) | \
-                    (0 << CPOL) | \
-                    (0 << CPHA) | \
-                    (0b01 << SPR0)
-       out     SPCR, r25
-       ldi     r25, (0 << SPI2X)
-       out     SPSR, r25
-
-       ijmp
-
-
-.dseg
-
-spi_buf:
-       .byte   16
+.include "./program.asm"
 
 
 ; ------------------------------------------------------------------------------
@@ -257,7 +155,13 @@ _zreg_loop:
        rjmp    _zreg_loop
 _zreg_done:
 
-       ; TODO: Set stack pointer
+       ; Set stack pointer
+       ldi     ZL, LOW(interp_regs + (0xd * 4))
+       ldi     ZH, HIGH(interp_regs + (0xd * 4))
+       ldi     r24, LOW(stack)
+       ldi     r25, HIGH(stack)
+       st      Z+, r24
+       st      Z+, r25
 
        ; Instruction pointer
        ldi     r25, LOW(entry)
@@ -1305,6 +1209,11 @@ exec_jmp:
 .dseg
 
 ; 16 general purpose 32-bit "registers" (V0-VF)
+.org   RAMEND+1 - (16*4) - 16
+
+stack:
+       .byte   16         ; Guard against accidentally clobbering regs
+
 interp_regs:
        .byte   16*4
 
diff --git a/asm_2/program.asm b/asm_2/program.asm
new file mode 100644 (file)
index 0000000..873e307
--- /dev/null
@@ -0,0 +1,114 @@
+; ------------------------------------------------------------------------------
+; Bytecode program, to be included with interpreter
+; ------------------------------------------------------------------------------
+
+
+; Pins for Nokia 5110 LCD
+.equ   P_LED  = 0x4
+.equ   P_SCLK = 0x5
+.equ   P_MOSI = 0x3
+.equ   P_DC   = 0x0
+.equ   P_RST  = 0x1
+.equ   P_SCE  = 0x2
+
+
+.cseg
+
+entry:
+       ; Set up ports and SPI
+       T_EXT   ext_init
+
+       ; Reset the LCD
+       T_JAL   lcd_reset
+
+       ; Do something with the LCD
+       T_MOVI  A0, 0x21
+       T_JAL   lcd_cmd
+       T_MOVI  A0, 0xb8
+       T_JAL   lcd_cmd
+       T_MOVI  A0, 0x04
+       T_JAL   lcd_cmd
+       T_MOVI  A0, 0x14
+       T_JAL   lcd_cmd
+       T_MOVI  A0, 0x20
+       T_JAL   lcd_cmd
+       T_MOVI  A0, 0x09
+       T_JAL   lcd_cmd
+
+       ; Idle while blinking the LCD backlight
+       T_MOVS  S0, 0
+       T_MOVS  S1, 1
+led_loop:
+       T_DOUT  S1, P_LED
+       T_MOVI  A0, 20000
+       T_JAL   delay
+
+       T_DOUT  S0, P_LED
+       T_MOVI  A0, 20000
+       T_JAL   delay
+
+       T_JMP   led_loop
+
+
+halt:
+       T_JMP   halt
+
+delay:
+       T_SUBS  A0, 1
+       T_BNZ   delay
+       T_JALR  TM, RA
+
+lcd_putc:
+       T_JALR  TM, RA
+
+lcd_gotoxy:
+       T_JALR  TM, RA
+
+lcd_reset:
+       T_MOVS  TM, 0
+       T_DOUT  TM, P_RST
+       T_MOVS  TM, 1
+       T_DOUT  TM, P_RST
+       T_JALR  TM, RA
+
+lcd_cmd:
+       T_MOVI  TM, spi_buf
+       T_STB   A0, TM, 0
+
+       T_MOVS  A0, 0
+       T_DOUT  A0, P_DC
+       T_DOUT  A0, P_SCE
+       T_SPI   TM, 1
+       T_MOVS  A0, 1
+       T_DOUT  A0, P_SCE
+
+       T_JALR  TM, RA
+
+ext_init:
+       movw    ZL, r24
+
+       ; Ports B and C all outputs
+       ldi     r25, 0xff
+       out     DDRB, r25
+       out     DDRC, r25
+
+       ; Set up SPI
+       ldi     r25, (0 << SPIE) | \
+                    (1 << SPE)  | \
+                    (0 << DORD) | \
+                    (1 << MSTR) | \
+                    (0 << CPOL) | \
+                    (0 << CPHA) | \
+                    (0b01 << SPR0)
+       out     SPCR, r25
+       ldi     r25, (0 << SPI2X)
+       out     SPSR, r25
+
+       ijmp
+
+
+.dseg
+
+spi_buf:
+       .byte   16
+
index 3241cbf96b4b169862766bed5dc5df050f8dd657..7523e1751eb0ee7fa12998d88872b378fa5edc37 100644 (file)
 .equ   FL = Vf
 
 
-; ------------------------------------------------------------------------------
-; The assembler packaged with avr_sim has a bug where PC evaluates to PC-1.
-; The avra assembler gets it correct, but I can't get the supposedly predefined
-; __AVRASM_VERSION__ macro to work, so for now just manually enter the error in
-; PC in this symbol.
-
-; Use with AVRA assembler
-; "AVRA: advanced AVR macro assembler Version 1.3.0 Build 1 (8 May 2010)"
-.equ   PCERROR = 0
-
-; Use with assembler packaged with avr_sim
-; "gavrasm Gerd's AVR assembler version 5.4 (C)2022 by DG4FAC"
-;.equ  PCERROR = -1
-
-
 ; ------------------------------------------------------------------------------
 ; Instruction building macros
 
diff --git a/asm_2/util.inc b/asm_2/util.inc
new file mode 100644 (file)
index 0000000..6bebd1c
--- /dev/null
@@ -0,0 +1,32 @@
+; Include guards are broken in AVRA, so these won't save you.
+#ifndef _UTIL_INC_
+#define _UTIL_INC_
+
+
+; ------------------------------------------------------------------------------
+; The assembler packaged with avr_sim has a bug where PC evaluates to PC-1.
+; The avra assembler gets it correct, but I can't get the supposedly predefined
+; __AVRASM_VERSION__ macro to work, so for now just manually enter the error in
+; PC in this symbol.
+
+; Use with AVRA assembler
+; "AVRA: advanced AVR macro assembler Version 1.3.0 Build 1 (8 May 2010)"
+.equ   PCERROR = 0
+
+; Use with assembler packaged with avr_sim
+; "gavrasm Gerd's AVR assembler version 5.4 (C)2022 by DG4FAC"
+;.equ  PCERROR = -1
+
+
+; ------------------------------------------------------------------------------
+; The AVR assembler doesn't come with an alignment directive
+
+.macro ALIGN
+       .if ((PC-PCERROR) % @0) != 0
+       .org (PC-PCERROR) + (@0 - ((PC-PCERROR) % @0))
+       .endif
+.endmacro
+
+
+.endif  /* _UTIL_INC_ */
+