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

Re: Mental challenge: the rainbow



On 6 feb, 20:57, mmphosis <mmpho...@yahoo.com> wrote:
> On Feb 5, 7:25 pm, "Marc S. Ressl" <mre...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > Hello everyone,
>
> > This code was posted by mmphosis at comp.sys.apple2.programmer:
>
> >  10 A = 9200
> >  20 B = 13136 + 32
> >  30 C = 100
> >  40  TEXT : HOME
> >  50 DATA 173,87,192,173,83,192,173,84,192,173,80,192,208,251
> >  55 DATA 173,86,192,160,22,136,208,253,234,173,87,192,76,9,3
> >  60  FOR I = 768 TO 796
> >  70  READ N: POKE I,N
> >  80  NEXT
> >  100  HGR : POKE  - 16302,0
> >  110  HCOLOR= 4
> >  120  HPLOT 0,0: CALL 62454
> >  130  HCOLOR= 2
> >  140  HPLOT 0,63 TO 279,63
> >  150  HPLOT 0,62 TO 279,62
> >  160  HCOLOR= 6
> >  170  HPLOT 0,61 TO 279,61
> >  180  HPLOT 0,60 TO 279,60
> >  190  HCOLOR= 1
> >  200  HPLOT 0,59 TO 279,59
> >  210  HPLOT 0,58 TO 279,58
> >  220  HCOLOR= 5
> >  230  HPLOT 0,55 TO 279,55
> >  240  HPLOT 0,54 TO 279,54
> >  250  HCOLOR= 0
> >  260  HPLOT 0,123 TO C,123
> >  261  HPLOT 0,122 TO C,122
> >  262  HPLOT 0,119 TO C,119
> >  263  HPLOT 0,118 TO C,118
> >  270  COLOR= 0
> >  280  FOR I = 0 TO 39
> >  290  VLIN 0,39 AT I
> >  300  NEXT
> >  310  COLOR= 13
> >  320  HLIN 0,39 AT 14
> >  330  FOR I = 0 TO 7
> >  340  POKE A + I,0
> >  345  POKE B + I,0
> >  350  NEXT
> >  360  COLOR= 1
> >  370  HLIN 0,39 AT 13
> >  380  VTAB 21
> >  390  PRINT  TAB( 16)"RAINBOW"
> >  400  PRINT : PRINT "MIXED GRAPHICS (HI-RES/COLOR)"
> >  500  CALL 768
>
> > I've re-factorized the timing code in OpenEmulator, and the rainbow is
> > showing. My problem is the "special" lines are flickering at the
> > beginning.
>
> > I have checked the code, and it seems it should be flickering (the
> > loop waits for a non-zero byte on the floating bus), but could
> > somebody with a real Apple II or II plus check?
>
> > Thanks a lot,
>
> > Marc.-
>
> From memory, a long long time ago, when I ran this on a real Apple II
> plus, it would *usually* (emphasis on usually) display the rainbow
> without any flickering.  But, I think that sometimes, if my memory
> serves me, it would flicker.  It could be a timing thing:  The code
> waits for a non-zero byte on the floating bus and it can only catch a
> byte every amount of cycles that the loop takes to iterate.  The
> positioning of those zero bytes is critical.  Maybe, sometimes it
> misses depending on what byte it starts reading the floating bus at,
> whereas *usually* (mmphosis on usually) it starts reading at a byte
> where everything aligns and the rainbow appears without flickering.
>
> mmphosis

Hello mmphosis:

thanks a lot for your response! I am very intrigued by this test, as
it seems excellent for testing emulators. So I went through it...

As to the BASIC part:

* BASIC Lines 110-120 fill $2000-$3FFF with $80
* BASIC Lines 130-240 draw the HIRES color lines 54-55, 58-59, 60-61,
62-63
* BASIC Lines 250-263 fill lines 118, 119, 122 and 123 with color 0
for X = 0 to 100 (this hides the delayed extensions of lines 54-63)
* BASIC Lines 330-350 fill $23F0-$23F7 and $3370-$3377 with $00 (this
is the important stuff)

* BASIC Lines 270-300 clear the text screen to $00
* BASIC Lines 360-380 draw the LORES line at Y=13 (HIRES lines 52-55)
* BASIC Lines 310-320 draw the LORES line at Y=14 (HIRES lines 56-59)

As to the assembly part:

0300-   AD 57 C0    LDA   $C057     // set HIRES
0303-   AD 53 C0    LDA   $C053     // set MIXED
0306-   AD 54 C0    LDA   $C054     // clear PAGE2

0309-   AD 50 C0    LDA   $C050     // read /TEXT, 4 cycles
030C-   D0 FB       BNE   $0309     // 3 cycles
030E-   AD 56 C0    LDA   $C056     // set LORES, 4 cycles
0311-   A0 16       LDY   #$16      // 2 cycles
0313-   88          DEY             // 2 cycles
0314-   D0 FD       BNE   $0313     // 3 cycles
0316-   EA          NOP             // 2 cycles
0317-   AD 57 C0    LDA   $C057     // set HIRES, 4 cycles
031A-   4C 09 03    JMP   $0309     // 3 cycles

The first loop searches for a zero value while scanning HIRES. This
happens on several occasions, but most importantly just before lines
51 and 55 (because of horizontal blanking).

When the first loop exits, LORES is switched on for 4+2+5*22+2 = 118
CPU cycles. This happens to be almost two scan lines (each scan line
has 65 CPU cycles).

I must confess this is pretty clever, and it also seems my emulator
has a bug :-).

With the best wishes,

Marc.-