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