Difference between revisions of "6502"

From SizeCoding
Jump to: navigation, search
m (ANTIC and GTIA info links)
m (Childishbeat moved page 6502 based CPUs to 6502: Less verbose)
 
(42 intermediate revisions by 8 users not shown)
Line 7: Line 7:
  
 
=== The 6502 processor  ===
 
=== The 6502 processor  ===
The 6502 processor can be seen as the 8bit micro ARM chip.  
+
The 6502 processor can be seen as the 8-bit micro ARM chip.  
It has only has 3 registers (Accumilator, IX and IY registers) and only a handful of instructions to work with.
+
It has only has 3 registers (Accumulator, X and Y registers) and a handful of instructions to work with.
  
 
=== Adressing modes ===
 
=== Adressing modes ===
Line 17: Line 17:
  
 
=== General 6502 Resources ===
 
=== General 6502 Resources ===
 +
* 6502.org http://www.6502.org/
 +
* 6502 instruction reference http://www.6502.org/tutorials/6502opcodes.html
 +
* 6502 books http://retro.hansotten.nl/6502-sbc/
 
* 6502 Assembler tutorial https://dwheeler.com/6502/oneelkruns/asm1step.html
 
* 6502 Assembler tutorial https://dwheeler.com/6502/oneelkruns/asm1step.html
 
* Easy 6502 code tester https://skilldrick.github.io/easy6502/
 
* Easy 6502 code tester https://skilldrick.github.io/easy6502/
 
* Synthetic instructions https://wiki.nesdev.com/w/index.php/Synthetic_instructions#8-bit_rotate
 
* Synthetic instructions https://wiki.nesdev.com/w/index.php/Synthetic_instructions#8-bit_rotate
  
 
+
== 6502 Based Platforms ==
== Atari 8bit family ==
+
*'''[[Atari 8Bit]]''' - Atari 8-Bit Family (Atari XL/XE, etc.)
The Atari XE/XL systems consists of the 6502 with custom hardware for graphics and sound.
+
*'''[[Apple II]]''' - Apple II(e)
 
+
*'''[[Commodore 64]]''' - Commodore 64
=== Setting up ===
+
*'''[[BBC Micro]]''' - Acorn BBC Micro/Master/Electron.
Setting up your development platform for the Atari 8bit systems is quite easy, first get the following tools:
+
*'''[[Atari Lynx]]''' - Atari Lynx Handheld
 
 
* Assembler: MADS Assembler - This assembler has nice macros for creating Binaries and SNA snapshot files out of the box. You can download it at https://mads.atari8.info/
 
* Emulator(s): I Found Altirra to work best for my usecase. Make sure to use the original Rev2 rom for best compatibility.
 
 
 
==== Special Memory Adresses ====
 
* FRAMECOUNTER_HIGH = 19
 
* FRAMECOUNTER_LOW  = 20
 
 
 
=== Video display ===
 
Video display on the Atari 8bit systems use the ANTIC and GTIA chips. Information can be found here:
 
* https://en.wikipedia.org/wiki/ANTIC
 
* https://www.atariarchives.org/agagd/chapter1.php
 
 
 
==== Getting something on screen ====
 
<syntaxhighlight lang="6502">
 
;fill screen with charset,(88,89)=an address
 
org $600; free 6th page:600-6ff
 
ldy #0
 
fl: tya
 
sta(88),y
 
iny
 
bne fl
 
jmp *
 
</syntaxhighlight>
 
 
 
To be added soon.
 
 
 
<syntaxhighlight lang="6502">
 
SDMCTL = $022f
 
HPOSP0  = $d000
 
SIZEP0  = $d008
 
GRAFP0  = $d00d
 
COLPM0  = $d012
 
 
 
FRAMECOUNTER_HIGH = 19
 
FRAMECOUNTER = 20
 
WSYNC = $d40a
 
VCOUNT = $d40b
 
 
 
sinewave = $0600 ; to $06ff
 
 
 
org $80
 
 
 
main
 
; disable all graphics/colors
 
ldx #0
 
stx SDMCTL
 
 
 
ldy #$7f
 
sty SIZEP0 ; size p0=127
 
 
ldx #0
 
ldy #$3f
 
make_sine:
 
value_lo
 
lda #0
 
clc
 
delta_lo
 
adc #0
 
sta value_lo+1
 
value_hi
 
lda #0
 
delta_hi
 
adc #0
 
sta value_hi+1
 
 
sta sinewave+$c0,x
 
sta sinewave+$80,y
 
eor #$7f
 
sta sinewave+$40,x
 
sta sinewave+$00,y
 
 
lda delta_lo+1
 
adc #8
 
sta delta_lo+1
 
bcc nothing
 
inc delta_hi+1
 
nothing
 
inx
 
dey
 
bpl make_sine
 
 
 
updateloop:
 
; vblank
 
lda VCOUNT
 
bne updateloop
 
 
 
; clear graphics
 
sta HPOSP0
 
sta GRAFP0
 
 
 
ldy #0
 
lda #47
 
sta COLPM0
 
yloop:
 
tya          ; graphics shape = y
 
sta WSYNC
 
sta GRAFP0
 
 
 
; a = sin(frame+y)+48
 
tya
 
adc FRAMECOUNTER
 
tax
 
lda sinewave,x
 
adc #48
 
sta HPOSP0
 
               
 
                iny
 
                bne yloop
 
jmp updateloop
 
 
 
run main
 
</syntaxhighlight>
 
 
 
=== Sound ===
 
The Atari 8bit systems use the Pokey chip to generate sound.
 
To be added soon.
 
 
 
==== Make some noise ====
 
To be added soon.
 
 
 
 
 
 
 
=== Additional Resources ===
 
Sizecoding resource for the Atari 8bit are:
 
* Mapping the Atari https://www.atariarchives.org/mapping/
 
* Atari 8bit Memory map https://www.atariarchives.org/mapping/memorymap.php
 
* Fready's undocumented 6502 opcodes https://github.com/FreddyOffenga/6502
 
* Atari OS Rev2 disassembly for MADS assembler https://github.com/ilmenit/A800-OS-XL-Rev2
 
* Fready's github https://github.com/FreddyOffenga/
 
 
 
== Commodore 64 ==
 
The Commodore systems consists of the 6502 with custom hardware for graphics and sound.
 
 
 
=== Setting up ===
 
Setting up your development platform for the Commodore systems is quite easy, first get the following tools:
 
 
 
* Assembler: To be added
 
* Emulator(s): VICE is the way to go
 
 
 
=== Autoboot ===
 
<syntaxhighlight lang="6502">
 
*=$0326
 
        .word start             
 
        .byte $ed,$f6
 
start
 
; rest of code
 
</syntaxhighlight>
 
Will give you autoboot and more space directly. (though writing through to $0400 will load it onto the screen unless you move the pointers)
 
 
 
=== Video display ===
 
Video display on the Commodore, it has the following video modes:
 
 
 
To be added soon.
 
 
 
==== Getting something on screen ====
 
To be added soon.
 
 
 
 
 
=== Sound ===
 
The Commodore 64 uses the famous SID chip to generate sound.
 
To be added soon.
 
 
 
==== Make some noise ====
 
To be added soon.
 
 
 
=== Additional Resources ===
 
* Codebase 64 https://codebase64.org/doku.php?id=base:start
 
 
 
== Apple II ==
 
The Apple II is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak.
 
 
 
=== Setting up ===
 
* ACME 6502 cross-assembler(https://sourceforge.net/projects/acme-crossass/)
 
* Apple Commander (http://applecommander.sourceforge.net) for batch compilation
 
* AppleWin emulator (https://github.com/AppleWin/AppleWin/releases). Supports Mockingboard card(AY-8910+speech synthesier), HDD, Z80 card(for CP/M), mouse etc.
 
* CiderPress(https://a2ciderpress.com)
 
 
 
Compilation can be done as follows (master.dsk can be found with applewin)
 
<syntaxhighlight>
 
acme hl.asm
 
java -jar AppleCommander-1.3.5.jar -d master.dsk hl
 
java -jar AppleCommander-1.3.5.jar -p master.dsk hl B 24576 < hl.bin
 
</syntaxhighlight>
 
 
 
=== Memory Map ===
 
<syntaxhighlight lang="6502">
 
  0-255 $0-$FF    ZERO-PAGE SYSTEM STORAGE
 
  256-511      $100-$1FF    SYSTEM STACK
 
  512-767      $200-$2FF    KEYBOARD CHARACTER BUFFER
 
  768-975      $300-$3CF    OFTEN AVAILABLE AS FREE SPACE FOR USER PROGRAMS
 
  976-1023    $3D0-3FF    SYSTEM VECTORS
 
1024-2047    $400-$7FF    TEXT AND LO-RES GRAPHICS PAGE 1 <--- !!!
 
2048-LOMEM    $800-LOMEM  PROGRAM STORAGE
 
2048-3071    $800-$BFF    TEXT AND LO-RES GRAPHICS PAGE 2 OR FREE SPACE
 
3072-8191    $C00-$1FFF  FREE SPACE UNLESS RAM APPLESOFT IS IN USE
 
8192-16383  $2000-$3FFF  HI-RES PAGE 1 OR FREE SPACE <--- !!!
 
16384-24575  $4000-$5FFF  HI-RES PAGE 2 OR FREE SPACE
 
24576-38999  $6000-$95FF  FREE SPACE AND STRING STORAGE
 
38400-49151  $9600-$BFFF  DOS
 
49152-53247  $C000-$CFFF  I/O HARDWARE (RESERVED)
 
53248-57343  $D000-$DFFF  APPLESOFT IN LANGUAGE CARD OR ROM
 
57344-63487  $E000-$F7FF  APPLESOFT OR INTEGER BASIC IN LANGUAGE CARD OR ROM
 
63488-65535  $F800-$FFFF  SYSTEM MONITOR
 
</syntaxhighlight>
 
 
 
=== Display ===
 
 
 
=== Graphics Modes ===
 
: Text Mode 40x24, for Apple IIe available 80x25 - use PR#3 for switch mode, or hardware switch
 
: LowRes 40x48, 16 colors: https://en.wikipedia.org/wiki/Apple_II_graphics
 
: Hires mode 280x192,6 colors: https://www.xtof.info/blog/?p=768
 
https://mrob.com/pub/xapple2/colors.html
 
https://archive.org/details/HiRes_Color_Graphics_on_the_Apple_II_Computer_by_Wozniak
 
 
 
However for sizecoding, you almost never want to do direct-access to graphics for Apple II in size-coding because the Apple II graphics modes are horrible.  The only fast way to do things is with large lookup tables.  To do hires you need to divide by 7 which as you can imagine is a bit difficult to do compactly on 6502. Double-hires is even crazier on top of that.  Deater did manage a color-bar style effect in double-hires in 128B but that was doing some crazy tricks with the firmware BASIC routines, definitely not direct-access.
 
 
 
Lores and Hires can be mixed modes and full-graphics
 
The screen structure is called memory holes(https://retrocomputing.stackexchange.com/questions/2534/what-are-the-screen-holes-in-apple-ii-graphics). The GBASCALC($F847) procedure is used to calculate the address of the horizontal line : IN:reg.A=Y, out : GBASL/GBASH($26/$27)=address. See also https://www.callapple.org/uncategorized/use-of-apple-ii-color-graphics-in-assembly-language/
 
 
 
==== Getting something on screen ====
 
Here is an example of a XOR texture, created by g0blinish
 
<syntaxhighlight lang="6502">
 
*=$6000
 
!to "HL.bin", plain ; set output file and format
 
!cpu 6502 ; set processor type
 
 
 
GBASL = $26
 
GBASH = $27
 
SETGR    =    $FB40 ; setup LoRes
 
GBASCALC = $F847 ; calc Address
 
 
 
CLRTEXT =  $C050 ;display graphics
 
SETTEXT =  $C051 ;display text
 
 
 
CLRMIXED = $C052 ;clear mixed mode- enable full graphics
 
SETMIXED = $C053 ;enable graphics/text mixed mode
 
 
 
PAGE1 =    $C054 ;select text/graphics page1
 
PAGE2 =    $C055 ;select text/graphics page2
 
 
 
CLRHIRES = $C056 ;select Lo-res
 
SETHIRES = $C057 ;select Hi-res
 
 
 
TMP= $FA
 
 
 
JSR  SETGR      ;GR
 
BIT CLRMIXED ; full screen
 
 
 
LDA #0 ; A=0
 
STA TMP ; POKE $FA,A
 
 
 
YLP ;
 
LDA TMP ; A=PEEK($FA)
 
; LSR ; A=A/2
 
JSR GBASCALC
 
LDY #0;Y=0
 
 
 
XLP TYA ; A=Y
 
EOR TMP ; A=A xor PEEK($FA)
 
and #$0F ; A=A and 15
 
TAX ; X=A
 
LDA COLORS,X ;A=PEEK(COLORS+X)
 
STA(GBASL),Y ; POKE PEEK($26)+256*PEEK($27)+Y,A
 
INY ; Y=Y+1
 
CPY #40 ; Y=40?
 
BNE XLP
 
INC TMP ; POKE $FA,PEEK($FA)+1
 
LDA TMP ; A=PEEK($FA)
 
CMP #24 ; A=24?
 
BNE YLP
 
 
M1 JMP M1 ; replace to RTS
 
 
 
COLORS ;N*17, pixel format is AAAABBBB, AAAA - upper dot, BBBB - lower dot
 
!byte $00,$11,$22,$33,$44,$55,$66,$77
 
!byte $88,$99,$AA,$BB,$CC,$DD,$EE,$FF
 
</syntaxhighlight>
 
 
 
==== Sound  ====
 
Here is an example for using the speaker, based onthe following basic program:
 
 
 
<syntaxhighlight lang="basic">
 
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256
 
; 60  CALL 770: RETURN
 
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K
 
; 100  FOR K = 1 TO N:V = V(K):P = P(K)
 
; 110  GOSUB 50
 
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96
 
</syntaxhighlight>
 
 
 
<syntaxhighlight lang="6502">
 
*=$6000
 
!to "HL.bin", plain ; set output file and format
 
!cpu 6502 ; set processor type
 
 
 
;start
 
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K
 
; 100  FOR K = 1 TO N:V = V(K):P = P(K)
 
ini:
 
lda #70
 
sta cnt+1
 
lda #music&255
 
sta gotbyte+1
 
lda #music/256
 
sta gotbyte+2
 
 
 
lop:
 
;V
 
jsr gotbyte
 
sta L300
 
jsr gotbyte
 
;P
 
jsr gotbyte
 
sta L301
 
jsr gotbyte
 
clc
 
adc #1
 
sta L320
 
jsr beep
 
 
dec cnt+1
 
cnt lda #70
 
bne lop
 
; 110  GOSUB 50
 
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256
 
; 60  CALL 770: RETURN
 
jmp ini
 
gotbyte
 
lda music
 
inc gotbyte+1
 
bne noinch
 
inc gotbyte+2
 
noinch
 
rts
 
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96
 
beep:
 
ldy #1
 
ldx #1
 
loc_302:
 
LDA $C030
 
 
 
loc_305:
 
DEY
 
BNE loc_30D
 
DEC L301
 
loc_30B:
 
BEQ loc_316
 
 
 
loc_30D:
 
DEX
 
BNE loc_305
 
LDX L300
 
JMP loc_302
 
loc_316:
 
DEC L320
 
BNE loc_30B
 
RTS
 
L301 !byte 0
 
L300 !byte 0
 
L320 !byte 0
 
music
 
!word 76,192,85,64,96,64,102,64,114,128,114,64,96,64,102,64,114,64,128,64
 
!word 114,64,152,64,171,64,152,512,76,192,85,64,96,64,102,64,114,128,114,64
 
!word 96,64,102,64,114,64,128,64,114,64,152,64,171,64,152,512,85,64,85,64
 
!word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64
 
!word 96,64,102,128,114,64,128,64,128,128,114,64,128,64,114,512,85,64,85,64
 
!word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64
 
!word 96,64,102,128,114,64,128,64,128,64,128,128,96,64,85,64,96,64,102,64,114,64,114,64
 
</syntaxhighlight>
 
 
 
=== Additional Resources ===
 
* Deater's page on Apple II sizecoding http://www.deater.net/weave/vmwprod/demos/sizecoding.html
 
* Article on double hi-res http://www.battlestations.zone/2017/04/apple-ii-double-hi-res-from-ground-up.html
 
* Applesoft Hi-Res Subroutines : http://hackzapple.org/scripts_php/index.php?menu=5&mod=ASM&sub=AAL&sub2=8112&PHPSESSID=f65fabfd0cdbf56b6bdc0ddac25117c6#a2
 
 
 
== Atari Lynx ==
 
The Atari Lynx consists of the 6502 with custom hardware for graphics and sound.
 
 
 
=== Setting up ===
 
Setting up your development platform for the Atari Lynx:
 
 
 
* Assembler: -
 
* Emulator(s): -
 
 
 
=== Video display ===
 
To be added soon.
 
 
 
==== Getting something on screen ====
 
To be added soon.
 
 
 
 
 
=== Sound ===
 
To be added soon.
 
 
 
==== Make some noise ====
 
To be added soon.
 
 
 
=== Additional Resources ===
 
Sizecoding resource for the Atari Lynx are sparse
 
* 42Bastian's website (link to be added)
 

Latest revision as of 10:41, 8 April 2022

Introduction

Wanting to start sizecoding on a 6502 platform in this day and age can be tough.

6502.jpg

So here is a bit of help to get you started:

The 6502 processor

The 6502 processor can be seen as the 8-bit micro ARM chip. It has only has 3 registers (Accumulator, X and Y registers) and a handful of instructions to work with.

Adressing modes

To be added.

Zero page

When using the 6502 for sizecoding, you'll mostly be working from zeropage

General 6502 Resources

6502 Based Platforms