# HG changeset patch # User John Tsiombikas # Date 1519296260 -7200 # Node ID 58ebd84822e733ea796844bd0362cb4509fb5f1e # Parent 48093e4bd99addf49529a217191ea9f21032cd74 it works diff -r 48093e4bd99a -r 58ebd84822e7 Makefile --- a/Makefile Wed Feb 21 18:00:45 2018 +0200 +++ b/Makefile Thu Feb 22 12:44:20 2018 +0200 @@ -16,7 +16,7 @@ OBJCOPY = $(tool_prefix)objcopy ASFLAGS = -m68000 -CFLAGS = -m68000 -pedantic -Wall +CFLAGS = -m68000 -ffreestanding -pedantic -Wall -O3 LDFLAGS = -T amiga.ld -print-gc-sections \ -L/usr/lib/gcc-cross/m68k-linux-gnu/6 -lgcc @@ -34,4 +34,8 @@ .PHONY: clean clean: - rm -f $(obj) $(bin) $(elf) + rm -f $(obj) src/boot/boot.o $(bin) $(elf) + +.PHONY: run +run: + fs-uae diff -r 48093e4bd99a -r 58ebd84822e7 amiga.ld --- a/amiga.ld Wed Feb 21 18:00:45 2018 +0200 +++ b/amiga.ld Thu Feb 22 12:44:20 2018 +0200 @@ -3,13 +3,11 @@ PROVIDE (_stacktop = 0x80000); SECTIONS { - /* bootblock will load us at 100h, after the interrupt vectors */ - . = 0x100; + /* bootblock will load us at 10000h */ + . = 0x10000; - .text : { - * (.text.startup); - * (.text); - } + .startup : { * (.startup); } + .text : { * (.text); } .rodata : { * (.rodata); } .data : { * (.data); } diff -r 48093e4bd99a -r 58ebd84822e7 src/boot/boot.s --- a/src/boot/boot.s Wed Feb 21 18:00:45 2018 +0200 +++ b/src/boot/boot.s Thu Feb 22 12:44:20 2018 +0200 @@ -1,20 +1,20 @@ | vi:filetype=gas68k: .equ CMD_READ, 2 + .equ EXEC_DO_IO, -0x1c8 + .equ LOADADDR, 0x10000 - .equ EXEC_DO_IO, -0x1c8 - +start: | starting with trackdisk device I/O request pointer in a1 | load the program at 0x100 and jump there | program length is patched by mk_adf just before start -start: - move.l -6(%pc), %d0 | get binary size + move.l -6(%pc), %d0 | get program size + move.w #0x080, 0xdff180 move.l %d0, 0x24(%a1) | I/O length - move.l #0x100, 0x28(%a1) | I/O data pointer + move.l #LOADADDR, 0x28(%a1) | I/O data pointer move.l #512, 0x2c(%a1) | I/O offset (skip first sector) move.w #CMD_READ, 0x1c(%a1) | I/O command - move.l %a1, -(%sp) jsr EXEC_DO_IO(%a6) - move.l (%sp)+, %a1 + move.w #0xf0f, 0xdff180 - bra 0x100 + jmp LOADADDR .align 4 diff -r 48093e4bd99a -r 58ebd84822e7 src/copper.c --- a/src/copper.c Wed Feb 21 18:00:45 2018 +0200 +++ b/src/copper.c Thu Feb 22 12:44:20 2018 +0200 @@ -5,7 +5,7 @@ static uint32_t *copmem, *curlist; static int mode, copmem_size; -extern uint32_t _mem_start; +extern uint32_t **_mem_start; int init_copper(int maxlist, int nlists) { @@ -14,7 +14,7 @@ mode = nlists >= COPPER_DOUBLE ? COPPER_DOUBLE : COPPER_SINGLE; copmem_size = maxlist * 4 * mode; - copmem = (uint32_t*)_mem_start; + copmem = *_mem_start; curlist = copperlist = copmem; *curlist = COPPER_END; diff -r 48093e4bd99a -r 58ebd84822e7 src/intr.s --- a/src/intr.s Wed Feb 21 18:00:45 2018 +0200 +++ b/src/intr.s Thu Feb 22 12:44:20 2018 +0200 @@ -10,4 +10,5 @@ movem.l (%sp)+, %d0-%a6 rte + .global dbgval dbgval: .word 0x00f diff -r 48093e4bd99a -r 58ebd84822e7 src/main.c --- a/src/main.c Wed Feb 21 18:00:45 2018 +0200 +++ b/src/main.c Thu Feb 22 12:44:20 2018 +0200 @@ -2,58 +2,69 @@ #include "intr.h" #include "copper.h" -void wait_vpos(int x); -void wait_vblank(void); - #define BPLSZ (320 / 8 * 256) static unsigned char fb0[BPLSZ]; +extern uint16_t dbgval; + +#define wait_vpos(x) \ + asm volatile ( \ + "0: move.l 0xdff004, %%d0\n\t" \ + "and.l #0x1ff00, %%d0\n\t" \ + "cmp.l %0, %%d0\n\t" \ + "bne 0b\n\t" \ + :: "i"((x) << 8) : "%d0") + +#define wait_vblank() wait_vpos(300) +#define wait_scanline(x) wait_vpos((x) + 0x2c) + +#define clear_bpl(p) \ + asm volatile ( \ + "move.l %0, %%a0\n\t" \ + "move.l %1, %%d0\n\t" \ + "0: clr.l (%%a0)+\n\t" \ + "dbra %%d0, 0b\n\t" \ + :: "a"(p), "i"(BPLSZ / 4 - 1) \ + : "a0", "d0") + +static uint32_t coplist[] = { + COPPER_MOVE(REGN_BPL1PTH, 0), + COPPER_MOVE(REGN_BPL1PTL, 0), + COPPER_VWAIT(50), + COPPER_MOVE(REGN_COLOR0, 0x00a), + COPPER_VWAIT(60), + COPPER_MOVE(REGN_COLOR0, 0x008), + COPPER_END +}; + int main(void) { - uint32_t fb0_addr = (uint32_t)fb0; - REG_INTENA = SETBITS(INTEN_VERTB | INTEN_MASTER); REG_DMACON = CLRBITS(DMA_ALL); - REG_BPLCON0 = BPLCON0_COUNT(0) | BPLCON0_COLOR; + REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR; REG_BPLCON1 = 0; REG_DIWSTART = 0x2981; REG_DIWSTOP = 0x29c1; REG_DDFSTART = 0x38; REG_DDFSTOP = 0xd0; - REG_COLOR0 = 0x00f; - REG_COLOR1 = 0xff0; - - init_copper(0, 0); + REG_COLOR0 = 0x008; + REG_COLOR1 = 0xaaa; wait_vblank(); - add_copper(COPPER_MOVE(REGN_BPL1PTH, fb0_addr >> 16)); - add_copper(COPPER_MOVE(REGN_BPL1PTL, fb0_addr)); + coplist[0] = COPPER_MOVE(REGN_BPL1PTH, (uint32_t)fb0 >> 16); + coplist[1] = COPPER_MOVE(REGN_BPL1PTL, (uint32_t)fb0); + REG32_COP1LC = (uint32_t)coplist; + REG_COPJMP1 = 0; - add_copper(COPPER_VWAIT(64)); - add_copper(COPPER_MOVE(REGN_COLOR0, 0xf00)); - add_copper(COPPER_VWAIT(70)); - add_copper(COPPER_MOVE(REGN_COLOR0, 0x00f)); + fb0[128 * 320 / 8 + 160 / 8] = 8; - add_copper(COPPER_END); + REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER); - fb0[128 * 320 / 8] = 8; + for(;;) { + wait_vblank(); + } - REG_DMACON = SETBITS(DMA_COPPER | DMA_MASTER); - enable_intr(); - - for(;;); return 0; } - -void wait_vpos(int x) -{ - x <<= 8; - while((REG32_VPOSR & 0x1ff00) < x); -} - -void wait_vblank(void) -{ - wait_vpos(300); -} diff -r 48093e4bd99a -r 58ebd84822e7 src/startup.s --- a/src/startup.s Wed Feb 21 18:00:45 2018 +0200 +++ b/src/startup.s Thu Feb 22 12:44:20 2018 +0200 @@ -1,9 +1,8 @@ | vi:filetype=gas68k: - .global start .global halt_cpu .extern main - .section .text.startup + .section .startup,"a" | enter supervisor mode (assumes VBR=0) move.l #super, 0x80 @@ -16,7 +15,7 @@ move.l #_bss_end, %a1 cmp.l %a0, %a1 beq.s 1f | skip zeroing if the section is empty -0: clr.l (%a0)+ +0: clr.b (%a0)+ cmp.l %a0, %a1 bne.s 0b 1: