English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 23 January 2006, 17:12   #1
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Starting a program

When writing an asm program what sort of structure should the program take?

How should it be written, what should you take into consideration etc?

----

Do you write the routine(s) that take over the system, open a screen, set colours etc.. or some other way maybe?

Are there any examples of the correct way to do this?
BippyM is offline  
Old 23 January 2006, 17:31   #2
Alter
Oldskool
 
Join Date: Dec 2005
Location: Norway
Age: 51
Posts: 28
Ususally i do it like this:
1.) Initialize : that is take over the system and put the copperlist in #$dff080, initialize DMACON ( #$dff09a) with the desired bits (if i will use sprites, bplane blitter and so on...)
2) I make what i call a waitmouse routine , like this:
wm:
cmp.b #$ff,$dff006 ; Vpos , rasterwait !!
bne.s wm

bsr Myroutine ; from here you jump to all your routines
; you can have as many bsr and routines
; as you want
btst #6,$bfe001 ; Check mousebutton
bne.s wm
Bsr exit
rts

My rotuine:
bla
blablabla
rts
Copperlist:
dc.w #$xxx,$xxx ; First i set DIWSTRT
and so on..... ; then DIWSTOP
; FFDSTRT
; FFDSTOP
; MODULO 0
; MODULO 1
; BPLCON0
; BPLCON1
; BPLANE POINTERS
; SPRPOINTERS
; BACKGR.COLORS
; BPLANE COLORS
dc,w #$ffff,$fffe ; END

exit:
bla bla
all the exit stuff
rts

This is how I do it and i feel personally that this is very tidy and clean way to do it, but thats me :-)
I upped in the zone last week a startupcode which was coded in this way. If you want it I can up it again...... :-)

Last edited by Alter; 23 January 2006 at 20:29.
Alter is offline  
Old 23 January 2006, 17:41   #3
NOB
Zone Friend
 
Join Date: Aug 2005
Location: Germany
Age: 52
Posts: 424
Quote:
Originally Posted by Alter
2) I make what i call a waitmouse routine , like this:
wm:
cmp.b #$ff,$dff006 ; Vpos
bne.s wm
RASTWAIT


lea $dff000,a2
rastwait:cmp.b #255,$6(a2)
bne.s rastwait
NOB is offline  
Old 23 January 2006, 18:20   #4
NOB
Zone Friend
 
Join Date: Aug 2005
Location: Germany
Age: 52
Posts: 424
here is another startup (oldskool A500)
nearly exactly the same as from alter.


lea $dff000,a2
move.w #$4000,$9a(a2);stopp irqs
lea copperlist,a3
move.l a3,$84(a2)
rastwait:
cmp.b #255,$6(a2);Vpos
bne.s rastwait
jsr dosomestuff
btst #6,$bfe001 ;waitmouse
beq.s end
jmp rastwait(pc)
end: move.w #$c000,9a(a2);enable irqs
rts
copperlist:
dc.w $0100,...
dc.w $ffff,$fffe
NOB is offline  
Old 23 January 2006, 20:26   #5
Alter
Oldskool
 
Join Date: Dec 2005
Location: Norway
Age: 51
Posts: 28
The only thing when you do it this way you should save the old copperlist and then return it when you exit the program , like this:
In the start, before anything else:
move.l #4,a0
move.l #156(a0),a0
move.l #38(a0),coppersave

then in the Exit just put :
move.l coppersave,$dff080

Remember also to make a label:
coppersave:
dc.l 0
Alter is offline  
Old 23 January 2006, 20:43   #6
NOB
Zone Friend
 
Join Date: Aug 2005
Location: Germany
Age: 52
Posts: 424
Quote:
Originally Posted by Alter
The only thing when you do it this way you should save the old copperlist and then return it when you exit the program , like this:
In the start, before anything else:
move.l #4,a0
move.l #156(a0),a0
move.l #38(a0),coppersave

then in the Exit just put :
move.l coppersave,$dff080

Remember also to make a label:
coppersave:
dc.l 0
(hmm , maybe 084/086).

but the startup modifies the coppersecond location high/low.
084/086.
It´s not necessary to rescue copperfirts location high/low.
080/082
NOB is offline  
Old 23 January 2006, 21:24   #7
Alter
Oldskool
 
Join Date: Dec 2005
Location: Norway
Age: 51
Posts: 28
Ahh I see , you move the coplist to $dff084 , I didnt see that :-) I use $dff080 for my coplist...:-)
Alter is offline  
Old 28 January 2006, 15:02   #8
Jherek Carnelia
Dazed and Confused
 
Jherek Carnelia's Avatar
 
Join Date: Dec 2001
Location: portsmouth/uk
Posts: 242
Quote:
Originally Posted by bippym
When writing an asm program what sort of structure should the program take?

How should it be written, what should you take into consideration etc?

----

Do you write the routine(s) that take over the system, open a screen, set colours etc.. or some other way maybe?

Are there any examples of the correct way to do this?
You might try this - from How To Code 6...


* Startup.asm - A working tested version of startup from Howtocode6
*
* Written by CJ of SAE... Freeware. Share and Enjoy!
*
* This code sets up one of two copperlists (one for PAL and one for NTSC)
* machines. It shows something to celebrate 3(?) years since the Berlin
* wall came down :-) Press left mouse button to return to normality.
* Tested on Amiga 3000 (ECS/V39 Kickstart) and Amiga 1200 (AGA/V39)
*
* $VER: startup.asm V6.tested (17.4.92)
* Valid on day of purchase only. No re-admission. No rain-checks.
* Now less bugs and more likely to work.
*
* Tested with Hisoft Devpac V3 and Argasm V1.09d

opt l-,o+ ; auto link, optimise on

opt o3- ; add this for Devpac 2+
machine mc68000 ; and this for Devpac 3

section mycode,code ; need not be in chipram

incdir "include:"
include "exec/types.i"
include "exec/funcdef.i" ; keep code simple and
include "exec/exec_lib.i" ; easy to read - use
include "exec/exec.i" ; the includes!
include "libraries/dosextens.i"
include "graphics/gfxbase.i"
include "graphics/graphics_lib.i"

include "iconstartup.i" ; Allows startup from icon


move.l 4.w,a6
sub.l a1,a1 ; Zero - Find current task
jsr _LVOFindTask(a6)

move.l d0,a1
moveq #127,d0 ; task priority to very high...
jsr _LVOSetTaskPri(a6)

move.l 4.w,a6 ; get ExecBase
lea gfxname(pc),a1 ; graphics name
moveq #33,d0 ; Kickstart 1.2 or higher
jsr _LVOOpenLibrary(a6)
tst.l d0
beq End ; failed to open? Then quit

move.l d0,gfxbase
move.l d0,a6
move.l gb_ActiView(a6),wbview
; store current view address

sub.l a1,a1 ; clear a1
jsr _LVOLoadView(a6) ; Flush View to nothing
jsr _LVOWaitTOF(a6) ; Wait once
jsr _LVOWaitTOF(a6) ; Wait again.

; Note: Something could come along inbetween the LoadView and
; your copper setup. But only if you decide to run something
; else after you start loading the demo. That's far to stupid
; to bother testing for in my opininon!!! If you want
; to stop this, then a Forbid() won't work (WaitTOF() disables
; Forbid state) so you'll have to do Forbid() *and* write your
; own WaitTOF() replacement. No thanks... I'll stick to running
; one demo at a time :-)

move.l 4.w,a6
cmp.w #36,LIB_VERSION(a6) ; check for Kickstart 2
blt.s .oldks ; nope...

; kickstart 2 or higher.. We can check for NTSC properly...

move.l GfxBase,a6
btst #2,gb_DisplayFlags(a6) ; Check for PAL
bne.s .pal
bra.s .ntsc

.oldks ; you really should upgrade! Check for V1.x kickstart


move.l 4.w,a6 ; execbase
cmp.b #50,VBlankFrequency(a6) ; Am I *running* PAL?
bne.s .ntsc

.pal move.l #mycopper,$dff080 ; bang it straight in.
bra.s .lp

.ntsc move.l #mycopperntsc,$dff080


.lp btst #6,$bfe001 ; ok.. I'll do an input
bne.s .lp ; handler next time.


CloseDown:
move.l wbview(pc),a1
move.l gfxbase,a6
jsr _LVOLoadView(a6) ; Fix view
jsr _LVOWaitTOF(a6)
jsr _LVOWaitTOF(a6) ; wait for LoadView()

move.l gb_copinit(a6),$dff080 ; Kick it into life

move.l a6,a1
move.l 4.w,a6
jsr _LVOCloseLibrary(a6) ; close graphics.library

End: moveq #0,d0 ; clear d0 for exit
rts ; back to workbench/cli


wbview dc.l 0
gfxbase dc.l 0
gfxname dc.b "graphics.library",0



section mydata,data_c ; keep data & code seperate!

mycopper dc.w $100,$0200 ; otherwise no display!
dc.w $180,$00
dc.w $8107,$fffe ; wait for $8107,$fffe
dc.w $180
co dc.w $f0f ; background red
dc.w $d607,$fffe ; wait for $d607,$fffe
dc.w $180,$ff0 ; background yellow
dc.w $ffff,$fffe
dc.w $ffff,$fffe

mycopperntsc
dc.w $100,$0200 ; otherwise no display!
dc.w $180,$00
dc.w $6e07,$fffe ; wait for $6e07,$fffe
dc.w $180,$f00 ; background red
dc.w $b007,$fffe ; wait for $b007,$fffe
dc.w $180,$ff0 ; background yellow
dc.w $ffff,$fffe
dc.w $ffff,$fffe
Jherek Carnelia is offline  
Old 07 February 2006, 22:50   #9
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
CJ of SAE/Comrade J of Share and Enjoy.... Jolyon Ralph, thats a blast from the past
Galahad/FLT is offline  
Old 10 February 2006, 15:11   #10
[A1]
 
Posts: n/a
Quote:
Originally Posted by Alter
The only thing when you do it this way you should save the old copperlist and then return it when you exit the program , like this:
In the start, before anything else:
move.l #4,a0
move.l #156(a0),a0
move.l #38(a0),coppersave

then in the Exit just put :
move.l coppersave,$dff080

Remember also to make a label:
coppersave:
dc.l 0
Sorry, but the coppersave code wont work like this! The adress of the original copperlist is saved in the structure of the graphics-library... so open it up and move the value which is stored at offset 38 from gfxbase back to $dff080.

move.l #156(a0),a0
move.l #38(a0),coppersave

I really would like to see the assembler which assembles those instructions above!

if a0 would point to gfxbase you would do

move.l 38(a0), coppersave

or directly

move.l 38(a0),$dff080
 
Old 10 February 2006, 15:35   #11
Alter
Oldskool
 
Join Date: Dec 2005
Location: Norway
Age: 51
Posts: 28
sorry, yes of course wrong spelling:
move.l 4,a0
move.l 156(a0),a0
move.l 38(a0),coppersave
.......
coppersave:
dc.l 0

It should compile correctly now :-)
Alter 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
External windows program communicating with program running inside WinUAE xxxxx support.WinUAE 10 19 February 2013 09:27
Paint program or program....... amigagenie request.Apps 2 29 January 2013 19:56
For a beginner what Program and Program language would you recommend? amigang New to Emulation or Amiga scene 5 27 March 2012 13:06
P-UAE boots directly when starting the program ipp0 support.OtherUAE 3 24 August 2011 09:31
Calling another program from a compiled Amos program...? andyr support.Apps 3 24 October 2004 23:47

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 17:34.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.15259 seconds with 15 queries