simple (?) cls routine to clear half the screen

All 680x0 related coding posts in this section please.

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

simple (?) cls routine to clear half the screen

Postby spiny » Mon Jul 30, 2012 9:34 pm

hi everyone,

I've been re-reading some more tutorials and i'm slowly trying them out, and i'm confused on what appears to be a really simple idea, a rout to clear half the screen. from the tutorial:

Code: Select all

cls2
   move.w   #2,-(a7)            ; get physbase (the address of screen memory being displayed on the monitor)
   trap   #14      
   addq.l   #2,a7      
   move.l   d0,a0               ; a0 points to screen
   move.w   #200-1,d1            ;
clrscr2
   move.w #160-1,d6
nested
   clr.w   (a0)+               ; all 0 means colour 0 :)
   dbra d6,nested
   adda.l #160*2,a0   
   dbra d1,clrscr2
   rts


in theory, according to the tutorial, this should load the screen address to a0, then clear 160 pixels, then add 160 to the screen address to jump to the next line, then loop 200 times.

but when I run it, it crashes with two bombs :D

i'm obviously missing something, the question is, what ? :)

cheers.

User avatar
Cyprian
Atari God
Atari God
Posts: 1518
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: simple (?) cls routine to clear half the screen

Postby Cyprian » Mon Jul 30, 2012 10:23 pm

here is your issue:

Code: Select all

adda.l #160*2,a0


this part clear 160 bytes (one full screen line in ST MID/LOW resolution):

Code: Select all

nested
   clr.w   (a0)+               ; all 0 means colour 0 :)
   dbra d6,nested


here you skip additional 320 bytes

Code: Select all

   adda.l #160*2,a0   


and repeat it 200 times:

Code: Select all

   move.w   #200-1,d1


(160+320)*200 = 96000

you just try to clear 96000 bytes area but the ST screen has 32000 bytes and Its placed at the end of memory. Therefore your access beyond 32766 byte, generates bus error.

Better tell us what exactly do you want to clear (Whole screen, upper half screen, lower part, left part, right part ect )
Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Mon Jul 30, 2012 10:37 pm

thanks cyprian, you're quite right, my maths was all over the place :D

I was trying to do this:

Code: Select all

cls2
   move.w   #2,-(a7)            ; get physbase (the address of screen memory being displayed on the monitor)
   trap   #14                  ; tos call
   addq.l   #2,a7               ; tos call
   move.l   d0,a0               ; a0 points to screen
   move.w   #100-1,d1            ; how many times (lines
clrscr2
   move.w #40-1,d6               ; half an ST low res line
nested
   clr.w   (a0)+               ; all 0 means colour 0 :)
   dbra d6,nested               ; loop d6 times
   adda.l #40*2,a0               ; skip last half of line
   dbra d1,clrscr2               ; loop d1 times
   rts                        ; the end


my first mistake was not reading the text of the tutorial correctly ... it was written to clear half the screen on a Falcon :D which is why the numbers don't add up :D

it appears to be working fine now ...

I was reading the tutorial earlier and thought that with some more loops, I could make a slightly more interesting screen clear by using smaller 'columns' and perhaps some pauses here and there. just for fun :)

FedePede04
Atari God
Atari God
Posts: 1072
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: simple (?) cls routine to clear half the screen

Postby FedePede04 » Mon Jul 30, 2012 10:46 pm

Hi

if it is for a 68000 processor then for me it look like to be a very ineffective routine
i don't know if it is the same for a Falcon

spiny wrote:thanks cyprian, you're quite right, my maths was all over the place :D

I was trying to do this:

Code: Select all

cls2
   move.w   #2,-(a7)            ; get physbase (the address of screen memory being displayed on the monitor)
   trap   #14                  ; tos call
   addq.l   #2,a7               ; tos call
   move.l   d0,a0               ; a0 points to screen
   move.w   #100-1,d1            ; how many times (lines
clrscr2
   move.w #40-1,d6               ; half an ST low res line
nested
   clr.w   (a0)+               ; all 0 means colour 0 :)
   dbra d6,nested               ; loop d6 times
   adda.l #40*2,a0               ; skip last half of line
   dbra d1,clrscr2               ; loop d1 times
   rts                        ; the end


my first mistake was not reading the text of the tutorial correctly ... it was written to clear half the screen on a Falcon :D which is why the numbers don't add up :D

it appears to be working fine now ...

I was reading the tutorial earlier and thought that with some more loops, I could make a slightly more interesting screen clear by using smaller 'columns' and perhaps some pauses here and there. just for fun :)
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Mon Jul 30, 2012 11:07 pm

FedePede04 wrote:Hi

if it is for a 68000 processor then for me it look like to be a very ineffective routine
i don't know if it is the same for a Falcon



I'm sure it's slow, but i'm trying to learn enough so I can 'read' example code and know what it does, which at the moment, it would seem I cannot :D

I still get a great sense of achievement when I make a little routine like this work, so it's all good practice :)

User avatar
Cyprian
Atari God
Atari God
Posts: 1518
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: simple (?) cls routine to clear half the screen

Postby Cyprian » Mon Jul 30, 2012 11:46 pm

this one should a bit be faster:

Code: Select all

cls2
   move.w   #2,-(a7)            ; get physbase (the address of screen memory being displayed on the monitor)
   trap   #14                  ; tos call
   addq.l   #2,a7               ; tos call
   move.l   d0,a0               ; a0 points to screen

   moveq.l  #0,d0
   move.w   #100-1,d1            ; how many times (lines
clrscr2
   REPT 20
     move.l   D0,(a0)+               ; all 0 means colour 0 :)
   ENDR
   lea   40*2(a0),a0               ; skip last half of line
   dbra d1,clrscr2               ; loop d1 times
   rts                        ; the end


and this one a much more faster:

Code: Select all

cls2
   move.w   #2,-(a7)            ; get physbase (the address of screen memory being displayed on the monitor)
   trap   #14                  ; tos call
   addq.l   #2,a7               ; tos call
   move.l   d0,a0               ; a0 points to screen
   lea   40*2(a0),a0

   moveq.l  #0,d0
   moveq.l  #0,d1
   moveq.l  #0,d2
   moveq.l  #0,d3
   move.w   #100-1,d7            ; how many times (lines
clrscr2
   REPT 5
     movem.l   D0-D3,-(a0)               ; all 0 means colour 0 :)
   ENDR
   lea   240(a0),a0               ; skip last half of line
   dbra d7,clrscr2               ; loop d1 times
   rts                        ; the end
Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Tue Jul 31, 2012 12:35 am

ok, the first one makes sense, and for the second one, is it moving a0 to the 'end' of the line then zeroing everything backwards towards the start of the line, in blocks of four ?

another possible daft question:

is REPT the same as 'unrolling' ?

thanks again :)

FedePede04
Atari God
Atari God
Posts: 1072
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: simple (?) cls routine to clear half the screen

Postby FedePede04 » Tue Jul 31, 2012 8:20 am

HI .

i think it is a good way to learn, looking after what other did, when you will both see good code and not so good code.

i have never code in dev. pack but i think that the REPT command is a marco command,
so it just paste the code between the REPT and ENDR the number times. so i this example it would past the code 5 times.

Movem, move the contain of more then one register, in this case to (a0)




spiny wrote:
FedePede04 wrote:Hi

if it is for a 68000 processor then for me it look like to be a very ineffective routine
i don't know if it is the same for a Falcon



I'm sure it's slow, but i'm trying to learn enough so I can 'read' example code and know what it does, which at the moment, it would seem I cannot :D

I still get a great sense of achievement when I make a little routine like this work, so it's all good practice :)
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: simple (?) cls routine to clear half the screen

Postby Nyh » Tue Jul 31, 2012 9:16 am

spiny wrote:ok, the first one makes sense, and for the second one, is it moving a0 to the 'end' of the line then zeroing everything backwards towards the start of the line, in blocks of four ?

Indeed, the movem.l instruction moves multiple registers at one time. To memory it can only do -(a0) and not (a0)+. The instruction is in first place used to move registers to the stack -(sp) and from the stack (sp)+. For the 68000 it is the most effective way to move data around. Using more registers makes the routine faster. For the 68000 this is about the fastest solution:

Code: Select all

cls2:
   movem.l  d3-d7/a2-a3,-(sp)
   move.w   #2,-(sp)            ; get physbase (the address of screen memory being displayed on the monitor)
   trap     #14                 ; tos call
   addq.l   #2,a7               ; tos call
   move.l   d0,a0               ; a0 points to screen
   lea      40*2(a0),a0

   moveq.l  #0,d0
   move.l   d0,d1
   move.l   d0,d2
   move.l   d0,d3
   move.l   d0,d4
   move.l   d0,d5
   move.l   d0,d6
   move.l   d0,a1
   move.l   d0,a2
   move.l   d0,a3
   
   move.w   #100-1,d7            ; how many times (lines
.loop:
   movem.l  d0-d6/a1-a3,-(a0)    ; 40 0 bytes are written
   movem.l  d0-d6/a1-a3,-(a0)    ; 40 0 bytes are written, total is 80
   lea   240(a0),a0              ; skip last half of line
   dbra d7,.loop                 ; loop d1 times
   movem.l  (sp)+,d3-d7/a2-a3
   rts                           ; the end

In this code uses 2 times 10 registers to clear the memory.
spiny wrote:another possible daft question:

is REPT the same as 'unrolling' ?

Yes, it is, the REPT macro repeats the instructions between REPT and ENDR and is primary used for loop unrolling.

Hans Wessels

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Tue Jul 31, 2012 10:06 am

FedePede04 wrote:HI .



i have never code in dev. pack but i think that the REPT command is a marco command,
so it just paste the code between the REPT and ENDR the number times. so i this example it would past the code 5 times.

Movem, move the contain of more then one register, in this case to (a0)




cool, thanks :)

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Tue Jul 31, 2012 10:07 am

Nyh wrote:
Hans Wessels


more thanks :)

cheers, Phil :)

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Tue Jul 31, 2012 10:33 am

one thing:

Code: Select all

   movem.l  d0-d6/a1-a3,-(a0)    ; 40 0 bytes are written, total is 80
   lea   240(a0),a0              ; skip last half of line


why is 240 used ? I would expect that to be 160, as a0 need to back to the end of the current 'line' then to the end of the next 'line' as well.

edit: I think is see, it skips two lines ?

User avatar
Cyprian
Atari God
Atari God
Posts: 1518
Joined: Fri Oct 04, 2002 11:23 am
Location: Warsaw, Poland

Re: simple (?) cls routine to clear half the screen

Postby Cyprian » Tue Jul 31, 2012 11:15 am

spiny wrote:one thing:
why is 240 used ? I would expect that to be 160, as a0 need to back to the end of the current 'line' then to the end of the next 'line' as well.

edit: I think is see, it skips two lines ?



keep in mind that procedure clears memory backward (from the middle to the begin of a line), and every line you need to put pointer to the middle of the next line. One line has 160 bytes therefore you need add 240 (160 + 80):

First line:
start address: 80 (middle line)
end address: 0 (begin line)

Second line:
start address: 240 (middle line)
end address: 160 (begin line)

Third line:
start address: 400 (middle line)
end address: 320 (begin line)
Jaugar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
SDrive / PAK68/3 / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.appspot.com/

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Tue Jul 31, 2012 8:29 pm

ah, moving to the middle, of course :)

I spent a few minutes with my calculator trying to work out multiples of 80 to see where the pointer would be :)

my next assignment is to work out how to display a PI1 in the same way, i.e. the left half and so on. I think I know how, i'll need to move 'through' the file as well as moving the screen pointer. It should keep me busy for the rest of the week :)

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Sat Aug 04, 2012 6:33 pm

ok, I managed to figure out the 'show half a pic' routing, so am posting it here for any other future 'newbie coders' :)

Code: Select all

showhalf                     ; attempt to show left half of PI1
   movem.l   picture+2,d0-d7         ; put picture palette in d0-d7
   movem.l   d0-d7,$FFFF8240.W      ; move palette from d0-d7 to actual hardware register where pal lives   
   move.w   #2,-(a7)            ; get physbase
   trap   #14                  ; tos stuff
   addq.l   #2,a7               ; tos stuff
   
   move.l   d0,a0               ; a0 points to screen memory
   move.l   #picture+34,a1         ; a1 points to picture

   move.w   #200,d0               ; 200 'lines'
   
   
partimage
   move.w #20-1,d6               ; number is amout of pixels to show per line - 20 QUARTER
showpart                     ;
   move.l   (a1)+,(a0)+            ; move one longword to screen
   dbra d6,showpart            ; loop d6 times
   
movepointers                  ;
   adda.l #40*2,a0               ; skip last half of line of screen
   adda.l #40*2,a1               ; skip last half of line of pic   

loopeverything   
   dbra   d0,partimage         ;
   rts                        ;


I expect there are quicker and more efficient ways to do this :D but i'm pleased to have worked out the syntax to make it work.
I do have a question though, about numbers again.
I 'show' 20 words (I think) then move to the 'end' of the line with 80 longs (I think) but that doesn't seem to add up to 160, which is what i'd expect for a line ?

obviously, I'm confused :) can anyone explain ?

WayneKerr
Atari nerd
Atari nerd
Posts: 49
Joined: Mon Mar 03, 2003 7:41 pm

Re: simple (?) cls routine to clear half the screen

Postby WayneKerr » Sun Aug 05, 2012 2:41 pm

Your code is correct, you've just confused yourself somewhere along the line. You say you 'show 20 words', but actually you 'show 20 LONGwords', that's all!
There are some obvious speedups (lea not adda.l #imm, pc-relative addressing of pic/screenbuff where possible, and the biggest one - unrolled loop since you know you will always write 20 longwords each time) but you'll discover those as you go along :)
Have fun, looking forward to seeing the megademo...

User avatar
spiny
Disk Imager Supreme
Disk Imager Supreme
Posts: 2509
Joined: Mon Aug 11, 2003 11:53 pm
Location: just outside bristol
Contact:

Re: simple (?) cls routine to clear half the screen

Postby spiny » Sun Aug 05, 2012 2:50 pm

WayneKerr wrote:Your code is correct, you've just confused yourself somewhere along the line. You say you 'show 20 words', but actually you 'show 20 LONGwords', that's all!
There are some obvious speedups (lea not adda.l #imm, pc-relative addressing of pic/screenbuff where possible, and the biggest one - unrolled loop since you know you will always write 20 longwords each time) but you'll discover those as you go along :)
Have fun, looking forward to seeing the megademo...


ah, that makes sense :)

could be a long wait for a megademo though :D


Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 3 guests