--- /dev/null
+# 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 <jon.langseth AT lilug.no>
+# This modified template is placed in the public domain like the original.
+#
+
+
+# Target name and MCU setup -------------------------------------------------
+
+TARGET = fbosd
+
+MCU = atmega328p
+
+# 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
+
+# Default settings:
+#F_CPU = 1000000
+# Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
+#FUSE_LOW = 0x62
+#FUSE_HIGH = 0xD9
+#FUSE_EXT = 0x7
+
+# Fancy 20MHz settings:
+F_CPU = 20000000
+## Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
+FUSE_LOW = 0xEF
+FUSE_HIGH = 0xD9
+FUSE_EXT = 0x7
+
+# Source files to compile ---------------------------------------------------
+
+# List C source files here. (C dependencies are automatically generated.)
+SRC = $(TARGET).c render.c draw.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 <http://savannah.nongnu.org/projects/avrdude>
+# 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
+
--- /dev/null
+#include "draw.h"
+#include <stdlib.h>
+
+extern uint8_t* screen_buffer;
+extern uint8_t hres_bytes;
+
+void sp(uint8_t x, uint8_t y, uint8_t color)
+{
+ if (color==0) screen_buffer[(x/8) + (y*hres_bytes)] &= ~0x80 >> (x&7);
+ else if (color==1) screen_buffer[(x/8) + (y*hres_bytes)] |= 0x80 >> (x&7);
+ else screen_buffer[(x/8) + (y*hres_bytes)] ^= 0x80 >> (x&7);
+}
+
+void set_pixel(uint8_t x, uint8_t y, uint8_t color)
+{
+ if (x >= hres_bytes*8 || y >= VRES)
+ return;
+ sp(x,y,color);
+}
+
+void fill(uint8_t color)
+{
+ switch(color) {
+ case c_BLACK:
+ for (int i = 0; i < (hres_bytes*VRES); i++)
+ screen_buffer[i] = 0;
+ break;
+ case c_WHITE:
+ for (int i = 0; i < (hres_bytes*VRES); i++)
+ screen_buffer[i] = 0xFF;
+ break;
+ case c_INVERT:
+ for (int i = 0; i < (hres_bytes*VRES); i++)
+ screen_buffer[i] = ~screen_buffer[i];
+ break;
+ }
+}
+
+
+/*
+Bresenham's line algorithm, optimized and simplified.
+ function line(x0, y0, x1, y1)
+ dx := abs(x1-x0)
+ dy := abs(y1-y0)
+ if x0 < x1 then sx := 1 else sx := -1
+ if y0 < y1 then sy := 1 else sy := -1
+ err := dx-dy
+
+ loop
+ setPixel(x0,y0)
+ if x0 = x1 and y0 = y1 exit loop
+ e2 := 2*err
+ if e2 > -dy then
+ err := err - dy
+ x0 := x0 + sx
+ end if
+ if e2 < dx then
+ err := err + dx
+ y0 := y0 + sy
+ end if
+ end loop
+*/
+void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t c)
+{
+
+ if (x0 > hres_bytes*8 || y0 > VRES || x1 > hres_bytes*8 || y1 > VRES)
+ return;
+
+ int dx, dy, sx, sy, err, p;
+
+ dx = abs( x1-x0 );
+ dy = abs( y1-y0 );
+ if ( x0 < x1 ) sx = 1; else sx = -1;
+ if ( y0 < y1 ) sy = 1; else sy = -1;
+ err = dx - dy;
+
+ while (1)
+ {
+ sp(x0, y0, c);
+ if ( ( x0 == x1 ) && ( y0 == y1 ) ) return;
+ p = 2 * err;
+ if ( p > -dy )
+ {
+ err = err - dy;
+ x0 = x0 + sx;
+ }
+ if ( p < dx )
+ {
+ err = err + dx;
+ y0 = y0 + sy;
+ }
+ }
+}
+// draw_row and draw_col ...
+// These whould really be used for optimization.
+// As is, they exist for conveniance, not speed :P
+void draw_col(uint8_t x, uint8_t y0, uint8_t y1, uint8_t c)
+{
+ draw_line( x, y0, x, y1, c );
+}
+void draw_row(uint8_t y, uint8_t x0, uint8_t x1, uint8_t c)
+{
+ draw_line( x0, y, x1, y, c );
+}
+
+
+void _draw_rect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, int8_t c, int8_t fc )
+{
+ if ( fc != -1 )
+ for (unsigned char i = 0; i < h; i++)
+ draw_line(x0,y0+i,x0+w,y0+i,c);
+
+ draw_line(x0,y0,x0+w,y0,c);
+ draw_line(x0,y0,x0,y0+h,c);
+ draw_line(x0+w,y0,x0+w,y0+h,c);
+ draw_line(x0,y0+h,x0+w,y0+h,c);
+}
+
+void _draw_circle(uint8_t x0, uint8_t y0, uint8_t radius, int8_t c, int8_t fc) {
+
+ int f = 1 - radius;
+ int ddF_x = 1;
+ int ddF_y = -2 * radius;
+ int x = 0;
+ int y = radius;
+ uint8_t pyy = y,pyx = x;
+
+ //there is a fill color
+ if (fc != -1)
+ draw_row(y0,x0-radius,x0+radius,fc);
+
+ sp(x0, y0 + radius,c);
+ sp(x0, y0 - radius,c);
+ sp(x0 + radius, y0,c);
+ sp(x0 - radius, y0,c);
+
+ while(x < y) {
+ if(f >= 0) {
+ y--;
+ ddF_y += 2;
+ f += ddF_y;
+ }
+ x++;
+ ddF_x += 2;
+ f += ddF_x;
+ //there is a fill color
+ if (fc > -1) {
+ //prevent double draws on the same rows
+ if (pyy != y) {
+ draw_row(y0+y,x0-x,x0+x,fc);
+ draw_row(y0-y,x0-x,x0+x,fc);
+ }
+ if (pyx != x && x != y) {
+ draw_row(y0+x,x0-y,x0+y,fc);
+ draw_row(y0-x,x0-y,x0+y,fc);
+ }
+ pyy = y;
+ pyx = x;
+ }
+
+ sp(x0 + x, y0 + y,c);
+ sp(x0 - x, y0 + y,c);
+ sp(x0 + x, y0 - y,c);
+ sp(x0 - x, y0 - y,c);
+ sp(x0 + y, y0 + x,c);
+ sp(x0 - y, y0 + x,c);
+ sp(x0 + y, y0 - x,c);
+ sp(x0 - y, y0 - x,c);
+ }
+}
+
+void draw_rect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t c)
+{
+ _draw_rect(x0, y0, w, h, c, -1);
+}
+
+void fill_rect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t c)
+{
+ _draw_rect(x0, y0, w, h, c, c);
+}
+
+void draw_circle(uint8_t x0, uint8_t y0, uint8_t radius, char c)
+{
+ _draw_circle(x0, y0, radius, c, -1);
+}
+
+void fill_circle(uint8_t x0, uint8_t y0, uint8_t radius, char c)
+{
+ _draw_circle(x0, y0, radius, c, c);
+}
+
+
--- /dev/null
+#ifndef DRAW_H
+#define DRAW_H
+
+#include <stdint.h>
+#include "video_properties.h"
+
+#define c_BLACK 0
+#define c_WHITE 1
+#define c_INVERT 2
+#define c_NONE -1
+
+
+void sp(uint8_t x, uint8_t y, uint8_t color);
+
+void set_pixel(uint8_t x, uint8_t y, uint8_t color);
+// TODO: may need unsigned char get_pixel(uint8_t x, uint8_t y);
+
+void fill(uint8_t color);
+// TODO: may need void shift(uint8_t distance, uint8_t direction);
+
+void draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t c);
+void draw_row(uint8_t x, uint8_t y0, uint8_t y1, uint8_t c);
+void draw_col(uint8_t y, uint8_t x0, uint8_t x1, uint8_t c);
+
+void _draw_rect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, int8_t c, int8_t fc);
+void _draw_circle(uint8_t x0, uint8_t y0, uint8_t radius, int8_t c, int8_t fc);
+
+void draw_rect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t c);
+void fill_rect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t c);
+void draw_circle(uint8_t x0, uint8_t y0, uint8_t radius, char c);
+void fill_circle(uint8_t x0, uint8_t y0, uint8_t radius, char c);
+
+// TODO: WILL need void draw_bitmap(uint8_t x, uint8_t y, const unsigned char * bmp, uint16_t i = 0, uint8_t width = 0, uint8_t lines = 0);
+// TODO draw_bitmap() will be useful for printing text, as printing text
+// TODO is drawing font elements, and font elements are ... bitmaps.
+
+#endif
--- /dev/null
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <stdlib.h>
+
+#include "video_properties.h"
+#include "render.h"
+#include "draw.h"
+
+void (*line_handler)( void );
+
+const int vres_scale = ( SCREEN_LINES / VRES -1 );
+const int hres_bytes = HRES / 8;
+
+volatile uint8_t* screen_buffer;
+
+volatile int line;
+volatile int buffer_position;
+
+void Delay_ms(int cnt)
+{
+ while(cnt-->0) _delay_ms(1);
+}
+
+void active_lines ( void )
+{
+ static uint8_t rept;
+
+ _delay_us(4);
+
+ asm_render_line();
+
+ if( !rept )
+ {
+ if ( buffer_position < ((VRES*hres_bytes)) )
+ buffer_position += hres_bytes;
+ rept = vres_scale;
+ }
+ else
+ rept--;
+
+}
+
+void blank_lines ( void )
+{
+ if ( line < FIRST_LINE )
+ {
+ PORTB ^= 0x001;
+ return;
+ }
+ line_handler = active_lines;
+}
+
+ISR (INT1_vect)
+{
+ line_handler();
+ line++;
+ if( line > LAST_LINE)
+ {
+ line = 0;
+ buffer_position = 0;
+ line_handler = &blank_lines;
+ EIMSK &= ~(uint8_t)(1<<INT1);
+ }
+}
+
+ISR (INT0_vect)
+{
+ // VSync is getting close to done.
+ // Set line-handler to blank-handler to count-up the undesired lines,
+ // and enable HSync interrupts.
+
+ line_handler = &blank_lines;
+
+ EIMSK |= (1<<INT1);
+
+}
+
+//Main Function
+int main(void)
+{
+
+ // Using some pins on PORTB for debug-indicator-LEDs
+ DDRB = (1<< PB0)|(1 << PB1)|(1 << PB2);
+ PORTB = 0x0;
+
+ // Using pin 7 on PD to clock out pixels \o/
+ DDRD = (1<<PD7);
+ PORTD = 0x0;
+
+ /* LM1881 pins are connected to:
+ INT0 / PCINT18 / PD2 <- VSYNC
+ INT1 / PCINT19 / PD3 <- CSYNC
+ PCINT20 / PD4 <- ODD/EVEN
+ */
+ EICRA |= (1<<ISC01)|(1<<ISC00); // Select Rising-edge interrupt for VSync
+ EICRA |= (1<<ISC11)|(1<<ISC10); // Select Rising-edge interrupt for HSync
+ EIMSK |= (1<<INT0); // Enable VSync-interrupts
+
+ // And enable interrupts globally.
+ sei();
+
+ // Allocate the framebuffer :D
+ screen_buffer = (uint8_t*) malloc( hres_bytes * VRES * sizeof(uint8_t) );
+ // And make sure it's cleared
+ fill(c_BLACK);
+
+ // Do some static drawing :P
+ set_pixel(28, 8, 1);
+ set_pixel(92, 82, 1);
+
+ set_pixel(92, 8, 1);
+ set_pixel(28, 82, 1);
+
+
+ draw_line(0, 0, 128, 92, 1);
+ draw_line(128, 0, 0, 92, 1);
+
+ draw_rect( 0, 1, 127, 91, 1);
+
+ draw_rect( 34, 21, 60, 50, 1);
+ _draw_rect( 24, 11, 80, 70, 1, -1);
+ draw_rect( 34, 21, 60, 50, 1);
+
+
+ _draw_circle( 64,46, 35, 1, -1 );
+ draw_circle( 64,46, 30, 1 );
+ fill_circle( 64,46, 25, 1 );
+ fill_circle( 64,46, 20, 0 );
+ fill_rect( 44, 31, 40, 30, 1);
+ fill_rect( 54, 41, 20, 10, 0);
+
+ for (;;)
+ PORTB ^= 0x002;
+
+ for ( int j = 8; j < 89; j++ )
+ {
+ draw_line(8,88-j,120,j, 2);
+ draw_line(120,j,8,88-j, 2);
+ Delay_ms(5);
+ draw_line(8,88-j,120,j, 2);
+ Delay_ms(5);
+ }
+ Delay_ms(150);
+ }
+}
+
+
+
--- /dev/null
+#include "render.h"
+#include <avr/io.h>
+
+
+extern volatile int buffer_position;
+extern volatile uint8_t hres_bytes;
+extern volatile char* screen_buffer;
+
+
+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,7" "\n\t" // Load bit T into r16 bit number 7
+ "OUT \\p,r16" "\n\t" // Send contents of r16 to %[port]
+ "NOP" "\n\t" // Delay ...
+ "NOP" "\n\t" // Delay ...
+ "NOP" "\n\t" // Delay ...
+ ".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,7" "\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" // Delay ...
+ "NOP" "\n\t" // Delay ...
+
+ "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 %[hr]" "\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],7" "\n\t" // Clear our "display bit" to ensure we end on black
+
+ :
+ : [port] "i" (_SFR_IO_ADDR(PORTD)),
+ "x" (screen_buffer),
+ "y" (buffer_position),
+ [hr] "d" (hres_bytes)
+ : "r16"
+ );
+}
--- /dev/null
+#ifndef RENDER_H
+#define RENDER_H
+
+void asm_render_line( void );
+
+#endif
--- /dev/null
+#ifndef V_PROPS_H
+#define V_PROPS_H
+
+#define HRES 128
+#define VRES 92
+
+#define FIRST_LINE 25
+#define LAST_LINE 301
+
+#define SCREEN_LINES ( LAST_LINE - FIRST_LINE )
+
+#endif