From 279823d854d79c96dde2e23a28c73b59cc9490eb Mon Sep 17 00:00:00 2001 From: Dirk Petrautzki Date: Sun, 25 Apr 2021 18:00:36 +0200 Subject: [PATCH 1/3] Remove unused r17 and r21 --- VGAX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VGAX.cpp b/VGAX.cpp index 2574378..5553635 100644 --- a/VGAX.cpp +++ b/VGAX.cpp @@ -178,7 +178,7 @@ ISR(TIMER2_OVF_vect) { : [port] "I" (_SFR_IO_ADDR(PORTD)), #endif "z" "I" (/*rline*/(byte*)vgaxfb + rlinecnt*VGAX_BWIDTH) - : "r16", "r17", "r20", "r21", "memory"); + : "r16", "r20", "memory"); //increment framebuffer line counter after 6 VGA lines #if defined(__AVR_ATmega2560__) && defined(ATMEGA2560_MAXRES) From 5f1c0712156d81418c7e5ecaa7d912f62e4cfc46 Mon Sep 17 00:00:00 2001 From: Dirk Petrautzki Date: Sat, 24 Apr 2021 13:42:04 +0200 Subject: [PATCH 2/3] Shorten dejitter code --- VGAX.cpp | 56 +++++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/VGAX.cpp b/VGAX.cpp index 5553635..dee4fe6 100644 --- a/VGAX.cpp +++ b/VGAX.cpp @@ -100,41 +100,27 @@ ISR(TIMER2_OVF_vect) { //interrupt jitter fix (needed to keep signal stable) //code from https://github.com/cnlohr/avrcraft/tree/master/terminal //modified from 4 nop align to 8 nop align - #define DEJITTER_OFFSET 1 - #define DEJITTER_SYNC -2 - asm volatile( - " lds r16, %[timer0] \n\t" // - #if defined(__AVR_ATmega2560__) - " add r16, %[toffset] \n\t" // - #endif - " subi r16, %[tsync] \n\t" // - " andi r16, 7 \n\t" // - " call TL \n\t" // - "TL: \n\t" // - #if defined(__AVR_ATmega2560__) - " pop r17 \n\t" //ATMEGA2560 has a 22bit PC! - #endif - " pop r31 \n\t" // - " pop r30 \n\t" // - " adiw r30, (LW-TL-5) \n\t" // - " add r30, r16 \n\t" // - //" adc r31, __zero_reg__ \n\t" // - " ijmp \n\t" // - "LW: \n\t" // - " nop \n\t" // - " nop \n\t" // - " nop \n\t" // - " nop \n\t" // - " nop \n\t" // - " nop \n\t" // - " nop \n\t" // - //" nop \n\t" // - "LBEND: \n\t" // - : - : [timer0] "i" (&TCNT0), - [toffset] "i" ((uint8_t)DEJITTER_OFFSET), - [tsync] "i" ((uint8_t)DEJITTER_SYNC) - : "r30", "r31", "r16", "r17"); + #define DEJITTER_SYNC 9 + { + uint8_t jitter; + asm volatile( + " lds %[jitter], %[timer0] \n\t" // + " subi %[jitter], %[tsync] \n\t" // + " andi %[jitter], 7 \n\t" // + " ldi ZL, pm_lo8(NOP_SLIDE) \n\t" // + " ldi ZH, pm_hi8(NOP_SLIDE) \n\t" // + " add ZL, %[jitter] \n\t" // + " adc ZH, __zero_reg__ \n\t" // + " ijmp \n\t" // + "NOP_SLIDE: \n\t" // + ".rept 7 \n\t" // + " nop \n\t" // + ".endr \n\t" // + : [jitter] "=d" (jitter) + : [timer0] "i" (&TCNT0), + [tsync] "i" ((uint8_t)DEJITTER_SYNC) + : "r30", "r31"); + } /* Output all pixels. From 1e01545fa6f8c031ce5f58dcb1036bbcf21fa106 Mon Sep 17 00:00:00 2001 From: Dirk Petrautzki Date: Sun, 25 Apr 2021 19:02:26 +0200 Subject: [PATCH 3/3] Fix #22 --- VGAXUtils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/VGAXUtils.h b/VGAXUtils.h index 14157e5..62dd81f 100644 --- a/VGAXUtils.h +++ b/VGAXUtils.h @@ -130,6 +130,8 @@ class VGAXUtils { //porting of TVOut::draw_rect method, writen by Myles Metzer static inline void draw_rect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t c, char fc) { + --w; + --h; if (fc != -1) { for (unsigned char i=y0; i < y0+h; i++) { VGAXUtils::draw_row(i, x0, x0+w, fc); @@ -288,6 +290,8 @@ class VGAXUtils { //Safe version with screen clipping static inline void draw_rect_safe(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t c, char fc) { + --w; + --h; if (fc != -1) { for (unsigned char i=y0; i < y0+h; i++) { VGAXUtils::draw_row_safe(i, x0, x0+w, fc);