diff --git a/pat80-io-devices/composite-pal-adapter/software/avr-assembly/character_generator.asm b/pat80-io-devices/composite-pal-adapter/software/avr-assembly/character_generator.asm index d8cfb1b..dbde929 100644 --- a/pat80-io-devices/composite-pal-adapter/software/avr-assembly/character_generator.asm +++ b/pat80-io-devices/composite-pal-adapter/software/avr-assembly/character_generator.asm @@ -76,7 +76,6 @@ cursor_pos_home: ; Set all positions to 0 clr POS_COLUMN clr POS_ROWP - clr POS_FINE ; Load framebuffer start position to Y ldi YH, high(FRAMEBUFFER) ldi YL, low(FRAMEBUFFER) @@ -88,16 +87,16 @@ cursor_pos_home: ; ldi POS_ROWP, 13 ; call set_framebuffer_pointer_to_text_cursor ; @modifies Y, R0, R1 -set_framebuffer_pointer_to_text_cursor: - ; Load framebuffer start position to Y - ldi YH, high(FRAMEBUFFER) - ldi YL, low(FRAMEBUFFER) - ; Obtain offset between 0,0 and current cursor position - mul POS_COLUMN, POS_ROWP ; result is in r1,r0 - ; Sum offset to Y - add YL, r0 - adc YH, r1 - ret +; set_framebuffer_pointer_to_text_cursor: +; ; Load framebuffer start position to Y +; ldi YH, high(FRAMEBUFFER) +; ldi YL, low(FRAMEBUFFER) +; ; Obtain offset between 0,0 and current cursor position +; mul POS_COLUMN, POS_ROWP ; result is in r1,r0 ; NOTE: wrong, multiplicate with bytes per row +; ; Sum offset to Y +; add YL, r0 +; adc YH, r1 +; ret @@ -105,19 +104,25 @@ set_framebuffer_pointer_to_text_cursor: ; Moves cursor to start of following screen line ; Takes care of particular cases, i.e. end of screen (shifts all screen up by one line) draw_carriage_return: - ; Set memory pointer to start of line - sub YL, POS_COLUMN - sbci YH, 0 - ; Set cursor to start of current line - clr POS_COLUMN - ; Go to next line - ldi HIGH_ACCUM, high(LINE_COLUMNS*FONT_HEIGHT) - add YH, HIGH_ACCUM - ldi HIGH_ACCUM, low(LINE_COLUMNS*FONT_HEIGHT) - adc YL, HIGH_ACCUM - ; Update row pointer - ldi HIGH_ACCUM, FONT_HEIGHT - add POS_ROWP, HIGH_ACCUM + ; Check if end of screen + cpi POS_ROWP, SCREEN_HEIGHT + brne draw_carriage_return_not_eos + call scroll_screen + dec POS_ROWP ; compensate for next inc + draw_carriage_return_not_eos: + ; Move cursor to line start + ldi POS_COLUMN, 0 + ; Move cursor to next line + ldi HIGH_ACCUM, FONT_HEIGHT + add POS_ROWP, HIGH_ACCUM + ; Compute memory pointer offset + mul POS_COLUMN, POS_ROWP ; result overwrites r0 and r1! + ; Set pointer to start of framebuffer + ldi ZL, low(FRAMEBUFFER) + ldi ZH, high(FRAMEBUFFER) + ; Add offset to pointer + add ZL, r0 + adc ZH, r1 ret ; Scrolls the screen by one line (=LINE_COLUMNS*FONT_HEIGHT bytes) @@ -126,18 +131,18 @@ draw_carriage_return: scroll_screen: clr POS_COLUMN ; cursor to first column ; "Read" Pointer to first char of second line - ldi YH, high(FRAMEBUFFER+LINE_COLUMNS*FONT_HEIGHT) - ldi YL, low(FRAMEBUFFER+LINE_COLUMNS*FONT_HEIGHT) + ldi YH, high(FRAMEBUFFER+(LINE_COLUMNS*FONT_HEIGHT)) + ldi YL, low(FRAMEBUFFER+(LINE_COLUMNS*FONT_HEIGHT)) ; "Write" Pointer to first char of first line - ldi XH, high(FRAMEBUFFER) - ldi XL, low(FRAMEBUFFER) + ldi ZH, high(FRAMEBUFFER) + ldi ZL, low(FRAMEBUFFER) ; Copy data scroll_screen_copy_loop: ld A, Y+ st Z+, A - cpi r31, high(FRAMEBUFFER_END-LINE_COLUMNS*FONT_HEIGHT) + cpi ZH, high(FRAMEBUFFER_END-(LINE_COLUMNS*FONT_HEIGHT)) brne scroll_screen_copy_loop - cpi r30, low(FRAMEBUFFER_END-LINE_COLUMNS*FONT_HEIGHT) + cpi ZL, low(FRAMEBUFFER_END-(LINE_COLUMNS*FONT_HEIGHT)) brne scroll_screen_copy_loop ; All the lines have been "shifted" up by one line. ; The first line is lost and the last is duplicate. Clear the last. diff --git a/pat80-io-devices/composite-pal-adapter/software/avr-assembly/communication.asm b/pat80-io-devices/composite-pal-adapter/software/avr-assembly/communication.asm index 53fa137..27b55bc 100644 --- a/pat80-io-devices/composite-pal-adapter/software/avr-assembly/communication.asm +++ b/pat80-io-devices/composite-pal-adapter/software/avr-assembly/communication.asm @@ -11,8 +11,6 @@ ; POS_COARSE: Register Y (16-bit, r31 and r30): Coarse position. Points to one of the chunks ; (character columns). 46 chunks per row, 304 rows. Used for character position, as ; 1 chunk = 1 byte = 1 character. -; POS_FINE: Register r24: Fine position. Represents the bit inside the chunk selected by POS_COARSE. -; Ignored in character mode (the character is always aligned to column). Used in graphic mode. ; Initializes and waits for a byte on PORTB comm_init: diff --git a/pat80-io-devices/composite-pal-adapter/software/avr-assembly/main.asm b/pat80-io-devices/composite-pal-adapter/software/avr-assembly/main.asm index 24dc6e3..3eaf47d 100644 --- a/pat80-io-devices/composite-pal-adapter/software/avr-assembly/main.asm +++ b/pat80-io-devices/composite-pal-adapter/software/avr-assembly/main.asm @@ -28,10 +28,8 @@ ; Cursor Position ; POS_COLUMN (0-46) represents the character/chunk column ; POS_ROWP (0-255) represent the chunk row. The caracter row is POS_ROWP/FONT_HEIGHT -; POS_FINE represents fine position (bit inside coarse-position-pointed chunk) in graphic mode. .def POS_COLUMN = r21 .def POS_ROWP = r20 -.def POS_FINE = r24 ; Internal registers .def A = r0 ; accumulator .def STATUS = r25 ; signal status (see STATUS TABLE)