<commit_before>; Single byte query/set routine

; syscall is a general purpose entry point to the OS which may optionally
; transfer a byte as an argument. On entry, X selects which routine is used
; and A contains the argument. On exit, A contains any return value and
; processor flags may have been modified.
;
; X	Routine
; 0	Query input buffer. Carry is set if input buffer non-empty.
;
; Values of X other than those above will result in an error.

.include "globals.inc"
.include "macros.inc"

.export syscall

.proc syscall
	save_xy
	save_word ptr1
	save_word ptr2

	; TODO: check value of X

	; Get the address of the syscall routine by adding X to
	; jump_table twice
	ldw ptr1, jump_table
	pha
	txa
	add_word ptr1
	add_word ptr1
	pla

	; Then copying word at that address into ptr2
	ldy #0
	lda (ptr1), Y
	sta ptr2, Y
	iny
	lda (ptr1), Y
	sta ptr2, Y

	; Jump to syscall routine at ptr2. Use JSR here to allow
	; syscall's rts instruction to come back here.
	jsr syscall_jump

	restore_word ptr2
	restore_word ptr1
	restore_xy
	rts
.endproc

syscall_jump:
	jmp (ptr2)

jump_table:
	.import haveinput
	.word haveinput
<commit_msg>syscall: increase efficiency of jump table<commit_after>; Single byte query/set routine

; syscall is a general purpose entry point to the OS which may optionally
; transfer a byte as an argument. On entry, A selects which routine is used
; and X contains the argument. On exit, A contains any return value and
; processor flags may have been modified and X is corrupted.
;
; A	Routine
; 0	Query input buffer. Carry is set if input buffer non-empty.
;
; Values of A other than those above will result in an error.

.include "globals.inc"
.include "macros.inc"

.export syscall

.proc syscall
	; TODO: check value of A < 128

	; Set A, X = X, A*2. This allows the syscall routines to be called with
	; A as the input argument.
	asl
	phx
	tax
	pla

	; Jump to syscall routine. Syscall routine's rts instruction will return
	; to caller.
	jmp (jump_table, X)
.endproc

jump_table:
	.import haveinput
	.word haveinput

{'fraction_non_alphanumeric': 0.056962025316455694, 'fraction_numerical': 0.010223953261927946, 'mean_word_length': 3.576837416481069, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3256952', 'n_tokens_mistral': 713, 'n_tokens_neox': 652, 'n_words': 318}