Load/save problems

Basic and Machine Language

Moderator: Moderators

Post Reply
adric22
Vic 20 Hobbyist
Posts: 143
Joined: Fri Mar 11, 2005 6:54 pm

Load/save problems

Post by adric22 »

Sorry for so many questions.. I'm having difficulty saving a file from ML. Here is the code I've come up with:

Code: Select all

GAMENAM	!BYTE 77, 65, 80 ; the word "map"
SAVEMAP
	LDA	#$01		; logical file 1
	LDX	#$08		; device 8
	LDY	#$FF		; (no command)
	JSR	$FFBA		; Kernal set logical file routine

	LDY	#<GAMENAM	; low byte of filename location
	LDX	#>GAMENAM	; high byte of filename location
	LDA	#$03		; length of filename
	JSR	$FFBD		; kernal set-name routine.

	LDA	#$00		; low byte of $4000
	STA	$05
	LDA	#$40		; high byte of $4000
	STA	$06
	LDX	#$00		; Low byte of $8000
	LDY	#$80		; High byte of $8000
	LDA	#$05
	JSR	$FFD8		; Start save routine.
	RTS
Essentially, I want to create a file on the disk drive called "MAP" and it should contain the 16K worth of data from $4000 to $8000 in the VIC-20's memory. Now, this routine is creating a 16K file on the drive, but it has no name. It just shows up as "" on the disk. I can't for the life of me figure out what I am doing wrong. I mean, even if the pointer was off, the accumulator stores the length of the name, so the name should have at least 3 characters even if they are the wrong characters. Any thoughts?
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I believe you have mixed up the X and Y registers. Try this:

LDX #<GAMENAM
LDY #>GAMENAM

If the file name points to a zero byte, the created file would be named empty string.
Anders Carlsson

Image Image Image Image Image
adric22
Vic 20 Hobbyist
Posts: 143
Joined: Fri Mar 11, 2005 6:54 pm

Post by adric22 »

carlsson wrote:I believe you have mixed up the X and Y registers. Try this:

LDX #<GAMENAM
LDY #>GAMENAM

If the file name points to a zero byte, the created file would be named empty string.
\

Thank you so much! That did solve the problem. I must have checked that 10 times and it looked right to me. At one point I had thought about swapping just to see what would happen, but, again, I was confused because I expected there would be at least some kind of name of 3 characters long..
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

Besides, shouldn't the file name string be terminated with a null character or it doesn't matter as you specify the length of it?

I found out by using Google, search for FFBA FFBD FFD8 until you find some relevant assembly language listings. Then look at how they used the routines, although it should be documented in some books as well. Since these Kernel calls are identical on the C64, you will get plenty of hits.
Anders Carlsson

Image Image Image Image Image
User avatar
Wilson
Vic 20 Enthusiast
Posts: 190
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Post by Wilson »

carlsson wrote:Besides, shouldn't the file name string be terminated with a null character or it doesn't matter as you specify the length of it?
correct.
Post Reply