Loading and Saving to Sedoric Disc

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
Post Reply
User avatar
Twilighte
Game master
Posts: 819
Joined: Sat Jan 07, 2006 12:07 am
Location: Luton, UK
Contact:

Loading and Saving to Sedoric Disc

Post by Twilighte » Tue Jan 16, 2007 8:42 pm

I have used two routines kindly sent to me from Symoon to Load and Save using Sedoric from ASM.
These both work.

Code: Select all

#define SwitchOutROM $04f2
#define SwitchInROM  $04f2
FilenameLine
 .byt "A-JUM.XI0",0

DiscSave
	sei
	ldx #<FilenameLine
	stx $e9
	ldx #>FilenameLine
	stx $ea
	jsr SwitchOutROM
	lda #$00
	jsr $d454
	;Setup Areas
	lda #<$8000 ;Start Address Lo
	sta $c052
	lda #>$8000 ;Start Address Hi
	sta $c053
	lda #<$9FFF ;End Address Lo
	sta $c054
	lda #>$9FFF ;End Address Hi
	sta $c055
	lda #$00
	sta $c04d
	sta $c04e
	lda #$40
	sta $c051
	jsr $de0b
	jsr SwitchInROM
	cli
	rts

DiscLoad
	sei
	ldx #<FilenameLine
	stx $e9
	ldx #>FilenameLine
	stx $ea
	;
	jsr SwitchOutROM

	lda #00
	jsr $dff9
	jsr SwitchInROM
	cli
	rts
incidentally, any disc error is generated in location $4FD so poll that and if you get 0, the operation was successful otherwise report the number to the user.
It is also a good idea to backup Zero page before accessing these routines. Under asm, you will no doubt be using zero page for your own stuff and you won't want sedoric messing up your variables.

Finally, immense thanks and gratitudes go to one Symoon for assisting me last night in correcting the load routine. Without him i would have been clueless and probably have taken another month to figure it out.
Last edited by Twilighte on Wed Jan 17, 2007 8:17 pm, edited 2 times in total.

User avatar
Symoon
Archivist
Posts: 1152
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France
Contact:

Post by Symoon » Tue Jan 16, 2007 11:45 pm

A few more details about the file type:
the LDA $#40 in the save routine is set there to save a data file, not auto.

The file type byte is described in Sedoric manual page 100, or on the on-line version of Defence-Force:
http://www.defence-force.org/computing/ ... htm#chap_7 (see annexe 4)

In English:
b0 : automatic execution (CSAVE ",AUTO" parameter)
b1 : unused
b2 : unused
b3 : direct
b4 : sequential
b5 : window (with b6 = 1)
b6 : data file
b7 : basic file

the "#40" is there for "data file", not auto. I can't recall exactly what b3, b4 and b5 are for (any Sedoric poweruser will say), but everything's fine when they're left at 0.

User avatar
waskol
Flight Lieutenant
Posts: 331
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

Post by waskol » Tue Nov 11, 2008 9:53 pm

Hello,

Please, I would like to know
- how I could use these in order to save an array and a couple of variables in C ?
I am so dumb in asm.
Well, in fact, I don't feel very comfortable with interfacing asm routines with the C part of my code, even if they are a few examples in the OSDK.

Well, I am just asking to assembly expert if they could kindly provide me a C library in order to load or save any file from a C program written with the OSDK.

Thank you soooooooooooooooooooooooooooooo much by advance.

User avatar
Symoon
Archivist
Posts: 1152
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France
Contact:

Post by Symoon » Wed Nov 12, 2008 2:36 am

waskol wrote:Well, I am just asking to assembly expert if they could kindly provide me a C library in order to load or save any file from a C program written with the OSDK.
I won't be able to help here, I have zero knowledge about doing a C library (never used C on Oric).
Anyone?

User avatar
Chema
Game master
Posts: 2016
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Post by Chema » Wed Nov 12, 2008 10:14 am

waskol wrote: Please, I would like to know
- how I could use these in order to save an array and a couple of variables in C ?
I am so dumb in asm.
Well, in fact, I don't feel very comfortable with interfacing asm routines with the C part of my code, even if they are a few examples in the OSDK.

Well, I am just asking to assembly expert if they could kindly provide me a C library in order to load or save any file from a C program written with the OSDK.
Little idea about how to use these particular routines from C, but even if Dbug could provide much better information, there are a couple of bits of information which can be useful to create your own routines in asm and call them from C.

You just need to remember that program arguments are passed through the pointer in sp (a zero-page pointer) and results are returned in registers X and A (can't remember now, which is the high part and which is the low part -- I think A is the low and X the high). Also remember that to be accessible from C, variables and function names should be preceeded by an underscore. So a routine which takes an integer and a character and returns an integer should look like:

Code: Select all

; int MyFunc (int i, char c)
_Myfunc
.(
  ; Get the integer and store it in (tmp,tmp+1)
  ldy #0
  lda (sp),y ; Get low byte of i
  sta tmp
  iny
  lda (sp),y ; Get high byte of i
  sta tmp+1
  ; Get the character and store it in (op)
  iny
  lda (sp),y ; Get char c
  sta op
  ; Do whatever...
  ...
  lda res ; Get result, low byte
  ldx res+1 ; Get result high byte
 rts
.)

Now just declare the function as extern and use it.

Code: Select all

extern int MyFunc(int, char);
...
r=MyFunc(a,b);
So you can create a C version for the DiscSave, for instance as...

Code: Select all

extern char DiscSave(char * filename, char * pini, char * pend);

_DiscSave
.(
  ldy #0
  lda (sp),y
  sta $e9
  iny
  lda (sp),y
  sta $e0
  
   jsr SwitchOutROM 
   lda #$00 
   jsr $d454 
  
   ;Setup Areas 
   ldy #2
   lda (sp),y ;Start Address Lo 
   sta $c052 
   iny
   lda (sp),y ;Start Address Hi 
   sta $c053 
   iny
   lda (sp),y ;End Address Lo 
   sta $c054
   iny 
   lda (sp),y ;End Address Hi 
   sta $c055 
   lda #$00 
   sta $c04d 
   sta $c04e 
   lda #$40 
   sta $c051 
   jsr $de0b 
   jsr SwitchInROM 
   cli 
   lda $4fd ; Get result (low byte)
   ldx #0   ; Get result (high byte)
   rts 
.)

Please bear in mind that I have just done this by memory, so it could be bugged... Also there is no provision for backing up zero-page... should see what part is being corrupted. Finally I know there are a couple of routines that serve to save some C registers to make the function re-entrant (I think those are enter and leave, but not sure).

Dbug can provide more insights to this... but I hope this helps to understand how to make a quick asm routine to be called from C..

Cheers

User avatar
waskol
Flight Lieutenant
Posts: 331
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

Post by waskol » Wed Nov 12, 2008 11:01 am

Thank you so much both of you !
Chema, now I can dig it up a little bit more and test this.

Thank you, thank you, thank you.

User avatar
Dbug
Site Admin
Posts: 2345
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Post by Dbug » Wed Nov 12, 2008 6:59 pm

What would be nice, is that you experiment by starting it as if it was a new osdk library module.

Basically all you have to do is:

- Create a .s file in the osdk/lib folder, for example "disk.s" and add your code in it (for example "_disc_save" and "_disc_load" (or better names if you find something better))
- Edit the "library.ndx" file in the same folder, and add a section with the list of all exported functions, just follow the examples (add a "-disk.s" line, and then tabulated lines with each exported function name)
- Edit the "lib.h" in osdk/include, and add the prototype for the functions.

That's all, from now on the functions will appear as standard library functions, and the linker will automatically add the modules if you call the function.

User avatar
Twilighte
Game master
Posts: 819
Joined: Sat Jan 07, 2006 12:07 am
Location: Luton, UK
Contact:

Post by Twilighte » Fri Nov 14, 2008 12:15 am

Incidentally, i do have somewhere a routine to get the Sedoric directory since i used it in AudioTracker. However the problem under asm is where to store it?
It could be a massive list and fetching parts of a directory may not be so easy. In audiotracker i just fetched up to 10 (i think) filenames whose extension matched one of AudioTrackers formats.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest