CPCWiki forum

General Category => Technical Support - Software related => Topic started by: the777 on 18:52, 18 January 25

Title: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: the777 on 18:52, 18 January 25
so i can take the decimal values and turn them into multicolored graphics.
Title: Re: is it possible to read sectors straight off a disk on the 6128?
Post by: Targhan on 19:05, 18 January 25
You can use the FDC tools I made a long time ago (in my signature). You can read both amsdos files, or the sector directy. The code is old but it is quite simple to understand to fit your needs.
Title: Re: is it possible to read sectors straight off a disk on the 6128?
Post by: the777 on 19:20, 18 January 25
Quote from: Targhan on 19:05, 18 January 25You can use the FDC tools I made a long time ago (in my signature). You can read both amsdos files, or the sector directy. The code is old but it is quite simple to understand to fit your needs.
i neglected to say, i would like it to work in basic. but thanks ill take a look
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: Targhan on 19:29, 18 January 25
Oh, well, if you know a bit of asm, you can make a Call with a few parameters (track, sector, sector count, destination buffer) from Basic and create the small asm code to load the sectors with my code.

However, if calling from Basic, I strongly suggest that you use regular Amsdos files, unless you have a very specific use-case!
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: the777 on 19:58, 18 January 25
Quote from: Targhan on 19:29, 18 January 25Oh, well, if you know a bit of asm, you can make a Call with a few parameters (track, sector, sector count, destination buffer) from Basic and create the small asm code to load the sectors with my code.

However, if calling from Basic, I strongly suggest that you use regular Amsdos files, unless you have a very specific use-case!
ive loaded it into winape and assembled it with no errors. although i cant work out how to call it from basic.
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: Targhan on 20:13, 18 January 25
The CALL command in Basic allows you to pass a number of 16 bits values and get them from Asm. I don't have the structure right now, but you can retrieve these values from asm via a pointer stored in IX+x (Sorry, I don't know x... maybe someone can be more accurate than I am! Or make a search). Anyway, if you don't know ASM it's not going to be easy for you. Also, you must stop the interruptions (DI) in asm, else the Basic is going meddle with the FDC code, which will make all operation fail (don't forget to EI at the end).

However, once again, I suggest you NOT to read straight sectors in Basic. Why do you want to achieve that you couldn't with straight Amsdos files?
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: Targhan on 20:21, 18 January 25
Ah, I just read in the code that:

; - The interruptions are CUT by the loading code.
; - Interruptions are turned on when turning on the FDC, so
;   put #c9fb in #38 before if you don't want your
;   interruptions code to be run at this moment.

So no need to DI/EI. However, you must save what is in #38 after the Basic CALL, and restore it before returning, else the Basic won't be able to continue its work (just like the test code that, line 67, though this is the save only, the restore is not here).
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: the777 on 20:32, 18 January 25
Quote from: Targhan on 20:13, 18 January 25The CALL command in Basic allows you to pass a number of 16 bits values and get them from Asm. I don't have the structure right now, but you can retrieve these values from asm via a pointer stored in IX+x (Sorry, I don't know x... maybe someone can be more accurate than I am! Or make a search). Anyway, if you don't know ASM it's not going to be easy for you. Also, you must stop the interruptions (DI) in asm, else the Basic is going meddle with the FDC code, which will make all operation fail (don't forget to EI at the end).

However, once again, I suggest you NOT to read straight sectors in Basic. Why do you want to achieve that you couldn't with straight Amsdos files?
no as i want to display a map of the disk
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: the777 on 20:35, 18 January 25
Quote from: Targhan on 20:21, 18 January 25Ah, I just read in the code that:

; - The interruptions are CUT by the loading code.
; - Interruptions are turned on when turning on the FDC, so
;  put #c9fb in #38 before if you don't want your
;  interruptions code to be run at this moment.

So no need to DI/EI. However, you must save what is in #38 after the Basic CALL, and restore it before returning, else the Basic won't be able to continue its work (just like the test code that, line 67, though this is the save only, the restore is not here).

 

could you give an example of what i would type in basic? as i dont really understand what #38 means.
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: Targhan on 21:58, 18 January 25
Quotecould you give an example of what i would type in basic? as i dont really understand what #38 means.

Mmmh, you might lacking some knowledge about how Basic works, and probably ASM, which I don't have time to really fill you in right now, so you'll have to make a search to really understand what is going on.

But basically, in ASM, do this, which looks like I did in the test code (but better: I save what I've modified to restore it at the end):
di
ld hl,(#38)
ld (Save38 + 1),hl
ld hl,#c9fb
ld (#38),hl
... read the Basic parameter via IX, and call the LOADSCTS code.

Then, at the end after reading the sector, restore what you have modified:
Save38 ld hl,0
ld (#38),hl
ei
ret

And you should be good to go. The only thing I didn't explain is how you to get the parameter from Basic. Make a search :).
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: BSC on 00:00, 19 January 25
As others have already pointed out, doing it purely in Basic is not possible. But you also don't need to deal with any external programs or even interrupts. Everything you need is already provided by Amsdos. You can find some example code here: https://www.cpcwiki.eu/index.php?title=Programming:Reading_a_sector_from_a_disc

But there's no way around dealing with assembly language, how to modify and assemble the example code so it fits your needs and how to call it from Basic, providing some arguments like track and sector number.

 
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: ZorrO on 00:21, 19 January 25
130 DATA  &21,&37 <read or &38 to write sector,
&80,&cd,&d4,&bc,&22,&34,&80,&79,&32,&36,&80,&1e,&00<drive,&16,&00<track,&0e,&c1<sector,&21,&00-&40 <buffor address 512bytes,&df,&34,&80,&c9,&00,&3c,&c0,&84,&85
140 FOR i=&8000 TO &8038:READ a:POKE i,a:NEXT

It looks rough but someone smart will know what to do with it.
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: Jean-Marie on 01:06, 19 January 25
This short listing (https://www.cpc-power.com/index.php?page=detail&onglet=notices&num=17369) from a greek mag provides a RSX which seems to do the job.

Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: Jean-Marie on 01:55, 19 January 25
This one (https://www.cpc-power.com/index.php?page=detail&onglet=notices&num=5755) looks good too, and is working! Syntax is |RDSECT,0,0,&C1,&8000 to read the first sector in 8000h.
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: the777 on 04:51, 19 January 25
Quote from: Jean-Marie on 01:55, 19 January 25This one (https://www.cpc-power.com/index.php?page=detail&onglet=notices&num=5755) looks good too, and is working! Syntax is |RDSECT,0,0,&C1,&8000 to read the first sector in 8000h.

thank you. ive managed to get them both working. although the code looks different in the disk version
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: McArti0 on 09:49, 01 February 25
Quote from: the777 on 20:35, 18 January 25could you give an example of what i would type in basic?

1 Dr=0: Tr=0: Sec=&41: er%=0
111 DIM hl%(255)
1111 CALL &BFFC,&E9DD,&C9, &B903,&CD00 ,&B90F,&CD00, 0,&100, &12, @er%,&1100, &C03C,&CD00, @hl%(0),&2100, Tr*&100+Dr,&1100, Sec,&100, &B900,&CD00, &B90F,&CD00, 7,&100

For read byte...

333 DEF FNbyte(by%)=PEEK(@hl%(0)+by%)

? FNbyte(123)

Sample fast code:

1 Dr=0: Tr=0: Sec=&41: er%=0
2 DEFINT b,i
111 DIM hl%(255): starthl%=0:i=0:b=0
222 DEF FNbyte(by%)=PEEK(starthl%+by%) : REM risk, all variables must be init.
333 REM DEF FNbyte(by%)=PEEK(@hl%(0)+by%) : REM slower
1000 REM
1111 CALL &BFFC,&E9DD,&C9, &B903,&CD00 ,&B90F,&CD00, 0,&100, &12, @er%,&1100, &C03C,&CD00, @hl%(0),&2100, Tr*&100+Dr,&1100, Sec,&100, &B900,&CD00, &B90F,&CD00, 7,&100
1150 PRINT"Dr:";CHR$(65+Dr);" Tr:";Tr;" Sec:";"&";HEX$(Sec);" Error:";er%:PRINT
1199 IF er%>0 THEN END ELSE t=TIME:starthl%=@hl%(0)
1200 FOR i=0 TO 511 STEP 16
1205 PRINT HEX$(i,3);" | ";
1206 FOR b=0 TO 15
1210 PRINT HEX$(PEEK(starthl%+b+i),2);" ";
1215 NEXT:PRINT"| ";
1216 FOR b=0 TO 15:PRINT CHR$(1);CHR$(PEEK(starthl%+b+i));:NEXT:PRINT
1220 NEXT
1999 PRINT USING"###.#";(TIME-t)/300
2000 END
2222 SAVE"sector2.bas",a
Title: Re: is it possible to read sectors straight off a disk on the 6128 in basic?
Post by: reidrac on 09:55, 01 February 25
hah, wrong post! Ignore me :facepalm:

(can be deleted!)
Powered by SMFPacks Menu Editor Mod