Page 1 of 2

simple 68k loop

Posted: Tue Oct 09, 2018 4:51 pm
by bioloid
Hello, first time I try to do asm on the 68k, something is wrong with this code:

mov.b #62, d0
L1:
dc.l _INT
dbeq d0,L1

so, what is wrong ? I try to call it a init.
Thanks

Re: simple 68k loop

Posted: Tue Oct 09, 2018 4:58 pm
by TmEE co.(TM)
What is that DC.L doing there ? It will be executed as an instruction which will depend on exact value of _INT.

Re: simple 68k loop

Posted: Tue Oct 09, 2018 5:04 pm
by bioloid
well I try to reduce the init code of megadrive :

from :

Code: Select all

.section .text.keepboot

        .org    0x00000000

_Start_Of_Rom:
_Vecteurs_68K:
        dc.l    0x00FFFE00              /* Stack address */
        dc.l    main            /* Program start address */

        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l     _INT, _INT, _INT, _INT
       dc.l     _INT, _INT, _INT, _INT
        dc.l     _INT, _INT, _INT, _INT
        dc.l    _INT, _INT, _INT, _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT
        dc.l    _INT 
        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT

        .incbin "boot/rom_head.bin", 0x10, 0x98

_INT:
        rte
to :

Code: Select all

.section .text.keepboot

        .org    0x00000000

_Start_Of_Rom:
_Vecteurs_68K:
        dc.l    0x00FFFE00              /* Stack address */
        dc.l    main            /* Program start address */

        mov.b    #62, d0
L1:
        dc.l    _INT
	dbeq    d0,L1

        .incbin "boot/rom_head.bin", 0x10, 0x98

_INT:
        rte
but it doesnt work and dont know how to debug!
edit: and maybe I'm totally wrong :)

Re: simple 68k loop

Posted: Tue Oct 09, 2018 5:06 pm
by cero
That is not code, it's data. You can't change it to code.

Re: simple 68k loop

Posted: Tue Oct 09, 2018 5:06 pm
by bioloid
shit, thanks.

Re: simple 68k loop

Posted: Tue Oct 09, 2018 5:07 pm
by bioloid
any idea to reduce the size ?

Re: simple 68k loop

Posted: Tue Oct 09, 2018 5:11 pm
by bioloid
maybe I should port this to asm :

Code: Select all

typedef unsigned short u16;
typedef unsigned long u32;
typedef volatile u16 vu16;
typedef volatile u32 vu32;

#define GFX_DATA_PORT           0xC00000
#define GFX_CTRL_PORT           0xC00004
#define GFX_WRITE_CRAM_ADDR(adr)    ((0xC000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x00)

void main()
{
    static const unsigned char regValues[] = { 0x04, 0x74, 0xE000, 0xD000, 0xC000, 0xDC00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x81, 0xD800, 0x00, 0x02, 0x01, 0x00, 0x00 };
    vu16 *pw;
    vu32 *pl;
    u16 i;
  
    // init
    pw = (u16 *) GFX_CTRL_PORT;
    for (i = 0x00; i < 0x13; i++) *pw = 0x8000 | (i << 8) | regValues[i];

    // set background color
    pw = (vu16*) GFX_DATA_PORT;
    pl = (vu32*) GFX_CTRL_PORT;
    *pl = GFX_WRITE_CRAM_ADDR(0);
    *pw = 7|7<<4|7<<8;
}
I'm trying to do uniform color screen to less bytes possible lol

Re: simple 68k loop

Posted: Tue Oct 09, 2018 5:58 pm
by bioloid
Ok I give up, I've added the repo here https://github.com/skarab/megadrive-512
maybe use it later.. or not.

Re: simple 68k loop

Posted: Tue Oct 09, 2018 6:33 pm
by OrangyTang
That looks like the interupt table at the start of a ROM. You can't get that any smaller, that's just what the MD rom format is, every rom has to have it.

Re: simple 68k loop

Posted: Tue Oct 09, 2018 7:03 pm
by Sik
All this thread and not a single person mentioned dcb.l? (which is basically dc.l in repeat)

This is the same thing as 62 dc.l _INT in a row:

Code: Select all

    dcb.l  62, _INT
...although I admit I'm not sure if GAS supports it, given how it loves to ignore established syntax (even if it doesn't, pretty sure it must have a similar directive)

Re: simple 68k loop

Posted: Tue Oct 09, 2018 7:25 pm
by Miquel
Sik, you can always use repeat, like:

Code: Select all

	.rept 16
		move.l	d0, (a1)+
	.endr
bioloid, if you don’t use exceptions for sure you can get rid of most of the vector table. And most of the header too except of the ‘SEGA’ mark. But yeah that’s kind of unorthodox.
If you are going for that kind of minimalism, absolutely go for asm instead of C.

Re: simple 68k loop

Posted: Wed Oct 10, 2018 6:15 am
by bioloid
Sik: wow awesome, will test :)
Miquel : I'm not sure if the header may be discarded, i've reduced .incbin "boot/rom_head.bin", 0x10, 0x98 <- the 0x100 to 0x98 it saves bytes but below it brokes the build. maybe I should play with sgdk.ld too.
You are perfectly right about asm, but I may want to keep C for flexibility if I want to use this for 4k and so later on...

Edit: Sik it doesn't compile sadly

and this one doesnt save bytes, it looks like it's unrolled at build time

Code: Select all

.rept 62
	dc.l    _INT
.endr
maybe a m68k-elf-as option

Re: simple 68k loop

Posted: Wed Oct 10, 2018 10:48 am
by Miquel
Certain, you only need 8 very first bytes for stack and pc init, and then on address 0x100 the ascii SEGA mark. You even can use this same address to init the copy protection chip, 2 less bytes!

Code: Select all

.section .text.boot
.org 0x0
	dc.l 0x00000000
	dc.l Reset
Reset:
	move.w	#0x2700, sr					/* disable exceptions */
	move.l	Header(pc), 0xA4000
.org 0x100
Header:
	.ascii	 "SEGA"
That's just an example, check everything is ok first.

As a base rule every time you use 4bytes as data probably there is a better way to do it.

Re: simple 68k loop

Posted: Wed Oct 10, 2018 5:56 pm
by bioloid
wow awesome thanks Miquel, it works!
I pushed it to the repo, I've added palette animation :)

Re: simple 68k loop

Posted: Thu Oct 11, 2018 4:33 am
by HardWareMan
The DBcc uses only 16 bits for count. So you should use .W and not .B or .L for move opcode. Also, DBcc count until -1, not 0. So, you should load counter with 4 for count to 5.

Anyway, all rookies should read M68000 Programming Manual.pdl before something ask here.