Author Topic: Pressing START in the loader screen, what does it do?  (Read 1518 times)

0 Members and 1 Guest are viewing this topic.

Offline keropi

  • Jr. Member
  • **
  • Posts: 59
Pressing START in the loader screen, what does it do?
« on: October 14, 2009, 01:51:20 AM »
Hiya!!

I got yesterday my cart, but I have a question... In the LOADER screen, if you press START there is some work going on, and then the colors invert... What happens?  :-\
I have no idea  ~sm-41.gif~ Is there an online manual or something?

Thanks!!!!  ::sm-29.gif::

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1491
  • Just a coding machine.
Re: Pressing START in the loader screen, what does it do?
« Reply #1 on: October 14, 2009, 10:49:41 AM »
It does nothing but wait for you to press the C button. Eventually, it's supposed to load a program into the PSRAM straight from USB, bypassing the flash altogether. Right now, it does nothing more than turn the USB on, wait for the C button, then turn the USB off.

Offline keropi

  • Jr. Member
  • **
  • Posts: 59
Re: Pressing START in the loader screen, what does it do?
« Reply #2 on: October 14, 2009, 11:58:27 AM »
ooohhhhh
thanks for the info!!!!

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1491
  • Just a coding machine.
Re: Pressing START in the loader screen, what does it do?
« Reply #3 on: October 14, 2009, 01:15:39 PM »
The main reason I know that was I was curious myself, so when Dr. neo released the source for the menu, that was one of the first things I checked.   :D

Online Dr.neo

  • Administrator
  • Hero Member
  • *****
  • Posts: 3467
Re: Pressing START in the loader screen, what does it do?
« Reply #4 on: October 15, 2009, 03:25:10 AM »
yes,the START key is use for download the rom from PC to MD myth cart PSRAM directly,but it need the NEO2 cart (build in PSRAM) to work together.

[1] press START in the menu
[2] goto MD Myth PC APP "link" page,select the MD5 rom and click "upload" butoon
[3] after it,press MD "C" key, then start to run.
In my world,have 0 and 1 only ......Matrix World......

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1491
  • Just a coding machine.
Re: Pressing START in the loader screen, what does it do?
« Reply #5 on: October 15, 2009, 12:29:55 PM »
Oh! I see how it works... first it turns on the USB and waits for the C button.

Code: [Select]
                CMP.B   #$80,d0   ;    START
                BEQ     RUN_X4
                NOP

                Jmp     MENU

RUN_X4:
                lea      MAKE30(PC),a0  ;BBBB
                JSR      PRINTA
                JSR      wjoy
                MOVE.W   #$FFFF,D0
                MOVE.W   D0,USB_ON


RUN_X4A:
                jsr     rjoy
                NOP
                CMP.B   #$20,d0    ;    C
                BEQ     RUN_X5
                NOP
                NOP
                NOP
                NOP
                JMP     RUN_X4A

During this time, the USB interface is active and the user can load something to a specific place in the flash over the USB.

After that, the user hits C and the USB is turned off and then the menu copies that specific place to the PSRAM and runs it.



Code: [Select]
RUN_X5:

                lea      MAKE13(PC),a0  ;BBBB
                JSR      PRINTA
                JSR      wjoy
                MOVE.W   #$0000,D0
                MOVE.W   D0,USB_ON
                NOP
                NOP
                NOP
                NOP
                NOP
                NOP
                MOVE.B   #$00,MODE
;*******************************************************************************
                MOVE.B   #$0B,ROM_Z        ;
                MOVE.B   #$00,RBK_H        ; A24~A25
;*******************************************************************************
                MOVE.B   #$00,RBK_L
;*******************************************************************************
                MOVE.B   #$01,SR_Z;        ; GBA SRAM SIZE
                MOVE.B   #$00,SR_B         ; GBA SRAM BANK
;*******************************************************************************
                MOVE.B   #$06,RUN
;*******************************************************************************
                JMP      MD5

It looks from the above code like the specific spot is the very start of the flash as both the high and low GBA flash banks are set to zero, while the rom size is set to 4MB. The MD5 routine copies the flash to PSRAM and runs it.

So the START function does actually do something. I just didn't get it at first because I thought the Genesis had to read the USB data coming from the PC. I didn't notice it was copying the flash to ram after waiting.  :-\

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2095
Re: Pressing START in the loader screen, what does it do?
« Reply #6 on: October 15, 2009, 01:00:32 PM »
As always , your posts are perfect and super detailed  >:D

Online Dr.neo

  • Administrator
  • Hero Member
  • *****
  • Posts: 3467
Re: Pressing START in the loader screen, what does it do?
« Reply #7 on: October 16, 2009, 12:10:37 AM »
As always , your posts are perfect and super detailed  >:D

i think so  ::sm-02::
In my world,have 0 and 1 only ......Matrix World......

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1491
  • Just a coding machine.
Re: Pressing START in the loader screen, what does it do?
« Reply #8 on: October 16, 2009, 09:57:05 AM »
Well, often not PERFECT... that's very hard to achieve, especially on unknown hardware like this. I do try to be detailed as that makes it easier for other programmers.

I'm glad I recognized what that was doing - I'm in the middle of making my own menu code, and I might have left that out if I thought it wasn't doing anything.
 ???

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2095
Re: Pressing START in the loader screen, what does it do?
« Reply #9 on: October 16, 2009, 01:56:13 PM »
Well, often not PERFECT... that's very hard to achieve, especially on unknown hardware like this. I do try to be detailed as that makes it easier for other programmers.

I'm glad I recognized what that was doing - I'm in the middle of making my own menu code, and I might have left that out if I thought it wasn't doing anything.
 ???

Cool!!!!!!!  ~sm-42.gif~ ~sm-42.gif~
By the way , the core will be in C? because then i can contribute to the source if you release it of course.
 ::sm-08.gif::

Also the menu has been updated to v220...i wonder what's new  ::sm-12.gif::

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1491
  • Just a coding machine.
Re: Pressing START in the loader screen, what does it do?
« Reply #10 on: October 16, 2009, 05:39:29 PM »
Cool!!!!!!!  ~sm-42.gif~ ~sm-42.gif~
By the way , the core will be in C? because then i can contribute to the source if you release it of course.
 ::sm-08.gif::

Also the menu has been updated to v220...i wonder what's new  ::sm-12.gif::

I was going to do it in C, but the need to run it from Work RAM as position independent code meant C was not really suitable. I also like working in 68000 assembly, so it's all assembly. I'm making it a nice gas-friendly assembly, so my gcc DevKit will compile it via makefile. Here's an example of the code: the startup done in gas fashion (and also fully commented as opposed to how you normally see the MD startup code).

Code: [Select]
| SEGA MegaDrive support code
| by Chilly Willy

|       .equ    BURAM, 1                /* uncomment this if you wish to have backup RAM */
|       .equ    DATASEG, 1              /* uncomment this if this is a C program (has initialized data segment) */

        .text

| Initial exception vectors. Since this exception table won't be here much of the time
| the boot menu runs with interrupts off, and exceptions will be assumed to hang.

        .long   0x01000000,initialize,exception,exception,exception,exception,exception,exception
        .long   exception,exception,exception,exception,exception,exception,exception,exception
        .long   exception,exception,exception,exception,exception,exception,exception,exception
        .long   exception,exception,exception,exception,hblank,exception,vblank,exception
        .long   exception,exception,exception,exception,exception,exception,exception,exception
        .long   exception,exception,exception,exception,exception,exception,exception,exception
        .long   exception,exception,exception,exception,exception,exception,exception,exception
        .long   exception,exception,exception,exception,exception,exception,exception,exception

| Standard MegaDrive ROM header at 0x100

        .ascii  "SEGA GENESIS    "
        .ascii  "(C)SEGA 2009.OCT"
        .ascii  "Neo Super 32X/MD"
        .ascii  "/SMS Flash Cart "
        .ascii  "                "
        .ascii  "Neo Super 32X/MD"
        .ascii  "/SMS Flash Cart "
        .ascii  "                "
        .ascii  "GM MK-0000 -00"
        .word   0x0000                  /* checksum - fixed by flashing app */
        .ascii  "J6              "
        .long   0x00000000,0x0001FFFF   /* ROM start, end */
        .long   0x00FF0000,0x00FFFFFF   /* RAM start, end */

        .ifdef  BURAM
        .ascii  "RA"                    /* External RAM */
        .byte   0xF8                    /* don't clear + odd bytes */
        .byte   0x20                    /* SRAM */
        .long   0x00200001,0x0020FFFF   /* SRAM start, end */
        .else
        .ascii  "            "          /* no SRAM */
        .endif

        .ascii  "    "
        .ascii  "                "
        .ascii  "                "
        .ascii  "                "
        .ascii  "JUE             "

| Standard MegaDrive startup at 0x200

initialize:
        tst.l   0xA10008                /* check CTRL1 and CTRL2 setup */
        bne.b   1f
        tst.w   0xA1000C                /* check CTRL3 setup */
1:
        bne     skip_setup              /* if any controller control port is setup, skip init */

| Initialize the MegaDrive hardware

        lea     InitData(PC),a5
        movem.w (a5)+,d5-d7
        movem.l (a5)+,a0-a4

| Check Hardware Version Number
        move.b  -0x10FF(a1),d0          /* 0xA10001 */
        andi.b  #0x0F,d0                /* VERS */
        beq     2f                      /* 0 = original hardware, TMSS not present */
        move.l  #0x53454741,0x2F00(a1)  /* Store Sega Security Code "SEGA" to TMSS */
2:
        move.w  (a4),d0                 /* read VDP Status reg */

| Set the stack pointer
        moveq   #0,d0
        movea.l d0,a6
        move    a6,usp

| Set VDP registers
        moveq   #23,d1
3:
        move.b  (a5)+,d5                /* lower byte = register data */
        move.w  d5,(a4)
        add.w   d7,d5                   /* + 0x0100 = next register */
        dbra    d1,3b
| clear VRAM
        move.l  (a5)+,(a4)              /* VDP Command = DMA Fill VRAM */
        move.w  d0,(a3)                 /* VDP (Fill) Data = 0 */

        move.w  d7,(a1)                 /* Z80 assert BusReq */
        move.w  d7,(a2)                 /* Z80 cancel Reset */
4:
        btst    d0,(a1)                 /* wait on BusReq */
        bne     4b
| Copy Z80 default program
        moveq   #37,d2
5:
        move.b  (a5)+,(a0)+
        dbra    d2,5b
| Restart Z80
        move.w  d0,(a2)                 /* Z80 assert Reset */
        move.w  d0,(a1)                 /* Z80 cancel BusReq */
        move.w  d7,(a2)                 /* Z80 cancel Reset */

| Clear Work RAM - (0x3FFF + 1) longs of 0
6:
        move.l  d0,-(a6)
        dbra    d6,6b

| Clear CRAM
        move.l  (a5)+,(a4)              /* set reg 1 and reg 15 */
        move.l  (a5)+,(a4)              /* write CRAM address 0 */
        moveq   #31,d3
7:
        move.l  d0,(a3)
        dbra    d3,7b

| Clear VSRAM
        move.l  (a5)+,(a4)              /* write VSRAM address 0 */
        moveq   #19,d4
8:
        move.l  d0,(a3)
        dbra    d4,8b

| Initialize PSG registers
        moveq   #3,d5
9:
        move.b  (a5)+,0x0011(a3)
        dbra    d5,9

        move.w  d0,(a2)                 /* Z80 cancel Reset */

        movem.l (a6),d0-d7/a0-a6        /* clear all CPU registers */
        move    #0x2700,sr              /* disable interrupts */

skip_setup:
        bra     continue


InitData:
        .word   0x8000, 0x3FFF, 0x0100      /* d5, d6, d7 initial values */
        .long   0x00A00000, 0x00A11100, 0x00A11200, 0x00C00000, 0x00C00004  /* a0 to a4 initial values */

| VDP register initialization values
        .byte   0x04    /* 8004 => write reg 0 = /IE1 (no HBL INT), /M3 (enable read H/V cnt) */
        .byte   0x14    /* 8114 => write reg 1 = /DISP (display off), /IE0 (no VBL INT), M1 (DMA enabled), /M2 (V28 mode) */
        .byte   0x30    /* 8230 => write reg 2 = Name Tbl A = 0xC000 */
        .byte   0x2c    /* 832C => write reg 3 = Name Tbl W = 0xB000 */
        .byte   0x07    /* 8407 => write reg 4 = Name Tbl B = 0xE000 */
        .byte   0x54    /* 8554 => write reg 5 = Sprite Attr Tbl = 0xA800 */
        .byte   0x00    /* 8600 => write reg 6 = always 0 */
        .byte   0x00    /* 8700 => write reg 7 = BG color */
        .byte   0x00    /* 8800 => write reg 8 = always 0 */
        .byte   0x00    /* 8900 => write reg 9 = always 0 */
        .byte   0x00    /* 8A00 => write reg 10 = HINT = 0 */
        .byte   0x00    /* 8B00 => write reg 11 = /IE2 (no EXT INT), full scroll */
        .byte   0x81    /* 8C81 => write reg 12 = H40 mode, no lace, no shadow/hilite */
        .byte   0x2b    /* 8D2B => write reg 13 = HScroll Tbl = 0xAC00 */
        .byte   0x00    /* 8E00 => write reg 14 = always 0 */
        .byte   0x01    /* 8F01 => write reg 15 = data INC = 1 */
        .byte   0x01    /* 9001 => write reg 16 = Scroll Size = 64x32 */
        .byte   0x00    /* 9100 => write reg 17 = W Pos H = left */
        .byte   0x00    /* 9200 => write reg 18 = W Pos V = top */
        .byte   0xff    /* 93FF => write reg 19 = DMA length low byte = 0xFF */
        .byte   0xff    /* 94FF => write reg 20 = DMA length high byte = 0xFF */
        .byte   0x00    /* 9500 => write reg 21 = DMA src addr low = 0 */
        .byte   0x00    /* 9600 => write reg 22 = DMA src addr mid = 0 */
        .byte   0x80    /* 9780 => write reg 23 = DMD = VRAM FILL, DMA src addr high = 0 */
| VDP Command
        .word   0x4000, 0x0080          /* DMA Fill VRAM */

| Z80 default program code
        .word   0xaf01, 0xd91f, 0x1127, 0x0021, 0x2600, 0xf977, 0xedb0, 0xdde1
        .word   0xfde1, 0xed47, 0xed4f, 0xd1e1, 0xf108, 0xd9c1, 0xd1e1, 0xf1f9
        .word   0xf3ed, 0x5636, 0xe9e9

| VDP Commands
        .word   0x8104, 0x8f01  /* set registers 1 (display off) and 15 (INC = 1) */
        .word   0xc000, 0x0000  /* write CRAM address 0 */
        .word   0x4000, 0x0010  /* write VSRAM address 0 */

| PSG register initialization values
        .byte   0x9f
        .byte   0xbf
        .byte   0xdf
        .byte   0xff

continue:
        tst.w    0x00C00004

| Initialization is skipped on reset, so don't assume anything here...

        move    #0x2700,sr              /* interrupts disabled */

| Clear Work RAM
        lea     0x00FF0000,a0
        movea.l a0,a1
        moveq   #0,d0
        move.w  #0x3FFF,d1
1:
        move.l  d0,(a0)+
        dbra    d1,1b
        movea.l a0,sp                   /* set stack pointer to top of RAM */

        .ifdef  DATASEG
| Copy initialized variables from ROM to RAM
        lea     _data,a0
        move.w  #_sdata-1,d0
2:
        move.b  (a0)+,(a1)+
        dbra    d0,2b
        .endif

        jsr     main

        bra     initialize

| Exception handlers - nothing since we don't use them

exception:
hblank:
vblank:
        rte

Online Dr.neo

  • Administrator
  • Hero Member
  • *****
  • Posts: 3467
Re: Pressing START in the loader screen, what does it do?
« Reply #11 on: October 17, 2009, 08:15:35 AM »
great ChillyWilly ,can't wait to see how nice is your new MD menu!  ~sm-43.gif~
In my world,have 0 and 1 only ......Matrix World......

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2095
Re: Pressing START in the loader screen, what does it do?
« Reply #12 on: October 17, 2009, 08:46:56 AM »
ChillyWilly thanks for posting this! I'm a beginner to 68K , but your code is so clean and commented that now i can understand all the boot process  ~sm-42.gif~ .

I've been studying the boot process using the source of emulators , but this is so clean!! Thanks !!
 O0O O0O O0O ~sm-44.gif~

I hope that you're going to release all the source so more people can learn from it.



By the way , these alpha-numerical labels are actually normal labels ?
Also great idea to add exception handler!

« Last Edit: October 17, 2009, 08:51:10 AM by Conle »

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1491
  • Just a coding machine.
Re: Pressing START in the loader screen, what does it do?
« Reply #13 on: October 17, 2009, 10:35:39 AM »
ChillyWilly thanks for posting this! I'm a beginner to 68K , but your code is so clean and commented that now i can understand all the boot process  ~sm-42.gif~ .

I've been studying the boot process using the source of emulators , but this is so clean!! Thanks !!
 O0O O0O O0O ~sm-44.gif~

I hope that you're going to release all the source so more people can learn from it.

By the way , these alpha-numerical labels are actually normal labels ?
Also great idea to add exception handler!

Thanks, that's the whole point to my own menu - make it very clean and very commented, and people should have something they can learn from as well as making the menu easy to maintain. I am about half way through the menu itself, and when I've got it done, I'll make a thread in the development sub-forum where I'll post all the code as well as some more insights into the hardware I had while working on the code.

That code above is my crt0.s file and is meant to be somewhat generic so I can use it for other MD projects. For example, if I used it for a game, I'd uncomment the equates at the top and actually use the exception handlers. Numeric labels are reusable local labels. You simply make a label

Code: [Select]
#:
then refer to it according to which way it is from the jump/branch. If you are referring to a numeric label earlier in the code, you use #b where the "b" stands for backward, and if referring to a numeric label later in the code, use #f where the "f" stands for forward. It goes to the FIRST number matching in the direction you specify, so you could just always use the same number if you can keep them straight.

Code: [Select]
1:
        tst.w (a0)
        bne.b 1f
        tst.w d0
        bne.b 1b
1:
        tst.w (a0)
        beq.b 1f
        bne.b 1b
        tst.w d1
        bne.b 1b
1:

I don't think that's quite as easy to follow, so I try to use unique numbers between absolute labels... in other words, I treat them like regular local labels.

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2095
Re: Pressing START in the loader screen, what does it do?
« Reply #14 on: October 18, 2009, 06:39:30 AM »
oops i missed this  ~sm-31.gif~ .

Thanks for replying , now it makes sense  :D

I can't wait to see your menu O0O O0O O0O
 ~sm-36.gif~