Words Fail Posted January 7 Share Posted January 7 (edited) I am trying something with data statements. Let's say I have this a=2 level1 sdata lev1=e 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end return otherbank level2 sdata lev2=e 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end return otherbank How can I load sdata with a name? like this: t = sread (lev(a)) In the above example I want to read data from the one called lev2.. which is represented by variable a. I can't figure out if that's doable. I get errors when trying to compile. Edited January 7 by Words Fail Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 7 Author Share Posted January 7 Also I can't get it to work at all.. it says: 43 bytes of ROM space left in bank1 -4656 bytes of ROM space left in bank1 error: Origin Reverse-indexed. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted January 7 Share Posted January 7 Have you read the last paragraph here: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#sdata Quote Note that all data tables, sequential or otherwise, must be located in the same bank where they are read. If you try to access data that lives in another bank, there will be no errors, but the data you get will certainly be incorrect. Check out the example program called Sound With Background “Music” to see how sdata can be used for music. Quote Link to comment Share on other sites More sharing options...
bogax Posted January 7 Share Posted January 7 (edited) at the risk of being more confusing than helpfull... v = sread(dat) the sread is sort of like this v = dat[pointer] pointer = pointer + 1 data dat [data] end except that with the normal data statement pointer is 8 bits so you can only address 256 bytes of data with the normal data statement dat is the name of the location of the data and with sdata the name is the name of a pointer which points to the data sdata dat = p [data] end is sort of like dim dat = q.p const datlo = <dat_ ; the lo byte of dat_ const dathi = >dat_ ; the hi byte of dat_ p = datlo q = dathi data dat_ [data] end with the data statement dat is the name for the location of the data with the sdata statement dat is the name of a 16 bit pointer (instead of "pointer") which is a little like an 8.8 variable except it's 16. and that pointer is intialized with the location of the data and since it's 16 bits you can reach 65536 bytes of data but sread only goes through them sequentially however you can change the pointer I don't think you even need the sdata statement you just need to pass sread a pointer/variable Edited January 7 by bogax Quote Link to comment Share on other sites More sharing options...
+Karl G Posted January 7 Share Posted January 7 16 hours ago, Words Fail said: I am trying something with data statements. Let's say I have this a=2 level1 sdata lev1=e 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end return otherbank level2 sdata lev2=e 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end return otherbank How can I load sdata with a name? like this: t = sread (lev(a)) In the above example I want to read data from the one called lev2.. which is represented by variable a. I can't figure out if that's doable. I get errors when trying to compile. The short answer is that sdata doesn't work like that, and you can't do reads in the way you are wanting here. if you reuse the same variables for both sdata blocks like you do here, then you would need to run the initialization before reading from the data blocks so it is reading from the correct one. The more normal case would be to use different variables for different data tables, and then use an if/then or on ... goto to select which one you want to read from. The long answer is what bogax is saying about sdata being implemented as pointers in assembly "under the hood", which can be useful if you want to learn the assembly side of things. Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 7 Author Share Posted January 7 14 hours ago, Random Terrain said: Have you read the last paragraph here: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#sdata Same error message for me. Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 7 Author Share Posted January 7 21 minutes ago, Karl G said: The short answer is that sdata doesn't work like that, and you can't do reads in the way you are wanting here. if you reuse the same variables for both sdata blocks like you do here, then you would need to run the initialization before reading from the data blocks so it is reading from the correct one. The more normal case would be to use different variables for different data tables, and then use an if/then or on ... goto to select which one you want to read from. The long answer is what bogax is saying about sdata being implemented as pointers in assembly "under the hood", which can be useful if you want to learn the assembly side of things. a has nothing to do with reading data. a is the level number I wish to load. if a = 1 then goto level1 if a = 2 then goto level2 if a = 3 then goto level3 if a = 4 then goto level4 if a = 5 then goto level5 if a = 6 then goto level6 if a = 7 then goto level7 if a = 8 then goto level8 if a = 9 then goto level9 if a = 10 then goto level10 if a = 11 then goto level11 if a = 12 then goto level12 if a = 13 then goto level13 if a = 14 then goto level14 if a = 15 then goto level15 if a = 16 then goto level16 .. etc I am trying to shorten that code with a variable.. goto level(a) or something.. So the game starts and a=0 which means to load my title screen.. after you press fire it does a=a+1 so now a=1.. so now that a=1 then it would gosub level(a) or something.. I can't figure out how to get that to work.. so it goes to level(a) in this case level1 which initializes our sdata. level1 sdata lev1=e 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end return level2 sdata lev2=e 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end return etc Quote Link to comment Share on other sites More sharing options...
+Karl G Posted January 7 Share Posted January 7 Check out "on...goto" and "on...gosub" in the bB manual. Quote Link to comment Share on other sites More sharing options...
bogax Posted January 7 Share Posted January 7 if you just need to change the pointer to point to the level data you could do something like this e = levplo[a] f = levphi[a] t = sread(e) data levplo <lev1, <lev2, <lev3, etc end data levphi >lev1, >lev2, >lev3, etc end data lev1 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end data lev2 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end etc Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 7 Author Share Posted January 7 22 minutes ago, bogax said: if you just need to change the pointer to point to the level data you could do something like this e = levplo[a] f = levphi[a] t = sread(e) data levplo <lev1, <lev2, <lev3, etc end data levphi >lev1, >lev2, >lev3, etc end data lev1 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end data lev2 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end etc I have no idea what that means. I have no idea why there are two sets of data levelplo and lev1, and then levphi and lev2. No idea what lev lo and hi are for. Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 7 Author Share Posted January 7 (edited) 49 minutes ago, Karl G said: Check out "on...goto" and "on...gosub" in the bB manual. so on a goto level1 level2 level3 level4 return is the same as if a=1 then goto level1 if a=2 then goto level2 if a=3 then goto level3 if a=4 then goto level4 ? Edited January 7 by Words Fail Quote Link to comment Share on other sites More sharing options...
+Karl G Posted January 7 Share Posted January 7 11 minutes ago, Words Fail said: so on a goto level1 level2 level3 level4 return is the same as if a=1 then goto level1 if a=2 then goto level2 if a=3 then goto level3 if a=4 then goto level4 ? Close. It starts counting from 0 instead of 1, but otherwise correct. Quote Link to comment Share on other sites More sharing options...
bogax Posted January 7 Share Posted January 7 (edited) normal bB variables are one byte, 8 bits and can have values 0..255 data addresses go upto 65535 and need two bytes sread needs a two byte pointer sdata lev1 = e defines e as the 16 bit pointer and since e only holds 8 bits the next byte, f holds the other 8 bits its kind of like dim lev1 = e except its 16 bits so maybe it's more like dim lev1 = f.e sdata also loads the 16 bit address of the data in to the lev1/f.e pointer data lev1 makes lev1 the name for the 16 bit address where the data is <lev1 is the lower 8 bits of lev1 >lev1 is the high 8 bits of lev1 data levplo <lev1, <lev2, <lev3, etc end creates a table of the lower 8 bits of the locations of the level data e = levplo[a] f = levphi[a] assign the lower 8 bits to e and the high 8 bits to f sread doesn't need you to assign a name for the pointer it just needs the the name of the variable that is the low byte of the pointer t = sread(e) Edited January 7 by bogax Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 7 Author Share Posted January 7 11 minutes ago, Karl G said: Close. It starts counting from 0 instead of 1, but otherwise correct. Thanks. Perfect. Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 7 Author Share Posted January 7 (edited) 1 hour ago, bogax said: normal bB variables are one byte, 8 bits and can have values 0..255 data addresses go upto 65535 and need two bytes sread needs a two byte pointer sdata lev1 = e defines e as the 16 bit pointer and since e only holds 8 bits the next byte, f holds the other 8 bits its kind of like dim lev1 = e except its 16 bits so maybe it's more like dim lev1 = f.e sdata also loads the 16 bit address of the data in to the lev1/f.e pointer data lev1 makes lev1 the name for the 16 bit address where the data is <lev1 is the lower 8 bits of lev1 >lev1 is the high 8 bits of lev1 data levplo <lev1, <lev2, <lev3, etc end creates a table of the lower 8 bits of the locations of the level data e = levplo[a] f = levphi[a] assign the lower 8 bits to e and the high 8 bits to f sread doesn't need you to assign a name for the pointer it just needs the the name of the variable that is the low byte of the pointer t = sread(e) I'm gonna take a break from programming for a bit as I don't understand any of that (I should say data statement programming) and just work on my game as is. I mean, my game works without the data statements, I just have a great idea to use data statements and think it'll make something really spectacular here. I have no idea what lo and hi are and I can't get data statements to read anything so far. All I wanna do is read the first two pieces of sdata. I'll come back for the rest later. So it reads the first 2 numbers and stores them as variables, does something, reads the second two, does something, etc. The data statement would really offer something special for my game.. it would offer me some professional polish, and I think may allow me to cram more levels in. Edited January 7 by Words Fail Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 8 Author Share Posted January 8 (edited) Hey I revisited this and figured out the error.. I have bank 2 temp1=temp1 twice in my code! Edited January 8 by Words Fail 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted January 8 Share Posted January 8 (edited) lo and hi are just abbreviations for low and high in the names to remind me what they are and help me keep things straight all these values are binary and bytes and stuff and we write them as hexadecimal suppose it was decimal I define a byte as two decimal digits normal bB variables are one byte and can only hold values 0..99 but memory be it RAM or ROM is numbered 0..9999 suppose I have a data table that starts at location 1234 12 is the hi byte of location 1234 34 is the lo byte of location 1234 suppose I have a table at location 1234 data data_table [some data] end data_table is the name for (location) 1234 <data_table is 34 >data_table is 12 I have a pointer named a it's a bB variable and it only holds values 0..99 it's a pointer because it holds a number which is the location in memory of some data, it points at the data suppose a contains 51 v = data_table[a] takes 1234 (the value of data_table) adds 51 (the contents of a) gets the data that's at location 1285 and sticks it in v since the pointer a can only hold values up to 99 you can only get to 99 values in the table that way an sdata statement makes the pointer 4 digits so you can get at 9999 values in a table four digits needs 2 bytes you specify a variable and the sdata statement assumes that the location after it is the second byte (that's the way the processor works) and the name you specify is not the name of the location of the table it's the name of the variable that contains the location of the data (the 4 digit 2 byte pointer) if you specify variable a then the 4 digit 2 byte pointer will be variables b,a (the variables are in order in memory b comes after a, f comes after e that's just the way bB does things) b contains 12, a contains 34 sread takes what ever variable you pass to it assumes that that is the low byte of a 2 byte pointer gets whatever is at the location pointed to by the pointer and increments the pointer if the pointer is the variables b,a and contains 1234 it will get what ever is at location 1234 and increment the pointer to point at 1235 for the next sread b will contain 12 a will contain 35 the 2 byte pointer is just a couple of variables you can point them at anything you want if you want the pointer to point at a paticular table you just set the pointer to the location of that table with sdata you don't know the location. the name is the name of the pointer that contains the location. with a data statement the name is for the location of the table/data and that is 4 digits, 2 bytes in a const declaration or in specifying of table data you can choose which byte by prepending < for the low byte or > for the high byte so if data_table is the name for 1234 <data_table = 34 >data_table = 12 so you can create a couple of tables containing the hi bytes and the lo bytes of the locations of your level data tables and use variable a, your level number, to pick the corresponding location out of the levplo and levphi tables which contain the locations of you level data tables (lev1, lev2, etc) and copy the level data table location to your chosen sread pointer which in this case are variables f,e I used abbreviations levplo and levphi for level pointer lo, level pointer hi for the names of the tables conaining the lo and hi bytes of the locations of the level data tables e = levplo[a] f = levphi[a] t = sread(e) data levplo <lev1, <lev2, <lev3, etc end data levphi >lev1, >lev2, >lev3, etc end data lev1 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end data lev2 14,4,15,4,17,4,18,4,11,6,12,6,14,6,15,6,17,6,18,6,20,6,21,6,8,8,9,8,23,8,24,8,23,10,24,10,23,12,24,12,23,14,24,14,11,16,12,16,14,16,15,16,17,16,18,16,20,16,21,16 end etc Edited January 8 by bogax Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 9 Author Share Posted January 9 In my previous program I had room for 30 levels and ran out space in the graphics bank. With the new program using data statements I shoved 28 levels in bank5, can fit another 28 or so in bank6 (depends on size of each level). I've got bank2 open for a bit more code, but banks3 and 4 wide open for code. So depending on how much the rest of my code uses up, I could fit more levels there. I still don't know how my sread is working.. example: Based on what level you are on it gosubs the sdata and then it loads the first two pieces of my data.. but as you can see in the example below I am doing an sread(rack1).. and for some reason all the levels load just fine. I was assuming I needed something like d = sread(level(a)) -- in there a would be the variable for what level you're on. But somehow all the levels load. bank 5 temp1=temp1 levelread d = sread(level1): e = sread(level1) return otherbank level1 sdata level1=b 14,3,15,3,17,3,18,3,11,5,12,5,14,5,15,5,17,5,18,5,20,5,21,5,8,7,9,7,23,7,24,7,8,9,9,9,23,9,24,9,8,11,9,11,23,11,24,11,8,13,9,13,23,13,24,13,11,15,12,15,14,15,15,15,17,15,18,15,20,15 21,15,14,17,15,17,17,17,18,17,255 end return otherbank level2 sdata level2=b 20,3,21,3,5,5,6,5,17,5,18,5,23,5,24,5,2,7,3,7,8,7,9,7,20,7,21,7,5,9,6,9,14,11,15,11,11,13,12,13,17,13,18,13,26,13,27,13,14,15,15,15,23,15,24,15,29,15,30,15,26,17,27,17,255 end return otherbank Quote Link to comment Share on other sites More sharing options...
bogax Posted January 9 Share Posted January 9 (edited) the sdata statement sets the pointer it doesn't matter if two sdata statements use the same variables for the pointer it will be whatever the last sdata statement executed set it to (unless you change it and of course sread increments it) Edited January 9 by bogax Quote Link to comment Share on other sites More sharing options...
Words Fail Posted January 10 Author Share Posted January 10 22 hours ago, bogax said: the sdata statement sets the pointer it doesn't matter if two sdata statements use the same variables for the pointer it will be whatever the last sdata statement executed set it to (unless you change it and of course sread increments it) I tried naming them all "level" and that did not work, so I definitely have to make them all different I guess. But whatever the differences are it doesn't matter. Sort of like how you can't have two of the same subroutine names. Quote Link to comment Share on other sites More sharing options...
bogax Posted January 10 Share Posted January 10 (edited) you can reuse the variable. in this case variable e when you use the sdata statement bB makes the name you give it an alias for the variable lev1 becomes an alias for the variable e like you'd dimmed it dim lev1 = e bB also declares a lable derived from the sdata name by appending _begin so here the lable would be lev1_begin if you use the same sdata name twice bB will try to declare the same lable twice with different values so yes similar to two subroutines with the same lable Edited January 10 by bogax Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.