From 060fbe0a05eab3ab6997ad0a2403b63c006ca522 Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Sat, 21 Jul 2012 02:28:57 +0200 Subject: [PATCH] Moved sync-generator code into project. Lots of duplicated code, but .... --- syncgen/Makefile | 307 +++++++++++++++++++++++++++++++++++++++++++ syncgen/avrosdlogo.h | 57 ++++++++ syncgen/main.c | 266 +++++++++++++++++++++++++++++++++++++ 3 files changed, 630 insertions(+) create mode 100644 syncgen/Makefile create mode 100644 syncgen/avrosdlogo.h create mode 100644 syncgen/main.c diff --git a/syncgen/Makefile b/syncgen/Makefile new file mode 100644 index 0000000..e68a327 --- /dev/null +++ b/syncgen/Makefile @@ -0,0 +1,307 @@ +# Hey Emacs, this is a -*- makefile -*- + +# AVR-GCC Makefile template, derived from the WinAVR template (which +# is public domain), believed to be neutral to any flavor of "make" +# (GNU make, BSD make, SysV make) +# +# Adaptations by Jon Langseth +# This modified template is placed in the public domain like the original. +# + + +# Target name and MCU setup ------------------------------------------------- + +TARGET = syncgen + +MCU = attiny85 + +# Processor frequency. +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# Typical values are: +# F_CPU = 1000000 +# F_CPU = 1843200 +# F_CPU = 2000000 +# F_CPU = 3686400 +# F_CPU = 4000000 +# F_CPU = 7372800 +# F_CPU = 8000000 +# F_CPU = 11059200 +# F_CPU = 14745600 +# F_CPU = 16000000 +# F_CPU = 18432000 +# F_CPU = 20000000 +F_CPU = 20000000 + +# Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/ +FUSE_LOW = 0xCF +FUSE_HIGH = 0xDF +FUSE_EXT = 0xFF +# Have had problems with efuse suggested by fusecalc, must check :P + +# Source files to compile --------------------------------------------------- + +# List C source files here. (C dependencies are automatically generated.) +SRC = main.c + +# List Assembler source files here. +# Make them always end in a capital .S. +ASRC = + +# Optimization level, can be [0, 1, 2, 3, s]. +# 0 = turn off optimization. s = optimize for size. +# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) +OPT = 1 + +# Output formats and debug format ------------------------------------------- + +# Output format. (can be srec, ihex, binary) +FORMAT = ihex + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = dwarf-2 + +# Command names (and paths/parameters to them...) --------------------------- + +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU)UL + +# Place -I options here +CINCS = + +CFLAGS = -g$(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CSTANDARD) +CFLAGS += -funsigned-char +CFLAGS += -funsigned-bitfields +CFLAGS += -fpack-struct +CFLAGS += -fshort-enums +CFLAGS += -Wall +CFLAGS += -Wstrict-prototypes +#CFLAGS += -mshort-calls +#CFLAGS += -fno-unit-at-a-time +#CFLAGS += -Wundef +#CFLAGS += -Wunreachable-code +#CFLAGS += -Wsign-compare + +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs + + +#Additional libraries. + +MATH_LIB = -lm + +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +# If this is left blank, then it will use the Standard printf version. +PRINTF_LIB = +#PRINTF_LIB = $(PRINTF_LIB_MIN) +#PRINTF_LIB = $(PRINTF_LIB_FLOAT) + + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +# If this is left blank, then it will use the Standard scanf version. +SCANF_LIB = +#SCANF_LIB = $(SCANF_LIB_MIN) +#SCANF_LIB = $(SCANF_LIB_FLOAT) + + +# External memory options + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff + +EXTMEMOPTS = + + +#LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref +LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) + + +# Programming support using avrdude. Settings and variables. + +AVRDUDE_PROGRAMMER = usbtiny +AVRDUDE_PORT = usb + +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +#AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level. Please use this when submitting bug +# reports about avrdude. See +# to submit bug reports. +#AVRDUDE_VERBOSE = -v -v + +AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER) + + +# Define all object files. +OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: elf hex eep size + +elf: $(TARGET).elf +hex: $(TARGET).hex +eep: $(TARGET).eep +lss: $(TARGET).lss +sym: $(TARGET).sym + +# Display size of file. +HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex +ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf + +size: + @echo + $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf + $(SIZE) --target=$(FORMAT) $(TARGET).hex + +# Program the device. +program: $(TARGET).hex $(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + + +# make fuseread can be used to test programmer connectivity, and naturally to verify fuses.. +fuseread: + $(AVRDUDE) $(AVRDUDE_BASIC) -q -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h + +FUSES = +ifdef FUSE_EXT +FUSES += -U efuse:w:$(FUSE_EXT):m +endif +FUSES += -U hfuse:w:$(FUSE_HIGH):m +FUSES += -U lfuse:w:$(FUSE_LOW):m + +fusebits: $(TARGET).hex + $(AVRDUDE) $(AVRDUDE_BASIC) $(FUSES) +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: $(TARGET).elf + $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof + + +extcoff: $(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + + +# Link: create ELF output file from object files. +$(TARGET).elf: $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + + +# Compile: create object files from C source files. +.c.o: + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +# Target: clean project. +clean: + $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \ + $(TARGET).map $(TARGET).sym $(TARGET).lss \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build elf hex eep lss sym program coff extcoff clean depend + diff --git a/syncgen/avrosdlogo.h b/syncgen/avrosdlogo.h new file mode 100644 index 0000000..6ba138e --- /dev/null +++ b/syncgen/avrosdlogo.h @@ -0,0 +1,57 @@ +#ifndef _IMG_LOGO_H +#define _IMG_LOGO_H +const uint8_t testimg_width = 64; +const uint8_t testimg_height = 50; +uint8_t testimg_data[] = { + 0b00000000, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b00000000, + 0b00001111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, + 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, + 0b00010111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11101000, + 0b00010100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00101000, + 0b00010100, 0b00000000, 0b00110000, 0b11000000, 0b01101111, 0b11100000, 0b00000000, 0b00101000, + 0b00100100, 0b00000000, 0b00110000, 0b11000000, 0b01101100, 0b11110000, 0b00000000, 0b00100100, + 0b00100100, 0b00000000, 0b01111000, 0b01100000, 0b11001100, 0b00011000, 0b00000000, 0b00100100, + 0b00100100, 0b00000000, 0b01111000, 0b01100000, 0b11001100, 0b00011000, 0b00000000, 0b00100100, + 0b00100100, 0b00000000, 0b11001100, 0b01100000, 0b11001100, 0b00011000, 0b00000000, 0b00100100, + 0b00100100, 0b00000000, 0b11001100, 0b00110001, 0b10001100, 0b00011000, 0b00000000, 0b00100100, + 0b00100100, 0b00000000, 0b10000100, 0b00110001, 0b10001100, 0b11110000, 0b00000000, 0b00100100, + 0b01001000, 0b00000001, 0b10000110, 0b00110001, 0b10001111, 0b11000000, 0b00000000, 0b00010010, + 0b01001000, 0b00000001, 0b11111110, 0b00011011, 0b00001100, 0b01100000, 0b00000000, 0b00010010, + 0b01001000, 0b00000011, 0b00000011, 0b00011011, 0b00001100, 0b01100000, 0b00000000, 0b00010010, + 0b01001000, 0b00000011, 0b00000011, 0b00011011, 0b00001100, 0b00110000, 0b00000000, 0b00010010, + 0b01001000, 0b00000011, 0b00000011, 0b00001010, 0b00001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001000, 0b00000110, 0b00000001, 0b10001110, 0b00001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001001, 0b11100110, 0b00000001, 0b10001110, 0b01001100, 0b00001101, 0b10000000, 0b00010010, + 0b01001001, 0b00000000, 0b00000000, 0b00000000, 0b01000000, 0b00001001, 0b00000000, 0b00010010, + 0b01001001, 0b00011101, 0b11101110, 0b11100110, 0b01110010, 0b01011111, 0b10110011, 0b10010010, + 0b01001001, 0b11110000, 0b00101001, 0b00101001, 0b01001010, 0b01001001, 0b01001010, 0b00010010, + 0b01001001, 0b00010001, 0b11101001, 0b00101111, 0b01001010, 0b01001001, 0b01111010, 0b00010010, + 0b01001001, 0b00010001, 0b00101001, 0b00101000, 0b01001010, 0b01001001, 0b01000010, 0b00010010, + 0b01001001, 0b00010001, 0b11101001, 0b00100111, 0b01110011, 0b11001001, 0b00111010, 0b00010010, + 0b01001000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00010010, + 0b01001000, 0b00000000, 0b11111000, 0b00011111, 0b00001111, 0b11000000, 0b00000000, 0b00010010, + 0b01001000, 0b00000011, 0b10001100, 0b00110001, 0b00001100, 0b01100000, 0b00000000, 0b00010010, + 0b01001000, 0b00000011, 0b00000110, 0b00110000, 0b00001100, 0b00110000, 0b00000000, 0b00010010, + 0b01001000, 0b00000110, 0b00000011, 0b00110000, 0b00001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001000, 0b00000110, 0b00000011, 0b00110000, 0b00001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001000, 0b00000110, 0b00000011, 0b00011100, 0b00001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001000, 0b00000110, 0b00000011, 0b00000111, 0b00001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001000, 0b00000110, 0b00000011, 0b00000001, 0b10001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001000, 0b00000110, 0b00000011, 0b00000001, 0b10001100, 0b00011000, 0b00000000, 0b00010010, + 0b01001000, 0b00000011, 0b00000110, 0b00000001, 0b10001100, 0b00110000, 0b00000000, 0b00010010, + 0b01001000, 0b00000011, 0b10001100, 0b00100011, 0b00001100, 0b01100000, 0b00000000, 0b00010010, + 0b01001000, 0b00000000, 0b11111000, 0b00111110, 0b00001111, 0b11001110, 0b00000111, 0b00010010, + 0b00100100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00001000, 0b10100100, + 0b00100100, 0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00001000, 0b10100100, + 0b00100100, 0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010001, 0b00001000, 0b10100100, + 0b00100100, 0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00010001, 0b00001000, 0b10100100, + 0b00100100, 0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00010001, 0b00001000, 0b10100100, + 0b00100100, 0b00000000, 0b00000000, 0b00000000, 0b00001010, 0b00010001, 0b00101000, 0b10100100, + 0b00010100, 0b00000000, 0b00000000, 0b00000000, 0b00000100, 0b00001110, 0b00100111, 0b00101000, + 0b00010100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00101000, + 0b00010111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11101000, + 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, + 0b00001111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11110000, + 0b00000000, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b11111111, 0b00000000, +}; +#endif diff --git a/syncgen/main.c b/syncgen/main.c new file mode 100644 index 0000000..efa18e7 --- /dev/null +++ b/syncgen/main.c @@ -0,0 +1,266 @@ +#include +#include +#include +#define ZERO PORTB=0b000 +#define BLACK PORTB=0b001 + +// -----..----- ^ +// | | | +// -| RST VCC |-` +// | | +// .--| X1 PB2 |- +// [ ] | | 470R +// '--| X2 PB1 |--^v^v-. +// | | |----> VidOut +// .--| GND PB0 |--^v^v-' +// | | | 1kR +//----- ------------ +/* +uint8_t testimg_data[] = +{ + 0b11111100, 0b00000000, 0b00000011, 0b10000000, 0b00000000, 0b00000000, + 0b11111100, 0b00000000, 0b00000011, 0b10000000, 0b00000000, 0b00000000, + 0b11111100, 0b00000000, 0b00000011, 0b10000000, 0b00000000, 0b00000000, + 0b11111100, 0b00000000, 0b00000011, 0b10000000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, + 0b11111100, 0b00000000, 0b00000011, 0b11000000, 0b00000000, 0b00000000, + 0b11111100, 0b00000000, 0b00000011, 0b11000000, 0b00000000, 0b00000000, + 0b11111100, 0b00000000, 0b00000011, 0b11000000, 0b00000000, 0b00000000, + 0b11111100, 0b00000000, 0b00000011, 0b11000000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00110000, 0b00000000, 0b00000011, 0b01100000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, + 0b00110010, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00110010, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00110010, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00110010, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00000000, 0b00000000, + 0b00110100, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00110100, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00110100, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00110100, 0b11001101, 0b10011011, 0b01101111, 0b00110000, 0b00000000, + 0b00000000, 0b00000000, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b01101100, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b01101100, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b01101100, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b01101100, + 0b01101100, 0b01101100, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b10010010, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b10010010, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b10010010, + 0b00110000, 0b11101100, 0b11110011, 0b11011001, 0b10110000, 0b10010010, + 0b10010010, 0b10010010, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b10000010, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b10000010, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b10000010, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b10000010, + 0b10000010, 0b10000010, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b01000100, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b01000100, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b01000100, + 0b00110110, 0b11111100, 0b01100011, 0b00011111, 0b10110000, 0b01000100, + 0b01000100, 0b01000100, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00101000, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00101000, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00101000, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00101000, + 0b00101000, 0b00101000, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00010000, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00010000, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00010000, + 0b00110110, 0b11011100, 0b01100011, 0b00011001, 0b10110000, 0b00010000, + 0b00010000, 0b00010000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00000000, 0b00000000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00110110, 0b11001100, 0b01100011, 0b00011001, 0b10111111, 0b00000000, + 0b00000000, 0b00000000, + 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, + 0b00000000, 0b00000000, +}; + +#define testimg_height 15 +#define testimg_width 208 + +#define START1 100 +#define END1 115 +#define START2 412 +#define END2 427 +*/ + +#include "avrosdlogo.h" +volatile int rasterline; +volatile uint16_t line; + +volatile uint8_t hres; +volatile int renderLine; +int stretch; + +void asm_render_line( void ) { + __asm__ __volatile__ ( + ".macro outbit p" "\n\t" + "BST __tmp_reg__,7" "\n\t" // Store bit 7 to T + "BLD r16,1" "\n\t" // Load bit T into r16 bit number 4 + "OUT \\p,r16" "\n\t" // Send contents of r16 to %[port] + "NOP" "\n\t" + ".endm" "\n\t" + + "ADD r26,r28" "\n\t" // Add register Y to register X, low part + "ADC r27,r29" "\n\t" // Add high Y to X with carry from low part + + "IN r16,%[port]" "\n\t" // Save port content to register 16 + "RJMP start_line" "\n\t" + + "loop_byte:" "\n\t" // Notice that in the macro we always use bit 7 and left-shift + "BST __tmp_reg__,6" "\n\t" // Here we use bit 6 without left-shift to output bit 0 + "BLD r16,1" "\n\t" // of each byte (except the last bit on the line) + "OUT %[port],r16" "\n\t" // We do not have time for a left-shift, teh "extra cycle" was used for "dec-branch" + "NOP" "\n\t" + + "start_line:" "\n\t" + "LD __tmp_reg__,X+" "\n\t" // Load from address pointed to by X into temporary register, then increment X-pointer + + "outbit %[port]" "\n\t" // Output bit 7 using Macro + "LSL __tmp_reg__" "\n\t" // Left-shift for next bit + "outbit %[port]" "\n\t" // Output bit 6 using Macro + "LSL __tmp_reg__" "\n\t" // Left-shift for next bit + "outbit %[port]" "\n\t" // Output bit 5 using Macro + "LSL __tmp_reg__" "\n\t" // Left-shift for next bit + "outbit %[port]" "\n\t" // Output bit 4 using Macro + "LSL __tmp_reg__" "\n\t" // Left-shift for next bit + "outbit %[port]" "\n\t" // Output bit 3 using Macro + "LSL __tmp_reg__" "\n\t" // Left-shift for next bit + "outbit %[port]" "\n\t" // Output bit 2 using Macro + "LSL __tmp_reg__" "\n\t" // Left-shift for next bit + "outbit %[port]" "\n\t" // Output bit 1 using Macro + + "DEC %[hres]" "\n\t" // Decrement num-bytes-remaining-in-resolution + "BRNE loop_byte" "\n\t" // Branch to loop6 if %[hres] != zero + + "LSL __tmp_reg__" "\n\t" // Left-shift for last bit on the line + "outbit %[port]" "\n\t" // Output bit 0 using Macro. + + "CBI %[port],1" "\n\t" // Clear our "display bit" to ensure we end on black + + : + : [port] "i" (_SFR_IO_ADDR(PORTB)), + "x" (testimg_data), + "y" (renderLine), + [hres] "d" (hres) + ); +} + +void hsync(void) +{ + line++; + ZERO; _delay_us(4); // sync + BLACK; _delay_us(8); // Back porch +} + +void vsync(uint8_t odd_even) +{ + uint8_t a,b; + cli(); + + // Pre-equalization pulses + b = odd_even ? 6 : 5; + for(a=0; a 312 ) ? line - 312 : line; + + if ( t_line > 118 && t_line < 118 + (2*testimg_height) ) + { + _delay_us(12); + asm_render_line(); + + if( !stretch ) + { + stretch = 1; + renderLine += hres; + if ( renderLine > ((testimg_height*hres)-1) ) renderLine = 0; + } else stretch--; + } + } + return; +} + +int main(void) +{ + rasterline = 0; + line = 0; + + hres = testimg_width / 8; + + DDRB =0b111; + + TCCR0A |= (1<