User Tools

Site Tools


base:runasmfrombasic

This is an old revision of the document!


Running an Assembler program from BASIC using SYS

A Basic program can call Assembler code using the SYS command. See the description of the SYS Basic command. Before calling the specified address, SYS “loads” the accumulator, the X and the Y index register, and the status register with the bytes stored at addresses 780–783/$030C–$030F: From BASIC, one can set up parameters and data here, to be processed by the machine language routine.

This typically leads to games using a Basic stub to call the game assembler code. This leads to a typical line like this:

1984 SYS 2084

The hexdump shows:

>C:0800  00 0c 08 c0  07 9e 20 32  30 38 34 00  00 00 00 00   ...... 2084.....

At $0801 is the pointer to the next Basic line the following two byte are the little endian number $07c0 which is the line number 1984 the follows $9e which is the Basic token for SYS. After that we have a space and the number 2084 in PETSCII.

A simple stub for use

A simple stub program looks like this (this uses xa65 syntax, see the xa65 homepage). The code:

	.word $0801
	* = $0801
	
basic:	.(
	.word end_of_basic
	.word 2017
	.byte $9e,$20
	.asc "(2064)"
end_of_basic:
	.byte 0,0,0
	.)

main:	sta $0400
	stx $0401
	sty $0402
	php
	pla
	sta $0403
	lda #$ff
	tax
	tay
  	rts

compiles to:

>C:0800  00 0e 08 e1  07 9e 20 28  32 30 36 34  29 00 00 00   ...... (2064)...
>C:0810  8d 00 04 8e  01 04 8c 02  04 08 68 8d  03 04 a9 ff   ..........h.....
>C:0820  aa a8 60 00  00 00 00 00  00 00 00 00  00 00 00 00   ..`.............

As can be easily seen the SYS to address 2064 starts the code at $0810.

base/runasmfrombasic.1501237619.txt.gz · Last modified: 2017-07-28 12:26 by pararaum