Jump to content

Photo

Pixel shift problem on st


11 replies to this topic

#1 Redreamer82 OFFLINE  

Redreamer82

    Combat Commando

  • 9 posts

Posted Wed Feb 27, 2019 11:33 PM

Hi! I've progressed somewhat since my last post and is now trying some pixel shifting. I'm starting in the top right corner and shifts word by word and plane after plane to the left. But it does not work like I want to. I can use my code for the top 19 words of each line, not for the first of some reason. I think I've done some trivial fault that any experienced assembly coder quickly can see.

If anyone have a sec to have a look at my code It would be much appriciated.

scroll
    move.w    #2,-(a7)    ;get screen address  
    trap    #14                 ;0  1  2  3,  4   5  6  7, ... ,  16   17   18   19
                            ;0  2  4  6,  8  10 12 14, ... ,  32   34   36   38
    addq.l    #2,a7;            ;0  8 16  24,32  40 48 56, ... , 128  136  144    152
    move.l    d0,scrolladr
    add.l    #152,scrolladr   ;add to get to last word, first bit plane

    move.l    #256,d7
scroll_loop
    move.l    scrolladr,a6

    move.w    #37,-(a7)    ;wait for vbl    
    trap    #14
    addq.l    #2,a7

    move.l  #15,d4     ;set rows to shift
bploop_resd5
        move.l  #3,d5  ;set bitplanes to shift
bploop_resd6
        move.l  #18,d6 ;set words width for each row (one bit plane at the time)
bploop
        roxl.w     (a6)
bp_no_carry        
        subq.l    #8,a6
        dbf     d6,bploop

        add.l   #152,a6    ;jump to start. (at the end)
    addq.l    #2,a6         ;inc to next bitplane
        dbf     d5,bploop_resd6    
        add.l   #152,a6
        dbf     d4,bploop_resd5

    dbf    d7,scroll_loop
    
    rts
 

I'm surprised that the instruction after roxl.l does not trash the X flag, but this is not the main problem right now. My main problem is that if I  try to shift the whole row (setting the move instruction below "bploop_resd6" to 19) makes the program crash. Probably addressing an odd byte, but I've not figured it out. =(



#2 Cyprian_K OFFLINE  

Cyprian_K

    Chopper Commander

  • 116 posts

Posted Thu Feb 28, 2019 6:44 AM

I did not investigate your code but I see "" instruction there. I guess it could be a root of your problem. "RTS" we use for return from subroutine, after using "JSR".

 

A valid GemDos program should be terminated with Pterm function:

*Exit - Pterm0
	clr.w	-(SP)
	trap	#1

More there:

http://toshyp.atari....500b.html#Pterm

http://toshyp.atari....00b.html#Pterm0

http://toshyp.atari....b.html#Ptermres

 

You can also add a waiting for key pressed function before Pterm:

; *Wait - Cconin
	move.w	#1,-(SP)
	trap	#1
	addq.l	#2,SP

Edited by Cyprian_K, Thu Feb 28, 2019 6:46 AM.


#3 ggn OFFLINE  

ggn

    Stargunner

  • 1,472 posts
  • Location:Athens, Greece

Posted Thu Feb 28, 2019 12:29 PM

I'm surprised that the instruction after roxl.l does not trash the X flag, but this is not the main problem right now. My main problem is that if I  try to shift the whole row (setting the move instruction below "bploop_resd6" to 19) makes the program crash. Probably addressing an odd byte, but I've not figured it out. =(


The X bit is deliberately not touched by many instructions so you can perform stuff like that roxl loop.

As for your main question, I tried modifying the program to use roxl everywhere and as expected, it shows up some junk on screen (a weird wrap around effect). This is due to the X bit not being clear when you first enter the loop.

How to fix this? One way of course would be to do something like clearing the CCR (move #0,CCR) but we can do something more elegant. Instead of roxl'ing the rightmost word you can lsl it. This has the added bonus of ignoring the state of the X bit initially and then setting it if the leftmost bit is 1. So in essence this will reset the X bit :). So your loop becomes:

bploop_resd6
        move.l  #18,d6 ;set words width for each row (one bit plane at the time)
        lsl.w (a6)
        subq.l #8,a6
bploop
        roxl.w     (a6)
bp_no_carry        
        subq.l    #8,a6
        dbf     d6,bploop
(untested at the moment but I hope you get the gist).

Now, when you get this working you'll see an odd tearing of the screen. This is normal and happens because you update the same buffer as the one the shifter chip shows on screen. If you do something like "add.l #16000,scrolladr" before you enter your loops, i.e. have it scroll the middle part of the screen, the tearing will go away. Of course to get rid of this problem properly you'll have to use double buffering. But hey, one step at a time!

Finally, a couple of optimising hints:

a) If you can afford it (memory wise) don't use dbra, especially in inner and tighter loops. Instead, prefer to unroll the code:

bploop
        rept 19
        roxl.w     (a6)
        subq.l    #8,a6
        endr
b) While we're at it, it's a bit wasteful to keep reducing the pointer when you can use the wonderful addressing modes of the 68000:

i set 144
bploop
        rept 19
        roxl.w     i(a6)
i set i-8
        endr
This will generate 19 instructions that have the offset hardcoded and decreasing (i.e. roxl.w 144(a6), roxl.w 136(a6), etc).

Hope this helps!

#4 Redreamer82 OFFLINE  

Redreamer82

    Combat Commando

  • Topic Starter
  • 9 posts

Posted Thu Feb 28, 2019 3:39 PM

Thanks ggn. I think very much in 8bit 6502 terms when I write my code, but hey, Ive just started to learn. I did the asl change for a start, this fixed the wrap around effect but I still dont understand why I get a crash when trying to move the whole row. I recorded this event. I hope it will ease the understanding.

https://drive.google...BeK5ZB0-eGo6HiJ



#5 ggn OFFLINE  

ggn

    Stargunner

  • 1,472 posts
  • Location:Athens, Greece

Posted Fri Mar 1, 2019 12:10 AM

Thanks ggn. I think very much in 8bit 6502 terms when I write my code, but hey, Ive just started to learn.


No worries, everyone has to start somewhere!

I did the asl change for a start,


Let me stop you there for a second for a small clarification: There are two kinds of shifts on the 68000 - arithmetic and logical. Arithmetic (asl/asr) keeps the leftmost bit intact as it shifts, while logical doesn't. Arithmetic shifts are great for when you want to do things with integers (as by convention the leftmost bit is considered sign) but since your data is not numeric, using asl is going to cause weird artifacts.

this fixed the wrap around effect but I still dont understand why I get a crash when trying to move the whole row. I recorded this event. I hope it will ease the understanding.
https://drive.google...BeK5ZB0-eGo6HiJ


Well, the 2nd run looks like you're not adjusting your offsets properly - probably your "add.l #152,a6 ;jump to start. (at the end)" needs to be 160?

Also, I see you're using devpac 3, so why not take advantage of the debugger? IIRC you can hit alt-d after you assemble, then you drop to Mon with the program loaded, then you type 'r' and 'g' (for 'run' and 'go'), wait for it to crash and then you should have a better idea of what's happening.

#6 Redreamer82 OFFLINE  

Redreamer82

    Combat Commando

  • Topic Starter
  • 9 posts

Posted Fri Mar 1, 2019 12:36 AM

Ive tried using the debugger but it does not work at the moment. Dont know why because it did work before. I get a "cant run" message or something similar. Maybe I should investigate why the debugger doesnt work, It is a powerful tool.

Skickat från min ANE-LX1 via Tapatalk

#7 fedepede04 OFFLINE  

fedepede04

    Chopper Commander

  • 141 posts

Posted Thu Mar 7, 2019 4:20 AM

why do you put 256 in d7, for me it look like its the Y Loop, so max 199 lines, or else you write out side your video array it can make the program crash.

instead of add.l #156,A6 use lea 156(A6),A6 its faster

 

 

and i would make the rol loop something like this

 

Moveq #15,D7

YLoop:

Moveq  #3,D5

BpLoop:

lsl.w 152(A6)

rol    144(A6)

rol    136(A6)
rol    128(A6)
ect.
rol   8(A6)
rol   (A6)
 
Addq.w #2,A6
Dbra     d5,BPloop 
Lea      152(A6),A6   ; NextLine
Dbra     D7,Yloop
 
 
edit: had an other look, and it look like that d7 is number of time to scroll so probably not why it crash

Edited by fedepede04, Thu Mar 7, 2019 4:26 AM.


#8 Redreamer82 OFFLINE  

Redreamer82

    Combat Commando

  • Topic Starter
  • 9 posts

Posted Mon Mar 11, 2019 2:38 AM

Thank you for your input! I try to learn as fast as possible but some things take time to digest :)

Skickat från min ANE-LX1 via Tapatalk

#9 ggn OFFLINE  

ggn

    Stargunner

  • 1,472 posts
  • Location:Athens, Greece

Posted Mon Mar 11, 2019 3:25 AM

Hi,

not sure if you ever got this to work, so here's a version that seems ok:

                clr.l   -(SP)
                move.w  #$20,-(SP)
                trap    #1              ;supervisor on
                addq.l  #6,SP

                clr.b   $FFFF8260.w     ;set st low resolution

                move.w  #2,-(SP)
                trap    #14
                addq.l  #2,SP
                movea.l D0,A0
                move.w  #32000/2-1,D0
fill_loop:      move.w  D0,(A0)+
                dbra    D0,fill_loop




scroll:
                move.w  #2,-(SP)        ;get screen address
                trap    #14             ;0  1  2  3,  4   5  6  7, ... ,  16   17   18   19
;                                       ;0  2  4  6,  8  10 12 14, ... ,  32   34   36   38
                addq.l  #2,SP           ;0  8 16  24,32  40 48 56, ... , 128  136  144    152
                move.l  D0,scrolladr

                addi.l  #16000,scrolladr ;point to the middle of the screen

                addi.l  #152,scrolladr  ;add to get to last word, first bit plane
                move.l  #256,D7
scroll_loop:
                movea.l scrolladr,A6
                move.w  #37,-(SP)       ;wait for vbl
                trap    #14
                addq.l  #2,SP
                move.l  #15,D4          ;set rows to shift
bploop_resd5:
                move.l  #3,D5           ;set bitplanes to shift
bploop_resd6:
                move.l  #18,D6          ;set words width for each row (one bit plane at the time)
                lsr.w   (A6)
                subq.l  #8,A6
bploop:
                roxl.w  (A6)
bp_no_carry:
                subq.l  #8,A6
                dbra    D6,bploop
                adda.l  #160,A6         ;jump to start. (at the end)
                addq.l  #2,A6           ;inc to next bitplane
                dbra    D5,bploop_resd6
                adda.l  #152,A6
                dbra    D4,bploop_resd5

                cmpi.b  #57,$FFFFFC02.w ;space pressed?
                bne.s   scroll_loop

;                dbra    D7,scroll_loop

                clr.w   -(SP)
                trap    #1


scrolladr:      DS.L 1

                END
In addition to making the scroll to work I modified a few things like adding a random pattern to the screen, and scrolling the middle part of the screen so it doesn't show tearing (too much that is), and waiting for space to exit.

#10 fedepede04 OFFLINE  

fedepede04

    Chopper Commander

  • 141 posts

Posted Tue Mar 12, 2019 1:34 AM

can i asked what you are doing,is it a text scroller?

 

you also need to feed you scroller with some graphic....

 

a couple of tips.

if the value is between -128,127, instead of using a move.l use moveq it clear the upper byte and word,  it's faster and take less memory.

when you set up a dbra loop use moveq or move.w, dbra is only word so it does not matter what in the upper word.

when you add a value there is less then a word to an address register, use add.w or lea (Ax,Dx.w),Ax again its faster and take less memory example lea (A0,D0.w),A0 


Edited by fedepede04, Tue Mar 12, 2019 1:35 AM.


#11 fedepede04 OFFLINE  

fedepede04

    Chopper Commander

  • 141 posts

Posted Tue Mar 12, 2019 1:45 AM

here is the text scroller that i use in my outrun demo.

it don't scroll a very big array, but it could maybe give you some ideas and it should be easy to modified.. 

;---------------------------------------------------------------------
;	Radio Scroll
;---------------------------------------------------------------------

	lea	FontGfx,a3
	moveq	#0,d6
	Moveq	#0,D0

	Moveq	#0,D0
	subq.w	#1,ScrollCounter
	Bpl.s	TextScroll_No_new_char
	Move.w	#5,ScrollCounter
	lea	ScrollWorkSpace(pc),a1

	move.l	ScrollTxtPointer(pc),A2
	
	Move.b	(a2)+,d6
	tst.b	d6
	bne.s	ScrollTxtNotFinish
	Move.l	ActiveScrollName(PC),A2
	
NoRestartScrollList:

	Move.b	(a2)+,d6
	Move.l	a2,ScrollTxtPointer	


ScrollTxtNotFinish:
	Cmp.b	#216,d6
	beq.s	CharIsAO
	Cmp.b	#248,d6
	bne.s	CharIsAO1
CharIsAO:
	move.b	#']',d6
CharIsAO1:

	Sub.w	#32,d6
	move.l	a2,ScrollTxtPointer
	cmp.w	#64,d6
	ble.s	ScrollTxtIsNotLowerCase
	sub.w	#32,d6
ScrollTxtIsNotLowerCase:

	lsl.w	#3,d6
 	Lea	(a3,d6.w),a3

	move.l	(a3)+,(a1)+
	move.l	(a3)+,(a1)+


	
	
	
	
TextScroll_No_new_char:	
	Lea	ScrollArray,A0	
	lea	ScrollWorkSpace(PC),a1
	Moveq	#5,d1
	Moveq	#0,d3
Scroll_loop:
	And.w	#%1111111111101111,sr
	move.b	(a1),d3
	Roxl.b	#1,d3
	Move.b	d3,(a1)+

	Roxl.w 	12(a0)
	Roxl.w 	8(a0)
	Roxl.w 	4(a0)

	Move.b	1(a0),d3
	Roxl.w	#1,d3
	Move.b	d3,1(a0)

	And.w	#%1111111111101111,sr
	Lea	16(a0),a0
	Dbra	d1,Scroll_loop

	
	
	
	Lea	ScrollArray,A1	
	Move.l	LogBase(PC),A0
	lea	$5C24(a0),a0

	Moveq	#5,d1
SCLoop:	
	Move.b	1(A1),1(A0)
	Move.w	4(A1),8(A0)
	Move.w	8(A1),16(A0)
	Move.w	12(A1),24(A0)
	Lea	160(A0),A0
	Lea	16(A1),A1
	Dbra	D1,SCLoop


Edited by fedepede04, Tue Mar 12, 2019 1:45 AM.


#12 Redreamer82 OFFLINE  

Redreamer82

    Combat Commando

  • Topic Starter
  • 9 posts

Posted Thu Mar 14, 2019 11:18 AM

thanks for your valuable suggestions for improvement! Im just trying to learn so I was not really aiming for a fully working demo at this moment. :)

Skickat från min ANE-LX1 via Tapatalk




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users