Loading and Saving from tape

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
Post Reply
User avatar
Dbug
Site Admin
Posts: 2930
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Loading and Saving from tape

Post by Dbug » Mon Feb 20, 2006 10:33 pm

I decided to reply to the post in Contiki
http://forum.defence-force.org/viewtopi ... highlight=
here to keep it a bit more focused.

Here are the (crapy) routines I used in my first demo (1997) and that I reused in ULA paint for loading and saving pictures...

Basicaly it does the same thing than CLOAD and CSAVE, except that you can force the loading adress to wherever you want (thus ignoring the loading adress that is present in the file header).

From C, I use the routine like this:

Code: Select all

void LoadPicture(const char *ptr_filename)
{
  FileFlagForceAdress	=1;
  FileAdress=BufferMain1;
  strcpy((char*)0x27f,ptr_filename);
  FileLoad();
}

Here is the assembly code routine:

Code: Select all

_FileFlagForceAdress	.byt	0
_FileAdress	.byt	0,0

; =========================================
;		Load a file from tape
; =========================================
_FileLoad
  php
  jsr $e76a	       ; Disable keyboard, enable tape engine remote 
  jsr $e4ac	       ; Read tape header
  lda _FileFlagForceAdress
  beq continue_load
  ; Patch load start and end adress
  clc
  lda _FileAdress
  sta $2a9
  adc #<8000-1
  sta $2ab
  lda _FileAdress+1
  sta $2aa
  adc #>8000-1
  sta $2ac
continue_load
  jsr $e4e0	       ; Perform loading of data
  jsr $e93d	       ; Restore keyboard, and stop engine remote
 plp
 rts

Obviously this crap routine forces the size at 8000 bytes... shame
But I'm too tired to try to correct that. I guess that the idea would be to subtract from 2ab/2ac what is in 2a9/2aa before adding the new forced load adress ?

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

Post by Twilighte » Tue Jan 16, 2007 11:14 pm

I worked out these routines for loading and saving to tape...

filename_text is a zero byte terminated string of the filename
Eg.

Code: Select all

filename_text
 .byt "FILENAME1",0

Code: Select all

save_cassfile
	sei
	jsr store_filename
	lda #<$8000 ;file start lo
	sta $02a9
	lda #>$8000 ;file start hi
	sta $02aa
	lda #<$9FFF ;file end lo
	sta $02ab
	lda #>$9FFF ;file end hi
	sta $02ac
	lda #00
	sta $02ad
	jsr csave_bit
	cli
	rts
csave_bit
	php
	jmp $e92c

load_cassfile
	sei
	jsr store_filename
	ldx #$00
	stx $02ad
	stx $02ae
	stx $025a
	stx $025b
	jsr cload_bit
	cli
	rts
cload_bit
	pha
	jmp $e874

store_filename
	ldx #$0f	;store filename
scfl_01	lda filename_text,x
	sta $027f,x
	dex
	bpl scfl_01
	rts

Post Reply