Skip to content

Commit 1e80800

Browse files
committed
Bug fix and optimisations
ALU.si simplify busy logic in integer division. Correct error in moving to the next bit in CLMUL background.si correctly wire up random number generator. Also changes in PAWS.si and video_memmap.si to pass 10 bits to background _memmap. terminal.si tidy up "variables" DEMO add in an NuCu program to randomly set the colours for the falling stars to provide a twinkling effect.;
1 parent 6f0827f commit 1e80800

File tree

10 files changed

+84
-68
lines changed

10 files changed

+84
-68
lines changed

RV64/ALU.si

+5-4
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,11 @@ unit alu_multicycle(
319319
alucarrylessmultiply ALUCLMUL( function3 <: function3, sourceReg1 <: sourceReg1, sourceReg2 <: sourceReg2 );
320320

321321
ALUMD.start := start & isALUMD; ALUCLMUL.start := start & isALUCLM;
322+
busy := start | ALUMD.busy | ALUCLMUL.busy;
322323

323324
algorithm <autorun> {
324325
while(1) {
325-
if( start ) { busy = 1; while( ALUMD.busy | ALUCLMUL.busy ) {} busy = 0; }
326+
if( start ) { while( ALUMD.busy | ALUCLMUL.busy ) {} }
326327
}
327328
}
328329

@@ -348,11 +349,11 @@ unit dointegerdivide(
348349
uint64 remainderNEXT <:: __unsigned(temporary) - ( bitresult ? __unsigned(divisor) : 0 );
349350
uint1 update = uninitialised;
350351

351-
update := 0;
352+
update := 0; busy := start | ~&bit;
352353

353354
algorithm <autorun> {
354355
while(1) {
355-
if( start ) { busy = 1; bit = startingbit; quotient = 0; remainder = 0; while( ~&bit ) { update = 1; } busy = 0; }
356+
if( start ) { bit = startingbit; quotient = 0; remainder = 0; while( ~&bit ) { update = 1; } }
356357
}
357358
}
358359
always_after {
@@ -411,7 +412,7 @@ unit alucarrylessmultiply(
411412
uint7 startat <:: &function3;
412413
uint7 stopat <:: ( function3 == 2b10 ) ? 64 : 63;
413414
uint7 count = uninitialised;
414-
uint7 countNEXT <:: count - 1;
415+
uint7 countNEXT <:: count + 1;
415416
uint1 update = uninitialised;
416417

417418
update := 0;

RV64/GPU.si

+3-6
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ unit drawline(
450450

451451
while(1) {
452452
if( start ) {
453-
busy = 1; ( x, y ) = copycoordinates( start_x, start_y ); numerator = start_numerator; count = 0; offset_x = 0; offset_y = 0;
453+
busy = 1; ( x, y ) = copycoordinates( start_x, start_y ); numerator = start_numerator; count = 0; offset_x = 0; offset_y = 0;
454454
while( working ) {
455455
if( singlepixel ) {
456456
bitmap_write = 1;
@@ -941,9 +941,7 @@ unit blit(
941941
PXS.offset = 0;
942942
while( pxworking ) {
943943
y2 = 0;
944-
while( y2working ) {
945-
x2 = 0; while( x2working ) { dooutput = 1; } y2 = y2NEXT;
946-
}
944+
while( y2working ) { x2 = 0; while( x2working ) { dooutput = 1; } y2 = y2NEXT; }
947945
PXS.offset = pxNEXT;
948946
}
949947
PYS.offset = pyNEXT;
@@ -992,10 +990,9 @@ unit pixelblock(
992990
) <reginputs> {
993991
uint2 toprocess = uninitialised; uint1 dooutput = uninitialised;
994992
int11 xSTART <:: x - 1;
995-
int11 xNEXT <:: bitmap_x_write + 1; int11 yNEXT <:: bitmap_y_write + 1;
993+
int11 xNEXT <:: bitmap_x_write + 1; int11 yNEXT <:: bitmap_y_write + 1;
996994

997995
colourmap.addr0 := colour; // LOOKUP THE COLOUR FROM THE REMAPPER
998-
999996
bitmap_write := 0; dooutput := 0;
1000997

1001998
algorithm <autorun> {

RV64/PAWS.si

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ $$if VGA then
264264
video_hs :> video_hs,
265265
video_vs :> video_vs,
266266
$$end
267-
static8bit <: TIMERS_Map.static16bit[0,8],
267+
staticGenerator <: TIMERS_Map.static16bit[0,10],
268268
blink <: TIMERS_Map.cursor,
269269

270270
sdcardlightcolour <: IO_Map.sdcardlightcolour,

RV64/SOFTWARE/PAWS/DEMO/DEMO.P64

864 Bytes
Binary file not shown.

RV64/SOFTWARE/c/demo/demo.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,6 @@ void backgrounddemo( void ) {
908908
tpu_set( 0, 17, TRANSPARENT, WHITE ); tpu_print( 1, "11 AND R0 <- (R0) & 7 // AND R0 BY 7" );
909909
tpu_set( 0, 18, TRANSPARENT, WHITE ); tpu_print( 1, "12 JMP 4 // JUMP TO 4" );
910910

911-
copper_startstop( 0 );
912-
913911
unsigned short memoryinit[8] = {
914912
WHITE,
915913
RED,
@@ -943,6 +941,31 @@ void backgrounddemo( void ) {
943941
copper_startstop( 1 );
944942
sleep1khz( 4000, 0 );
945943

944+
displayreset();
945+
copper_startstop( 0 );
946+
947+
tpu_print_centre( 59, TRANSPARENT, WHITE, 1, "COPPER Random Colour Stars Test" );
948+
949+
tpu_set( 0, 2 , TRANSPARENT, WHITE ); tpu_print( 1, "00 SET BM <- BKG_SNOW // SET MODE TO SNOW" );
950+
tpu_set( 0, 3 , TRANSPARENT, WHITE ); tpu_print( 1, "01 SET BA <- BLACK // SET ALT TO BLACK" );
951+
tpu_set( 0, 4 , TRANSPARENT, WHITE ); tpu_print( 1, "02 SET BC <- WHITE // SET COLOUR TO WHITE" );
952+
953+
tpu_set( 0, 5 , TRANSPARENT, WHITE ); tpu_print( 1, "03 SET R0 <- RANDOM & 255 // SET R0 TO RANDOM & 255" );
954+
tpu_set( 0, 6 , TRANSPARENT, WHITE ); tpu_print( 1, "04 SET BC <- (R0) // SET COLOUR TO R0" );
955+
tpu_set( 0, 7 , TRANSPARENT, WHITE ); tpu_print( 1, "05 JMP 3 // JUMP TO 3" );
956+
957+
copper_program( 0, CU_SET, CU_BM, CU_RL, BKG_SNOW ); // BACKGROUND SNOW GENERATOR
958+
copper_program( 1, CU_SET, CU_BA, CU_RL, BLACK ); // BACKGROUND ALT BLACK
959+
copper_program( 2, CU_SET, CU_BC, CU_RL, WHITE ); // BACKGROUND WHITE
960+
961+
copper_program( 3, CU_RND, CU_R0, CU_RL, 255 ); // SET R0 = RAND & 255
962+
copper_program( 4, CU_SET, CU_BC, CU_RR, CU_R0 ); // SET BACKGROUND = R0
963+
copper_program( 5, CU_JMP, FALSE, CU_RL, 3 ); // JUMP 3
964+
965+
copper_startstop( 1 );
966+
sleep1khz( 4000, 0 );
967+
968+
946969
}
947970

948971
// PUT SOME OBJECTS ON THE TILEMAP AND WRAP LOWER LAYER UP AND LEFT , UPPER LAYER DOWN AND RIGHT

RV64/ULX3S/BUILD_ulx3s/PAWSv2-64.bit

7.77 KB
Binary file not shown.

RV64/background.si

+29-31
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,7 @@ unit background_display(
5151
}
5252
}
5353
}
54-
55-
unit starfield(
56-
input uint10 pix_x,
57-
input uint9 pix_y,
58-
output! uint1 star
59-
) <reginputs> {
60-
// Variables for SNOW (from @sylefeb)
61-
int32 frame = 0;
62-
int12 rand_x = 0;
63-
uint10 dotpos <:: ( frame >> rand_x[10,2] ) + rand_x;
64-
65-
always_after {
66-
// Increment frame number for the snow/star field
67-
{ frame = frame + ( ( pix_x == 639 ) & ( pix_y == 479 ) ); }
68-
{ rand_x = |pix_x ? rand_x * 31421 + 6927 : 1; }
69-
{ star = ( pix_y == dotpos ); }
70-
}
71-
}
72-
73-
unit new_background_writer(
54+
unit background_writer(
7455
input uint10 pix_x,
7556
input uint9 pix_y,
7657
input uint1 pix_active,
@@ -116,7 +97,7 @@ unit new_background_writer(
11697
}
11798
}
11899
}
119-
unit new_copper(
100+
unit nucu(
120101
input uint10 pix_x,
121102
input uint9 pix_y,
122103
input uint1 pix_vblank,
@@ -141,22 +122,22 @@ unit new_copper(
141122
input uint80 memoryinit // INITIAL SETTINGS OF THE MEMORY
142123
) <reginputs> {
143124
uint7 PC = 0; // PROGRAM COUNTER
144-
uint7 PCnext <:: PC + 1; // NEXT INSTRUCTION
145-
uint7 PCskip <:: PC + 2; // NEXT INSTRUCTION IF SKIP
146-
147125
uint2 PCinc = uninitialised; // PC ACTION FLAG == 0 PCnext, == 1 PCskip, == 2 RL value
148126
uint1 WR = uninitialised; // WRITE TO REGISTERS FLAG
149127
uint1 WM = uninitialised; // WRITE TO MEMORY FLAG
150128

151129
uint10 MEM[8] = uninitialised; // STORAGE FOR 8 MEMORY LOCATIONS
152-
uint10 REGS[4] = uninitialised; // STORAGE FOR 4 REGISTERS
153-
uint10 reg1 = uninitialised; // CONTENTS OF REG 1
154-
uint10 reg2 = uninitialised; // CONTENTS OF REG 2 OR LITERAL VALUE
155-
uint10 result = uninitialised; // RESULT OF OP
156130

157131
PCinc := 0; WR := 1; WM := 0;
158132

159133
always_after {
134+
uint7 PCnext = PC + 1; // NEXT INSTRUCTION
135+
uint7 PCskip = PC + 2; // NEXT INSTRUCTION IF SKIP
136+
uint10 reg1 = uninitialised; // CONTENTS OF REG 1
137+
uint10 reg2 = uninitialised; // CONTENTS OF REG 2 OR LITERAL VALUE
138+
uint10 result = uninitialised; // RESULT OF OP
139+
uint10 REGS[4] = uninitialised; // STORAGE FOR 4 REGISTERS
140+
160141
switch( OPD.rdata0 ) { // EXTRACT REG1
161142
case 0: { reg1 = pix_vblank; } // VBLANK
162143
case 1: { reg1 = pix_x; } // X COORD
@@ -207,9 +188,7 @@ unit new_copper(
207188
}
208189
}
209190

210-
if( WM ) { // WRITE TO MEMORY
211-
MEM[ reg1[0,3] ] = result;
212-
}
191+
if( WM ) { MEM[ reg1[0,3] ] = result; } // WRITE TO MEMORY
213192

214193
switch( PCinc ) { // UPDATE PC
215194
default: { PC = PCnext; } // NEXT INSTRUCTION
@@ -229,3 +208,22 @@ unit new_copper(
229208
OP.addr0 = PC; OPD.addr0 = PC; OPF.addr0 = PC; OPL.addr0 = PC; // MOVE TO THE NEXT INSTRUCTION
230209
}
231210
}
211+
212+
unit starfield(
213+
input uint10 pix_x,
214+
input uint9 pix_y,
215+
output! uint1 star
216+
) <reginputs> {
217+
// Variables for SNOW (from @sylefeb)
218+
int32 frame = 0;
219+
int12 rand_x = 0;
220+
uint10 dotpos <:: ( frame >> rand_x[10,2] ) + rand_x;
221+
222+
always_after {
223+
// Increment frame number for the snow/star field
224+
{ frame = frame + ( ( pix_x == 639 ) & ( pix_y == 479 ) ); }
225+
{ rand_x = |pix_x ? rand_x * 31421 + 6927 : 1; }
226+
{ star = ( pix_y == dotpos ); }
227+
}
228+
}
229+

RV64/caches.si

-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ unit cache_read(
234234
input uint$sdram_addr_width$ address,
235235
output! uint32 rdata,
236236
) <reginputs> {
237-
238237
always_after {
239238
uint$sdram_addr_width$ address0 = address + { address[1,1], 1b0 };
240239

RV64/terminal.si

+13-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ unit terminal(
2020
uint6 yterminalpos <:: ( pix_vblank ? 0 : pix_y - 416 ); // Character position on the terminal x 0-79, y 0-7 * 80
2121
uint1 terminalpixel <:: CGROM.line[ ~pix_x[0,3], 1 ]; // Derive the actual pixel in the current terminal
2222

23-
terminal.addr0 := pix_x1[3,7] + yterminalpos[3,3] * 80; // Setup the reading of the terminal memory
23+
terminal.addr0 := pix_x1[3,7] + yterminalpos[3,3] * 80; // Setup the reading of the terminal memory
2424

2525
always_after {
2626
uint1 is_cursor = blink & ( ( pix_x >> 3 ) == terminal_x ) & ( &yterminalpos[3,3] ); // Determine if cursor, and if cursor is flashing
@@ -55,25 +55,23 @@ unit terminal_writer(
5555
) <reginputs> {
5656
terminalcursor TC( terminal_x <: terminal_x );
5757

58-
// Terminal active (scroll) flag and temporary storage for scrolling
59-
uint10 terminal_scroll = uninitialised;
60-
uint10 terminal_scroll_next <:: terminal_scroll + 1;
61-
uint10 terminal_scroll_next_line <:: terminal_scroll + 80;
62-
6358
// Setup the writing to the terminal memory
6459
terminal.wenable1 := 0;
6560

6661
algorithm <autorun> {
67-
uint1 scrolling <:: ( terminal_scroll < 560 );
62+
uint10 terminal_scroll = uninitialised; // PRESENT MEMORY ADDRESS FOR SCROLLING/WIPING LAST LINE
63+
uint10 terminal_scroll_next <:: terminal_scroll + 1; // NEXT CHARACTER FOR SCROLLING
64+
uint10 terminal_scroll_next_line <:: terminal_scroll + 80; // CHARACTER ON LINE BELOW FOR SCROLLING
65+
uint1 scrolling <:: ( terminal_scroll < 560 ); // SCROLLING OR WIPING LAST LINE
6866
uint1 working <:: ( terminal_scroll != 640 );
6967

7068
while(1) {
7169
if( |terminal_active ) {
7270
while( working ) {
73-
terminal.addr1 = terminal_scroll_next_line; // READ NEXT LINE
71+
terminal.addr1 = terminal_scroll_next_line; // READ NEXT LINE
7472
++:
7573
terminal.addr1 = terminal_scroll;
76-
terminal.wdata1 = terminal_active[1,1] ? 0 : scrolling ? terminal.rdata1 : 0; // COPY CHARACTER IF SCROLLING, BLANK IF LAST LINE/WIPE
74+
terminal.wdata1 = terminal_active[1,1] ? 0 : scrolling ? terminal.rdata1 : 0; // COPY CHARACTER IF SCROLLING, BLANK IF LAST LINE/WIPE
7775
terminal.wenable1 = 1; terminal_scroll = terminal_scroll_next;
7876
}
7977
if( terminal_active[1,1] ) { terminal_x = 0; }
@@ -86,25 +84,25 @@ unit terminal_writer(
8684

8785
always_after {
8886
if( |terminal_write ) {
89-
onehot( terminal_write ) { // WRITE CHARACTER
87+
onehot( terminal_write ) { // WRITE CHARACTER
9088
case 0: {
9189
switch( terminal_character ) {
92-
case 8: { // BACKSPACE, move back one character
90+
case 8: { // BACKSPACE, move back one character
9391
if( |terminal_x ) {
9492
terminal_x = TC.PREV;
9593
terminal.addr1 = TC.ADDRESS; terminal.wdata1 = 0; terminal.wenable1 = 1;
9694
}
9795
}
98-
case 10: { terminal_active = 1; } // LINE FEED, force scroll
99-
case 13: { terminal_x = 0; } // CARRIAGE RETURN, return to left
100-
default: { // Display character
96+
case 10: { terminal_active = 1; } // LINE FEED, force scroll
97+
case 13: { terminal_x = 0; } // CARRIAGE RETURN, return to left
98+
default: { // Display character
10199
terminal.addr1 = TC.ADDRESS; terminal.wdata1 = terminal_character; terminal.wenable1 = 1;
102100
terminal_active = TC.endofline;
103101
terminal_x = TC.NEXT;
104102
}
105103
}
106104
}
107-
case 1: { terminal_active = 2; } // RESET
105+
case 1: { terminal_active = 2; } // RESET
108106
}
109107
}
110108
}

RV64/video_memmap.si

+8-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ $$if VGA then
115115
$$end
116116

117117
// RNG + CURSOR
118-
input uint8 static8bit,
118+
input uint10 staticGenerator,
119119
input uint1 blink,
120120

121121
// STATUSLIGHTS
@@ -167,7 +167,6 @@ $$else
167167
uint9 yscreen <: vblank ? 0 : pix_y;
168168
$$end
169169

170-
171170
uint3 hilorez = 0; // FLAG FOR hi or lo SWITCH FOR TILEMAPS, CHARACTERMAP { cm, tm_u, tm_l }
172171

173172
// BACKGROUND
@@ -181,7 +180,7 @@ $$end
181180
pix_vblank <: vblank,
182181
memoryAddress <: memoryAddress,
183182
writeData <: writeData,
184-
static2bit <: static8bit[0,2]
183+
staticGenerator <: staticGenerator[0,10]
185184
);
186185

187186
uint2 writeDirectDo = 0; // I/O TO VIDEO CLOCK WRITE 2 CYCLE FLAG
@@ -199,7 +198,7 @@ $$end
199198
memoryWriteDirect <: writeDirectDo[0,1],
200199
readDataDirect :> readDataDirect,
201200
accesssize <: accesssize,
202-
static8bit <: static8bit
201+
static8bit <: staticGenerator[0,8]
203202
);
204203

205204
// Character Map Window
@@ -463,7 +462,7 @@ unit background_memmap(
463462
output uint10 readData,
464463

465464
input uint2 colourmode,
466-
input uint2 static2bit
465+
input uint10 staticGenerator
467466
) <reginputs> {
468467
// BACKGROUND CO-PROCESSOR PROGRAM STORAGE
469468
simple_dualport_bram uint4 OP <@video_clock,@clock> [ 128 ] = uninitialised;
@@ -481,16 +480,17 @@ unit background_memmap(
481480
pix_active <: pix_active,
482481
pix_vblank <: pix_vblank,
483482
pixel :> pixel,
484-
staticGenerator <: static2bit,
483+
staticGenerator <: staticGenerator[0,2],
485484
b_colour <: BACKGROUND_COPPER.BACKGROUNDcolour,
486485
b_alt <: BACKGROUND_COPPER.BACKGROUNDalt,
487486
b_mode <: BACKGROUND_COPPER.BACKGROUNDmode,
488487
colourmode <: colourmode
489488
);
490-
new_copper BACKGROUND_COPPER <@video_clock,!video_reset> (
489+
nucu BACKGROUND_COPPER <@video_clock,!video_reset> (
491490
pix_x <: pix_x,
492491
pix_y <: pix_y,
493492
pix_vblank <: pix_vblank,
493+
staticGenerator <: staticGenerator,
494494
backgroundcolour <: BACKGROUND_WRITER.BACKGROUNDcolour,
495495
backgroundcolour_alt <: BACKGROUND_WRITER.BACKGROUNDalt,
496496
backgroundcolour_mode <: BACKGROUND_WRITER.BACKGROUNDmode,
@@ -500,7 +500,7 @@ unit background_memmap(
500500
OPL <:> OPL,
501501
memoryinit <: memoryinit
502502
);
503-
new_background_writer BACKGROUND_WRITER(
503+
background_writer BACKGROUND_WRITER(
504504
OP <:> OP,
505505
OPD <:> OPD,
506506
OPF <:> OPF,

0 commit comments

Comments
 (0)