simple 68k loop

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

simple 68k loop

Post by bioloid » Tue Oct 09, 2018 4:51 pm

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

User avatar
TmEE co.(TM)
Very interested
Posts: 2358
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: simple 68k loop

Post by TmEE co.(TM) » Tue Oct 09, 2018 4:58 pm

What is that DC.L doing there ? It will be executed as an instruction which will depend on exact value of _INT.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

Re: simple 68k loop

Post by bioloid » Tue Oct 09, 2018 5:04 pm

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 :)
Last edited by bioloid on Tue Oct 09, 2018 5:06 pm, edited 1 time in total.

cero
Very interested
Posts: 253
Joined: Mon Nov 30, 2015 1:55 pm

Re: simple 68k loop

Post by cero » Tue Oct 09, 2018 5:06 pm

That is not code, it's data. You can't change it to code.

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

Re: simple 68k loop

Post by bioloid » Tue Oct 09, 2018 5:06 pm

shit, thanks.

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

Re: simple 68k loop

Post by bioloid » Tue Oct 09, 2018 5:07 pm

any idea to reduce the size ?

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

Re: simple 68k loop

Post by bioloid » Tue Oct 09, 2018 5:11 pm

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

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

Re: simple 68k loop

Post by bioloid » Tue Oct 09, 2018 5:58 pm

Ok I give up, I've added the repo here https://github.com/skarab/megadrive-512
maybe use it later.. or not.

OrangyTang
Interested
Posts: 26
Joined: Tue Feb 23, 2016 4:45 pm

Re: simple 68k loop

Post by OrangyTang » Tue Oct 09, 2018 6:33 pm

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.

User avatar
Sik
Very interested
Posts: 845
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: simple 68k loop

Post by Sik » Tue Oct 09, 2018 7:03 pm

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)
Sik is pronounced as "seek", not as "sick".

User avatar
Miquel
Very interested
Posts: 437
Joined: Sat Jul 30, 2016 12:33 am

Re: simple 68k loop

Post by Miquel » Tue Oct 09, 2018 7:25 pm

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.

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

Re: simple 68k loop

Post by bioloid » Wed Oct 10, 2018 6:15 am

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

User avatar
Miquel
Very interested
Posts: 437
Joined: Sat Jul 30, 2016 12:33 am

Re: simple 68k loop

Post by Miquel » Wed Oct 10, 2018 10:48 am

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.

bioloid
Very interested
Posts: 139
Joined: Fri May 18, 2012 8:22 pm

Re: simple 68k loop

Post by bioloid » Wed Oct 10, 2018 5:56 pm

wow awesome thanks Miquel, it works!
I pushed it to the repo, I've added palette animation :)

User avatar
HardWareMan
Very interested
Posts: 726
Joined: Sat Dec 15, 2007 7:49 am
Location: Kazakhstan, Pavlodar

Re: simple 68k loop

Post by HardWareMan » Thu Oct 11, 2018 4:33 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests