amiga_boottest
changeset 4:995d42b33974 tip
serial output
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 23 Feb 2018 13:29:37 +0200 |
parents | 555b986cc420 |
children | |
files | README src/hwregs.h src/main.c src/serial.c src/serial.h |
diffstat | 5 files changed, 141 insertions(+), 12 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/README Fri Feb 23 13:29:37 2018 +0200 1.3 @@ -0,0 +1,27 @@ 1.4 +Amiga floppy boot test 1.5 +---------------------- 1.6 +Bootblock code in src/boot/boot.s uses the Amiga exec in ROM to load the 1.7 +flat binary image from from the first N sectors to address 0x10000, and jumps 1.8 +there. The size of the binary is patched immediately before the first 1.9 +instruction of the boot code by tools/mk_adf.py. 1.10 + 1.11 +Linkscript puts code from the .startup segment (src/startup.s) at the load 1.12 +address, and it starts by setting the trap0 exception vector to point to the 1.13 +next instruction and executes a trap 0, to enter supervisor mode and take 1.14 +complete control of the system. Then it clears .bss, sets the stack and calls 1.15 +the C main function. 1.16 + 1.17 +A few words about the graphics hack 1.18 +----------------------------------- 1.19 +The IFS fractal is calculated in 16.16 fixed point, using a mersenne twister 1.20 +random number generator (src/rng.c) for picking an IFS transformation to do each 1.21 +time. Two bitplanes are enabled both pointing to the same IFS pixel buffer, with 1.22 +a few scanlines offset and a different per-pixel scroll (data fetch delay) in 1.23 +BPLCON1. The palette is set up in a way to give priority to bitplane 0, i.e. use 1.24 +green for pixels with bit 0 set, and use a shadow color for pixels which have 1.25 +only bit 1 set. This gives the illusion of a shadow layer. 1.26 + 1.27 +Serial debug output 1.28 +------------------- 1.29 +Serial comm needs RTS/CTS (hardware) flow control. 1.30 + stty 38400 crtscts cs8 -parenb -ixon -ixoff raw -iutf8 -F /dev/ttyUSB0
2.1 --- a/src/hwregs.h Thu Feb 22 14:46:32 2018 +0200 2.2 +++ b/src/hwregs.h Fri Feb 23 13:29:37 2018 +0200 2.3 @@ -345,6 +345,10 @@ 2.4 #define REG_COPJMP1 REG(REGN_COPJMP1) 2.5 #define REG_COPJMP2 REG(REGN_COPJMP2) 2.6 2.7 +#define REG_SERPER REG(REGN_SERPER) 2.8 +#define REG_SERDATR REG(REGN_SERDATR) 2.9 +#define REG_SERDAT REG(REGN_SERDAT) 2.10 + 2.11 /* ------ bits ------- */ 2.12 #define SETBITS(x) ((x) | 0x8000) 2.13 #define CLRBITS(x) (x) 2.14 @@ -425,4 +429,16 @@ 2.15 #define CIAA_PA_FIR0 0x40 2.16 #define CIAA_PA_FIR1 0x80 2.17 2.18 +enum { 2.19 + SERDATR_STOP8 = 0x0100, 2.20 + SERDATR_STOP9 = 0x0200, 2.21 + SERDATR_RXD = 0x0800, 2.22 + SERDATR_TSRE = 0x1000, 2.23 + SERDATR_TBE = 0x2000, 2.24 + SERDATR_RBF = 0x4000, 2.25 + SERDATR_OVRUN = 0x8000 2.26 +}; 2.27 + 2.28 +#define ADKCON_UARTBRK 0x0800 2.29 + 2.30 #endif /* HWREGS_H_ */
3.1 --- a/src/main.c Thu Feb 22 14:46:32 2018 +0200 3.2 +++ b/src/main.c Fri Feb 23 13:29:37 2018 +0200 3.3 @@ -2,9 +2,14 @@ 3.4 #include "intr.h" 3.5 #include "copper.h" 3.6 #include "rng.h" 3.7 +#include "serial.h" 3.8 3.9 -#define BPLSZ (320 / 8 * 256) 3.10 -static unsigned char fb0[BPLSZ]; 3.11 +#define SCR_W 336 3.12 +#define SCR_H 256 3.13 +#define HMOD ((SCR_W - 320) / 8) 3.14 + 3.15 +#define BPLSZ (SCR_W / 8 * SCR_H) 3.16 +static unsigned char fb0[BPLSZ + 3 * SCR_W]; 3.17 3.18 extern uint16_t dbgval; 3.19 3.20 @@ -29,8 +34,7 @@ 3.21 : "a0", "d0") 3.22 3.23 static uint32_t coplist[] = { 3.24 - COPPER_MOVE(REGN_BPL1PTH, 0), 3.25 - COPPER_MOVE(REGN_BPL1PTL, 0), 3.26 + 0, 0, 0, 0, /* placeholder of bitplane pointer setting */ 3.27 3.28 COPPER_MOVE(REGN_COLOR0, 0x234), 3.29 COPPER_VWAIT(15), 3.30 @@ -52,22 +56,31 @@ 3.31 { 3.32 int32_t x = 0, y = 0; 3.33 3.34 + ser_init(38400); 3.35 + ser_print("Amiga debug console initialized\n"); 3.36 + 3.37 REG_INTENA = SETBITS(INTEN_VERTB | INTEN_MASTER); 3.38 3.39 REG_DMACON = CLRBITS(DMA_ALL); 3.40 - REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR; 3.41 - REG_BPLCON1 = 0; 3.42 + REG_BPLCON0 = BPLCON0_COUNT(2) | BPLCON0_COLOR; 3.43 + REG_BPLCON1 = 0xfa; 3.44 + REG_BPL1MOD = HMOD - 2; 3.45 + REG_BPL2MOD = HMOD - 2; 3.46 REG_DIWSTART = 0x2981; 3.47 REG_DIWSTOP = 0x29c1; 3.48 - REG_DDFSTART = 0x38; 3.49 + REG_DDFSTART = 0x30; 3.50 REG_DDFSTOP = 0xd0; 3.51 3.52 REG_COLOR0 = 0x235; 3.53 - REG_COLOR1 = 0x2f5; 3.54 + REG_COLOR1 = 0x2e5; 3.55 + REG_COLOR2 = 0x113; 3.56 + REG_COLOR3 = 0x2e5; 3.57 3.58 wait_vblank(); 3.59 - coplist[0] = COPPER_MOVE(REGN_BPL1PTH, (uint32_t)fb0 >> 16); 3.60 - coplist[1] = COPPER_MOVE(REGN_BPL1PTL, (uint32_t)fb0); 3.61 + coplist[0] = COPPER_MOVE(REGN_BPL1PTH, ((uint32_t)fb0 + 3 * SCR_W / 8) >> 16); 3.62 + coplist[1] = COPPER_MOVE(REGN_BPL1PTL, (uint32_t)fb0 + 3 * SCR_W / 8); 3.63 + coplist[2] = COPPER_MOVE(REGN_BPL2PTH, (uint32_t)fb0 >> 16); 3.64 + coplist[3] = COPPER_MOVE(REGN_BPL2PTL, (uint32_t)fb0); 3.65 REG32_COP1LC = (uint32_t)coplist; 3.66 REG_COPJMP1 = 0; 3.67 3.68 @@ -105,11 +118,15 @@ 3.69 py = 128 - (x >> 11); 3.70 3.71 if(py >= 0) { 3.72 - pptr = fb0 + (py * 320 + px) / 8; 3.73 + pptr = fb0 + (py * SCR_W + px) / 8; 3.74 *pptr = *pptr | (0x80 >> (px & 7)); 3.75 } 3.76 3.77 - wait_vblank(); 3.78 + if((REG_CIAA_PORTA & CIAA_PA_FIR0) == 0) { 3.79 + ser_print("restarting fractal\n"); 3.80 + wait_vblank(); 3.81 + clear_bpl(fb0); 3.82 + } 3.83 } 3.84 3.85 return 0;
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/serial.c Fri Feb 23 13:29:37 2018 +0200 4.3 @@ -0,0 +1,48 @@ 4.4 +#include "hwregs.h" 4.5 +#include "serial.h" 4.6 + 4.7 +#define CLK 3546895 4.8 +#define BVAL(b) (CLK / (b) - 1) 4.9 + 4.10 +static inline uint16_t baudval(int baud) 4.11 +{ 4.12 + switch(baud) { 4.13 + case 110: return BVAL(110); 4.14 + case 300: return BVAL(300); 4.15 + case 600: return BVAL(600); 4.16 + case 1200: return BVAL(1200); 4.17 + case 2400: return BVAL(2400); 4.18 + case 4800: return BVAL(4800); 4.19 + case 9600: return BVAL(9600); 4.20 + case 14400: return BVAL(14400); 4.21 + case 19200: return BVAL(19200); 4.22 + case 38400: return BVAL(38400); 4.23 + case 57600: return BVAL(57600); 4.24 + case 115200: return BVAL(115200); 4.25 + default: 4.26 + break; 4.27 + } 4.28 + return BVAL(baud); 4.29 +} 4.30 + 4.31 +void ser_init(int baud) 4.32 +{ 4.33 + REG_SERPER = baudval(baud) & 0x7fff; 4.34 +} 4.35 + 4.36 +/* 4.37 +void ser_putchar(int c) 4.38 +{ 4.39 + REG_SERDAT = ((uint16_t)c & 0xff) | 0x100; 4.40 +} 4.41 +*/ 4.42 + 4.43 +void ser_print(const char *s) 4.44 +{ 4.45 + while(*s) { 4.46 + if(*s == '\n') { 4.47 + ser_putchar('\r'); 4.48 + } 4.49 + ser_putchar(*s++); 4.50 + } 4.51 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/serial.h Fri Feb 23 13:29:37 2018 +0200 5.3 @@ -0,0 +1,21 @@ 5.4 +#ifndef SERIAL_H_ 5.5 +#define SERIAL_H_ 5.6 + 5.7 +#include "hwregs.h" 5.8 + 5.9 +/* dff030 is REG_SERDAT 5.10 + * dff018 is REG_SERDATR 5.11 + * bit 13 of SERDATR is TBE (transmit buffer empty) 5.12 + */ 5.13 +#define ser_putchar(c) \ 5.14 + asm volatile( \ 5.15 + "or.w #0x100, %0\n\t" \ 5.16 + "0: btst #13, 0xdff018\n\t" \ 5.17 + "beq 0b\n\t" \ 5.18 + "move.w %0, 0xdff030\n\t" \ 5.19 + :: "d"((int16_t)c)) 5.20 + 5.21 +void ser_init(int baud); 5.22 +void ser_print(const char *s); 5.23 + 5.24 +#endif /* SERIAL_H_ */