Jump to content
IGNORED

Another simple problem.


wallaby

Recommended Posts

you keep saying "WORKS" but you don't say what it works for or what you're trying to do

 

you don't say what playerpointers is, but assuming you mean either of player0pointer or player1pointer,

if playerpointers is player0pointer that will end up with the address of player1pointer in a

the address of player1pointer is the address of player0pointer + 2

if playerpointers is player1pointer you'll end up with the address of player0height in a

(in the standard kernel)

Edited by bogax
Link to comment
Share on other sites

The < takes the LOW BYTE of a 16 bit value. Likewise the > takes the HIGH BYTE. What that means is if playerpointers has a value of $1234 then:

  • <playerpointers = $34
  • >playerpointers = $12
The problem* you're having is for assembly code math like this:

LDA #<(playerpointers+temp1)

occurs at compile time, not when your code runs. For an example of what's going on, looking in 2600basic.h I see these definitions (the ones for bB DPC+ are probably different, but the concept is the same)

 

player0pointer = $8A ;uses $8A-$8B
...
temp1 = $9C ;used by kernel.  can be used in program too, but

The instruction:

LDA #<(player0pointer+temp1)

is compiled like this by dasm:

LDA #<(player0pointer+temp1)

LDA #<($8A+$9C)

LDA #<($126)

LDA #$26

add a variable value to playerpointers like this:

; assuming temp1 holds the variable value to add
  clc
  lda temp1
  adc #<playerpointers
  sta RESULT

playerpointers is most likely a 16 bit value, the above only correctly handles the addition if you're working with an 8 bit value. For 16 bit math you'd do this:

; assuming temp1 holds the variable value to add
  clc
  lda temp1
  adc #<playerpointers
  sta LOW_BYTE_OF_RESULT 
  lda #0
  adc #>playerpointers
  sta HIGH_BYTE_OF_RESULT

The _OF_RESULT values are wherever you need the values to go to.

 

* you also have # and < reversed from normal convention, though dasm appears to correctly handle it in either order.

Link to comment
Share on other sites



I would add two points to what Spiceware said


you don't actually need asm to do any of that you can do it in bB

if you just can't figure out how to do it in bB it's not necessary to resort to asm

you can certainly do a better job of it with asm than bB would do

so if you just want to learn some asm more power to you


if playerpointers is meant to be a table of pointers into sprite data

the more usual way, the facility built into the processor for that, is to

use an index register


and since the index register is 8 bits (in this case) you'd only have to deal with one byte

even though the addresses are two bytes the upper byte doesn't change


with indexing you supply an address, whatever is in the index register gets added to it and

the result is used as the address




; table of pointers to individual sprites in a table of sprite data

data playerpointers
locationofsprite0, locationofsprite1, locationofsprite2, etc
end

; table of sprite data sprites are 8 bytes

data spritedata
%00111100 ; locationofsprite0 = spritedata, a 16 bit address
%01111110
%11000011
%11000011
%11000011
%11000011
%01111110
%00111000 ; top of sprite 0

%00111100 ; locationofsprite1 = spritedata + 8, a 16 bit address
%00011000
%00011000
%00011000
%00011000
%00011000
%01111000
%00111000 ; top of sprite 1

%11111111 ; locationofsprite1 = spritedata + 16, a 16 bit address
%11000000
%11100000
%00111000
%00001110
%11000011
%01100110
%00111100 ; top of sprite 2
end

; then to set player0 to sprite 1 in bB

player0pointer = spritedata[1]

; if you wanted to set player1pointer to sptite 2 you could do it this way
; player1pointer is the second location after player0pointer (the pointer is a 16 bit address, two bytes)

a = 2

player0pointer[a] = spritedata[2]



here's an excerpt from the asm listing produced




1736 f493 ;
1737 f493
1738 f493 .L013 ; const locationofsprite0 = < spritedata
1739 f493
1740 f493 .L014 ; const locationofsprite1 = < ( spritedata + 8 )
1741 f493
1742 f493 .L015 ; const locationofsprite2 = < ( spritedata + 16 )
1743 f493
1744 f493 .
1745 f493 ;
1746 f493
1747 f493 .
1748 f493 ;
1749 f493
1750 f493 .
1751 f493 ;
1752 f493
1753 f493 .
1754 f493 ;
1755 f493
1756 f493 .L016 ; data playerpointers
1757 f493
1758 f493 4c 9a f4 JMP .skipL016
1759 f496 playerpointers
1760 f496 9d a5 ad 00 .byte.b locationofsprite0, locationofsprite1, locationofsprite2, ;etc
1761 f49a
1762 f49a .skipL016
1763 f49a .
1764 f49a ;
1765 f49a
1766 f49a .
1767 f49a ;
1768 f49a
1769 f49a .
1770 f49a ;
1771 f49a
1772 f49a .L017 ; data spritedata
1773 f49a
1774 f49a 4c b5 f4 JMP .skipL017
1775 f49d spritedata
1776 f49d 3c .byte.b %00111100 ; locationofsprite0 = spritedata, a 16 bit address
1777 f49e
1778 f49e 7e .byte.b %01111110
1779 f49f
1780 f49f c3 .byte.b %11000011
1781 f4a0
1782 f4a0 c3 .byte.b %11000011
1783 f4a1
1784 f4a1 c3 .byte.b %11000011
1785 f4a2
1786 f4a2 c3 .byte.b %11000011
1787 f4a3
1788 f4a3 7e .byte.b %01111110
1789 f4a4
1790 f4a4 38 .byte.b %00111000 ; top of sprite 0
1791 f4a5
1792 f4a5 3c .byte.b %00111100 ; locationofsprite1 = spritedata + 8, a 16 bit address
1793 f4a6
1794 f4a6 18 .byte.b %00011000
1795 f4a7
1796 f4a7 18 .byte.b %00011000
1797 f4a8
1798 f4a8 18 .byte.b %00011000
1799 f4a9
1800 f4a9 18 .byte.b %00011000
1801 f4aa
1802 f4aa 18 .byte.b %00011000
1803 f4ab
1804 f4ab 78 .byte.b %01111000
1805 f4ac
1806 f4ac 38 .byte.b %00111000 ; top of sprite 1
1807 f4ad
1808 f4ad ff .byte.b %11111111 ; locationofsprite1 = spritedata + 16, a 16 bit address
1809 f4ae
1810 f4ae c0 .byte.b %11000000
1811 f4af
1812 f4af e0 .byte.b %11100000
1813 f4b0
1814 f4b0 38 .byte.b %00111000
1815 f4b1
1816 f4b1 0e .byte.b %00001110
1817 f4b2
1818 f4b2 c3 .byte.b %11000011
1819 f4b3
1820 f4b3 66 .byte.b %01100110
1821 f4b4
1822 f4b4 3c .byte.b %00111100 ; top of sprite 2
1823 f4b5
1824 f4b5 .skipL017
1825 f4b5 .
1826 f4b5 ;
1827 f4b5
1828 f4b5 .
1829 f4b5 ;
1830 f4b5
1831 f4b5 .
1832 f4b5 ;
1833 f4b5
1834 f4b5 .L018 ; player0pointer = spritedata[1]
1835 f4b5
1836 f4b5 a2 01 LDX #1
1837 f4b7 bd 9d f4 LDA spritedata,x
1838 f4ba 85 8a STA player0pointer
1839 f4bc .
1840 f4bc ;
1841 f4bc
1842 f4bc .
1843 f4bc ;
1844 f4bc
1845 f4bc .
1846 f4bc ;
1847 f4bc
1848 f4bc .
1849 f4bc ;
1850 f4bc
1851 f4bc .L019 ; a = 2
1852 f4bc
1853 f4bc a9 02 LDA #2
1854 f4be 85 d6 STA a
1855 f4c0 .
1856 f4c0 ;
1857 f4c0
1858 f4c0 .L020 ; player0pointer[a] = spritedata[2]
1859 f4c0
1860 f4c0 a2 02 LDX #2
1861 f4c2 bd 9d f4 LDA spritedata,x
1862 f4c5 a6 d6 LDX a
1863 f4c7 95 8a STA player0pointer,x
1864 f4c9 .

Link to comment
Share on other sites

 

 

occurs at compile time, not when your code runs.

 

That makes perfect sense now! Thank you for the detailed answer. I'm using so many of your code snippets in my game now. The extra cartridge ram variables are invaluable to what I'm trying to do now.

 

 

 

if playerpointers is meant to be a table of pointers into sprite data

 

Playerpointers is built-in to DPC+. It offsets a base address by a few bytes depending on the player data. So it sort of already works as an index. What I'm using it for is to change sprite data based on the player. It's easy to specifically set the offset to whatever you need, but it got more difficult for me when I wanted to turn it all into a single function to save ROM space. It wasn't as efficient to write the function in bB because I needed the variables that bB uses for function parameters.

Link to comment
Share on other sites

Okay! I got this. What I had to do was make the pointers a constant. So:

 

const player2lo = <(playerpointers+2)

 

Then I could:

 

LDA #player2lo

 

I tried so many different ways. So many wrong things! I started to question my resolve. :)

 

Edison: I give UP!! The world is in darkness!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...