Commit 0e3f3add authored by John P. Willis's avatar John P. Willis

Console and storage work

parent b65c3b3b
......@@ -7,6 +7,7 @@
#include "bus.bi"
#include "config.bi"
#include "message.bi"
#include "cpu.bi"
sub console_attach()
......@@ -20,7 +21,7 @@ sub console_attach()
with console_device
.dev_tag = "console"
.io_base = 0
.io_port_count = 5
.io_port_count = 7
.dev_init = @console_init_local
.dev_reset = @console_reset_local
.dev_cycle = @console_cycle_local
......@@ -28,6 +29,8 @@ sub console_attach()
.dev_output = @console_output
end with
console_refresh = @console_refresh_local
message_print "console_attach(): local console"
case "serial"
......@@ -35,7 +38,7 @@ sub console_attach()
with console_device
.dev_tag = "console"
.io_base = 0
.io_port_count = 4
.io_port_count = 7
.dev_init = @console_init_serial
.dev_reset = @console_reset_serial
.dev_cycle = @console_cycle_serial
......@@ -43,6 +46,8 @@ sub console_attach()
.dev_output = @console_output
end with
console_refresh = @console_refresh_serial
console_port = config_get("console", "port")
console_bps = config_get("console", "bps")
console_parity = config_get("console", "parity")
......@@ -70,7 +75,7 @@ sub console_init_serial()
dim result as long
dim serial_string as string
serial_string = console_port & ":" & console_bps & "," & console_parity & "," & console_data_bits & "," & console_stop_bits
serial_string = console_port & ":" & console_bps & "," & console_parity & "," & console_data_bits & "," & console_stop_bits & ",cs0,ds0,cd0,rs"
result = open com(serial_string, as console_file_number)
......@@ -101,6 +106,8 @@ function console_input(port_number as ushort) as ushort
return horizontal_offset
case (console_io_base + 3)
return vertical_offset
case (console_io_base + 4)
return len(console_input_buffer)
case else
return 0
end select
......@@ -138,47 +145,53 @@ sub console_output(port_number as ushort, value as ushort)
st_write_byte CONSOLE_PAGE, i, 0
next i
case (console_io_base + 5)
console_refresh()
case (console_io_base + 6)
mutexlock console_mutex
for i = 1 to value
st_write_byte cpu_state.ds, cpu_state.di, asc(mid(console_input_buffer, i, 1))
cpu_state.di += 1
next i
console_input_buffer = mid(console_input_buffer, value + 1)
mutexunlock console_mutex
end select
end sub
sub console_cycle_local(byval userdata as any ptr)
dim i as integer
dim c as ubyte
do
sleep sleep_duration, 1
dim old_row as integer
dim old_col as integer
if bus_get_stop_flag(0) = 1 then exit do
loop
dim col as ubyte = 1 'x
dim row as ubyte = 1 'y
end sub ' console_cycle_local()
do
col = 1
row = 1
sub console_cycle_serial(byval userdata as any ptr)
old_row = csrlin()
old_col = pos()
mutexlock console_mutex
do
' mutexlock console_mutex
for i = CONSOLE_OFFSET to CONSOLE_LIMIT - 1
c = st_read_byte(CONSOLE_PAGE, i)
locate row, col
console_bytes_waiting = loc(console_file_number)
print chr(c);
if col >= CONSOLE_WIDTH then
row = row + 1
col = 1
else
col = col + 1
end if
next i
if console_bytes_waiting > 0 then
message_print "console_cycle_serial(): reading " & console_bytes_waiting & " bytes from console"
console_input_buffer &= input(console_bytes_waiting, console_file_number)
end if
mutexunlock console_mutex
' mutexunlock console_mutex
sleep sleep_duration, 1
......@@ -186,55 +199,75 @@ sub console_cycle_local(byval userdata as any ptr)
loop
locate 26,1
end sub ' console_cycle_local()
sub console_cycle_serial(byval userdata as any ptr)
end sub ' console_cycle_serial()
sub console_refresh_local()
dim i as integer
dim c as ubyte
dim output_str as string
dim old_row as integer
dim old_col as integer
dim col as ubyte = 1 'x
dim row as ubyte = 1 'y
dim bytes_waiting as integer
dim input_buffer as string
do
bytes_waiting = lof(console_file_number)
mutexlock console_mutex
if bytes_waiting > 0 then
message_print "console_cycle_serial(): reading " & bytes_waiting & " bytes from console"
input_buffer &= input(bytes_waiting, console_file_number)
end if
col = 1
row = 1
col = 1
row = 1
old_row = csrlin()
old_col = pos()
for i = CONSOLE_OFFSET to CONSOLE_LIMIT - 1
c = st_read_byte(CONSOLE_PAGE, i)
for i = CONSOLE_OFFSET to CONSOLE_LIMIT - 1
output_str = chr(27) & "[" & trim(str(row + horizontal_offset)) & ";" & trim(str(col + vertical_offset)) & "H" & chr(c)
c = st_read_byte(CONSOLE_PAGE, i)
locate row, col
print #console_file_number, output_str;
print chr(c);
if col >= CONSOLE_WIDTH then
row = row + 1
col = 1
else
col = col + 1
end if
next i
if col >= CONSOLE_WIDTH then
row = row + 1
col = 1
else
col = col + 1
end if
sleep sleep_duration, 1
next i
if bus_get_stop_flag(0) = 1 then exit do
loop
mutexunlock console_mutex
end sub ' console_cycle_serial()
end sub ' console_refresh_local()
sub console_refresh_serial()
dim i as integer
dim c as ubyte
dim output_str as string
dim col as ubyte = 1 'x
dim row as ubyte = 1 'y
for i = CONSOLE_OFFSET to CONSOLE_LIMIT - 1
c = st_read_byte(CONSOLE_PAGE, i)
output_str = chr(27) & "[" & trim(str(row + horizontal_offset)) & ";" & trim(str(col + vertical_offset)) & "H" & chr(c)
print #console_file_number, output_str;
if col >= CONSOLE_WIDTH then
row = row + 1
col = 1
else
col = col + 1
end if
next i
end sub ' console_refresh_serial()
\ No newline at end of file
......@@ -8,10 +8,12 @@
' OUT
'
' IOBASE + 0: 1 = Enable Cursor; 0 = Disable Cursor
' 1: Set refresh sleep value (ms)
' 1: Set cycle sleep value (ms)
' 2: Set horizontal offset
' 3: Set vertical offset
' 4: Write to this port to clear video buffer
' 5: Refresh console
' 6: Copy <value> bytes from console buffer to DS:DI
'
' IN
'
......@@ -19,7 +21,7 @@
' 1: Read refresh sleep value (ms)
' 2: Read horizontal offset
' 3: Read vertical offset
' 4: Nonsense!
' 4: Get byte count of console buffer
#define CONSOLE_PAGE &H0001
......@@ -42,10 +44,15 @@ dim shared vertical_offset as ushort = 0
dim shared sleep_duration as ushort = 50
dim shared cursor_enabled as ushort = 1
dim shared console_input_buffer as string
dim shared console_bytes_waiting as ushort
dim shared console_file_number as integer
dim shared console_io_base as ushort
dim shared console_refresh as sub()
declare sub console_attach()
declare sub console_init_local()
declare sub console_reset_local()
......@@ -56,3 +63,5 @@ declare sub console_cycle_local(byval userdata as any ptr)
declare sub console_init_serial()
declare sub console_reset_serial()
declare sub console_cycle_serial(byval userdata as any ptr)
declare sub console_refresh_local()
declare sub console_refresh_serial()
\ No newline at end of file
......@@ -128,7 +128,7 @@ sub cli()
disk_output iobase + 2, page_offset
disk_output iobase + 3, disk_track
disk_output iobase + 4, disk_sector
disk_output iobase + 5, disk_sector
case "assemble", "a"
......
......@@ -12,4 +12,8 @@ declare sub st_write_byte(page as integer, offset as integer, value as byte)
declare sub st_load_page(file as string, page as integer)
declare sub st_save_page(file as string, page as integer)
declare sub st_write_word(page as integer, offset as integer, wordval as ushort)
declare function st_read_word(page as integer, offset as integer) as ushort
\ No newline at end of file
declare function st_read_word(page as integer, offset as integer) as ushort
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment