Difference between revisions of "6502"

From SizeCoding
Jump to: navigation, search
Line 23: Line 23:
 
* 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
−
 
−
== Atari 8-bit family ==
 
−
The systems in this family are: Atari 400, 800, 5200, 1200XL, 600XL, 800XL, 130XE, 65XE, 800XE and XEGS.<br />
 
−
 
−
The Atari 8-bit systems consists of the 6502 with custom hardware for graphics and sound.
 
−
 
−
=== Setting up ===
 
−
Setting up your development platform for the Atari 8bit systems is quite easy, first get the following tools:
 
−
 
−
* 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
 
−
 
−
==== Sync with frame  ====
 
−
<syntaxhighlight lang="6502">
 
−
RTCLOK      equ $0012
 
−
      lda RTCLOK+2
 
−
waits
 
−
      cmp RTCLOK+2
 
−
      beq waits
 
−
</syntaxhighlight>
 
−
 
−
Or if you don't mind trashing RTCLOK
 
−
 
−
<syntaxhighlight lang="6502">
 
−
RTCLOK      equ $0012
 
−
waits
 
−
      lsr RTCLOK+2
 
−
      bcc waits
 
−
</syntaxhighlight>
 
−
 
−
Which is two bytes shorter.
 
−
 
−
==== 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 8-bit use the POKEY chip to generate sound.
 
−
* https://en.wikipedia.org/wiki/POKEY
 
−
 
−
==== BASIC ====
 
−
<syntaxhighlight lang="6502">
 
−
; from Analog, 1985-09,pp.25-32
 
−
*=$2000
 
−
AUDF1=$D200
 
−
AUDC1=$D201
 
−
AUDCTL=$D208
 
−
SKCTL=$D20F
 
−
 
−
.MACRO SOUND ; voice,pitch,dist,vol;,dur
 
−
lda #%2
 
−
sta AUDF1+2*%1
 
−
    lda #[[%3 * 16] | %4] ;lda #[[%3 shl 4] or %4]
 
−
    sta AUDC1+2*%1
 
−
.ENDM
 
−
 
−
lda #0
 
−
sta AUDCTL
 
−
lda #3
 
−
sta SKCTL
 
−
 
−
SOUND 0,121,10,8
 
−
 
−
jmp *
 
−
</syntaxhighlight>
 
−
==== 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/
 

Revision as of 08:19, 10 March 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