Page 1 of 2

(Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 1:55 pm
by paulshoe70
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

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 2:08 pm
by ogsteviestrow
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.

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 2:26 pm
by paulshoe70
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

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 2:36 pm
by Invisible
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:

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 2:57 pm
by paulshoe70
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

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 3:07 pm
by Invisible
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

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 3:16 pm
by paulshoe70
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

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 3:44 pm
by Invisible
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

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 3:57 pm
by paulshoe70
This is excellent and really helpful to me, thank you!

Re: (Hopefully) simple example request

PostPosted: Tue Oct 24, 2017 4:04 pm
by Invisible
you're welcome...

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

/Simon :ugeek: