Horizontal HIRES and Text scrolling code needed.

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
User avatar
peacer
Flight Lieutenant
Posts: 451
Joined: Wed Jun 09, 2010 9:23 pm
Location: Turkey
Contact:

Horizontal HIRES and Text scrolling code needed.

Post by peacer »

What I need is to scroll a line to the left on hires with given number of lines 1 bit each time.

I don't know C language so OSDK is very away from me. So direct op code listing is good.

I plan to rotate each byte, add one pixel to the left byte if carry is set to 1.

I wonder if this scroll is fast enough on the screen for about 100 lines each time.

Is there a such ready-made machine code routine?

If not available or if such a scroll would be so slow for a game , a text scroll routine is also needed with one byte/ character scroll is this time.Text scrolling is easier of course and I think I could do that but if a ready text scroll code is available I can use that too.

My machine code programming capability was better than this time . I was coding in machine code by directly hex codes like #A9 means LDA , #85 means STA etc. Now I see that I forgot many things and need help :)

Also I always mix addressing modes too. Now it seems more complicated than the past to me :D

I want also to modify the code to not affect some characters on the screen while scrolling so that flickering of the characters on the scrolling lines won't happen.

So to cut it short, is there such screen scrolling codes available ?
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Chema »

I don't have a general purpose routine to do this. Maybe Dbug have some nice scroller code in his demos :)

Anyway I did a lateral scroll in Skool Daze, which could give you an idea about how it can be done. A zero page pointer tmp1 is loaded with the address of the set of lines (6 byte wide was my case) to scroll, and it handled 8 lines (the height of a character). The column of pixels to scroll in is in reg A (I stored the character set by columns, instead of by rows as usual).

This code scrolled the text speech bubble one pixel. The overall idea is:
- repeat for 8 lines
- get the pixel value to scroll in in the carry (asl with the parameter)
- repeat for 6 characters (bytes), that is a width of 6x6=36 pixels
- get the current value of the rightmost byte in screen and rol it
- fix the 6th bit (it must be set to 1 and its contents must enter the next scan). This is the cmp #192/and/ora (thanks Dbug!)
- store

Code: Select all

slide_col_bubble
.(
	sta tmp+1
	lda #8
	sta tmp

loop_s_col
	asl tmp+1
	ldy #6
loop_s_row
	lda (tmp1),y
	rol
	cmp #192
	and #%00111111
	ora #%01000000
	sta (tmp1),y
	dey
	bne loop_s_row

	lda tmp1
	clc
	adc #40
	sta tmp1
	bcc nocarry1
	inc tmp1+1
nocarry1

	dec tmp
	bne loop_s_col
	
	rts

.)

Mmmm... about scrolling fast 100 lines of 40 bytes each... I doubt you can do that *really* quickly. Though it depends on what your target speed is, of course.

Scrolling on a character basis is much much easier and faster. And much much less smoother.
User avatar
peacer
Flight Lieutenant
Posts: 451
Joined: Wed Jun 09, 2010 9:23 pm
Location: Turkey
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by peacer »

It surely gave idea. Thank you very much :)
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Dbug »

peacer wrote:I don't know C language so OSDK is very away from me. So direct op code listing is good.
You know that you can use OSDK with only Assembler? It does not have to be C.

If you download it, you will see that there are samples using only assembler.

The advantage is that if you use it, we can easily share and test your code and suggest changes. Else we need to use the same syntax as you do, use the same assembler or converter, etc... which makes things more complicated than necessary
peacer wrote:What I need is to scroll a line to the left on hires with given number of lines 1 bit each time.
For the scrolls, well, it really depends of how much memory you have.

As usual it's a trade off, between slow but memory efficient code, versus much faster but memory hungry code.

Chema gave a method that works nicely doing real time shift, there is a variant that involves not rotating at all but instead using two tables that represent the current byte shifted by one or more bit: It all become a matter of reading and ORIC values.

The fastest method I know is to not bitshift the screen at all but only one column of byte per frame, but it requires 6 times more memory by using 6 copies of the screen, each shifted by one bit: All you do is to update the part that gets updated and copy the whole buffer in a round-robin fashing, alternating between the 6 copies.

It's about as fast as it can be (on the Oric): A pure copy of the screen data
User avatar
peacer
Flight Lieutenant
Posts: 451
Joined: Wed Jun 09, 2010 9:23 pm
Location: Turkey
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by peacer »

In my time when I learned anything about machine code , everything was so diffucult.

For the beginning, machine code was just basic program with hex loader and numbers to me.

So I learned machine code from numbers , not from commands. So #A9 #85 seems more meaningful than LDA #85. Nonsense and Strange? Yes. But I get used to it in this way. Its like in the movie "matrix" , I can directly read from the memory and machine code from numbers :)

In turkish, we describe this situation with this sentence : "pointing the left ear by right hand"

I know its nonsense to learn it in more diffucult way but machine code syntax like LDA ($43,X) , LDA $05FF,X seems more complicated to me.

You are right, I have to learn in this way but it needs time :)

About scrolling again, I need "most fast scrolling" code . Not much free memory is needed.
Godzil
Squad Leader
Posts: 774
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Godzil »

Dbug wrote: It's about as fast as it can be (on the Oric): A pure copy of the screen data
How quick is a "memcpy" on the oric?
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Dbug »

Godzil wrote:
Dbug wrote: It's about as fast as it can be (on the Oric): A pure copy of the screen data
How quick is a "memcpy" on the oric?
Depends :)

If you don't have any control on the area you copy from and copy to, you do not have the same possibilities compared to if you have full control of the source and target areas (and size to copy).

A generic memcpy is going to be much slower than a dedicated one.

For example you could copy a buffer to the screen with a bunch of lda/sta:

Code: Select all

lda buffer+256*0,x
sta $a000+256*0,x
lda buffer+256*1,x
sta $a000+256*1,x
...
lda buffer+256*99,x
sta $a000+256*99,x
By unrolling the code like that you reduce the cost of the loop/decrement instructions.

I personally tend to do 40 iterations and have one lda/sta couple per scanline, that makes it even faster and have the advantage of being easy to compute :)
Godzil
Squad Leader
Posts: 774
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Godzil »

Of course ^^ My question was not directed, but I thought about a screen copy or course.

Thanks^^
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Chema »

Yep exactly the same technique I use for double buffering. Surely Dbug suggested me the idea when I was working in 1337 :)

Dbug is right. If you need a pixel scroll and you need it to be fast, a table with the pre-rotated elements will do. As only 6 bits are used that is two tables with 64 entries, one with the rotated byte and (I guess) another one with the value of the zero bit to ORA into the scan on the left (which would be the value of the carry if rol were used)?

128 bytes in total and two indexed access to a table plus the lda, ora and sta. Am I right Dbug?
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Dbug »

Chema wrote:Yep exactly the same technique I use for double buffering. Surely Dbug suggested me the idea when I was working in 1337 :)

Dbug is right. If you need a pixel scroll and you need it to be fast, a table with the pre-rotated elements will do. As only 6 bits are used that is two tables with 64 entries, one with the rotated byte and (I guess) another one with the value of the zero bit to ORA into the scan on the left (which would be the value of the carry if rol were used)?

128 bytes in total and two indexed access to a table plus the lda, ora and sta. Am I right Dbug?
If you are sure that your source data is only having 6 bits, yes correct.
Me in general I take two tables of 256 bytes just to be on the safe side :D

And yes, the point is to be able to handle the move from the last pixel of the byte from 'bit 5' to 'bit 0' in the next byte while keeping the bits 6 and 7 unchanged :)
User avatar
peacer
Flight Lieutenant
Posts: 451
Joined: Wed Jun 09, 2010 9:23 pm
Location: Turkey
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by peacer »

I tried to type in this machine code to simple hires scroll but it crashed. Can you examine and tell me what is wrong?

As I said before, I don't know much about 6502 command syntax so I will write HEX OP code and try to explain what I mean to do in BASIC notation.

#A9 20 #85 00 #A9 A3 #85 01 ---> DOKE 0,#A320 . Its the beginning of the 20'th line on hires
#A9 28 #85 03 ----> POKE 3,40 . This will be used as counter for adressing the next line.
#18 ----> Clear CARRY
#A0 28 ----> Y=40 . How many lines to be scrolled is determined into Y register.
#A2 28 -----> X=40. Last byte on each line.
#36 00 ------> Rotate let the content of adress in deek(0)+x . ( ROL Zero Page X )
#CA ------> X=X-1
#D0,FB ------> REPEAT sequence until X reach to 0
#18 -------> CLEAR carry
#A5,00 -------> A=PEEK(0)
#65,03 --------> A=A+PEEK(3)+CARRY
#85,00 -----> POKE 0,A
#A5,01 -------> A=PEEK(1)
#69,00 --------> A=A+CARRY
#85,01 -------> POKE 1,A
#88 --------> Y=Y-1
#D0,F9 --------> REPEAT SEQUENCE Until Y reach to 0
#60 ------> END

I know its so complicated than Mnemonics syntax but for now thats the only thing I can do.

To summarize, this code is supposed to scroll 40 lines 1 pixel to left starting from 20th line on hires but when I call it it just hangs oricutron. I thing I have problem with ROL command but I couldn't find the error.

I added the hex loading basic program to this post.

When you run the program it write codes into memory after #400

I added a hires drawing routine to create something on HIRES. If you type GOSUB 10 you can have that routine.

then CALL 1024 is supposed to scroll but it will collaps emulator. So before running machine code you have to check the basic listing.

So ; What am I doing wrong :))
Attachments
HIRES.tap
(414 Bytes) Downloaded 680 times
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Chema »

Urgh, I find the hex notation impossible to follow, even with the basic comments, sorry. From a quick glance I think the rol might be using the wrong address mode. If you load the address of the starting position on the screen into a zero page pointer, wouldn't it be possible that you intended to use indirect indexed mode? At least that is what I always do.

Else you are rotating something in the middle of the zero page.

Have I missed something? It is quite late at night now, and I a sleepy :)

Also beware that if you do not take care of setting the 6th bit, you will put attributes on the screen, with unknown results. Also keep the 7th bit cleared so you do not set the inverse mode. And be careful, as it is the content of the 5th bit what you want to shift to the next byte. Check my code, the part where the cmp, and and Ora are done to provide this.
User avatar
Symoon
Archivist
Posts: 2301
Joined: Sat Jan 14, 2006 12:44 am
Location: Paris, France

Re: Horizontal HIRES and Text scrolling code needed.

Post by Symoon »

To understand each other, Peacer, you can try the great Oric Explorer. It will read your TAP file, and disassemble it with the mnemonics. Then you just have to copy/paste.
I am myself coding machine code with hex values, I still have trouble reading assembler. Having the hex code and the mnemonics next to them helps a lot.

Example:

Code: Select all

$1000  78         SEI           x  
$1001  A9 11      LDA #$11      .. 
$1003  8D A8 BB   STA $BBA8     ...
$1006  A2 18      LDX #$18      .. 
$1008  A0 9C      LDY #$9C      .. 
(...)
User avatar
peacer
Flight Lieutenant
Posts: 451
Joined: Wed Jun 09, 2010 9:23 pm
Location: Turkey
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by peacer »

Ah shame on me, I didn't know about Oric Explorer Utility. I even checked bin2txt to paste the basic code but failed. Thank you very much. Maybe I won't learn machine coding from this topic but I learned about that software :D

Here is the mnemonics of the code I am trying to run.

Code: Select all

$0400  A9 20      LDA #$20      .  
$0402  85 00      STA $00       .. 
$0404  A9 A3      LDA #$A3      .. 
$0406  85 01      STA $01       .. 
$0408  A9 28      LDA #$28      .( 
$040A  85 03      STA $03       .. 
$040C  18         CLC           .  
$040D  A0 10      LDY #$10      .. 
$040F  A2 28      LDX #$28      .( 
$0411  36 00      ROL $00,X     6. 
$0413  CA         DEX           .  
$0414  D0 FB      BNE $0411     .. 
$0416  18         CLC           .  
$0417  A5 00      LDA $00       .. 
$0419  65 03      ADC $03       e. 
$041B  85 00      STA $00       .. 
$041D  A5 01      LDA $01       .. 
$041F  69 00      ADC #$00      i. 
$0421  85 01      STA $01       .. 
$0423  88         DEY           .  
$0424  D0 E9      BNE $040F     .. 
$0426  60         RTS           `  
Yes I forgot about 7th and 8th bits . I thought when I ROL a byte, if the first byte is out as carry it will be transferred to next byte easily but that as a mistake. I have to check 6th and 7th bit and now that is complicated.

About ROL $00,X command, I might really be confused about adressing issue. With Zero Page-X adressing method I thought ;

ROL $00,X means to take PEEK(DEEK (0)+X) and rotate it.

Is it wrong? Do I have to use another opcode? Is there indirect indexing in zero page?

Also I believe there might be problem after #416 . I want to add 40 to DEEK(0) value after one line scroll but it might be complicated too.
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Horizontal HIRES and Text scrolling code needed.

Post by Chema »

Just a quick answer, without looking at the code, yet :)
peacer wrote:Yes I forgot about 7th and 8th bits . I thought when I ROL a byte, if the first byte is out as carry it will be transferred to next byte easily but that as a mistake. I have to check 6th and 7th bit and now that is complicated.
This can easily turn out like a hung Oric, as you might be switching to HIRES 60Hz mode or TEXT (either 60 or 50 Hz), setting ink to zero, etc...

That is the difficult part of the whole routine indeed.
About ROL $00,X command, I might really be confused about adressing issue. With Zero Page-X adressing method I thought ;

ROL $00,X means to take PEEK(DEEK (0)+X) and rotate it.

Is it wrong? Do I have to use another opcode? Is there indirect indexing in zero page?
Mmmm... I don't think so. zero page indexed mode will do something more like (PEEK(0+X)), so you are rotating the actual contents of the zero page, and not the 00 position, but the 00+X. I think you want to use the value stored in zero page as a pointer to the start of the line, and use the register X to select the actual scan in the line (from 0 to 39). That requires an zero page indirect indexed mode, which only works with register Y, btw.

Check:
http://en.wikibooks.org/wiki/6502_Assem ... _X:_zp.2Cx
Also I believe there might be problem after #416 . I want to add 40 to DEEK(0) value after one line scroll but it might be complicated too.
Can't see the problem, really, as you stored 40 on address $03. It is not the fastest way possible at all, but should work.

Cheers
Post Reply