Page 1 of 1

set color and paper

Posted: Mon Aug 24, 2020 5:36 pm
by goyo
Hello,
do you know how i can set paper and ink in 6502 ? dont find documentations ..

how can i call these rom subroutine ?

paper and ink rom adresse : #EAFC

try to put color in A register and call subroutine but it dont work ?

Re: set color and paper

Posted: Mon Aug 24, 2020 6:17 pm
by Dbug
If you search in OSDK\lib, you will find a "library.ndx" file, which contains the list of all supported routines, including paper and ink:

Code: Select all

-graphics.s
        (...)
	_paper
	_ink
        (...)
from that you can see that paper and ink are in "graphics.s" which is at the same location:

Code: Select all

_paper
        ldx #1         ;Get one parm
        jsr getXparm
        jsr $f204      ;paper
        jmp grexit     ;common exit point

_ink
        ldx #1         ;Get one parm
        jsr getXparm
        jsr $f210      ;ink
        jmp grexit     ;common exit point
the getXparm is also in the index file:

Code: Select all

-ggeneral.s
	getXparm
        (...)
which is implemented that way:

Code: Select all

getXparm               ; Get X params (16bit) from stack
        ldy #0         ; X is the number of params
        sty $2e0       ; Zero error indicator.
        stx tmp        ; store X in storage byte
        ldx #0
getXloop
        lda (sp),y
        sta $2e1,x
        inx    
        iny    
        lda (sp),y
        sta $2e1,x
        inx 
        iny            ; 
        dec tmp        ; decrement pointer
        bne getXloop
        rts
So basically what the code does, is to take the input parameter on the C stack and it writes it to the array that starts in $2E0 (PARAMS) which is used by all the graphics functions, $2E0 itself is used as the error code in case of wrong parameters.

So I guess in your case if you want to call these functions, all you need to do is:
- Clear $2E0
- Write the INK or COLOR value in $2E1
- Call either $f204 or $f210

That being said, if you do that, you are basically calling the ROM; which means you are forfeiting the top 16K of overlay memory, so I would suggest to use your own routine to do that, which additionally allows you to put the color attributes were you want, like INK first and then PAPER, to limit the visually lost column used by INK, all you need is a simple loop that write two bytes from A000 to A000+40*200, skipping every 40 bytes :)

Re: set color and paper

Posted: Mon Aug 24, 2020 8:12 pm
by mikeb
Dbug wrote:
Mon Aug 24, 2020 6:17 pm
like INK first and then PAPER, to limit the visually lost column used by INK,
This is true, of course the normal Oric BASIC screen (TEXT mode) writes PAPER first *then* INK, revelling in the two "lost" columns! I wonder why? Was it to stop people seeing a 39-column screen and thinking they'd been short changed?

If you start the line with INK then PAPER, your first column will have a black background (default at the start of every line is black paper, white ink, until told otherwise).

Re: set color and paper

Posted: Wed Aug 26, 2020 10:44 am
by goyo
Dbug wrote:
Mon Aug 24, 2020 6:17 pm
If you search in OSDK\lib, you will find a "library.ndx" file, which contains the list of all supported routines, including paper and ink:

Code: Select all

-graphics.s
        (...)
	_paper
	_ink
        (...)
from that you can see that paper and ink are in "graphics.s" which is at the same location:

Code: Select all

_paper
        ldx #1         ;Get one parm
        jsr getXparm
        jsr $f204      ;paper
        jmp grexit     ;common exit point

_ink
        ldx #1         ;Get one parm
        jsr getXparm
        jsr $f210      ;ink
        jmp grexit     ;common exit point
the getXparm is also in the index file:

Code: Select all

-ggeneral.s
	getXparm
        (...)
which is implemented that way:

Code: Select all

getXparm               ; Get X params (16bit) from stack
        ldy #0         ; X is the number of params
        sty $2e0       ; Zero error indicator.
        stx tmp        ; store X in storage byte
        ldx #0
getXloop
        lda (sp),y
        sta $2e1,x
        inx    
        iny    
        lda (sp),y
        sta $2e1,x
        inx 
        iny            ; 
        dec tmp        ; decrement pointer
        bne getXloop
        rts
So basically what the code does, is to take the input parameter on the C stack and it writes it to the array that starts in $2E0 (PARAMS) which is used by all the graphics functions, $2E0 itself is used as the error code in case of wrong parameters.

So I guess in your case if you want to call these functions, all you need to do is:
- Clear $2E0
- Write the INK or COLOR value in $2E1
- Call either $f204 or $f210

That being said, if you do that, you are basically calling the ROM; which means you are forfeiting the top 16K of overlay memory, so I would suggest to use your own routine to do that, which additionally allows you to put the color attributes were you want, like INK first and then PAPER, to limit the visually lost column used by INK, all you need is a simple loop that write two bytes from A000 to A000+40*200, skipping every 40 bytes :)
Thank you Dbug for yours precisions. :)
so when i compile with graphics.s I have :

Code: Select all

Building the program D at adress $600
Assembling main.S
Assembling displayhires.S
Assembling keyboard.S
Assembling shifttables.S
Assembling graphics.S
Linking
D:\osdk\sample\assembly\cwadbook
Unresolved external: sp
Unresolved external: tmp
Errors durink link.
ERROR : Build failed.
Appuyez sur une touche pour continuer...
even when i add ggenral.s

I dont find where tmp and sp is déclared :oops:

Re: set color and paper

Posted: Wed Aug 26, 2020 11:31 am
by jbperin
goyo wrote:
Wed Aug 26, 2020 10:44 am

Unresolved external: sp
Unresolved external: tmp
Appuyez sur une touche pour continuer...[/code]

even when i add ggenral.s

I dont find where tmp and sp is déclared :oops:
I sometime encounter this kind of issue. I usually solve it by:
- cleaning the BUILD directory of the project,
- cleaning the TMP directory of the OSDK directory
- closing the cmd windows and reopening a fresh one
- crossing finger and praying

I don't know exactly which step is important, but it usually fixes the problem.


As Dbug said, you could obtain the same result as the ink and paper commands by simply writing the corresponding attribute in graphic memory.

Look at here if you want to find inspiration:

https://github.com/oric-software/BattleZone4Oric/blob/master/Main.c#L166


It mainly comes from the article that you certainly have already read:

https://osdk.org/index.php?page=articles&ref=ART9

Re: set color and paper

Posted: Wed Aug 26, 2020 11:57 am
by iss
For this particular issue the ONLY relevant solution is: :D
jbperin wrote:
Wed Aug 26, 2020 11:31 am
- crossing finger and praying
Now seriously: There is one BIG difference which should be always taken into account and it is: what type is your project: [C with some ASM functions eventually] or [ASSEMBLER ONLY]. If you have C code then you don't need to care about such symbols like 'sp', 'tmp', etc - they are automatically defined and linked. But when you use only ASM sources these are undefined. So, you have 2 options:
- use a simple 'main.c' file which purpose is only to call your '_asm_main' function, i.e.

Code: Select all

// this is the assembler entry function
void asm_main();

// this is the default C entry function
void main() {
	asm_main();
}
- define all missing symbols which are mostly placed in the ZEROPAGE, i.e.

Code: Select all

.zero
sp .word 0
tmp .byte 0
....
I recommend to start with the first option as more simple ;).

Re: set color and paper

Posted: Wed Aug 26, 2020 6:07 pm
by Dbug
goyo wrote:
Wed Aug 26, 2020 10:44 am
Dbug wrote:
Mon Aug 24, 2020 6:17 pm
If you search in OSDK\lib, you will find a "library.ndx" file, which contains the list of all supported routines, including paper and ink:
(...)
Thank you Dbug for yours precisions. :)
so when i compile with graphics.s I have :
(...)
Unresolved external: sp
Unresolved external: tmp
even when i add ggenral.s
I dont find where tmp and sp is déclared :oops:
Two things:
- Please cut some of the content when you quote, else we have to scroll down through content which was already read by everybody (use the "Preview" button if necessary)
- Please attach some actual source code, ideally the minimal complete project that shows the problem so it can be reproduced

There are many reasons about why you program failed, including having OSDKLINK=-B in the options, but without having the actual code it's hard to know.

Re: set color and paper

Posted: Thu Aug 27, 2020 11:26 am
by goyo
finally I created the following code : :o

Is there a more optimal code...? :oops:

Code: Select all

_set_hires_colors ; set paper and ink color in hires mode.
.(
ldy #200

suite

	lda ScreenAdressLow,y
	sta writepaper+1
	sta writeink+1
	lda ScreenAdressHigh,y
	sta writepaper+2	
	sta writeink+2

	lda papercolor

writepaper
	sta $1234

	
	inc writeink+1
	lda inkcolor
writeink
	sta $1234
	dey
bne suite
rts
.)

Re: set color and paper

Posted: Thu Aug 27, 2020 5:39 pm
by Dbug
I don't think the "inc writeink+1" is correct, because if the value was 255 it will not increment the high byte value, but instead you could do that:

Code: Select all

	ldx #1
suite	
(...)
	lda inkcolor
writeink
	sta $1234,x
Also by starting at 200, you are accessing the screen address array off by one (it goes from 0 to 1999), so probably use "lda ScreenAdressLow-1,y"
" instead of "lda ScreenAdressLow,y" (and same for High).

But please, give me your (complete) original code that shows the error, else I can't fix things.

Re: set color and paper

Posted: Sat Aug 29, 2020 1:13 pm
by goyo
Dbug wrote:
Thu Aug 27, 2020 5:39 pm
I don't think the "inc writeink+1" is correct, because if the value was 255 it will not increment the high byte value, but instead you could do that:

Code: Select all

	ldx #1
suite	
(...)
	lda inkcolor
writeink
	sta $1234,x
Also by starting at 200, you are accessing the screen address array off by one (it goes from 0 to 1999), so probably use "lda ScreenAdressLow-1,y"
" instead of "lda ScreenAdressLow,y" (and same for High).

But please, give me your (complete) original code that shows the error, else I can't fix things.
thx dbug, your solution works fine!
I learn day after day ... thanks to you and others members