GCCを使ってぴゅう太でHELLO WORLDする その2

GCC for the TIですがBash on Windowsでも動きました!

http://atariage.com/forums/topic/164295-gcc-for-the-ti/

ぴゅう太サンプルプログラムをつくりました。念のためGCC使うには8KB拡張RAM(6000-7FFF)が必要です。

http://d.hatena.ne.jp/tanam/20160923/1474645666

Makefile

GAS=/home/user01/tigcc/bin/tms9900-as
LD=/home/user01/tigcc/bin/tms9900-ld
CC=/home/user01/tigcc/bin/tms9900-gcc

ELF2CART=/home/user01/tigcc/bin/elf2cart

LDFLAGS=\
  --section-start .text=8000 --section-start .data=4000

OBJECT_LIST=\
  header.o\
  crt0.o\
  sub.o\
  main.o

PREREQUISITES=\
  $(OBJECT_LIST)
  
all: $(PREREQUISITES)
	$(LD) $(OBJECT_LIST) $(LDFLAGS) -o hello.elf > hello.map
	$(ELF2CART) hello.elf hello.bin

.phony clean:
	rm *.o
	rm *.elf
	rm *.bin
	rm *.map

%.o: %.asm
	$(GAS) $< -o $@

%.o: %.c
	$(CC) -c $< -O2 -o $@

header.asm

# ROM header
  byte 0x55, 0x55, 0x04, 0x60

# Entry point for program
  data  _start

crt0.asm

 def _start

_start:
# limi 0       # Disable interrupts
  lwpi >7000   # Set initial workspace

# Create stack
  li sp, >8000

# Enter C environment
  bl @main

# We cannot properly handle a return from C code.
# Instead, just spin here until the console is reset
  jmp $

main.c

void sub(void); // prototype

int main() {
asm volatile("lwpi >f0a0");
asm volatile("li   r12,>0060"); // INITIAL CELL FUNCTION
asm volatile("bl   @>019c");
asm volatile("li   r7,>1800");  // VRAM FILL FUNCTION
asm volatile("li   r8,>f200");
asm volatile("li   r9,>2000");
asm volatile("bl   @>002c");
asm volatile("li   r7,>1800");  // SCROLL AREA FUNCTION
asm volatile("li   r8,>02e0");
asm volatile("li   r9,>06e0");
asm volatile("bl   @>0180");
asm volatile("bl   @>023c");   // LINE INPUT FUNCTION
asm volatile("nop");
asm volatile("nop");
asm volatile("li   r9,>0000"); // SET CURSOR TO 0000
asm volatile("lwpi >7000");
    sub();
    return 0;
}

sub.c

char c_putch(char c){
char *addr=0x4ff0;
        if (c >= '0' && c <='9') {
*addr++=0x19;
*addr=0xa2+8*(c-'0');
        } else if (c >= 'A' && c <='Z') {
*addr++=0x1a;
*addr=0x2a+8*(c-'A');
} else {
*addr++=0x19;
*addr=0x22;
}
asm volatile("lwpi >f0a0");
asm volatile("mov  @>4ff0,r7");
asm volatile("bl   @>0194");
asm volatile("lwpi >7000");
return 0;
}

void c_puts(const char *s) {while(*s) c_putch(*s++);}

void sub()
{
c_puts("HELLO WORLD");
}