[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Wrong Value From Two Bytes -- Encoding
On Sat, 15 Feb 2003, Bryan Parkoff wrote:
> Date: Sat, 15 Feb 2003 02:28:10 -0600
> From: Bryan Parkoff <BParkoff@satx.rr.com>
> Newsgroups: comp.sys.apple2
> Subject: Wrong Value From Two Bytes -- Encoding
>
> Previous newsgroups show incorrect value. For example, you put value
> #C1 before #C1 goes into EA and EB. If you want to restore from two bytes
> into one byte, you will get value #C0 instead of #C1. It is not correct.
> Please take a look at your code below and try to figure out why.
>
> LDA #0
> loop: STA $27
> wait1: LDA $c08c,x
> BPL wait1
> ROL ; shift value to the left
> STA $26
> wait2: LDA $c08c,x
> BPL wait2
> AND $26; and value
> STA $002c,y
> EOR $27; check"sum" (i.e. checkeor :-) )
> DEY
> BPL loop
>
Hi,
The answer is quite simple: there is something missing. :-(
Before this code is executed, the sector header field is read, at which end
the following instructions are executed:
waitfor96: LDA $c08c,x
BPL waitfor96
CMP #$96
BNE waitford5
After this, the carry bit is set, because the value, of course, must have
been $96. Comparing the accumulator with its value will always set the bit.
This is the reason why you do not find a special "SEC" instruction here,
although it is necessary for the code to have the carry bit set. Further
below, the ROL instruction needs this carry bit to shift the value 1 into
the lowest bit of the accumulator. Otherwise the AND instruction afterwards
will fail to give the right result.
So, please, add some kind of command to your program which will somehow set
the carry bit and it should run fine. (BTW.: The code shown here is directly
taken from DOS 3.3 ($b964), so it really should work, shouldn't it? ;-) )
Kind regards
Holger
>
> On Thu, 19 Dec 2002, Bryan Parkoff wrote:
>
> > Date: Thu, 19 Dec 2002 22:49:07 -0600
> > From: Bryan Parkoff <BParkoff@satx.rr.com>
> > Newsgroups: comp.sys.apple2
> > Subject: 4-4 Format for GCR Question
> >
> > 4-4 Format for GCR Question
> >
> > I know how to use ASL and AND opcode to put two bytes into one byte.
> >
> > For example:
> >
> > c0 c1 c1 c0
> > c1 c1 c1 c0
> >
> > With ASL
> >
> > 0c 1c 1c 0c
> > c1 c1 c1 c0
> >
> > With AND
> >
> > 01111100
> >
> > It is how I can see above. My question is -- How can I add '1' to
> each
> > bit before one byte can become two bytes? Which instruction (opcode) do I
> > use? Please advise.
> >
> > --
> > Yours Truly,
> >
> > Bryan Parkoff
> > BParkoff@satx.rr.com
> >
> Hi,
>
> sorry, I'm not sure what you mean. Are you referring to the odd even format?
> If not, don't read the following. :-)
>
> DOS 3.3 uses the odd even format to store the sector information in the
> sector header (track, sector etc). At address $b96d it reads (Y = 3):
> LDA #0
> loop: STA $27
> wait1: LDA $c08c,x
> BPL wait1
> ROL ; shift value to the left
> STA $26
> wait2: LDA $c08c,x
> BPL wait2
> AND $26; and value
> STA $002c,y
> EOR $27; check"sum" (i.e. checkeor :-) )
> DEY
> BPL loop
>
> Shift and AND as you've written.
>
> Writing is done at address $bcc4 (A = byte):
>
> PHA ; put byte on stack
> LSR ; first shift bits to the right
> ORA $3e; $3e contains the value #$aa (s.b.)
> STA $c08d,x; write to latch
> CMP $c08c,x; write byte
> PLA ; restore byte
> NOP ; time delay
> NOP
> NOP
> ORA #$aa; this is probably what you were looking for
> NOP ; time delay
> NOP
> PHA
> PLA
> STA $c08d,x; write to latch
> CMP $c08c,x; write byte
> RTS
>
> Hope, this helps.
>
> Holger
>
>
> --
> Yours Truly,
>
> Bryan Parkoff
> BParkoff@satx.rr.com
>
>
>