Commit b65c3b3b authored by John P. Willis's avatar John P. Willis
Browse files

Disk work

parent b2b7d2a3
......@@ -6,3 +6,8 @@ bps=9600
parity=N
data_bits=8
stop_bits=1
[disk]
count=2
0=disk0.dsk
1=disk1.dsk
\ No newline at end of file
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
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 disk.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
MKDISK_OBJS = mkdisk.o disk.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
FBCFLAGS = -g -mt #-d STACKDEBUG -d INSTDEBUG #-d LEXDEBUG
all: vm assembler rom test
all: vm assembler diskutil rom test
diskutil: mkdisk
vm: ilxim
test: t_stack.bin
rom: rom.bin xiasm
rom: rom.bin diskboot.bin xiasm
diskboot.bin: diskboot.xa
./xiasm diskboot.xa
rom.bin: rom.xa
./xiasm rom.xa
......@@ -18,15 +25,24 @@ t_stack.bin: t_stack.xa
assembler: xiasm
mkdisk: $(MKDISK_OBJS)
fbc $(FBCFLAGS) -x mkdisk $(MKDISK_OBJS)
xiasm: $(XIASM_OBJS)
fbc $(FBCFLAGS) -x xiasm $(XIASM_OBJS)
xiasm.o: xiasm.bas
fbc $(FBCFLAGS) -m xiasm -o xiasm.o -c xiasm.bas
mkdisk.o: mkdisk.bas
fbc $(FBCFLAGS) -m mkdisk -o mkdisk.o -c mkdisk.bas
ilxim: $(VM_OBJS)
fbc $(FBCFLAGS) -x ilxim $(VM_OBJS)
disk.o: disk.bas
fbc $(FBCFLAGS) -o disk.o -c disk.bas
profile.o: profile.bas
fbc $(FBCFLAGS) -o profile.o -c profile.bas
......
......@@ -65,6 +65,9 @@
#define OP_CMP 014
#define OP_CMPSZ 015
#define OP_CNS 016
#define OP_CSN 017
#define OP_BRANCH 020
#define OP_BEQ 021
#define OP_BNE 022
......
......@@ -24,11 +24,81 @@ sub disk_attach()
.dev_output = @disk_output
end with
disk_io_base = disk_device.io_base
bus_attach 5, disk_device
end sub
sub disk_init()
sub disk_init()
dim i as integer
dim disk_header as disk_header_t
if installed_disk_count > 0 then
for i = 0 to installed_disk_count - 1
close #installed_disks(i).file_number
next i
end if
installed_disk_count = val(config_get("disk", "count"))
redim installed_disks(installed_disk_count) as installed_disk_t
for i = 0 to installed_disk_count - 1
installed_disks(i).host_file = config_get("disk", trim(str(i)))
installed_disks(i).file_number = freefile()
open installed_disks(i).host_file for binary as #installed_disks(i).file_number
get #installed_disks(i).file_number, , disk_header
with installed_disks(i)
.track_count = disk_header.track_count
.sectors_per_track = disk_header.sectors_per_track
end with
disk_build_seek_table i
message_print "disk_init(): channel " & trim(str(i)) & ": " & disk_header.track_count & " tracks, " & disk_header.sectors_per_track & " sectors/track (host file " & installed_disks(i).host_file & ")"
next i
for i = 0 to installed_disk_count - 1
disk_seek i, 0
next i
end sub
sub disk_build_seek_table(new_channel as ushort)
dim f_num as integer
dim f_header as disk_header_t
dim f_track as disk_track_t
dim i as integer
dim f_pos as integer
dim t_cnt as ushort
f_num = installed_disks(new_channel).file_number
t_cnt = installed_disks(new_channel).track_count
seek #f_num, 1
get #f_num, , f_header
redim preserve disk_seek_table(installed_disk_count, t_cnt) as ushort
for i = 0 to t_cnt
f_pos = seek(f_num)
disk_seek_table(new_channel, i) = f_pos
get #f_num, , f_track
next i
seek #f_num, 1
end sub
......@@ -60,13 +130,11 @@ sub disk_output(port_number as ushort, value as ushort)
case (disk_io_base + 2)
sect_buf_offset = value
case (disk_io_base + 3)
track = value
disk_seek channel, value
case (disk_io_base + 4)
sector = value
disk_read value
case (disk_io_base + 5)
' read
case (disk_io_base + 6)
' write
disk_write value
end select
end sub
......@@ -74,9 +142,101 @@ end sub
sub disk_cycle(byval userdata as any ptr)
do
sleep 500
sleep 500, 1
if bus_get_stop_flag(5) = 1 then exit do
loop
end sub
\ No newline at end of file
end sub
sub disk_create(file_path as string, track_count as ushort)
dim file_number as integer
dim file_header as disk_header_t
dim track as disk_track_t
dim i as integer
file_number = freefile()
open file_path for binary as #file_number
with file_header
.magic = "XDI"
.track_count = track_count
.sectors_per_track = 512 'hardcoded for now
end with
put #file_number, , file_header
for i = 0 to track_count - 1
put #file_number, , track
next i
close #file_number
end sub
sub disk_seek(new_channel as ushort, new_track as ushort)
dim f_num as integer
dim f_pos as integer
f_num = installed_disks(new_channel).file_number
seek #f_num, disk_seek_table(new_channel, new_track)
f_pos = seek(f_num)
message_print "disk_seek(): channel " & new_channel & ": track " & new_track & " (host file offset " & f_pos &")"
installed_disks(new_channel).current_track = new_track
end sub
sub disk_read(tgt_sector as ushort)
dim tmp_track as disk_track_t
dim tmp_sector as disk_sector_t
dim f_num as integer
dim i as integer
dim c_byte as integer = 0
f_num = installed_disks(channel).file_number
get #f_num, ,tmp_track
tmp_sector = tmp_track.sectors(tgt_sector)
for i = sect_buf_offset to sect_buf_offset + 512
st_write_byte sect_buf_page, i, tmp_sector.sector(c_byte)
c_byte += 1
next i
end sub
sub disk_write(tgt_sector as ushort)
dim tmp_track as disk_track_t
dim tmp_sector as disk_sector_t
dim f_num as integer
f_num = installed_disks(channel).file_number
dim i as integer
dim c_byte as integer = 0
for i = sect_buf_offset to sect_buf_offset + 512
tmp_sector.sector(c_byte) = st_read_byte(sect_buf_page, i)
c_byte += 1
next i
tmp_track.sectors(tgt_sector) = tmp_sector
put #f_num, , tmp_track
end sub
function disk_get_iobase() as ushort
return disk_io_base
end function
\ No newline at end of file
......@@ -8,9 +8,8 @@
' 1: Set sector memory buffer page
' 2: Set sector memory buffer offset
' 3: Set disk track for current channel
' 4: Set disk sector for current channel
' 5: Read current track/sector into sector memory buffer
' 6: Write current sector memory buffer to current track/sector
' 4: Read sector X from current track into sector memory buffer
' 5: Write current sector memory buffer to sector in current track
'
' IN
'
......@@ -25,32 +24,41 @@ type disk_header_t
sectors_per_track as ushort
end type
type disk_track_t
sectors(512) as disk_sector_t
end type
type disk_sector_t
sector(512) as ubyte
end type
type disk_track_t
sectors(512) as disk_sector_t
end type
type installed_disk_t
host_file as string
file_number as integer
current_track as ushort
track_count as ushort
sectors_per_track as ushort
end type
dim shared disk_seek_table(any, any) as ushort
dim shared installed_disks() as installed_disk_t
dim shared installed_disk_count as ushort
dim shared channel as ushort
dim shared sect_buf_page as ushort
dim shared sect_buf_offset as ushort
dim shared track as ushort
dim shared sector as ushort
dim shared disk_io_base as ushort
declare sub disk_attach()
declare sub disk_init()
declare sub disk_build_seek_table(new_channel as ushort)
declare sub disk_reset()
declare function disk_input(port_number as ushort) as ushort
declare sub disk_output(port_number as ushort, value as ushort)
declare sub disk_cycle()
\ No newline at end of file
declare sub disk_cycle(byval userdata as any ptr)
declare sub disk_create(file_path as string, track_count as ushort)
declare sub disk_seek(new_channel as ushort, new_track as ushort)
declare sub disk_read(tgt_sector as ushort)
declare sub disk_write(tgt_sector as ushort)
declare function disk_get_iobase() as ushort
\ No newline at end of file
......@@ -26,8 +26,8 @@ LABEL __query_disk0
;
IN WORD %GA,240
CMP WORD %GA,1
BGE WORD {__load_boot}
CMP WORD %GA,0
BGT WORD {__load_boot}
;
; disk 0 is not installed. print error message and halt.
......@@ -50,14 +50,13 @@ LABEL __load_boot
;
; select disk 0, track 0, sector 0
;
OUT WORD 240,0
OUT WORD 243,0
OUT WORD 244,0
OUT WORD 240,0 ; channel 0
OUT WORD 243,0 ; track 0
;
; read sector into buffer
;
OUT WORD 245,0
OUT WORD 244,0 ; sector 0
;
; jump to loaded code
......
......@@ -9,6 +9,7 @@
#include "asm.bi"
#include "util.bi"
#include "console.bi"
#include "disk.bi"
#include "bus.bi"
#include "message.bi"
......@@ -28,6 +29,7 @@ sub startup()
bus_clear
console_attach
disk_attach
init_cpu
cli
......@@ -52,9 +54,7 @@ sub cli()
line input "ilxim> ", cli_cmd
mutexunlock console_mutex
if cli_cmd = "" then cli_cmd = last_cmd
if cli_cmd = "" then cli_cmd = last_cmd
arg_count = lex(cli_cmd)
cmd_name = get_lexer_entry(0).strval
......@@ -84,6 +84,53 @@ sub cli()
end if
st_save_page img_file, page_index
case "writesect", "ws"
dim iobase as ushort = disk_get_iobase()
dim page_index as integer
dim page_offset as integer
dim disk_channel as ushort
dim disk_track as ushort
dim disk_sector as ushort
if get_lexer_entry(1).lexer_class = LC_BYTE then
page_index = get_lexer_entry(1).byteval
else
page_index = get_lexer_entry(1).intval
end if
if get_lexer_entry(2).lexer_class = LC_BYTE then
page_offset = get_lexer_entry(2).byteval
else
page_offset = get_lexer_entry(2).intval
end if
if get_lexer_entry(3).lexer_class = LC_BYTE then
disk_channel = get_lexer_entry(3).byteval
else
disk_channel = get_lexer_entry(3).intval
end if
if get_lexer_entry(4).lexer_class = LC_BYTE then
disk_track = get_lexer_entry(4).byteval
else
disk_track = get_lexer_entry(4).intval
end if
if get_lexer_entry(5).lexer_class = LC_BYTE then
disk_sector = get_lexer_entry(5).byteval
else
disk_sector = get_lexer_entry(5).intval
end if
disk_output iobase + 0, disk_channel
disk_output iobase + 1, page_index
disk_output iobase + 2, page_offset
disk_output iobase + 3, disk_track
disk_output iobase + 4, disk_sector
case "assemble", "a"
dim le_origin as lexer_entry
dim origin_addr as ushort
......
'
' mkdisk.bas
'
#include "mkdisk.bi"
#include "disk.bi"
#include "lexer.bi"
sub main(args as string)
dim arg_count as integer
dim file_name as string
dim track_count as ushort
arg_count = lex(args)
file_name = get_lexer_entry(0).strval
track_count = val(get_lexer_entry(1).strval)
disk_create file_name, track_count
end sub
main command()
end
\ No newline at end of file
'
' mkdisk.bi
'
declare sub main(args as string)
\ 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