Untested code

This commit is contained in:
Daniele Verducci (ZenPenguin) 2021-02-22 13:59:55 +01:00
parent 75f5ce057f
commit 2c65665900
3 changed files with 35 additions and 34 deletions

View File

@ -76,7 +76,6 @@ cursor_pos_home:
; Set all positions to 0 ; Set all positions to 0
clr POS_COLUMN clr POS_COLUMN
clr POS_ROWP clr POS_ROWP
clr POS_FINE
; Load framebuffer start position to Y ; Load framebuffer start position to Y
ldi YH, high(FRAMEBUFFER) ldi YH, high(FRAMEBUFFER)
ldi YL, low(FRAMEBUFFER) ldi YL, low(FRAMEBUFFER)
@ -88,16 +87,16 @@ cursor_pos_home:
; ldi POS_ROWP, 13 ; ldi POS_ROWP, 13
; call set_framebuffer_pointer_to_text_cursor ; call set_framebuffer_pointer_to_text_cursor
; @modifies Y, R0, R1 ; @modifies Y, R0, R1
set_framebuffer_pointer_to_text_cursor: ; set_framebuffer_pointer_to_text_cursor:
; Load framebuffer start position to Y ; ; Load framebuffer start position to Y
ldi YH, high(FRAMEBUFFER) ; ldi YH, high(FRAMEBUFFER)
ldi YL, low(FRAMEBUFFER) ; ldi YL, low(FRAMEBUFFER)
; Obtain offset between 0,0 and current cursor position ; ; Obtain offset between 0,0 and current cursor position
mul POS_COLUMN, POS_ROWP ; result is in r1,r0 ; mul POS_COLUMN, POS_ROWP ; result is in r1,r0 ; NOTE: wrong, multiplicate with bytes per row
; Sum offset to Y ; ; Sum offset to Y
add YL, r0 ; add YL, r0
adc YH, r1 ; adc YH, r1
ret ; ret
@ -105,19 +104,25 @@ set_framebuffer_pointer_to_text_cursor:
; Moves cursor to start of following screen line ; 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) ; Takes care of particular cases, i.e. end of screen (shifts all screen up by one line)
draw_carriage_return: draw_carriage_return:
; Set memory pointer to start of line ; Check if end of screen
sub YL, POS_COLUMN cpi POS_ROWP, SCREEN_HEIGHT
sbci YH, 0 brne draw_carriage_return_not_eos
; Set cursor to start of current line call scroll_screen
clr POS_COLUMN dec POS_ROWP ; compensate for next inc
; Go to next line draw_carriage_return_not_eos:
ldi HIGH_ACCUM, high(LINE_COLUMNS*FONT_HEIGHT) ; Move cursor to line start
add YH, HIGH_ACCUM ldi POS_COLUMN, 0
ldi HIGH_ACCUM, low(LINE_COLUMNS*FONT_HEIGHT) ; Move cursor to next line
adc YL, HIGH_ACCUM
; Update row pointer
ldi HIGH_ACCUM, FONT_HEIGHT ldi HIGH_ACCUM, FONT_HEIGHT
add POS_ROWP, HIGH_ACCUM 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 ret
; Scrolls the screen by one line (=LINE_COLUMNS*FONT_HEIGHT bytes) ; Scrolls the screen by one line (=LINE_COLUMNS*FONT_HEIGHT bytes)
@ -126,18 +131,18 @@ draw_carriage_return:
scroll_screen: scroll_screen:
clr POS_COLUMN ; cursor to first column clr POS_COLUMN ; cursor to first column
; "Read" Pointer to first char of second line ; "Read" Pointer to first char of second line
ldi YH, high(FRAMEBUFFER+LINE_COLUMNS*FONT_HEIGHT) ldi YH, high(FRAMEBUFFER+(LINE_COLUMNS*FONT_HEIGHT))
ldi YL, low(FRAMEBUFFER+LINE_COLUMNS*FONT_HEIGHT) ldi YL, low(FRAMEBUFFER+(LINE_COLUMNS*FONT_HEIGHT))
; "Write" Pointer to first char of first line ; "Write" Pointer to first char of first line
ldi XH, high(FRAMEBUFFER) ldi ZH, high(FRAMEBUFFER)
ldi XL, low(FRAMEBUFFER) ldi ZL, low(FRAMEBUFFER)
; Copy data ; Copy data
scroll_screen_copy_loop: scroll_screen_copy_loop:
ld A, Y+ ld A, Y+
st Z+, A 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 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 brne scroll_screen_copy_loop
; All the lines have been "shifted" up by one line. ; All the lines have been "shifted" up by one line.
; The first line is lost and the last is duplicate. Clear the last. ; The first line is lost and the last is duplicate. Clear the last.

View File

@ -11,8 +11,6 @@
; POS_COARSE: Register Y (16-bit, r31 and r30): Coarse position. Points to one of the chunks ; 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 ; (character columns). 46 chunks per row, 304 rows. Used for character position, as
; 1 chunk = 1 byte = 1 character. ; 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 ; Initializes and waits for a byte on PORTB
comm_init: comm_init:

View File

@ -28,10 +28,8 @@
; Cursor Position ; Cursor Position
; POS_COLUMN (0-46) represents the character/chunk column ; 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_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_COLUMN = r21
.def POS_ROWP = r20 .def POS_ROWP = r20
.def POS_FINE = r24
; Internal registers ; Internal registers
.def A = r0 ; accumulator .def A = r0 ; accumulator
.def STATUS = r25 ; signal status (see STATUS TABLE) .def STATUS = r25 ; signal status (see STATUS TABLE)