(Hopefully) simple example request

This area for discussing Assembly language.

(Hopefully) simple example request

Postby paulshoe70 » Tue Oct 24, 2017 1:55 pm

Hi everyone,

Although I am very familiar with programming in BASIC, I am struggling somewhat to learn assembly language. I'm going through William Barden's book, primarily. Although it is a great resource, it only touches upon how to create graphics in assembly language which is primarily what I am wanting to do at this point.

I learn best by looking at simple examples, and then messing around with the code to see what happens.

With that in mind, it would be super helpful to me if someone could provide a simple coding example in assembly language that does the following:

1. Draws a square whose four sides are 48 pixels in length with an "X" drawn in the middle where the X is simply two lines extending corner to corner.
2. Can be called from a BASIC program using the USR command... which I believe means it should include an ORG $7000 (or thereabouts) and an RTS at the end
3. Suitable to be displayed in PMODE 4 starting at page 2 (PMODE 4,2)

This will show me how to draw vertical lines and 45 degree lines.

I've figured out how to draw horizontal lines in assembly... that's straightforward enough. However, I haven't figured out vertical and 45 degree lines yet.

Thanks! :)

-Paul
paulshoe70
 
Posts: 8
Joined: Fri Oct 20, 2017 8:52 am

Re: (Hopefully) simple example request

Postby ogsteviestrow » Tue Oct 24, 2017 2:08 pm

Glad to have you here Paul, check an earlier post, Rick Adams is posting some assembly routines he's creating to generate CoCo 3 graphics, some of those may be useful.
I'm sure you'll get some responses here, though, we got a good group already.
Steve Strowbridge aka The Original Gamer Stevie Strow
Host of CoCoTALK! the nation's leading live talk show featuring the Tandy Color Computer

ogStevieStrow@gmail.com

http://ogsteviestrow.com
http://cocotalk.live
http://imacoconut.com
http://8bit256.com
User avatar
ogsteviestrow
Site Admin
 
Posts: 54
Joined: Mon Sep 18, 2017 11:31 pm
Location: Port Saint Lucie, FL

Re: (Hopefully) simple example request

Postby paulshoe70 » Tue Oct 24, 2017 2:26 pm

Hi Steve!

I read Rick's post and stepped through his code earlier today, as a matter of fact. What is simple for my main man Rick is still too advanced for me. :lol:

-Paul
paulshoe70
 
Posts: 8
Joined: Fri Oct 20, 2017 8:52 am

Re: (Hopefully) simple example request

Postby Invisible » Tue Oct 24, 2017 2:36 pm

I can probably help you out there....

vertical lines are just 1px at a bit position spaced by 32 bytes

pmode4 uses 1 bit per pixel - so you need to specify wich bit(s) you want set

/Simon :ugeek:
Invisible
 
Posts: 12
Joined: Tue Oct 17, 2017 1:50 pm

Re: (Hopefully) simple example request

Postby paulshoe70 » Tue Oct 24, 2017 2:57 pm

Hi Simon,

That makes sense to me, and i think something like this would display the first pixel at the top of the line at coordinates 0,0 of the PMODE 4,2 page:

LDA #$80
LDX #$1200
<label> STA ,X
...
..
.
CMPX #$1420
BNE <label>

But how do I increment X by 32? Do I use the LEAX operand, like an "LEAX +32,X" maybe? Seems like I tried that and it didn't work. Is there an ADDX operand?

-Paul
paulshoe70
 
Posts: 8
Joined: Fri Oct 20, 2017 8:52 am

Re: (Hopefully) simple example request

Postby Invisible » Tue Oct 24, 2017 3:07 pm

leax 32,x would work there

LDA #$80
LDX #$1200
<label> STA ,X
leax 32,x
CMPX #$1420
BNE <label>

another way (cheaper) is to use ABX (thats unsigned btw)

so
lda #$80
ldb #$20
ldx #$1200
loop sta ,x
abx
cmpx #$1420
blo loop
Invisible
 
Posts: 12
Joined: Tue Oct 17, 2017 1:50 pm

Re: (Hopefully) simple example request

Postby paulshoe70 » Tue Oct 24, 2017 3:16 pm

Ah ha!!!!

I guess I didn't get to the chapter about operand ABX (or I read it and then forgot which is pretty likely). Thanks Simon!! :D
paulshoe70
 
Posts: 8
Joined: Fri Oct 20, 2017 8:52 am

Re: (Hopefully) simple example request

Postby Invisible » Tue Oct 24, 2017 3:44 pm

i just cooked a *quick* square here for you

i wouldn't *normally* code like that, but it's simple enough for you to read and hopefully understand.....

it's just PURE assembly at $7000 (sets up it's own pmode 4 and pcls etc)

lemme know when you want to get to diagonals :ugeek:

Code: Select all
   org   $7000
********************************
start   lda   #$f0      ;set up pmode 4 (at $400)
   sta   $ffc3      ;sam MODE bits
   sta   $ffc5
   sta   $ff22      ;VDG REGISTER
********************************
   ldd   #$0      ;a/b=0
   ldx   #$400      ;screen offset
pcls   std   ,x++
   cmpx   #$400+6144   ;pmode screen is 6144 bytes (256*192 pixels 1 bit per pixel)
   blo   pcls

********************************
* Draw 2 horizontal lines
********************************
   ldx   #$d0c      ;start position of line
   jsr   hline
   ldx   #$d0c+(32*48)   ;start position of line (48 pixels further down)
   jsr   hline

********************************
* Draw 2 vertical lines
********************************
   ldx   #$d0c+32   ;start position
   lda   #$80      ;BIT VALUE FOR PIXEL POSITION IN BYTE
   jsr   vline

   ldx   #$d0c+(5+32)   ;start position
   lda   #$1      ;BIT VALUE FOR PIXEL POSITION IN BYTE
   jsr   vline


poo   jmp   poo

********************************
*horizontal
*we KNOW we want 48 px (6 bytes)
********************************
hline   ldd   #$ffff
   std   ,x++
   std   ,x++
   std   ,x++
   rts

********************************
* Vertical line
********************************
vline   ldb   #47      ;line counter   
vloop   sta   ,x      ;store it
   leax   32,x      ;next vertical pixel
   decb         ;done count ??
   bne   vloop      ;nope
   rts

   end    start
Last edited by Invisible on Wed Oct 25, 2017 12:55 am, edited 1 time in total.
Invisible
 
Posts: 12
Joined: Tue Oct 17, 2017 1:50 pm

Re: (Hopefully) simple example request

Postby paulshoe70 » Tue Oct 24, 2017 3:57 pm

This is excellent and really helpful to me, thank you!
paulshoe70
 
Posts: 8
Joined: Fri Oct 20, 2017 8:52 am

Re: (Hopefully) simple example request

Postby Invisible » Tue Oct 24, 2017 4:04 pm

you're welcome...

the diagonals we can do a little *trick* (cyclic bit rotation) while traversing downwards from left to right

/Simon :ugeek:
Invisible
 
Posts: 12
Joined: Tue Oct 17, 2017 1:50 pm

Next

Return to Assembly

Who is online

Users browsing this forum: No registered users and 1 guest

cron