Jump to content

Photo

Load Data from disk in Assembly


49 replies to this topic

#1 peteym5 OFFLINE  

peteym5

    River Patroller

  • 2,261 posts
  • Location:Buffalo NY USA

Posted Sat Oct 7, 2017 12:07 PM

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



#2 flashjazzcat ONLINE  

flashjazzcat

    Quadrunner

  • 13,819 posts
  • Location:United Kingdom

Posted Sat Oct 7, 2017 12:47 PM

This should tell you everything you need to know:

 

Atariki: Accessing Files



#3 pirx OFFLINE  

pirx

    Moonsweeper

  • 438 posts
  • Location:Poland

Posted Tue Oct 10, 2017 2:35 AM

the "battery" is really the "accumulator" :)))



#4 xxl OFFLINE  

xxl

    Stargunner

  • 1,104 posts
  • Location:Rabka-Zdrój /Poland

Posted Fri Oct 13, 2017 12:23 AM

 

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



#5 snicklin OFFLINE  

snicklin

    River Patroller

  • 2,137 posts
  • Location:Australia

Posted Fri Oct 13, 2017 4:53 AM

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.or....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.



#6 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Fri Oct 13, 2017 6:33 AM

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.



#7 Stormtrooper of Death ONLINE  

Stormtrooper of Death

    Moonsweeper

  • 424 posts
  • Location:The Netherlands

Posted Sat Oct 14, 2017 7:57 AM

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.



#8 xxl OFFLINE  

xxl

    Stargunner

  • 1,104 posts
  • Location:Rabka-Zdrój /Poland

Posted Sat Oct 14, 2017 11:33 AM

Is the purpose of xBIOS to help programmers who are not good enough to program their own device code?

 

No, xBIOS is a 1KB library responsible for handling files and directories... without DOS 



#9 Heaven/TQA ONLINE  

Heaven/TQA

    Quadrunner

  • 10,924 posts
  • Location:Baden-Württemberg, Germany

Posted Mon Oct 16, 2017 10:27 AM

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....

#10 baktra OFFLINE  

baktra

    Dragonstomper

  • 527 posts
  • Location:Czech republic

Posted Tue Oct 17, 2017 1:04 AM

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, Tue Oct 17, 2017 1:08 AM.


#11 xxl OFFLINE  

xxl

    Stargunner

  • 1,104 posts
  • Location:Rabka-Zdrój /Poland

Posted Tue Oct 17, 2017 12:56 PM

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.or...ighSpeedDevices


Edited by xxl, Tue Oct 17, 2017 1:05 PM.


#12 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Mon Mar 5, 2018 11:20 PM

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.



#13 kenjennings OFFLINE  

kenjennings

    Dragonstomper

  • 789 posts
  • Me + sio2pc-usb + 70 old floppies
  • Location:Florida, USA

Posted Tue Mar 6, 2018 1:57 PM

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, Tue Mar 6, 2018 1:59 PM.


#14 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Tue Mar 6, 2018 11:34 PM

 

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.



#15 xxl OFFLINE  

xxl

    Stargunner

  • 1,104 posts
  • Location:Rabka-Zdrój /Poland

Posted Wed Mar 7, 2018 1:48 AM

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)



#16 flashjazzcat ONLINE  

flashjazzcat

    Quadrunner

  • 13,819 posts
  • Location:United Kingdom

Posted Wed Mar 7, 2018 1:59 AM

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


You don't need XBIOS if you just want to write sectors directly to a disk. The OS provides facilities for that.

#17 Wrathchild ONLINE  

Wrathchild

    River Patroller

  • 2,057 posts
  • Location:Reading, UK.

Posted Wed Mar 7, 2018 2:02 AM

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



#18 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Wed Mar 7, 2018 8:55 AM

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

 

But I am going to see if I can use the modifications to create a file first.



#19 Wrathchild ONLINE  

Wrathchild

    River Patroller

  • 2,057 posts
  • Location:Reading, UK.

Posted Wed Mar 7, 2018 10:16 AM

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.



#20 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Wed Mar 7, 2018 5:10 PM

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. 



#21 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Wed Jun 27, 2018 10:42 PM

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. 



#22 xxl OFFLINE  

xxl

    Stargunner

  • 1,104 posts
  • Location:Rabka-Zdrój /Poland

Posted Thu Jun 28, 2018 2:55 AM

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.



#23 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Thu Jun 28, 2018 11:26 AM

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




#24 xxl OFFLINE  

xxl

    Stargunner

  • 1,104 posts
  • Location:Rabka-Zdrój /Poland

Posted Thu Jun 28, 2018 1:33 PM

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, Thu Jun 28, 2018 3:50 PM.


#25 peteym5 OFFLINE  

peteym5

    River Patroller

  • Topic Starter
  • 2,261 posts
  • Location:Buffalo NY USA

Posted Thu Jun 28, 2018 9:27 PM

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? 






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users