[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with machine code



Hi,
I stumbled upon a machine language routine to access disks via RWTS.  It
loads at $2000 with the IOB at $2008.  I was getting annoyed with delays
when reading entire tracks from Applesoft as I had to peek in new sector
values and such which was slowing it down so I wanted to take a crack at
writing a machine language routine to read one entire track in one
operation.  From what I am able to do it appears to be much faster but
there's a problem.  Aparently the BNE instruction will branch one cycle too
soon.  Here's the code, with comments between most lines.

First some S-C Macro Assembler stuff

1000  .LIST OFF
1010  .OR $0300
1020  .TA $0300
1030  .TF TRACK
1040  LDX #$0F

This loads the value $0f (15 decimal) into the X register.  That's the last
sector on a track.  We'll use this later.

1060 DISK STX $200D

This stores the X register at $200d, where the RWTS calling subroutine
expects the sector number.  The DISK label is put there so we can jump back
here which we will do later.

1070  JSR $2000

This calls the subroutine which sets up and calls RWTS.

1080  LDY $2011

Loads the Y register from $2011.  This address contains the page number of
the location in memory where RWTS will store the read data.

1090  INY

Well, when preparing for the next read we need to put the new data somewhere
else.  So we increment the Y register.
1100  STY $2011

Ok, now we store the Y register back at $2011.

1110  LDX $200D

Load up the X register from $200D, which still has the sector number we just
read.

1120  DEX

Decrement X.

1130  BNE DISK

Branch back to the DISK label to read another sector.

1140  RTS

End the whole thing.

The problem with this routine is that it only reads fifteen sectors, not
sixteen.  The BNE aparently is falling through when X reaches 1, not 0.  Any
thoughts on how to solve this, or a better way to write such a routine?
Thanks.
Jayson.