'start and end byte codes
symbol start = 0x00
symbol finish = 0xAA
'index of each command and its data
symbol start_red = 0
symbol end_red = 1
symbol start_freq = 2
symbol end_freq = 4
symbol start_mux = 5
symbol end_mux = 7
symbol char_start = 8
symbol colour = 0x23 'pink! or try 1 as blue or 2 as red!
'data: see above for index into this array
data 0,(0xed,colour,0xEF, 0x07, 0x00,0xEE, 0x00)
' character data, can only fit one character (0) would be more,
data char_start,(%01100110,%01111110,%01111110,%01111110,%01111110,%01100110,%01000010,%00000000)
'custom symbols for getting parity and
'stop bits for data, also memory addresses
'for parameters
symbol set_parity = b4
symbol parity = b5
symbol var_proc = w5
symbol block_loop = b6
' i use these locations to store
' params for the routines as some of them
' are nested and need variables
symbol from_range = $50
symbol to_range = $51
symbol line_number = $54
symbol line_lower_byte = $55
symbol line_uppet_byte = $56
symbol bytes_per_line = 27
'symbols for shift out
symbol sclk = 2 ‘ clock (output pin)
symbol sdata = 0 ‘ data (output pin for shiftout)
symbol counter = b7 ‘ variable used during loop
symbol mask = w4 ‘ bit masking variable
symbol var_out = w6 ‘ data variable used during shiftout
symbol bits = 12 ‘ number of bits - two stop bits, one parity bit, and eight data bits, one start bit
symbol MSBvalue = 128 ‘ MSBvalue
' **main!**
' main method, will set up internal variables and set
' the background colour to whatever colour is set to up above
main:
pause 3000
setfreq m8
'set up freqency variables
poke from_range, start_freq
poke to_range, end_freq
gosub sub_block
'set up mux variable
poke from_range, start_mux
poke to_range, end_mux
gosub sub_block
'set colour to red
poke from_range, start_red
poke to_range, end_red
gosub sub_block
'print out some characters
poke line_number, 0
poke line_lower_byte, 0
gosub draw_line
poke line_number, 1
poke line_lower_byte, 1
gosub draw_line
poke line_number, 2
poke line_lower_byte, 0
gosub draw_line
' this draws the fourth line on the screen
' had to take this out to get the one character (0)
' in memory
'
' poke line_number, 3
' poke line_lower_byte, 1
' gosub draw_line
'make screen refresh as fast as possible
pwmout 2 , 39, 80
clock:
'pulsout sclk,1 ‘ pulse clock for 5us (m8 mode)
goto clock
' **sub_block**
' writes out start and end bytes and will write out
' bytes from the eeprom based upon values
' from_range and to_range
'
' say 'from' is set to 10 and 'to' is set to 12
' it will write out bytes 10 11 12 from eeprom
' wrapped in start and end bytes with correct parity
sub_block:
gosub sub_start'start byte
peek from_range, b0'get params
peek to_range, b1
set_parity = 1'set parity
for block_loop = b0 to b1
read block_loop, var_out
gosub out
next block_loop
gosub sub_finish'end byte
return
' **draw_line**
' draws a character onto the screen
' based upon a word in storage - THIS IS BROKEN
' i ran out of space to make it work
draw_line:
gosub sub_start
peek line_number, b0
b1 = bytes_per_line * b0
var_out = 0x80 + b1
set_parity = 1
gosub out
for b0 = 1 to 27
peek line_lower_byte, b2
b2 = b2 * 8
b1 = b0 % 5
b2 = b2 + b1
b2 = b2 + char_start
read b2, var_out
gosub out
next b0
gosub sub_finish
return
' **sub_start**
' **sub_finish**
' will send start/end byte with correct parrity
' small optimisation here, shared code, bit messy
sub_start:
var_out = start
goto _sub_out
sub_finish:
var_out = finish
_sub_out:
set_parity = 0
gosub out
return
'**out**
'shift out lsb first
out:
' will turn a byte into a 12 bit word with 2 stop bits and parity
' parity will be based on set_parity
parity = 0
var_proc = var_out
for counter = 1 to 8
mask = var_proc & 1 ‘ mask LSB
parity = parity ^ mask
var_proc = var_proc / 2 ‘ shift variable right for LSB
next counter
parity = parity ^ set_parity
var_proc = parity * 512
var_out = var_out*2
var_out = 0x0C00 | var_out
var_out = var_out | var_proc
'actually do the shifting out
for counter = 1 to bits ‘ number of bits
mask = var_out & 1 ‘ mask LSB
low sdata ‘ data low
if mask = 0 then skipLSB
high sdata ‘ data high
skipLSB: pulsout sclk,1 ‘ pulse clock for 10us
var_out = var_out / 2 ‘ shift variable right for LSB
next counter
return