Need help with an incrementing 16-bit pointer
Re: Need help with an incrementing 16-bit pointer
I've become the maintainer of Nick's easy6502. It has a very rough-and-ready approach to parsing, which isn't as fully featured as one might want, and really needs a rework. I did take a different approach in my fork as posted over here:
65Org16 and 65Org32 emulation online
As a maintainer, I am being very slack indeed about working on the code. It would be great if someone with more energy and skills could join in. But I would very much want to keep the tutorial and the existing examples working as they are.
65Org16 and 65Org32 emulation online
As a maintainer, I am being very slack indeed about working on the code. It would be great if someone with more energy and skills could join in. But I would very much want to keep the tutorial and the existing examples working as they are.
-
EvilSandwich
- Posts: 36
- Joined: 13 Oct 2019
- Location: Pennsylvania, USA
Re: Need help with an incrementing 16-bit pointer
barrym95838 wrote:
EvilSandwich wrote:
That's actually very close to my first version of the code. The only reason I abandoned it was because the "Top to Bottom" fill was a specific effect that I was going for and this will fill the four horizontal sections at the same time.
I have never heard of a symbolic assembler that didn't allow + or - in its operands. That would be a crippling omission IMO.
One thing I'm starting to learn very quickly is that all assemblers are slightly unique and all have their little quirks that can throw me for a loop if I'm used to using another assembler. Labels in particular are never defined the same way, I've noticed.
I've seen
Code: Select all
THIS = $01
THAT equ $01
and
Define THING $01BigEd wrote:
I've become the maintainer of Nick's easy6502. It has a very rough-and-ready approach to parsing, which isn't as fully featured as one might want, and really needs a rework. I did take a different approach in my fork as posted over here:
65Org16 and 65Org32 emulation online
As a maintainer, I am being very slack indeed about working on the code. It would be great if someone with more energy and skills could join in. But I would very much want to keep the tutorial and the existing examples working as they are.
65Org16 and 65Org32 emulation online
As a maintainer, I am being very slack indeed about working on the code. It would be great if someone with more energy and skills could join in. But I would very much want to keep the tutorial and the existing examples working as they are.
Its half the reason I haven't gotten completely overwhelmed.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Need help with an incrementing 16-bit pointer
EvilSandwich wrote:
barrym95838 wrote:
I have never heard of a symbolic assembler that didn't allow + or - in its operands. That would be a crippling omission IMO.
Code: Select all
LDA #{expression_of_some_kind}and the expression could use whatever operators the assembler recognizes, and the only limitation is line length, often 256 characters. You might have the ANDing of constants (or numbers which can be changed in the assembler, like an EQUate that can be changed many times), shifting, XORing, addition, etc.. The LDA# always results in an $A9 op code being laid down, and its operand byte gets figured out by the assembler and laid down after the op code. The 6502 computer that runs the program has no interest in how the assembler arrived at that operand byte, or what it means.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: Need help with an incrementing 16-bit pointer
EvilSandwich wrote:
Holy crap, do you have any idea how helpful the Easy6502 assembler is? It's been invaluable in helping me figure out the bare basics. As long as it can read and run all the opcodes, I can always work around the bare bone assembler quirks.
Its half the reason I haven't gotten completely overwhelmed.
-
EvilSandwich
- Posts: 36
- Joined: 13 Oct 2019
- Location: Pennsylvania, USA
Re: Need help with an incrementing 16-bit pointer
I think the most frustrating part about all this is that I actually managed to make it work before with an older and way cruder version of the subroutine. But for some reason, I can't seem to recreate it.
This program works like a dream exactly the way I designed it too.
The second version of the clearscreen subroutine for the above confetti program that im working on right now. This one is a nonfunctional brick:
But yeah, I can get the pointer to increment in a million different ways, but that's not really the issue. I just can't get the program to read the silly thing from the zero page. :/
As you can see, I've been playing around with keyboard inputs and randomization in this program too. $00FE randomizes to a new value every clock cycle by the virtual hardware and $00FF's value is the ASCII value of the last keystroke.
If one of you way more experienced guys can tell me the silly and obvious thing I'm overlooking to get it to read the pointer, I'm all ears. lol
EDIT:
Note that both counters work just fine, but I can't seem to read the second one at all.
This program works like a dream exactly the way I designed it too.
Code: Select all
idle: ;Waiting for input
;Press W to Pop Confetti Forever!
;Press O to Pop Confetti Just Once
;Press S to Pause Confetti
;Press Q to End Program
LDA $ff ;reading last keystroke
CMP #$71 ;If Q, End Program
BEQ end
CMP #$53
BEQ idle
CMP #$6f
BEQ poponce
CMP #$77 ;If W, Pop Confetti! Yay! :D
BEQ poprepeat
JMP idle ;If no input, continue idle
poponce:
LDA #$00 ;clearing last keystroke
STA $ff
JMP clearscreen ;cleaning up old confetti
poprepeat: ;prepping program for confetti
JMP clearscreen ;cleaning up old confetti
finish: ;ending program
JMP end
clearscreen: ;clearing screen for new confetti
LDX #$00 ;initial values and start
LDY #$01
STX $01
STY $02
incrementhigh: ;increment high byte
LDX $02 ;checking if finished
CPX #$05
BEQ boom ;pop confetti!
INC $02 ;increment high byte
LDX #$00 ;returning low byte to 0
STX $01
incrementlow: ;increment low byte
LDA #$00 ;define floor color
STA ($01,X) ;sweep pixel
INC $01 ;increment low byte
LDY $01 ;load low byte counter
CPY #$00 ;check low counter to see
;if high byte needs to be
;incremented
;otherwise increment low byte
BEQ incrementhigh
BNE incrementlow
boom: ;Yay! Party Time! :D :D :D
loop: ;main confetti loop
LDX $fe ;load random colors and locations
LDA $fe
STA $0200,x ;POP!
LDX $fe
LDA $fe
STA $0300,x ;POP!
LDX $fe
LDA $fe
STA $0400,x ;POP!
LDX $fe
LDA $fe
STA $0500,x ;POP! Yay! All done!
INY ;count confetti
CPY #$20 ;make sure you have
;32 x 4 confetti pieces
BNE loop ;if not enough,
;restart confetti loop
JMP idle ;else return to idle
;and wait for input
end:
BRK
Code: Select all
LDA #$01 ;Initial values
LDX #$00
LDY #$02
STX $00 ;low byte
STY $01 ;high byte
mainloop: ;placeholder program loop
JSR counter ;increment pointer
LDA #$00 ;define floor color
STA ($01,X) ;sweep pixel
LDY $01 ;checking high byte
CPY #$05
BNE mainloop ;loop again
LDX $00 ;checking low byte
CPX #$ff
BNE mainloop ;loop again
BRK ;when value is 05ff, end
counter: ;incrementing subroutine
l_up: ;increment low byte
LDX $00
INC $00
CPX #$ff ;check if high byte needs to be incremented
BEQ h_up
RTS ;if not, return to main loop
h_up: ;increment high byte and return to main loop
INC $01
RTSAs you can see, I've been playing around with keyboard inputs and randomization in this program too. $00FE randomizes to a new value every clock cycle by the virtual hardware and $00FF's value is the ASCII value of the last keystroke.
If one of you way more experienced guys can tell me the silly and obvious thing I'm overlooking to get it to read the pointer, I'm all ears. lol
EDIT:
Note that both counters work just fine, but I can't seem to read the second one at all.
Re: Need help with an incrementing 16-bit pointer
This jumps out:
What's the value in X at this point?
Code: Select all
STA ($01,X) ;sweep pixel
-
EvilSandwich
- Posts: 36
- Joined: 13 Oct 2019
- Location: Pennsylvania, USA
Re: Need help with an incrementing 16-bit pointer
BigEd wrote:
This jumps out:
What's the value in X at this point?
Code: Select all
STA ($01,X) ;sweep pixel
EDIT: Whoops double post. Sorry.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Need help with an incrementing 16-bit pointer
Remember what I said on the last page, at viewtopic.php?p=70660#p70660 . Your "counter" subroutine can leave different values in X, and in your instruction "STA ($01,X)", the X value will get added to the number $01 to get the ZP address to read another address from, and you'll store to that final resulting address.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
-
EvilSandwich
- Posts: 36
- Joined: 13 Oct 2019
- Location: Pennsylvania, USA
Re: Need help with an incrementing 16-bit pointer
GARTHWILSON wrote:
Remember what I said on the last page, at viewtopic.php?p=70660#p70660 . Your "counter" subroutine can leave different values in X, and the value will get added to the number $01 to get the ZP address to read another address from, and you'll store to that final resulting address.
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Need help with an incrementing 16-bit pointer
EvilSandwich wrote:
So I accidentally made the value of X not equal to the Low Byte in the second version?
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
-
EvilSandwich
- Posts: 36
- Joined: 13 Oct 2019
- Location: Pennsylvania, USA
Re: Need help with an incrementing 16-bit pointer
I was in the middle of stepping through my code with a debugger and found what you just said. I feel foolish now.
So I guess the better question is not "Why isn't the second one working?" and actually "Why did the first one work?"
So I guess the better question is not "Why isn't the second one working?" and actually "Why did the first one work?"
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Need help with an incrementing 16-bit pointer
You really need to get the 6502/65816 programmer's manual "Programming the 65816—Including the 6502, 65C02 and 65802" by David Eyes and Ron Lichty. It thoroughly diagrams every addressing mode, to clear up this confusion.
It is definitely the best 65xx programming manual available, and a must-have for every 65xx programmer! It starts with the basics, followed by architecture, the CMOS 65c02's many improvements over the original NMOS 6502 including added instructions and addressing modes and fixing the NMOS's bugs and quirks, and then the natural progression to the 65816; a thorough tutorial, writing applications, then very detailed and diagrammed information on all 34 addressing modes, at least a page of very detailed description for each instruction, with info on every addressing mode available for that instruction, then instruction lists, tables, and groups, of all 255 active op codes, plus more. 469 pages. From Western Design Center. (.pdf) Note: There were many problems with the earlier .pdf version that were not in the original paper manual; but in late March 2015, WDC scanned and OCR'ed the paper manual and posted the new, repaired .pdf.
It is definitely the best 65xx programming manual available, and a must-have for every 65xx programmer! It starts with the basics, followed by architecture, the CMOS 65c02's many improvements over the original NMOS 6502 including added instructions and addressing modes and fixing the NMOS's bugs and quirks, and then the natural progression to the 65816; a thorough tutorial, writing applications, then very detailed and diagrammed information on all 34 addressing modes, at least a page of very detailed description for each instruction, with info on every addressing mode available for that instruction, then instruction lists, tables, and groups, of all 255 active op codes, plus more. 469 pages. From Western Design Center. (.pdf) Note: There were many problems with the earlier .pdf version that were not in the original paper manual; but in late March 2015, WDC scanned and OCR'ed the paper manual and posted the new, repaired .pdf.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
-
EvilSandwich
- Posts: 36
- Joined: 13 Oct 2019
- Location: Pennsylvania, USA
Re: Need help with an incrementing 16-bit pointer
Can I just say that Western Design Center seems to keep proving again and again how awesome they are? lol
Re: Need help with an incrementing 16-bit pointer
In the first version of the code, X is always zero, which is what you want, as your 16 bit pointer is in 0001 and 0002.
If you use STX ($01, X) with a non-zero value of X, you are using a pointer that's somewhere different from 0001 and 0002, because X is an index into zero page.
It sounds like you might be thinking of a mode ($01), X - which doesn't exist. In that case, the pointer is always at 0001 and 0002, but the value of X is added. In that case, you have some freedom as to whether you increment the low byte of the pointer, or X, because the two will be added together. But as this mode doesn't exist, you can't be doing that. The mode does exist with Y, but you should be aiming to understand the addressing mode you are using, not one that you're not.
If you use STX ($01, X) with a non-zero value of X, you are using a pointer that's somewhere different from 0001 and 0002, because X is an index into zero page.
It sounds like you might be thinking of a mode ($01), X - which doesn't exist. In that case, the pointer is always at 0001 and 0002, but the value of X is added. In that case, you have some freedom as to whether you increment the low byte of the pointer, or X, because the two will be added together. But as this mode doesn't exist, you can't be doing that. The mode does exist with Y, but you should be aiming to understand the addressing mode you are using, not one that you're not.
-
EvilSandwich
- Posts: 36
- Joined: 13 Oct 2019
- Location: Pennsylvania, USA
Re: Need help with an incrementing 16-bit pointer
BigEd wrote:
In the first version of the code, X is always zero, which is what you want, as your 16 bit pointer is in 0001 and 0002.
If you use STX ($01, X) with a non-zero value of X, you are using a pointer that's somewhere different from 0001 and 0002, because X is an index into zero page.
It sounds like you might be thinking of a mode ($01), X - which doesn't exist. In that case, the pointer is always at 0001 and 0002, but the value of X is added. In that case, you have some freedom as to whether you increment the low byte of the pointer, or X, because the two will be added together. But as this mode doesn't exist, you can't be doing that. The mode does exist with Y, but you should be aiming to understand the addressing mode you are using, not one that you're not.
If you use STX ($01, X) with a non-zero value of X, you are using a pointer that's somewhere different from 0001 and 0002, because X is an index into zero page.
It sounds like you might be thinking of a mode ($01), X - which doesn't exist. In that case, the pointer is always at 0001 and 0002, but the value of X is added. In that case, you have some freedom as to whether you increment the low byte of the pointer, or X, because the two will be added together. But as this mode doesn't exist, you can't be doing that. The mode does exist with Y, but you should be aiming to understand the addressing mode you are using, not one that you're not.
So I want to keep X equal to 0?