init repo

This commit is contained in:
RomanRom2 committed 2025-01-28 19:17:01 +03:00
commit 90e6151613
3260 files changed
+3745062

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
*.o
+830
View File
@@ -0,0 +1,830 @@
// NOTE: disable a couple of defines if you get "IndexError: list index out of range"
//#define DEBUG // Indicate data on the LEDs as a counter
//#define TESTS // Run some test procedures instead of actual terminal, defined in helpers.h
//#define SLOW // Runs tests slower
#define COLORS // Enable terminal colors (costs extra memory)
//#define LEDS // Allow for usage of Gigatron LEDs within the application (costs extra memory)
#define FAST_START // Quick startup by disabling the screen during initialization
#define ANSI_BLOCK_CHARS // Allow ANSI block characters (costs extra memory)
//#define TERMINAL_MODES // Enable terminal modes (costs extra memory)
#define TINY_FONT // Enables small font (costs extra memory)
// Successful combinations (trial and error), leave out one of the following:
// COLORS
// LEDS and ANSI_BLOCK_CHARS
// LEDS and TERMINAL_MODES
// ANSI_BLOCK_CHARS and TERMINAL_MODES
// We can only define the port after including the helper file
#include "vtactionstates.h"
#include "helpers.h"
// Enable SPI hardware by assigning Slave Select pin (SS0 to SS3). Note that SS0 is reserved for an SD card.
// Comment out to do local loopback
#define IOPORT SS1
byte oldchar;
byte intermediate = 0;
int params[10] = {0};
byte paramCount = 0;
int savedCursor = 0;
char response[10] = {0};
byte responseIndex = 0;
#ifdef TESTS
void main(void)
{
test();
while( 1 );
}
#else
// Forward declaration
void vt_parse( byte _byte );
byte SPIExchangeKey( byte _key );
void main(void)
{
byte spiData;
ScreenPos = (int)screenMemory;
#ifndef TINY_FONT
ScreenPos |= 0x02;
#endif
if ( romType < romTypeValue_DEVROM )
{
//puts( "Terminal is only supported\non ROMv4 or higher." );
puts( "Terminal is only supported\non xopr's DEVROM." );
while(1);
}
#ifdef FAST_START
// Disable video to increase speed
sysFn = SYS_SetMode_v2_80;
vAC = 1975;
__syscall(230); // 270-80/2
#else
// Set lower video mode to increase speed
sysFn = SYS_SetMode_v2_80;
vAC = 3;
__syscall(230); // 270-80/2
#endif
EraseInDisplay( 2, ScreenPos );
drawCursor( 1 );
setCursor( 0, 0 );
#ifdef IOPORT
// Enable SPI port
sysFn = SYS_ExpanderControl_v4_40;
vAC = ~IOPORT & SPI_MASK | BANK0;
__syscall(250); // 270-40/2
// To disable
//vAC = IOPORT & SPI_MASK | BANK0;
#endif
#ifdef LEDS
// Disable LED sequencer and set 4th led
ledState = 1;
xoutMask = 8;
#endif
#ifdef FAST_START
// Set lower video mode to increase speed
sysFn = SYS_SetMode_v2_80;
vAC = 3;
__syscall(230); // 270-80/2
#endif
while ( 1 )
{
if ( response[ responseIndex ] )
{
spiData = response[ responseIndex ];
responseIndex++;
// End of string?
if ( !response[ responseIndex ] )
{
response[ 0 ] = 0;
responseIndex = 0;
}
#ifndef IOPORT
// Color output marking it dummy
Color = Red;
PutChar( spiData );
Color = White;
#endif
}
else
{
spiData = serialRaw;
#ifndef IOPORT
if ( spiData == DEL )
spiData = BS;
#endif
if ( spiData == oldchar )
spiData = 0;
else
oldchar = spiData;
#if defined(DEBUG) && defined(LEDS)
// Blinky led on input to detect freezes
if ( spiData && spiData != 0xff )
xoutMask++;
#endif
#ifdef IOPORT
// Translate buttons to escape code
switch ( spiData )
{
case buttonUp: response[ 0 ] = 0x1B; response[ 1 ] = '['; response[ 2 ] = 'A'; response[ 3 ] = 0;break;
case buttonDown: response[ 0 ] = 0x1B; response[ 1 ] = '['; response[ 2 ] = 'B'; response[ 3 ] = 0;break;
case buttonRight: response[ 0 ] = 0x1B; response[ 1 ] = '['; response[ 2 ] = 'C'; response[ 3 ] = 0;break;
case buttonLeft: response[ 0 ] = 0x1B; response[ 1 ] = '['; response[ 2 ] = 'D'; response[ 3 ] = 0;break;
}
#else
// Translate buttons to local action
switch ( spiData )
{
case buttonUp: cursorUp( 1, 0 ); break;
case buttonDown: cursorDown( 1, 0 ); break;
case buttonRight: cursorRight( 1 ); break;
case buttonLeft: cursorLeft( 1 ); break;
}
vt_parse( spiData );
#endif
}
#ifdef IOPORT
// Send key to terminal server
spiData = SPIExchangeKey( spiData );
vt_parse( spiData );
#endif
}
}
void vt_action_regular( byte _byte )
{
if ( _byte >= SP && _byte < DEL )
{
// Print character
PutChar( _byte );
drawCursor( 1 );
}
#ifdef ANSI_BLOCK_CHARS
else if ( _byte == 176 )
{
// Block light
PutGlyph( 0x280a );
drawCursor( 1 );
}
else if ( _byte == 177 )
{
// Block medium
PutGlyph( 0x5555 );
drawCursor( 1 );
}
else if ( _byte == 178 )
{
// Block dark
PutGlyph( 0x7d5f );
drawCursor( 1 );
}
else if ( _byte == 219 )
{
// Block
PutChar( 127 );
drawCursor( 1 );
}
else if ( _byte == 220 )
{
// Block bottom
PutGlyph( 0x6318 );
drawCursor( 1 );
}
else if ( _byte == 221 )
{
// Block left
PutGlyph( 0x03ff );
drawCursor( 1 );
}
else if ( _byte == 222 )
{
// Block right
PutGlyph( 0xec00 );
drawCursor( 1 );
}
else if ( _byte == 223 )
{
// Block top
PutGlyph( 0x1ce7 );
drawCursor( 1 );
}
#endif
}
void vt_action_control_sequence_execute( byte _byte )
{
switch ( _byte )
{
case 'A':
// ESC [ Pn A CUU -- Cursor Up -- Host to VT100 and VT100 to Host
if ( params[0] == 0 )
params[0] = 1;
cursorUp( params[0], 0 );
break;
case 'B':
// ESC [ Pn B CUD -- Cursor Down -- Host to VT100 and VT100 to Host
if ( params[0] == 0 )
params[0] = 1;
cursorDown( params[0], 0 );
break;
case 'C':
// ESC [ Pn C CUF -- Cursor Forward -- Host to VT100 and VT100 to Host
if ( params[0] == 0 )
params[0] = 1;
cursorRight( params[0] );
break;
case 'D':
// ESC [ Pn D CUB -- Cursor Backward -- Host to VT100 and VT100 to Host (n positions, default 1), stop at margin
if ( params[0] == 0 )
params[0] = 1;
cursorLeft( params[0] );
break;
case 'H':
// ESC [ Pn ; Pn H CUP -- Cursor Position (line, column)
case 'f':
// ESC [ Pn ; Pn f HVP -- Horizontal and Vertical Position (line, column)
// The numbering of lines depends on the state of the Origin Mode (DECOM).
if ( params[0] )
params[0]--;
if ( paramCount < 2 )
params[1] = 0;
if ( params[1] )
params[1]--;
setCursor( params[0], params[1] );
break;
case 'J':
// ESC [ Ps J ED -- Erase In Display (
// 0 Erase from the active position to the end of the screen, inclusive (default)
// 1 Erase from start of the screen to the active position, inclusive
// 2 Erase all of the display -- all lines are erased, changed to single-width, and the cursor does not move.
// Erase stored cursor character
drawCursor( 0 );
EraseInDisplay( params[0], ScreenPos );
// Restore cursor
drawCursor( 1 );
break;
case 'K':
// ESC [ Ps K EL -- Erase In Line
// 0 Erase from the active position to the end of the line, inclusive (default)
// 1 Erase from the start of the screen to the active position, inclusive
// 2 Erase all of the line, inclusive
// Erase stored cursor character
drawCursor( 0 );
EraseInLine( params[0], ScreenPos );
// Restore cursor
drawCursor( 1 );
break;
case 'c':
// ESC [ Pn c DA -- Device Attributes (empty/0 from host, response from terminal:)
// No options ESC [?1;0c
// Processor option (STP) ESC [?1;1c
// Advanced video option (AVO) ESC [?1;2c (10 additional lines of 132 column display,bold...)
// AVO and STP ESC [?1;3c
// Graphics option (GPO) ESC [?1;4c
// GPO and STP ESC [?1;5c
// GPO and AVO ESC [?1;6c
// GPO, STP and AVO ESC [?1;7c
// Identify: set response to send back
snprintf(response, sizeof response, "\x1B[?1;0c");
//puts_ex( response );
break;
case 'g':
// ESC [ Ps g TBC -- Tabulation Clear (0=current, 3=all)
break;
#ifdef TERMINAL_MODES
case 'h':
// ESC [ Ps ; . . . ; Ps h SM -- Set Mode (reset mode counterpart)
while ( paramCount-- )
{
if ( !params[ paramCount ] )
continue;
if ( params[ paramCount ] == 20 )
params[ paramCount ] = 0;
if ( params[ paramCount ] > 9 )
continue;
terminalModes |= (1 << params[ paramCount ]);
}
break;
case 'l':
// ESC [ Ps ; Ps ; . . . ; Ps l RM -- Reset Mode (set mode counterpart)
while ( paramCount-- )
{
if ( !params[ paramCount ] )
continue;
if ( params[ paramCount ] == 20 )
params[ paramCount ] = 0;
if ( params[ paramCount ] > 9 )
continue;
terminalModes &= ~(1 << params[ paramCount ]);
}
break;
#endif
#ifdef COLORS
case 'm':
// ESC [ Ps ; . . . ; Ps m SGR -- Select Graphic Rendition (attributes)
// Restore character (attribute under cursor will change)
drawChar( cursor );
while ( paramCount-- )
{
switch ( params[ paramCount ] )
{
case 0: Color = White; BgColor = Blue; break;
case 30: Color = Black; break;
case 31: Color = Red; break;
case 32: Color = Green; break;
case 33: Color = Yellow; break;
case 34: Color = Blue; break;
case 35: Color = Magenta; break;
case 36: Color = Cyan; break;
case 37: Color = LightGray; break;
case 40: BgColor = Black; break;
case 41: BgColor = Red; break;
case 42: BgColor = Green; break;
case 43: BgColor = Yellow; break;
case 44: BgColor = Blue; break;
case 45: BgColor = Magenta; break;
case 46: BgColor = Cyan; break;
case 47: BgColor = LightGray; break;
case 90: Color = DarkGray; break;
case 91: Color = LightRed; break;
case 92: Color = LightGreen; break;
case 93: Color = LightYellow; break;
case 94: Color = LightBlue; break;
case 95: Color = LightMagenta; break;
case 96: Color = LightCyan; break;
case 97: Color = White; break;
case 100: BgColor = DarkGray; break;
case 101: BgColor = LightRed; break;
case 102: BgColor = LightGreen; break;
case 103: BgColor = LightYellow; break;
case 104: BgColor = LightBlue; break;
case 105: BgColor = LightMagenta; break;
case 106: BgColor = LightCyan; break;
case 107: BgColor = White; break;
}
}
// Restore cursor
drawCursor( 1 );
break;
#endif
case 'n':
// ESC [ Ps n DSR -- Device Status Report
switch ( params[ 0 ] )
{
case 5:
// 5 Command from host -- Please report status (using a DSR control sequence)
// 0 Response from VT100 -- Ready, No malfunctions detected (default)
// 3 Response from VT100 -- Malfunction -- retry
// Report ready: set response to send back
snprintf( response, sizeof response, "\x1B[0n" );
break;
case 6:
// 6 Command from host -- Please report active position (using a CPR control sequence) response
// ESC [ Pn ; Pn R: CPR -- Cursor Position Report -- VT100 to Host (line,column)
// Report ready: set response to send back
// Abuse intermediate variable
intermediate = (ScreenPos >> 8);
if ( videoTable[0] > intermediate )
intermediate = intermediate + 120 - videoTable[0];
else
intermediate -= videoTable[0];
intermediate /= ( CHAR_HEIGHT + CHAR_LEADING );
snprintf( response, sizeof response, "\x1B[%u,%uR", intermediate + 1, ( ScreenPos & 0xff ) / CHAR_WIDTH + 1 );
break;
}
break;
#ifdef LEDS
case 'q':
// ESC [ Ps q DECLL -- Load LEDS (Linux supports L1 as scroll lock, L2 NumLock, L3 as Caps lock , )
// ESC [ Ps;Ps;...Ps q
// 0 or None All LEDs Off
// 1 L1 On
// 2 L2 On
// 3 L3 On
// 4 L4 On
// Set LEDs
while ( paramCount-- )
{
if ( !params[ paramCount ] )
{
xoutMask = 0;
}
else if ( params[ paramCount ] <= 4 )
{
// Turn number into bit mask
params[ paramCount ]--;
xoutMask |= ( 1 << params[ paramCount ] );
}
}
break;
#endif
/*
case 'r':
// ESC [ Pn; Pn r DECSTBM -- Set Top and Bottom Margins (startline, endline scroll)
break;
case 'x':
// ESC [ <sol>; <par>; <nbits>; <xspeed>; <rspeed>; <clkmul>; <flags> x DECREPTPARM -- Report Terminal Parameters
break;
case 'y':
// ESC [ 2 ; Ps y DECTST -- Invoke Confidence Test
// Test Weight
// 0: reset only
// 1: Power up self-test (ROM check sum, RAM, NVR keyboard and AVO if installed)
// 2: Data Loop Back (loop back connector required)
// 4: EIA modem control test (loop back connector required)
// 8: Repeat Selected Test(s) indefinitely (until failure or power off)
// 0 Attributes off
// 1 Bold or increased intensity
// 4 Underscore
// 5 Blink
// 7 Negative (reverse) image
break;
*/
}
}
void vt_action_control_sequence( byte _byte )
{
if ( _byte >= 0x30 && _byte <= 0x39 )
{
// Pn: Numbers: param
params[paramCount] = params[paramCount] * 10 + _byte - 0x30;
}
else if ( _byte == ';' )
{
// Ps: Next param
paramCount++;
params[paramCount] = 0;
}
else if ( _byte >= 0x40 && _byte <= 0x7E )
{
// Offset param count (0->1)
paramCount++;
// Handle Control sequence
vt_action_control_sequence_execute( _byte );
paramCount = 0;
params[0] = 0;
mode = VTPARSE_MODE_REGULAR;
}
else if ( _byte == '?' )
{
// Note that in some cases, ESC[? is sent and therefore allowed
}
}
void vt_action_escape_sequence( byte _byte )
{
switch ( _byte )
{
case '0':
// SCS -- Select Character Set
// G0 ( or G1 ) Special graphics
break;
case '1':
// SCS -- Select Character Set
// G0 ( or G1 ) Alternate ROM standard
break;
case '2':
// SCS -- Select Character Set
// G0 ( or G1 ) Alternate ROM special graphics
break;
case '3':
case '4':
// # DECDHL -- Double Height Line
// top/bottom
break;
case '5':
// # DECSWL -- Single-width Line
break;
case '6':
// # DECDWL -- Double-Width Line
break;
case '7':
// DECSC -- Save Cursor
// This sequence causes the cursor position, graphic rendition (attributes), and character set to be saved. (See DECRC).
savedCursor = ScreenPos;
break;
case '8':
// # DECALN -- Screen Alignment Display
// Fill screen with 'E'
if ( intermediate != '#' )
{
// DECRC -- Restore Cursor
if ( savedCursor != ScreenPos )
{
// Restore character behind cursor
drawChar( cursor );
ScreenPos = savedCursor;
// Draw cursor
drawCursor( 1 );
}
}
break;
case 'A':
// SCS -- Select Character Set
// G0 ( or G1 ) UK
// VT52: Cursor up (no scroll)
break;
case 'B':
// SCS -- Select Character Set
// G0 ( or G1 ) ASCII
// VT52: Cursor down (no scroll)
break;
case 'C':
// VT52: Cursor right (no scroll/newline)
break;
case 'D':
// IND -- Index (cursor down, allow scroll)
cursorDown( 1, 0 );
// VT52: Cursor left (no scroll/newline)
break;
case 'E':
// NEL -- Next Line (CRLF, allow scroll)
Newline();
drawCursor( 1 );
break;
case 'F':
// VT52: Enter Graphics Mode
break;
case 'G':
// VT52: Select ASCII character set
break;
case 'H':
// HTS -- Horizontal Tabulation Set
// VT52: Move the cursor to the home position.
break;
case 'I':
// VT52: Reverse Line Feed
break;
case 'J':
// VT52: Erase to End of Screen
break;
case 'K':
// VT52: Erase to End of Line
break;
case 'M':
// RI -- Reverse Index (cursor up, allow scoll)
cursorUp( 1, 1 );
break;
case 'Y':
// VT52: Direct Cursor Address (needs line, column)
//mode = VTPARSE_MODE_ESCAPE_CURSOR_LINE;
break;
case 'Z':
// DECID -- Identify Terminal, deprecated->ESC[?1;0c
// set response to send back
snprintf(response, sizeof response, "\x1B[?1;0c");
//puts_ex( response );
// VT52: Identify, reply with ESC / Z
break;
#ifdef TERMINAL_MODES
case '=':
// DECKPAM -- Keypad Application Mode
terminalModes |= DECKPAM;
// VT52: Enter Alternate Keypad Mode
break;
case '>':
// DECKPNM -- Keypad Numeric Mode
terminalModes &= ~DECKPAM;
#endif
// VT52: Exit Alternate Keypad Mode
break;
case '<':
// VT52: Enter ANSI Mode (ignore VT52 escape codes)
break;
}
// Note: the previous switch statement is at its max apparently
switch ( _byte )
{
case 'c':
// RIS -- Reset To Initial State
break;
case '[':
// CSI -- Control Sequence Introducer
mode = VTPARSE_MODE_CONTROL_SEQUENCE;
break;
}
// Reset mode if it was not altered
if ( mode == VTPARSE_MODE_ESCAPE_INTERMEDIATE )
mode = VTPARSE_MODE_REGULAR;
intermediate = 0;
}
void vt_action_escape_intermediate( byte _byte )
{
if ( _byte >= 0x30 && _byte <= 0x7E )
{
// Handle escape (might turn into control sequence)
vt_action_escape_sequence( _byte );
}
else if ( _byte < 0x20 || _byte >= 0x2F )
{
// TODO: Error
}
// Store intermediate (assume only 1 character)
if ( !intermediate )
intermediate = _byte;
}
byte vt_parse_control_char( byte _byte )
{
/*
if ( _byte != NUL )
{
snprintf(response, sizeof response, "%d", _byte );
puts_ex( response );
}
*/
// Check if we need to parse a control char in the stream
if ( _byte == NUL )
{
// Ignored on input (not stored in input buffer; see full duplex protocol).
}
else if ( _byte == ENQ )
{
// Transmit answerback message.
}
else if ( _byte == BEL )
{
// bell sound
}
else if ( _byte == BS )
{
// Backspace
// TODO: rollover
if ((ScreenPos & 0xff) >= CHAR_WIDTH)
{
// Remove cursor
drawChar( cursor );
ScreenPos -= CHAR_WIDTH;
// draw cursor
drawCursor( 0 );
}
}
else if ( _byte == '`'/*HT*/ )
{
// move to next tabstop (align on 8*CHAR_WIDTH pixels)
drawChar( cursor );
PutChar_ex( HT );
// Restore character behind cursor
drawCursor( 1 );
}
else if ( _byte >= LF && _byte <= FF )
{
// Line feed: depends on mode
// Note: incoming keyboard enter translates to line feed
#ifndef IOPORT
drawChar( cursor );
Newline();
drawCursor( 1 );
#endif
}
else if ( _byte == CR )
{
// (Carriage) Return
Newline();
drawCursor( 1 );
}
else if ( _byte == SO )
{
// TODO: SO 016 0E Invoke G1 character set, as designated by SCS control sequence.
}
else if ( _byte == SI )
{
// TODO: SI 017 0F Select G0 character set, as selected by ESC ( sequence.
}
else if ( _byte == XON )
{
// TODO: XON 021 11 Causes terminal to resume transmission.
}
else if ( _byte == XOFF )
{
// TODO: XOFF 023 13 Causes terminal to stop transmitted all codes except XOFF and XON.
}
else if ( _byte == ESC || _byte == CAN || _byte == SUB )
{
// Clear params/intermediates, abort or restart escape sequence
intermediate = 0;
paramCount = 0;
params[0] = 0;
// Restart or Abort?
if ( _byte == ESC )
mode = VTPARSE_MODE_ESCAPE_INTERMEDIATE;
else
mode = VTPARSE_MODE_REGULAR;
}
else if ( _byte == DEL )
{
// Ignored on input (not stored in input buffer).
}
else
{
// No control character
return 0;
}
// Control character parsed
return 1;
}
void vt_parse( byte _byte )
{
// Check if we got a control character (which will be parsed)
if ( vt_parse_control_char( _byte ) )
return;
switch ( mode )
{
case VTPARSE_MODE_REGULAR: // (control+printable characters)
vt_action_regular( _byte );
break;
case VTPARSE_MODE_ESCAPE_INTERMEDIATE: // 0x20-0x2F (attribute chars)
vt_action_escape_intermediate( _byte );
break;
case VTPARSE_MODE_CONTROL_SEQUENCE: // 0x40-x07E (characters)
vt_action_control_sequence( _byte );
break;
}
}
byte SPIExchangeKey( byte _key )
{
*(int*)(sysArgs) = (int)&_key; // Start address
*(int*)(sysArgs+2) = (int)(&_key) + 1; // End address
sysFn = SYS_SpiExchangeBytes_v4_134;
__syscall(203); // 270-134/2
return _key;
}
#endif
Binary file not shown.
@@ -0,0 +1,249 @@
From c3a397c28c4c0f2502e038b58bc4d282242f22a9 Mon Sep 17 00:00:00 2001
From: xopr <xopr@ackspace.nl>
Date: Mon, 20 Jan 2020 13:30:17 +0100
Subject: [PATCH] Added SYS_VDrawWord function
---
Core/dev.py | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 216 insertions(+), 3 deletions(-)
diff --git a/Core/dev.py b/Core/dev.py
index 76a18881..4c3ef583 100755
--- a/Core/dev.py
+++ b/Core/dev.py
@@ -815,9 +815,23 @@ ld(hi('REENTER'),Y) #15 slot 0xc8
jmp(Y,'REENTER') #16
ld(-20/2) #17
-ld(hi('REENTER'),Y) #15 slot 0xcb
-jmp(Y,'REENTER') #16
-ld(-20/2) #17
+#-----------------------------------------------------------------------
+# Extension SYS_VDrawWord_134
+#-----------------------------------------------------------------------
+
+# Draw 3x5 glyph from word
+# sysArgs[0] Color 0 (background)
+# sysArgs[1] Color 1 (pen)
+# sysArgs[2:3] 16 bits (word) (destructive), bit (14, 9, 4),(13, 8, 3),(12, 7, 2),(11, 6, 1),(10, 5, 0)
+# they are grouped in chunks of 5 bits from top left to bottom right (with special case: MSB=offset)
+# for example: bit 14 is column 1 row 1, ..., bit 10 is column 1 row 5
+# bit 9 is column 2 row 1, ..., bit 0 is column 3 row 5
+# sysArgs[4:5] Position on screen
+
+label('SYS_VDrawWord_134')
+ld(hi('sys_VDrawWord'),Y);C('Draw a 3x5 glyph') #15 slot 0xcb
+jmp(Y,'sys_VDrawWord') #16
+ld([sysArgs+4], X) #17
ld(hi('REENTER'),Y) #15 slot 0xce
jmp(Y,'REENTER') #16
@@ -5349,6 +5363,205 @@ ld([sysArgs+2]) # Decrement byte count and loop
bne('.slb1') #
suba(1) #
+# SYS_VDrawWord_134 implementation
+label('sys_VDrawWord')
+
+# Line 1
+ld([sysArgs+5], Y) #18 store arg5 in Y
+
+#TODO: MSB set means empty line (bmi)
+ld([sysArgs+3]) #19 load (high) byte
+anda(0x40) #20 mask bit (r1c1)
+bne('.fgc1') #21 branch if bit set (AC not equal 0)
+bra('.drawpxl1') #22 jump to "draw pixel"
+ld([sysArgs+0]) #23a select BG color
+label('.fgc1')
+ld([sysArgs+1]) #23b select FG color
+label('.drawpxl1')
+st([Y,Xpp]) #24 Draw pixel, increase X
+
+ld([sysArgs+3]) #25 load (high) byte
+anda(0x02) #26 mask bit (r1c2)
+bne('.fgc2') #27 branch if bit set (AC not equal 0)
+bra('.drawpxl2') #28 jump to "draw pixel"
+ld([sysArgs+0]) #29a select BG color
+label('.fgc2')
+ld([sysArgs+1]) #29b select FG color
+label('.drawpxl2')
+st([Y,Xpp]) #30 Draw pixel, increase X
+
+ld([sysArgs+2]) #31 load (low) byte
+anda(0x10) #32 mask bit (r1c3)
+bne('.fgc3') #33 branch if bit set (AC not equal 0)
+bra('.drawpxl3') #34 jump to "draw pixel"
+ld([sysArgs+0]) #35a select BG color
+label('.fgc3')
+ld([sysArgs+1]) #35b select FG color
+label('.drawpxl3')
+st([Y,Xpp]) #36 Draw pixel, increase X
+
+
+ld([sysArgs+5]) #37 load arg5 (vert)
+adda(1) #38 increase by one
+st([sysArgs+5]) #39 store result (destructive)
+
+
+# Line 2
+ld(AC, Y) #40 load (new) Y position
+ld([sysArgs+4], X) #41 store arg4 in X (reset X)
+
+ld([sysArgs+3]) #42 load (high) byte
+anda(0x20) #43 mask bit (r1c1)
+bne('.fgc4') #44 branch if bit set (AC not equal 0)
+bra('.drawpxl4') #45 jump to "draw pixel"
+ld([sysArgs+0]) #46a select BG color
+label('.fgc4')
+ld([sysArgs+1]) #46b select FG color
+label('.drawpxl4')
+st([Y,Xpp]) #47 Draw pixel, increase X
+
+ld([sysArgs+3]) #48 load (high) byte
+anda(0x01) #49 mask bit (r1c2)
+bne('.fgc5') #50 branch if bit set (AC not equal 0)
+bra('.drawpxl5') #51 jump to "draw pixel"
+ld([sysArgs+0]) #52a select BG color
+label('.fgc5')
+ld([sysArgs+1]) #52b select FG color
+label('.drawpxl5')
+st([Y,Xpp]) #53 Draw pixel, increase X
+
+ld([sysArgs+2]) #54 load (low) byte
+anda(0x08) #55 mask bit (r1c3)
+bne('.fgc6') #56 branch if bit set (AC not equal 0)
+bra('.drawpxl6') #57 jump to "draw pixel"
+ld([sysArgs+0]) #58a select BG color
+label('.fgc6')
+ld([sysArgs+1]) #58b select FG color
+label('.drawpxl6')
+st([Y,Xpp]) #59 Draw pixel, increase X
+
+ld([sysArgs+5]) #60 load arg5 (vert)
+adda(1) #61 increase by one
+st([sysArgs+5]) #62 store result (destructive)
+
+
+# Line 3
+ld(AC, Y) #63 load (new) Y position
+ld([sysArgs+4], X) #64 store arg4 in X (reset X)
+
+ld([sysArgs+3]) #65 load (high) byte
+anda(0x10) #66 mask bit (r1c1)
+bne('.fgc7') #67 branch if bit set (AC not equal 0)
+bra('.drawpxl7') #68 jump to "draw pixel"
+ld([sysArgs+0]) #69a select BG color
+label('.fgc7')
+ld([sysArgs+1]) #69b select FG color
+label('.drawpxl7')
+st([Y,Xpp]) #70 Draw pixel, increase X
+
+ld([sysArgs+2]) #71 load (low) byte
+anda(0x80) #72 mask bit (r1c2)
+bne('.fgc8') #73 branch if bit set (AC not equal 0)
+bra('.drawpxl8') #74 jump to "draw pixel"
+ld([sysArgs+0]) #75a select BG color
+label('.fgc8')
+ld([sysArgs+1]) #75b select FG color
+label('.drawpxl8')
+st([Y,Xpp]) #76 Draw pixel, increase X
+
+ld([sysArgs+2]) #77 load (low) byte
+anda(0x04) #78 mask bit (r1c3)
+bne('.fgc9') #79 branch if bit set (AC not equal 0)
+bra('.drawpxl9') #80 jump to "draw pixel"
+ld([sysArgs+0]) #81 select BG color
+label('.fgc9')
+ld([sysArgs+1]) #82a select FG color
+label('.drawpxl9')
+st([Y,Xpp]) #82b Draw pixel, increase X
+
+ld([sysArgs+5]) #83 load arg5 (vert)
+adda(1) #84 increase by one
+st([sysArgs+5]) #85 store result (destructive)
+
+
+# Line 4
+ld(AC, Y) #86 load (new) Y position
+ld([sysArgs+4], X) #87 store arg4 in X (reset X)
+
+ld([sysArgs+3]) #88 load (high) byte
+anda(0x08) #89 mask bit (r1c1)
+bne('.fgc10') #90 branch if bit set (AC not equal 0)
+bra('.drawpxl10') #91 jump to "draw pixel"
+ld([sysArgs+0]) #92a select BG color
+label('.fgc10')
+ld([sysArgs+1]) #92b select FG color
+label('.drawpxl10')
+st([Y,Xpp]) #93 Draw pixel, increase X
+
+ld([sysArgs+2]) #94 load (low) byte
+anda(0x40) #95 mask bit (r1c2)
+bne('.fgc11') #96 branch if bit set (AC not equal 0)
+bra('.drawpxl11') #97 jump to "draw pixel"
+ld([sysArgs+0]) #98a select BG color
+label('.fgc11')
+ld([sysArgs+1]) #98b select FG color
+label('.drawpxl11')
+st([Y,Xpp]) #99 Draw pixel, increase X
+
+ld([sysArgs+2]) #100 load (low) byte
+anda(0x02) #101 mask bit (r1c3)
+bne('.fgc12') #102 branch if bit set (AC not equal 0)
+bra('.drawpxl12') #103 jump to "draw pixel"
+ld([sysArgs+0]) #104a select BG color
+label('.fgc12')
+ld([sysArgs+1]) #104b select FG color
+label('.drawpxl12')
+st([Y,Xpp]) #105 Draw pixel, increase X
+
+ld([sysArgs+5]) #106 load arg5 (vert)
+adda(1) #107 increase by one
+st([sysArgs+5]) #108 store result (destructive)
+
+
+# Line 5
+ld(AC, Y) #109 load (new) Y position
+ld([sysArgs+4], X) #110 store arg4 in X (reset X)
+
+ld([sysArgs+3]) #111 load (high) byte
+anda(0x04) #112 mask bit (r1c1)
+bne('.fgc13') #113 branch if bit set (AC not equal 0)
+bra('.drawpxl13') #114 jump to "draw pixel"
+ld([sysArgs+0]) #115a select BG color
+label('.fgc13')
+ld([sysArgs+1]) #115b select FG color
+label('.drawpxl13')
+st([Y,Xpp]) #116 Draw pixel, increase X
+
+ld([sysArgs+2]) #117 load (low) byte
+anda(0x20) #118 mask bit (r1c2)
+bne('.fgc14') #119 branch if bit set (AC not equal 0)
+bra('.drawpxl14') #120 jump to "draw pixel"
+ld([sysArgs+0]) #121a select BG color
+label('.fgc14')
+ld([sysArgs+1]) #121b select FG color
+label('.drawpxl14')
+st([Y,Xpp]) #122 Draw pixel, increase X
+
+ld([sysArgs+2]) #123 load (low) byte
+anda(0x01) #124 mask bit (r1c3)
+bne('.fgc15') #125 branch if bit set (AC not equal 0)
+bra('.drawpxl15') #126 jump to "draw pixel"
+ld([sysArgs+0]) #127a select BG color
+label('.fgc15')
+ld([sysArgs+1]) #127b select FG color
+label('.drawpxl15')
+st([Y,Xpp]) #128 Draw pixel, increase X
+
+# Return to interpreter
+ld(hi('REENTER'), Y) #129
+jmp(Y,'REENTER') #130
+ld(-134/2) #131
+
# XXX Unfinished
#-----------------------------------------------------------------------
--
2.17.1
+818
View File
@@ -0,0 +1,818 @@
#ifdef TINY_FONT
#define ROWS 20
#define COLS 40
#define CHAR_LEADING 0
#define CHAR_WIDTH 4
#define CHAR_HEIGHT 6
#else
// NOTE: Normal chars have a horizontal offset of 2, 26 chars
#define ROWS 15
#define COLS 26
#define CHAR_LEADING 0
#define CHAR_WIDTH 6
#define CHAR_HEIGHT 8
#endif
#define MAX_X (COLS*CHAR_WIDTH)
#define MAX_Y (ROWS*(CHAR_HEIGHT+CHAR_LEADING))
// Standard includes
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
// System include
#include <Gigatron.h>
// SPI ports (active low)
#define SS0 0x04
#define SS1 0x08
#define SS2 0x10
#define SS3 0x20
#define BANK0 0x40
#define BANK1 0x80
#define SPI_MASK 0x3c
#define BANK_MASK 0xc0
#define DarkYellow 0x05
#define Yellow 0x0a
#define LightYellow 0x0f
#define DarkMagenta 0x11
#define Magenta 0x22
#define LightMagenta 0x33
#define DarkCyan 0x14
#define Cyan 0x28
#define LightCyan 0x3c
#define DarkGray 0x15
#define LightGray 0x2a
#define romType (*(byte*)0x0021)
#define romTypeValue_ROMv4 0x38
#define romTypeValue_DEVROM 0xf8
#define xoutMask (*(byte*)0x0014)
#define ledState (*(byte*)0x002E)
#define ledTempo (*(byte*)0x002F)
#define SYS_VDrawWord_134 0x00cb
#define SYS_Draw4_30 0x04d4
#define SYS_SetMode_v2_80 0x0b00
#define SYS_SetMemory_v2_54 0x0b03
#define SYS_ExpanderControl_v4_40 0x0b09
#define SYS_SpiExchangeBytes_v4_134 0x0b15
// Forward declaration
void cursorDown( byte _amount, byte _allowScroll );
#define NEWLINE_EX() {cursorDown(1,1);ScreenPos &= 0xff00;}
#define NEWLINE_EX2() {cursorDown(1,1);ScreenPos &= 0xff00;ScreenPos |= 0x0002;}
#define ROW_TO_SCREEN(_r,_s){\
((byte*)&_s)[1] = _r * ( CHAR_HEIGHT + CHAR_LEADING ) + videoTable[0];\
if ( ((byte*)&_s)[1] > 0x7f )\
((byte*)&_s)[1] -= 120;\
}
#ifdef TINY_FONT
// Hijack original functions
#define PutChar(c) PutChar_ex(c)
//#define puts(s) puts_ex(s)
#define Newline() NEWLINE_EX()
#else
#define Newline() NEWLINE_EX2()
#endif
int cursor[ 12 ];
const int tinyfont[96] = {
#include "../Utils/BabelFish/tinyfont.h"
};
void EraseInLine( byte _mode, int _screenCoord )
{
byte size;
char line;
switch ( _mode )
{
case 0:
// Erase from the active position to the end of the line, inclusive (default)
//size = 160 - (_screenCoord & 0x00ff);
size = 160 - ((byte*)&_screenCoord)[0];
break;
case 1:
// Erase from the start of the line to the active position, inclusive
size = 160 - ((byte*)&_screenCoord)[0] + CHAR_WIDTH;
_screenCoord = _screenCoord & 0xff00;
break;
case 2:
// Erase all of the line, inclusive
_screenCoord = _screenCoord & 0xff00;
size = 160;
break;
}
// Clear this line
sysFn = SYS_SetMemory_v2_54;
sysArgs[1] = BgColor; // Set background color
for ( line = 0; line < CHAR_HEIGHT; ++line )
{
*(int*)(sysArgs+2) = _screenCoord; // Destination
sysArgs[0] = size; // Count
__syscall(243); // 270-54/2
_screenCoord += 256;
}
}
void PutChar_ex( byte c )
{
// DECAWM->autowrap to newline (allow scroll) or overwrite last char
byte i;
#ifdef TERMINAL_MODES
byte wrap = (terminalModes & DECAWM) ? 1 : 0;
#else
byte wrap = 1;
#endif
// Accept newlines
if (c == '\n')
{
Newline();
return;
}
if ( c == 9 )
{
// TODO: make tab work for big font as well
ScreenPos += 8 * CHAR_WIDTH;
ScreenPos &= ~(8*CHAR_WIDTH - 1);
}
else if ( c < 32 || c > 127 )
return;
// Wrap to new line if we're outside the view
if (((byte*)&ScreenPos)[0] >= MAX_X )
{
if ( wrap )
{
Newline();
}
else
{
ScreenPos -= CHAR_WIDTH;
}
}
if ( c == 9 )
return;
i = c - 32;
sysFn = SYS_VDrawWord_134;
sysArgs[0] = BgColor;
sysArgs[1] = Color;
*(int*)(sysArgs+2) = tinyfont[ i ];
*(int*)(sysArgs+4) = ScreenPos;
__syscall(202); // 270-135/2
// Note that the column can be out of the display area
// (to prevent automatic newlines at the end of the screen)
//column++;
ScreenPos += CHAR_WIDTH;
}
signed char puts_ex(const char *s)
{
// Note that this fuction is dumbed down: no stream support
for (; *s; s++)
{
PutChar(*s);
}
return EOF;
}
void ScrollUp()
{
int screenCoord;
byte i;
// Clear first line since video rolls over
ROW_TO_SCREEN( 0, screenCoord );
EraseInLine( 2, screenCoord );
// Scroll up by manipulating video indirection table
i = 240;
do
{
byte page;
i -= 2;
page = videoTable[i] + CHAR_HEIGHT + CHAR_LEADING;
videoTable[i] = page & 128 ? page - 120 : page;
} while (i);
}
void PutGlyph( unsigned long _g )
{
// Wrap to new line if we're outside the view
if (((byte*)&ScreenPos)[0] >= MAX_X )
Newline();
sysFn = SYS_VDrawWord_134;
sysArgs[0] = BgColor;
sysArgs[1] = Color;
*(int*)(sysArgs+2) = _g;
*(int*)(sysArgs+4) = ScreenPos;
__syscall(202); // 270-135/2
// Note that the column can be out of the display area
// (to prevent automatic newlines at the end of the screen)
//column++;
ScreenPos += CHAR_WIDTH;
}
void drawChar( int* _char )
{
if (((byte*)&ScreenPos)[0] >= MAX_X )
return;
*(int*)ScreenPos = _char[0];
*(int*)(ScreenPos + 2) = _char[1];
*(int*)(ScreenPos + 256) = _char[2];
*(int*)(ScreenPos + 258) = _char[3];
*(int*)(ScreenPos + 512) = _char[4];
*(int*)(ScreenPos + 514) = _char[5];
*(int*)(ScreenPos + 768) = _char[6];
*(int*)(ScreenPos + 770) = _char[7];
*(int*)(ScreenPos + 1024) = _char[8];
*(int*)(ScreenPos + 1026) = _char[9];
*(int*)(ScreenPos + 1280) = _char[10];
*(int*)(ScreenPos + 1282) = _char[11];
}
void drawCursor( byte _copy )
{
byte i;
// TODO: maybe try and draw on the next line
if (((byte*)&ScreenPos)[0] >= MAX_X )
return;
// TODO: MAX_Y
if ( _copy )
{
cursor[0] = *(int*)ScreenPos;
cursor[1] = *(int*)(ScreenPos + 2);
cursor[2] = *(int*)(ScreenPos + 256);
cursor[3] = *(int*)(ScreenPos + 258);
cursor[4] = *(int*)(ScreenPos + 512);
cursor[5] = *(int*)(ScreenPos + 514);
cursor[6] = *(int*)(ScreenPos + 768);
cursor[7] = *(int*)(ScreenPos + 770);
cursor[8] = *(int*)(ScreenPos + 1024);
cursor[9] = *(int*)(ScreenPos + 1026);
cursor[10] = *(int*)(ScreenPos + 1280);
cursor[11] = *(int*)(ScreenPos + 1282);
}
else
{
for ( i = 0; i < 12; i++ )
cursor[i] = BgColor << 8 | BgColor;
}
// Prepare SYS call
sysFn = SYS_Draw4_30;
sysArgs[0] = Color;
sysArgs[1] = Color;
sysArgs[2] = Color;
sysArgs[3] = BgColor;
*(int*)(sysArgs+4) = ScreenPos;
// Draw bitmap to screen as 'n' vertical slices
// TODO: there are not enough cycles to include the 6th line when drawing a character; dont draw any pixels in it for now to avoid clutter
//for (i=CHAR_HEIGHT; i>0; --i)
for (i=5; i>0; --i)
{
__syscall(255); // 270-30/2
sysArgs[5]++;
}
}
void setCursor( byte _r, byte _c )
{
// Restore character behind cursor
//drawChar( cursor );
if ( _r >= ROWS )
_r = ROWS - 1;
if ( _c >= COLS )
_c = COLS - 1;
// Calculate row with scroll offset in mind
ROW_TO_SCREEN( _r, ScreenPos );
ScreenPos &= 0xff00;
#ifdef TINY_FONT
ScreenPos |= (( _c * CHAR_WIDTH + videoTable[1] ) & 0x00ff );
#else
ScreenPos |= (( _c * CHAR_WIDTH + videoTable[1] + 2) & 0x00ff );
#endif
// Draw cursor
//drawCursor( 1 );
}
void EraseInDisplay( byte _mode, int _screenCoord )
{
byte line;
byte row = ((byte*)&_screenCoord)[1];
if ( videoTable[0] > row )
row += 120;
row -= videoTable[0];
row /= ( CHAR_HEIGHT + CHAR_LEADING );
// Erase current line
EraseInLine( _mode, _screenCoord );
// 0: end
// 1: begin
// 2: all
if ( _mode && row )
{
// Erase begin or all of screen
for ( line = 0; line < row; ++line )
{
#if defined( SLOW ) && defined( TESTS )
BusyWait( 10 );
#endif
ROW_TO_SCREEN( line, _screenCoord );
EraseInLine( 2, _screenCoord );
}
}
if ( _mode != 1 )
{
// Erase end or all of screen
//for ( ++row; row < ROWS - 1; ++row )
for ( ++row; row < ROWS; ++row )
{
#if defined( SLOW ) && defined( TESTS )
BusyWait( 10 );
#endif
ROW_TO_SCREEN( row, _screenCoord );
EraseInLine( 2, _screenCoord );
}
}
}
void cursorUp( byte _amount, byte _allowScroll )
{
// TODO: avoid usage of int -> (byte*)&_screenCoord)[1];
/*
byte row = ((byte*)&_screenCoord)[1];
if ( videoTable[0] > row )
row += 120;
row -= videoTable[0];
row /= ( CHAR_HEIGHT + CHAR_LEADING );
*/
int y = (ScreenPos >> 8) - videoTable[0];
if ( y < 0 )
y += 120;
while ( _amount-- )
{
if ( y >= ( CHAR_HEIGHT + CHAR_LEADING ) )
{
ScreenPos -= (( CHAR_HEIGHT + CHAR_LEADING ) << 8 );
y -= CHAR_HEIGHT + CHAR_LEADING;
}
else if ( _allowScroll )
{
// TODO: ScrollDown();
}
else
{
break;
}
}
}
void cursorDown( byte _amount, byte _allowScroll )
{
// Determine y offset (avoid usage of int)
byte row = ((byte*)&ScreenPos)[1];
if ( videoTable[0] > row )
row += 120;
row -= videoTable[0];
row /= ( CHAR_HEIGHT + CHAR_LEADING );
while ( _amount-- )
{
if ( row < (ROWS - 1) )
{
row++;
ROW_TO_SCREEN( row, ScreenPos );
}
else if ( _allowScroll )
{
ScrollUp();
ROW_TO_SCREEN( row, ScreenPos );
}
else
{
break;
}
}
}
void cursorLeft( byte _amount )
{
// TODO: avoid usage of int
int x = (ScreenPos & 0xff );
while ( _amount-- )
{
if ( x >= CHAR_WIDTH )
{
ScreenPos -= CHAR_WIDTH;
x -= CHAR_WIDTH;
}
else
{
break;
}
}
}
void cursorRight( byte _amount )
{
// TODO: avoid usage of int
int x = (ScreenPos & 0xff );
while ( _amount-- )
{
if ( x < (MAX_X - CHAR_WIDTH) )
{
ScreenPos += CHAR_WIDTH;
x += CHAR_WIDTH;
}
else
{
break;
}
}
}
#ifdef TESTS
void test()
{
reset();
setCursor( 0, 0 );
puts_ex( "Tests:" );
reset();
test_cursor();
reset();
test_clear();
reset();
test_colors();
reset();
test_linewrap();
reset();
test_scroll();
reset();
test_cursorscroll();
reset();
test_newline();
reset();
test_e3();
// Done
reset();
ledState = 0;
setCursor( 2, 2 );
puts_ex( "Done." );
}
void test_cursor()
{
// test setCursor, drawCursor and cursor up/down/left/right
setCursor( 2, 2 );
puts_ex( "Cursor" );
// bottom right corner: '#'
drawChar( cursor );
setCursor( 100, 100 );
PutChar( '#' );
drawCursor( 1 );
xoutMask++;
BusyWait( 60 );
// top right corner: 'B'
drawChar( cursor );
cursorLeft( 1 ); // TODO: fix cursor
cursorUp( 100, 0 );
PutChar( 'B' );
drawCursor( 1 );
xoutMask++;
BusyWait( 60 );
// top left corner: 'A'
drawChar( cursor );
cursorLeft( 100 );
PutChar( 'A' );
drawCursor( 1 );
xoutMask++;
BusyWait( 60 );
// bottom left corner: 'D'
drawChar( cursor );
cursorLeft( 1 ); // TODO: fix cursor
cursorDown( 100, 0 );
PutChar( 'D' );
drawCursor( 1 );
xoutMask++;
BusyWait( 60 );
// bottom right corner: 'C'
drawChar( cursor );
cursorRight( 100 );
PutChar( 'C' );
drawCursor( 1 );
xoutMask++;
BusyWait( 60 );
}
void test_clear()
{
// Test EraseInDisplay and inherently, EraseInLine in all 3 variations
setCursor( 2, 2 );
puts_ex( "Clear" );
// Erase lower half with red
BgColor = DarkRed;
setCursor( ROWS / 2, COLS / 2 );
EraseInDisplay( 0, ScreenPos );
xoutMask++;
BusyWait( 60 );
// Erase upper half with green
BgColor = DarkGreen;
EraseInDisplay( 1, ScreenPos );
xoutMask++;
BusyWait( 60 );
// Erase all with black
BgColor = Black;
EraseInDisplay( 2, ScreenPos );
xoutMask++;
BusyWait( 60 );
}
void test_colors()
{
// Test all 64 foreground and background colors
byte r;
byte c;
setCursor( 2, 2 );
puts_ex( "Colors" );
BgColor = Black;
for ( r = 0; r < 8; ++r )
{
for ( c = 0; c < 8; ++c )
{
setCursor( r + 5, c + 8 );
Color = 8 * r + c;
PutChar( '#' );
}
}
xoutMask++;
Color = White;
for ( r = 0; r < 8; ++r )
{
for ( c = 0; c < 8; ++c )
{
setCursor( r + 5, c + 24 );
BgColor = 8 * r + c;
PutChar( '.' );
}
}
xoutMask++;
BusyWait( 60 );
}
void test_linewrap()
{
// Test line wrapping
byte count;
char linewrap[] = "Line wrap";
setCursor( 2, 2 );
puts_ex( linewrap );
BusyWait( 60 );
setCursor( 0, 0 );
count = 20;
Color = LightGreen;
while ( count-- )
{
puts_ex( linewrap );
xoutMask++;
BusyWait( 5 );
}
// Force DECAWM (automatic wrap mode) off
#ifdef TERMINAL_MODES
terminalModes &= ~DECAWM;
count = 5;
Color = LightRed;
while ( count-- )
{
puts_ex( linewrap );
xoutMask++;
BusyWait( 5 );
}
#endif
}
void test_scroll()
{
// Test screen scrolling
byte count = 21;
setCursor( 2, 2 );
puts_ex( "Scroll" );
while ( count-- )
{
ScrollUp();
setCursor( 0, 10 );
puts_ex( "line 1 will be erased" );
setCursor( 19, 16 );
puts_ex( "line 20" );
xoutMask++;
BusyWait( 10 );
}
// TODO: scroll down/left/up
}
void test_cursorscroll()
{
// Test cursor scrolling
byte count;
setCursor( 2, 2 );
puts_ex( "CursorScroll" );
// Center
setCursor( ROWS / 2, COLS / 2 );
count = 21;
while ( count-- )
{
cursorDown( 1, 1 );
PutChar( '^' );
xoutMask++;
BusyWait( 30 );
}
/*
// Center
setCursor( ROWS / 2, COLS / 2 );
count = 21;
while ( count-- )
{
cursorUp( 1, 1 );
PutChar( 'v' );
xoutMask++;
BusyWait( 30 );
}
*/
}
void test_newline()
{
// Test newline scrolling
byte count = 21;
char newline[] = "Newline";
setCursor( 2, 2 );
puts_ex( newline );
setCursor( 8, 0 );
drawCursor( 0 );
while ( count-- )
{
drawChar( cursor );
Newline();
puts_ex( newline );
drawCursor( 1 );
xoutMask++;
BusyWait( 30 );
}
}
void test_e3()
{
// Fill screen with 'E', wait a second and fill the next 3 lines with '3'
byte c;
byte r = ROWS;
setCursor( 2, 2 );
puts_ex( "E3" );
drawCursor( 1 );
BusyWait( 60 );
drawChar( cursor );
setCursor( 0, 0 );
drawCursor( 1 );
// Fill screen with 'E'
while ( r-- )
{
c = COLS;
while ( c-- )
{
PutChar( 'E' );
drawCursor( 0 );
#ifdef SLOW
BusyWait( 1 );
#endif
xoutMask++;
}
}
BusyWait( 60 );
r = 3;
while ( r-- )
{
c = COLS;
while ( c-- )
{
PutChar( '3' );
drawCursor( 0 );
#ifdef SLOW
BusyWait( 3 );
#endif
xoutMask++;
}
}
}
void reset()
{
byte i = 240;
byte t = 127;
ledState = 0;
BusyWait( 60 );
// LEDs static on
ledState = 1;
xoutMask = 0xf;
//Reset cursor
ScreenPos = (int)screenMemory;
// Clear display
BgColor = Blue;
Color = White;
EraseInDisplay( 2, ScreenPos );
// Reset scroll
// Scroll up by manipulating video indirection table
do
{
i -= 2;
videoTable[i] = t--;
} while (i);
// Store and draw (empty) cursor
drawCursor( 0 );
drawChar( cursor );
}
#endif
+71
View File
@@ -0,0 +1,71 @@
#ifndef VTACTIONSTATES_DOT_H
#define VTACTIONSTATES_DOT_H
#ifdef TERMINAL_MODES
// Terminal modes
#define LNM (1 << 0) // !LNM -- Line Feed/New Line Mode
#define DECCKM (1 << 1) // Cursor Keys Mode
#define DECANM (1 << 2) // ANSI/VT52 Mode
#define DECCOLM (1 << 3) // Column Mode
#define DECSCLM (1 << 4) // Scrolling Mode
#define DECSCNM (1 << 5) // Screen Mode
#define DECOM (1 << 6) // Origin Mode
#define DECAWM (1 << 7) // Autowrap Mode
#define DECARM (1 << 8) // Auto Repeat Mode
#define DECINLM (1 << 9) // Interlace Mode
#define DECKPAM (1 << 10) // Keypad Application Mode
#endif
// Control characters
#define NUL 0x00
#define SOH 0x01
#define STX 0x02
#define ETX 0x03
#define EOT 0x04
#define ENQ 0x05
#define ACK 0x06
#define BEL 0x07
#define BS 0x08
#define HT 0x09
#define LF 0x0A
#define VT 0x0B
#define FF 0x0C
#define CR 0x0D
#define SO 0x0E
#define SI 0x0F
#define DLE 0x10
#define DC1 0x11
#define XON 0x11
#define DC2 0x12
#define DC3 0x13
#define XOFF 0x13
#define DC4 0x14
#define NAK 0x15
#define SYN 0x16
#define ETB 0x17
#define CAN 0x18
#define EM 0x19
#define SUB 0x1A
#define ESC 0x1B
#define FS 0x1C
#define GS 0x1D
#define RS 0x1E
#define US 0x1F
#define SP 0x20
#define DEL 0x7F
typedef enum {
VTPARSE_MODE_REGULAR = 0, // (control+printable characters)
VTPARSE_MODE_ESCAPE_INTERMEDIATE = 1, //
VTPARSE_MODE_CONTROL_SEQUENCE = 2, //
VTPARSE_MODE_ESCAPE_CURSOR_LINE = 3, // waiting for line value
VTPARSE_MODE_ESCAPE_CURSOR_COLUMN = 4, // waiting for column value
} vtparse_mode_t;
vtparse_mode_t mode = VTPARSE_MODE_REGULAR;
#ifdef TERMINAL_MODES
int terminalModes = LNM | DECCKM | DECANM | DECAWM | DECARM;
#endif
#endif // VTACTIONSTATES_DOT_H
+44
View File
@@ -0,0 +1,44 @@
# NetTerm
This gigatron program is an attempt to create a terminal that talks over SPI1 to the outside world.
Every keypress on the gigatron will be transfered over SPI, and every byte (apart from ANSI escapecodes) goes from SPI to the screen.
For the first run, execute `make lcc` in the *gigatron-rom* root folder.
run `make Contrib/xopr/NetTerm/NetTerm.gt1` in the root folder to build a new version.
If you want to test the NetTerm without expander hardware (i.e., emulator), you can comment out the following define:
```
//#define IOPORT SS1
```
**Note:**
This application is still experimental and written to work best with a [Gigatron expander card](https://forum.gigatron.io/viewtopic.php?f=4&t=64) combined with a patched *dev.rom* that enables drawing of the 3x5 'tinyfont'.
To apply the patch, run `git apply Contrib/xopr/NetTerm/SYS_VDrawWord.patch` followed by `make dev.rom` and `make burn` to compile and burn the DEVROM to EPRPOM.
The patch itself was created using:
```
git add Core/dev.py
git commit -m "Added SYS_VDrawWord function"
git format-patch -1 master --stdout > Contrib/xopr/NetTerm/SYS_VDrawWord.patch
git reset HEAD^
git checkout -- Core/dev.py
```
# SPI_slave
This Arduino program acts like a SPI slave that transfers bytes from and to the (USB) serial connection.
It can be used to hook the gigatron up to the PC as a terminal client, or powered without USB, used as TTL serial (pins 0 and 1).
**Note:**
Make sure you disable the Arduino reset when using it as a USB serial terminal.
For programming, either re-enable Arduino reset or reset it manually directly after clicking upload.
Newer Arduinos have a scratch/solder pad for that (which one can scratch through and solder a jumper on): it should be in the middle of an Arduino uno with a label "Reset on".
## Run a terminal server
To run a terminal server for the (Arduino) Serial port, verify which port it uses (in my case, it was /dev/**ttyACM0**.
On a systemd linux machine:
* run: `systemctl enable serial-getty@ttyACM0.service` (or the appropriate Arduino serial device)
* edit: `/etc/systemd/system/getty.target.wants/serial-getty@ttyACM0.service`
* and change `ExecStart=...... $TERM` into `ExecStart=...... vt100`
* then run: `systemctl daemon-reload`
* and: `systemctl restart serial-getty@ttyACM0.service`
+57
View File
@@ -0,0 +1,57 @@
// NOTE: make sure you disable the Arduino reset when using it as a serial terminal
// run: `systemctl enable serial-getty@ttyACM0.service` (or the appropriate Arduino serial device
// edit: `/etc/systemd/system/getty.target.wants/serial-getty@ttyACM0.service`
// and change
// ExecStart=...... $TERM
// into:
// ExecStart=...... vt52
// then run: `systemctl daemon-reload`
// and: `systemctl restart serial-getty@ttyACM0.service`
#define SERIAL_BUFFER_SIZE 1024
//from https://forum.arduino.cc/index.php?topic=52111.0
#include "pins_arduino.h"
volatile char serialByte = 0;
volatile char spiByte = 0;
void setup (void)
{
// Note: The Atmega16u2 uses U2X mode, where 300 baud isn't possible
// CH340G has a minimum of 2400 baud
// https://github.com/arduino/ArduinoCore-avr/issues/265
// Fetch updated firmware from: https://github.com/facchinm/Arduino_avrusb_firmware/tree/master/arduino-usbserial
// https://www.arduino.cc/en/Hacking/DFUProgramming8U2
// see https://forum.arduino.cc/index.php?topic=385567.0
Serial.begin( 300 );
// have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// turn on interrupts
SPCR |= _BV(SPIE);
}
// SPI interrupt routine
ISR (SPI_STC_vect)
{
spiByte = SPDR;
SPDR = serialByte;
serialByte = 0;
}
// main loop - wait for flag set in interrupt routine
void loop (void)
{
if ( spiByte && spiByte > 0 )
{
Serial.print( spiByte );
spiByte = 0;
}
if ( !serialByte && Serial.available() )
serialByte = Serial.read();
}