As usual in software and the world of computing, one is often FORCED to become distracted from the task in hand, only to have to go down a rabbit hole of convoluted learning, just to accomplish ONE simple goal:
I am learning 6502 assembley, I know a TINY bit of Python, and the Python example code I give here is from a 6502 tutorial:
rom = bytearray([0xea] * 32768)
rom[0x0010] = 0xad
rom[0x0011] = 0xff
with open("rom.bin", "wb") as out_file:
out_file.write(rom)
Okay, so this generates a 32k bin file, populated with "ea" from beginning to end EXCEPT for the 0x0010 and 0x0011 locations.
Question: without vanishing down a distracting rabbit hole of needing to trawl the web, piecing together fragments of poorly-written "tutotials", most of which make VAST assumptions as to the knowledge level of the reader... how do I specify *A RANGE* of addresses - let's say "0x20 to 0x30" to fill with a certain byte? Example - I want to fill 0x20-0x30 inclusive, with "ff" data?
Many thanks!
So you are going down the deep dark Python distraction road!
See https://www.pitt.edu/~naraehan/python3/more_on_for_loops.html (https://www.pitt.edu/~naraehan/python3/more_on_for_loops.html)
You'd want a for loop with a numeric range. Something like:
for addr in range(0x20,0x30+1):
rom[addr] = 0xFF
Any 6502 tutorial that digresses into Python is most likely not really worth reading.
So you are going down the deep dark Python distraction road!
See https://www.pitt.edu/~naraehan/python3/more_on_for_loops.html (https://www.pitt.edu/~naraehan/python3/more_on_for_loops.html)
You'd want a for loop with a numeric range. Something like:
for addr in range(0x20,0x30+1):
rom[addr] = 0xFF
Any 6502 tutorial that digresses into Python is most likely not really worth reading.
Yeah you're right, but I just needed a quick tool to generate the .bin, and your code works - thanks! I won't mention the video series, but in the series I am following, half of one of the tutorials goes off at a tangent showing us how to write some Arduino code to make a 6502 pin monitor; I was of the same opinion as you, re distractions, when I first watched it, but I see he's showing us how to monitor... I was just like "Ermm, I thought this was 6502 ASM, 'how to make a bus monitor in Arduino IDE' " but since his content is SO SO well explained and of excellent quality, I can overlook it, and who am I "set him straight" - I am a n00b to all this 6502-ness! :)
Thanks so much - I was getting hung up, as I hadn't realised that hex numbers could be used in "range".
Normally you would create 6502 assembly code using an assembler which takes text input and produces a binary object file -- much like a C compiler (or Java compiler).
Every assembler uses the same basic syntax, but there can be a lot of variation especially in the way constant data is specified.
If you go to the online assembler at https://6502asm.com you can see what assembly language looks like by bringing up any of the example programs.
This particular assembler uses the "dcb" directive to declare constant data areas. For instance, if you bring up the "alive.asm" example at the end you will see:
ypos:
dcb $00,$02,$20,$02,$40,$02,$60,$02
dcb $80,$02,$a0,$02,$c0,$02,$e0,$02
dcb $00,$03,$20,$03,$40,$03,$60,$03
dcb $80,$03,$a0,$03,$c0,$03,$e0,$03
dcb $00,$04,$20,$04,$40,$04,$60,$04
dcb $80,$04,$a0,$04,$c0,$04,$e0,$04
dcb $00,$05,$20,$05,$40,$05,$60,$05
dcb $80,$05,$a0,$05,$c0,$05,$e0,$05
which is declaring a data block of 64 bytes. Each byte is specified in the case. To specify that a range of bytes should be filled with a single constant value a different directive would most likely be used -- if such a feature is supported at all by the assembler. Otherwise you could always fall back on using a directive like "dcb" and just repeat the byte value once for each memory location.