Jump to content
IGNORED

Load Data from disk in Assembly


Recommended Posts

I am attempting to set up something that can set up something that can Save and Load data to and from disk in assembly for a new and upcoming game. I know its not too hard to do from Basic, but not sure how this works in assembly. This is what I figured out so far. Cannot find any good examples on how to set this up.

        LDA #CIO_READ
  	STA ICCOM,X
  	LDA # <FNAME_00 	; FILENAME IS D:Filename
  	STA ICBAL,X
  	LDA # >FNAME_00
  	STA ICBAH,X
  	LDA #0  	
  	STA ICAUX2,X

Link to comment
Share on other sites

 

I am attempting to set up something that can set up something that can Save and Load data to and from disk in assembly for a new and upcoming game.

 

answer is... xB:

1.

ldy < fname

ldx > fname

jsr xBIOS_OPEN_FILE

fname .byte c'MYFILE COM'

-

ldy < dest

ldx > dest

jsr xBIOS_LOAD_DATA

2.

ldy < src

ldx > src

jsr xBIOS_WRITE_DATA

  • Like 2
Link to comment
Share on other sites

Yes, xBIOS is a great way of doing this.

 

Pete, if you're looking for some instructions for xBIOS, you can find them here:

https://atariwiki.org/wiki/Wiki.jsp?page=XBIOS

 

I translated some sources (well, Google did and I cleaned up the translation) and mixed together a few examples I found on the net. Let me know if there are any document problems.

 

I've read a few of your posts on here and I know that you work on cartridge software too. Just last night I was fiddling around and managed to get a cartridge program running together with xBIOS, so that it can save its progress to disk. At the moment I just got it reading from the disk, but from a cartridge program.

  • Like 2
Link to comment
Share on other sites

I am planning on using xBIOS with the next Secretum Labyrinth. The other thing I am doing is making an updater for games on AtariMax cartridges that just re-flash the banks that need updating instead waiting to do the whole cartridge. It will even have a safety check to make sure the correct game is in the cartridge slot so it does not accidentally damage another game or a blank cartridge. I started running into problems re-flashing whole 1024K AtariMax cartridges that only need to reflash one or two 8K banks. It may be adapted to other cartridge types, but AtariMax is most commonly used for larger games that are 128K to 1024K right now.

Link to comment
Share on other sites

I've never heard about xBIOS before. Anyhow, when I wrote the Phantasy demo, i just programmed disk IO using the standard memorylocations for drive communication. Is the purpose of xBIOS to help programmers who are not good enough to program their own device code ? No offense ment to anybody. Just wondering, because i dont know xBIOS.

 

Read the information, and liked the musicplay routine during loading. Never was able to program this myselve in the 80s.

Link to comment
Share on other sites

I've never heard about xBIOS before. Anyhow, when I wrote the Phantasy demo, i just programmed disk IO using the standard memorylocations for drive communication. Is the purpose of xBIOS to help programmers who are not good enough to program their own device code ? No offense ment to anybody. Just wondering, because i dont know xBIOS.

 

Read the information, and liked the musicplay routine during loading. Never was able to program this myselve in the 80s.

If you want to use file system you dont want to write your own IO. And esp when memory is tight and you dont want to load DOS....

Link to comment
Share on other sites

I would have two questions:

1) Is there any software using xBIOS with source code available? An example with xBIOS in RAM under ROM would be nice.

2) Does vanilla (without any extensions) xBIOS tolerate some disk drive enhancements - HAPPY, SPEEDY etc? Toleration = works perfectly with HAPPY and SPEEDY, but with default speed.

 

Thanks.

I am asking because I would like to write a copier - DISK>MEMORY>TAPE and xBIOS would be a very good solution for reading from floppy residing under ROM. Currently I used xBIOS for the "Floppy disk of the lost miner" and it went well.

Edited by baktra
Link to comment
Share on other sites

1. easy way:

copy this: 43 58 41 55 54 4F 52 55 4E 20 20 20 D9 D8 E2 02 E0 02 00 00 00 00 FE 00 00 as xbios.cfg file

 

opt h-
.byte $43 ; for xB 4.3
.byte c’XAUTORUN ‚ ; autorun filename
.byte >$D900 ; xB adress
.byte >$D800 ; buffer adress
.word $02e2 ; INITAD adress
.word $02e0 ; RUNAD adress
.word $0000 ; I/O module adress – $0000 means xB build in SIO
.word $0000 ; I/O relocator adress - $0000 means xB build in
.byte $fe ; PORTB, without BASIC
.byte $00 ; NMIEN
.byte $00 ; IRQEN

 

and now xB is under ROM

 

my SlightSID Player use config like this (xB under ROM)

 

 

2. ofcourse :

 

https://atariwiki.org/wiki/Wiki.jsp?page=XBIOS#section-XBIOS-UseOfHighSpeedDevices

Edited by xxl
  • Like 2
Link to comment
Share on other sites

  • 4 months later...

Did the original creators of this thing figure out how to create new files? I see under "XBIOS Limitations" It cannot create new file names. I would like to set up a save game progress thing. I wonder if this is something that be added along with all the other functions.

Link to comment
Share on other sites

Did the original creators of this thing figure out how to create new files? I see under "XBIOS Limitations" It cannot create new file names. I would like to set up a save game progress thing. I wonder if this is something that be added along with all the other functions.

 

It appears to support writing to files. So, in this case you could designate game save files (SAVE001, SAVE002, SAVE003) and pre-populate them on disk, then overwrite them when the user chooses the save file.

Edited by kenjennings
Link to comment
Share on other sites

 

It appears to support writing to files. So, in this case you could designate game save files (SAVE001, SAVE002, SAVE003) and pre-populate them on disk, then overwrite them when the user chooses the save file.

That is what I am thinking about, also. Wonder if there is a way to write to sectors directly.

Link to comment
Share on other sites

of course:

 

; PUT SECTOR

lda <sector
sta xDAUX1
lda >sector
sta xDAUX2
jsr xBIOS_FLUSH_BUFFER

and

; GET SECTOR

lda >sector
ldy <sector
jsr xBIOS_READ_SECTOR

 

thanks to this you can also write the "create_file" procedurę...

 

 

xBUFFERH equ xBIOS+$3f0 ; Buffer adr hi byte (1 byte)
xBUFSIZE equ xBIOS+$3f1 ; Buffer size lo byte $100-SIZE (1 byte)

 

xDAUX1 equ xBIOS+$3fe ; Sector lo byte (1 byte)
xDAUX2 equ xBIOS+$3ff ; Sector hi byte (1 byte)

  • Like 1
Link to comment
Share on other sites

Some 'Page Read/Write' code courtesy of Infocom :)

DUNIT	= $0301
DCOMND	= $0302
DSTATS	= $0303
DBUFLO	= $0304
DBUFHI	= $0305
DTIMLO	= $0306
DTIMHI	= $0306
DBYTLO	= $0308
DBYTHI	= $0309
DAUX1	= $030A
DAUX2	= $030B

DSKINV	= $E453

	.zeropage
BlockNum:       .res 2
SectorNum:      .res 2
	
	.data
	.export CurrentDrive
CurrentDrive:	.BYTE 1

	.code

; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B	R O U T	I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
	.export WriteBufToNextBlock
WriteBufToNextBlock:
		LDA	#0
		STA	ptr1
		LDA	#4
		STA	ptr1+1
; End of function WriteBufToNextBlock

; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B	R O U T	I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦

	.export NextBlockW
NextBlockW:
		INC	BlockNum
		BNE	WriteBlock
		INC	BlockNum+1
	.export WriteBlock
WriteBlock:
		LDA	#$57
		JMP	loc_0_2023
; End of function NextBlockW

; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B	R O U T	I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
	.export ReadNextBlockToBuf
ReadNextBlockToBuf:
		LDA	#0
		STA	ptr1
		LDA	#4
		STA	ptr1+1
; End of function ReadNextBlockToBuf

; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B	R O U T	I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦

	.export NextBlockR
NextBlockR:
		INC	BlockNum
		BNE	ReadBlock
		INC	BlockNum+1
; End of function NextBlockR

; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B	R O U T	I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦

	.export ReadBlock
ReadBlock:
		LDA	#$52
loc_0_2023:
		STA	DCOMND
		LDA	ptr1
		STA	DBUFLO
		LDA	ptr1+1
		STA	DBUFHI
		LDA	CurrentDrive
		STA	DUNIT
		CLC	
		LDA	BlockNum
		ADC	BlockNum
		STA	SectorNum
		LDA	BlockNum+1
		ADC	BlockNum+1
		STA	SectorNum+1
		CLC	
		LDA	SectorNum
		ADC	FirstDataSectorLo
		STA	SectorNum
		LDA	SectorNum+1
		ADC	FirstDataSectorHi
		STA	SectorNum+1
		JSR	GetSectorData
		BPL	DoNext128Bytes
		RTS	
; ---------------------------------------------------------------------------
DoNext128Bytes:
		INC	SectorNum
		BNE	loc_0_205C
		INC	SectorNum+1
loc_0_205C:
		CLC	
		LDA	#$80
		ADC	ptr1
		STA	DBUFLO
		LDA	#0
		ADC	ptr1+1
		STA	DBUFHI
; End of function ReadBlock

; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B	R O U T	I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦

GetSectorData:
		LDA	SectorNum
		STA	DAUX1
		LDA	SectorNum+1
		STA	DAUX2
		JMP	DSKINV
; End of function GetSectorData

; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B	R O U T	I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
	.export ReadDiskBlock
ReadDiskBlock:
		JSR	ReadBlock
		BMI	DiskError
		RTS	
; End of function ReadDiskBlock

; ---------------------------------------------------------------------------
DiskError:
		; ... do what you want here

  • Like 2
Link to comment
Share on other sites

I have to see how hard it would be to have the OS create a file then have XBIOS save desired data.

 

It isn't the job of the OS to create a file, that is what a DOS is for.

 

You can perhaps get the drive to format a blank disk and then write specific patterns to the appropriate sectors to give you initial 'position' xBIOS requires.

Link to comment
Share on other sites

I might do the write sector direct thing then, and maybe keep a list of game saves in 1 or 2 separate sectors, can use more than 8+3 characters there.

 

Another option to saving game progress is using an AtariMax flash cartridge and leave one bank open to save the game progresses.

Link to comment
Share on other sites

  • 3 months later...

Recently, I had been getting around to using this XBIOS thing to save game progress for an adventure style game I am working on. I needed to relocate it from its default address and it is creating some problems. First think I noticed it is doing a JMP(xIOV) and I tracked it down to point to 22D3. When program is in default location it points to something right past a RTS instruction without an label. Just past "xBIOS_SET_BUFFER_SIZE" and "L22CC" I gave this a label as "xBIOS_DEFAULT_DEVICE" but not sure if that is accurately describing the routine. Is there a more recently all labeled English version of this that is all labeled and can be relocated anywhere in memory? I really need help to make this XBIOS thing work.

Link to comment
Share on other sites

xB relocates itself as you place a .cfg file on the disk. Write where you want to relocate xB and where to relocate the buffer, on this example I will create a cfg file for you.

Link to comment
Share on other sites

Yeah, I do not see a CFG file, or using one to compile XBIOS with my program. Are you talking the ATR image you download that displays that small blue screen with light blue text?

 

Here is some of the code I am using. Am I missing anything?

L06FB       = $06FB
L06FE       = $06FE
L06FF       = $06FF
			
xBIOS_BUFFER = $2300
xBIOS_BUFFER_FC = xBIOS_BUFFER + $7C
xBIOS_BUFFER_FD = xBIOS_BUFFER + $7D
xBIOS_BUFFER_FE = xBIOS_BUFFER + $7E
xBIOS_BUFFER_FF = xBIOS_BUFFER + $7F

      LDX #>xBIOS_BUFFER 
      JSR xBIOS_RELOCATE_BUFFER
      JSR xBIOS_SET_DEFAULT_DEVICE  
      JSR Save_Game_File
      RTS

Save_Game_File
      LDY <$0600
      LDX >$0600          
      JSR xBIOS_SET_LENGTH            
      LDY <slfname 
      LDX >slfname
      JSR xBIOS_OPEN_FILE
      LDY <($1800)
      LDX >($1800)
      JSR xBIOS_WRITE_DATA
      RTS

slfname 
     .BYTE "GAMEFIL0SAV"
slfblock = slfname + 7


Link to comment
Share on other sites

xBIOS_BUFFER = $2300

      LDX #>xBIOS_BUFFER 
      JSR xBIOS_RELOCATE_BUFFER
;      JSR xBIOS_SET_DEFAULT_DEVICE  ; look below  1.
      JSR Save_Game_File
      RTS

Save_Game_File
      LDY <slfname 
      LDX >slfname
      JSR xBIOS_OPEN_FILE
      LDY <$0600
      LDX >$0600
      JSR xBIOS_SET_LENGTH   ; look below 2.
LDY <($1800)
LDX >($1800)

JSR xBIOS_WRITE_DATA

RTS

slfname .BYTE "GAMEFIL0SAV"

slfblock = slfname + 7

 

 

So you want to relocate the buffer only (after game loads)? xBIOS_RELOCATE_BUFFER is ok then.
1. it is not necessary. unless you have OS ROM turned off? it also means that you will use SIO drives only. you can relocate IO moduke also... if you want
2. the amount of data to send should be set after opening the file. you do not have to set this if the file on the disk is $600 bytes long
you can check whether the operation was successful - the C flag will be clear.
Edited by xxl
Link to comment
Share on other sites

I tried to run the routine with OSROM on. Now this is running from a cartridge that never initialized the OS or loaded anything in. Does anything need to be called from the OS to make this work. Also that code WrathChild in post #19 "'Page Read/Write' code courtesy of Infocom..." Does that need the OS booted first to work? The cartridge game is using some memory from $0200 to $1000 to store some variables. Would this be a problem?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...