Skip to content

Commit 0bd4e67

Browse files
authored
feat: tab() modifier for print/input (#122)
1 parent 71916bc commit 0bd4e67

8 files changed

Lines changed: 284 additions & 233 deletions

File tree

modules/tokeniser/__kwdtext.asm

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -50,62 +50,63 @@ KeywordSet0:
5050
.text 4,$10,"SGN(" ; $ac SGN(
5151
.text 4,$0e,"SPC(" ; $ad SPC(
5252
.text 5,$45,"STR$(" ; $ae STR$(
53-
.text 5,$56,"TILE(" ; $af TILE(
54-
.text 6,$a9,"TIMER(" ; $b0 TIMER(
55-
.text 4,$40,"TRUE" ; $b1 TRUE
56-
.text 4,$0b,"VAL(" ; $b2 VAL(
57-
.text 4,$05,"FRE(" ; $b3 FRE(
58-
.text 2,$94,"FN" ; $b4 FN
59-
.text 3,$e7,"FOR" ; $b5 FOR
60-
.text 2,$8f,"IF" ; $b6 IF
61-
.text 4,$34,"PROC" ; $b7 PROC
62-
.text 6,$c1,"REPEAT" ; $b8 REPEAT
63-
.text 5,$79,"WHILE" ; $b9 WHILE
64-
.text 5,$6b,"ENDFN" ; $ba ENDFN
65-
.text 5,$66,"ENDIF" ; $bb ENDIF
66-
.text 7,$0b,"ENDPROC" ; $bc ENDPROC
67-
.text 4,$3f,"NEXT" ; $bd NEXT
68-
.text 4,$2f,"THEN" ; $be THEN
69-
.text 5,$8c,"UNTIL" ; $bf UNTIL
70-
.text 4,$2e,"WEND" ; $c0 WEND
71-
.text 2,$95,"AT" ; $c1 AT
72-
.text 2,$9b,"BY" ; $c2 BY
73-
.text 4,$1c,"CALL" ; $c3 CALL
74-
.text 6,$b2,"CIRCLE" ; $c4 CIRCLE
75-
.text 5,$67,"CLEAR" ; $c5 CLEAR
76-
.text 5,$7f,"COLOR" ; $c6 COLOR
77-
.text 6,$d4,"COLOUR" ; $c7 COLOUR
78-
.text 4,$1a,"DATA" ; $c8 DATA
79-
.text 3,$da,"DIM" ; $c9 DIM
80-
.text 6,$db,"DOWNTO" ; $ca DOWNTO
81-
.text 4,$29,"ELSE" ; $cb ELSE
82-
.text 4,$34,"FROM" ; $cc FROM
83-
.text 3,$e5,"GFX" ; $cd GFX
84-
.text 4,$24,"HERE" ; $ce HERE
85-
.text 5,$63,"IMAGE" ; $cf IMAGE
86-
.text 3,$e5,"LET" ; $d0 LET
87-
.text 4,$28,"LINE" ; $d1 LINE
88-
.text 5,$6b,"LOCAL" ; $d2 LOCAL
89-
.text 7,$1a,"MEMCOPY" ; $d3 MEMCOPY
90-
.text 4,$21,"NAME" ; $d4 NAME
91-
.text 3,$db,"OFF" ; $d5 OFF
92-
.text 2,$9d,"ON" ; $d6 ON
93-
.text 7,$20,"OUTLINE" ; $d7 OUTLINE
94-
.text 7,$0f,"PALETTE" ; $d8 PALETTE
95-
.text 4,$3f,"PLOT" ; $d9 PLOT
96-
.text 4,$2f,"POKE" ; $da POKE
97-
.text 5,$73,"POKED" ; $db POKED
98-
.text 5,$7b,"POKEL" ; $dc POKEL
99-
.text 5,$86,"POKEW" ; $dd POKEW
100-
.text 4,$1c,"READ" ; $de READ
101-
.text 4,$2e,"RECT" ; $df RECT
102-
.text 3,$e4,"REM" ; $e0 REM
103-
.text 5,$7b,"SOLID" ; $e1 SOLID
104-
.text 5,$89,"SOUND" ; $e2 SOUND
105-
.text 6,$d7,"SPRITE" ; $e3 SPRITE
106-
.text 4,$45,"TEXT" ; $e4 TEXT
107-
.text 2,$a3,"TO" ; $e5 TO
108-
.text 4,$3c,"STEP" ; $e6 STEP
53+
.text 4,$ff,"TAB(" ; $af TAB(
54+
.text 5,$56,"TILE(" ; $b0 TILE(
55+
.text 6,$a9,"TIMER(" ; $b1 TIMER(
56+
.text 4,$40,"TRUE" ; $b2 TRUE
57+
.text 4,$0b,"VAL(" ; $b3 VAL(
58+
.text 4,$05,"FRE(" ; $b4 FRE(
59+
.text 2,$94,"FN" ; $b5 FN
60+
.text 3,$e7,"FOR" ; $b6 FOR
61+
.text 2,$8f,"IF" ; $b7 IF
62+
.text 4,$34,"PROC" ; $b8 PROC
63+
.text 6,$c1,"REPEAT" ; $b9 REPEAT
64+
.text 5,$79,"WHILE" ; $ba WHILE
65+
.text 5,$6b,"ENDFN" ; $bb ENDFN
66+
.text 5,$66,"ENDIF" ; $bc ENDIF
67+
.text 7,$0b,"ENDPROC" ; $bd ENDPROC
68+
.text 4,$3f,"NEXT" ; $be NEXT
69+
.text 4,$2f,"THEN" ; $bf THEN
70+
.text 5,$8c,"UNTIL" ; $c0 UNTIL
71+
.text 4,$2e,"WEND" ; $c1 WEND
72+
.text 2,$95,"AT" ; $c2 AT
73+
.text 2,$9b,"BY" ; $c3 BY
74+
.text 4,$1c,"CALL" ; $c4 CALL
75+
.text 6,$b2,"CIRCLE" ; $c5 CIRCLE
76+
.text 5,$67,"CLEAR" ; $c6 CLEAR
77+
.text 5,$7f,"COLOR" ; $c7 COLOR
78+
.text 6,$d4,"COLOUR" ; $c8 COLOUR
79+
.text 4,$1a,"DATA" ; $c9 DATA
80+
.text 3,$da,"DIM" ; $ca DIM
81+
.text 6,$db,"DOWNTO" ; $cb DOWNTO
82+
.text 4,$29,"ELSE" ; $cc ELSE
83+
.text 4,$34,"FROM" ; $cd FROM
84+
.text 3,$e5,"GFX" ; $ce GFX
85+
.text 4,$24,"HERE" ; $cf HERE
86+
.text 5,$63,"IMAGE" ; $d0 IMAGE
87+
.text 3,$e5,"LET" ; $d1 LET
88+
.text 4,$28,"LINE" ; $d2 LINE
89+
.text 5,$6b,"LOCAL" ; $d3 LOCAL
90+
.text 7,$1a,"MEMCOPY" ; $d4 MEMCOPY
91+
.text 4,$21,"NAME" ; $d5 NAME
92+
.text 3,$db,"OFF" ; $d6 OFF
93+
.text 2,$9d,"ON" ; $d7 ON
94+
.text 7,$20,"OUTLINE" ; $d8 OUTLINE
95+
.text 7,$0f,"PALETTE" ; $d9 PALETTE
96+
.text 4,$3f,"PLOT" ; $da PLOT
97+
.text 4,$2f,"POKE" ; $db POKE
98+
.text 5,$73,"POKED" ; $dc POKED
99+
.text 5,$7b,"POKEL" ; $dd POKEL
100+
.text 5,$86,"POKEW" ; $de POKEW
101+
.text 4,$1c,"READ" ; $df READ
102+
.text 4,$2e,"RECT" ; $e0 RECT
103+
.text 3,$e4,"REM" ; $e1 REM
104+
.text 5,$7b,"SOLID" ; $e2 SOLID
105+
.text 5,$89,"SOUND" ; $e3 SOUND
106+
.text 6,$d7,"SPRITE" ; $e4 SPRITE
107+
.text 4,$45,"TEXT" ; $e5 TEXT
108+
.text 2,$a3,"TO" ; $e6 TO
109+
.text 4,$3c,"STEP" ; $e7 STEP
109110
.text $FF
110111
KeywordSet1:
111112
.text 0,$65,"" ; $80 !0:EOF

source/common/commands/inputprint.asm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ _CPLoop:
9797
beq _CPTab
9898
cmp #KWD_AT ; `at` modifier
9999
beq _CPAtModifier
100+
cmp #KWD_TABLPAREN ; `tab` modifier
101+
beq _CPTabModifier
100102
dey ; undo the get
101103
jsr EvaluateExpressionAt0 ; evaluate expression at 0.
102104
lda NSStatus,x ; read the status
@@ -135,6 +137,9 @@ _CPNumber:
135137
_CPAtModifier:
136138
jsr CPPrintAt ; subroutine to keep `_CPLoop` within branch range
137139
bra Command_IP_Main
140+
_CPTabModifier:
141+
jsr CPPrintTab ; subroutine to keep `_CPLoop` within branch range
142+
bra Command_IP_Main
138143
;
139144
; New line
140145
;
@@ -362,4 +367,47 @@ CPPrintAt:
362367
_range_error:
363368
jmp RangeError ; branch to range error handler
364369

370+
;;
371+
; Handle the `tab(column)` modifier for print/input statements.
372+
;
373+
; Parses the column coordinate from the statement and positions the cursor
374+
; accordingly. If the requested column is to the left of the current cursor
375+
; position, moves the cursor to the next line and then to the specified column.
376+
;
377+
; \in Y Current parsing position in the statement.
378+
; \out Y Updated parsing position after consuming column argument
379+
; and the closing parenthesis.
380+
; \out EXTRow If newline occurred, set to the updated row coordinate.
381+
; \out EXTColumn Set to the specified column coordinate.
382+
; \out EXTAddress If newline occurred, updated to point to the start of the
383+
; current row.
384+
; \sideeffects - Modifies registers `A` and `X`.
385+
; \see Evaluate8BitInteger, CheckComma, EXTSetCurrentLine,
386+
; EXTScreenHeight, EXTScreenWidth, RangeError
387+
;;
388+
CPPrintTab:
389+
; Parse
390+
ldx #0 ; bottom stack level
391+
jsr Evaluate8BitInteger ; parse column into `A`
392+
sta zTemp0 ; save it in `zTemp0` for now
393+
jsr CheckRightBracket
394+
395+
; Set the cursor position
396+
lda zTemp0
397+
cmp EXTColumn ; compare with current column
398+
bcs _CPTabSetColumnOnly ; if requested column is to the right, just move there
399+
400+
inc EXTRow ; move to next row
401+
stz EXTPendingWrap ; clear pending wrap, if any
402+
403+
pha
404+
phy
405+
jsr EXTSetCurrentLine ; set current line address to `EXTRow`
406+
ply
407+
pla
408+
409+
_CPTabSetColumnOnly:
410+
sta EXTColumn ; save column into `EXTColumn`
411+
rts
412+
365413
.send code

source/common/errors/charcheck.asm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ CheckNextA:
4444
iny ; skip character
4545
rts ; and exit
4646
CNAFail:
47-
jmp SyntaxError
48-
47+
jmp SyntaxError
48+
4949
.send code
50-
50+
5151
; ***************************************************************************************
5252
;
5353
; Changes and Updates
@@ -58,4 +58,3 @@ CNAFail:
5858
; ==== =====
5959
;
6060
; ***************************************************************************************
61-

source/common/generated/kwdconst.inc

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -107,62 +107,63 @@ KWD_SCREENLPAREN = $ab; $ab SCREEN(
107107
KWD_SGNLPAREN = $ac; $ac SGN(
108108
KWD_SPCLPAREN = $ad; $ad SPC(
109109
KWD_STRDOLLARLPAREN = $ae; $ae STR$(
110-
KWD_TILELPAREN = $af; $af TILE(
111-
KWD_TIMERLPAREN = $b0; $b0 TIMER(
112-
KWD_TRUE = $b1; $b1 TRUE
113-
KWD_VALLPAREN = $b2; $b2 VAL(
114-
KWD_FRELPAREN = $b3; $b3 FRE(
115-
KWD_FN = $b4; $b4 FN
116-
KWD_FOR = $b5; $b5 FOR
117-
KWD_IF = $b6; $b6 IF
118-
KWD_PROC = $b7; $b7 PROC
119-
KWD_REPEAT = $b8; $b8 REPEAT
120-
KWD_WHILE = $b9; $b9 WHILE
121-
KWD_ENDFN = $ba; $ba ENDFN
122-
KWD_ENDIF = $bb; $bb ENDIF
123-
KWD_ENDPROC = $bc; $bc ENDPROC
124-
KWD_NEXT = $bd; $bd NEXT
125-
KWD_THEN = $be; $be THEN
126-
KWD_UNTIL = $bf; $bf UNTIL
127-
KWD_WEND = $c0; $c0 WEND
128-
KWD_AT = $c1; $c1 AT
129-
KWD_BY = $c2; $c2 BY
130-
KWD_CALL = $c3; $c3 CALL
131-
KWD_CIRCLE = $c4; $c4 CIRCLE
132-
KWD_CLEAR = $c5; $c5 CLEAR
133-
KWD_COLOR = $c6; $c6 COLOR
134-
KWD_COLOUR = $c7; $c7 COLOUR
135-
KWD_DATA = $c8; $c8 DATA
136-
KWD_DIM = $c9; $c9 DIM
137-
KWD_DOWNTO = $ca; $ca DOWNTO
138-
KWD_ELSE = $cb; $cb ELSE
139-
KWD_FROM = $cc; $cc FROM
140-
KWD_GFX = $cd; $cd GFX
141-
KWD_HERE = $ce; $ce HERE
142-
KWD_IMAGE = $cf; $cf IMAGE
143-
KWD_LET = $d0; $d0 LET
144-
KWD_LINE = $d1; $d1 LINE
145-
KWD_LOCAL = $d2; $d2 LOCAL
146-
KWD_MEMCOPY = $d3; $d3 MEMCOPY
147-
KWD_NAME = $d4; $d4 NAME
148-
KWD_OFF = $d5; $d5 OFF
149-
KWD_ON = $d6; $d6 ON
150-
KWD_OUTLINE = $d7; $d7 OUTLINE
151-
KWD_PALETTE = $d8; $d8 PALETTE
152-
KWD_PLOT = $d9; $d9 PLOT
153-
KWD_POKE = $da; $da POKE
154-
KWD_POKED = $db; $db POKED
155-
KWD_POKEL = $dc; $dc POKEL
156-
KWD_POKEW = $dd; $dd POKEW
157-
KWD_READ = $de; $de READ
158-
KWD_RECT = $df; $df RECT
159-
KWD_REM = $e0; $e0 REM
160-
KWD_SOLID = $e1; $e1 SOLID
161-
KWD_SOUND = $e2; $e2 SOUND
162-
KWD_SPRITE = $e3; $e3 SPRITE
163-
KWD_TEXT = $e4; $e4 TEXT
164-
KWD_TO = $e5; $e5 TO
165-
KWD_STEP = $e6; $e6 STEP
110+
KWD_TABLPAREN = $af; $af TAB(
111+
KWD_TILELPAREN = $b0; $b0 TILE(
112+
KWD_TIMERLPAREN = $b1; $b1 TIMER(
113+
KWD_TRUE = $b2; $b2 TRUE
114+
KWD_VALLPAREN = $b3; $b3 VAL(
115+
KWD_FRELPAREN = $b4; $b4 FRE(
116+
KWD_FN = $b5; $b5 FN
117+
KWD_FOR = $b6; $b6 FOR
118+
KWD_IF = $b7; $b7 IF
119+
KWD_PROC = $b8; $b8 PROC
120+
KWD_REPEAT = $b9; $b9 REPEAT
121+
KWD_WHILE = $ba; $ba WHILE
122+
KWD_ENDFN = $bb; $bb ENDFN
123+
KWD_ENDIF = $bc; $bc ENDIF
124+
KWD_ENDPROC = $bd; $bd ENDPROC
125+
KWD_NEXT = $be; $be NEXT
126+
KWD_THEN = $bf; $bf THEN
127+
KWD_UNTIL = $c0; $c0 UNTIL
128+
KWD_WEND = $c1; $c1 WEND
129+
KWD_AT = $c2; $c2 AT
130+
KWD_BY = $c3; $c3 BY
131+
KWD_CALL = $c4; $c4 CALL
132+
KWD_CIRCLE = $c5; $c5 CIRCLE
133+
KWD_CLEAR = $c6; $c6 CLEAR
134+
KWD_COLOR = $c7; $c7 COLOR
135+
KWD_COLOUR = $c8; $c8 COLOUR
136+
KWD_DATA = $c9; $c9 DATA
137+
KWD_DIM = $ca; $ca DIM
138+
KWD_DOWNTO = $cb; $cb DOWNTO
139+
KWD_ELSE = $cc; $cc ELSE
140+
KWD_FROM = $cd; $cd FROM
141+
KWD_GFX = $ce; $ce GFX
142+
KWD_HERE = $cf; $cf HERE
143+
KWD_IMAGE = $d0; $d0 IMAGE
144+
KWD_LET = $d1; $d1 LET
145+
KWD_LINE = $d2; $d2 LINE
146+
KWD_LOCAL = $d3; $d3 LOCAL
147+
KWD_MEMCOPY = $d4; $d4 MEMCOPY
148+
KWD_NAME = $d5; $d5 NAME
149+
KWD_OFF = $d6; $d6 OFF
150+
KWD_ON = $d7; $d7 ON
151+
KWD_OUTLINE = $d8; $d8 OUTLINE
152+
KWD_PALETTE = $d9; $d9 PALETTE
153+
KWD_PLOT = $da; $da PLOT
154+
KWD_POKE = $db; $db POKE
155+
KWD_POKED = $dc; $dc POKED
156+
KWD_POKEL = $dd; $dd POKEL
157+
KWD_POKEW = $de; $de POKEW
158+
KWD_READ = $df; $df READ
159+
KWD_RECT = $e0; $e0 RECT
160+
KWD_REM = $e1; $e1 REM
161+
KWD_SOLID = $e2; $e2 SOLID
162+
KWD_SOUND = $e3; $e3 SOUND
163+
KWD_SPRITE = $e4; $e4 SPRITE
164+
KWD_TEXT = $e5; $e5 TEXT
165+
KWD_TO = $e6; $e6 TO
166+
KWD_STEP = $e7; $e7 STEP
166167
KWD1_ASSEMBLE = $83; $83 ASSEMBLE
167168
KWD1_ASSERT = $84; $84 ASSERT
168169
KWD1_BITMAP = $85; $85 BITMAP

source/common/generated/kwdconst0.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ KWC_SHIFT1 = $81
66
KWC_SHIFT2 = $82
77
KWC_STRING = $FF
88
KWC_HEXCONST = $FE
9-
KWC_FIRST_STRUCTURE = $b4
10-
KWC_FIRST_STRUCTURE_DEC = $ba
11-
KWC_LAST_STRUCTURE = $c0
9+
KWC_FIRST_STRUCTURE = $b5
10+
KWC_FIRST_STRUCTURE_DEC = $bb
11+
KWC_LAST_STRUCTURE = $c1
1212
KWC_FIRST_UNARY = $83
13-
KWC_LAST_UNARY = $b3
13+
KWC_LAST_UNARY = $b4

0 commit comments

Comments
 (0)