Avamander / arduino-tvout

Arduino-TVout
325 stars 81 forks source link

Update TVoutPrint.cpp #140

Closed davidadkins1 closed 1 year ago

davidadkins1 commented 1 year ago

TVout::write does not allow the last column to be printed.

if (cursor_x >= (display.hres*8 - pgm_read_byte(font))) {

should be

if (cursor_x > (display.hres*8 - pgm_read_byte(font))) {

Avamander commented 1 year ago

I'm not sure it's correct.

Trying to print characters when cursor_x is equal to horizontal resolution will mean the printed letter will exceed the horizontal resolution (display.hres*8 - pgm_read_byte(font))).

The cursor is at the end of the screen, next letter would end up beyond it, would it not?

davidadkins1 commented 1 year ago

I have verified this in my project. I cannot write the last column because of the >= My testing indicates that cursor_x is the left-most pixel of the character that is to be rendered in X. pgm_read_byte(font) returns the width of the font in pixels.

given: resolution is 128x96 font is 4x6 cursor_x is 0 to 127 the last valid cursor_x for a 4x6 font is 124 124.125.126.127 (the last column)

where:

display.hres = 16 pgm_read_byte(font) = 4 cursor_x = 124

display.hres*8 - pgm_read_byte(font) = 128 - 4 = 124 cursor_x >= 124 so the character is printed on the next line. This is a "bug."

where:

display.hres = 16 pgm_read_byte(font) = 4 cursor_x = 125

display.hres*8 - pgm_read_byte(font) = 128 - 4 = 124 cursor_x > 124 so character is printed on the next line.

where:

display.hres = 16 pgm_read_byte(font) = 4 cursor_x = 128 (actually this is invalid, but since you asked)

display.hres*8 - pgm_read_byte(font) = 128 - 4 = 124 cursor_x > 124 so character is printed on the next line.

TVout::inc_txtline() appears to properly handle scrolling on the bottom line.

davidadkins1 commented 1 year ago

Here is some sample code and two pictures made with and without the write bug. Notice 128 is divisible by the 4-bit wide font. The 6x8 font does not exhibit the problem unless the x resolution is divisible by 6. For example, 126x96 with the 6x8 font has the problem.

include

include

TVout TV;

void setup()
{ TV.begin(NTSC); TV.select_font(font4x6); TV.clear_screen();

for (char i = 32; i < 127; i++) { TV.write(i); } }

void loop() { }

PXL_20221117_203653368

PXL_20221117_203458208

Avamander commented 1 year ago

Thank you for the convincing argumentation and the fix.