2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/display.c Sun May 28 19:03:58 2017 +0200
2.3 @@ -0,0 +1,58 @@
2.4 +/*
2.5 + * Write to display memory.
2.6 + *
2.7 + * Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
2.8 + *
2.9 + * This program is free software: you can redistribute it and/or modify
2.10 + * it under the terms of the GNU General Public License as published by
2.11 + * the Free Software Foundation, either version 3 of the License, or
2.12 + * (at your option) any later version.
2.13 + *
2.14 + * This program is distributed in the hope that it will be useful,
2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.17 + * GNU General Public License for more details.
2.18 + *
2.19 + * You should have received a copy of the GNU General Public License
2.20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2.21 + */
2.22 +
2.23 +#include <stdint.h>
2.24 +#include "mips.h"
2.25 +#include "vga.h"
2.26 +
2.27 +void init_framebuffer_with_pattern()
2.28 +{
2.29 + uint32_t *addr = (uint32_t *) KSEG1_BASE;
2.30 + uint32_t base, value;
2.31 + uint16_t x, y;
2.32 + uint8_t row, offset;
2.33 +
2.34 + for (y = 0; y < LINE_COUNT; y++)
2.35 + {
2.36 + /* Start each line with a base value. */
2.37 +
2.38 + row = y / 16;
2.39 + base = (row << 26) | (row << 18) | (row << 10) | (row << 2);
2.40 +
2.41 + /* Set the intensity bit on every other palette row. */
2.42 +
2.43 + if (row % 2) base |= 0x80808080;
2.44 +
2.45 + for (x = 0; x < LINE_LENGTH; x += 4)
2.46 + {
2.47 + /* Combine the base value with the offset. */
2.48 +
2.49 + offset = x / 20;
2.50 + value = base | (offset << 24) | (offset << 16) | (offset << 8) | offset;
2.51 +
2.52 + /* Store the value. */
2.53 +
2.54 + *addr = value;
2.55 +
2.56 + /* Access the next word. */
2.57 +
2.58 + addr++;
2.59 + }
2.60 + }
2.61 +}
3.1 --- a/vga.S Sun May 28 17:04:48 2017 +0200
3.2 +++ b/vga.S Sun May 28 19:03:58 2017 +0200
3.3 @@ -19,20 +19,7 @@
3.4
3.5 #include "mips.h"
3.6 #include "pic32.h"
3.7 -
3.8 -#define LINE_LENGTH 160 /* pixels */
3.9 -
3.10 -#define HFREQ_LIMIT 643 /* 24MHz cycles */
3.11 -#define HSYNC_START 460 /* 24MHz cycles */
3.12 -#define HSYNC_LIMIT 64 /* 24MHz cycles */
3.13 -#define HSYNC_END (HSYNC_START + HSYNC_LIMIT)
3.14 -
3.15 -#define VISIBLE_START 70 /* horizontal lines, back porch end */
3.16 -#define VFP_START 582 /* horizontal lines, front porch start */
3.17 -#define VSYNC_START 620 /* horizontal lines, front porch end */
3.18 -#define VSYNC_END 622 /* horizontal lines, back porch start */
3.19 -
3.20 -#define SCREEN_SIZE (40 * 1024)
3.21 +#include "vga.h"
3.22
3.23 /* Disable JTAG functionality on pins. */
3.24
3.25 @@ -67,6 +54,7 @@
3.26
3.27 .text
3.28 .globl _start
3.29 +.extern init_framebuffer_with_pattern
3.30
3.31 _start:
3.32 /*
3.33 @@ -126,7 +114,7 @@
3.34
3.35 /* Initialise framebuffer. */
3.36
3.37 - jal init_framebuffer
3.38 + jal init_framebuffer_with_pattern
3.39 nop
3.40
3.41 sync
3.42 @@ -589,78 +577,6 @@
3.43
3.44
3.45
3.46 -init_framebuffer_with_pattern:
3.47 - li $v0, KSEG1_BASE
3.48 - li $t8, SCREEN_SIZE
3.49 - move $t2, $zero /* x div 20 */
3.50 - move $t3, $zero /* x mod 20 */
3.51 - move $t4, $zero /* y mod 16 */
3.52 - move $t5, $zero /* base value: [(0...15) << 2] * 4 */
3.53 - move $t6, $zero /* offset value: [0...7] * 4 */
3.54 -
3.55 -_init_fbwp_loop:
3.56 - li $t9, 0xfcfcfcfc
3.57 - and $t9, $t9, $t5 /* get bits 5...2 of the base value */
3.58 - or $t9, $t9, $t6 /* combine base<5:2> and offset values */
3.59 -
3.60 - /* Test for bit 2 and set bit 7 if set, thus setting the intensity. */
3.61 -
3.62 - andi $t7, $t5, 0b00000100
3.63 - beqz $t7, _init_fbwp_loop_write
3.64 - nop
3.65 -
3.66 - li $t7, 0x80808080
3.67 - or $t9, $t9, $t7 /* set intensity in each byte */
3.68 -
3.69 -_init_fbwp_loop_write:
3.70 - sw $t9, 0($v0)
3.71 - addiu $v0, $v0, 4
3.72 -
3.73 - addiu $t3, $t3, 1 /* (x mod 20) += 1 */
3.74 -
3.75 - /* Update the offset value every twenty pixels. */
3.76 -
3.77 - addiu $t9, $t3, -5
3.78 - bnez $t9, _init_fbwp_loop_end
3.79 - nop
3.80 -
3.81 - li $t9, 0x01010101
3.82 - addu $t6, $t6, $t9 /* offset += [1] * 4 */
3.83 - addiu $t2, $t2, 1 /* (x div 20) += 1 */
3.84 - move $t3, $zero /* (x mod 20) = 0 */
3.85 -
3.86 - /* Test for the next line. */
3.87 -
3.88 - addiu $t9, $t2, -8
3.89 - bnez $t9, _init_fbwp_loop_end
3.90 - nop
3.91 -
3.92 - move $t2, $zero /* (x div 20) = 0 */
3.93 - move $t6, $zero /* offset = 0 */
3.94 -
3.95 -_init_fbwp_loop_next_y:
3.96 - addiu $t4, $t4, 1 /* (y mod 16) += 1 */
3.97 -
3.98 - /* Update the base value every sixteen rows. */
3.99 -
3.100 - addiu $t9, $t4, -16
3.101 - bnez $t9, _init_fbwp_loop_end
3.102 - nop
3.103 -
3.104 - li $t9, 0x04040404
3.105 - addu $t5, $t5, $t9 /* base += [(1 << 2)] * 4 */
3.106 - move $t4, $zero /* (y mod 16) = 0 */
3.107 -
3.108 -_init_fbwp_loop_end:
3.109 - addiu $t8, $t8, -4
3.110 - bnez $t8, _init_fbwp_loop
3.111 - nop
3.112 -
3.113 - jr $ra
3.114 - nop
3.115 -
3.116 -
3.117 -
3.118 /* Utilities. */
3.119
3.120 handle_error_level:
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/vga.h Sun May 28 19:03:58 2017 +0200
4.3 @@ -0,0 +1,19 @@
4.4 +#ifndef __VGA_H__
4.5 +#define __VGA_H__
4.6 +
4.7 +#define LINE_LENGTH 160 /* pixels */
4.8 +#define LINE_COUNT 256 /* distinct display lines */
4.9 +
4.10 +#define HFREQ_LIMIT 643 /* 24MHz cycles */
4.11 +#define HSYNC_START 460 /* 24MHz cycles */
4.12 +#define HSYNC_LIMIT 64 /* 24MHz cycles */
4.13 +#define HSYNC_END (HSYNC_START + HSYNC_LIMIT)
4.14 +
4.15 +#define VISIBLE_START 70 /* horizontal lines, back porch end */
4.16 +#define VFP_START (VISIBLE_START + 2 * LINE_COUNT)
4.17 +#define VSYNC_START 620 /* horizontal lines, front porch end */
4.18 +#define VSYNC_END 622 /* horizontal lines, back porch start */
4.19 +
4.20 +#define SCREEN_SIZE (40 * 1024)
4.21 +
4.22 +#endif /* __VGA_H__ */