Jump to content



0

Inverting Bytes


40 replies to this topic

#26 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Wed Apr 21, 2004 4:41 PM

I just thought, since in most other languages you set up an array, where as in Asm you just put a bunch of bytes one after another. It seems like less of an array than other languages, and that's why I wasnt sure if it was ok. Thanks for clearing that up.

-J

#27 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Wed Apr 21, 2004 5:08 PM

Ok I'm still really confused why my program doesn't work. It should scroll through the array that I made, with the right side symetrical (but not mirrored) and inverted. From what I can see, the first vertical line of playfeild (which is 10 scanlines high) is working, while the rest are all screwed up. Can anyone tell me what I did wrong? Thanks a bunch!

-J

It won't let me upload a file that's .asm, so here's the code:




	processor 6502

	include "vcs.h"

	include "macro.h"



Scroll  = $80

BlCount  = $81



	SEG

	ORG $F000



Reset



	ldx #0

	lda #0



Clear

	sta 0,x

	inx

	bne Clear



	lda #$84

	sta COLUPF



	lda #$04

	sta COLUBK



	lda #%00000000

	sta CTRLPF



	lda #%11111111

	sta PF0



Frame



	lda #0

	sta VBLANK



	lda #2

	sta VSYNC



	sta WSYNC

	sta WSYNC

	sta WSYNC



	lda #0

	sta VSYNC



	ldx #37

TopBlank

	sta WSYNC

	dex

	bne TopBlank



	ldx #0



Pic



	lda #0

	sta BlCount



Block



	sta WSYNC



	ldy Scroll,x



	lda LData1,y

	sta PF1



	lda LData2,y

	sta PF2



	inc BlCount

	ldy BlCount



	Sleep 12



	lda LData1,y

	EOR #$FF

	sta PF1



	lda LData2,y

	EOR #$FF

	sta PF2



	cpy #10

	bne Block



	inx

	cpx #20

	bne Pic



	ldy Scroll

	cpy #180

	bne NoReset

	lda #0

	sta Scroll



NoReset



	inc Scroll



	lda #%01000010

	sta VBLANK



	ldx #30

Overscan

	sta WSYNC

	dex

	bne Overscan



	jmp Frame



LData1

        .byte #%00000000

        .byte #%00000000

        .byte #%00000001

        .byte #%00000010

        .byte #%00000100

        .byte #%00001000

        .byte #%00001000

        .byte #%00010000

        .byte #%00010000

        .byte #%00010000

        .byte #%00100000

        .byte #%00100000

        .byte #%00100000

        .byte #%00100000

        .byte #%00010000

        .byte #%00010000

        .byte #%00001000

        .byte #%00000100

        .byte #%00000011

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000001

        .byte #%00000001

        .byte #%00000010

        .byte #%00000010

        .byte #%00000100

        .byte #%00000100

        .byte #%00001000

        .byte #%00001000

        .byte #%00001000

        .byte #%00001000

        .byte #%00000100

        .byte #%00000100

        .byte #%00000010

        .byte #%00000001

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000001

        .byte #%00000010

        .byte #%00000100

        .byte #%00001000

        .byte #%00010000

        .byte #%00010000

        .byte #%00100000

        .byte #%00100000

        .byte #%01000000

        .byte #%01000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%01000000

        .byte #%01000000

        .byte #%01000000

        .byte #%00100000

        .byte #%00100000

        .byte #%00010000

        .byte #%00001000

        .byte #%00000100

        .byte #%00000100

        .byte #%00000010

        .byte #%00000010

        .byte #%00000001

        .byte #%00000001

        .byte #%00000001

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000001

        .byte #%00000001

        .byte #%00000001

        .byte #%00000010

        .byte #%00000010

        .byte #%00000010

        .byte #%00000100

        .byte #%00000100

        .byte #%00001000

        .byte #%00001000

        .byte #%00010000

        .byte #%00010000

        .byte #%00100000

        .byte #%00100000

        .byte #%01000000

        .byte #%01000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%01000000

        .byte #%01000000

        .byte #%01000000

        .byte #%01000000

        .byte #%01000100

        .byte #%10001100

        .byte #%10011100

        .byte #%10011100

        .byte #%10111100

        .byte #%00111000

        .byte #%01111000

        .byte #%01111000

        .byte #%01111000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11100000

        .byte #%11100000

        .byte #%11100000

        .byte #%11100000

        .byte #%11000000

        .byte #%11000000

        .byte #%11000000

        .byte #%11000000

        .byte #%01000000

        .byte #%01000000

        .byte #%01000000

        .byte #%00100000

        .byte #%00100000

        .byte #%00100000

        .byte #%11000000

        .byte #%11000000

        .byte #%11000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%10000000

        .byte #%10000000

        .byte #%10000000

        .byte #%11000000

        .byte #%11000000

        .byte #%11000000

        .byte #%11100000

        .byte #%11100000

        .byte #%11100000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000

        .byte #%11110000



LData2

        .byte #%00000001

        .byte #%00000001

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000011

        .byte #%00000100

        .byte #%00001000

        .byte #%00010000

        .byte #%00010000

        .byte #%00100000

        .byte #%00100000

        .byte #%01000000

        .byte #%01000000

        .byte #%01000000

        .byte #%01000000

        .byte #%00100000

        .byte #%00100000

        .byte #%00010000

        .byte #%00010000

        .byte #%00001000

        .byte #%00000100

        .byte #%00000010

        .byte #%00000001

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000001

        .byte #%00000001

        .byte #%00000010

        .byte #%00000010

        .byte #%00000010

        .byte #%00000001

        .byte #%00000001

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000001

        .byte #%00000001

        .byte #%00000001

        .byte #%00000001

        .byte #%00000001

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%10000000

        .byte #%11000000

        .byte #%11000000

        .byte #%11000000

        .byte #%11000000

        .byte #%11000000

        .byte #%10000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000

        .byte #%00000000





	ORG $FFFA



	.word Reset

	.word Reset

	.word Reset



END

Remember I'm still a newbie, so don't make fun of my crappy code! :D

#28 EricBall OFFLINE  

EricBall

    Dragonstomper

  • 711 posts
  • Location:Markham, Ontario, Canada

Posted Wed Apr 21, 2004 8:49 PM

Quote

As all Real Programmers know, the only useful data structure is the Array. Strings, Lists, Structures, Sets-- these are all special cases of arrays and can be treated that way just as easily without messing up your programming language with all sorts of complications.

No, there are no data structures; only data stored in memory. How the program choses to interpret that data is up to the programmer.

Of course, you could get even more literal and talk about bits or electrical signals, but some degree of abstraction and equivalence is necessary to stay sane.

#29 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Thu Apr 22, 2004 1:32 AM

So does anyone see the error in my source code? I'm still stuck.

-J

#30 Cybergoth ONLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Thu Apr 22, 2004 2:35 AM

Hi there!

Jedd said:

So does anyone see the error in my source code?  I'm still stuck.

Replacing

ldy Scroll,x

with

ldy Scroll

might do the trick.

Greetings,
Manuel

#31 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Thu Apr 22, 2004 10:42 AM

:( That didn't work either. What that line is doing is taking the location of the original starting byte of the playfeild data for that screen, and adds it to the scanline (actually, the vertical pixel) for that screen and loads it into x. Then it looks up the byte at that location for PF1 and PF2. Without the ,x , it would look up the same byte of PF information for each scanline of the screen, making the screen always have vertical lines.

I was thinking maybe I have too many 6502 cycles going on, so maybe the lines are falling into the next line, and the data is overlapping the other scanlines. I counted the # of cycles and it looked like it made it, does anyone else see an error there?

-J

#32 Cybergoth ONLINE  

Cybergoth

    Quadrunner

  • 8,207 posts
  • This is Sparta!
  • Location:Bavaria

Posted Thu Apr 22, 2004 10:51 AM

Hi there!

Jedd said:

What that line is doing is taking the location of the original starting byte of the playfeild data for that screen, and adds it to the scanline (actually, the vertical pixel) for that screen and loads it into x.

No. What that line is doing is reading different RAM values into Y, depending on X. First it reads from $80, then from $81 and so on, until with X = $20 you're reading from $A0. Then you're resetting X to zero thus starting all over reading from $80 again.

Greetings,
Manuel

#33 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Thu Apr 22, 2004 11:10 AM

Also you should load your scroll offset outside of the display loop.
But like always I'm brining up a non-critical issue ;)

#34 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Thu Apr 22, 2004 11:40 AM

Happy_Dude said:

Also you should load your scroll offset outside of the display loop.
But like always I'm brining up a non-critical issue ;)

So, before sta WSYNC? Because I had it that way before, then I realized I might as well put it in since I'm having the 6502 sleep for a while anyway.

I still can't get it to work! I think I'm going to just start over and completely re-write the code.

-J

#35 Happy_Dude OFFLINE  

Happy_Dude

    River Patroller

  • 4,208 posts
  • Forum Slacker
  • Location:Sydney, Australia

Posted Thu Apr 22, 2004 12:05 PM

Before Block
The Y index isn't changed during the block display loop.
It doesn't hurt how it is I guess. Like I said, non-critical :P

#36 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Sun May 9, 2004 11:00 PM

I got frustrated and left Atari programming for a few weeks, but today I was bored so I re-coded my scrolling program. Unfortunately it still does not work. Here are the guts of my program:

;192 lines of picture



	ldx #0

	stx Scanline



	inc Scroll



	sta WSYNC



Pic



	inc Scanline



	ldx Scanline

	ldy Scroll,x



	lda PFData0,y

	sta PF0

	lda PFData1,y

	sta PF1

	lda PFData2,y

	sta PF2



	ldx #0

	stx Skip8



Block

	sta WSYNC

	inc Skip8

	ldx Skip8

	cpx #10

	bne Block



	ldx Scanline

	cpx #19

	bne Pic


;End lines of picture

Or you can download the whole thing here.

From what I can see it should work. Scroll and Scanline are both increasing the way they should be. Scroll increases once every frame, Scanline increases once every 10 scanlines. But for some reason when they are added together, you get 0. Can anyone pleeeeeease tell me why it doesn't work?

-J

#37 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Mon May 10, 2004 2:06 AM

  ldx Scanline 

  ldy Scroll,x
Here is your problem. Ldy Scroll,x does not add Scanline and Scroll, but it loads the content of the memory Scroll + Scanline points to into y.

What you probably want is:

  lda Scanline 

  clc

  adc Scroll

  tay


#38 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Mon May 10, 2004 8:28 AM

Awesome thankyou! It scrolls beautifully. Just so I know what is going on, can someone please explain what clc and adc do?

-J

#39 Sean M. OFFLINE  

Sean M.

    Combat Commando

  • 2 posts

Posted Mon May 10, 2004 11:11 AM

How's it hangin' Jedd?

CLC
Clears the carry flag. By "clear" I mean "make it zero".

ADC
Adds the operand to the acc, then adds in the carry flag.

So, having a CLC ADC combo does a simple ADD, assuming the 6502 has an ADD instruction, which it doesn't (MOS-Tek were a bunch of cheap SOB's :).

You really ought to know basic stuff like this...

#40 Bruce Tomlin OFFLINE  

Bruce Tomlin

    River Patroller

  • 3,531 posts
  • CD C9 01
  • Location:Austin, TX

Posted Mon May 10, 2004 11:29 AM

Just for the record here: MOS Technology != MOSTEK

MOS Technology were the 6502 creators who were bought out by Commdore in 1976.

http://www.antiquete...mpanies/MOS.htm

#41 Jedd OFFLINE  

Jedd

    Star Raider

  • 68 posts
  • Location:Cali

Posted Mon May 10, 2004 4:27 PM

Sean M. said:

You really ought to know basic stuff like this...

I've been doing this for a little over a month. :D Thanks for the help!

-J




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users