Questions tagged [6502]

For 6502 series of processors, including hardware and assembly language questions. Use with [hardware] for the hardware interface in particular.

Filter by
Sorted by
Tagged with
13 votes
3 answers
2k views

What's the convention for < > low/high-byte in 8-bit assembler?

It's a little hard to Google for greater-than and less-than symbols in assembler math... If you saw, let's say, 6502 code like... lda #>SOME_LABEL or Z80 code like... ld a,>SOME_LABEL ...would ...
Luxocrates's user avatar
12 votes
1 answer
752 views

Were there 6502 revisions B and C, and what were they like?

The first 6502 was the 6502 revision A, which famously does not include the ROR instruction (this is sometimes described as a hardware bug, but that's apparently a myth). Then, some time later, there'...
Lorraine's user avatar
  • 37.9k
1 vote
1 answer
169 views

Interfacing with the Commodore 64 IEC Serial Port using Assembly

I'm struggling a bit to find relevant documentation on this subject when it comes to using just assembly. All I've found is either irrelevant or for BASIC. My goal is to be able to send and receive ...
SkyeG06's user avatar
  • 21
15 votes
3 answers
3k views

Difference between machine language and machine code, maybe in the C64 community?

I've always been sure that "machine language" and "machine code" are totally synonymous and mean programming directly in the language the machine understands, whether in binary, ...
hippietrail's user avatar
  • 6,313
13 votes
1 answer
393 views

Error in Apple I manual's Wozmon listing or Hardware description?

The Apple I Operation Manual includes a full listing of Steve Wozniak's amazing 256 byte 6502 Hex Monitor, aka Wozmon, as well as some explanation of how to interact with the Apple I hardware. My ...
Jason Clark's user avatar
3 votes
1 answer
196 views

45GS02 (65CE02) stack high register

I was looking through some source for a 6502 cross-assembler and noticed that the extensions for the 45GS02/65CE02 (C65) have an oddity - while most of the new registers are set through the acc using ...
Maury Markowitz's user avatar
7 votes
1 answer
279 views

Is there really any implementation of a Ada compiler/cross-compiler/interpreter for 6502?

I found some Ada compilers for CP/M machines but no luck for 6502-based C64/Apple II/BBC Micro. I'm not sure if Abacus Ada on C64 exists or how much a subset it implements for Ada. There is, though, ...
Schezuk's user avatar
  • 3,722
27 votes
6 answers
6k views

Did anyone ever run out of stack space on the 6502?

Unlike its main rival the Z80, the 6502 had a size limit of 256 bytes for the hardware stack. That sounds like a very tight limit, but in my experience, it was never actually an issue; by the time you ...
rwallace's user avatar
  • 58.1k
6 votes
2 answers
221 views

6502 Assembly on Apple IIe: GETLN fails with 'syntax error' under ProDOS

I'm writing a text adventure in assembly for the Apple IIe (using Merlin). I'm also using ProDOS 8 v2.0.3. At some point, I have a subroutine to read user input from the keyboard using the GETLN1 call....
Taciano Dreckmann Perez's user avatar
3 votes
1 answer
169 views

How can I check whether a define-style string macro is defined in CA65?

I have spent hours trying to figure out how to get conditional include paths functional in CA65 (or really, any conditional string values at all). Is it even possible? What I want is to be able to ...
Mark Ormston's user avatar
10 votes
1 answer
355 views

Why would a Reset key bounce disconnect Apple DOS?

This answer stated that hitting the Apple II Reset key twice, in quick succession, could cause DOS to be disconnected from the I/O hooks. I don't understand why that would happen. Quick background: ...
fadden's user avatar
  • 8,645
12 votes
3 answers
3k views

Why doesn't the NMOS 6502 have the illegal instruction, STA immediate?

The 6502's instructions have the form aaa-bbb-cc, where cc picks an instruction group. Group 01 is the most regular and easy to understand. In this group, aaa picks an instruction from the list 000 ...
Lorraine's user avatar
  • 37.9k
8 votes
2 answers
2k views

Which order does the 6502 read its vectors in?

I'm looking at gianlucag/mos6502 and Mike Chambers' fake6502. They have observable differences in the way that they read the reset vector. Rubbermallet reads the $fffc first, and then $fffd. I'm ...
Lorraine's user avatar
  • 37.9k
12 votes
1 answer
947 views

Carry handling during address generation on a 6502

I'm trying to learn a bit more about the internal workings of the 6502. The manual says that the branch instructions do not affect the carry flag. However, my understanding is that some carry handling ...
Patrick LeBoutillier's user avatar
17 votes
1 answer
3k views

Why was the 6502 version of Microsoft BASIC coded like the 8080 and 6800 versions even though this was rather inefficient?

It's quite clear that the 6502 version of Microsoft BASIC at all levels uses substantially the same structure and technique as the earlier 8080 and 6800 versions. As has been pointed out in various ...
cjs's user avatar
  • 24.5k
2 votes
2 answers
359 views

From an electrical and software engineering perspective, ignoring available software, should I go for the Z80 or 65C02? [closed]

This might be a weird title but I noticed that recommendations for one over the other usually go into a direction that is not too helpful for me. I would like to build an 8 bit computer and picked ...
Asyx's user avatar
  • 29
2 votes
1 answer
343 views

Obtaining a CPU execution trace on a Commodore 64 [closed]

I need to collect the execution trace of all instructions executed by the 6502 on a C64. I tried C64 Debugger, but I couldn't find any option for this. Is it possible to obtain with C64 Debugger? Are ...
Digerkam's user avatar
  • 311
9 votes
1 answer
498 views

What is the purpose of the 2x4-bit split of the PCH incrementer?

On this detailed 6502 block diagram that can be found all over the net, the increment logic for the high byte of the program counter is split into two 4-bit parts, with a named PCHC line for the carry ...
Cactus's user avatar
  • 2,593
8 votes
1 answer
543 views

How does the VIC-II/CPU memory access work on the C64?

As a programmer I knew that on the C64 the CPU got the bus in the high phase of PHI2 and the VIC-II got it in the low phase and also stole extra high phases when required. However, it wasn't until ...
Robin Elvin's user avatar
6 votes
0 answers
562 views

Transistor-level schematic of 65C02

I am looking for a transistor-level schematic for the 65C02, something like the one for the 6502 created by davidmjc (https://github.com/davidmjc/6502). I am a teacher planning to give a student ...
JRN's user avatar
  • 1,255
1 vote
1 answer
246 views

Transfer between bus and register in 6502 CPU

For one register of 6502 CPU (here X Index register) : If the SB/X (load) signal and X/SB (bus enable) signal are both asserted at the same time, what happens ? X Index register take the bus value ...
Johnmph's user avatar
  • 389
2 votes
1 answer
229 views

Timer B Interrupt occurs only once

I was following this tutorial on Commodore 64 timer interrupts and tried to replicate it (except all I was planning on doing was changing the border color.) I noticed that my interrupt only occurs ...
puppydrum64's user avatar
  • 1,638
3 votes
1 answer
277 views

Did any 6502-based system with cycle-stealing memory access steal the first available read, rather than asserting READY three cycles early?

On the 6502, the READY signal may be used to extend read cycles indefinitely, but will have no effect if asserted during write cycles. As a result, many devices that need to steal cycles from the CPU ...
supercat's user avatar
  • 33.9k
14 votes
3 answers
3k views

When was the 6502 second sourced?

According to https://en.wikipedia.org/wiki/Second_source MOS Technology licensed Rockwell and Synertek to second-source the 6502 microprocessor and its support components. This makes sense; the 6502 ...
rwallace's user avatar
  • 58.1k
10 votes
2 answers
2k views

How did the 6502 designers intend for the indirect addressing modes to be used?

The 6502 has three indirect addressing modes: Indirect, Indexed Indirect (Indirect,X) and Indirect Indexed (Indirect,Y). Indirect is only used on the JMP instruction, no other. Why was this mode ...
nexus_2006's user avatar
  • 1,055
16 votes
3 answers
3k views

Can the 6502 clock be changed on the fly?

I was wondering if the original NMOS 6502 has any timing limitations on changing the clock rate during operation? I ask, because the CSG 8502 version could "run at double the clock rate of the ...
Maury Markowitz's user avatar
12 votes
1 answer
774 views

How common was MADSEL?

I recently completed a software disassembly of the 1980 coin-op arcade game Missile Command. I'm curious whether a feature of the hardware is unique or commonplace. First, a bit of background: ...
fadden's user avatar
  • 8,645
11 votes
4 answers
2k views

Could the Z80 do interference-free video as the 6502 could?

Technically this isn't just about video since it applies to any regularly scheduled DMA¹ from a non-CPU subsystem, but video is the most common application of this technique so I'll use that as the ...
cjs's user avatar
  • 24.5k
6 votes
1 answer
238 views

What bit do the BBRn/BBSn opcodes check?

I am working with a W65C02S chip and it has extra opcodes, BBRn and BBSn that branch on a bit set, or bit reset. However, I cannot find on which register or memory location this check is done. When ...
Bart Friederichs's user avatar
3 votes
1 answer
179 views

CC65 ignores request to correctly offset memory areas in output files

I'm trying to segment my C code into two distinct memory areas, one which will be flashed to a ROM chip and another which will end up somewhere else. Here is what I have in sbc.cfg (I was originally ...
ifconfig's user avatar
  • 133
8 votes
0 answers
224 views

Systems that used the Rockwell R65C00/21 or R65C29

The Rockwell R65C00/21 and R65C29 are described in an October 1984 datasheet ("R65C00/21 dual CMOS microcomputer and R65C29 dual CMOS microprocessor," Document no. 29651N64, rev. 2) which is ...
JRN's user avatar
  • 1,255
5 votes
1 answer
366 views

Apple II Assembly DSECT

I'm trying to define a section of data in a program. The Apple 6502 Assembler/Editor mentions an assembler directive called "DSECT" but I can't tell if I'm using it correctly or not. Here is ...
Kuang's user avatar
  • 53
25 votes
2 answers
4k views

Was leaving all xxxxxx11 opcodes unused on the 6502 a deliberate design choice?

The 6502, like many 8-bit processors, has a somewhat arcane opcode-mode restrictions. On most such processors, the restriction is a clear result of trying to pack a lot of instructions into a limited ...
supercat's user avatar
  • 33.9k
2 votes
2 answers
345 views

How to properly convert an active-low joystick routine to active-high

My last question wasn't specific enough so I'll rephrase it. I've been having trouble with programming game consoles/computers like Commodore 64 that have active-low joysticks, where the bits are all ...
puppydrum64's user avatar
  • 1,638
18 votes
3 answers
4k views

What is the purpose of mirrored memory regions in NES's CPU memory map? [duplicate]

[Please see answers to this related question as well] I've started reading the "official" NES Documentation and in page ten, it says that "memory locations $0000-$07FF are mirrored ...
anmomu's user avatar
  • 183
6 votes
1 answer
277 views

Commodore 64 sound seems to freeze at a high pitch if executed too soon after startup

I created this little sound driver for sound effects, it makes a classic "laser beam" sound you would hear in old arcade games. There's just one problem, and it's a bit of a strange one. I ...
puppydrum64's user avatar
  • 1,638
3 votes
1 answer
146 views

Spontaneous movement and game crashes from active-low joystick routines [closed]

I've noticed this recurring problem when I'm trying to program joysticks or buttons that are active-low (0 = pressed), like on the Commodore 64 or Game Boy Advance. Regardless of the language or ...
puppydrum64's user avatar
  • 1,638
4 votes
2 answers
773 views

How to wait for vBlank on Commodore 64

I'm not new to 6502 Assembly but I am new to the Commodore 64. I'm used to the NES where you have to write everything yourself, such as the NMI/RESET/IRQ vectors, etc, but from what I understand the ...
puppydrum64's user avatar
  • 1,638
6 votes
2 answers
421 views

Macro for counted string accepting multiple arguments?

Using ca65 assembler, I'd like to use a macro to encode a string as a pascal style string or FORTH counted string with a leading length byte. In ca65 documentation there is this example: ....
Alexandre Dumont's user avatar
11 votes
3 answers
2k views

Protecting 6502 decimal mode code from interrupts

A common idiom in 6502 assembly code is to protect sequences of code that rely on decimal mode from being interrupted. This because an interrupt handler typically clears decimal mode (cld), and thus ...
Brian H's user avatar
  • 59.8k
9 votes
3 answers
2k views

C++ compilation for the Z80 and 6502?

I know it's almost heresy to ask something like this, but ... We have C compilers for the Z80/6502 and there used to exist a thing called the Comeau C++ compiler, that produced C code as output. There ...
user1095108's user avatar
1 vote
1 answer
96 views

Is there a way to use .ident or * (PC) in numeric macro variables (using .set)?

I'm trying to write a macro to create "headers" in a linked list fashion. In each header the first 2 bytes should be the address of the previous header starting address (0000 in the first ...
Alexandre Dumont's user avatar
6 votes
1 answer
519 views

Where does the 6502 store the low order byte after fetching for read instructions?

I am trying to get a mental model of how the 6502 operates. I am going off this image: However please suggest a better one if it helps understanding . On this website it describes how a read ...
questionerofdy's user avatar
6 votes
1 answer
685 views

Why does the JSR operation not jump?

I am building a computer based on the 65C02S, and when stepping through the code, I see strange things happening. This is my code: SEI CLD LDX #$ff TXS JSR someRoutine ... This translates to this ...
Bart Friederichs's user avatar
6 votes
2 answers
666 views

Why doesn't Visual6502 simulate RRA in the way I expect?

As everyone knows, the 6502 has many many undefined opcodes. One of these is RRA, which essentially performs both ROR and ADC. From what I understand of hardware (really not much) and the explanation ...
Lorraine's user avatar
  • 37.9k
17 votes
2 answers
3k views

Why does the 6502 JSR instruction only increment the return address by 2 bytes?

Currently messing with 6502 assembly on a C64, and I don't understand why the JSR instruction is so weird. According to the instruction table, JSR is a 3-byte instruction and only operates in absolute ...
Jeroen Jacobs's user avatar
2 votes
1 answer
292 views

How to convert series of hex digits in memory into the format for use with Applesoft math subroutines

I'm trying to write a calculator program in assembly for the Apple //e. I know that there are built-in subroutines for performing all kinds of math operations involving the floating-point accumulator (...
Al Gorithm's user avatar
9 votes
1 answer
773 views

Why does the 6502 read from the stack before writing it?

I am building a W65C02S based computer for fun, and I try to build basically all the tools myself. Including the assembler (yes, I know they exist, I just want to make everything from scratch myself, ...
Bart Friederichs's user avatar
15 votes
1 answer
2k views

How did the 6502 CPU get its name?

I am interested in the etymology of the name for the 6502 CPU. How were those numbers arrived at by the designers? Do they refer to anything specific? Is there some sort of origin story? I found some ...
lookaside's user avatar
  • 481
10 votes
1 answer
1k views

6502 double store and copy protection?

I was watching a video on netlist simulation of the 6502. The presenter mentions how the 6502 has a double store upon using INCY, and then offhandedly mentions that this can be used for copy ...
b degnan's user avatar
  • 1,059