Code: Select all
LevelList = {1,2,3}
get first value from LevelList
if the first value == 1
display sprite one at (0,0)
if the first value == 2
display sprite two at (0,0)
etc.
Code: Select all
LevelData: .db 1,2,3
Moderator: MaxCoderz Staff
Code: Select all
LevelList = {1,2,3}
get first value from LevelList
if the first value == 1
display sprite one at (0,0)
if the first value == 2
display sprite two at (0,0)
etc.
Code: Select all
LevelData: .db 1,2,3
Code: Select all
ld a,(LevelData)
cp 1
jp z,DispSpriteOne
cp 2
jp z,DispSpriteTwo
cp 3
jp z,DispSpriteThree
etc.
Code: Select all
start:
ld a, (leveldata)
dec a ; Sets the zero flag if a was one
jr z, dispsprite1
dec a ; A is already decremented, if we do it again we have subtracted 2 in total, zero is set if A was 2
jr z, dispsprite2
dec a ; Zero set if A was 3
jr z, dispsprite3
;...
Code: Select all
ld a, (leveldata) ; Gets the first element
ld a, (leveldata+1) ; Gets the 2nd element
ld a, (leveldata+2) ; Gets the 3rd element
;...
I have no idea why I wrote this, 28days says about the same... lol is something wrong with the font after the first codebox?driesguldolf wrote:Halifax is entirely correct, though I'd like the emphase that you should think the memory as one BIG array.
Now those elements of that array are bytes.
To recall any of it's elements is very simple:where index is a number ranging from 0-65535 (aka addresses).Code: Select all
ld a, (index)
This effectively gets the byte stored at 'address' and copies it's content to the register A
Keep in mind that the only thing you can store there are numbers (or better ones and zeros). That implies that your code are also numbers, in fact each instruction you type will be converted (by the assembler) into a number(s) (aka opcodes)
Now the .db directive simply states that the assembler has to put some numbers on the following locations
Thus:(*) Text is no exception of the fact that you can only store numbers in memory: each character is represented by a number (TASM uses 'ASCII' to find out what character translates to what number)Code: Select all
.db 13 ; Inserts the number '13' in your program .db -4 ; I assume you know how the Z80 deals with negative numbers .db 888 ; ERROR: the value is supposed to fit in a byte (and 888 is outside 8bit (aka byte) range) .db 67,8,123,0 ; You can have multiple bytes after each other .db "This is text!" ; (*)
Would be exaclty the same as typing .db "This is text"Code: Select all
.db 84,104,105,115,32,105,115,32,116,101,120,116,33
Now you can think "Do I have to remember all the addresses where I store my data out of my head?". Of course you do!... lol just kiddin', in TASM there are 'labels'. If you write something at the start of a line TASM will interpret it as a label and assigns a value to it corresponding to the address the next byte will be stored when you run your program
Too bad you cannot claim all that memory, the first 32Kb is used with the Flash memory and a lot of the other half is claimed by TIOS.
When you run a program it is copied to $9D95 (people commonly use hexadecimal to talk about addresses)
Do you mean you just want to index the list?nepmarauder wrote:Assuming I am correct and you can store variable lists this way, how can you specify and retrieve a specific number in the list?Code: Select all
LevelData: .db 1,2,3
Code: Select all
ld de,LevelData ;base address ( &LevelData ) use BC if DE is in use
ld hl,(index) ;if index is a variable, if you computer it just leave this line out
add hl,de ;forget about multiplication: this is a byte array anyway
;(hl) now refers to the number LevelData[index]
Code: Select all
ld de,LevelData ;base address ( &LevelData ) use BC if DE is in use
ld hl,(index) ;if index is a variable, if you computer it just leave this line out
add hl,hl ;it might be a good idea to pre-multiply the index..
add hl,de
;slightly more complicated: (hl) refers to the LSB of LevelData[index], don't forget to 'inc hl' and read the MSB as well!
Code: Select all
ld a,(LevelData)
dec a ;if it started with zero, use OR A (..or AND A..) first
jp z,DispSpriteOne
dec a
jp z,DispSpriteTwo
dec a
jp z etc etc..
Code: Select all
ld a,(LevelData)
dec a ;only needed because you start at 1
ld l,a
ld h,0
ld d,h
ld e,a
add hl,hl ;x2
add hl,de ;x3
ld de,jumpTable
add hl,de
jp (hl)
jumpTable:
jp SpriteOne
jp SpriteTwo
jp SpriteThree
etc..
Code: Select all
ld a,(leveldata)
dec a
ld h,0
ld l,a
add hl,hl ;only x2 this time
ld de,vectortable
add hl,de
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
jp (hl)
vectortable:
.dw SpriteOne
.dw SpriteTwo
.dw SpriteThree
etc
Code: Select all
ld a,(LevelData)
ld h,0
ld l,a
add hl,hl ;x2
add hl,hl ;x4
add hl,hl ;x8
ld de,Sprites
add hl,de
call DrawSpriteHL