6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon May 20, 2024 9:26 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Pet 2001 assembly
PostPosted: Mon Jul 06, 2020 9:01 am 
Offline

Joined: Mon Jul 06, 2020 8:55 am
Posts: 5
Hi,

I'm a bloody beginner in Pet 2001's assembly language (or machine code) and I'm trying get an entrypoint...
Here a little BASIC-prg:

100 PRINTCHR$(147)
110 P=32807
120 POKEP,254:POKEP+40,97:POKEP+80,251
140 IF PEEK(151)=50 AND P>32846 THENPOKEP+80,32:P=P-40:GOTO120
150 IF PEEK(151)=18 AND P<33648 THENPOKEP,32:P=P+40:GOTO120
160 GOTO140

Is anybody here so kind and clever to post an assembly code for this?

Thank you very much,
Oldman


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Mon Jul 06, 2020 10:17 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10802
Location: England
Welcome! It would be good if we had a thread full of suggestions as to how to get started with assembly. And perhaps we do, but I don't see it right now. (I know this isn't directly answering your question, but it takes a lot of effort to write a good book, so we can hope a good book will be a good resource, perhaps even better than a quick forum post.)

Here's what I have found:
Tutorials and Primers (reference: specifically links to 9 books or web sites.)
First 6502 assembly program (thread in the Programming subforum)
6502 Assembler (thread in Newbies subforum)
Program-Writing: Where Do I Start? (chapter in Garth's primer)

I recommend easy6502, but learning styles differ, and a book might work better for you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Mon Jul 06, 2020 11:39 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
It's something like this in 6502.
Code:
p equ $20

 lda #147  ; L100
 jsr chrout
 lda #<32807 ; L110
 sta p+0
 lda #>32807
 sta p+1
loop:
 ldy #0 ; L120
 lda #254
 sta (p),y
 ldy #40
 lda #97
 sta (p),y
 ldy #80
 lda #251
 sta (p),y
wait:
 lda 151 ; L140/150 PEEK tests
 cmp #50
 beq up
 cmp #18
 beq down
 jmp wait: ; L160

up:
 lda p+0 ; L140
 cmp #<32846
 lda p+1
 sbc #>32846
 bmi wait
 ldy #80
 lda #32
 sta (p),y
 sec
 lda p+0
 sbc #40
 sta p+0
 bcs *+4
 dec p+1
 jmp loop

down:
 lda p+0 ; L150
 cmp #<33648
 lda p+1
 sbc #>33648
 bpl wait
 ldy #0
 lda #32
 sta (p),y
 clc
 lda p+0
 adc #40
 sta p+0
 bcc *+4
 inc p+1
 jmp loop

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Last edited by BitWise on Thu Jul 09, 2020 10:42 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Thu Jul 09, 2020 6:32 pm 
Offline

Joined: Mon Jul 06, 2020 8:55 am
Posts: 5
thank you very much, I'll look into it over the weekend...


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Thu Jul 09, 2020 7:42 pm 
Offline

Joined: Mon Jul 06, 2020 8:55 am
Posts: 5
BitWise wrote:
It's something like this in 6502.
Code:
p equ $20

...

basically, i think i understand what this code does... and how it does it. i fail at this line. It seems to be the declaration of the variable p, which is always referenced.

All 6502 assemblers also fail because of this - and I am not sure how to declare p.

thank you very much,
Oldman


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Thu Jul 09, 2020 8:13 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Many assemblers will accept "p = $20". It's basically defining p as a label pointing to a zero-page address, or equivalently as a constant.


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Thu Jul 09, 2020 11:02 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
I fixed a typo in the down comparison. I had two #< LSB constants. Now its:
Code:
 lda p+0 ; L150
 cmp #<33648
 lda p+1
 sbc #>33648

The 'equ' (or .equ) directive (equate) defines a symbol (p in this case) to have a specific value. I set p to $20, an address on zero page than is used as a pointer into the video RAM area. Some assemblers use '=' but that often creates a symbol you can change later on (X = X+1). A symbol created with equate can usually not be changed.

My own 6502 assembler generates code for control structures like if/then/else and loops. You could write this code like this:
Code:
                                             .6502

         00000020          = p               .equ    $20
         00001234          = chrout          .equ    $1234   ; Address of print subroutine

                                             .code
                                             .org    $2000

00:2000  A993              :                 lda #147  ; L100
00:2002  203412            :                 jsr chrout
00:2005  A927              :                 lda #<32807 ; L110
00:2007  8520              :                 sta p+0
00:2009  A980              :                 lda #>32807
00:200B  8521              :                 sta p+1
                                             repeat
00:200D  A000              :                  ldy #0 ; L120
00:200F  A9FE              :                  lda #254
00:2011  9120              :                  sta (p),y
00:2013  A028              :                  ldy #40
00:2015  A961              :                  lda #97
00:2017  9120              :                  sta (p),y
00:2019  A050              :                  ldy #80
00:201B  A9FB              :                  lda #251
00:201D  9120              :                  sta (p),y
                                              repeat
00:201F  A597              :                   lda 151 ; L140/150 PEEK tests
00:2021  C932              :                   cmp #50
00:2023  D01E              :                   if eq
00:2025  A520              :                    lda p+0 ; L140
00:2027  C94E              :                    cmp #<32846
00:2029  A521              :                    lda p+1
00:202B  E980              :                    sbc #>32846
00:202D  3011              :                    if pl
00:202F  A050              :                     ldy #80
00:2031  A920              :                     lda #32
00:2033  9120              :                     sta (p),y
00:2035  38                :                     sec
00:2036  A520              :                     lda p+0
00:2038  E928              :                     sbc #40
00:203A  8520              :                     sta p+0
00:203C  B002              :                     if cc
00:203E  C621              :                      dec p+1
                                                 endif
                                                endif
00:2040  4C6820            :                    break
                                               endif
00:2043  C912              :                   cmp #18
00:2045  D01E              :                   if eq
00:2047  A520              :                    lda p+0 ; L150
00:2049  C970              :                    cmp #<33648
00:204B  A521              :                    lda p+1
00:204D  E983              :                    sbc #>33648
00:204F  1011              :                    if mi
00:2051  A000              :                     ldy #0
00:2053  A920              :                     lda #32
00:2055  9120              :                     sta (p),y
00:2057  18                :                     clc
00:2058  A520              :                     lda p+0
00:205A  6928              :                     adc #40
00:205C  8520              :                     sta p+0
00:205E  9002              :                     if cs
00:2060  E621              :                      inc p+1
                                                 endif
                                                endif
00:2062  4C6820            :                    break
                                               endif
00:2065  4C1F20            :                  forever
00:2068  4C0D20            :                 forever

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Fri Jul 10, 2020 7:50 am 
Offline

Joined: Mon Jul 06, 2020 8:55 am
Posts: 5
BitWise wrote:
...
My own 6502 assembler generates code for control structures like if/then/else and loops. You could write this code like this:
..


which assembler do you use?

I'm really new to 6502 assembler. At uni I had to learn Siemens assembler, but that was a long time ago :D
so i don't even know which assembler is useful for getting started.

thanks a lot
Oldman


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Fri Jul 10, 2020 8:25 am 
Online
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
Oldman wrote:
which assembler do you use?

It's his own creation. You can get it at http://www.obelisk.me.uk/dev65/as65.html . I have it listed in my list of mostly free 65xx assemblers about half way down my links page at http://wilsonminesco.com/links.html#assem . The page has about 500 links mostly to 65xx things, things which I deemed worthy.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Fri Jul 10, 2020 10:04 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Here is a simple example with batch files for Windows.
Attachment:
dist 2020-07-10.zip [3.53 MiB]
Downloaded 64 times

It needs a Java runtime installed to run (run 'java -version' in a command window to see if you have one). If you convert the .BAT files to shell scripts it will run on Linux.

The Dev65.JAR actually contains all my assemblers as they are all built from a common base. The 65xx part alone is < 500K

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Last edited by BitWise on Fri Jul 10, 2020 10:32 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Fri Jul 10, 2020 10:25 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
And here it is for Linux;
Attachment:
dist-linux 2020-07-10.zip [3.53 MiB]
Downloaded 57 times

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Mon Jul 13, 2020 1:07 pm 
Offline

Joined: Mon Jul 06, 2020 8:55 am
Posts: 5
BitWise wrote:
Here is a simple example with batch files for Windows.
Attachment:
dist 2020-07-10.zip

It needs a Java runtime installed to run (run 'java -version' in a command window to see if you have one). If you convert the .BAT files to shell scripts it will run on Linux.

The Dev65.JAR actually contains all my assemblers as they are all built from a common base. The 65xx part alone is < 500K


thanks! i have unpacked the assembler and assembled the provided example - it works.

i have tested your code afterwards - it throws a lot of errors right at the beginning - are you using a different assembler?

thanks a lot,
oldman


Top
 Profile  
Reply with quote  
 Post subject: Re: Pet 2001 assembly
PostPosted: Mon Jul 13, 2020 3:40 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
Oldman wrote:
BitWise wrote:
Here is a simple example with batch files for Windows.
Attachment:
dist 2020-07-10.zip

It needs a Java runtime installed to run (run 'java -version' in a command window to see if you have one). If you convert the .BAT files to shell scripts it will run on Linux.

The Dev65.JAR actually contains all my assemblers as they are all built from a common base. The 65xx part alone is < 500K


thanks! i have unpacked the assembler and assembled the provided example - it works.

i have tested your code afterwards - it throws a lot of errors right at the beginning - are you using a different assembler?

thanks a lot,
oldman


Probably needs a bit of a prolog, like:
Code:
 .6502

 .code
 .org $1234


Which example of mine did you assemble? The structured one is cut from the listing file.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: