1,885
edits
Changes
→Basic Controls
[[Category:SPO600]][[Category:6502]][[Category:Assembly Language]][[Image:6502_Emulator_Screenshot.png|thumb|400px|right|A screen shot of the 6502 Emulator running [[6502_Emulator_Example_Code#Etch-a-Sketchtm_Style_Drawing|the drawing example code]].]]A simple web-based [[6502]] emulator is available at [http://6502.cdot.systems http://6502.cdot.systems]. This emulator is used in the [[SPO600]] course to teach 8-bit [[Assembly Language|assembly language]] before transitioning to more complex 64-bit x86_64 and [[AArch64]] assembly language. {{Admon/tip|Hex notation - $XX|In most 6502 documentation, including this page, the <code>$</code> prefix indicates hexadecimal notation. On other systems, this may be designated by a <code>0x</code> prefix.}}
== Basic Controls ==
The emulator has a text area for data entryentering and editing code, a small bit-mapped graphics screen (32x32 pixels), a character screen (80x25 characters), a debug area, a memory monitor, and a message area.
These controls are available at the top of the screen:
* Assemble - assembles the code in the text area, placing the resulting binary machine language code at $0600 and outputting any error messasges to the message area.
* Run - runs the assembled code, ''if'' it assembled correctly. While the code is running, this button becomes a Stop button.
* Reset - changes resets the PC to $0600, clears state of the bitmap and character displays, and clears emulator (see the stack [[#Peripherals and zero pageMemory Map|Memory Map]] section below).* Hexdump - shows , in hexadecimal, the hexadecimal values stored in memory starting at $0600
* Disassemble - shows a combined hexdump and disassembly of code at $0600
* Notes - displays notes about the emulator in the message area.
The Speed slider lets you adjust the speed of the emulator from about 1% of native 6502 performance (left) to roughly full native speed (right). Setting the speed slider to a lower setting can be useful for debugging and for viewing the progress of operations on the displays.
There are also controls to Save and Load the text area to/from local storage on the computer on which it is running (as a download/upload); this works nicely with a local git repository (or clone).
== Assembler Capabilities ==
The assembler accepts these inputs:
=== Instructions ===
* 6502 assembler instructions, optionally prefixed with a label and a colon. Examples:
** simple instruction: <code>STA $10</code>
** instruction with a label: <code>LOOP: STA ($10),Y</code>
*** when a label is used, the address of the label can be referenced using the label name: <code>JMP LOOP</code>
=== Directives ===
* Origin assignment: You can tell the assembler where to assemble the following code with this syntax: <code>*=$XXXX</code> where XXXX is an address in hexadecimal. Multiple origin assignments may be used. Example: <code>*=$1800</code>
* "define" directive: Macro assignments may be created with the "define" directive: <code>define macro value</code> -- for example: <code>define WHITE $01</code> -- the macro value will be substituted into lines wherever the macro name appears (e.g., <code>LDA #WHITE</code>).
* "dcb" directive: the Define Constant Byte (dcb) directive will cause the assembler to place individual byte values into memory. These byte values may be in hexadecimal prefixed with $, decimal with no prefix, or single printable non-space characters quoted with double quotes.
=== High and Low Label Bytes ===
* The low byte of the label X can be accessed as <X and the high byte can be accessed as >X. For example, this code will load the low byte of the label "start" into the A register: <code>LDA #<START</code> - note that this only works with labels, and not with macros.
* You can use labels and origin assignment together to get a label for any address in the system. For example, to get a label pointing to the first byte of the character display, you could place this at the end of your program:
*=$f000
DISPLAY:
You could then create a pointer to that address at $0027 with this code:
LDA #<DISPLAY
STA $27
LDA #>DISPLAY
STA $28
=== Comments ===
* any characters on a line following an unquoted semicolon <code>;</code> are treated as a comment and ignored.
== Using the Debugger ==
== Using the Monitor ==
Selecting the Monitor checkbox will display the specified region of memory as code is executed. For example, specifying a start of $00 and a length of $ff 100 will display the entire zero page. Once enabled, the monitor may not display until the code is executed (via Run button).
== Turning the Text Screen On/Off ==
The checkbox labeled "Text Screen" can be used to hide the character display to free up more screen space for editing code.Note also that the character display can be used for additional program memory (whether the display is enabled or not) when it's not required for output. == Peripherals and Memory Map ==The entire 64K address space is available and is populated with RAM except for peripherals and a small ROM area. Visually, the memory map looks like this: {| border="1" cellpadding="2" cellspacing="0" width="100%"!Page(s)!!Address Range!!Description!!Subdivided Address Range!!Description|-|rowspan="4"|$00||rowspan="4"|$0000-$00FF||rowspan="4"|Zero Page||$0000-$00FD||Fast-access variable storage. Your software can use this region as you see fit.|-|$00F5-$00FD||Variables used by the ROM routines -- Do not use this region if you are using the ROM routines.|-|$00FE||Random number generator.|-|$00FF||Last key pressed on keyboard -- See description below|-|$01||$0100-$01FF||Stack|| ||Hardware stack - values are pushed on to the stack by the PHA, PHP, JSR, and BRK instructions (plus hardware interrupts), and pulled from the stack by the PLA, PLP, RTS, and RTI instructions. The stack is first-in/last out (FILO) aka last-in, first-out (LIFO), and it descends in memory. After 256 bytes have been pushed on the stack, the stack will overflow back to the beginning and the oldest data will be overwritten. The current stack location is tracked in the Stack Pointer (SP) register.|-|$02-$05||$0200-$05FF||Bitmapped Display|| ||32x32 pixel graphics display -- See description below.|-|$06-$EF||$0600-$EFFF||Program Memory|| ||RAM available for program use. By default, programs will be assembled starting at memory location $0600. This space is available for software and data. The arrangement and use of this memory is left to the programmer.|-|$F0-FC||$F000-$FCFF||Character Display|| ||80 colummn x 25 line character display for text messages -- See description below.|-|$FD||$FD00-$FDFF||Reserved|| ||This memory range is reserved for future ROM expansion.|-|rowspan="3"|$FE-$FF||rowspan="3"|$FE00-$FFFF||rowspan="3"|ROM||$FE00-FF80||This region is occupied by a small Read-Only Memory (ROM) image that contains input-output routines for the character display and keyboard.|-|$FF81-$FFF9||Entry point table - This table consists of 3-byte "entry points" for the ROM routines. To access a particular routine, use the Jump to SubRoutine (JSR) instruction with the corresponding entry point. This arrangement allows the ROM image to be revised without changing the entry point locations. See [[#ROM Routines|ROM Routines]] below for details on the available entry points.|-|$FFFA-$FFFF||Hardware vectors - On a hardware 6502 system, three 2-byte pointers (or "vectors") are used to access software routines to handle non-maskable interrupts (NMI) and the BRK instruction (vector $FFFA), CPU reset (vector $FFFC), and hardware interrupt (IRQ) (vector $FFFF). Since this is an emulator, these vectors are not used.|}
== Example Code ==
See the [[6502 Emulator Example Code]] page.
== Source Code ==
The emulator's source code can be found at https://github.com/ctyler/6502js ... Pull Requests are welcome.