Skip to content

Commit

Permalink
Adds COLOR print function.
Browse files Browse the repository at this point in the history
This closes #47.
  • Loading branch information
dmsc committed Jul 12, 2022
1 parent eecbb8b commit 66ba7f1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
25 changes: 24 additions & 1 deletion manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,8 @@ Console Print and Input Statements
**PRINT _expr_, ... / ?**
**PRINT _expr_ TAB(_expr_) ...**
**PRINT _expr_ RTAB(_expr_) ...**
**PRINT _expr_ ; ...**
**PRINT COLOR(_expr_) _expr_ ; ...**
**PRINT _expr_ ; ...**

Outputs strings and numbers to the
screen.
Expand All @@ -1020,6 +1021,22 @@ Console Print and Input Statements
next multiple of 10, allowing easy
printing of tabulated data.

The `COLOR` function alters the color
the text that follows, depending on
the graphics mode. This is abbreviated
`C.`. Use 0 or 128 in graphics 0, for
normal or inverse video. Use 0, 32,
128 or 160 in graphics mode 1 and 2
for the four available text colors,
see the two examples bellow:

' In GRAPHICS 0:
? "NORMAL"; COLOR(128) "INVERSE"

' In GRAPHICS 2:
S = 1234
? #6, "SCORE: "; COLOR(32) S

The `TAB` function advances the
position to a column multiple of the
argument, so that `TAB(10)` is the
Expand Down Expand Up @@ -1078,6 +1095,12 @@ Console Print and Input Statements
using the functions to print to any
device except the screen.

*Advanced:* The `COLOR` function does
an *exclusive or* of the given value
with the value of each character in
the original string before printing.



**Writes A Character To Screen**
**PUT _num_ / PU.**
Expand Down
12 changes: 6 additions & 6 deletions src/editor.bas
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ ENDPROC
'
PROC ShowInfo
' Print two "-", then filename, then complete with '-' until right margin
pos. 0, 0 : ? "";
? FileName$;
repeat : put $12 : until peek(@@RMARGN) = peek(@@COLCRS)
pos. 0, 0 : ? ""$92$92;
? color(128) FileName$;
repeat : put $92 : until peek(@@RMARGN) = peek(@@COLCRS)
' Fill last character
poke @@OLDCHR, $52
poke @@OLDCHR, $D2
' Go to cursor position
pos. scrColumn, scrLine
put 29
Expand Down Expand Up @@ -633,8 +633,8 @@ PROC ChgLine
exec CopyToEdit

' Print status
pos. 32, 0 : ? 1 + topLine + scrLine;
put $12
pos. 32, 0 : ? color(128) 1 + topLine + scrLine;
put $92

' Redraw line
hDraw = 0
Expand Down
2 changes: 1 addition & 1 deletion src/interp/a5200/putchar.asm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
; -----------------------

.export putc, get_text_addr
.importzp tmp3, tmp4
.importzp tmp4
.importzp DINDEX, COLCRS, ROWCRS, SAVMSC

.segment "RUNTIME"
Expand Down
18 changes: 16 additions & 2 deletions src/interp/print_str.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,25 @@
; Print string
; ------------

.import putc
.importzp tmp1, tmp2, next_instruction
.import putc, stack_l
.importzp tmp1, tmp2, tmp3, next_instruction, sptr
.export print_str_tmp1

.segment "RUNTIME"

.proc EXE_PRINT_COLOR_STR ; PRINT string in AX
pha
lda stack_l, y
inc sptr
tay
pla
.byte $2C ; Skip 2 bytes over next "LDY"
.endproc

.proc EXE_PRINT_STR ; PRINT string in AX
ldy #0
print_cont:
sty tmp3
sta tmp1
stx tmp1+1
ptmp: ; Prints string in TMP1
Expand All @@ -43,6 +55,7 @@ ptmp: ; Prints string in TMP1
sta tmp2
loop: iny
lda (tmp1), y
eor tmp3
jsr putc
cpy tmp2
bne loop
Expand All @@ -53,5 +66,6 @@ print_str_tmp1 = EXE_PRINT_STR::ptmp

.include "deftok.inc"
deftoken "PRINT_STR"
deftoken "PRINT_COLOR_STR"

; vi:syntax=asm_ca65
3 changes: 2 additions & 1 deletion src/syntax/basic.syn
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TOKENS {
# Position (used also in graphics)
TOK_POSITION
# Print statements
TOK_PRINT_STR, TOK_PRINT_TAB, TOK_PRINT_RTAB
TOK_PRINT_STR, TOK_PRINT_TAB, TOK_PRINT_RTAB, TOK_PRINT_COLOR_STR
# Simple console input and output
TOK_GETKEY, TOK_INPUT_STR, TOK_PUT, TOK_BYTE_PUT
# Jumps
Expand Down Expand Up @@ -297,6 +297,7 @@ PRINT_SEP_EOL:

# - One item to print, converted to string:
PRINT_ONE_STR:
"Color" T_EXPR emit { TOK_PUSH } PRINT_ONE emit TOK_PRINT_COLOR_STR
PRINT_ONE emit TOK_PRINT_STR
pass

Expand Down

0 comments on commit 66ba7f1

Please sign in to comment.