summaryrefslogtreecommitdiff
path: root/programs/sub-suite/subasm.s
blob: ec58a40491237eb504de97990701c7a52d84f620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
; SuBAsm
; The Sux Bootstrapped Assembler.
;
; by mr b0nk 500 <b0nk@b0nk.xyz>

subasm:
	ldb #0		; Set the first pointer
	lda.d #cmd_buf	; to the command buffer.
	jsr set_ptr	;
	tba		; Reset A.
	tax		; Reset X.
	jsr chk_shcmd	; Did we get a shortend command?
	bne @cmd	; Yes, so skip everything else.
	jsr chk_cmd	; No, but did we get a full command?
	bne @cmd	; Yes, so skip everything else.
	jsr lex		; No, so start lexing this line.
	bra @end	; We are done.
@cmd:
	ldb #1		; Set the second pointer
	lda.d #cmd_srt	; to the command subroutine table.
	jsr set_ptr	;
	deb		; Reset B.
	tba		; Reset A.
	lda regf	; Get the command ID.
	cmp #8		; Is the command ID greater than the command count?
	bcs @end	; Yes, so we're done.
	lsl #1		; No, so multiply the command ID by two.
	tay		; Set the index to the offset that we just calculated.
	lda.w (ptr2), y	; Get the command subroutine, from the command subroutine table.
	ldb #2		; Save it in the third pointer.
	jsr set_ptr	;
	ldb #0		; Reset B.
	jsr (ptr3)	; Run the command's subroutine.
@end:
	and #0		; Reset A.
	jsr update_ptr	; Get the screen buffer index.
	tay		; Save it in Y.
	and #0		; Reset A.
	rts		; End of subasm.

chk_shcmd:
	tba		; Reset A.
	inb		; Set the second pointer
	lda.w #sh_cmds	; to the shortend command table.
	jsr set_ptr	;
	deb		; Reset B.
	tba		; Reset A.
	phy.w		; Preserve the screen buffer position.
	txy		; Set our index to zero.
	lda (ptr), y	; Is there nothing in the command buffer?
	beq @false	; Yes, so return that we failed.
	cmp #' '	; No, but is this character, a space?
	beq @false	; Yes, so return that we failed.
	jsr tolower	; No, so convert it to lowercase.
@loop:
	ldb (ptr2), y	; Are we at the end of the table?
	beq @false	; Yes, so return that we failed.
	cmp b		; No, so did the character match?
	beq @found	; Yes, so check if there are any arguments.
	iny		; No, so check the next command.
	bra @loop	; Keep looping.
@found:
	sty regf	; Save the command ID.
	ldy #1		; Check the next character in the command buffer.
	lda (ptr), y	; Is this the end of the buffer?
	beq @true	; Yes, so return that we succeded.
	cmp #' '	; No, but is this a space?
	beq @true	; Yes, so return that we succeded.
	bra @false	; No, so return that we failed.
@true:
	lda #1		; Return true.
	bra @end	; We are done.
@false:
	ldb #0		; Reset B.
	tba		; Return false.
	tax		; Reset X.
@end:
	ply.w		; Get back the screen buffer position.
	rts		; End of chk_shcmd.


chk_cmd:
	tba		; Reset A.
	tax		; Reset X.
	sta.q idx0	; Reset the first index.
	sta.q idx1	; Reset the second index.
@loop:
	lda.w #cmds	; Get pointer to the start of the command table.
	clc		; Prepare for a non carrying add.
	adc.w idx0	; Offset the pointer, by the length of the previous string.
	pha.q		; Preserve the command string pointer.
	jsr strcaseg	; Is the command buffer, the same as the command string?
	pla.q		; Get the command string pointer back.
	beq @true	; Yes, so return true.
	ldb idx1	; No, so Get the command ID.
	cpb #7		; Have we reached the end of the command table?
	beq @false	; Yes, so return false.
	inc idx1	; No, so increment the command ID.
@getlen:
	jsr strlen	; Get the string's length.
	inc		; Add one to the length.
	clc		; Prepare for a non carrying add.
	adc.w idx0	; Add the string offset to the current length
	sta.w idx0	; Save the offset in the first index.
	bra @loop	; Keep looping.
@true:
	ldb idx1	; Get the command ID.
	stb regf	; Return the command ID.
	ldb #1		; Return true.
	bra @end	; We are done.
@false:
	ldb #0		; Return false.
@end:
	rts		; End of chk_cmd.

viewmem:
	lda.q prg_cnt	; Get the program counter.
	sta.q idx0	; Save the address in the first index.
	and #$F0	; Clear the first four bits of the address.
	sta idx0	; Overwrite the first byte, with the masked byte.
	lda #19		; Move the cursor to the right, by 19 columns.
	sta scr_col	;
	jsr update_pos	;
	jsr print_lo	; Print the low nibble offsets.
	ldx #0		; Reset X.
	ldb #0		; Reset B.
	stb idx1	; Reset the byte count.
@loop:
	lda #'\n'	; Print a newline.
	jsr print_char	;
	jsr print_hi	; Place the address in the string buffer.
	jsr print_chunk	; Place the next 16 bytes in the string buffer.
	lda.d #strbuf	; Print the string buffer.
	jsr print_str	;
	inc idx1	; Increment the chunk count.
	ldb idx1	; Get the chunk count.
	cpb #$10	; Did we print 16 chunks?
	beq @end	; Yes, so we're done.
	lda.q idx0	; No, so get the address index.
	clc		; Prepare for a non carrying add.
	adc #$10	; Add 16 to the address.
	sta.q idx0	; Put it back into the address.
	and #0		; Reset A.
	bra @loop	; Keep looping.
@end:
	lda #'\n'	; Print a newline.
	jsr print_char	;
	and #0		; Reset A.
	rts		; End of viewmem.


list:
	nop		;
@end:
	rts		; End of list.
asm:
	nop		;
@end:
	rts		; End of asm.
help:
	nop		;
@end:
	rts		; End of help.
inst:
	nop		;
@end:
	rts		; End of inst.
run:
	nop		;
@end:
	rts		; End of run.
set:
	nop		;
@end:
	rts		; End of set.