Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

302 lines (230 sloc) 6.099 kb
;##################################
;# func_lem1802_clear_screen #
;# #
;# Description: #
;# Clears the screen #
;# #
;# Args: #
;# REG A = video ram address #
;# REG B = color #
;##################################
:clear_character
.dat " "
.globl func_lem1802_clear_screen
:func_lem1802_clear_screen
JSR func_pusha
SET C, B
SHL B, 4
ADD B, C
SHL B, 8
ADD B, [clear_character]
SET X, 0
SET Y, A
:clear_screen_loop
SET [Y], B
ADD X, 1
ADD Y, 1
IFL X, 384
SET PC, clear_screen_loop
JSR func_popa
SET PC, POP
;#####################################################
;# func_lem1802_prints #
;# #
;# Description: #
;# Prints a string to the screen #
;# #
;# Args: #
;# REG A = video ram address #
;# REG B = address of null terminated string #
;# REG C = foreground color #
;# REG X = background color or use existing if X>0xF #
;#####################################################
:crs_x
.dat 0
:crs_y
.dat 0
:prints_str_address
.dat 0
.globl func_lem1802_prints
:func_lem1802_prints
JSR func_pusha
SET Y, 0
SET [prints_str_address], B
:prints_loop
SET Z, [prints_str_address]
ADD Z, Y
; Increase the character index
ADD Y, 1
; Check for end of string
IFE [Z], 0
SET PC, prints_done
; Check for newline character
IFE [Z], 0xA
SET PC, prints_newline
; Decide background color
SET J, X
IFL X, 0x10
SET PC, prints_use_x_backcolor
SET B, [crs_y]
MUL B, 32
ADD B, [crs_x]
ADD B, A
SET J, [B]
SHR J, 8
AND J, 0xF
:prints_use_x_backcolor
; Print character
SET I, C
SHL I, 4
ADD I, J
SHL I, 8
SET J, [Z]
AND J, 0xFF
ADD I, [Z]
SET [B], I
; Move the cursor
ADD [crs_x], 1
IFL [crs_x], 32
SET PC, prints_loop
SET [crs_x], 0
ADD [crs_y], 1
IFL [crs_y], 12
SET PC, prints_loop
SUB [crs_y], 1
SET PUSH, Z
SET Z, X
JSR func_lem1802_scroll
SET Z, POP
SET PC, prints_loop
:prints_newline
SET PUSH, Z
SET Z, X
JSR func_lem1802_printnl
SET Z, POP
SET PC, prints_loop
:prints_done
JSR func_popa
SET PC, POP
;#####################################################
;# func_lem1802_printnl #
;# #
;# Description: #
;# Moves the cursor to the next line #
;# #
;# Args: #
;# REG A = video ram address #
;# REG Z = background color (used if scrolling) #
;#####################################################
.globl func_lem1802_printnl
:func_lem1802_printnl
JSR func_pusha
SET [crs_x], 0
ADD [crs_y], 1
IFL [crs_y], 12
SET PC, println_done
SUB [crs_y], 1
JSR func_lem1802_scroll
:println_done
JSR func_popa
SET PC, POP
;###########################################################
;# func_lem1802_scroll #
;# #
;# Description: #
;# Scrolls the "console" #
;# #
;# Args: #
;# REG A = video ram address #
;# REG Z = background color (used when clearing last line) #
;###########################################################
.globl func_lem1802_scroll
:func_lem1802_scroll
JSR func_pusha
SET B, 0
SET C, 0
:scroll_next_y
:scroll_next_x
SET X, C
MUL X, 32
ADD X, B
ADD X, A
SET Y, X
ADD Y, 32
SET [X], [Y]
ADD B, 1
IFL B, 32
SET PC, scroll_next_x
SET B, 0
ADD C, 1
IFL C, 11
SET PC, scroll_next_y
; Clear the last line
SET B, 0
SET I, Z
SHL I, 8
:scroll_clear_last_line
SET X, 11
MUL X, 32
ADD X, B
ADD X, A
IFL Z, 0x10
SET PC, scroll_no_reuse_col
SET I, [X]
SHR I, 8
AND I, 0xF
SHL I, 8
:scroll_no_reuse_col
SET [X], [clear_character]
ADD [X], I
ADD B, 1
IFL B, 32
SET PC, scroll_clear_last_line
JSR func_popa
SET PC, POP
;#####################################################
;# func_lem1802_printi #
;# #
;# Description: #
;# Prints an integer to the screen #
;# #
;# Args: #
;# REG A = video ram address #
;# REG B = integer #
;# REG C = foreground color #
;# REG X = background color or use existing if X>0xF #
;#####################################################
:numbers_ascii_start
.dat "0"
.comm integer_string, 6
.globl func_lem1802_printi
:func_lem1802_printi
JSR func_pusha
SET Y, B
SET Z, Y
MOD Z, 10000
DIV Y, 10000
SET [integer_string + 0], Y
ADD [integer_string + 0], [numbers_ascii_start]
SET Y, Z
MOD Z, 1000
DIV Y, 1000
SET [integer_string + 1], Y
ADD [integer_string + 1], [numbers_ascii_start]
SET Y, Z
MOD Z, 100
DIV Y, 100
SET [integer_string + 2], Y
ADD [integer_string + 2], [numbers_ascii_start]
SET Y, Z
MOD Z, 10
DIV Y, 10
SET [integer_string + 3], Y
ADD [integer_string + 3], [numbers_ascii_start]
SET Y, Z
SET [integer_string + 4], Y
ADD [integer_string + 4], [numbers_ascii_start]
SET B, integer_string
JSR func_lem1802_prints
JSR func_popa
SET PC, POP
Jump to Line
Something went wrong with that request. Please try again.