Send data to PC via USB Gecko
#1
Send data to PC via USB Gecko

This code will send a byte to your PC via USB Gecko. The code included is provided as an example of how it works. It will send each character of a String that is passed into the strlen method.

(NTSC-U)
C20206FC 0000000E
8C040001 9421FFB0
BDC10008 7E600026
3A400019 3A2000D0
3E00CD00 7C0F0378
2C0F0000 40A20008
39E0000A 55EFA016
65EFB000 92306814
91F06824 92506820
81D06820 71CE0001
40A2FFF8 81F06824
91D06814 55EF37FF
4182FFC4 7E6FF120
B9C10008 38210050
60000000 00000000

(PAL)
C202125C 0000000E
8C040001 9421FFB0
BDC10008 7E600026
3A400019 3A2000D0
3E00CD00 7C0F0378
2C0F0000 40A20008
39E0000A 55EFA016
65EFB000 92306814
91F06824 92506820
81D06820 71CE0001
40A2FFF8 81F06824
91D06814 55EF37FF
4182FFC4 7E6FF120
B9C10008 38210050
60000000 00000000

(NTSC-J)
C2021180 0000000E
8C040001 9421FFB0
BDC10008 7E600026
3A400019 3A2000D0
3E00CD00 7C0F0378
2C0F0000 40A20008
39E0000A 55EFA016
65EFB000 92306814
91F06824 92506820
81D06820 71CE0001
40A2FFF8 81F06824
91D06814 55EF37FF
4182FFC4 7E6FF120
B9C10008 38210050
60000000 00000000

(NTSC-K)
C20212C4 0000000E
8C040001 9421FFB0
BDC10008 7E600026
3A400019 3A2000D0
3E00CD00 7C0F0378
2C0F0000 40A20008
39E0000A 55EFA016
65EFB000 92306814
91F06824 92506820
81D06820 71CE0001
40A2FFF8 81F06824
91D06814 55EF37FF
4182FFC4 7E6FF120
B9C10008 38210050
60000000 00000000



Code:
#============================================================#
#                           Source                           #
#------------------------------------------------------------#
# Original Address Ports:                                    #
# RMCE - 0x800206FC                                          #
# RMCP - 0x8002125C                                          #
# RMCJ - 0x80021180                                          #
# RMCK - 0x800212C4                                          #
#============================================================#

#============================================================#
#                           strlen                           #
#------------------------------------------------------------#
#               r4                                           #
# strlen(const char* str);                                   #
#============================================================#

.globl _start
_start:
    lbzu    r0, 1(r4) # Original Instruction -- Load the next character in the String into r0
    
    # Function Prologue
    stwu    r1, -80(r1) # Make space for 18 registers
    stmw    r14, 8(r1)  # Push r14-r31 onto the stack
    
    mfcr    r19 # Preserve the Condition Register in r19
    
#============================================================#
#                        exi_sendbyte                        #
#============================================================#
    
exi_sendbyte:
    li    r18, 0x19 # 2 Bytes Immediate Read/Write
    li    r17, 0xD0 # Memory Card [USB Gecko] Port B (Channel 1, Device 0, Frequnecy 3 (32Mhz Clock))
    lis    r16, 0xCD00 # Hardware Base Registers
    
#============================================================#
#                        exi_sendloop                        #
#============================================================#
    
exi_sendloop:
    mr    r15, r0 # Load the byte to be transfered into r15
    
    cmpwi    r15, 0 # Check if the byte is a null-terminator (\0)
    bne+    cr0, branch_not_null_terminator
    li    r15, 0xA # If it is, replace it with a newline character (\n) [For GeckoReader]
    
branch_not_null_terminator:
    slwi    r15, r15, 20 # (sendbyte << 20);
    oris    r15, r15, 0xB000 # 0xB0000000 (Send Write Byte Command) | (OR)
    
#============================================================#
#                        exi_checksend                       #
#============================================================#
    
exi_checksend:
    stw    r17, 0x6814(r16) # Store the word in r17 into the EXI Channel 1 Parameter Register to select the USB Gecko device
    stw    r15, 0x6824(r16) # Store the word in r15 into the EXI Channel 1 Immediate Data Register to store the data
    stw    r18, 0x6820(r16) # Store the word in r18 into the EXI Channel 1 Control Register to start the transfer
    
#============================================================#
#                    exi_checkreceivewait                    #
#============================================================#
    
exi_checkreceivewait:
    lwz    r14, 0x6820(r16) # Load the word in the EXI Channel 1 Control Register into r14
    andi.    r14, r14, 1 # Return 0 or 1, 1 if the transfer is not complete
    bne-    cr0, exi_checkreceivewait # while ((exi_chan1cr)&1);
    
    lwz    r15, 0x6824(r16) # Load the word in the EXI Channel 1 Immediate Data Register into r15
    stw    r14, 0x6814(r16) # Store the word in r14 into the EXI Channel 1 Parameter Register to indicate the transfer is complete
    
    extrwi.    r15, r15, 1, 5 # Return 0 or 1, 1 if the byte was received
    beq+    cr0, exi_sendloop # Retry if the byte was not received
    
# Function Epilogue...
    mtcr    r19 # Restore the Condition Register from r19
    
    lmw    r14, 8(r1) # Pop r14-r31 off the stack
    addi    r1, r1, 80 # Release the space



Code Creator: Star
Code Credits: Nuke, Kenobi
[Image: kMjbn9w.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)