I'd like to have new people get a sprite onscreen and control it then keep building on that.
So is something like I've shown much to basic?Or needs more comments?
This is in Kickass assembler
Code: Select all
.pc = $801
.byte $0b, $08, $06, $00, $9e, $32, $30, $36, $34, 0,0,0
.pc = $810
jmp Start
Constants and Defines can't be modified
.const SpriteFrameRegister = $07f8
.const SpriteEnableRegister = $d015
.const SpriteColorRegister = $d027
.const SpriteXMostSignificantBitRegister = $d010
Start:
//First Lets clear the screen using default blank char which is $20 hex or 32 decimal
//We start by declaring the x register at zero and increase the x register to loop through and clear the screen
ldx #0 //x = 0 decimal
lda #32 //accumulator = 32 decimal
ClearScreenLoop: //ClearscreenLoop is a label
//This instruction stores the contants of the accumulator into the address $400(1024 decimal)plus the offset of the x register
//Basically place 32 decimal at $400+x since we loaded the accumulator with decimal 32 (blank char or space if you prefer)
//We also loaded the x register with decimal 0 so what gets stored to $400?
//$400,x is the equivalent of $400+0 = $400 now if x register was = 1 that would point to the address $400+1 = $401
//if x register was 2 $400+2 = $402 pretty easy huh!
//So accumulator = 32,x register = 0 sta $400,x = place decimal 32 at address $400 + xregister offset
//The contants of address $400+x becomes 32
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //you'll notice other addresses besides starting address $400, ($500,$600,$700)
//The screen is 1024 bytes in 6502 we can't access more than 256 bytes so 1024/256 = 4 now count how many addresses there are
//$400,$500,$600,$700 is four addresses in total
//So in order to clear all 1024 bytes of screen memory we have to store the accumulator plus the x register offset to four
//addresses
sta $400,x //Store the value of the accumulator to $400+x
sta $500,x //Store the value of the accumulator to $500+x
sta $600,x //Store the value of the accumulator to $600+x
sta $700,x //Store the value of the accumulator to $700+x
inx //Increment x register used as loop counter
bne ClearScreenLoop //what the instruction does is "branch if zero flag is not set" (it does not care about the X register at all). so for that to make any sense, you'd have to put "increment X register, and set zero flag to 1 if the result is zero" as comment into the previous line (which is really over the top). hence reducing it to just "repeat until index overflows" Thanks Groepaz for the explanation much more clear now!