(Hopefully) simple example request

This area for discussing Assembly language.

Re: (Hopefully) simple example request

Postby nowhereman999 » Tue Oct 24, 2017 8:04 pm

HI Simon,

This is great stuff to help beginners out with understanding graphics using assembly language. It will also be a great resource in the future for other new comers to CoCo graphics!

Great job!

One thing that will help your code look better on the forums is to click on the {code} button (on the top bar with the Bold, Italics and other buttons are) and put your assembly code between the {code} and {/code} this will keep the formatting of the spaces and make the source code easier to read. You can go back to your previous posts and edit them and hit preview to see how it looks.

Cheers,
Glen
nowhereman999
 
Posts: 33
Joined: Mon Sep 18, 2017 11:43 pm

Re: (Hopefully) simple example request

Postby paulshoe70 » Wed Oct 25, 2017 11:15 am

Here is my first run at code for a diagonal line. It seems to be working... but I may have over-complicated it... Other than using the stack to store and retrieve the outside loop counter variable, I couldn't figure out another way to do a nested loop...

Code: Select all
**********************
* DRAW DIAGONAL LINES
**********************
          LDX     #$1400
          JSR     DLINE
POO       JMP     POO

**********************
* DIAGONAL LINE
**********************
DLINE     LDB     #6          ; LOAD B WITH COUNTER OF 6 FOR SECTIONS OF 8 BITS
          PSHS    B           ; PUT COUNTER VALUE ON THE STACK
DLOOP     CLRB
          LDA     #$7F
          ORCC    #1          ; SET CC BIT TO 1
          LDB     #8          ; LOAD B WITH 8 COUNTER FOR BIT ROTATION
DLOOP1    STA     ,X          ; STORE A TO PUT PIXEL IN SCREEN
          LEAX    32,X        ; MOVE DOWN TO NEXT LINE
          RORA                ; MOVE PIXEL BIT TO THE RIGHT ONE PLACE
          DECB                ; DECREASE COUNTER BY 1
          BNE     DLOOP1      ; EQUAL TO ZERO?  IF NO THEN DLOOP1 AGAIN
          LEAX    1,X         ; MOVE TO THE RIGHT ONE BYTE
          PULS    B           ; RETRIEVE SECTION COUNTER
          DECB                ; DECREASE THIS BY 1
          PSHS    B           ; STORE IT AGAIN
          CMPB    #0          ; COMPARE B TO ZERO
          BNE     DLOOP       ; EQUAL TO ZERO?  IF NO THEN DLOOP AGAIN
          RTS
paulshoe70
 
Posts: 8
Joined: Fri Oct 20, 2017 8:52 am

Re: (Hopefully) simple example request

Postby Invisible » Wed Oct 25, 2017 11:21 am

Code: Select all
********************************
* Diagonal down
********************************
ddown   ldb   #6      ;6 bytes of diagonal
again   lda   ,x      ;get current screen location
   ora   pixel      ;*OR* in the new value   
   sta   ,x      ;set byte on screen
   leax   32,x      ;next line
   lsr       pixel       ;rotate the byte
         bcc       again      ;no carry so we are NOT done with our byte
         ror       pixel      ;reintroduce the carry falloff
   leax   1,x      ;next byte   
nocy0   decb
   bne   again
   rts      
Last edited by Invisible on Wed Oct 25, 2017 12:07 pm, edited 1 time in total.
Invisible
 
Posts: 12
Joined: Tue Oct 17, 2017 1:50 pm

Re: (Hopefully) simple example request

Postby Invisible » Wed Oct 25, 2017 11:37 am

MAYBE you are TOO complicated there....

HERE is the complete code (annotated) that will draw your square + first diagonal

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
   bsr   hline
   ldx   #$d0c+(32*48)   ;start position of line (48 pixels further down)
   bsr   hline

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

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

********************************
* Draw downward diagonal
********************************
   ldx   #$d0c+32   ;start position
   lda   #$40      ;BIT VALUE FOR PIXEL POSITION IN BYTE
   sta   pixel
   bsr   ddown

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

********************************
* Diagonal down
********************************
ddown   ldb   #6      ;6 bytes of diagonal
again   lda   ,x      ;get current screen location
   ora   pixel      ;*OR* in the new value   
   sta   ,x      ;set byte on screen
   leax   32,x      ;next line
   lsr       pixel       ;rotate the byte
         bcc       again      ;no carry so we are NOT done with our byte
         ror       pixel      ;reintroduce the carry falloff
   leax   1,x      ;next byte   
nocy0   decb
   bne   again
   rts         
********************************
* Diagonal up
********************************


pixel   fcb   $40
   end    start


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

Re: (Hopefully) simple example request

Postby William Schaub » Thu Nov 02, 2017 4:46 pm

You can find a full datasheet for the SAM and VDG here along with a very interesting book (and audio lessons on "tape" ) that I'm slowly extracting programs from and adding to my github:

http://maltedmedia.com/6809/

https://github.com/wschaub/coco/tree/ma ... g_The_6809

One thing to note is the writes to the SAM. the value written to ffc3 and ffc5 doesn't matter anything written there will flip a control bit in the SAM chip (which unfortunately you can not query the state of) The value written to ff22 really does matter however and is a real read/write register that is part of one of the PIA chips that service the VDG along with a few other things.
William Schaub
 
Posts: 8
Joined: Mon Oct 16, 2017 9:08 pm

Previous

Return to Assembly

Who is online

Users browsing this forum: No registered users and 1 guest

cron