Commit 2f8a09a1 authored by John P. Willis's avatar John P. Willis

Initial work on serial console

parent 46b54da1
[console]
mode=serial
port=COM
bps=9600
parity=N
data_bits=8
stop_bits=1
VM_OBJS = ilxi.o asm.o cpu.o error.o host.o storage.o lexer.o inst.o util.o bus.o console.o signal.o message.o
XIASM_OBJS = xiasm.o asm.o cpu.o lexer.o storage.o inst.o error.o util.o console.o bus.o signal.o message.o
VM_OBJS = ilxi.o asm.o cpu.o error.o host.o storage.o lexer.o inst.o util.o bus.o console.o signal.o message.o profile.o config.o
XIASM_OBJS = xiasm.o asm.o cpu.o lexer.o storage.o inst.o error.o util.o console.o bus.o signal.o message.o profile.o config.o
FBCFLAGS = -g -mt
# -d STACKDEBUG
# -d LEXDEBUG
......@@ -29,6 +29,12 @@ xiasm.o: xiasm.bas
ilxim: $(VM_OBJS)
fbc $(FBCFLAGS) -x ilxim $(VM_OBJS)
profile.o: profile.bas
fbc $(FBCFLAGS) -o profile.o -c profile.bas
config.o: config.bas
fbc $(FBCFLAGS) -o config.o -c config.bas
asm.o: asm.bas
fbc $(FBCFLAGS) -o asm.o -c asm.bas
......@@ -69,4 +75,4 @@ message.o: message.bas
fbc $(FBCFLAGS) -o message.o -c message.bas
clean:
rm -f *.o ilxim xiasm rom.bin
rm -f *.o ilxim xiasm rom.bin t_stack.bin
......@@ -631,7 +631,7 @@ function asm_disassemble(page as ushort, offset as ushort) as string
msb = st_read_byte(page, offset)
addr = asm_bytes_to_ushort(lsb, msb)
tmp_str &= trim(str(addr))
tmp_str &= trim(hex(addr)) & "h"
case AM_REGD 'register direct
......@@ -645,12 +645,12 @@ function asm_disassemble(page as ushort, offset as ushort) as string
msb = st_read_byte(page, offset)
addr = asm_bytes_to_ushort(lsb, msb)
tmp_str &= "#" & trim(str(addr))
tmp_str &= "#" & trim(hex(addr)) & "h"
case AM_REGDD 'reg. direct + disp
reg = st_read_byte(page, offset)
tmp_str &= "%" & asm_decode_register(reg) & "+" & trim(str(displacement))
tmp_str &= "%" & asm_decode_register(reg) & "+" & trim(hex(displacement)) & "h"
case AM_MEMDD 'mem. direct + disp
......@@ -659,7 +659,7 @@ function asm_disassemble(page as ushort, offset as ushort) as string
msb = st_read_byte(page, offset)
addr = asm_bytes_to_ushort(lsb, msb)
tmp_str &= "#" & trim(str(addr)) & "+" & trim(str(displacement))
tmp_str &= "#" & trim(hex(addr)) & "h+" & trim(hex(displacement)) & "h"
case AM_REGI 'register indirect
reg = st_read_byte(page, offset)
......@@ -672,11 +672,11 @@ function asm_disassemble(page as ushort, offset as ushort) as string
msb = st_read_byte(page, offset)
addr = asm_bytes_to_ushort(lsb, msb)
tmp_str &= "(#" & trim(str(addr)) & ")"
tmp_str &= "(#" & trim(hex(addr)) & "h)"
case AM_REGID 'reg. indirect + disp
reg = st_read_byte(page, offset)
tmp_str &= "(%" & asm_decode_register(reg) & ")+" & trim(str(displacement))
tmp_str &= "(%" & asm_decode_register(reg) & ")+" & trim(hex(displacement)) & "h"
case AM_MEMID 'mem. indirect + disp
lsb = st_read_byte(page, offset)
......@@ -684,7 +684,7 @@ function asm_disassemble(page as ushort, offset as ushort) as string
msb = st_read_byte(page, offset)
addr = asm_bytes_to_ushort(lsb, msb)
tmp_str &= "(#" & trim(str(addr)) & ")+" & trim(str(displacement))
tmp_str &= "(#" & trim(hex(addr)) & "h)+" & trim(hex(displacement)) & "h"
end select
......@@ -694,7 +694,7 @@ function asm_disassemble(page as ushort, offset as ushort) as string
dasm_offset = offset
return tmp_str
return ucase(tmp_str)
end function ' asm_disassemble()
......@@ -711,7 +711,7 @@ sub asm_disassemble_range(page as ushort, start_offset as ushort, count as ushor
print ilxi_pad_left(hex(page), "0", 4); ":";
print ilxi_pad_left(hex(dasm_offset), "0", 4); " ";
print asm_disassemble(page, dasm_offset)
print ucase(asm_disassemble(page, dasm_offset))
dasm_offset += 1
......
'
' config.bas
'
#include "config.bi"
#include "profile.bi"
#include "util.bi"
function config_get(section as string, key as string) as string
return profile_read(config_file(), section, key)
end function ' config_get()
sub config_set(section as string, key as string, value as string)
profile_write config_file(), section, key, value
end sub ' config_set()
function config_file() as string
dim home_directory as string = environ("HOME")
if file_exists("./.ilximrc") = 1 then return "./.ilximrc"
if file_exists(home_directory & "/.ilximrc") then return home_directory & "/.ilximrc"
if file_exists("/etc/ilxim.conf") then return "/etc/ilxim.conf"
return ""
end function ' config_file()
\ No newline at end of file
'
' config.bi
'
declare function config_get(section as string, key as string) as string
declare sub config_set(section as string, key as string, value as string)
declare function config_file() as string
\ No newline at end of file
......@@ -5,31 +5,88 @@
#include "console.bi"
#include "storage.bi"
#include "bus.bi"
#include "config.bi"
#include "message.bi"
sub console_attach()
dim dev as dev_entry
with dev
.dev_tag = "console"
.io_base = 0
.io_port_count = 4
.dev_init = @console_init
.dev_reset = @console_reset
.dev_cycle = @console_cycle
.dev_input = @console_input
.dev_output = @console_output
end with
dim console_mode as string = config_get("console", "mode")
select case console_mode
case "local"
with dev
.dev_tag = "console"
.io_base = 0
.io_port_count = 4
.dev_init = @console_init_local
.dev_reset = @console_reset_local
.dev_cycle = @console_cycle_local
.dev_input = @console_input
.dev_output = @console_output
end with
message_print "console_attach(): local console"
case "serial"
with dev
.dev_tag = "console"
.io_base = 0
.io_port_count = 4
.dev_init = @console_init_serial
.dev_reset = @console_reset_serial
.dev_cycle = @console_cycle_serial
.dev_input = @console_input
.dev_output = @console_output
end with
console_port = config_get("console", "port")
console_bps = config_get("console", "bps")
console_parity = config_get("console", "parity")
console_data_bits = config_get("console", "data_bits")
console_stop_bits = config_get("console", "stop_bits")
message_print "console_attach(): serial console at " & console_port & ": (" & console_bps & " " & console_parity & console_data_bits & console_stop_bits & ")"
end select
bus_attach 0, dev
end sub
sub console_init()
sub console_init_local()
console_mutex = mutexcreate()
end sub
sub console_reset()
sub console_init_serial()
console_mutex = mutexcreate()
console_file_number = freefile()
dim result as long
dim serial_string as string
serial_string = console_port & ":" & console_bps & "," & console_parity & "," & console_data_bits & "," & console_stop_bits
result = open com(serial_string, as console_file_number)
if err > 0 then
message_print "console_init_serial(): error #" & trim(str(err)) & " occurred opening " & console_port & ":"
end if
print #console_file_number, chr(27) & "[2J"
end sub
sub console_reset_local()
end sub
sub console_reset_serial()
end sub
......@@ -41,7 +98,7 @@ sub console_output(port_number as ushort, value as ushort)
end sub
sub console_cycle(byval userdata as any ptr)
sub console_cycle_local(byval userdata as any ptr)
dim i as integer
dim c as ubyte
......@@ -64,7 +121,10 @@ sub console_cycle(byval userdata as any ptr)
for i = CONSOLE_OFFSET to CONSOLE_LIMIT - 1
c = st_read_byte(CONSOLE_PAGE, i)
locate row, col, 0: print chr(c);
locate row, col
print chr(c);
if col >= CONSOLE_WIDTH then
row = row + 1
......@@ -74,8 +134,6 @@ sub console_cycle(byval userdata as any ptr)
end if
next i
locate old_row, old_col
mutexunlock console_mutex
sleep 25
......@@ -86,4 +144,47 @@ sub console_cycle(byval userdata as any ptr)
locate 26,1
end sub
\ No newline at end of file
end sub ' console_cycle_local()
sub console_cycle_serial(byval userdata as any ptr)
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
do
col = 1
row = 1
mutexlock console_mutex
for i = CONSOLE_OFFSET to CONSOLE_LIMIT - 1
c = st_read_byte(CONSOLE_PAGE, i)
output_str = chr(27) & "[" & trim(str(row)) & ";" & trim(str(col)) & "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
mutexunlock console_mutex
sleep 25
if bus_get_stop_flag(0) = 1 then exit do
loop
end sub ' console_cycle_serial()
'
' console.bi
'
#define CONSOLE_PAGE &H0001
#define CONSOLE_OFFSET &H0000
#define CONSOLE_LIMIT &H07D0
......@@ -7,9 +11,21 @@
common shared console_mutex as any ptr
dim shared console_port as string
dim shared console_bps as string
dim shared console_parity as string
dim shared console_data_bits as string
dim shared console_stop_bits as string
dim shared console_file_number as integer
declare sub console_attach()
declare sub console_init()
declare sub console_reset()
declare sub console_init_local()
declare sub console_reset_local()
declare function console_input(port_number as ushort) as ushort
declare sub console_output(port_number as ushort, value as ushort)
declare sub console_cycle(byval userdata as any ptr)
\ No newline at end of file
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)
......@@ -86,8 +86,6 @@ sub cpu()
dim data_type as ubyte
cpu_clear_flag FL_HALT
cls
bus_start
' main cpu loop
......
'
' profile.bas
'
' Adapted from PROFILE.BAS from the book "Visual Basic for MS-DOS Workshop"
' and updated to use more modern syntax and static variable declaration.
'
' Also, completely re-factored to use more modern error handling.
'
#include "profile.bi"
function profile_read(ini_file as string, ini_section as string, ini_key as string) as string
dim tmp_section as string = "[" & ini_section & "]"
dim file_num as integer
dim section_flag as integer
dim current_line as string
file_num = freefile()
open ini_file for input as #file_num
if err > 0 then
close #file_num
return ""
end if
do until eof(file_num)
line input #file_num, current_line
if left(current_line, 1) = "[" then
if instr(current_line, tmp_section) = 1 then
section_flag = 1
else
section_flag = 0
end if
end if
if section_flag = 1 then
if instr(current_line, ini_key) = 1 then
close #file_num
return trim(mid(current_line, instr(current_line, "=") + 1))
end if
end if
loop
end function ' profile_read()
sub profile_write (ini_file as string, ini_section as string, ini_key as string, ini_value as string)
dim tmp_section as string = "[" & ini_section & "]"
dim file_num as integer
dim n as integer
dim i as integer
dim section_found as integer
dim section_flag as integer
dim key_found as integer
dim new_line as integer
redim p(1) as string
file_num = freefile()
open ini_file for input as #file_num
if err > 0 then exit sub
do until eof(file_num)
n += 1
redim preserve p(n) as string
line input #file_num, p(n)
loop
close #file_num
for i = 1 to n
if left(p(i), 1) = "[" then
if instr(p(i), tmp_section) = 1 then
section_flag = 1
section_found = i
else
section_flag = 0
end if
end if
if section_flag = 1 then
if instr(p(i), ini_key) = 1 then
p(i) = ini_key & "=" & ini_value
key_found = 1
exit for
end if
end if
next i
if section_found = 0 then
redim preserve p(n + 3)
p(n + 2) = tmp_section
p(n + 3) = ini_key & "=" & ini_value
n += 3
elseif key_found = 0 then
new_line = section_found + 1
redim preserve p(n + 1)
for i = n to new_line step - 1
p(i + 1) = p(i)
next i
p(new_line) = ini_key & "=" & ini_value
n += 1
end if
file_num = freefile()
open ini_file for output as file_num
for i = 1 to n
print #file_num, p(i)
next i
close #file_num
end sub ' profile_write()
'
' profile.bi
'
declare function profile_read(ini_file as string, ini_section as string, ini_key as string) as string
declare sub profile_write(ini_file as string, ini_section as string, ini_key as string, ini_value as string)
......@@ -84,5 +84,5 @@ LABEL __word_fail
CPSZ
LABEL __main_tail
BRANCH __mail_tail
HLT
......@@ -16,4 +16,20 @@ function ilxi_pad_left(input_str as string, pad_char as string, total_size as in
output_str = output_str & input_str
return output_str
end function
\ No newline at end of file
end function
function file_exists(file_name as string) as integer
dim file_num as integer = freefile()
open file_name for input as #file_num
if err > 0 then
return 0
else
close #file_num
return 1
end if
end function
......@@ -2,4 +2,5 @@
' util.bi
'
declare function ilxi_pad_left(input_str as string, pad_char as string, total_size as integer) as string
\ No newline at end of file
declare function ilxi_pad_left(input_str as string, pad_char as string, total_size as integer) as string
declare function file_exists(file_name as string) as integer
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