Small assembly snippet corrupted.

You need an actual VIC.

Moderator: Moderators

Post Reply
malcontent
Vic 20 Hobbyist
Posts: 129
Joined: Sun Dec 26, 2010 1:51 pm

Small assembly snippet corrupted.

Post by malcontent »

So I know I'm over looking something basic that I probably have no knowledge about, but I have this little snippet of code I wrote as I was fooling around with the sound registers, and when I load it in VICE some of the bytes are changed that causes it to BRK. I found a workaround where choosing the auto-start option "inject to ram" did not cause the corruption, so it seems to be something the kernal load does?

Code: Select all

	*=$1000
	!byte 00,0b,10,00,00,9e,34,31,30,36 ;sys4104
	lda #15
	sta vol
	sta bass
loop	inc bass
	eor bass
	rol bass	
	ldy #0	;delay
-	iny
	bne -	
	jmp loop
in particular the end is corrupted, the iny, and the bne. This program doesn't do much sonically, its just the point I was at when messing around.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Small assembly snippet corrupted.

Post by Mike »

First of all, BASIC programs (and also the stub here) do not begin at $xxx0, but at $xxx1 [*] and the first 0 byte in your example is not supposed to be part of the program. Just cross-check against any BASIC program stored to disk with the SAVE command.

Second, the lines of a BASIC program all end with a 0 byte. The last line is then followed by another two 0 bytes of an empty link-pointer. The three 0 bytes signify the end of the program. If they are missing, the relink routine called after LOAD continues after the BASIC stub and corrupts the assembly program behind it (or possibly even hangs!), as you have noted.

So, here we go with the corrected version:

Code: Select all

	*=$1001
	!byte 0b,10,00,00,9e,34,31,30,39,00,00,00 ; 0 sys4109
	lda #15
	sta vol
	sta bass
loop	inc bass
	eor bass
	rol bass	
	ldy #0	;delay
-	iny
	bne -	
	jmp loop
It can be loaded normally ("relative") with ",8" to the BASIC start. The absolute load with ",8,1" is only necessary for pure machine code or data that is loaded to another address than the BASIC start, and where the KERNAL load routine then takes the load address from the first two bytes of the *.prg file. These are not shown here, rather automatically prepended by the assembler before save.

That also shows why $1000 as start address is a bad choice. It actually forces you to load the program with ",8,1" as if it was a machine program to be executed with SYS later. But it is the reason of those BASIC stubs to make a machine program easily executable with LOAD"...",8 and RUN only!


[*]: to be more precise, that 0 byte is actually stored in the address before the BASIC start, and it is prepared so by the BASIC interpreter itself. Normally the pointer at 43/44 points to an address ending in $xxx1, like $0401, $1001 or $1201 on the VIC-20, or $0801 on the C64. You could have point it elsewhere at an address with another value than 1 as low byte. Still the requirement remains, that a 0 byte must be placed before the BASIC start - and this is in the responsibility of the party moving the BASIC start, not of the program being loaded!
malcontent
Vic 20 Hobbyist
Posts: 129
Joined: Sun Dec 26, 2010 1:51 pm

Re: Small assembly snippet corrupted.

Post by malcontent »

Ah, In my heart, I sort of knew basic started at 1001, but figured the padding byte would help, basically I just entered the sys line and looked at it in a monitor, makes sense that I forgot the trailing zeros doing it that way. Much obliged!
Post Reply