English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 22 March 2020, 15:56   #1
itpedersen
Registered User

 
Join Date: Oct 2019
Location: Denmark
Posts: 5
Asm one. Horizontal demonstration

Need a example for a small copper amiga program that can demonstranter how to control the beam the horizontal way. For instance draw a rectangle in the middel of the screen... The vertical way seems more logical... Cant figur out the horizontal way
itpedersen is offline  
Old 23 March 2020, 23:13   #2
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,598
Quote:
Originally Posted by itpedersen View Post
Need a example for a small copper amiga program that can demonstranter how to control the beam the horizontal way. For instance draw a rectangle in the middel of the screen... The vertical way seems more logical... Cant figur out the horizontal way
I quickly wrote a tiny source text which shows that. You can ignore most of the code, except the copper list and the macros used by it. Note that this simplified example only works for rectangles which do not cross vpos 256.
Code:
        include "graphics/gfxbase.i"
        include "custom.i"


; Program parameters
BGCOLOR         equ     $aaa    ; background color
RCOLOR          equ     $844    ; rectangle color
RVPOS           equ     100     ; rectangle's vertical start position
RHPOS           equ     120     ; rectangle's horizontal start position
RWIDTH          equ     80
RHEIGHT         equ     50


; AmigaOS constants
EXECBASE        equ     4

; exec LVOs
CloseLibrary    equ     -414
OpenLibrary     equ     -552

; graphics LVOs
LoadView        equ     -222
WaitTOF         equ     -270


; Copper macros
CMOVE   macro   ; register,value
        dc.w    \1,\2
        endm

CWAIT   macro   ; vpos,hpos
        dc.w    ((\1)&$ff)<<8|(((\2)&$fe)|1)
        dc.w    $fffe
        endm

CEND    macro
        dc.w    $ffff,$fffe
        endm


        section code,code

;---------------------------------------------------------------------------
; Program start from CLI. WB-start is not supported.

        ; take over system
        bsr     init
        beq     .2

        ; execute main routine and wait for mouse button to exit
        bsr     main
.1:     btst    #6,$bfe001
        bne     .1

        ; restore system
.2:     bsr     exit
        moveq   #0,d0
        rts


;---------------------------------------------------------------------------
init:
; Save current state and take over the system.
; -> a6 = CUSTOM
; -> Z-flag indicates error

        move.l  (EXECBASE).w,a6

        ; open graphics.library
        lea     GfxName(pc),a1
        moveq   #33,d0
        jsr     OpenLibrary(a6)
        move.l  d0,_GfxBase
        beq     .1

        ; save currently active View and load a NULL-View
        move.l  d0,a6
        move.l  gb_ActiView(a6),ActiView
        sub.l   a1,a1
        jsr     LoadView(a6)
        jsr     WaitTOF(a6)
        jsr     WaitTOF(a6)

        ; disable all interrupts and DMA
        lea     CUSTOM,a6
        move.w  #$8000,d1
        move.w  INTENAR(a6),d0
        or.w    d1,d0
        move.w  d0,Oldintena
        move.w  DMACONR(a6),d0
        or.w    d1,d0
        move.w  d0,Olddmacon
        not.w   d1
        move.w  d1,INTENA(a6)
        move.w  d1,DMACON(a6)

.1:     rts

GfxName:
        dc.b    "graphics.library",0
        even


;---------------------------------------------------------------------------
exit:
; Restore the system and the display to its previous state.

        move.l  _GfxBase,d1
        beq     .1                      ; init failed, nothing to restore

        ; reenable system DMA and interrupts
        lea     CUSTOM,a5
        move.w  #$7fff,d0
        move.w  d0,INTENA(a5)
        move.w  d0,DMACON(a5)
        move.w  Olddmacon,DMACON(a5)
        move.w  Oldintena,INTENA(a5)

        ; restore system View
        move.l  d1,a6
        move.l  ActiView,a1
        jsr     LoadView(a6)
        move.l  gb_copinit(a6),COP1LC(a5)

        ; close graphics.library
        move.l  a6,a1
        move.l  (EXECBASE).w,a6
        jsr     CloseLibrary(a6)

.1:     rts


;---------------------------------------------------------------------------
main:
; Display a rectangle using the Copper.
; a6 = CUSTOM

        ; load copper list and enable Copper-DMA
        move.l  #clist,COP1LC(a6)
        move.w  #$8280,DMACON(a6)
        rts


        section copper,data_c

clist:
        CMOVE   COLOR00,BGCOLOR
CUR_VP  set     RVPOS
        rept    RHEIGHT
        CWAIT   CUR_VP,RHPOS
        CMOVE   COLOR00,RCOLOR
        CWAIT   CUR_VP,RHPOS+RWIDTH
        CMOVE   COLOR00,BGCOLOR
CUR_VP  set     CUR_VP+1
        endr
        CEND


        section bss,bss

_GfxBase:
        ds.l    1
ActiView:
        ds.l    1
Oldintena:
        ds.l    1
Olddmacon:
        ds.l    1
It depends on two include files. gfxbase.i is from the official SDK. custom.i defines all hardware registers and CUSTOM=$dff000. You certainly have something similar.
I don't like addresses instead of symbols for hardware registers. It looks so messy.
phx is offline  
Old 26 March 2020, 00:05   #3
itpedersen
Registered User

 
Join Date: Oct 2019
Location: Denmark
Posts: 5
Thanks... Did not Know about the macros...

Gave me something to think about


Quote:
Originally Posted by phx View Post
I quickly wrote a tiny source text which shows that. You can ignore most of the code, except the copper list and the macros used by it. Note that this simplified example only works for rectangles which do not cross vpos 256.
Code:
        include "graphics/gfxbase.i"
        include "custom.i"


; Program parameters
BGCOLOR         equ     $aaa    ; background color
RCOLOR          equ     $844    ; rectangle color
RVPOS           equ     100     ; rectangle's vertical start position
RHPOS           equ     120     ; rectangle's horizontal start position
RWIDTH          equ     80
RHEIGHT         equ     50


; AmigaOS constants
EXECBASE        equ     4

; exec LVOs
CloseLibrary    equ     -414
OpenLibrary     equ     -552

; graphics LVOs
LoadView        equ     -222
WaitTOF         equ     -270


; Copper macros
CMOVE   macro   ; register,value
        dc.w    \1,\2
        endm

CWAIT   macro   ; vpos,hpos
        dc.w    ((\1)&$ff)<<8|(((\2)&$fe)|1)
        dc.w    $fffe
        endm

CEND    macro
        dc.w    $ffff,$fffe
        endm


        section code,code

;---------------------------------------------------------------------------
; Program start from CLI. WB-start is not supported.

        ; take over system
        bsr     init
        beq     .2

        ; execute main routine and wait for mouse button to exit
        bsr     main
.1:     btst    #6,$bfe001
        bne     .1

        ; restore system
.2:     bsr     exit
        moveq   #0,d0
        rts


;---------------------------------------------------------------------------
init:
; Save current state and take over the system.
; -> a6 = CUSTOM
; -> Z-flag indicates error

        move.l  (EXECBASE).w,a6

        ; open graphics.library
        lea     GfxName(pc),a1
        moveq   #33,d0
        jsr     OpenLibrary(a6)
        move.l  d0,_GfxBase
        beq     .1

        ; save currently active View and load a NULL-View
        move.l  d0,a6
        move.l  gb_ActiView(a6),ActiView
        sub.l   a1,a1
        jsr     LoadView(a6)
        jsr     WaitTOF(a6)
        jsr     WaitTOF(a6)

        ; disable all interrupts and DMA
        lea     CUSTOM,a6
        move.w  #$8000,d1
        move.w  INTENAR(a6),d0
        or.w    d1,d0
        move.w  d0,Oldintena
        move.w  DMACONR(a6),d0
        or.w    d1,d0
        move.w  d0,Olddmacon
        not.w   d1
        move.w  d1,INTENA(a6)
        move.w  d1,DMACON(a6)

.1:     rts

GfxName:
        dc.b    "graphics.library",0
        even


;---------------------------------------------------------------------------
exit:
; Restore the system and the display to its previous state.

        move.l  _GfxBase,d1
        beq     .1                      ; init failed, nothing to restore

        ; reenable system DMA and interrupts
        lea     CUSTOM,a5
        move.w  #$7fff,d0
        move.w  d0,INTENA(a5)
        move.w  d0,DMACON(a5)
        move.w  Olddmacon,DMACON(a5)
        move.w  Oldintena,INTENA(a5)

        ; restore system View
        move.l  d1,a6
        move.l  ActiView,a1
        jsr     LoadView(a6)
        move.l  gb_copinit(a6),COP1LC(a5)

        ; close graphics.library
        move.l  a6,a1
        move.l  (EXECBASE).w,a6
        jsr     CloseLibrary(a6)

.1:     rts


;---------------------------------------------------------------------------
main:
; Display a rectangle using the Copper.
; a6 = CUSTOM

        ; load copper list and enable Copper-DMA
        move.l  #clist,COP1LC(a6)
        move.w  #$8280,DMACON(a6)
        rts


        section copper,data_c

clist:
        CMOVE   COLOR00,BGCOLOR
CUR_VP  set     RVPOS
        rept    RHEIGHT
        CWAIT   CUR_VP,RHPOS
        CMOVE   COLOR00,RCOLOR
        CWAIT   CUR_VP,RHPOS+RWIDTH
        CMOVE   COLOR00,BGCOLOR
CUR_VP  set     CUR_VP+1
        endr
        CEND


        section bss,bss

_GfxBase:
        ds.l    1
ActiView:
        ds.l    1
Oldintena:
        ds.l    1
Olddmacon:
        ds.l    1
It depends on two include files. gfxbase.i is from the official SDK. custom.i defines all hardware registers and CUSTOM=$dff000. You certainly have something similar.
I don't like addresses instead of symbols for hardware registers. It looks so messy.
itpedersen is offline  
Old 26 March 2020, 01:27   #4
Antiriad_UK
OCS forever!

Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 187
Quote:
Originally Posted by phx View Post
I quickly wrote a tiny source text which shows that. You can ignore most of the code, except the copper list and the macros used by it. Note that this simplified example only works for rectangles which do not cross vpos 256.
I thought I was the only one with a CMOVE macro
Antiriad_UK is offline  
Old 26 March 2020, 10:29   #5
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 49
Posts: 519
Obviously when you create a macro you are free to do it anyway you like, but is there a reason to deviate from standard motorola's order move #value,destination in CMOVE?

Just curious if it's a random thing or not...
alkis is offline  
Old 26 March 2020, 11:49   #6
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 581
Quote:
Originally Posted by alkis View Post
Obviously when you create a macro you are free to do it anyway you like, but is there a reason to deviate from standard motorola's order move #value,destination in CMOVE?

Just curious if it's a random thing or not...
It's a copper instruction stored as word pairs in memory. It is not a 68000 instruction. The copper interprets the 2 words as "register" (1st word) and "data to write to that register" (2nd word)
DanScott is offline  
Old 26 March 2020, 12:44   #7
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 49
Posts: 519
Quote:
Originally Posted by DanScott View Post
It's a copper instruction stored as word pairs in memory. It is not a 68000 instruction. The copper interprets the 2 words as "register" (1st word) and "data to write to that register" (2nd word)
Code:
; Copper macros
CMOVE   macro   ; value, register
        dc.w    \2,\1
        endm
why not like that? (that was my question)
alkis is offline  
Old 26 March 2020, 14:04   #8
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 581
Quote:
Originally Posted by alkis View Post
Code:
; Copper macros
CMOVE   macro   ; value, register
        dc.w    \2,\1
        endm
why not like that? (that was my question)
I guess, the main reason is that most Amiga coders (before using macros) are used to seeing it as regular data statements eg..

dc.w $0180,$0000
DanScott is offline  
Old 26 March 2020, 15:03   #9
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 49
Posts: 519
Quote:
Originally Posted by DanScott View Post
I guess, the main reason is that most Amiga coders (before using macros) are used to seeing it as regular data statements eg..

dc.w $0180,$0000
Yeah, but they are used to
Code:
move.w #0,$180
and I'd assume that
Code:
CMOVE 0,$180
is closer. I guess we can leave it that is a preference thing and you can have it however you like it.
alkis is offline  
Old 26 March 2020, 15:49   #10
DanScott
Lemon. / Core Design

DanScott's Avatar
 
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 581
Quote:
Originally Posted by alkis View Post
Yeah, but they are used to
Code:
move.w #0,$180
and I'd assume that
Code:
CMOVE 0,$180
is closer. I guess we can leave it that is a preference thing and you can have it however you like it.
but it's not related in any way to Motorola 68k
DanScott is offline  
Old 26 March 2020, 16:00   #11
roondar
Registered User

 
Join Date: Jul 2015
Location: The Netherlands
Posts: 1,710
I'd say the reason it's "register, value" is that this is how the Copper actually works.
See, it's not actually "register, value" from the perspective of the Copper. Rather, it's "instruction, value".

Or perhaps better put it's more like "MOVE|register,value", "WAIT|condition,value", "SKIP|condition,value".
Edit: the one thing that makes this a bit less clear is that the value for the MOVE instruction is actually 0, so you end up with just the register number as the instruction after the or.

The macro's are just there to make things a bit easier and I'd argue it's best to stick with the way the Copper works as the Copper is it's own little processor and not a 68k (like DanScott pointed out)

Last edited by roondar; 26 March 2020 at 16:25.
roondar is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
EHB, HAM6 and HAM8 demonstration pictures? TroyWilkins Amiga scene 95 22 November 2016 11:24
Tool to convert asm to gnu asm (gas) Asman Coders. Asm / Hardware 6 12 October 2013 13:45
Demonstration and Interview with Jan Derogee trackah123 Amiga scene 2 22 February 2009 14:19
First public demonstration of Dragon(Elbox) ppill News 15 10 December 2006 00:29
Report from mA1-C/OS4 demonstration In Istanbul Paul News 0 21 December 2004 12:37

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:49.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.07253 seconds with 14 queries