Author Topic: 6502 ASM  (Read 9226 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
6502 ASM
« on: April 01, 2008 »
6502 Assembler for someone who know all about them like Shockwave who used code in assembler in old days  ;D

http://www.6502asm.com/

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 6502 ASM
« Reply #1 on: April 01, 2008 »
nop

6502C was the Commodore 64 CPU, as well as the one used in the BBC Micro range.
It was crap in a lot of ways, even in the day.  To access a 16bit address, to address 64kb, it needed 2 instructions and it only had 3  8bit registers (compare with variables) called X,Y,A.  Most of the instructions could only operate on A.  The Z80, in the competing products, had 16bit addressing and 10 times as many registers.

Here endeth another history lesson.

Jim

Challenge Trophies Won:

Offline Agent Smith

  • ZX 81
  • *
  • Posts: 24
  • Karma: 3
    • View Profile
Re: 6502 ASM
« Reply #2 on: April 01, 2008 »
What a coincidence :) I'm currently writing a 6502 Simulator, in Forth.
I still have my old Apple IIe, Atari 800XL and I recently bought a replica Apple I kitset, which I've yet to put together.

Actually, the very first computer I ever owned was a Sinclair ZX81, but I never much liked the Z80.
What I really want is to build my own Atari 800 laptop, like Ben Heckendorn.

Yep the 6502 was pretty basic alright, but it was so dirt cheap when it came out, all the home computer vendors (and hobbyists) jumped for it, so it really helped foment the golden era of home computing.

However, IMO the best CPU of the 8-bit era was undoubtedly the 6809.

« Last Edit: April 01, 2008 by Agent Smith »

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 6502 ASM
« Reply #3 on: April 01, 2008 »
The old NES had one of these too didnt it? and I think I heard that there was no multiply command but I may be wrong here. 8 bit Chips really were minimalistic

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: 6502 ASM
« Reply #4 on: April 01, 2008 »
My c64 assembler was on a cartridge, and as crappy as it was it was great too.

C64 basic was so utterly horrible that you may as well have just learned 6502 instead.. And many did :D
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: 6502 ASM
« Reply #5 on: April 01, 2008 »
Yup, no multiply command on the 6502, or the Z80 for that matter.  Lots of people wrote routines that used self generating, self modifying code to do multiplies.
I remember reading an article about Nodes of Yesod for the ZX Spectrum.  The programmer says he allocated 20bytes for the data structure for each object but ended up only using 19bytes.  But he never bothered fixing it because the x20 routine was shorter and faster than the x19 one :)

Jim
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #6 on: April 01, 2008 »
Quote
To access a 16bit address, to address 64kb, it needed 2 instructions

I had an electron (actually still got it somewhere) and although it had 32k RAM (&0000-&7FFF) it also had 32k ROM (&8000-&FFFF) all of which I thought could be addressed directly with absolute addressing even though you couldn't write to the ROM.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #7 on: April 01, 2008 »
This has just reminded me of something else, I had to write a multiplication routine among other things on a 6800 (very similar to the 6502). The thing was a PCB with the cpu and some ram and an eprom nailed onto a bit of wood with a 6 digit hex display and keypad, that's the british defence industry for ya.

Offline stormbringer

  • Time moves by fast, no second chance
  • Amiga 1200
  • ****
  • Posts: 453
  • Karma: 73
    • View Profile
    • www.retro-remakes.net
Re: 6502 ASM
« Reply #8 on: April 02, 2008 »
ahhh great memories! I remember the hours I spend writing an integer division routine for my 65816 assembler (brother of the 6502)... endless headaches.. and I'm not sure I fully understood the algorithm at that time  ??? ??? ???
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: 6502 ASM
« Reply #9 on: April 03, 2008 »
It was god like working in ASM on the C64 between the ages of 10 and 20.

Removing cycle flicker, destroying borders, adding sprites and building basic maths routines for 3d and line drawing.

I want a VIC II chip for my Pentium.

Sweet memories.
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #10 on: April 04, 2008 »
As I've metioned in the 'dungeon crawler' thread, I'm thinking about trying something out in 6502. I have some ideas about how to go about the final drawing stage but going to have to look into dealing with transforms and divides for perspective and things like that. I imagine fixed point is most likely the way to go and would probably prefer performance over precision as it's going to be a bit wobbly anyway.

Has anyone got any links that might be relevant? And would anyone be interested in helping out?

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 6502 ASM
« Reply #11 on: April 04, 2008 »
Hugi number 15 has a really good artical about it. BTW fixed point can be more acurate than floating point within a given range so long as you dont overflow or underflow because its basically integer math. But of course Floats allow for greater precision.

Hero are some x86 implementations that work using 16:16 fixed point most are from the Hugi artical but the division routines were given to me by a member of the FASM board cos the divide in Hugi didnt work unless the result was garaunteed to be an integer :
*ff ... fixed point to fixed point
*fi ... fixed point to integer

Code: [Select]
name 'fixedpoint.inc'
fixfi macro B,A
    mov eax,[A]
    shl eax,10h
    mov [B],eax
fixfi endm
intif macro B,A
    mov eax,[A]
    shr eax,10h
    mov [B],eax
intif endm
fracf macro B,A
    mov edx,[A]
    xor eax,eax
    xchg ax,dx
    mov [B],eax
fracf endm
modff macro C,A,B
    mov  eax,[A]
    mov  edx,eax
    sar  edx,16
    shl  edx,16
    idiv [B]
    xor  edx,edx
    xchg eax,edx
    xchg  ax,dx
    mov  [C],eax
modff endm
addff macro C,A,B
    mov  eax,[A]
    add  eax,[B]
    mov  [C],eax
addff endm
addfi macro C,A,B
    mov  eax,[A]
    shl  eax,16
    add  eax,[B]
    mov  [C],eax
addfi endm
subff macro C,A,B
    mov  eax,[A]
    sub  eax,[B]
    mov  [C],eax
subff endm
subfi macro C,A,B
    mov  eax,[A]
    shl  eax,16
    sub  eax,[B]
    mov  [C],eax
subfi endm
mulff macro C,A,B
    mov  eax,[A]
    mov  edx,[B]
    imul edx
    shrd eax,edx
    mov  [C],eax
mulff endm
mulfi macro C,A,B
    mov  eax,[A]
    mov  edx,[B]
    imul edx
    mov  [C],eax
mulfi endm
divff macro C,A,B
    mov  eax,[A]
    mov  edx,eax
    sar  edx,16
    shl  edx,16
    idiv [b]
    mov  [C],eax
divff endm
divfi macro C,A,B
    mov  eax,[A]
    cdq
    idiv [B]
    mov  [C],eax
divfi endm

Heres a link to the divison fix
http://board.flatassembler.net/topic.php?t=7681
« Last Edit: April 04, 2008 by rain_storm »

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #12 on: April 04, 2008 »
Thanks rain_storm. There's going to be a fair bit more work with it though as the 6502 only has 3 8 bit registers and no divide or multiply instruction. I may have to make some compromises and got for something less than 16:16 too.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 6502 ASM
« Reply #13 on: April 04, 2008 »
Yeah that does make it more complicated perhaps there is already functions for fixed point math in 6502. Im interested in fixed point too so if I see something of interest i'll post it here

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #14 on: April 04, 2008 »
'perhaps there is already functions for fixed point math in 6502'

It has 8 bit add and subtract :( that is all.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 6502 ASM
« Reply #15 on: April 04, 2008 »
Sorry I ment code on the web for 6502 that provides that functionality lol

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #16 on: April 04, 2008 »
Ah LOL, I get ya now. That's the sort of thing I was meaning when I asked if anyone had any links to anything too.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #17 on: April 04, 2008 »
I've dug out my old manual, it has some examples of multiply and divide, only for 8 bit but it's a start.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: 6502 ASM
« Reply #18 on: April 05, 2008 »
http://6502.org/source/ <- has something of interest

Natural Log - LOG
Common Log - LOG10
Exponential - EXP
Floating Add - FADD
Floating Subtract - FSUB
Floating Multiply - FMUL
Floating Divide - FDIV
Convert Floating to Fixed - FIX
Convert Fixed to Floating - FLOAT


Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: 6502 ASM
« Reply #19 on: April 05, 2008 »
Hmmmm, very cool, thanks rain_storm K+.