I'm not at all familiar with the assembler you're using, so I may not be able to answer everything, but I'll do my best.
That can vary a lot from assembler to assembler, and even in the same assembler there are different ways to go about it, but at the most basic level, a variable is exactly the same thing as a label, just a nickname for an address. Most assemblers will let you do MyVariable = $05F0 to define a variable, and many people like this simple approach.Okay. So first just curious, how do you define variables?
Any data you may need to use in your program... e.g. the positions of enemies in a level, a list of sprite entries, the map of a level... In some cases you can hardcode some of that information in the logic itself, but you don't want to write 1000 different sprite drawing subroutines just because you have 1000 different sprites in your game, you write only one subroutine and point it to one of a 1000 sprite definitions (data) stored in the ROM.As for the .db stuff, I'm sorry to say I'm still having trouble understanding what it's used for. What is raw data?
An address table is literally that, a list of addresses pointing to different things. For example, say you have a maze game with 20 levels, each with a different maze layout. Will you write 20 different functions to draw those maps on the screen? No, you'll write one function, and pass the number of the level you want to draw as an argument. The function will then use this number as an index to read one of 20 addresses from a table, and use that address to read the data it needs to draw the requested level.And what are address tables and all those?
Say I want to make a program to tell everyone how many cookies I ate each day in January. I need a function that will receive a day of the month as an argument, and will return the number of cookies I ate that day:Is there any examples on when you want to use .db (and the others) to do something specific?
Code: Select all
;Subroutine: returns number of cookies eaten in a day of January. ;Input: A = day in January (1 to 31); ;Output: A = number of cookies; GetCookiesForDay: ;subtracts 1 because table starts from 0, not 1 sec sbc #1 ;uses this number as an index tax ;gets the number of cookies from the table lda CookiesPerDay, x ;returns rts ;Table: lists cookies eaten for each day in January. CookiesPerDay: .db 4, 3, 2, 2, 6, 5, 5, 2, 0, 2, 4, 3, 2, 2, 6, 4, 0, 2, 2, 2, 4, 3, 2, 3, 6, 5, 6, 2, 0, 2, 3
Code: Select all
;gets the number of cookies eaten in January 7 lda #7 jsr GetCookiesForDay
The purpose of # is to define an addressing mode for instructions (immediate addressing), so you normally shouldn't use it for anything other than the operand of a CPU instruction.Would there be any difference if you wrote a row like that and used either hex addresses like $F1, or value ones like #$F1?
Normally you need a name (label) before every block of data in your program, so you have a way of referencing that data, but it is possible that you don't need a name if you're calculating the address of a data table in some other way.Okay I kind of catch you there. I just wondered, is it supposed to specific "data", or just all the "data"?
At its core level, assembly doesn't have many symbols at all... It's mainly the ones we already talked about: # for immediate, $ for hex, % for binary, () and/or  for indirection. Anything beyond that is assembler-specific, so you should refer to your assembler's documentation.Okay. Is there any chart with all the symbols and their uses in 6502?
EDIT: fixed CLC/SEC mix-up.